summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Skripkin <paskripkin@gmail.com>2021-06-02 22:26:40 +0300
committerDavid S. Miller <davem@davemloft.net>2021-06-03 14:13:26 -0700
commitc47cc304990a2813995b1a92bbc11d0bb9a19ea9 (patch)
tree434c67f2c3d561623e2de4ab6fdbc7fdb057bc09
parent261ba78cc364ad595cead555a7d2a61471eac165 (diff)
net: kcm: fix memory leak in kcm_sendmsg
Syzbot reported memory leak in kcm_sendmsg()[1]. The problem was in non-freed frag_list in case of error. In the while loop: if (head == skb) skb_shinfo(head)->frag_list = tskb; else skb->next = tskb; frag_list filled with skbs, but nothing was freeing them. backtrace: [<0000000094c02615>] __alloc_skb+0x5e/0x250 net/core/skbuff.c:198 [<00000000e5386cbd>] alloc_skb include/linux/skbuff.h:1083 [inline] [<00000000e5386cbd>] kcm_sendmsg+0x3b6/0xa50 net/kcm/kcmsock.c:967 [1] [<00000000f1613a8a>] sock_sendmsg_nosec net/socket.c:652 [inline] [<00000000f1613a8a>] sock_sendmsg+0x4c/0x60 net/socket.c:672 Reported-and-tested-by: syzbot+b039f5699bd82e1fb011@syzkaller.appspotmail.com Fixes: ab7ac4eb9832 ("kcm: Kernel Connection Multiplexor module") Cc: stable@vger.kernel.org Signed-off-by: Pavel Skripkin <paskripkin@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/kcm/kcmsock.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c
index 6201965bd822..1c572c8daced 100644
--- a/net/kcm/kcmsock.c
+++ b/net/kcm/kcmsock.c
@@ -1066,6 +1066,11 @@ out_error:
goto partial_message;
}
+ if (skb_has_frag_list(head)) {
+ kfree_skb_list(skb_shinfo(head)->frag_list);
+ skb_shinfo(head)->frag_list = NULL;
+ }
+
if (head != kcm->seq_skb)
kfree_skb(head);