[RHEL7,COMMIT] ms/netfilter: ipset: avoid null deref when IPSET_ATTR_LINENO is present

Submitted by Vasily Averin on Dec. 3, 2020, 9:21 a.m.


Message ID 202012030921.0B39L5Te004860@vz7build.vvs.sw.ru
State New
Series "Series without cover letter"
Headers show

Commit Message

Vasily Averin Dec. 3, 2020, 9:21 a.m.
The commit is pushed to "branch-rh7-3.10.0-1160.6.1.vz7.171.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1160.6.1.vz7.171.1
commit 1497e298cc2a0a0cce1353b618e33c10131895e4
Author: Florian Westphal <fw@strlen.de>
Date:   Thu Dec 3 12:21:05 2020 +0300

    ms/netfilter: ipset: avoid null deref when IPSET_ATTR_LINENO is present
    The set uadt functions assume lineno is never NULL, but it is in
    case of ip_set_utest().
    syzkaller managed to generate a netlink message that calls this with
    LINENO attr present:
    general protection fault: 0000 [#1] PREEMPT SMP KASAN
    RIP: 0010:hash_mac4_uadt+0x1bc/0x470 net/netfilter/ipset/ip_set_hash_mac.c:104
    Call Trace:
     ip_set_utest+0x55b/0x890 net/netfilter/ipset/ip_set_core.c:1867
     nfnetlink_rcv_msg+0xcf2/0xfb0 net/netfilter/nfnetlink.c:229
     netlink_rcv_skb+0x177/0x450 net/netlink/af_netlink.c:2477
     nfnetlink_rcv+0x1ba/0x460 net/netfilter/nfnetlink.c:563
    pass a dummy lineno storage, its easier than patching all set
    This seems to be a day-0 bug.
    Cc: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
    Reported-by: syzbot+34bd2369d38707f3f4a7@syzkaller.appspotmail.com
    Fixes: a7b4f989a6294 ("netfilter: ipset: IP set core support")
    Signed-off-by: Florian Westphal <fw@strlen.de>
    Acked-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
    (cherry-picked from commit 22dad713b8a5ff488e07b821195270672f486eb2)
    Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
 net/netfilter/ipset/ip_set_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
index 6d20f97..6ef5898 100644
--- a/net/netfilter/ipset/ip_set_core.c
+++ b/net/netfilter/ipset/ip_set_core.c
@@ -1678,6 +1678,7 @@  ip_set_utest(struct sock *ctnl, struct sk_buff *skb,
 	struct ip_set *set;
 	struct nlattr *tb[IPSET_ATTR_ADT_MAX + 1] = {};
 	int ret = 0;
+	u32 lineno;
 	if (unlikely(protocol_min_failed(attr) ||
 		     !attr[IPSET_ATTR_SETNAME] ||
@@ -1694,7 +1695,7 @@  ip_set_utest(struct sock *ctnl, struct sk_buff *skb,
-	ret = set->variant->uadt(set, tb, IPSET_TEST, NULL, 0, 0);
+	ret = set->variant->uadt(set, tb, IPSET_TEST, &lineno, 0, 0);
 	/* Userspace can't trigger element to be re-added */
 	if (ret == -EAGAIN)