In the Linux kernel, the following vulnerability has been resolved:
afunix: Don't return OOB skb in manageoob().
syzbot reported use-after-free in unixstreamrecv_urg(). [0]
The scenario is
The recent commit 8594d9b85c07 ("afunix: Don't call skbget() for OOB skb.") uncovered the issue.
If the OOB skb is consumed and the next skb is peeked in manage_oob(), we still need to check if the skb is OOB.
Let's do so by falling back to the following checks in manage_oob() and add the test case in selftest.
Note that we need to add a similar check for SIOCATMARK.
Read of size 4 at addr ffff8880326abcc4 by task syz-executor178/5235
CPU: 0 UID: 0 PID: 5235 Comm: syz-executor178 Not tainted 6.11.0-rc5-syzkaller-00742-gfbdaffe41adc #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024 Call Trace: <TASK> dumpstack lib/dumpstack.c:93 [inline] dumpstacklvl+0x241/0x360 lib/dumpstack.c:119 printaddressdescription mm/kasan/report.c:377 [inline] printreport+0x169/0x550 mm/kasan/report.c:488 kasanreport+0x143/0x180 mm/kasan/report.c:601 unixstreamreadactor+0xa6/0xb0 net/unix/afunix.c:2959 unixstreamrecvurg+0x1df/0x320 net/unix/afunix.c:2640 unixstreamreadgeneric+0x2456/0x2520 net/unix/afunix.c:2778 unixstreamrecvmsg+0x22b/0x2c0 net/unix/afunix.c:2996 sockrecvmsgnosec net/socket.c:1046 [inline] sockrecvmsg+0x22f/0x280 net/socket.c:1068 _sysrecvmsg+0x1db/0x470 net/socket.c:2816 _sysrecvmsg net/socket.c:2858 [inline] _sysrecvmsg+0x2f0/0x3e0 net/socket.c:2888 dosyscallx64 arch/x86/entry/common.c:52 [inline] dosyscall64+0xf3/0x230 arch/x86/entry/common.c:83 entrySYSCALL64afterhwframe+0x77/0x7f RIP: 0033:0x7f5360d6b4e9 Code: 48 83 c4 28 c3 e8 37 17 00 00 0f 1f 80 00 00 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007fff29b3a458 EFLAGS: 00000246 ORIG_RAX: 000000000000002f RAX: ffffffffffffffda RBX: 00007fff29b3a638 RCX: 00007f5360d6b4e9 RDX: 0000000000002001 RSI: 0000000020000640 RDI: 0000000000000003 RBP: 00007f5360dde610 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001 R13: 00007fff29b3a628 R14: 0000000000000001 R15: 0000000000000001 </TASK>
Allocated by task 5235: kasansavestack mm/kasan/common.c:47 [inline] kasansavetrack+0x3f/0x80 mm/kasan/common.c:68 unpoisonslabobject mm/kasan/common.c:312 [inline] kasanslaballoc+0x66/0x80 mm/kasan/common.c:338 kasanslaballoc include/linux/kasan.h:201 [inline] slabpostallochook mm/slub.c:3988 [inline] slaballocnode mm/slub.c:4037 [inline] kmemcacheallocnodenoprof+0x16b/0x320 mm/slub.c:4080 _allocskb+0x1c3/0x440 net/core/skbuff.c:667 allocskb include/linux/skbuff.h:1320 [inline] allocskbwithfrags+0xc3/0x770 net/core/skbuff.c:6528 sockallocsendpskb+0x91a/0xa60 net/core/sock.c:2815 sockallocsendskb include/net/sock.h:1778 [inline] queueoob+0x108/0x680 net/unix/afunix.c:2198 unixstreamsendmsg+0xd24/0xf80 net/unix/afunix.c:2351 socksendmsgnosec net/socket.c:730 [inline] _socksendmsg+0x221/0x270 net/socket.c:745 syssendmsg+0x525/0x7d0 net/socket.c:2597 _syssendmsg net/socket.c:2651 [inline] _syssendmsg+0x2b0/0x3a0 net/socket.c:2680 dosyscallx64 arch/x86/entry/common.c:52 [inline] dosyscall64+0xf3/0x230 arch/x86/entry/common.c:83 entrySYSCALL64afterhwframe+0x77/0x7f
Freed by task 5235: kasansavestack mm/kasan/common.c:47 ---truncated---
[
{
"id": "CVE-2024-47711-1a5a424b",
"target": {
"file": "net/unix/af_unix.c"
},
"digest": {
"threshold": 0.9,
"line_hashes": [
"210029696815513512634367243006013491104",
"158112504418513247449447724606358804089",
"148907966686384885678229636547507511746",
"49414087519496752920714308599207068502",
"154959313991721027859924630176394942300",
"235657019554850817973617502456153104489",
"270838727483376131492157244231260645748",
"54265324998167101094663001107738138069",
"203816501869745845869015607751351136721",
"26551238335690375454778620531876031797"
]
},
"deprecated": false,
"signature_type": "Line",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@5aa57d9f2d5311f19434d95b2a81610aa263e23b",
"signature_version": "v1"
},
{
"id": "CVE-2024-47711-305f2949",
"target": {
"file": "net/unix/af_unix.c"
},
"digest": {
"threshold": 0.9,
"line_hashes": [
"210029696815513512634367243006013491104",
"158112504418513247449447724606358804089",
"148907966686384885678229636547507511746",
"49414087519496752920714308599207068502",
"154959313991721027859924630176394942300",
"235657019554850817973617502456153104489",
"270838727483376131492157244231260645748",
"54265324998167101094663001107738138069",
"203816501869745845869015607751351136721",
"26551238335690375454778620531876031797"
]
},
"deprecated": false,
"signature_type": "Line",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@4a7f9a2591a923bdde4bd7eac33490b6ae3b257c",
"signature_version": "v1"
},
{
"id": "CVE-2024-47711-3b2f7e0b",
"target": {
"file": "tools/testing/selftests/net/af_unix/msg_oob.c"
},
"digest": {
"threshold": 0.9,
"line_hashes": [
"136336590444714270304088152917276592649",
"104713847446542202845887412627332487521",
"148682951524921640785638617150135384268"
]
},
"deprecated": false,
"signature_type": "Line",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@4a7f9a2591a923bdde4bd7eac33490b6ae3b257c",
"signature_version": "v1"
},
{
"id": "CVE-2024-47711-5667028f",
"target": {
"file": "net/unix/af_unix.c",
"function": "manage_oob"
},
"digest": {
"length": 1199.0,
"function_hash": "59162129637969261255958439013578062057"
},
"deprecated": false,
"signature_type": "Function",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@4a7f9a2591a923bdde4bd7eac33490b6ae3b257c",
"signature_version": "v1"
},
{
"id": "CVE-2024-47711-68aac1c3",
"target": {
"file": "net/unix/af_unix.c",
"function": "unix_ioctl"
},
"digest": {
"length": 901.0,
"function_hash": "255934561964195744826884131967846433511"
},
"deprecated": false,
"signature_type": "Function",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@5aa57d9f2d5311f19434d95b2a81610aa263e23b",
"signature_version": "v1"
},
{
"id": "CVE-2024-47711-718bc6f2",
"target": {
"file": "net/unix/af_unix.c",
"function": "unix_ioctl"
},
"digest": {
"length": 901.0,
"function_hash": "255934561964195744826884131967846433511"
},
"deprecated": false,
"signature_type": "Function",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@4a7f9a2591a923bdde4bd7eac33490b6ae3b257c",
"signature_version": "v1"
},
{
"id": "CVE-2024-47711-864bbd3e",
"target": {
"file": "net/unix/af_unix.c",
"function": "manage_oob"
},
"digest": {
"length": 1199.0,
"function_hash": "59162129637969261255958439013578062057"
},
"deprecated": false,
"signature_type": "Function",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@5aa57d9f2d5311f19434d95b2a81610aa263e23b",
"signature_version": "v1"
},
{
"id": "CVE-2024-47711-c96403ac",
"target": {
"file": "tools/testing/selftests/net/af_unix/msg_oob.c"
},
"digest": {
"threshold": 0.9,
"line_hashes": [
"136336590444714270304088152917276592649",
"104713847446542202845887412627332487521",
"148682951524921640785638617150135384268"
]
},
"deprecated": false,
"signature_type": "Line",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@5aa57d9f2d5311f19434d95b2a81610aa263e23b",
"signature_version": "v1"
}
]