From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
patches@lists.linux.dev,
syzbot+7f7f201cc2668a8fd169@syzkaller.appspotmail.com,
Kuniyuki Iwashima <kuniyu@amazon.com>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.1 21/69] af_unix: Clear stale u->oob_skb.
Date: Mon, 15 Apr 2024 16:20:52 +0200 [thread overview]
Message-ID: <20240415141946.807128853@linuxfoundation.org> (raw)
In-Reply-To: <20240415141946.165870434@linuxfoundation.org>
6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <kuniyu@amazon.com>
[ Upstream commit b46f4eaa4f0ec38909fb0072eea3aeddb32f954e ]
syzkaller started to report deadlock of unix_gc_lock after commit
4090fa373f0e ("af_unix: Replace garbage collection algorithm."), but
it just uncovers the bug that has been there since commit 314001f0bf92
("af_unix: Add OOB support").
The repro basically does the following.
from socket import *
from array import array
c1, c2 = socketpair(AF_UNIX, SOCK_STREAM)
c1.sendmsg([b'a'], [(SOL_SOCKET, SCM_RIGHTS, array("i", [c2.fileno()]))], MSG_OOB)
c2.recv(1) # blocked as no normal data in recv queue
c2.close() # done async and unblock recv()
c1.close() # done async and trigger GC
A socket sends its file descriptor to itself as OOB data and tries to
receive normal data, but finally recv() fails due to async close().
The problem here is wrong handling of OOB skb in manage_oob(). When
recvmsg() is called without MSG_OOB, manage_oob() is called to check
if the peeked skb is OOB skb. In such a case, manage_oob() pops it
out of the receive queue but does not clear unix_sock(sk)->oob_skb.
This is wrong in terms of uAPI.
Let's say we send "hello" with MSG_OOB, and "world" without MSG_OOB.
The 'o' is handled as OOB data. When recv() is called twice without
MSG_OOB, the OOB data should be lost.
>>> from socket import *
>>> c1, c2 = socketpair(AF_UNIX, SOCK_STREAM, 0)
>>> c1.send(b'hello', MSG_OOB) # 'o' is OOB data
5
>>> c1.send(b'world')
5
>>> c2.recv(5) # OOB data is not received
b'hell'
>>> c2.recv(5) # OOB date is skipped
b'world'
>>> c2.recv(5, MSG_OOB) # This should return an error
b'o'
In the same situation, TCP actually returns -EINVAL for the last
recv().
Also, if we do not clear unix_sk(sk)->oob_skb, unix_poll() always set
EPOLLPRI even though the data has passed through by previous recv().
To avoid these issues, we must clear unix_sk(sk)->oob_skb when dequeuing
it from recv queue.
The reason why the old GC did not trigger the deadlock is because the
old GC relied on the receive queue to detect the loop.
When it is triggered, the socket with OOB data is marked as GC candidate
because file refcount == inflight count (1). However, after traversing
all inflight sockets, the socket still has a positive inflight count (1),
thus the socket is excluded from candidates. Then, the old GC lose the
chance to garbage-collect the socket.
With the old GC, the repro continues to create true garbage that will
never be freed nor detected by kmemleak as it's linked to the global
inflight list. That's why we couldn't even notice the issue.
Fixes: 314001f0bf92 ("af_unix: Add OOB support")
Reported-by: syzbot+7f7f201cc2668a8fd169@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=7f7f201cc2668a8fd169
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20240405221057.2406-1-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
net/unix/af_unix.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index e1af94393789f..373530303ad19 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2677,7 +2677,9 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
}
} else if (!(flags & MSG_PEEK)) {
skb_unlink(skb, &sk->sk_receive_queue);
- consume_skb(skb);
+ WRITE_ONCE(u->oob_skb, NULL);
+ if (!WARN_ON_ONCE(skb_unref(skb)))
+ kfree_skb(skb);
skb = skb_peek(&sk->sk_receive_queue);
}
}
--
2.43.0
next prev parent reply other threads:[~2024-04-15 14:39 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-15 14:20 [PATCH 6.1 00/69] 6.1.87-rc1 review Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 01/69] smb3: fix Open files on server counter going negative Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 02/69] ata: libata-scsi: Fix ata_scsi_dev_rescan() error path Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 03/69] batman-adv: Avoid infinite loop trying to resize local TT Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 04/69] ring-buffer: Only update pages_touched when a new page is touched Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 05/69] Bluetooth: Fix memory leak in hci_req_sync_complete() Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 06/69] drm/amd/pm: fixes a random hang in S4 for SMU v13.0.4/11 Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 07/69] PM: s2idle: Make sure CPUs will wakeup directly on resume Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 08/69] media: cec: core: remove length check of Timer Status Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 09/69] arm64: dts: imx8-ss-conn: fix usdhc wrong lpcg clock order Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 10/69] Revert "drm/qxl: simplify qxl_fence_wait" Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 11/69] nouveau: fix function cast warning Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 12/69] scsi: hisi_sas: Modify the deadline for ata_wait_after_reset() Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 13/69] scsi: qla2xxx: Fix off by one in qla_edif_app_getstats() Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 14/69] net: openvswitch: fix unwanted error log on timeout policy probing Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 15/69] u64_stats: fix u64_stats_init() for lockdep when used repeatedly in one file Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 16/69] xsk: validate user input for XDP_{UMEM|COMPLETION}_FILL_RING Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 17/69] geneve: fix header validation in geneve[6]_xmit_skb Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 18/69] bnxt_en: Reset PTP tx_avail after possible firmware reset Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 19/69] net: ks8851: Inline ks8851_rx_skb() Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 20/69] net: ks8851: Handle softirqs at the end of IRQ thread to fix hang Greg Kroah-Hartman
2024-04-15 14:20 ` Greg Kroah-Hartman [this message]
2024-04-15 14:20 ` [PATCH 6.1 22/69] octeontx2-af: Fix NIX SQ mode and BP config Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 23/69] ipv6: fib: hide unused pn variable Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 24/69] ipv4/route: avoid unused-but-set-variable warning Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 25/69] ipv6: fix race condition between ipv6_get_ifaddr and ipv6_del_addr Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 26/69] Bluetooth: SCO: Fix not validating setsockopt user input Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 27/69] Bluetooth: L2CAP: " Greg Kroah-Hartman
2024-04-15 14:20 ` [PATCH 6.1 28/69] netfilter: complete validation of " Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 29/69] net/mlx5: Properly link new fs rules into the tree Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 30/69] net/mlx5e: Fix mlx5e_priv_init() cleanup flow Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 31/69] net/mlx5e: HTB, Fix inconsistencies with QoS SQs number Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 32/69] net: sparx5: fix wrong config being used when reconfiguring PCS Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 33/69] net: dsa: mt7530: trap link-local frames regardless of ST Port State Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 34/69] af_unix: Do not use atomic ops for unix_sk(sk)->inflight Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 35/69] af_unix: Fix garbage collector racing against connect() Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 36/69] net: ena: Fix potential sign extension issue Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 37/69] net: ena: Wrong missing IO completions check order Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 38/69] net: ena: Fix incorrect descriptor free behavior Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 39/69] tracing: hide unused ftrace_event_id_fops Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 40/69] iommu/vt-d: Allocate local memory for page request queue Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 41/69] btrfs: qgroup: correctly model root qgroup rsv in convert Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 42/69] btrfs: record delayed inode root in transaction Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 43/69] btrfs: qgroup: convert PREALLOC to PERTRANS after record_root_in_trans Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 44/69] io_uring/net: restore msg_control on sendzc retry Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 45/69] kprobes: Fix possible use-after-free issue on kprobe registration Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 46/69] drm/i915/vrr: Disable VRR when using bigjoiner Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 47/69] drm/amdkfd: Reset GPU on queue preemption failure Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 48/69] drm/ast: Fix soft lockup Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 49/69] drm/client: Fully protect modes[] with dev->mode_config.mutex Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 50/69] vhost: Add smp_rmb() in vhost_vq_avail_empty() Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 51/69] vhost: Add smp_rmb() in vhost_enable_notify() Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 52/69] perf/x86: Fix out of range data Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 53/69] x86/cpu: Actually turn off mitigations by default for SPECULATION_MITIGATIONS=n Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 54/69] selftests: timers: Fix abs() warning in posix_timers test Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 55/69] x86/apic: Force native_apic_mem_read() to use the MOV instruction Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 56/69] irqflags: Explicitly ignore lockdep_hrtimer_exit() argument Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 57/69] x86/bugs: Fix return type of spectre_bhi_state() Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 58/69] x86/bugs: Fix BHI documentation Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 59/69] x86/bugs: Cache the value of MSR_IA32_ARCH_CAPABILITIES Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 60/69] x86/bugs: Rename various ia32_cap variables to x86_arch_cap_msr Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 61/69] x86/bugs: Fix BHI handling of RRSBA Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 62/69] x86/bugs: Clarify that syscall hardening isnt a BHI mitigation Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 63/69] x86/bugs: Remove CONFIG_BHI_MITIGATION_AUTO and spectre_bhi=auto Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 64/69] x86/bugs: Replace CONFIG_SPECTRE_BHI_{ON,OFF} with CONFIG_MITIGATION_SPECTRE_BHI Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 65/69] drm/i915/cdclk: Fix CDCLK programming order when pipes are active Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 66/69] drm/i915: Disable port sync when bigjoiner is used Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 67/69] drm/amdgpu: Reset dGPU if suspend got aborted Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 68/69] drm/amdgpu: always force full reset for SOC21 Greg Kroah-Hartman
2024-04-15 14:21 ` [PATCH 6.1 69/69] drm/amd/display: fix disable otg wa logic in DCN316 Greg Kroah-Hartman
2024-04-15 17:36 ` [PATCH 6.1 00/69] 6.1.87-rc1 review Florian Fainelli
2024-04-15 19:47 ` Pavel Machek
2024-04-15 23:53 ` Kelsey Steele
2024-04-16 0:17 ` Mark Brown
2024-04-16 6:34 ` Ron Economos
2024-04-16 11:55 ` Yann Sionneau
2024-04-16 12:03 ` Jon Hunter
2024-04-16 14:22 ` Pascal Ernster
2024-04-16 20:18 ` Mateusz Jończyk
2024-04-17 7:43 ` 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=20240415141946.807128853@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=kuniyu@amazon.com \
--cc=patches@lists.linux.dev \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
--cc=syzbot+7f7f201cc2668a8fd169@syzkaller.appspotmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox