Skip to content

Commit 593d1eb

Browse files
joannekoongkuba-moo
authored andcommitted
Revert "net: Add a second bind table hashed by port and address"
This reverts: commit d5a42de ("net: Add a second bind table hashed by port and address") commit 538aaf9 ("selftests: Add test for timing a bind request to a port with a populated bhash entry") Link: https://lore.kernel.org/netdev/20220520001834.2247810-1-kuba@kernel.org/ There are a few things that need to be fixed here: * Updating bhash2 in cases where the socket's rcv saddr changes * Adding bhash2 hashbucket locks Links to syzbot reports: https://lore.kernel.org/netdev/00000000000022208805e0df247a@google.com/ https://lore.kernel.org/netdev/0000000000003f33bc05dfaf44fe@google.com/ Fixes: d5a42de ("net: Add a second bind table hashed by port and address") Reported-by: syzbot+015d756bbd1f8b5c8f09@syzkaller.appspotmail.com Reported-by: syzbot+98fd2d1422063b0f8c44@syzkaller.appspotmail.com Reported-by: syzbot+0a847a982613c6438fba@syzkaller.appspotmail.com Signed-off-by: Joanne Koong <joannelkoong@gmail.com> Link: https://lore.kernel.org/r/20220615193213.2419568-1-joannelkoong@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 219b51a commit 593d1eb

10 files changed

Lines changed: 83 additions & 611 deletions

File tree

include/net/inet_connection_sock.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#undef INET_CSK_CLEAR_TIMERS
2626

2727
struct inet_bind_bucket;
28-
struct inet_bind2_bucket;
2928
struct tcp_congestion_ops;
3029

3130
/*
@@ -58,7 +57,6 @@ struct inet_connection_sock_af_ops {
5857
*
5958
* @icsk_accept_queue: FIFO of established children
6059
* @icsk_bind_hash: Bind node
61-
* @icsk_bind2_hash: Bind node in the bhash2 table
6260
* @icsk_timeout: Timeout
6361
* @icsk_retransmit_timer: Resend (no ack)
6462
* @icsk_rto: Retransmit timeout
@@ -85,7 +83,6 @@ struct inet_connection_sock {
8583
struct inet_sock icsk_inet;
8684
struct request_sock_queue icsk_accept_queue;
8785
struct inet_bind_bucket *icsk_bind_hash;
88-
struct inet_bind2_bucket *icsk_bind2_hash;
8986
unsigned long icsk_timeout;
9087
struct timer_list icsk_retransmit_timer;
9188
struct timer_list icsk_delack_timer;

include/net/inet_hashtables.h

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -90,32 +90,11 @@ struct inet_bind_bucket {
9090
struct hlist_head owners;
9191
};
9292

93-
struct inet_bind2_bucket {
94-
possible_net_t ib_net;
95-
int l3mdev;
96-
unsigned short port;
97-
union {
98-
#if IS_ENABLED(CONFIG_IPV6)
99-
struct in6_addr v6_rcv_saddr;
100-
#endif
101-
__be32 rcv_saddr;
102-
};
103-
/* Node in the inet2_bind_hashbucket chain */
104-
struct hlist_node node;
105-
/* List of sockets hashed to this bucket */
106-
struct hlist_head owners;
107-
};
108-
10993
static inline struct net *ib_net(struct inet_bind_bucket *ib)
11094
{
11195
return read_pnet(&ib->ib_net);
11296
}
11397

114-
static inline struct net *ib2_net(struct inet_bind2_bucket *ib)
115-
{
116-
return read_pnet(&ib->ib_net);
117-
}
118-
11998
#define inet_bind_bucket_for_each(tb, head) \
12099
hlist_for_each_entry(tb, head, node)
121100

@@ -124,15 +103,6 @@ struct inet_bind_hashbucket {
124103
struct hlist_head chain;
125104
};
126105

127-
/* This is synchronized using the inet_bind_hashbucket's spinlock.
128-
* Instead of having separate spinlocks, the inet_bind2_hashbucket can share
129-
* the inet_bind_hashbucket's given that in every case where the bhash2 table
130-
* is useful, a lookup in the bhash table also occurs.
131-
*/
132-
struct inet_bind2_hashbucket {
133-
struct hlist_head chain;
134-
};
135-
136106
/* Sockets can be hashed in established or listening table.
137107
* We must use different 'nulls' end-of-chain value for all hash buckets :
138108
* A socket might transition from ESTABLISH to LISTEN state without
@@ -164,12 +134,6 @@ struct inet_hashinfo {
164134
*/
165135
struct kmem_cache *bind_bucket_cachep;
166136
struct inet_bind_hashbucket *bhash;
167-
/* The 2nd binding table hashed by port and address.
168-
* This is used primarily for expediting the resolution of bind
169-
* conflicts.
170-
*/
171-
struct kmem_cache *bind2_bucket_cachep;
172-
struct inet_bind2_hashbucket *bhash2;
173137
unsigned int bhash_size;
174138

