From patchwork Fri Feb 21 07:37:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 230611 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C57C8C35641 for ; Fri, 21 Feb 2020 08:47:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 92E7C2071E for ; Fri, 21 Feb 2020 08:47:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582274873; bh=6GnYNQpX3kRlCJgr37H2+nzeqECSZmwoGPWyPnE+dIw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=xWU2jBhv8DCgUzQ/RjV8FX+HUT1VOZXv0yWkh/NIYSPuZhC9s40sPXpQuZtTx0CLR 9gReOAmoQew1wcDg2CcU37GrS28VTZXEVukw7oBHj6xfVMX32KbyI+8qLgd4S7KJ3i ez/CHz6KIW1wtkp4uoIkaW0unmh81EWJeXxengqM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729171AbgBUIrx (ORCPT ); Fri, 21 Feb 2020 03:47:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:43878 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728412AbgBUHrz (ORCPT ); Fri, 21 Feb 2020 02:47:55 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 907D620801; Fri, 21 Feb 2020 07:47:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582271275; bh=6GnYNQpX3kRlCJgr37H2+nzeqECSZmwoGPWyPnE+dIw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IlCrIQnawFLsRchAoN4YzZLmgBaqc9J3ZkQDv2IQQCQKiiKQNFW8m+u8lXRSZexnn EhyMWOLrEp00PQ70IhezmL7RbYARUfJd1g6demMxrSJpQphGs4A9NZTSo+Z8eUVssp q+SSaqsdhhZp9OzmsMGs4sfkqC5mNvvHZldC4KTk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jakub Sitnicki , Daniel Borkmann , John Fastabend , Sasha Levin Subject: [PATCH 5.5 103/399] bpf, sockhash: Synchronize_rcu before freeing map Date: Fri, 21 Feb 2020 08:37:08 +0100 Message-Id: <20200221072412.438200611@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072402.315346745@linuxfoundation.org> References: <20200221072402.315346745@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jakub Sitnicki [ Upstream commit 0b2dc83906cf1e694e48003eae5df8fa63f76fd9 ] 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: Sasha Levin --- net/core/sock_map.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/core/sock_map.c b/net/core/sock_map.c index 085cef5857bbf..405397801bb07 100644 --- a/net/core/sock_map.c +++ b/net/core/sock_map.c @@ -881,6 +881,9 @@ static void sock_hash_free(struct bpf_map *map) /* wait for psock readers accessing its map link */ synchronize_rcu(); + /* wait for psock readers accessing its map link */ + synchronize_rcu(); + bpf_map_area_free(htab->buckets); kfree(htab); }