From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5DB472D7DDA; Mon, 27 Oct 2025 19:15:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761592539; cv=none; b=Ce9vyfJz4Jbbh16NeF3xGthHxqKXupbs1VF0MnIoEcCTCjZoePehSs5iM17DKNNRnYI0bP5MH2g3f4ajcyvZlrSZUDTe6N9oEl8tzC3Hi4wa+WIFRU4hyR6IIvq1lTj72Pi234eW1qiu07PIj42XTp0vreqRkiZezzzQlWk5Sgk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761592539; c=relaxed/simple; bh=TGkRWxxSSHl9scq5lAjnBxahVQQ1ULanb0VTecItDIc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fkr4zdlnlfXmk4Re2USzCRHy5LeTGZu97YMtMBHcengTE7UW0vrnRJk1i8CqXJJDgm5jIlXVmFpkFfbDYxyi8Pzt2iMoftHWr3WHihHI3gGBHPIbBH5Al8LXTQV9ZMwbrjqf0GygDHcYl5vYKEWjky/WQ8zAsehMF8T7CanTwZQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=bl7kw4tM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="bl7kw4tM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB86EC4CEF1; Mon, 27 Oct 2025 19:15:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1761592539; bh=TGkRWxxSSHl9scq5lAjnBxahVQQ1ULanb0VTecItDIc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bl7kw4tMoqc0zArLAlF8jDV5v1IKquOuHqdzY1ZJk2N9EyoISNTNhp/7l15Er7/Be dpYunzM5QF5ZDNR30WbVLAiIwWQvXqIiBeEVnS8GF+EDd6/c2XkbaN2K58DfiB0paU Yibqfcub2qlJtp8JCyzzJTGGTtTWnN2eS3jHshQQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+916742d5d24f6c254761@syzkaller.appspotmail.com, stable , Victoria Votokina Subject: [PATCH 6.1 113/157] most: usb: Fix use-after-free in hdm_disconnect Date: Mon, 27 Oct 2025 19:36:14 +0100 Message-ID: <20251027183504.280932677@linuxfoundation.org> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251027183501.227243846@linuxfoundation.org> References: <20251027183501.227243846@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: Victoria Votokina commit 4b1270902609ef0d935ed2faa2ea6d122bd148f5 upstream. hdm_disconnect() calls most_deregister_interface(), which eventually unregisters the MOST interface device with device_unregister(iface->dev). If that drops the last reference, the device core may call release_mdev() immediately while hdm_disconnect() is still executing. The old code also freed several mdev-owned allocations in hdm_disconnect() and then performed additional put_device() calls. Depending on refcount order, this could lead to use-after-free or double-free when release_mdev() ran (or when unregister paths also performed puts). Fix by moving the frees of mdev-owned allocations into release_mdev(), so they happen exactly once when the device is truly released, and by dropping the extra put_device() calls in hdm_disconnect() that are redundant after device_unregister() and most_deregister_interface(). This addresses the KASAN slab-use-after-free reported by syzbot in hdm_disconnect(). See report and stack traces in the bug link below. Reported-by: syzbot+916742d5d24f6c254761@syzkaller.appspotmail.com Cc: stable Closes: https://syzkaller.appspot.com/bug?extid=916742d5d24f6c254761 Fixes: 97a6f772f36b ("drivers: most: add USB adapter driver") Signed-off-by: Victoria Votokina Link: https://patch.msgid.link/20251010105241.4087114-2-Victoria.Votokina@kaspersky.com Signed-off-by: Greg Kroah-Hartman --- drivers/most/most_usb.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) --- a/drivers/most/most_usb.c +++ b/drivers/most/most_usb.c @@ -929,6 +929,10 @@ static void release_mdev(struct device * { struct most_dev *mdev = to_mdev_from_dev(dev); + kfree(mdev->busy_urbs); + kfree(mdev->cap); + kfree(mdev->conf); + kfree(mdev->ep_address); kfree(mdev); } /** @@ -1121,13 +1125,6 @@ static void hdm_disconnect(struct usb_in if (mdev->dci) device_unregister(&mdev->dci->dev); most_deregister_interface(&mdev->iface); - - kfree(mdev->busy_urbs); - kfree(mdev->cap); - kfree(mdev->conf); - kfree(mdev->ep_address); - put_device(&mdev->dci->dev); - put_device(&mdev->dev); } static int hdm_suspend(struct usb_interface *interface, pm_message_t message)