All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Eric Dumazet <edumazet@google.com>,
	Willem de Bruijn <willemb@google.com>,
	syzbot <syzkaller@googlegroups.com>,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH 4.14 45/69] af_packet: fix data-race in packet_setsockopt / packet_setsockopt
Date: Mon,  7 Feb 2022 12:06:07 +0100	[thread overview]
Message-ID: <20220207103757.109325470@linuxfoundation.org> (raw)
In-Reply-To: <20220207103755.604121441@linuxfoundation.org>

From: Eric Dumazet <edumazet@google.com>

commit e42e70ad6ae2ae511a6143d2e8da929366e58bd9 upstream.

When packet_setsockopt( PACKET_FANOUT_DATA ) reads po->fanout,
no lock is held, meaning that another thread can change po->fanout.

Given that po->fanout can only be set once during the socket lifetime
(it is only cleared from fanout_release()), we can use
READ_ONCE()/WRITE_ONCE() to document the race.

BUG: KCSAN: data-race in packet_setsockopt / packet_setsockopt

write to 0xffff88813ae8e300 of 8 bytes by task 14653 on cpu 0:
 fanout_add net/packet/af_packet.c:1791 [inline]
 packet_setsockopt+0x22fe/0x24a0 net/packet/af_packet.c:3931
 __sys_setsockopt+0x209/0x2a0 net/socket.c:2180
 __do_sys_setsockopt net/socket.c:2191 [inline]
 __se_sys_setsockopt net/socket.c:2188 [inline]
 __x64_sys_setsockopt+0x62/0x70 net/socket.c:2188
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x44/0xd0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x44/0xae

read to 0xffff88813ae8e300 of 8 bytes by task 14654 on cpu 1:
 packet_setsockopt+0x691/0x24a0 net/packet/af_packet.c:3935
 __sys_setsockopt+0x209/0x2a0 net/socket.c:2180
 __do_sys_setsockopt net/socket.c:2191 [inline]
 __se_sys_setsockopt net/socket.c:2188 [inline]
 __x64_sys_setsockopt+0x62/0x70 net/socket.c:2188
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x44/0xd0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x44/0xae

value changed: 0x0000000000000000 -> 0xffff888106f8c000

Reported by Kernel Concurrency Sanitizer on:
CPU: 1 PID: 14654 Comm: syz-executor.3 Not tainted 5.16.0-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011

Fixes: 47dceb8ecdc1 ("packet: add classic BPF fanout mode")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Willem de Bruijn <willemb@google.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Link: https://lore.kernel.org/r/20220201022358.330621-1-eric.dumazet@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 net/packet/af_packet.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1770,7 +1770,10 @@ static int fanout_add(struct sock *sk, u
 		err = -ENOSPC;
 		if (refcount_read(&match->sk_ref) < PACKET_FANOUT_MAX) {
 			__dev_remove_pack(&po->prot_hook);
-			po->fanout = match;
+
+			/* Paired with packet_setsockopt(PACKET_FANOUT_DATA) */
+			WRITE_ONCE(po->fanout, match);
+
 			po->rollover = rollover;
 			rollover = NULL;
 			refcount_set(&match->sk_ref, refcount_read(&match->sk_ref) + 1);
@@ -3915,7 +3918,8 @@ packet_setsockopt(struct socket *sock, i
 	}
 	case PACKET_FANOUT_DATA:
 	{
-		if (!po->fanout)
+		/* Paired with the WRITE_ONCE() in fanout_add() */
+		if (!READ_ONCE(po->fanout))
 			return -EINVAL;
 
 		return fanout_set_data(po, optval, optlen);



  parent reply	other threads:[~2022-02-07 11:19 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-07 11:05 [PATCH 4.14 00/69] 4.14.265-rc1 review Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 01/69] Bluetooth: refactor malicious adv data check Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 02/69] s390/hypfs: include z/VM guests with access control group set Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 03/69] scsi: zfcp: Fix failed recovery on gone remote port with non-NPIV FCP devices Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 04/69] udf: Restore i_lenAlloc when inode expansion fails Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 05/69] udf: Fix NULL ptr deref when converting from inline format Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 06/69] PM: wakeup: simplify the output logic of pm_show_wakelocks() Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 07/69] netfilter: nft_payload: do not update layer 4 checksum when mangling fragments Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 08/69] serial: stm32: fix software flow control transfer Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 09/69] tty: n_gsm: fix SW flow control encoding/handling Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 10/69] tty: Add support for Brainboxes UC cards Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 11/69] usb-storage: Add unusual-devs entry for VL817 USB-SATA bridge Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 12/69] usb: common: ulpi: Fix crash in ulpi_match() Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 13/69] usb: gadget: f_sourcesink: Fix isoc transfer for USB_SPEED_SUPER_PLUS Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 14/69] USB: core: Fix hang in usb_kill_urb by adding memory barriers Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 15/69] usb: typec: tcpm: Do not disconnect while receiving VBUS off Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 16/69] net: sfp: ignore disabled SFP node Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 17/69] powerpc/32: Fix boot failure with GCC latent entropy plugin Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 18/69] lkdtm: Fix content of section containing lkdtm_rodata_do_nothing() Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 19/69] i40e: Increase delay to 1 s after global EMP reset Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 20/69] i40e: fix unsigned stat widths Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 21/69] rpmsg: char: Fix race between the release of rpmsg_ctrldev and cdev Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 22/69] rpmsg: char: Fix race between the release of rpmsg_eptdev " Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 23/69] scsi: bnx2fc: Flush destroy_work queue before calling bnx2fc_interface_put() Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 24/69] ipv6_tunnel: Rate limit warning messages Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 25/69] net: fix information leakage in /proc/net/ptype Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 26/69] ping: fix the sk_bound_dev_if match in ping_lookup Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 27/69] ipv4: avoid using shared IP generator for connected sockets Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 28/69] hwmon: (lm90) Reduce maximum conversion rate for G781 Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 29/69] NFSv4: Handle case where the lookup of a directory fails Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 30/69] NFSv4: nfs_atomic_open() can race when looking up a non-regular file Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 31/69] net-procfs: show net devices bound packet types Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 32/69] drm/msm: Fix wrong size calculation Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 33/69] drm/msm/dsi: invalid parameter check in msm_dsi_phy_enable Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 34/69] ibmvnic: dont spin in tasklet Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 35/69] yam: fix a memory leak in yam_siocdevprivate() Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 36/69] ipv4: raw: lock the socket in raw_bind() Greg Kroah-Hartman
