Skip to content

Commit

Permalink
net: kcm: fix memory leak in kcm_sendmsg
Browse files Browse the repository at this point in the history
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: [email protected]
Fixes: ab7ac4e ("kcm: Kernel Connection Multiplexor module")
Cc: [email protected]
Signed-off-by: Pavel Skripkin <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
pskrgag authored and davem330 committed Jun 3, 2021
1 parent 261ba78 commit c47cc30
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions net/kcm/kcmsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,11 @@ static int kcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
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);

Expand Down

0 comments on commit c47cc30

Please sign in to comment.