From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
patches@lists.linux.dev, Eric Dumazet <edumazet@google.com>,
Wang Liang <wangliang74@huawei.com>,
Jakub Kicinski <kuba@kernel.org>, Alva Lan <alvalan9@foxmail.com>
Subject: [PATCH 5.4 74/91] net: fix data-races around sk->sk_forward_alloc
Date: Thu, 30 Jan 2025 15:01:33 +0100 [thread overview]
Message-ID: <20250130140136.652138587@linuxfoundation.org> (raw)
In-Reply-To: <20250130140133.662535583@linuxfoundation.org>
5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wang Liang <wangliang74@huawei.com>
commit 073d89808c065ac4c672c0a613a71b27a80691cb upstream.
Syzkaller reported this warning:
------------[ cut here ]------------
WARNING: CPU: 0 PID: 16 at net/ipv4/af_inet.c:156 inet_sock_destruct+0x1c5/0x1e0
Modules linked in:
CPU: 0 UID: 0 PID: 16 Comm: ksoftirqd/0 Not tainted 6.12.0-rc5 #26
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
RIP: 0010:inet_sock_destruct+0x1c5/0x1e0
Code: 24 12 4c 89 e2 5b 48 c7 c7 98 ec bb 82 41 5c e9 d1 18 17 ff 4c 89 e6 5b 48 c7 c7 d0 ec bb 82 41 5c e9 bf 18 17 ff 0f 0b eb 83 <0f> 0b eb 97 0f 0b eb 87 0f 0b e9 68 ff ff ff 66 66 2e 0f 1f 84 00
RSP: 0018:ffffc9000008bd90 EFLAGS: 00010206
RAX: 0000000000000300 RBX: ffff88810b172a90 RCX: 0000000000000007
RDX: 0000000000000002 RSI: 0000000000000300 RDI: ffff88810b172a00
RBP: ffff88810b172a00 R08: ffff888104273c00 R09: 0000000000100007
R10: 0000000000020000 R11: 0000000000000006 R12: ffff88810b172a00
R13: 0000000000000004 R14: 0000000000000000 R15: ffff888237c31f78
FS: 0000000000000000(0000) GS:ffff888237c00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007ffc63fecac8 CR3: 000000000342e000 CR4: 00000000000006f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<TASK>
? __warn+0x88/0x130
? inet_sock_destruct+0x1c5/0x1e0
? report_bug+0x18e/0x1a0
? handle_bug+0x53/0x90
? exc_invalid_op+0x18/0x70
? asm_exc_invalid_op+0x1a/0x20
? inet_sock_destruct+0x1c5/0x1e0
__sk_destruct+0x2a/0x200
rcu_do_batch+0x1aa/0x530
? rcu_do_batch+0x13b/0x530
rcu_core+0x159/0x2f0
handle_softirqs+0xd3/0x2b0
? __pfx_smpboot_thread_fn+0x10/0x10
run_ksoftirqd+0x25/0x30
smpboot_thread_fn+0xdd/0x1d0
kthread+0xd3/0x100
? __pfx_kthread+0x10/0x10
ret_from_fork+0x34/0x50
? __pfx_kthread+0x10/0x10
ret_from_fork_asm+0x1a/0x30
</TASK>
---[ end trace 0000000000000000 ]---
Its possible that two threads call tcp_v6_do_rcv()/sk_forward_alloc_add()
concurrently when sk->sk_state == TCP_LISTEN with sk->sk_lock unlocked,
which triggers a data-race around sk->sk_forward_alloc:
tcp_v6_rcv
tcp_v6_do_rcv
skb_clone_and_charge_r
sk_rmem_schedule
__sk_mem_schedule
sk_forward_alloc_add()
skb_set_owner_r
sk_mem_charge
sk_forward_alloc_add()
__kfree_skb
skb_release_all
skb_release_head_state
sock_rfree
sk_mem_uncharge
sk_forward_alloc_add()
sk_mem_reclaim
// set local var reclaimable
__sk_mem_reclaim
sk_forward_alloc_add()
In this syzkaller testcase, two threads call
tcp_v6_do_rcv() with skb->truesize=768, the sk_forward_alloc changes like
this:
(cpu 1) | (cpu 2) | sk_forward_alloc
... | ... | 0
__sk_mem_schedule() | | +4096 = 4096
| __sk_mem_schedule() | +4096 = 8192
sk_mem_charge() | | -768 = 7424
| sk_mem_charge() | -768 = 6656
... | ... |
sk_mem_uncharge() | | +768 = 7424
reclaimable=7424 | |
| sk_mem_uncharge() | +768 = 8192
| reclaimable=8192 |
__sk_mem_reclaim() | | -4096 = 4096
| __sk_mem_reclaim() | -8192 = -4096 != 0
The skb_clone_and_charge_r() should not be called in tcp_v6_do_rcv() when
sk->sk_state is TCP_LISTEN, it happens later in tcp_v6_syn_recv_sock().
Fix the same issue in dccp_v6_do_rcv().
Suggested-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Fixes: e994b2f0fb92 ("tcp: do not lock listener to process SYN packets")
Signed-off-by: Wang Liang <wangliang74@huawei.com>
Link: https://patch.msgid.link/20241107023405.889239-1-wangliang74@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Alva Lan <alvalan9@foxmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
net/dccp/ipv6.c | 2 +-
net/ipv6/tcp_ipv6.c | 4 +---
2 files changed, 2 insertions(+), 4 deletions(-)
--- a/net/dccp/ipv6.c
+++ b/net/dccp/ipv6.c
@@ -602,7 +602,7 @@ static int dccp_v6_do_rcv(struct sock *s
by tcp. Feel free to propose better solution.
--ANK (980728)
*/
- if (np->rxopt.all)
+ if (np->rxopt.all && sk->sk_state != DCCP_LISTEN)
opt_skb = skb_clone_and_charge_r(skb, sk);
if (sk->sk_state == DCCP_OPEN) { /* Fast path */
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1393,7 +1393,7 @@ static int tcp_v6_do_rcv(struct sock *sk
by tcp. Feel free to propose better solution.
--ANK (980728)
*/
- if (np->rxopt.all)
+ if (np->rxopt.all && sk->sk_state != TCP_LISTEN)
opt_skb = skb_clone_and_charge_r(skb, sk);
if (sk->sk_state == TCP_ESTABLISHED) { /* Fast path */
@@ -1430,8 +1430,6 @@ static int tcp_v6_do_rcv(struct sock *sk
if (nsk != sk) {
if (tcp_child_process(sk, nsk, skb))
goto reset;
- if (opt_skb)
- __kfree_skb(opt_skb);
return 0;
}
} else
next prev parent reply other threads:[~2025-01-30 14:20 UTC|newest]
Thread overview: 97+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-30 14:00 [PATCH 5.4 00/91] 5.4.290-rc1 review Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 01/91] jbd2: flush filesystem device before updating tail sequence Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 02/91] dm array: fix releasing a faulty array block twice in dm_array_cursor_end Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 03/91] dm array: fix unreleased btree blocks on closing a faulty array cursor Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 04/91] dm array: fix cursor index when skipping across block boundaries Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 05/91] ieee802154: ca8210: Add missing check for kfifo_alloc() in ca8210_probe() Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 06/91] net: 802: LLC+SNAP OID:PID lookup on start of skb data Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 07/91] tcp/dccp: complete lockless accesses to sk->sk_max_ack_backlog Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 08/91] tcp/dccp: allow a connection when sk_max_ack_backlog is zero Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 09/91] net_sched: cls_flow: validate TCA_FLOW_RSHIFT attribute Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 10/91] tls: Fix tls_sw_sendmsg error handling Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 11/91] dm thin: make get_first_thin use rcu-safe list first function Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 12/91] sctp: sysctl: cookie_hmac_alg: avoid using current->nsproxy Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 13/91] sctp: sysctl: auth_enable: " Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 14/91] drm/amd/display: Add check for granularity in dml ceil/floor helpers Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 15/91] ACPI: resource: Add TongFang GM5HG0A to irq1_edge_low_force_override[] Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 16/91] ACPI: resource: Add Asus Vivobook X1504VAP to irq1_level_low_skip_override[] Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 17/91] drm/amd/display: increase MAX_SURFACES to the value supported by hw Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 18/91] USB: serial: option: add MeiG Smart SRM815 Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 19/91] USB: serial: option: add Neoway N723-EA support Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 20/91] staging: iio: ad9834: Correct phase range check Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 21/91] staging: iio: ad9832: " Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 22/91] usb-storage: Add max sectors quirk for Nokia 208 Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 23/91] USB: serial: cp210x: add Phoenix Contact UPS Device Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 24/91] usb: gadget: u_serial: Disable ep before setting port to null to fix the crash caused by port being null Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 25/91] USB: usblp: return error when setting unsupported protocol Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 26/91] USB: core: Disable LPM only for non-suspended ports Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 27/91] usb: fix reference leak in usb_new_device() Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 28/91] usb: gadget: f_fs: Remove WARN_ON in functionfs_bind Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 29/91] iio: pressure: zpa2326: fix information leak in triggered buffer Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 30/91] iio: dummy: iio_simply_dummy_buffer: " Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 31/91] iio: light: vcnl4035: " Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 32/91] iio: imu: kmx61: " Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 33/91] iio: adc: ti-ads8688: " Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 34/91] iio: gyro: fxas21002c: Fix missing data update in trigger handler Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 35/91] iio: adc: ti-ads124s08: Use gpiod_set_value_cansleep() Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 36/91] iio: adc: at91: call input_free_device() on allocated iio_dev Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 37/91] iio: inkern: call iio_device_put() only on mapped devices Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 38/91] arm64: dts: rockchip: fix defines in pd_vio node for rk3399 Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 39/91] arm64: dts: rockchip: fix pd_tcpc0 and pd_tcpc1 node position on rk3399 Greg Kroah-Hartman
2025-01-30 14:00 ` [PATCH 5.4 40/91] arm64: dts: rockchip: add #power-domain-cells to power domain nodes Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 41/91] arm64: dts: rockchip: add hevc power domain clock to rk3328 Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 42/91] phy: core: fix code style in devm_of_phy_provider_unregister Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 43/91] phy: core: Fix that API devm_of_phy_provider_unregister() fails to unregister the phy provider Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 44/91] ocfs2: correct return value of ocfs2_local_free_info() Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 45/91] ocfs2: fix slab-use-after-free due to dangling pointer dqi_priv Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 46/91] sctp: sysctl: rto_min/max: avoid using current->nsproxy Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 47/91] riscv: abstract out CSR names for supervisor vs machine mode Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 48/91] riscv: remove unused handle_exception symbol Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 49/91] RISC-V: Avoid dereferening NULL regs in die() Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 50/91] riscv: Avoid enabling interrupts " Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 51/91] riscv: Fix sleeping in invalid context " Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 52/91] riscv: prefix IRQ_ macro names with an RV_ namespace Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 53/91] RISC-V: Dont enable all interrupts in trap_init() Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 54/91] net: ethernet: ti: cpsw_ale: Fix cpsw_ale_get_field() Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 55/91] net: net_namespace: Optimize the code Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 56/91] net: add exit_batch_rtnl() method Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 57/91] gtp: use " Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 58/91] gtp: Use for_each_netdev_rcu() in gtp_genl_dump_pdp() Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 59/91] gtp: Destroy device along with udp sockets netns dismantle Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 60/91] nfp: bpf: prevent integer overflow in nfp_bpf_event_output() Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 61/91] drm/v3d: Ensure job pointer is set to NULL after job completion Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 62/91] i2c: mux: demux-pinctrl: check initial mux selection, too Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 63/91] mac802154: check local interfaces before deleting sdata list Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 64/91] hfs: Sanity check the root record Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 65/91] kheaders: Ignore silly-rename files Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 66/91] poll_wait: add mb() to fix theoretical race between waitqueue_active() and .poll() Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 67/91] nvmet: propagate npwg topology Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 68/91] net: ethernet: xgbe: re-add aneg to supported features in PHY quirks Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 69/91] fs/proc: fix softlockup in __read_vmcore (part 2) Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 70/91] irqchip/gic-v3: Handle CPU_PM_ENTER_FAILED correctly Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 71/91] hrtimers: Handle CPU state correctly on hotplug Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 72/91] ipv6: avoid possible NULL deref in rt6_uncached_list_flush_dev() Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 73/91] scsi: sg: Fix slab-use-after-free read in sg_release() Greg Kroah-Hartman
2025-01-30 14:01 ` Greg Kroah-Hartman [this message]
2025-01-30 14:01 ` [PATCH 5.4 75/91] ASoC: wm8994: Add depends on MFD core Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 76/91] scsi: iscsi: Fix redundant response for ISCSI_UEVENT_GET_HOST_STATS request Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 77/91] irqchip/sunxi-nmi: Add missing SKIP_WAKE flag Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 78/91] gfs2: Truncate address space when flipping GFS2_DIF_JDATA flag Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 79/91] m68k: Update ->thread.esp0 before calling syscall_trace() in ret_from_signal Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 80/91] m68k: Add missing mmap_read_lock() to sys_cacheflush() Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 81/91] signal/m68k: Use force_sigsegv(SIGSEGV) in fpsp040_die Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 82/91] net: xen-netback: hash.c: Use built-in RCU list checking Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 83/91] net/xen-netback: prevent UAF in xenvif_flush_hash() Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 84/91] vfio/platform: check the bounds of read/write syscalls Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 85/91] ext4: avoid ext4_error()s caused by ENOMEM in the truncate path Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 86/91] ext4: fix slab-use-after-free in ext4_split_extent_at() Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 87/91] USB: serial: quatech2: fix null-ptr-deref in qt2_process_read_urb() Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 88/91] Revert "usb: gadget: u_serial: Disable ep before setting port to null to fix the crash caused by port being null" Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 89/91] Input: atkbd - map F23 key to support default copilot shortcut Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 90/91] Input: xpad - add unofficial Xbox 360 wireless receiver clone Greg Kroah-Hartman
2025-01-30 14:01 ` [PATCH 5.4 91/91] Input: xpad - add support for wooting two he (arm) Greg Kroah-Hartman
2025-01-30 19:35 ` [PATCH 5.4 00/91] 5.4.290-rc1 review Naresh Kamboju
2025-01-31 8:57 ` Greg Kroah-Hartman
2025-01-30 20:24 ` Florian Fainelli
2025-01-30 22:21 ` Pavel Machek
2025-01-31 5:38 ` Jon Hunter
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=20250130140136.652138587@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=alvalan9@foxmail.com \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=patches@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=wangliang74@huawei.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.