Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2363528lqp; Sun, 24 Mar 2024 15:54:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUNcQmhLWvMcBd90PascA70ifG+nupMR/D9V6IimIkpvfF0f845MRqYXL/Ou4TBE1FVqo7yUTlmFDuuHI5QwgPxTkkhSzSDpjS9QF9Bhw== X-Google-Smtp-Source: AGHT+IFkmLOu4cZP4QMJiUuE2wrcKY1QfddeW6ySuuoyzB45YOz6dCuSJk0yMVtxeg2E3bSuziiQ X-Received: by 2002:a17:902:cf0f:b0:1e0:c5e6:c5af with SMTP id i15-20020a170902cf0f00b001e0c5e6c5afmr224591plg.55.1711320883074; Sun, 24 Mar 2024 15:54:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711320883; cv=pass; d=google.com; s=arc-20160816; b=MspGK2DeNMlKO0crvlds8WrZCYWMukQ2T7VmGn5xfac9/FQfUmFJ+jVHStPb/FEtad hBuzr931ZOIN7J84H7IrQGv3p8JiZAS/q6L1Abhk7oHKwhdQB2MthJ2OCywvYpY1I1Ie Z3Z67gVa6+YHh1LG7JkLvoSCMmsZHr4LYKsCZ8EYTzJLSVmMABb+WHkeE16z/BB+ovze IGmpQJj3bPe3pJh1qCGksCZbQN+bSJrZ1p3KrMyDW6yhIjB5ebnnrxl2JNafHTbuHCQC 5tFgHbDKpmc5GGR4s2RF31AwY5XMsmi3CuMfyl3BwgsThfr9kAj4yACGAfZv2hrfVwP7 7ksA== 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=LlclplrpaeTMXELZVvYnmHJx+zwWUKi8UcPlB9UGju4=; fh=OCnjtxDsSZ8V3tgsCeD/qBHH2lF+rmGkEECi+7bMGds=; b=CQ7zTyjoailR69/bXSBM/OSf5FCD3tg/unvJblFXS3DgXzgUFoTPWgMjtIX8tA7SGZ ORYwa3qh7vtPG6Op49yklvfWfDXYKoNFWGiO1vqQlbxTKZH7e50cYqv7N7/qWF3k/cTi OxrAOcUzqHh5QD/QdTsduEaNyr2C4zuly9y3y2Z0lrs/5kbjy+5iuZognAv6RymvPhap z4wfopQQ9AllF+FX18H9gW8hJHu60SEf0odxd5Rha1aMQnUJB7aeejCtTRR6ofEMG0wE OZ9hyzjZpNNlg971z3fG5EQeOroaJc07JA3zhgpMhvnC4A2xqENMPBbTBmVzhhu8uaXU Mf8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Y2ZyWgqa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112969-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112969-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e12-20020a170902b78c00b001ddda28e5cdsi3849937pls.402.2024.03.24.15.54.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 15:54:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112969-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Y2ZyWgqa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112969-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112969-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id ABEBF281609 for ; Sun, 24 Mar 2024 22:54:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 129B7129A96; Sun, 24 Mar 2024 22:36:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Y2ZyWgqa" 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 2B002129A7D; Sun, 24 Mar 2024 22:36:21 +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=1711319781; cv=none; b=WR3p9FcpXqeNDeubCkiXPqa7OVcXdbEavC2OpifJ7UAzAEI4cRL9qdfuLWv7uMkTgZXDhUVHO/HT6+i+1aeglF2kH/IT2b7yry7vGIAdCuloVnhvAapHgGib/njYvqlnhs5ZDWyVwwMofEUkHV9GkIbZKDhUTFriBtMTK2Kuy9M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319781; c=relaxed/simple; bh=06FpT3mRKSJTpgTZHFDze+IrA6YW+8cePTPaBKN39AE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kedkT3XB1DpRtXqTWdcoz+Oc1rNDbas6IgUBDs8onNP1bwOn+G5qSvGD77/OLbESlpVOWOiGAgTc0b5MZrqUtObA6pnM5qoXKYt7G1JzFVv3Zd9h1ejWw8KSzqZiVdOUVAXwAAhJ19rvOr6MJI/A2RO01u5oDrbh7aU1dIB3vuE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Y2ZyWgqa; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2763EC433C7; Sun, 24 Mar 2024 22:36:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711319781; bh=06FpT3mRKSJTpgTZHFDze+IrA6YW+8cePTPaBKN39AE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y2ZyWgqazo7hKazo4zZ2y32RDv5fd1BkQgm2Wm5cny98oZ6LQkrbFwIQfPeJ+BrSR /+6q2THE5S/+wyJs/OOLTD06ohlxcv1vrFArNHczBbVOCCu59dQ4s2u7GC85/e8TP2 YYrdX+eVGu/Avio95wUyyi0PdFP1i5xhcZTukG562vmCy0EmoYbaJ5lrvi/5eYEdzj L0LD+jkcQG+NfgbRDe668Eb7bRjRZzwRlltiibguqeS4s/XVn0THxo4i+uB1lYNWWb 1oCgbiI0kAwIWBXbuTXf+LAIIl7bg9rC2nGtkL/zUhLfZRDiwCL1M9BKzgRSoQSq4B +Y1LSGHWtp73w== 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.8 082/715] inet_diag: annotate data-races around inet_diag_table[] Date: Sun, 24 Mar 2024 18:24:21 -0400 Message-ID: <20240324223455.1342824-83-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-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 8e6b6aa0579e1..9804e9608a5a0 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); @@ -1503,7 +1503,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); @@ -1520,7 +1520,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