Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2525762lqp; Mon, 25 Mar 2024 01:08:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX+FVzC/Bb3qnFiPwxySSL59zS6z9npOf98VldvpYIu6tGxU4zI/KrjJZ62fEZViirpOcqiKbvul+i7a7YqzzqNFMtgYMGhcJiAK+Chvg== X-Google-Smtp-Source: AGHT+IFXg49IwoRLpW5uvz2z616HACCQM3PnXbHyuforwHsOR1xZE1Yt8ZRTFoeoQyG2Mhkk/OhU X-Received: by 2002:a05:6214:509e:b0:696:9340:44b9 with SMTP id kk30-20020a056214509e00b00696934044b9mr721499qvb.56.1711354120233; Mon, 25 Mar 2024 01:08:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711354120; cv=pass; d=google.com; s=arc-20160816; b=wKNj4DptYGrHkfqSoO87W5mUY1db1feAU0H8F23js87M+efuntf+oD8/GTgXq8LsU8 dBqznZ36OrtsuBOAukuYWY7Ku2+TlGtiKS0OdAXkLcj+4PYjjHWaJH3apKt6m94PCf2z tDKFI7IVft2SppZdaHOsJNQQE2xMQBROE9vRCHnRKjnGG5nhKzdkx4al6gTgs5TJQyEr CeBNn6/HCeZKNbGE2B70/qiml65Ht1D0noaUO22zEKcj6povjrpT5Co/20Zf8IGlMffG YimOZdOwDsu63kV6hsOz5gWzhioqNGbPfob4BCBLuyIZhPu+GqgZUN5mvhIkHvqVj2CI 75tw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=sCI4RPAL7sWCmAiqusTxHpKeDYW4qjjdxP8OC2COqCk=; fh=OCnjtxDsSZ8V3tgsCeD/qBHH2lF+rmGkEECi+7bMGds=; b=MH4LHQhPKZZ8iDubFB943A5i5KrMmZL5XOFL/MLrMYXlJGW2Uj9x/zuSvkWrn29q/B /WZtSuYz0c8Uk6XEEhWjAReuRYlBAN6E5g9G2frTjsEql4c+vefWFAJN1rstqp43ygT5 qJq31F/hI7Im5IGYmf1bvYBiJEN4Z3PdPe8xFnSf8RRDPa++rCIjHzse99+Hxiic4v7o Mv6HeNA7+WEdWshM8gMEyk4O/F7dhOp96z5AON2UjndR61plMypsIiznjCqCJP1bigRF KS4v6pAA+2cIfL1/uDNu/uM2FkZQmZS/SSkoxyIEOaRZqX1U6Td5B0mLF07EiLB2ya/d amxw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qIXbUngG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115869-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115869-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id iw7-20020a0562140f2700b00696930639e4si486623qvb.27.2024.03.25.01.08.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 01:08:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115869-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qIXbUngG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115869-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115869-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id EBDA51C2DA3A for ; Mon, 25 Mar 2024 08:08:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E052159206; Mon, 25 Mar 2024 03:02:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qIXbUngG" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71D2F145B29; Sun, 24 Mar 2024 23:13:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322027; cv=none; b=d5UOMhFE4HRALpAYoKiOHtaBzN+oVixvkbtaGV3ma+0w6sycGRpEwSnI/CQRCVdAzAEH0CkKWfDfVcNb34SrIo2yGnytsDZ/XAuU+MUiGzWFl3xfwl8+Pl6HJ6BklvbAaHdfvwvk8LG88RPeFRXYxk+Dc+Ete6EVe4Gqr2IofcM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322027; c=relaxed/simple; bh=40v7DOVjA7rwg/GnBHyYenR1x2eP7t8SduFzhGeItWo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pRPGAytlArRwP7lUoGNGU1xjXhqDrO80Ipv11jEYOF1nhC68U1PQ6jZGMnoNQ8cllL1K+rpEryJMeCg/3354iOHkZiJ/3sCZQQXA2qjmAH2K7z+4xtsBqtdbIPl/7qP1OGETSF3js+TFB8DoLUZHqAFXa2kmwSo/6jty6XkzRks= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qIXbUngG; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E06BC433C7; Sun, 24 Mar 2024 23:13:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711322027; bh=40v7DOVjA7rwg/GnBHyYenR1x2eP7t8SduFzhGeItWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qIXbUngGbW4KWtWfvxOlMA5cyS0ZYemSj953Cnr5V3Xdih7eQFUjgMdpoz+k376Bn zxw6I1W9yYoo3YHL8i2O+dgZncklbG/hP7UEqBLTj92xhH4pxrtpIIN1AWlO8SSdtv sGCZoW4nKSYVz7bjBS3692o/c0YXbOI9ECf64UTA5e9KTMDREFryX2raKHRWxU2tsQ aOqA457jGQ0QNjsDVkPOJ0Qd2x3dXfzhIkFYCa1o6fB0mhOJwPLPdNg2ixT7Jt446X itYsIPKarfeARR0paCsGiRbtSaYimkSnfWpsMRWWjVRJNRQb5VsAHGWSNpZtLaaTfJ 8wWd4sIVCdbgQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Eric Dumazet , Guillaume Nault , Kuniyuki Iwashima , Willem de Bruijn , Paolo Abeni , Sasha Levin Subject: [PATCH 6.1 099/451] inet_diag: annotate data-races around inet_diag_table[] Date: Sun, 24 Mar 2024 19:06:15 -0400 Message-ID: <20240324231207.1351418-100-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Eric Dumazet [ Upstream commit e50e10ae5d81ddb41547114bfdc5edc04422f082 ] inet_diag_lock_handler() reads inet_diag_table[proto] locklessly. Use READ_ONCE()/WRITE_ONCE() annotations to avoid potential issues. Fixes: d523a328fb02 ("[INET]: Fix inet_diag dead-lock regression") Signed-off-by: Eric Dumazet Reviewed-by: Guillaume Nault Reviewed-by: Kuniyuki Iwashima Reviewed-by: Willem de Bruijn Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- net/ipv4/inet_diag.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c index f7426926a1041..8f690a6e61baa 100644 --- a/net/ipv4/inet_diag.c +++ b/net/ipv4/inet_diag.c @@ -57,7 +57,7 @@ static const struct inet_diag_handler *inet_diag_lock_handler(int proto) return ERR_PTR(-ENOENT); } - if (!inet_diag_table[proto]) + if (!READ_ONCE(inet_diag_table[proto])) sock_load_diag_module(AF_INET, proto); mutex_lock(&inet_diag_table_mutex); @@ -1419,7 +1419,7 @@ int inet_diag_register(const struct inet_diag_handler *h) mutex_lock(&inet_diag_table_mutex); err = -EEXIST; if (!inet_diag_table[type]) { - inet_diag_table[type] = h; + WRITE_ONCE(inet_diag_table[type], h); err = 0; } mutex_unlock(&inet_diag_table_mutex); @@ -1436,7 +1436,7 @@ void inet_diag_unregister(const struct inet_diag_handler *h) return; mutex_lock(&inet_diag_table_mutex); - inet_diag_table[type] = NULL; + WRITE_ONCE(inet_diag_table[type], NULL); mutex_unlock(&inet_diag_table_mutex); } EXPORT_SYMBOL_GPL(inet_diag_unregister); -- 2.43.0