From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org
Subject: [PATCH net-next 6/6] netfilter: nfnetlink_hook: fix check for snprintf() overflow
Date: Wed, 23 Jun 2021 19:03:01 +0200 [thread overview]
Message-ID: <20210623170301.59973-7-pablo@netfilter.org> (raw)
In-Reply-To: <20210623170301.59973-1-pablo@netfilter.org>
From: Dan Carpenter <dan.carpenter@oracle.com>
The kernel version of snprintf() can't return negatives. The
"ret > (int)sizeof(sym)" check is off by one because and it should be
>=. Finally, we need to set a negative error code.
Fixes: e2cf17d3774c ("netfilter: add new hook nfnl subsystem")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nfnetlink_hook.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/netfilter/nfnetlink_hook.c b/net/netfilter/nfnetlink_hook.c
index 58fda6ac663b..50b4e3c9347a 100644
--- a/net/netfilter/nfnetlink_hook.c
+++ b/net/netfilter/nfnetlink_hook.c
@@ -126,8 +126,10 @@ static int nfnl_hook_dump_one(struct sk_buff *nlskb,
#ifdef CONFIG_KALLSYMS
ret = snprintf(sym, sizeof(sym), "%ps", ops->hook);
- if (ret < 0 || ret > (int)sizeof(sym))
+ if (ret >= sizeof(sym)) {
+ ret = -EINVAL;
goto nla_put_failure;
+ }
module_name = strstr(sym, " [");
if (module_name) {
--
2.30.2
prev parent reply other threads:[~2021-06-23 17:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-23 17:02 [PATCH net-next 0/6] Netfilter updates for net-next Pablo Neira Ayuso
2021-06-23 17:02 ` [PATCH net-next 1/6] netfilter: nft_exthdr: Search chunks in SCTP packets only Pablo Neira Ayuso
2021-06-23 19:40 ` patchwork-bot+netdevbpf
2021-06-23 17:02 ` [PATCH net-next 2/6] netfilter: nft_extdhr: Drop pointless check of tprot_set Pablo Neira Ayuso
2021-06-23 17:02 ` [PATCH net-next 3/6] netfilter: nf_tables: add last expression Pablo Neira Ayuso
2021-06-23 17:02 ` [PATCH net-next 4/6] netfilter: conntrack: pass hook state to log functions Pablo Neira Ayuso
2021-06-23 17:03 ` [PATCH net-next 5/6] docs: networking: Update connection tracking offload sysctl parameters Pablo Neira Ayuso
2021-06-23 17:03 ` Pablo Neira Ayuso [this message]
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=20210623170301.59973-7-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.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).