From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9F1B348C5E; Sat, 30 May 2026 16:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780159152; cv=none; b=e0zTQ/Eii3MYDnfBeUYsexKXrNpdIQGsL29K6D9uuAhXLpdir7G0NJbka4TJCVVO5qPWN1iwXh/z7qEC/LRV67re9GItLeUrFVrhyPyk/rS5QAFhWPVgabAqWI554yaIhON4IbbAwpWzj1df4ze0v2HU7PIr/wR0Htq/4cAhGmY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780159152; c=relaxed/simple; bh=aYVIN9wGwC9w5YTBkxzgdxl7hlIP2ct2KpC9t4q5Js8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EOsRZyImSayhz39lXZOA76WaWPYkjEc7ZpC9WYx09/cL4ITMcB2aY6kCRScA3lSQWjv/94j74Dugb5SzJMviVcoKm3S2KE4+/XGmB2UJti1mhoG3jA+y+dIc9hDKOIzZx/NqouMW2W0S3fDHA96vzqca5P36x+ZC1gF/cJs1IC4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=C3KPhCBV; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="C3KPhCBV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23AB91F00893; Sat, 30 May 2026 16:39:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780159150; bh=YxluW7DsdfupGkLPhaclml5Nu0IcJJEnSjFXWXCSDfI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=C3KPhCBVTj/qwuJjAj/7SjcmjvV1ClSuyFqYTztG/0Iy0xkKB7wyv8+VXv0iTqPbm pQO8bH688T4VMSYVpmwN3tlnNLS3Igcj/mhwTfssuXdTwQNcnIeIYf9WyD1pmaUXyA eBJjoP3VMjm4yuJVcnU5ld7TAwjn+oStQLAeDeMQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+47321e8fd5a4c84088db@syzkaller.appspotmail.com, Jeongjun Park , Hans Verkuil Subject: [PATCH 6.1 105/969] media: as102: fix to not free memory after the device is registered in as102_usb_probe() Date: Sat, 30 May 2026 17:53:49 +0200 Message-ID: <20260530160303.219438887@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260530160300.485627683@linuxfoundation.org> References: <20260530160300.485627683@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jeongjun Park commit 8bd29dbe03fc5b0f039ab2395ff37b64236d2f0c upstream. In as102_usb driver, the following race condition occurs: ``` CPU0 CPU1 as102_usb_probe() kzalloc(); // alloc as102_dev_t .... usb_register_dev(); fd = sys_open("/path/to/dev"); // open as102 fd .... usb_deregister_dev(); .... kfree(); // free as102_dev_t .... sys_close(fd); as102_release() // UAF!! as102_usb_release() kfree(); // DFB!! ``` When a USB character device registered with usb_register_dev() is later unregistered (via usb_deregister_dev() or disconnect), the device node is removed so new open() calls fail. However, file descriptors that are already open do not go away immediately: they remain valid until the last reference is dropped and the driver's .release() is invoked. In as102, as102_usb_probe() calls usb_register_dev() and then, on an error path, does usb_deregister_dev() and frees as102_dev_t right away. If userspace raced a successful open() before the deregistration, that open FD will later hit as102_release() --> as102_usb_release() and access or free as102_dev_t again, occur a race to use-after-free and double-free vuln. The fix is to never kfree(as102_dev_t) directly once usb_register_dev() has succeeded. After deregistration, defer freeing memory to .release(). In other words, let release() perform the last kfree when the final open FD is closed. Cc: Reported-by: syzbot+47321e8fd5a4c84088db@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=47321e8fd5a4c84088db Fixes: cd19f7d3e39b ("[media] as102: fix leaks at failure paths in as102_usb_probe()") Signed-off-by: Jeongjun Park Signed-off-by: Hans Verkuil Signed-off-by: Greg Kroah-Hartman --- drivers/media/usb/as102/as102_usb_drv.c | 2 ++ 1 file changed, 2 insertions(+) --- a/drivers/media/usb/as102/as102_usb_drv.c +++ b/drivers/media/usb/as102/as102_usb_drv.c @@ -405,7 +405,9 @@ static int as102_usb_probe(struct usb_in failed_dvb: as102_free_usb_stream_buffer(as102_dev); failed_stream: + usb_set_intfdata(intf, NULL); usb_deregister_dev(intf, &as102_usb_class_driver); + return ret; failed: usb_put_dev(as102_dev->bus_adap.usb_dev); usb_set_intfdata(intf, NULL);