From: zhang kai <zhangkaiheb@126.com>
To: davem@davemloft.net
Cc: yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
zhang kai <zhangkaiheb@126.com>
Subject: [PATCH] ipv4: only allow increasing fib_info_hash_size
Date: Tue, 12 Oct 2021 19:06:58 +0800 [thread overview]
Message-ID: <20211012110658.10166-1-zhangkaiheb@126.com> (raw)
and when failed to allocate memory, check fib_info_hash_size.
Signed-off-by: zhang kai <zhangkaiheb@126.com>
---
net/ipv4/fib_semantics.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index a632b66bc..7547708a9 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -1403,17 +1403,20 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
if (!new_size)
new_size = 16;
- bytes = new_size * sizeof(struct hlist_head *);
- new_info_hash = fib_info_hash_alloc(bytes);
- new_laddrhash = fib_info_hash_alloc(bytes);
- if (!new_info_hash || !new_laddrhash) {
- fib_info_hash_free(new_info_hash, bytes);
- fib_info_hash_free(new_laddrhash, bytes);
- } else
- fib_info_hash_move(new_info_hash, new_laddrhash, new_size);
-
- if (!fib_info_hash_size)
- goto failure;
+
+ if (new_size > fib_info_hash_size) {
+ bytes = new_size * sizeof(struct hlist_head *);
+ new_info_hash = fib_info_hash_alloc(bytes);
+ new_laddrhash = fib_info_hash_alloc(bytes);
+ if (!new_info_hash || !new_laddrhash) {
+ fib_info_hash_free(new_info_hash, bytes);
+ fib_info_hash_free(new_laddrhash, bytes);
+
+ if (!fib_info_hash_size)
+ goto failure;
+ } else
+ fib_info_hash_move(new_info_hash, new_laddrhash, new_size);
+ }
}
fi = kzalloc(struct_size(fi, fib_nh, nhs), GFP_KERNEL);
--
2.17.1
next reply other threads:[~2021-10-12 11:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-12 11:06 zhang kai [this message]
2021-10-12 13:55 ` [PATCH] ipv4: only allow increasing fib_info_hash_size David Ahern
[not found] ` <3bd88b51.6c7.17c77339c10.Coremail.zhangkaiheb@126.com>
2021-10-13 2:33 ` David Ahern
[not found] ` <5219d023.14d1.17c778a9a18.Coremail.zhangkaiheb@126.com>
[not found] ` <1e3f52c3.350f.17c78afcc56.Coremail.zhangkaiheb@126.com>
2021-10-14 2:51 ` David Ahern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211012110658.10166-1-zhangkaiheb@126.com \
--to=zhangkaiheb@126.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=yoshfuji@linux-ipv6.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).