From nobody Tue Sep 29 09:08:36 2026 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB8593D171F for ; Mon, 10 Aug 2026 12:12:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786363938; cv=none; b=iNSPvt04FGqp1OckbOERmMD9oaNiDQWM3sMB9u2Jb7BIWbGso1zcj65O6WCkI5qEcr8hfN1nV+ehUyGsIre/SOi+OfL2Uvjf4r3zLpDxJMPryikOMi4zHmcq7jn19daJUnqIFjPFvZpWvavFOfAscTYZieKu78zR5bfeCRhxXlA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786363938; c=relaxed/simple; bh=n5t0F7BzvSgZNkQJ/YimmEsQrhjAMXpb16NZlz8/d+c=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=aYwRAYCVPG+EwWwO+gnpgiRt5xR8r0QrQc0CzNpuxae2Fh3Axqd87FJ1h3/C7R1xofMKvwmJdQA77wuc+7bZ94cv4xNZ+RaA4hqHMlXL/Lhqx2HAwOkmNhgnBCVn0Rf0aMxS9CBb2TcVn6AeUyWfhgjf51VcQ2TuO7lEeabcK5I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PhUxFIVc; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PhUxFIVc" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4954a2e73a9so10832735e9.3 for ; Mon, 10 Aug 2026 05:12:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786363935; x=1786968735; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=vSwL7aNN7hYKFTp1kfxgml5r4vyPUCqPEJX0Du3qOqU=; b=PhUxFIVc/mq3gr7q9AmqhOvZQtBz0K1YA/0aKVNE0v1fb5VW8l8scvoXwYb9sz4TO+ BTb6ywr2TppJpXQLZH59MjvBV62FoAhC2+bvamOwi95lzLgnvSfYb1onSM8oU7uRJ6lW 6Il1v1cEDr6xNz7K2CdaJ+mIzbJGFqsM5RI+a9Shlj0xYOSyR1GF8lSAZQeDSXTe0Tvg Z2wY/kk7z+/2Z1PXiirXOWHK6N1Gj51n1IOoRkzKJ/eaE0mMe0pkNeULaJZbva/hKv0n 8BayK+k3/RKc2YKldjkoTE+HAI5OSRAe6RRXQ+K9mKl4KqUQfyrqrPfwgN03Ea8Hfhyc fxtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786363935; x=1786968735; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=vSwL7aNN7hYKFTp1kfxgml5r4vyPUCqPEJX0Du3qOqU=; b=d4ydfUU0Pz/jzu/5W0X1q+CAeOOjgizAQ52X3Dc7xI0cC+rx4Ejk81VHgEmLzAKyja qRXpGOP0uz8Pasl4wX5KW+mubQxQCC+YG1oaNtoSr7lw6tp3H9TLWthc1Xxc5UGlIjGd yNhInTGcf3GkXdfl2Ru6o5HOtVwoamkTN9/X0VaD7EDF4c2YB2GhBYaEGgCgXVQqfVxF 1znx5kjA/ccoAUGcoCALTB9wmMIgQVXT2vBuhj1qXpAMG29LMWlKImDbN2Tc6v76oqOp LYEQ2w6TYY7unBBQhb3efkra6OmpOrzZ3xM0dqFp3lt9pB1sZgZpvuZ8UKYlOzCXUMbl AIfA== X-Gm-Message-State: AOJu0Yw/Oux0I7SY5DLfuCdNJmdb609GOPnkz2xEaajP14N2oiup6fGg vNYD64yc6eAmNC1mH9jUHOdNdGR9B1A3hU8mYmLVZAiN/7V5LX5gJQeW X-Gm-Gg: AR+sD11I+ot7dIajG3DjVDmhWxBZYtBPwcLCmzJQZiI4UrKQC3Z3ejkjj0/c/efwXoj 8xAeH3Pmsteak3DnFCzyBicDUqVQdKvx5bWTCK28O1vk4EojDhc9/RcU/+maHehZbJ8SJokSnIN vYJci3jRLItx1JWBcVe4IAofS2zOTGzGeVDVqoUfUQLylD4MEduiN37XlCAP0Q7ryqN+cNO2wzD pUzyn5R8ieFCNUl6B23+Zd5ld3P6NoFQnnzmo18nbo+YRQMt+I1PVyQ3sErhhf+sK5d0lxniueZ 3e6hE4vWCcytXOPqPxJpL/Kz7SKkw/3q9i4X6U8H+//4c40XXFa4HF4pp4LK9YkN1Dk3iefDP8k nmwCYZ4SCwEOCnObcra8sNnPknwTVC2HcdXdBhEMpzq8sBNFTOTF1vUbZfWc6cnyjuMBUoGROH3 cal1x9J2KRwbb464LLEhzRmKNcwR0Zdh/InhoXx4cDGv63zWMLmxPJM7Rk0Q== X-Received: by 2002:a05:600c:840f:b0:496:c1f3:e8fb with SMTP id 5b1f17b1804b1-4994e71ffafmr549042025e9.8.1786363934643; Mon, 10 Aug 2026 05:12:14 -0700 (PDT) Received: from kali ([135.136.16.250]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4995e9f9424sm254883645e9.8.2026.08.10.05.12.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2026 05:12:14 -0700 (PDT) From: =?UTF-8?q?Miguel=20Pe=C3=B1aranda?= To: linux-usb@vger.kernel.org Cc: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH] usb: usbfs: fix use-after-free of usb_device in usbdev_release() Date: Mon, 10 Aug 2026 14:12:09 +0200 Message-ID: <20260810121209.795089-1-mig.penaranda07@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable usbdev_release() drops its reference to the struct usb_device before draining the list of completed async URBs, but that drain path reads back through the same object: free_async() calls dec_usb_memory_use_count() for any URB whose buffer came from the usbfs mmap() region, and its first statement is bus_to_hcd(ps->dev->bus). After a disconnect the usbfs reference can be the last one, in which case usb_put_dev() frees the device and the subsequent loop reads offset 80 of freed memory and uses the result as a struct usb_hcd *, which hcd_buffer_free_pages() then dereferences. This is reachable by an unprivileged process that has read/write access to a /dev/bus/usb node: mmap() the fd, submit one URB with a buffer inside the mapping, wait for the device to be unplugged, then munmap() and close(). It reproduces on every attempt rather than being a race, because a live MAP_SHARED vma holds a reference on the struct file, so usbdev_release() cannot run until the last vma is gone and the freeing branch of dec_usb_memory_use_count() is always taken. BUG: KASAN: slab-use-after-free in dec_usb_memory_use_count+0x3ae/0x410 Read of size 8 at addr ffff8880122ee050 by task poc/769 CPU: 1 UID: 1000 PID: 769 Comm: poc Tainted: G B 6.12.94 #3 Call Trace: dec_usb_memory_use_count+0x3ae/0x410 free_async+0x2aa/0x4f0 usbdev_release+0x375/0x460 __fput+0x3ea/0xb50 __x64_sys_close+0x86/0x100 Allocated by task 11: usb_alloc_dev+0x55/0xd90 hub_event+0x2524/0x43d0 Freed by task 769: kfree+0x121/0x360 device_release+0xd2/0x280 usb_put_dev+0x23/0x30 usbdev_release+0x2d8/0x460 Release the device reference after the drain loop instead. Nothing between the two points requires it to have been dropped. Fixes: f7d34b445abc ("USB: Add support for usbfs zerocopy.") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5 Signed-off-by: Miguel Pe=C3=B1aranda Reviewed-by: Alan Stern --- drivers/usb/core/devio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index e191934..486ced7 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c @@ -1113,7 +1113,6 @@ static int usbdev_release(struct inode *inode, struct= file *file) if (!ps->suspend_allowed) usb_autosuspend_device(dev); usb_unlock_device(dev); - usb_put_dev(dev); put_pid(ps->disc_pid); put_cred(ps->cred); =20 @@ -1122,6 +1121,7 @@ static int usbdev_release(struct inode *inode, struct= file *file) free_async(as); as =3D async_getcompleted(ps); } + usb_put_dev(dev); =20 kfree(ps); return 0; --=20 2.53.0