175139
/* The 2nd listener table hashed by local port and address */
@@ -229,44 +193,14 @@ inet_bind_bucket_create(struct kmem_cache *cachep, struct net *net,
229193
void inet_bind_bucket_destroy(struct kmem_cache *cachep,
230194
struct inet_bind_bucket *tb);
231195

232-
static inline bool check_bind_bucket_match(struct inet_bind_bucket *tb,
233-
struct net *net,
234-
const unsigned short port,
235-
int l3mdev)
236-
{
237-
return net_eq(ib_net(tb), net) && tb->port == port &&
238-
tb->l3mdev == l3mdev;
239-
}
240-
241-
struct inet_bind2_bucket *
242-
inet_bind2_bucket_create(struct kmem_cache *cachep, struct net *net,
243-
struct inet_bind2_hashbucket *head,
244-
const unsigned short port, int l3mdev,
245-
const struct sock *sk);
246-
247-
void inet_bind2_bucket_destroy(struct kmem_cache *cachep,
248-
struct inet_bind2_bucket *tb);
249-
250-
struct inet_bind2_bucket *
251-
inet_bind2_bucket_find(struct inet_hashinfo *hinfo, struct net *net,
252-
const unsigned short port, int l3mdev,
253-
struct sock *sk,
254-
struct inet_bind2_hashbucket **head);
255-
256-
bool check_bind2_bucket_match_nulladdr(struct inet_bind2_bucket *tb,
257-
struct net *net,
258-
const unsigned short port,
259-
int l3mdev,
260-
const struct sock *sk);
261-
262196
static inline u32 inet_bhashfn(const struct net *net, const __u16 lport,
263197
const u32 bhash_size)
264198
{
265199
return (lport + net_hash_mix(net)) & (bhash_size - 1);
266200
}
267201

268202
void inet_bind_hash(struct sock *sk, struct inet_bind_bucket *tb,
269-
struct inet_bind2_bucket *tb2, const unsigned short snum);
203+
const unsigned short snum);
270204

271205
/* Caller must disable local BH processing. */
272206
int __inet_inherit_port(const struct sock *sk, struct sock *child);

