Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3942393imm; Mon, 8 Oct 2018 12:03:59 -0700 (PDT) X-Google-Smtp-Source: ACcGV61/ybQVZ2OhtdoIVA/WxM3RuzKcFmIbwtqjpZUDenxwm14P1ygskxY6/m0KkxH8c4CMF0IE X-Received: by 2002:a63:da57:: with SMTP id l23-v6mr22644180pgj.179.1539025439310; Mon, 08 Oct 2018 12:03:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539025439; cv=none; d=google.com; s=arc-20160816; b=gNGyVw0/TJ5iiPbxTMhmEqCMeweX4rSiXC8VevRDrXIuo2kZ79GsRuO+aK5VrDRRGR XmbsoymaSry93dOF7RXJki6ynQC1bqAtlEppf6mgzFsZW7mZqqpdxllxul/mrgzzBQFD O3ih+tnbsKxGS2Hbi2CscIYXXt5C8Q4VSA3bZ465SAoSp2WcL6oPEDCWbwSb9rxnaGtm bukOTW6powuHlRRM4gzLsujAOizZZNCVE6xzLBZRq4bM3hS3rCMByav8ya/2JLFC6OYb IcoVk4bJ8hJk3ySQXau57hXqbf9Vdsh1uLUhhVZPnBJv43rDDX7vHsAYWUg+kuBc1jBl K55A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cMATQD4kpZesI1gn6rXX+jXN6RzOj8pO29vaw4wWQ2g=; b=tC80hmw+e47p55Y/7gSRhNcVnH29x1CKO/+h4jpypVnGst5totaO251wX4kNJPn07w s4u65Mpxy2zalKp6s5Wt0SGXQG3m5JvAlbNvOHOC7M8Ku1SmILgF7cYAglbKSogWkSZ+ ijGobzbsq4wbdxHLXnApwSqkKCt/SpYBuTkq3RZJpb/4Q0P8qdM9OEeokVXH97u2Pbb6 iSkbc7Tjs2JklBQsc5c1jO5MdQNFgovccgFTMZfW/Q/LmLETExl0KS7l6BFkPs4sA8fj zL1FJKuHdIBFsdlCptZtFV9Djmx6ia3BEiE5i5ITZrnhJLCEgQFF4oMCtTNN/vs1cKzl 1MQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P3PxIXV5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h18-v6si18664203pgk.351.2018.10.08.12.03.44; Mon, 08 Oct 2018 12:03:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P3PxIXV5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726928AbeJICPh (ORCPT + 99 others); Mon, 8 Oct 2018 22:15:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:48942 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730752AbeJICAT (ORCPT ); Mon, 8 Oct 2018 22:00:19 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D25D42064A; Mon, 8 Oct 2018 18:47:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024433; bh=IsDN8sYWBRcDbsQfeX5KWlSywER9ggdvEMRJF5Q48k4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P3PxIXV5614JMlHLAaMJwm+Fjm/A4hQEHW1gG0cr9Gxil29yQCsxlAIhzCFrWwns7 PTy8oE3YdEfZpUwE5brjj+e4pB9niQSUZ7ED3SxuD3MdZ2s7M2S4FzbPQTJkWH0L+x 3XNrP/ZAiarYT7xy44IOIgHJHm5+QZlyeb36aue4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Borkmann , John Fastabend , Alexei Starovoitov , Sasha Levin Subject: [PATCH 4.18 013/168] bpf, sockmap: fix psock refcount leak in bpf_tcp_recvmsg Date: Mon, 8 Oct 2018 20:29:53 +0200 Message-Id: <20181008175620.542501811@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175620.043587728@linuxfoundation.org> References: <20181008175620.043587728@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Daniel Borkmann [ Upstream commit 15c480efab01197c965ce0562a43ffedd852b8f9 ] In bpf_tcp_recvmsg() we first took a reference on the psock, however once we find that there are skbs in the normal socket's receive queue we return with processing them through tcp_recvmsg(). Problem is that we leak the taken reference on the psock in that path. Given we don't really do anything with the psock at this point, move the skb_queue_empty() test before we fetch the psock to fix this case. Fixes: 8934ce2fd081 ("bpf: sockmap redirect ingress support") Signed-off-by: Daniel Borkmann Acked-by: John Fastabend Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/sockmap.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) --- a/kernel/bpf/sockmap.c +++ b/kernel/bpf/sockmap.c @@ -915,6 +915,8 @@ static int bpf_tcp_recvmsg(struct sock * if (unlikely(flags & MSG_ERRQUEUE)) return inet_recv_error(sk, msg, len, addr_len); + if (!skb_queue_empty(&sk->sk_receive_queue)) + return tcp_recvmsg(sk, msg, len, nonblock, flags, addr_len); rcu_read_lock(); psock = smap_psock_sk(sk); @@ -925,9 +927,6 @@ static int bpf_tcp_recvmsg(struct sock * goto out; rcu_read_unlock(); - if (!skb_queue_empty(&sk->sk_receive_queue)) - return tcp_recvmsg(sk, msg, len, nonblock, flags, addr_len); - lock_sock(sk); bytes_ready: while (copied != len) {