2022-02-07 11:05 ` [PATCH 4.14 37/69] ipv4: tcp: send zero IPID in SYNACK messages Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 38/69] bpf: fix truncated jump targets on heavy expansions Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 39/69] netfilter: nat: remove l4 protocol port rovers Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 40/69] netfilter: nat: limit port clash resolution attempts Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 41/69] ipheth: fix EOVERFLOW in ipheth_rcvbulk_callback Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 42/69] net: amd-xgbe: ensure to reset the tx_timer_active flag Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 43/69] net: amd-xgbe: Fix skb data length underflow Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 44/69] rtnetlink: make sure to refresh master_dev/m_ops in __rtnl_newlink() Greg Kroah-Hartman
2022-02-07 11:06 ` Greg Kroah-Hartman [this message]
2022-02-07 11:06 ` [PATCH 4.14 46/69] audit: improve audit queue handling when "audit=1" on cmdline Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 47/69] ASoC: ops: Reject out of bounds values in snd_soc_put_volsw() Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 48/69] ASoC: ops: Reject out of bounds values in snd_soc_put_volsw_sx() Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 49/69] ASoC: ops: Reject out of bounds values in snd_soc_put_xr_sx() Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 50/69] drm/nouveau: fix off by one in BIOS boundary checking Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 51/69] block: bio-integrity: Advance seed correctly for larger interval sizes Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 52/69] RDMA/mlx4: Dont continue event handler after memory allocation failure Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 53/69] iommu/vt-d: Fix potential memory leak in intel_setup_irq_remapping() Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 54/69] iommu/amd: Fix loop timeout issue in iommu_ga_log_enable() Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 55/69] spi: bcm-qspi: check for valid cs before applying chip select Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 56/69] spi: mediatek: Avoid NULL pointer crash in interrupt Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 57/69] spi: meson-spicc: add IRQ check in meson_spicc_probe Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 58/69] net: ieee802154: ca8210: Stop leaking skbs Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 59/69] net: ieee802154: Return meaningful error codes from the netlink helpers Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 60/69] net: macsec: Verify that send_sci is on when setting Tx sci explicitly Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 61/69] drm/i915/overlay: Prevent divide by zero bugs in scaling Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 62/69] ASoC: fsl: Add missing error handling in pcm030_fabric_probe Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 63/69] scsi: bnx2fc: Make bnx2fc_recv_frame() mp safe Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 64/69] nfsd: nfsd4_setclientid_confirm mistakenly expires confirmed client Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 65/69] selftests: futex: Use variable MAKE instead of make Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 66/69] rtc: cmos: Evaluate century appropriate Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 67/69] EDAC/altera: Fix deferred probing Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 68/69] EDAC/xgene: " Greg Kroah-Hartman
2022-02-07 11:06 ` [PATCH 4.14 69/69] ext4: fix error handling in ext4_restore_inline_data() Greg Kroah-Hartman
2022-02-07 22:20 ` [PATCH 4.14 00/69] 4.14.265-rc1 review Guenter Roeck
2022-02-08  1:45 ` Slade Watkins
2022-02-08  8:31 ` Jon Hunter
2022-02-08  9:58 ` Naresh Kamboju

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220207103757.109325470@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzkaller@googlegroups.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.