include/net/sock.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ struct sk_filter;
348348
* @sk_txtime_report_errors: set report errors mode for SO_TXTIME
349349
* @sk_txtime_unused: unused txtime flags
350350
* @ns_tracker: tracker for netns reference
351-
* @sk_bind2_node: bind node in the bhash2 table
352351
*/
353352
struct sock {
354353
/*
@@ -538,7 +537,6 @@ struct sock {
538537
#endif
539538
struct rcu_head sk_rcu;
540539
netns_tracker ns_tracker;
541-
struct hlist_node sk_bind2_node;
542540
};
543541

544542
enum sk_pacing {
@@ -819,16 +817,6 @@ static inline void sk_add_bind_node(struct sock *sk,
819817
hlist_add_head(&sk->sk_bind_node, list);
820818
}
821819

822-
static inline void __sk_del_bind2_node(struct sock *sk)
823-
{
824-
__hlist_del(&sk->sk_bind2_node);
825-
}
826-
827-
static inline void sk_add_bind2_node(struct sock *sk, struct hlist_head *list)
828-
{
829-
hlist_add_head(&sk->sk_bind2_node, list);
830-
}
831-
832820
#define sk_for_each(__sk, list) \
833821
hlist_for_each_entry(__sk, list, sk_node)
834822
#define sk_for_each_rcu(__sk, list) \
@@ -846,8 +834,6 @@ static inline void sk_add_bind2_node(struct sock *sk, struct hlist_head *list)
846834
hlist_for_each_entry_safe(__sk, tmp, list, sk_node)
847835
#define sk_for_each_bound(__sk, list) \
848836
hlist_for_each_entry(__sk, list, sk_bind_node)
849-
#define sk_for_each_bound_bhash2(__sk, list) \
850-
hlist_for_each_entry(__sk, list, sk_bind2_node)
851837

852838
/**
853839
* sk_for_each_entry_offset_rcu - iterate over a list at a given struct offset

net/dccp/proto.c

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,12 +1120,6 @@ static int __init dccp_init(void)
11201120
SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT, NULL);
11211121
if (!dccp_hashinfo.bind_bucket_cachep)
11221122
goto out_free_hashinfo2;
1123-
dccp_hashinfo.bind2_bucket_cachep =
1124-
kmem_cache_create("dccp_bind2_bucket",
1125-
sizeof(struct inet_bind2_bucket), 0,
1126-
SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT, NULL);
1127-
if (!dccp_hashinfo.bind2_bucket_cachep)
1128-
goto out_free_bind_bucket_cachep;
11291123

11301124
/*
11311125
* Size and allocate the main established and bind bucket
@@ -1156,7 +1150,7 @@ static int __init dccp_init(void)
11561150

11571151
if (!dccp_hashinfo.ehash) {
11581152
DCCP_CRIT("Failed to allocate DCCP established hash table");
1159-
goto out_free_bind2_bucket_cachep;
1153+
goto out_free_bind_bucket_cachep;
11601154
}
11611155

11621156
for (i = 0; i <= dccp_hashinfo.ehash_mask; i++)
@@ -1182,23 +1176,14 @@ static int __init dccp_init(void)
11821176
goto out_free_dccp_locks;
11831177
}
11841178

1185-
dccp_hashinfo.bhash2 = (struct inet_bind2_hashbucket *)
1186-
__get_free_pages(GFP_ATOMIC | __GFP_NOWARN, bhash_order);
1187-
1188-
if (!dccp_hashinfo.bhash2) {
1189-
DCCP_CRIT("Failed to allocate DCCP bind2 hash table");
1190-
goto out_free_dccp_bhash;
1191-
}
1192-
11931179
for (i = 0; i < dccp_hashinfo.bhash_size; i++) {
11941180
spin_lock_init(&dccp_hashinfo.bhash[i].lock);
11951181
INIT_HLIST_HEAD(&dccp_hashinfo.bhash[i].chain);
1196-
INIT_HLIST_HEAD(&dccp_hashinfo.bhash2[i].chain);
11971182
}
11981183

11991184
rc = dccp_mib_init();
12001185
if (rc)
1201-
goto out_free_dccp_bhash2;
1186+
goto out_free_dccp_bhash;
12021187

12031188
rc = dccp_ackvec_init();
12041189
if (rc)
@@ -1222,38 +1207,30 @@ static int __init dccp_init(void)
12221207
dccp_ackvec_exit();
12231208
out_free_dccp_mib:
12241209
dccp_mib_exit();
1225-
out_free_dccp_bhash2:
1226-
free_pages((unsigned long)dccp_hashinfo.bhash2, bhash_order);
12271210
out_free_dccp_bhash:
12281211
free_pages((unsigned long)dccp_hashinfo.bhash, bhash_order);
12291212
out_free_dccp_locks:
12301213
inet_ehash_locks_free(&dccp_hashinfo);
12311214
out_free_dccp_ehash:
12321215
free_pages((unsigned long)dccp_hashinfo.ehash, ehash_order);
1233-
out_free_bind2_bucket_cachep:
1234-
kmem_cache_destroy(dccp_hashinfo.bind2_bucket_cachep);
12351216
out_free_bind_bucket_cachep:
12361217
kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep);
12371218
out_free_hashinfo2:
12381219
inet_hashinfo2_free_mod(&dccp_hashinfo);
12391220
out_fail:
12401221
dccp_hashinfo.bhash = NULL;
1241-
dccp_hashinfo.bhash2 = NULL;
12421222
dccp_hashinfo.ehash = NULL;
12431223
dccp_hashinfo.bind_bucket_cachep = NULL;
1244-
dccp_hashinfo.bind2_bucket_cachep = NULL;
12451224
return rc;
12461225
}
12471226

12481227
static void __exit dccp_fini(void)
12491228
{
1250-
int bhash_order = get_order(dccp_hashinfo.bhash_size *
1251-
sizeof(struct inet_bind_hashbucket));
1252-
12531229
ccid_cleanup_builtins();
12541230
dccp_mib_exit();
1255-
free_pages((unsigned long)dccp_hashinfo.bhash, bhash_order);
1256-
free_pages((unsigned long)dccp_hashinfo.bhash2, bhash_order);
1231+
free_pages((unsigned long)dccp_hashinfo.bhash,
1232+
get_order(dccp_hashinfo.bhash_size *
1233+
sizeof(struct inet_bind_hashbucket)));
12571234
free_pages((unsigned long)dccp_hashinfo.ehash,
12581235
get_order((dccp_hashinfo.ehash_mask + 1) *
12591236
sizeof(struct inet_ehash_bucket)));

0 commit comments

Comments
 (0)