Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2086298lqb; Mon, 27 May 2024 07:28:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVcBEkZjyg+NBSpppKgoLFqmKp3nKj3tePQvEL4ICS6X2jRpBfchot4CenBXTioMp771kc64nclbgux8dZ4bogWoBlc7WTlW9aYJTWAUA== X-Google-Smtp-Source: AGHT+IFI9ei1zmy2lneGJnbuVvLNryBG3/NZ1L2nASpoMrdBFi5b4NTX0X/m74iRqqS6JI2Ou/Jy X-Received: by 2002:a05:6358:480b:b0:18e:3ec:94cb with SMTP id e5c5f4694b2df-197e5114f9emr1195014555d.14.1716820090103; Mon, 27 May 2024 07:28:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716820090; cv=pass; d=google.com; s=arc-20160816; b=jnzOAPnIvuKQrEeQLD7VTOgtskin5ZcyFG3sPN6S+cv1V8VX9WzJ0TheEFyWyffFE8 6TKMQPkGNAkKdVYQFeAMNeXlIj5Ug+/dSjTvJKXjFAaJhy1mJRrAwyI0Tgo1Ct7ED9oV FudZJjm+E32su+wG8OiQDxvZ9EPhp49FsMPAPRX61vTQVm0TmDdKkXjMrS6HTYELwmRz EhI27ldmTLmmGKhMVWE+0r04Z5OrgQT2alJyGufKt32aKF0H5sOabDsGsLhOhuygZi4P BS2GaDn1lANHQMDAlWeQToYG/YAlFmL+zU0rK5Xm9baA8Xjxnp/2O6E8cetG1HHlWP/k R2vg== 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=4CJZYqLaxluSJVAdYWQh/teGueKyU+yF2peHz5EvsPM=; fh=eFajrIIJxmS8NRCcJqYNNX8yhPjOyZPneAswItKXPhg=; b=S8/MhTtOYZ/L+pVgXoAcRehHLRz54Jtl6cBg0KttBDiJsFMQeIJdEp2LW/SQgTgKaq bI3r8J7mhE+EWCqAqEzK4DEbQTOAZdP8BCbYhTNEBHe5oFqebU0H3qdaItBLdSVvjxe8 8LF+ZvnkPELDU3Mgganvyq6tbwvb3WBTWMfxFE2hon70WMsTusDD8q699rjlaj08nb2F CrhxCHNJbzUMLH19ltt4azP0UiqNDNBeXflFxLwPBpKszIY66lHl67NY3HalEyUOoKsi Qo/a26RpK9tTHqojF/9Xl+c+AGAs029P8J8qlpWsXI3GCRGSxUZAVg0xtRyqgKuIHADz a8DQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mUJFDVrN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190857-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190857-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 41be03b00d2f7-6822789040asi6424349a12.399.2024.05.27.07.28.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 07:28:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190857-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=mUJFDVrN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190857-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190857-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 53CAD2A57B1 for ; Mon, 27 May 2024 14:27:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A9CA15DBBC; Mon, 27 May 2024 14:15:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mUJFDVrN" 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 95F6E17B4F2; Mon, 27 May 2024 14:15:03 +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=1716819303; cv=none; b=iV+Q9iCr62ggnNptq+zmY9QaHlzQTtcjBj+8IEsZ94PYjrRVQ6vv/pADArKEckk0hbQb3sPyKK9NYh91M7rgB3zU5+e4IN2TAciBaQZU79PWgdZXmHyD/9dEU5HmLzu4Nb/AfjjBUgqLnJKWdusuTZsLPsckXKHYGbqIS/C35Uw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819303; c=relaxed/simple; bh=gT3PUxRsUL+n6n4zrXENoJgzxNiIqZwJ8cCv7JfCF08=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=smXf2uCXh1SpxA7k67y53UVRELoBxdnd7ny1Ssd7ADrYSKwctG9Fq9graoqVL1/D1yO74fMr361fdeLuOG70zsf7jDJgsYbWmRZAoHwzgxWE4WOWExoYAMvpvySgXKXwwbTFHfyirshilrf0+1L9HEOPR4I1atZT/iMrt9KsG7k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mUJFDVrN; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31FD0C32789; Mon, 27 May 2024 14:15:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716819303; bh=gT3PUxRsUL+n6n4zrXENoJgzxNiIqZwJ8cCv7JfCF08=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mUJFDVrNCYigR27WJdnT76yFkGu1BMwGeTW48jwEr/29CBpRm4zcXKTUk4XzHP5cQ xTH8MqO65FyDlrhqAHnO3u5bHraDZ2BRJg/oeCcG0hOlb4/ia2dhANs8Yfp7o1gnGb dxvCVisbB0VmjncLpCQJ5TFi3IcyhcKE28g8yLupDPhUnAUZEXP3yu08Qzxibm+y41 AWpU0FAjj0UTh4R1LSDgZMSCOOQ6MT/+RQUpvgLdy5FsHwKQ7aRblVS6hknLJc2p+b x5Gd8xG2pK/+AT6/If1vlEUxFGAak8vUTbJ5hLlNZd1Hd5DJLVB62TwRD7gpPAN7s2 Ioi2ycWZXjfZQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Breno Leitao , Jakub Kicinski , Sasha Levin , davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 6.8 21/30] netpoll: Fix race condition in netpoll_owner_active Date: Mon, 27 May 2024 10:13:30 -0400 Message-ID: <20240527141406.3852821-21-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240527141406.3852821-1-sashal@kernel.org> References: <20240527141406.3852821-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 X-stable-base: Linux 6.8.11 Content-Transfer-Encoding: 8bit From: Breno Leitao [ Upstream commit c2e6a872bde9912f1a7579639c5ca3adf1003916 ] KCSAN detected a race condition in netpoll: BUG: KCSAN: data-race in net_rx_action / netpoll_send_skb write (marked) to 0xffff8881164168b0 of 4 bytes by interrupt on cpu 10: net_rx_action (./include/linux/netpoll.h:90 net/core/dev.c:6712 net/core/dev.c:6822) read to 0xffff8881164168b0 of 4 bytes by task 1 on cpu 2: netpoll_send_skb (net/core/netpoll.c:319 net/core/netpoll.c:345 net/core/netpoll.c:393) netpoll_send_udp (net/core/netpoll.c:?) value changed: 0x0000000a -> 0xffffffff This happens because netpoll_owner_active() needs to check if the current CPU is the owner of the lock, touching napi->poll_owner non atomically. The ->poll_owner field contains the current CPU holding the lock. Use an atomic read to check if the poll owner is the current CPU. Signed-off-by: Breno Leitao Link: https://lore.kernel.org/r/20240429100437.3487432-1-leitao@debian.org Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/core/netpoll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/netpoll.c b/net/core/netpoll.c index 543007f159f99..55bcacf67df3b 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -316,7 +316,7 @@ static int netpoll_owner_active(struct net_device *dev) struct napi_struct *napi; list_for_each_entry_rcu(napi, &dev->napi_list, dev_list) { - if (napi->poll_owner == smp_processor_id()) + if (READ_ONCE(napi->poll_owner) == smp_processor_id()) return 1; } return 0; -- 2.43.0