Skip to content

Commit

Permalink
net: xfrm: fix memory leak in xfrm_user_rcv_msg
Browse files Browse the repository at this point in the history
[ Upstream commit 7c1a80e ]

Syzbot reported memory leak in xfrm_user_rcv_msg(). The
problem was is non-freed skb's frag_list.

In skb_release_all() skb_release_data() will be called only
in case of skb->head != NULL, but netlink_skb_destructor()
sets head to NULL. So, allocated frag_list skb should be
freed manualy, since consume_skb() won't take care of it

Fixes: 5106f4a ("xfrm/compat: Add 32=>64-bit messages translator")
Reported-and-tested-by: syzbot+fb347cf82c73a90efcca@syzkaller.appspotmail.com
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
pskrgag authored and gregkh committed Aug 12, 2021
1 parent c03d1a2 commit e95a18d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions net/xfrm/xfrm_user.c
Expand Up @@ -2811,6 +2811,16 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,

err = link->doit(skb, nlh, attrs);

/* We need to free skb allocated in xfrm_alloc_compat() before
* returning from this function, because consume_skb() won't take
* care of frag_list since netlink destructor sets
* sbk->head to NULL. (see netlink_skb_destructor())
*/
if (skb_has_frag_list(skb)) {
kfree_skb(skb_shinfo(skb)->frag_list);
skb_shinfo(skb)->frag_list = NULL;
}

err:
kvfree(nlh64);
return err;
Expand Down

0 comments on commit e95a18d

Please sign in to comment.