netfilter: nfnetlink_hook: fix check for snprintf() overflow
Subsystems (4)
PATCH 1/1 netfilter: nfnetlink_hook: fix check for snprintf() overflow
The kernel version of snprintf() can't return negatives. The "ret > (int)sizeof(sym)" check is off by one because and it should be
Quoted 1 line
=. Finally, we need to set a negative error code.
Fixes e2cf17d3774c ("netfilter: add new hook nfnl subsystem")
Signed-off-by Dan Carpenter <[email protected]>
--- net/netfilter/nfnetlink_hook.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/nfnetlink_hook.c +3 -1
@@ -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) {
Signature · 1 line
2.30.2
Quoted 3 lines · Dan Carpenter
The kernel version of
snprintf()can't return negatives. The "ret > (int)sizeof(sym)" check is off by one because and it should beQuoted 1 line
=. Finally, we need to set a negative error code.
Reviewed-by Florian Westphal <[email protected]>
Quoted 3 lines · Dan Carpenter
The kernel version of
snprintf()can't return negatives. The "ret > (int)sizeof(sym)" check is off by one because and it should beQuoted 1 line
=. Finally, we need to set a negative error code.
Applied, thanks.