Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1253077lqa; Mon, 29 Apr 2024 03:04:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXKmTVLnQMm+8vC2AlcaZbR9lVDYHAFn+2uhArz6tviluciAHihcyiIfWPOs5cadU7YxHS0KcylAXftyP4IUHxZYS9F2QhjF1ey+nY+3w== X-Google-Smtp-Source: AGHT+IG+ZeNB6P+NhQmEK6/aLWJr8EuR86s0Dd+UF85Etmw5+aVzBSPbLJeqNERCk0ogA4jCHXv3 X-Received: by 2002:a05:6830:1106:b0:6eb:7e60:6028 with SMTP id w6-20020a056830110600b006eb7e606028mr6883800otq.30.1714385094756; Mon, 29 Apr 2024 03:04:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714385094; cv=pass; d=google.com; s=arc-20160816; b=ya3aztvuJuiaLiEijLhrSizMRLK8HNnbpgrSiWXg4uLi6qpXFW6jjtGVbtYBwX3I/D Y8j5NIF2s/2baNACf/ENOLddr5EcjmpO/69Sm6is6Db5swKFGK3hG6lOr5aOi3N65bxa oQ8d1k1SsODMgvRpFN9GQP6ATh85dnomCOlLuGu0F5pM3pYauDA0LuOpUe2l9rz25pzf BZ2F9Tb0qr06cb6YxFazQG1l+FODPhpSOJs5FlIgM1YVx20xeTGqsA5fg3VMWWEImNVt G7UcKpUCjyFMrCfekJVzaCvhngRd61sl6cDoUzzaRkJdXt/IcK8zlS/ON8Ml7LGvj7bM V4Hg== 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:message-id:date:subject:cc:to :from; bh=u871SX269932WaLaHJ9AhtcP7Cj5iBk3lhKgV6jUuqM=; fh=JMff9rOGE1o6Dk0i1ujNaikYmZm9bCqBJMGHCqDdVWY=; b=H1TFU/sGv1VUEdMTmVjvKGZ3WToTQj/doRF04O4lliFVd8o9m0D8BCh7f0LfU+Ke5W MQGrlsbIegoWtBDSi43Z3Tx5w+7E9K1JeKtGa8mZp/aY2hrk8FiWcRh7C8u3RwFP1U/t /yckIyLhfVgGAcGyRtVPVm62N3wtuQt8zUGTUAOttW5NL5Hp2HAj5/nChmrwKK/MFvz+ rlL2nxmttQ/dbwxJGyna7G8ZTjsAXe0qAMD4B85N2X0v4eyhJlZpI+BgaA2crmRb2pTW eSqLlpaZ+dkfODvmKD+Gl9jtg15aw08MGf2TTEX1msREqfVb9X8xhgl4cIzWIrfmfDP1 3yKw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-162015-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162015-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x13-20020ae9f80d000000b0078eed1c156csi24977789qkh.191.2024.04.29.03.04.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 03:04:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-162015-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-162015-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162015-linux.lists.archive=gmail.com@vger.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 77E971C219A1 for ; Mon, 29 Apr 2024 10:04:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B4EE22C85F; Mon, 29 Apr 2024 10:04:45 +0000 (UTC) Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9702029421; Mon, 29 Apr 2024 10:04:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714385085; cv=none; b=JQ7NNWQpYGdnw2PY3VoNjMoIpTm8z4T0wdQf8PriPvt/CaJnbzMXP2c+Oebs8sRmp63vhl9uRBNIPGEZZNJwdDKhzask+VZY/Igb27yEBFH+CguCyZHFVvmD7a12QnD9tyMTbCjIl5SOYjD/WniIXYIPrgm8P7q1sUpdHUQRAQ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714385085; c=relaxed/simple; bh=iv0of1SDuLM2j+lS8i9Lv/zFTg7B6r5cfF5tUfHgGdQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=EAuv0iKYstykdOCmZyX7q2YeIsKWcRSkfxpAJ1RXiqxwnrjMl7UxTDfP9Fzx/C4boLQVoon4yk1afZ0VU4cRhihVyY9mxFJBROCKv20tTwgY26YJgCanTfNuyvFY2sqVVBm9LEa6JOun85uJn41wwKNAMI3oTTP3040l5sJv5Fs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a55b93f5540so565496866b.1; Mon, 29 Apr 2024 03:04:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714385082; x=1714989882; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=u871SX269932WaLaHJ9AhtcP7Cj5iBk3lhKgV6jUuqM=; b=fjfYm4am06ul0JfcU8kGDnRTV5v0ZtcmqmI4SVXjGkmHA/HUAMcgk3A+2RZ+PYs2Qe QtOKKtkdbTY/fNAxkMFfvk/leRRJJa1vMAEr/XlbWpjVaQx23ooOBgv6eod0hI+FZRYJ RWMx9o3wnjbFuyiNSk3qhu/8N5ZBaJxObaq/ZVMDemlbQwh/QzL9EZ8FvUkhJMaBRhBs NSZ8jwAKjaCsh0p3pHkAWYZelmWnOB+rZ2FEz9Vxg5QXZsVtPQaFpitgdZqsbadl5Au8 1zsf/MziGpIh7I5x7F4yH/opZIOTah/xVU21OE524pGKTYenhy+pp2148AAxYJsNFbpJ g8+A== X-Forwarded-Encrypted: i=1; AJvYcCWqzjnPBjCLk8yYCQ6PX1bEAU1Gf5HrS9CeZtNI+wLJtM9DMLZIGW7QVHxxF88rt5ox2SAfJoj0D+RP9TjIw/b78m4QA5pS2zOGfWw1QQHnwWOgbbSz17fAWOV6aSfhLTWgepvL X-Gm-Message-State: AOJu0YzAgdmouwxi7wTYDJxVQkpNEz0zf4gh3QeRRDYWwEbYOtm0u72J r4CkBZ2GAcqKoglbZXxY5kPjgrU1NcTQWpsCgMkrxS52sSVF05ky X-Received: by 2002:a17:906:7185:b0:a58:73f0:4d1a with SMTP id h5-20020a170906718500b00a5873f04d1amr6449916ejk.70.1714385081700; Mon, 29 Apr 2024 03:04:41 -0700 (PDT) Received: from localhost (fwdproxy-lla-006.fbsv.net. [2a03:2880:30ff:6::face:b00c]) by smtp.gmail.com with ESMTPSA id z13-20020a170906434d00b00a51e5813f4fsm13924963ejm.19.2024.04.29.03.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 03:04:41 -0700 (PDT) From: Breno Leitao To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: leit@meta.com, netdev@vger.kernel.org (open list:NETWORKING [GENERAL]), linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next] netpoll: Fix race condition in netpoll_owner_active Date: Mon, 29 Apr 2024 03:04:33 -0700 Message-ID: <20240429100437.3487432-1-leitao@debian.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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 543007f159f9..55bcacf67df3 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