Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp748968imm; Thu, 13 Sep 2018 07:12:07 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbcx6+/k2CUtmdQCR+Ly3NrVTuDjOVJvitf6vq7+TdfqOU3YPAYQcraSLbTa24WFZJ5y/uh X-Received: by 2002:a63:5845:: with SMTP id i5-v6mr7397302pgm.272.1536847927217; Thu, 13 Sep 2018 07:12:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847927; cv=none; d=google.com; s=arc-20160816; b=z819YbHELEx4R9xK8sk6CquFhF4xalhfCURl7Fp8LQaqDZVPBS20pyg8kHog81RjGg S+F9lP1aXVigZLpBKr2Q/hgBUZAemg2OcUqeOOIqyNpws8JeqRcCr/w5i6kdRUhgwWTJ rt6fgUVKrhDqDCP/I3YI/pYSEqUxHInKwVP0k/lfwiZC7HHXuz6byLGEjPsddvLVrSFH 4NnSH0krSBSlFPSB0G+iWyQybTB1S7ZmJVToMDg3Kt79F7uEpehB5oMFyNVX05PtowXV x5oHCRyEMOiyp4lOWdvdt4cKa11d8rZxyoKUWzRslRiS/b43mDiv0Ks7RsN5qgUBXEyZ dGsg== 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; bh=GaM79B1oh6aTQKYYMlsTF1snK2+emD2n83XX5efwaoM=; b=UjaLSJtCeroqjPYgJ2quoBpW/NDwHWuLWH9sz+l1rwLpj4Yu/xkfdnFkecqZgUSriN pAFn02oHGLCOp4OI2OoGp/5D2xG62Ps1Yq5fXHNh1yTGUNVK+pTaDqS+U133HyOu78lZ un7mmpRiU0uMOnu4mjFqsz5XKV8mn+vTV9+Nw4wo5ChAveX4/x5GXHbaedvl9aqHqE9E Wd2vylZziS0Ju3o3jQGixImX6r1TTBa9ki0cWnwbBnmlPYGysP7UT1ANC7i0BhEqO0fk bj6WpUO1wz1JPwcEbu4vv5R/E0b6Th9r1oXiUHkmcMdbDcLUvXWVky4TIBBeTrIH6IYM z2WA== ARC-Authentication-Results: i=1; mx.google.com; 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 a13-v6si4290986pgj.495.2018.09.13.07.11.48; Thu, 13 Sep 2018 07:12:07 -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; 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 S1731042AbeIMTEL (ORCPT + 99 others); Thu, 13 Sep 2018 15:04:11 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33866 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728671AbeIMTEL (ORCPT ); Thu, 13 Sep 2018 15:04:11 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E1A11D1B; Thu, 13 Sep 2018 13:54:34 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Borkmann , John Fastabend , Song Liu , Alexei Starovoitov , Sasha Levin Subject: [PATCH 4.18 063/197] bpf, sockmap: fix map elem deletion race with smap_stop_sock Date: Thu, 13 Sep 2018 15:30:12 +0200 Message-Id: <20180913131844.047074315@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@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 166ab6f0a0702fdd4d865ad5090bf3094ed83428 ] The smap_start_sock() and smap_stop_sock() are each protected under the sock->sk_callback_lock from their call-sites except in the case of sock_map_delete_elem() where we drop the old socket from the map slot. This is racy because the same sock could be part of multiple sock maps, so we run smap_stop_sock() in parallel, and given at that point psock->strp_enabled might be true on both CPUs, we might for example wrongly restore the sk->sk_data_ready / sk->sk_write_space. Therefore, hold the sock->sk_callback_lock as well on delete. Looks like 2f857d04601a ("bpf: sockmap, remove STRPARSER map_flags and add multi-map support") had this right, but later on e9db4ef6bf4c ("bpf: sockhash fix omitted bucket lock in sock_close") removed it again from delete leaving this smap_stop_sock() instance unprotected. Fixes: e9db4ef6bf4c ("bpf: sockhash fix omitted bucket lock in sock_close") Signed-off-by: Daniel Borkmann Acked-by: John Fastabend Acked-by: Song Liu Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin 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 @@ -1784,8 +1784,11 @@ static int sock_map_delete_elem(struct b if (!psock) goto out; - if (psock->bpf_parse) + if (psock->bpf_parse) { + write_lock_bh(&sock->sk_callback_lock); smap_stop_sock(psock, sock); + write_unlock_bh(&sock->sk_callback_lock); + } smap_list_map_remove(psock, &stab->sock_map[k]); smap_release_sock(psock, sock); out: