From nobody Mon Sep 8 23:56:01 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3327FC7EE23 for ; Sat, 25 Feb 2023 18:29:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229632AbjBYS3Z (ORCPT ); Sat, 25 Feb 2023 13:29:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229569AbjBYS3X (ORCPT ); Sat, 25 Feb 2023 13:29:23 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C463E058 for ; Sat, 25 Feb 2023 10:28:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677349716; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Zv/xQL8kguH2DCyuojYf/vRV+UjJ6qJW7G0m4Ktfp5I=; b=S2Zr4YbA6RSEwvFIkSmr3uRzqDdPLuDRZc57RlHxyIzTnAuZOX3tNeJFYaiRPkPFepXWNC KaDHyaEiRwNSTjwydZjhsCjGa0H2U06TTndtqBeUOlAK7oRmpnjmuXd9NHKZGj9RzkdCyA 2wLXHIXw7/0tUWSg6/pKSneenCHDbUQ= Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-28-GlUOS5pNOHGJqAC_CZHgDA-1; Sat, 25 Feb 2023 13:28:35 -0500 X-MC-Unique: GlUOS5pNOHGJqAC_CZHgDA-1 Received: by mail-pl1-f200.google.com with SMTP id z1-20020a170902d54100b00198bc9ba4edso1348941plf.21 for ; Sat, 25 Feb 2023 10:28:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Zv/xQL8kguH2DCyuojYf/vRV+UjJ6qJW7G0m4Ktfp5I=; b=P6r5Uu8vjNEVmsVDzJNtlZA9gSJuEWefikIHR7PflQmuFn8BuSl8DAbd9DJWLAMK31 PhtIExaJiaFOWJ1JnHXqBdWxm73bxU/XzV6Pa60GGLtnFa6l0F4wZlhCxn7zb5n2CwyK awrqoYxf9azWiNrqQThOELmzITgEUHxbyr8ijY2BpSpIXodKlI33JzDb7+io3p7dCxbr uNCGnW4Qo0/StKcTV7qfoIRXoaQYSI7coyf4Kabx1vss1cm04z/j6I94MZRTKtmfwPPN 8/DGVZjMU2W39T89zD+tiI4fDl4/6MUM9MTXFg6hhJS5wekwJvOTEX2aGw9zDTgW3Cge jS+A== X-Gm-Message-State: AO0yUKXLfXx3ChLq4VKpzuj94SpBPEpQ/vP6QPM0HR7sYW61gyAV6ai0 NFkP3bze6sO25z9odIYdKVs7F32hW8Z4NyXkaLvoNTHm7n4O7UOGUTB+bn/ZARpAfxFCz6/uOS2 zcWvG1PVmccI2M2Sb1YmI/yd7 X-Received: by 2002:a17:902:f64b:b0:19a:b588:6fe2 with SMTP id m11-20020a170902f64b00b0019ab5886fe2mr3116031plg.13.1677349714051; Sat, 25 Feb 2023 10:28:34 -0800 (PST) X-Google-Smtp-Source: AK7set8yuR7pxdQ8IMkY1K+3yOajNqaFNAzNJnxZdw75CwKi770/K/ZEOAKP5zhvvS2KVZohmIAXeQ== X-Received: by 2002:a17:902:f64b:b0:19a:b588:6fe2 with SMTP id m11-20020a170902f64b00b0019ab5886fe2mr3116018plg.13.1677349713689; Sat, 25 Feb 2023 10:28:33 -0800 (PST) Received: from localhost.localdomain ([240d:1a:c0d:9f00:ca6:1aff:fead:cef4]) by smtp.gmail.com with ESMTPSA id a2-20020a170902ee8200b0019926c7757asm1543214pld.289.2023.02.25.10.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 10:28:33 -0800 (PST) From: Shigeru Yoshida To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Shigeru Yoshida , syzbot+b563d33852b893653a9e@syzkaller.appspotmail.com Subject: [PATCH net] net: caif: Fix use-after-free in cfusbl_device_notify() Date: Sun, 26 Feb 2023 03:28:20 +0900 Message-Id: <20230225182820.4048336-1-syoshida@redhat.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/cai= f_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 Goo= gle 01/01/2011 Workqueue: netns cleanup_net Call Trace: __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 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. Link: https://syzkaller.appspot.com/bug?id=3Dc3bfd8e2450adab3bffe4d80821fbb= ced600407f [1] Reported-by: syzbot+b563d33852b893653a9e@syzkaller.appspotmail.com Signed-off-by: Shigeru Yoshida --- 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 ebc202ffdd8d..bf61ea4b8132 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; =20 + if (what =3D=3D NETDEV_UNREGISTER && dev->reg_state >=3D NETREG_UNREGISTE= RED) + 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") =3D=3D 0)) --=20 2.39.0