From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
patches@lists.linux.dev,
"sjur.brandeland@stericsson.com" <sjur.brandeland@stericsson.com>,
syzbot+b563d33852b893653a9e@syzkaller.appspotmail.com,
Shigeru Yoshida <syoshida@redhat.com>,
Jakub Kicinski <kuba@kernel.org>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.10 042/104] net: caif: Fix use-after-free in cfusbl_device_notify()
Date: Wed, 15 Mar 2023 13:12:13 +0100 [thread overview]
Message-ID: <20230315115733.761542328@linuxfoundation.org> (raw)
In-Reply-To: <20230315115731.942692602@linuxfoundation.org>
From: Shigeru Yoshida <syoshida@redhat.com>
[ Upstream commit 9781e98a97110f5e76999058368b4be76a788484 ]
syzbot reported use-after-free in cfusbl_device_notify() [1]. This
causes a stack trace like below:
BUG: KASAN: use-after-free in cfusbl_device_notify+0x7c9/0x870 net/caif/caif_usb.c:138
Read of size 8 at addr ffff88807ac4e6f0 by task kworker/u4:6/1214
CPU: 0 PID: 1214 Comm: kworker/u4:6 Not tainted 5.19.0-rc3-syzkaller-00146-g92f20ff72066 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: netns cleanup_net
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
print_address_description.constprop.0.cold+0xeb/0x467 mm/kasan/report.c:313
print_report mm/kasan/report.c:429 [inline]
kasan_report.cold+0xf4/0x1c6 mm/kasan/report.c:491
cfusbl_device_notify+0x7c9/0x870 net/caif/caif_usb.c:138
notifier_call_chain+0xb5/0x200 kernel/notifier.c:87
call_netdevice_notifiers_info+0xb5/0x130 net/core/dev.c:1945
call_netdevice_notifiers_extack net/core/dev.c:1983 [inline]
call_netdevice_notifiers net/core/dev.c:1997 [inline]
netdev_wait_allrefs_any net/core/dev.c:10227 [inline]
netdev_run_todo+0xbc0/0x10f0 net/core/dev.c:10341
default_device_exit_batch+0x44e/0x590 net/core/dev.c:11334
ops_exit_list+0x125/0x170 net/core/net_namespace.c:167
cleanup_net+0x4ea/0xb00 net/core/net_namespace.c:594
process_one_work+0x996/0x1610 kernel/workqueue.c:2289
worker_thread+0x665/0x1080 kernel/workqueue.c:2436
kthread+0x2e9/0x3a0 kernel/kthread.c:376
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:302
</TASK>
When unregistering a net device, unregister_netdevice_many_notify()
sets the device's reg_state to NETREG_UNREGISTERING, calls notifiers
with NETDEV_UNREGISTER, and adds the device to the todo list.
Later on, devices in the todo list are processed by netdev_run_todo().
netdev_run_todo() waits devices' reference count become 1 while
rebdoadcasting NETDEV_UNREGISTER notification.
When cfusbl_device_notify() is called with NETDEV_UNREGISTER multiple
times, the parent device might be freed. This could cause UAF.
Processing NETDEV_UNREGISTER multiple times also causes inbalance of
reference count for the module.
This patch fixes the issue by accepting only first NETDEV_UNREGISTER
notification.
Fixes: 7ad65bf68d70 ("caif: Add support for CAIF over CDC NCM USB interface")
CC: sjur.brandeland@stericsson.com <sjur.brandeland@stericsson.com>
Reported-by: syzbot+b563d33852b893653a9e@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?id=c3bfd8e2450adab3bffe4d80821fbbced600407f [1]
Signed-off-by: Shigeru Yoshida <syoshida@redhat.com>
Link: https://lore.kernel.org/r/20230301163913.391304-1-syoshida@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
net/caif/caif_usb.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/caif/caif_usb.c b/net/caif/caif_usb.c
index b02e1292f7f19..24488a4e2d26e 100644
--- a/net/caif/caif_usb.c
+++ b/net/caif/caif_usb.c
@@ -134,6 +134,9 @@ static int cfusbl_device_notify(struct notifier_block *me, unsigned long what,
struct usb_device *usbdev;
int res;
+ if (what == NETDEV_UNREGISTER && dev->reg_state >= NETREG_UNREGISTERED)
+ return 0;
+
/* Check whether we have a NCM device, and find its VID/PID. */
if (!(dev->dev.parent && dev->dev.parent->driver &&
strcmp(dev->dev.parent->driver->name, "cdc_ncm") == 0))
--
2.39.2
next prev parent reply other threads:[~2023-03-15 12:24 UTC|newest]
Thread overview: 114+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-15 12:11 [PATCH 5.10 000/104] 5.10.175-rc1 review Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 001/104] fs: prevent out-of-bounds array speculation when closing a file descriptor Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 002/104] fork: allow CLONE_NEWTIME in clone3 flags Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 003/104] x86/CPU/AMD: Disable XSAVES on AMD family 0x17 Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 004/104] drm/amdgpu: fix error checking in amdgpu_read_mm_registers for soc15 Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 005/104] drm/connector: print max_requested_bpc in state debugfs Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 006/104] ext4: fix cgroup writeback accounting with fs-layer encryption Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 007/104] ext4: fix RENAME_WHITEOUT handling for inline directories Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 008/104] ext4: fix another off-by-one fsmap error on 1k block filesystems Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 009/104] ext4: move where set the MAY_INLINE_DATA flag is set Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 010/104] ext4: fix WARNING in ext4_update_inline_data Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 011/104] ext4: zero i_disksize when initializing the bootloader inode Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 012/104] nfc: change order inside nfc_se_io error path Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 013/104] udf: Fix off-by-one error when discarding preallocation Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 014/104] irq: Fix typos in comments Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 015/104] irqdomain: Look for existing mapping only once Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 016/104] irqdomain: Refactor __irq_domain_alloc_irqs() Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 017/104] irqdomain: Fix mapping-creation race Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 018/104] irqdomain: Change the type of size in __irq_domain_add() to be consistent Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 019/104] irqdomain: Fix domain registration race Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 020/104] iommu/vt-d: Fix lockdep splat in intel_pasid_get_entry() Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 021/104] iommu/vt-d: Fix PASID directory pointer coherency Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 022/104] arm64: efi: Make efi_rt_lock a raw_spinlock Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 023/104] RISC-V: Avoid dereferening NULL regs in die() Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 024/104] riscv: Avoid enabling interrupts " Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 025/104] riscv: Add header include guards to insn.h Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 026/104] scsi: core: Remove the /proc/scsi/${proc_name} directory earlier Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 027/104] ext4: Fix possible corruption when moving a directory Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 028/104] drm/nouveau/kms/nv50-: remove unused functions Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 029/104] drm/nouveau/kms/nv50: fix nv50_wndw_new_ prototype Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 030/104] drm/msm: Fix potential invalid ptr free Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 031/104] drm/msm/a5xx: fix setting of the CP_PREEMPT_ENABLE_LOCAL register Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 032/104] drm/msm: Document and rename preempt_lock Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 033/104] drm/msm/a5xx: fix the emptyness check in the preempt code Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 034/104] drm/msm/a5xx: fix context faults during ring switch Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 035/104] bgmac: fix *initial* chip reset to support BCM5358 Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 036/104] nfc: fdp: add null check of devm_kmalloc_array in fdp_nci_i2c_read_device_properties Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 037/104] powerpc: dts: t1040rdb: fix compatible string for Rev A boards Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 038/104] ila: do not generate empty messages in ila_xlat_nl_cmd_get_mapping() Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 039/104] selftests: nft_nat: ensuring the listening side is up before starting the client Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 040/104] net: usb: lan78xx: Remove lots of set but unused ret variables Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 041/104] net: lan78xx: fix accessing the LAN7800s internal phy specific registers from the MAC driver Greg Kroah-Hartman
2023-03-15 12:12 ` Greg Kroah-Hartman [this message]
2023-03-15 12:12 ` [PATCH 5.10 043/104] net: stmmac: add to set device wake up flag when stmmac init phy Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 044/104] net: phylib: get rid of unnecessary locking Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 045/104] bnxt_en: Avoid order-5 memory allocation for TPA data Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 046/104] netfilter: ctnetlink: revert to dumping mark regardless of event type Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 047/104] netfilter: tproxy: fix deadlock due to missing BH disable Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 048/104] btf: fix resolving BTF_KIND_VAR after ARRAY, STRUCT, UNION, PTR Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 049/104] net: ethernet: mtk_eth_soc: fix RX data corruption issue Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 050/104] scsi: megaraid_sas: Update max supported LD IDs to 240 Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 051/104] platform: x86: MLX_PLATFORM: select REGMAP instead of depending on it Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 052/104] net/smc: fix fallback failed while sendmsg with fastopen Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 053/104] SUNRPC: Fix a server shutdown leak Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 054/104] riscv: Use READ_ONCE_NOCHECK in imprecise unwinding stack mode Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 055/104] RISC-V: Dont check text_mutex during stop_machine Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 056/104] ext4: Fix deadlock during directory rename Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 057/104] iommu/amd: Add a length limitation for the ivrs_acpihid command-line parameter Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 058/104] PCI/PM: Define pci_restore_standard_config() only for CONFIG_PM_SLEEP Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 059/104] watch_queue: fix IOC_WATCH_QUEUE_SET_SIZE alloc error paths Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 060/104] tpm/eventlog: Dont abort tpm_read_log on faulty ACPI address Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 061/104] block, bfq: fix possible uaf for bfqq->bic Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 062/104] block, bfq: fix uaf for bfqq in bfq_exit_icq_bfqq Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 063/104] block/bfq-iosched.c: use "false" rather than "BLK_RW_ASYNC" Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 064/104] block, bfq: replace 0/1 with false/true in bic apis Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 065/104] block, bfq: fix uaf for bfqq in bic_set_bfqq() Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 066/104] clk: qcom: mmcc-apq8084: remove spdm clocks Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 067/104] MIPS: Fix a compilation issue Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 068/104] powerpc: Check !irq instead of irq == NO_IRQ and remove NO_IRQ Greg Kroah-Hartman
2023-03-15 12:31 ` Christophe Leroy
2023-03-15 12:12 ` [PATCH 5.10 069/104] powerpc/kcsan: Exclude udelay to prevent recursive instrumentation Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 070/104] alpha: fix R_ALPHA_LITERAL reloc for large modules Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 071/104] macintosh: windfarm: Use unsigned type for 1-bit bitfields Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 072/104] PCI: Add SolidRun vendor ID Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 073/104] PCI: Avoid FLR for SolidRun SNET DPU rev 1 Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 074/104] scripts: handle BrokenPipeError for python scripts Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 075/104] media: ov5640: Fix analogue gain control Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 076/104] media: rc: gpio-ir-recv: add remove function Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 077/104] ipmi/watchdog: replace atomic_add() and atomic_sub() Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 078/104] ipmi:watchdog: Set panic count to proper value on a panic Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 079/104] skbuff: Fix nfct leak on napi stolen Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 080/104] drm/i915: Dont use BAR mappings for ring buffers with LLC Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 081/104] sched/uclamp: Make task_fits_capacity() use util_fits_cpu() Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 082/104] sched/uclamp: Fix fits_capacity() check in feec() Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 083/104] sched/uclamp: Make select_idle_capacity() use util_fits_cpu() Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 084/104] sched/uclamp: Make asym_fits_capacity() " Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 085/104] sched/uclamp: Make cpu_overutilized() " Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 086/104] sched/uclamp: Cater for uclamp in find_energy_efficient_cpu()s early exit condition Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 087/104] sched/fair: Detect capacity inversion Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 088/104] sched/fair: Consider capacity inversion in util_fits_cpu() Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 089/104] sched/uclamp: Fix a uninitialized variable warnings Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 090/104] sched/fair: Fixes for capacity inversion detection Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 091/104] ext4: refactor ext4_free_blocks() to pull out ext4_mb_clear_bb() Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 092/104] ext4: add ext4_sb_block_valid() refactored out of ext4_inode_block_valid() Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 093/104] ext4: add strict range checks while freeing blocks Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 094/104] ext4: block range must be validated before use in ext4_mb_clear_bb() Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 095/104] arch: fix broken BuildID for arm64 and riscv Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 096/104] powerpc/vmlinux.lds: Define RUNTIME_DISCARD_EXIT Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 097/104] powerpc/vmlinux.lds: Dont discard .rela* for relocatable builds Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 098/104] s390: define RUNTIME_DISCARD_EXIT to fix link error with GNU ld < 2.36 Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 099/104] sh: define RUNTIME_DISCARD_EXIT Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 100/104] UML: " Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 101/104] KVM: nVMX: Dont use Enlightened MSR Bitmap for L3 Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 102/104] KVM: VMX: Introduce vmx_msr_bitmap_l01_changed() helper Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 103/104] KVM: VMX: Fix crash due to uninitialized current_vmcs Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 104/104] s390/dasd: add missing discipline function Greg Kroah-Hartman
2023-03-15 14:21 ` [PATCH 5.10 000/104] 5.10.175-rc1 review Chris Paterson
2023-03-15 14:23 ` Guenter Roeck
2023-03-15 14:26 ` Guenter Roeck
2023-03-16 7:56 ` Greg Kroah-Hartman
2023-03-15 20:18 ` Florian Fainelli
2023-03-15 23:17 ` Daniel Díaz
2023-03-15 23:58 ` Shuah Khan
2023-03-16 0:00 ` Shuah Khan
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=20230315115733.761542328@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=kuba@kernel.org \
--cc=patches@lists.linux.dev \
--cc=sashal@kernel.org \
--cc=sjur.brandeland@stericsson.com \
--cc=stable@vger.kernel.org \
--cc=syoshida@redhat.com \
--cc=syzbot+b563d33852b893653a9e@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;
as well as URLs for NNTP newsgroup(s).