Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2403454lqp; Sun, 24 Mar 2024 18:04:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXCl8nt15N6BOsvcaqd2pClvca8p5QdVd9CMr52X/DBPxAWdaorvcEP7We0YWVOiGxuJc449X5R3WtcmbICRIp5vPTH4WIpMfoqCxHqbg== X-Google-Smtp-Source: AGHT+IGDBVjsb/0zlWt5OqdHwbaBSUi1jI4UYYfFW429RG57H+A9sTjsfTueNXMMWMNTdHW9qDdi X-Received: by 2002:a05:622a:1aa9:b0:431:2813:88d4 with SMTP id s41-20020a05622a1aa900b00431281388d4mr6204119qtc.3.1711328670928; Sun, 24 Mar 2024 18:04:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711328670; cv=pass; d=google.com; s=arc-20160816; b=FapoXKeV0SAbnFsAoRbvfNMa//kDp5shqQQrhrfgXqFpBnYfrc66uF6oCBWOrfyNC5 ZzXXEdhdjgR5QIIVKKfHYzO18d7uoopFmf/gLeqG24JGYuFeWA1IQAfdWssSb+JbcWVO 1uS7JigvCVDfsYs+HjksFfHHCYKa63Ju5IOHBH+hYf2CO0GKbXKhGoLbF8c5JphIfk7D cn4TjtF7jTGd1mrvM92weFXuHOUrVfHHiAKOKITaFmLjE33hxrgOSCv+GnEAASPPTkhT 1CsoPI76AiX/9a20+DFubTRHiL2nXpCFRDeLL63mXv9xVeBdQBLt/T0xPq4SYi9Ur4/v Hv3A== 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=0ZiyeDOXEMhZ+aKyPnzCPdFFmXZcfLwpmtLmdp5fyGU=; fh=HUAkuQ9k6GMpcj3MzpQebljEd5zs2+SWfEouva0nEEM=; b=Eiw0k502TbR7kfTJ6+4nhW/HIMDm9RJecvTJ998sSlAyohQOQcwu9y3iXFIq6SIcyo q7gtkv7jFsZdA38b/Fogo9SKwSIWacD4dRWc0gEb0W3jUhxu1gXco+9bR8TVWDCP1jHi 6fsnj0pnaSn4uJRxtRmvf/wPLtDsKa3h5kJtP9i+taUcbD4XuVdCm6i+LV3a60rtNCnq PCoPeqlhWE/GhYXOP/6EMy+Jy+Hzlltn1JakgyKMrtIDI2Z30pGviVdgkMIhRQ+as/F6 OB0MrOo5om6x5c3LZ5ywQLeiTccxnRBK/2xwn5ofrJbY4dxp0qokKRPGdCHu/FRh3UYa Q0Sw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=so04lcQK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113562-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113562-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id bc13-20020a05622a1ccd00b004312a74f9aasi4493956qtb.417.2024.03.24.18.04.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 18:04:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113562-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=so04lcQK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113562-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113562-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A38661C24ACF for ; Mon, 25 Mar 2024 01:04:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 066161C5AA4; Sun, 24 Mar 2024 22:46:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="so04lcQK" 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 0C4F9745F4; Sun, 24 Mar 2024 22:46:04 +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=1711320365; cv=none; b=YReRc07Qoliuq5y6wxTVY3OpqFdvgq3q91i2d8OQJ/gMIY1I+bsXA9Y/gToj8eeCSDVQe7FhcaEZjPHb5giExigp0bfHhKnChjSvBIc/Fv9qbPpOsJAg2XxKWMkZVQSoFjBhK6WHCN4xoiQKkSGrDrf8eQBYq0z/qM/abLM3UNE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320365; c=relaxed/simple; bh=xCNH6G4YpmWOsFnG8Q+Y7uchheJOww5GVoQSLLdhQZk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=evg+Z5xCPeh7zC96Wb0n9kTxJu1dUlUjGSTViYj+B0Vl7/ECTKx2u4jypaPpv4XoR7/uTTYqK4Il/6CyqSsoJsr1pHTiP9qw8ItprQRZ3DaSJYdbquSm8E0ppbga2/zr97n12rbxDsHcVlJAOS63XeD39/gWoJyQwXNKqF4pQ20= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=so04lcQK; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 868FDC433F1; Sun, 24 Mar 2024 22:46:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320364; bh=xCNH6G4YpmWOsFnG8Q+Y7uchheJOww5GVoQSLLdhQZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=so04lcQK+QEsWSSTmNjCUxygrrrj/KSWAqAf0xVlpu0saoJAKwl7dHCcyezpnwyQn eRDX112VpcGiX157x4TdGMSekl6vIJ0UevjNt3rzxIH/wlNYN3Q8MKaNt+B2+nMn0k Y89m6E6D2r+s9ylphNdFbeqxFVh36eYUUnCf9sOACAHkW7JJuvDLgok4CZ2TJce9kI qlL5yD19hifxNxNmGJ4TVJC8tDEKvQxAa4xIE3dvQwhONAm6PbGA5TICKvnyQdkbVU bb6/BYfj36f7fK+S4GsqxIMCeF3r1YMI4bdycS709+gWZToKD5sPyPV4IYIStriZ7I aoDSjTDZEN9ow== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Eric Dumazet , syzbot+c669c1136495a2e7c31f@syzkaller.appspotmail.com, Willem de Bruijn , Willem de Bruijn , Jason Xing , "David S . Miller" , Sasha Levin Subject: [PATCH 6.8 671/715] packet: annotate data-races around ignore_outgoing Date: Sun, 24 Mar 2024 18:34:10 -0400 Message-ID: <20240324223455.1342824-672-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 6ebfad33161afacb3e1e59ed1c2feefef70f9f97 ] ignore_outgoing is read locklessly from dev_queue_xmit_nit() and packet_getsockopt() Add appropriate READ_ONCE()/WRITE_ONCE() annotations. syzbot reported: BUG: KCSAN: data-race in dev_queue_xmit_nit / packet_setsockopt write to 0xffff888107804542 of 1 bytes by task 22618 on cpu 0: packet_setsockopt+0xd83/0xfd0 net/packet/af_packet.c:4003 do_sock_setsockopt net/socket.c:2311 [inline] __sys_setsockopt+0x1d8/0x250 net/socket.c:2334 __do_sys_setsockopt net/socket.c:2343 [inline] __se_sys_setsockopt net/socket.c:2340 [inline] __x64_sys_setsockopt+0x66/0x80 net/socket.c:2340 do_syscall_64+0xd3/0x1d0 entry_SYSCALL_64_after_hwframe+0x6d/0x75 read to 0xffff888107804542 of 1 bytes by task 27 on cpu 1: dev_queue_xmit_nit+0x82/0x620 net/core/dev.c:2248 xmit_one net/core/dev.c:3527 [inline] dev_hard_start_xmit+0xcc/0x3f0 net/core/dev.c:3547 __dev_queue_xmit+0xf24/0x1dd0 net/core/dev.c:4335 dev_queue_xmit include/linux/netdevice.h:3091 [inline] batadv_send_skb_packet+0x264/0x300 net/batman-adv/send.c:108 batadv_send_broadcast_skb+0x24/0x30 net/batman-adv/send.c:127 batadv_iv_ogm_send_to_if net/batman-adv/bat_iv_ogm.c:392 [inline] batadv_iv_ogm_emit net/batman-adv/bat_iv_ogm.c:420 [inline] batadv_iv_send_outstanding_bat_ogm_packet+0x3f0/0x4b0 net/batman-adv/bat_iv_ogm.c:1700 process_one_work kernel/workqueue.c:3254 [inline] process_scheduled_works+0x465/0x990 kernel/workqueue.c:3335 worker_thread+0x526/0x730 kernel/workqueue.c:3416 kthread+0x1d1/0x210 kernel/kthread.c:388 ret_from_fork+0x4b/0x60 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:243 value changed: 0x00 -> 0x01 Reported by Kernel Concurrency Sanitizer on: CPU: 1 PID: 27 Comm: kworker/u8:1 Tainted: G W 6.8.0-syzkaller-08073-g480e035fc4c7 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 02/29/2024 Workqueue: bat_events batadv_iv_send_outstanding_bat_ogm_packet Fixes: fa788d986a3a ("packet: add sockopt to ignore outgoing packets") Reported-by: syzbot+c669c1136495a2e7c31f@syzkaller.appspotmail.com Closes: https://lore.kernel.org/netdev/CANn89i+Z7MfbkBLOv=p7KZ7=K1rKHO4P1OL5LYDCtBiyqsa9oQ@mail.gmail.com/T/#t Signed-off-by: Eric Dumazet Cc: Willem de Bruijn Reviewed-by: Willem de Bruijn Reviewed-by: Jason Xing Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/core/dev.c | 2 +- net/packet/af_packet.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 76e6438f4858e..f56f81e587236 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -2261,7 +2261,7 @@ void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev) rcu_read_lock(); again: list_for_each_entry_rcu(ptype, ptype_list, list) { - if (ptype->ignore_outgoing) + if (READ_ONCE(ptype->ignore_outgoing)) continue; /* Never send packets back to the socket diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index c9bbc26866907..e6a8701a38dbe 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -3998,7 +3998,7 @@ packet_setsockopt(struct socket *sock, int level, int optname, sockptr_t optval, if (val < 0 || val > 1) return -EINVAL; - po->prot_hook.ignore_outgoing = !!val; + WRITE_ONCE(po->prot_hook.ignore_outgoing, !!val); return 0; } case PACKET_TX_HAS_OFF: @@ -4129,7 +4129,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname, 0); break; case PACKET_IGNORE_OUTGOING: - val = po->prot_hook.ignore_outgoing; + val = READ_ONCE(po->prot_hook.ignore_outgoing); break; case PACKET_ROLLOVER_STATS: if (!po->rollover) -- 2.43.0