https://github.com/torvalds/linux
Revision 3aff8aaca4e36dc8b17eaa011684881a80238966 authored by Maxim Mikityanskiy on 04 October 2022, 21:27:18 UTC, committed by Luiz Augusto von Dentz on 02 November 2022, 21:12:34 UTC
Fix the race condition between the following two flows that run in parallel: 1. l2cap_reassemble_sdu -> chan->ops->recv (l2cap_sock_recv_cb) -> __sock_queue_rcv_skb. 2. bt_sock_recvmsg -> skb_recv_datagram, skb_free_datagram. An SKB can be queued by the first flow and immediately dequeued and freed by the second flow, therefore the callers of l2cap_reassemble_sdu can't use the SKB after that function returns. However, some places continue accessing struct l2cap_ctrl that resides in the SKB's CB for a short time after l2cap_reassemble_sdu returns, leading to a use-after-free condition (the stack trace is below, line numbers for kernel 5.19.8). Fix it by keeping a local copy of struct l2cap_ctrl. BUG: KASAN: use-after-free in l2cap_rx_state_recv (net/bluetooth/l2cap_core.c:6906) bluetooth Read of size 1 at addr ffff88812025f2f0 by task kworker/u17:3/43169 Workqueue: hci0 hci_rx_work [bluetooth] Call Trace: <TASK> dump_stack_lvl (lib/dump_stack.c:107 (discriminator 4)) print_report.cold (mm/kasan/report.c:314 mm/kasan/report.c:429) ? l2cap_rx_state_recv (net/bluetooth/l2cap_core.c:6906) bluetooth kasan_report (mm/kasan/report.c:162 mm/kasan/report.c:493) ? l2cap_rx_state_recv (net/bluetooth/l2cap_core.c:6906) bluetooth l2cap_rx_state_recv (net/bluetooth/l2cap_core.c:6906) bluetooth l2cap_rx (net/bluetooth/l2cap_core.c:7236 net/bluetooth/l2cap_core.c:7271) bluetooth ret_from_fork (arch/x86/entry/entry_64.S:306) </TASK> Allocated by task 43169: kasan_save_stack (mm/kasan/common.c:39) __kasan_slab_alloc (mm/kasan/common.c:45 mm/kasan/common.c:436 mm/kasan/common.c:469) kmem_cache_alloc_node (mm/slab.h:750 mm/slub.c:3243 mm/slub.c:3293) __alloc_skb (net/core/skbuff.c:414) l2cap_recv_frag (./include/net/bluetooth/bluetooth.h:425 net/bluetooth/l2cap_core.c:8329) bluetooth l2cap_recv_acldata (net/bluetooth/l2cap_core.c:8442) bluetooth hci_rx_work (net/bluetooth/hci_core.c:3642 net/bluetooth/hci_core.c:3832) bluetooth process_one_work (kernel/workqueue.c:2289) worker_thread (./include/linux/list.h:292 kernel/workqueue.c:2437) kthread (kernel/kthread.c:376) ret_from_fork (arch/x86/entry/entry_64.S:306) Freed by task 27920: kasan_save_stack (mm/kasan/common.c:39) kasan_set_track (mm/kasan/common.c:45) kasan_set_free_info (mm/kasan/generic.c:372) ____kasan_slab_free (mm/kasan/common.c:368 mm/kasan/common.c:328) slab_free_freelist_hook (mm/slub.c:1780) kmem_cache_free (mm/slub.c:3536 mm/slub.c:3553) skb_free_datagram (./include/net/sock.h:1578 ./include/net/sock.h:1639 net/core/datagram.c:323) bt_sock_recvmsg (net/bluetooth/af_bluetooth.c:295) bluetooth l2cap_sock_recvmsg (net/bluetooth/l2cap_sock.c:1212) bluetooth sock_read_iter (net/socket.c:1087) new_sync_read (./include/linux/fs.h:2052 fs/read_write.c:401) vfs_read (fs/read_write.c:482) ksys_read (fs/read_write.c:620) do_syscall_64 (arch/x86/entry/common.c:50 arch/x86/entry/common.c:80) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:120) Link: https://lore.kernel.org/linux-bluetooth/CAKErNvoqga1WcmoR3-0875esY6TVWFQDandbVZncSiuGPBQXLA@mail.gmail.com/T/#u Fixes: d2a7ac5d5d3a ("Bluetooth: Add the ERTM receive state machine") Fixes: 4b51dae96731 ("Bluetooth: Add streaming mode receive and incoming packet classifier") Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
1 parent ba9169f
Tip revision: 3aff8aaca4e36dc8b17eaa011684881a80238966 authored by Maxim Mikityanskiy on 04 October 2022, 21:27:18 UTC
Bluetooth: L2CAP: Fix use-after-free caused by l2cap_reassemble_sdu
Bluetooth: L2CAP: Fix use-after-free caused by l2cap_reassemble_sdu
Tip revision: 3aff8aa
File | Mode | Size |
---|---|---|
bpf | ||
cgroup | ||
configs | ||
debug | ||
dma | ||
entry | ||
events | ||
futex | ||
gcov | ||
irq | ||
kcsan | ||
livepatch | ||
locking | ||
module | ||
power | ||
printk | ||
rcu | ||
sched | ||
time | ||
trace | ||
.gitignore | -rw-r--r-- | 67 bytes |
Kconfig.freezer | -rw-r--r-- | 92 bytes |
Kconfig.hz | -rw-r--r-- | 1.7 KB |
Kconfig.locks | -rw-r--r-- | 4.9 KB |
Kconfig.preempt | -rw-r--r-- | 4.8 KB |
Makefile | -rw-r--r-- | 5.1 KB |
acct.c | -rw-r--r-- | 15.8 KB |
async.c | -rw-r--r-- | 9.2 KB |
audit.c | -rw-r--r-- | 64.8 KB |
audit.h | -rw-r--r-- | 10.7 KB |
audit_fsnotify.c | -rw-r--r-- | 5.3 KB |
audit_tree.c | -rw-r--r-- | 25.6 KB |
audit_watch.c | -rw-r--r-- | 13.7 KB |
auditfilter.c | -rw-r--r-- | 34.4 KB |
auditsc.c | -rw-r--r-- | 80.8 KB |
backtracetest.c | -rw-r--r-- | 1.9 KB |
bounds.c | -rw-r--r-- | 943 bytes |
capability.c | -rw-r--r-- | 14.8 KB |
cfi.c | -rw-r--r-- | 2.2 KB |
compat.c | -rw-r--r-- | 6.8 KB |
configs.c | -rw-r--r-- | 2.0 KB |
context_tracking.c | -rw-r--r-- | 23.2 KB |
cpu.c | -rw-r--r-- | 65.8 KB |
cpu_pm.c | -rw-r--r-- | 6.1 KB |
crash_core.c | -rw-r--r-- | 12.7 KB |
crash_dump.c | -rw-r--r-- | 1.1 KB |
cred.c | -rw-r--r-- | 24.2 KB |
delayacct.c | -rw-r--r-- | 7.0 KB |
dma.c | -rw-r--r-- | 3.3 KB |
exec_domain.c | -rw-r--r-- | 1.1 KB |
exit.c | -rw-r--r-- | 45.5 KB |
extable.c | -rw-r--r-- | 4.2 KB |
fail_function.c | -rw-r--r-- | 6.8 KB |
fork.c | -rw-r--r-- | 79.8 KB |
freezer.c | -rw-r--r-- | 5.4 KB |
gen_kheaders.sh | -rwxr-xr-x | 3.2 KB |
groups.c | -rw-r--r-- | 5.0 KB |
hung_task.c | -rw-r--r-- | 9.6 KB |
iomem.c | -rw-r--r-- | 4.7 KB |
irq_work.c | -rw-r--r-- | 7.5 KB |
jump_label.c | -rw-r--r-- | 20.4 KB |
kallsyms.c | -rw-r--r-- | 23.7 KB |
kallsyms_internal.h | -rw-r--r-- | 858 bytes |
kcmp.c | -rw-r--r-- | 5.4 KB |
kcov.c | -rw-r--r-- | 29.2 KB |
kexec.c | -rw-r--r-- | 7.3 KB |
kexec_core.c | -rw-r--r-- | 31.1 KB |
kexec_elf.c | -rw-r--r-- | 11.4 KB |
kexec_file.c | -rw-r--r-- | 32.3 KB |
kexec_internal.h | -rw-r--r-- | 1.3 KB |
kheaders.c | -rw-r--r-- | 1.6 KB |
kmod.c | -rw-r--r-- | 5.0 KB |
kprobes.c | -rw-r--r-- | 73.8 KB |
ksysfs.c | -rw-r--r-- | 6.3 KB |
kthread.c | -rw-r--r-- | 41.6 KB |
latencytop.c | -rw-r--r-- | 7.6 KB |
module_signature.c | -rw-r--r-- | 1.1 KB |
notifier.c | -rw-r--r-- | 17.9 KB |
nsproxy.c | -rw-r--r-- | 12.8 KB |
padata.c | -rw-r--r-- | 27.4 KB |
panic.c | -rw-r--r-- | 18.8 KB |
params.c | -rw-r--r-- | 23.1 KB |
pid.c | -rw-r--r-- | 18.2 KB |
pid_namespace.c | -rw-r--r-- | 11.3 KB |
profile.c | -rw-r--r-- | 13.2 KB |
ptrace.c | -rw-r--r-- | 36.9 KB |
range.c | -rw-r--r-- | 3.0 KB |
reboot.c | -rw-r--r-- | 32.1 KB |
regset.c | -rw-r--r-- | 1.9 KB |
relay.c | -rw-r--r-- | 29.9 KB |
resource.c | -rw-r--r-- | 51.7 KB |
resource_kunit.c | -rw-r--r-- | 4.3 KB |
rseq.c | -rw-r--r-- | 10.0 KB |
scftorture.c | -rw-r--r-- | 20.0 KB |
scs.c | -rw-r--r-- | 2.9 KB |
seccomp.c | -rw-r--r-- | 63.4 KB |
signal.c | -rw-r--r-- | 123.3 KB |
smp.c | -rw-r--r-- | 34.4 KB |
smpboot.c | -rw-r--r-- | 11.9 KB |
smpboot.h | -rw-r--r-- | 640 bytes |
softirq.c | -rw-r--r-- | 24.1 KB |
stackleak.c | -rw-r--r-- | 4.5 KB |
stacktrace.c | -rw-r--r-- | 10.4 KB |
static_call.c | -rw-r--r-- | 158 bytes |
static_call_inline.c | -rw-r--r-- | 12.5 KB |
stop_machine.c | -rw-r--r-- | 18.3 KB |
sys.c | -rw-r--r-- | 65.3 KB |
sys_ni.c | -rw-r--r-- | 10.2 KB |
sysctl-test.c | -rw-r--r-- | 10.7 KB |
sysctl.c | -rw-r--r-- | 59.8 KB |
task_work.c | -rw-r--r-- | 5.1 KB |
taskstats.c | -rw-r--r-- | 15.8 KB |
torture.c | -rw-r--r-- | 25.3 KB |
tracepoint.c | -rw-r--r-- | 20.3 KB |
tsacct.c | -rw-r--r-- | 5.0 KB |
ucount.c | -rw-r--r-- | 9.1 KB |
uid16.c | -rw-r--r-- | 5.1 KB |
uid16.h | -rw-r--r-- | 442 bytes |
umh.c | -rw-r--r-- | 15.2 KB |
up.c | -rw-r--r-- | 1.5 KB |
user-return-notifier.c | -rw-r--r-- | 1.3 KB |
user.c | -rw-r--r-- | 5.9 KB |
user_namespace.c | -rw-r--r-- | 35.7 KB |
usermode_driver.c | -rw-r--r-- | 4.3 KB |
utsname.c | -rw-r--r-- | 3.8 KB |
utsname_sysctl.c | -rw-r--r-- | 3.5 KB |
watch_queue.c | -rw-r--r-- | 17.2 KB |
watchdog.c | -rw-r--r-- | 22.6 KB |
watchdog_hld.c | -rw-r--r-- | 7.7 KB |
workqueue.c | -rw-r--r-- | 168.4 KB |
workqueue_internal.h | -rw-r--r-- | 2.4 KB |
Computing file changes ...