netfilter: nfnetlink_hook: fix check for snprintf() overflow
authorDan Carpenter <dan.carpenter@oracle.com>
Sat, 19 Jun 2021 13:55:46 +0000 (16:55 +0300)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 21 Jun 2021 20:05:29 +0000 (22:05 +0200)
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

index 58fda6a..50b4e3c 100644 (file)
@@ -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) {