xfrm: fix rcu lock in xfrm_notify_userpolicy()

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2130609
Tested: basic IPsec tests + invalid configuration tests

commit 93ec1320b0170d7a207eda2d119c669b673401ed
Author: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date:   Wed Sep 22 10:50:06 2021 +0200

    xfrm: fix rcu lock in xfrm_notify_userpolicy()

    As stated in the comment above xfrm_nlmsg_multicast(), rcu read lock must
    be held before calling this function.

    Reported-by: syzbot+3d9866419b4aa8f985d6@syzkaller.appspotmail.com
    Fixes: 703b94b93c19 ("xfrm: notify default policy on update")
    Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
This commit is contained in:
Sabrina Dubroca 2023-03-27 17:02:02 +02:00
parent 5ce6912ce8
commit 7e18e73490
1 changed files with 6 additions and 1 deletions

View File

@ -1969,6 +1969,7 @@ static int xfrm_notify_userpolicy(struct net *net)
int len = NLMSG_ALIGN(sizeof(*up));
struct nlmsghdr *nlh;
struct sk_buff *skb;
int err;
skb = nlmsg_new(len, GFP_ATOMIC);
if (skb == NULL)
@ -1987,7 +1988,11 @@ static int xfrm_notify_userpolicy(struct net *net)
nlmsg_end(skb, nlh);
return xfrm_nlmsg_multicast(net, skb, 0, XFRMNLGRP_POLICY);
rcu_read_lock();
err = xfrm_nlmsg_multicast(net, skb, 0, XFRMNLGRP_POLICY);
rcu_read_unlock();
return err;
}
static bool xfrm_userpolicy_is_valid(__u8 policy)