Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2575176lqp; Mon, 25 Mar 2024 03:12:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX2QiL003U+BIyV5aIEd69lapzz436c+CckgHAJT9Vxro602HuskM0qMnWcO6AOaWqVh5JzOKlRPIiA7GIH4HS5Jva+WZDR1dROdyjf6A== X-Google-Smtp-Source: AGHT+IGnI6R3gMAl7xYw5PYXOh7n6EecP7bfymc5inYuZLz6hkx3My3iBaw2T+fV19+4pisDorwt X-Received: by 2002:a50:d7d1:0:b0:566:f81:41a1 with SMTP id m17-20020a50d7d1000000b005660f8141a1mr4722788edj.22.1711361526647; Mon, 25 Mar 2024 03:12:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711361526; cv=pass; d=google.com; s=arc-20160816; b=cnodjz/vLiVAB2JCzrZzOE2+W8aHe8xFFZIq2JQAUlRwG+TOwM8NY+CZz9to3SKQsS zA0+AmQB8kS2bgFrd/LVKXiQ0zKkG4aiO/ippThuYdPNoAous8g2mitz1+tXDOHeN4nS +Iml0dkebH5COlX0jScx7UbiolzH+ce7f7HrlBCs10uyyGAL4746TX+hU1kdaHay+scC GD/FIMCTce/w4pd+qhn5F33FpzLeyivm3/ZQF/5es8RfCzybQwHej4DxJxakGoHl7qOF gEi+6+2pUCHhO5SmTR0iKPqdLNjngEFsh0jaIp2OJq3cSRtYWqtOUF0+nNE3t5gYF6rL 1cQw== 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=FQ211vu2w8dlMqzymYvSd8xPOFVJoPmCd/Ka5ziAMmE=; fh=OCnjtxDsSZ8V3tgsCeD/qBHH2lF+rmGkEECi+7bMGds=; b=dPDJkDpkxw/sl2NAR4EBcze4xUFICbm2cmxy+nbtIuIVCQkEPEQA5dF48RhwYHeA5G 8r9j2AFFtM0XPlnQouYA0OCmMNxjj0qerVN6tc36bSLmkBUdt5ZEydFqevXrW/aj+c4M Y+VAA85Io7DPkV6k+gy/vsNb8NVLznbE0nM0sLoJWkLrfgGZbrZi1T5oz5c1rdqrNnw0 fY4XDa4DMCriuQFaALXQzf8dbQZvXKeCKt113THmqz/Ssj7+7z5DT9Ff+3BVcJhPOd2N EREJqXbY4RpbH/fv7z4vO0TuIJkxaWkqdIswRC7udmrSTwBx9opucoshuUmlhrDDHu5y QIUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U6YDQhwv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-116136-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116136-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. [147.75.80.249]) by mx.google.com with ESMTPS id d13-20020a056402400d00b0056c0875fa5fsi1308765eda.20.2024.03.25.03.12.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 03:12:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116136-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U6YDQhwv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-116136-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116136-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 4EF4E1F22752 for ; Mon, 25 Mar 2024 10:12:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B43A3AF2DA; Mon, 25 Mar 2024 03:32:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="U6YDQhwv" 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 4F98A2811DC; Sun, 24 Mar 2024 23:41:20 +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=1711323680; cv=none; b=LiRYPfXdPKSmZ6WRFiBo+de2trfMwG/3D0xvqMiT4IHKgWCBrh9EWE/4DiDkgZ+Pvnon6ItVfHA1mludFSilopTcNBjkPap+8eonGEhyLzgHyum21p5nIJZnBQK9XwJbt0iJ2XE1dxz9dxXmXo8B9A2Uxw1DJ3LN5H1vJ6HBi5o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711323680; c=relaxed/simple; bh=6m+hw0ytwK8q3A+8x1/O6dFDlxarc7SQSSmQSXbygAM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dAiDapxYRHykxgbaDicJM2yxwzrShV6TK05ibI4jHvzxRkvsFWGas3NQ2TpCv+4qv9PEHGFJJKWHKMPxpLrGtKnQTOEdlJrHH4m7PmFnYjcIS46fWaiwDkohloHBcQAae4h+JHq/h2aHj9AOi1slkkTF6FRcmT2c1LUCTc3oV+c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U6YDQhwv; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46D4FC43390; Sun, 24 Mar 2024 23:41:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711323680; bh=6m+hw0ytwK8q3A+8x1/O6dFDlxarc7SQSSmQSXbygAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U6YDQhwvcC+68Tf87qV1KYAWdKjkFx85pm4lN1QGizsmpuApoZGKG6wTMR5eA6QeO E/yCd2YWCeCSduLqB5Q6be5VWaiVwZlVoo8NyPtNeEiRy33qEOQKJM0g7qvkBtkeJE M/xGW5FMU4TvjsGNzYfZILlqhWa5Uyxh+zFLGvAJUNJGZ4TTozMLDL7Bmtkj8c0KMk 3PZ8n8ja/BqF6iMO+PFd85O+400G9bIORyn9lMwdGFjV+EAGOkEaPK0gQm5xgTqjpz I9EhT1zZEUQQnSZ05WS28nup1yCS+iPfd/VI5ajWpwQuG06D1kH+mEpPJZ2/+fE/+M KzozOTKl/PiPg== 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 5.10 052/238] inet_diag: annotate data-races around inet_diag_table[] Date: Sun, 24 Mar 2024 19:37:20 -0400 Message-ID: <20240324234027.1354210-53-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324234027.1354210-1-sashal@kernel.org> References: <20240324234027.1354210-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 fa9f1de58df46..27a5a7d66d184 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); @@ -1413,7 +1413,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); @@ -1430,7 +1430,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