Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2592338lqp; Mon, 25 Mar 2024 03:53:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUvXpQ/ju6rYKUwpr/OO5Qcy1iahnDyvTCVOrijxVXDh8SoRjEXMOk302tNuIJ8RkxIwJaKXAOhl8CzRwHDq71invLrSKG3VLKkp7bACA== X-Google-Smtp-Source: AGHT+IH9fkwatVYUMpXfKoA5Tigi66ArjUHn6LLDqygCHTtKoOXkHOiZYa0KP1LjokIQ8znRhrmB X-Received: by 2002:a50:c309:0:b0:56b:a91c:65a4 with SMTP id a9-20020a50c309000000b0056ba91c65a4mr4814559edb.7.1711364021373; Mon, 25 Mar 2024 03:53:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711364021; cv=pass; d=google.com; s=arc-20160816; b=OHlQuARe1yUzBIjEQj4AR4WqLI/ElPGvL/k6ClHEdMykGY9NbAKi1Z7EMHoClkmGgd Meu1vrReU1+jK8YMK3Ne8dArVR4E1+dHLHkTqaPI2657PgRQRhU0W/yJOhLycZmuhNur Z/aXa3ZFjeXxbkfkj0Jd3BV1xgSdgBEWVdrcIjcBNC8WXF8KusDSShL4rZ9VtdrtCRtv fgHHvUDSiE0Lz19uG5plTC7qxeT0XADDGkuN/BfLqva1Moxj6IYsZ+Nfe4SpC12RpfK4 5WSO8VuCoDTDFQr2+YbC8aFbmbXWsJBiQ3xMDbV5lsN37WUMtExIZqIb+fBTTvsG4B/v 9kjQ== 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=Px5PtwOD8SqGAKEUr0Z1NnKeTTYIPqnyP+GMKjkGYMU=; fh=OCnjtxDsSZ8V3tgsCeD/qBHH2lF+rmGkEECi+7bMGds=; b=0X2w5gdqHFhrYf1jMHRjIIQS1AA195xbsRucgJZlVK4Ip7rP8NaR2P3i5XgJM1X2NB yHauHwGQuS0doGjbMQTKDn7Nomo8sF1g3GIIoB7AHXo4qeNKl4TjgIdJIU/4XtQrlgL/ hkMo4QZIXpV3PRIkK/QdYp007WGwfBxPD5jMsBLYUzsLnha8zU8Q70ceLWfhHWLcqbMI EmVdh/DspHwXcc+vcl2KmCUipdLfHP/WZ9k6j/9jmi4cd3litQIuFCr/mOR3ta9U1sBt znXc4AXVdt2G6BVTFC5ppI78qd0M1ti6OpkxsY8DjT54z4ivyZD8th1k4Ui6ZKGKjxoE PU8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BljaAypH; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115413-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115413-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id fd20-20020a056402389400b0056bf2d405b6si2490190edb.31.2024.03.25.03.53.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 03:53:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115413-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BljaAypH; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115413-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115413-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 3B2791F2E6BE for ; Mon, 25 Mar 2024 10:52:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E5702057D4; Mon, 25 Mar 2024 02:36:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BljaAypH" 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 22659142E8B; Sun, 24 Mar 2024 22:49:51 +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=1711320593; cv=none; b=NiCeGrDi5rmxpfpnXWbToZjzoDCWNuaObfggEkpzzsti8QgEHDNd9ctqu14qYc5cgF0e9WPGhEdUaF1tS/posf6hKjPWp0X7ChT1lkXx6xMs4Xa7MeQoKnURhL0MAb3zpfLglsag1G9sOVdnnMOePat/sU7vhkfgliu9AB8Ge20= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320593; c=relaxed/simple; bh=0+48isTzNvrmKnyqjubuz+hXbpcC9TAg3X50SmYHahw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QayZ1/zyAPfXMWuw2Trnbp8E5HUYfLQGyNH/zTLd9kc9Ihe6CjoJKR5Q9WyoiYJWppJfidV0EMATx1K+FQeMxQIFhGXSlFJ0Y43grtjSJoXheHynCGJrIQdmMgax/lJodJHrSupoetmw9FXtFRgYaj7V49SPCcr/5IDYLoh2RYs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BljaAypH; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DDB6EC433F1; Sun, 24 Mar 2024 22:49:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320591; bh=0+48isTzNvrmKnyqjubuz+hXbpcC9TAg3X50SmYHahw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BljaAypH48eKhFHrIntztfUIYbuX6F0MkO4omcAwqUe8cErRTG/p/EHD13IUzwniO 8nVHFjuVYqdS8NII+hcG+FPI5a8whMyDyoEgTQLPbOUV9cPcFtD6TDBA8JAzdaziJL GEdmiOmoUIuJw/U5A8U589xQGV0F7banO01K6BIkc+5gC6SZx0ypOmfYi6W9gDe2yk kYj1bBrrpt55sEDzS7/X1nhhZfj0/LaxLCwULS+0/AOqZvDsQuoutVBeyTJnp7h1Ab 4FyigRLXxU37OSYqgk28J2vh+aIF6Cvo5ZRqLL+deJqdUKabzfZvOnxjkbM8RY5OPX GpzV+J61uHymQ== 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.7 153/713] inet_diag: annotate data-races around inet_diag_table[] Date: Sun, 24 Mar 2024 18:37:59 -0400 Message-ID: <20240324224720.1345309-154-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324224720.1345309-1-sashal@kernel.org> References: <20240324224720.1345309-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 7d0e7aaa71e0a..5f7fdbd01cf9b 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