Skip to content

Commit

Permalink
netfilter: nfnetlink_hook: fix check for snprintf() overflow
Browse files Browse the repository at this point in the history
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: e2cf17d ("netfilter: add new hook nfnl subsystem")
Signed-off-by: Dan Carpenter <[email protected]>
Reviewed-by: Florian Westphal <[email protected]>
Signed-off-by: Pablo Neira Ayuso <[email protected]>
  • Loading branch information
Dan Carpenter authored and ummakynes committed Jun 21, 2021
1 parent 3078d96 commit 24610ed
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion net/netfilter/nfnetlink_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 24610ed

Please sign in to comment.