Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp687105ybv; Thu, 13 Feb 2020 07:46:41 -0800 (PST) X-Google-Smtp-Source: APXvYqyca4dW4fZH4qndpWXbimtDzdPgTIWLhIVfwpusBtc79F+N9EtxJOgqG8bzUn9nikfcNcFx X-Received: by 2002:aca:1913:: with SMTP id l19mr3159643oii.47.1581608801696; Thu, 13 Feb 2020 07:46:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581608801; cv=none; d=google.com; s=arc-20160816; b=J4DdkT/oGI9n6n9snyWWAwNXZkM9r/kb4pdmbJZBYCTV2s32pEL2tsW2GdD+IRfZb3 QfqiRhjX9wyyfGVT9W+xYdCRGiUV1PS/gOMk36duuvBYH6bgubA7pUdlwk9I5z+i7icO UAoND6VGSC70lWMArEp3B05cI/xC9ruwfGSHOXL7KxfWRmjufN95s5N+UwaeJd2Rz2wN OYWPjvELXE1mnnFRqQMh6SsTm4GOcKM4/hwMMxGy7au9DbaXz5J9rQTydSrtmNBQRRS4 KWP8Wj8/6HYzKrnQNTIga30cmto8fVozjOzZORFv0CfcmCeRLT7HtZjoMtTJmo9QhCrs pHlw== 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=JfvOpuf63r69ZZYmtgEnUjao7KW2zujtHrfAPNYt/+0=; b=1LNrMtI2zv3y7g+opyFiRNeL0JOOmkXYS5tp2N1pQKNPw+YmUnesOjJx5kckWJrpcg KsOjorpJRVi4Y2lcaD1fN/nHIh0rqDmkc12OL7ysHJ6NryOteldExSH+jvVb/JJSeZJq nTe+d4NzGz8gkNC7oEEwiy4KNjoOLPuHikvZxXafeQBzyACIm3YiuKn1iSOweVEwkr+y tzB9pTnKu4VeSGXJYUl2m56JG07PlzkmbIB5XTSD6J2kypcGUHvPvoDsBzsL0LfVariO dGMVV0nk3iKTnrw0GZtoDPhj5vavSTdObG6j1N73R+AbR+juNIiHxwi6B8W5z/t+D9XC sPZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1lJ5gmJm; 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 r10si1213179otn.241.2020.02.13.07.46.29; Thu, 13 Feb 2020 07:46:41 -0800 (PST) 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=1lJ5gmJm; 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 S2387712AbgBMPqV (ORCPT + 99 others); Thu, 13 Feb 2020 10:46:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:49726 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729354AbgBMP1S (ORCPT ); Thu, 13 Feb 2020 10:27:18 -0500 Received: from localhost (unknown [104.132.1.104]) (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 B7C1720661; Thu, 13 Feb 2020 15:27:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581607636; bh=AzMvOGFeP02uYb2htvlWBAJwij+2RSgKQh/WezhmmP4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1lJ5gmJmRyI0zh+XeYpOAG+hvPTLuI0o987osSdu1EbTspbLxowOI0xDb3BOn5TSY AeS3v7H3aoIvdlbTpLc4clpOvmaGgFeCMJlLlGBrdMv3SLA7GYNvSkWyfqwLOJDihx KSuIR8v7Te7v7SZ6aEmeP62tQrO0gBtgRoF2qcRY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jakub Sitnicki , Daniel Borkmann , John Fastabend Subject: [PATCH 5.4 23/96] bpf, sockhash: Synchronize_rcu before freeing map Date: Thu, 13 Feb 2020 07:20:30 -0800 Message-Id: <20200213151848.153137952@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200213151839.156309910@linuxfoundation.org> References: <20200213151839.156309910@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Jakub Sitnicki commit 0b2dc83906cf1e694e48003eae5df8fa63f76fd9 upstream. We need to have a synchronize_rcu before free'ing the sockhash because any outstanding psock references will have a pointer to the map and when they use it, this could trigger a use after free. This is a sister fix for sockhash, following commit 2bb90e5cc90e ("bpf: sockmap, synchronize_rcu before free'ing map") which addressed sockmap, which comes from a manual audit. Fixes: 604326b41a6fb ("bpf, sockmap: convert to generic sk_msg interface") Signed-off-by: Jakub Sitnicki Signed-off-by: Daniel Borkmann Acked-by: John Fastabend Link: https://lore.kernel.org/bpf/20200206111652.694507-3-jakub@cloudflare.com Signed-off-by: Greg Kroah-Hartman --- net/core/sock_map.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/net/core/sock_map.c +++ b/net/core/sock_map.c @@ -250,6 +250,7 @@ static void sock_map_free(struct bpf_map } raw_spin_unlock_bh(&stab->lock); + /* wait for psock readers accessing its map link */ synchronize_rcu(); bpf_map_area_free(stab->sks); @@ -873,6 +874,9 @@ static void sock_hash_free(struct bpf_ma raw_spin_unlock_bh(&bucket->lock); } + /* wait for psock readers accessing its map link */ + synchronize_rcu(); + bpf_map_area_free(htab->buckets); kfree(htab); }