Thread (1 message) 1 message, 1 author, 2021-10-13

Re: [PATCH] ipv4: only allow increasing fib_info_hash_size

From: David Ahern <hidden>
Date: 2021-10-13 02:33:27
Also in: lkml
Subsystem: networking [general], networking [ipv4/ipv6], the rest · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern, Ido Schimmel, Linus Torvalds

Possibly related (same subject, not in this thread)

On 10/12/21 7:10 PM, 张凯 wrote:
1) Below shift operation will set fib_info_hash_size to zero if there
are so many routes: 
  unsigned int new_size = fib_info_hash_size << 1;

    This will wrap value of fib_info_hash_size, and a lot of fib_info
will insert to a small hash bucket.
so this patch disables above wrap.
2) Check whether fib_info_hash_size is zero only needed after allocation
failed:
if (!new_info_hash || !new_laddrhash) {
why not something simpler like this:
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index 3364cb9c67e0..5c4bd1cebe0a 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -1401,6 +1401,10 @@ struct fib_info *fib_create_info(struct
fib_config *cfg,

                if (!new_size)
                        new_size = 16;
+
+               if (new_size < fib_info_hash_size)
+                       goto failure;
+
                bytes = new_size * sizeof(struct hlist_head *);
                new_info_hash = fib_info_hash_alloc(bytes);
                new_laddrhash = fib_info_hash_alloc(bytes);

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help