From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.linuxfoundation.org ([140.211.169.12]:55746 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389836AbeGTNdL (ORCPT ); Fri, 20 Jul 2018 09:33:11 -0400 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+d464d2c20c717ef5a6a8@syzkaller.appspotmail.com, John Fastabend , Alexei Starovoitov Subject: [PATCH 4.17 080/101] bpf: sockmap, consume_skb in close path Date: Fri, 20 Jul 2018 14:14:26 +0200 Message-Id: <20180720121426.660871694@linuxfoundation.org> In-Reply-To: <20180720121422.837870592@linuxfoundation.org> References: <20180720121422.837870592@linuxfoundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: stable-owner@vger.kernel.org List-ID: 4.17-stable review patch. If anyone has any objections, please let me know. ------------------ From: John Fastabend commit 7ebc14d507b4b55105da8d1a1eda323381529cc7 upstream. Currently, when a sock is closed and the bpf_tcp_close() callback is used we remove memory but do not free the skb. Call consume_skb() if the skb is attached to the buffer. Reported-by: syzbot+d464d2c20c717ef5a6a8@syzkaller.appspotmail.com Fixes: 1aa12bdf1bfb ("bpf: sockmap, add sock close() hook to remove socks") Signed-off-by: John Fastabend Signed-off-by: Alexei Starovoitov Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/sockmap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/kernel/bpf/sockmap.c +++ b/kernel/bpf/sockmap.c @@ -471,7 +471,8 @@ static int free_sg(struct sock *sk, int while (sg[i].length) { free += sg[i].length; sk_mem_uncharge(sk, sg[i].length); - put_page(sg_page(&sg[i])); + if (!md->skb) + put_page(sg_page(&sg[i])); sg[i].length = 0; sg[i].page_link = 0; sg[i].offset = 0; @@ -480,6 +481,8 @@ static int free_sg(struct sock *sk, int if (i == MAX_SKB_FRAGS) i = 0; } + if (md->skb) + consume_skb(md->skb); return free; }