From nobody Sat Oct 18 02:17:41 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 D1C4BC4332F for ; Wed, 19 Oct 2022 08:52:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231768AbiJSIwL (ORCPT ); Wed, 19 Oct 2022 04:52:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231598AbiJSIsk (ORCPT ); Wed, 19 Oct 2022 04:48:40 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE82B8FD60; Wed, 19 Oct 2022 01:46:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5A674B822E6; Wed, 19 Oct 2022 08:43:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5CB0C433D6; Wed, 19 Oct 2022 08:42:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666168979; bh=dGaokMN2ZM66MraQW54O4r/eFRtqHnwl58/YQQQdXYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mJd1s1nOR7mL9TY8jt/Gwtp1uAwUFT9JvSt0dMDb5M91kYsLlLt2LCqwNalmXTe2m VotIMj3yGP7lJjj3HgxgpdXQnC8nAAej4/byA61BZoqTrJIvDAvQRMYWitdTXwje5r qFlQ7F97d1GneTtS9U6a39AS0+kq8rkeU3MJ39kU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hyunwoo Kim , Helge Deller Subject: [PATCH 6.0 110/862] fbdev: smscufx: Fix use-after-free in ufx_ops_open() Date: Wed, 19 Oct 2022 10:23:17 +0200 Message-Id: <20221019083254.787822786@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 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" From: Hyunwoo Kim commit 5610bcfe8693c02e2e4c8b31427f1bdbdecc839c upstream. A race condition may occur if the user physically removes the USB device while calling open() for this device node. This is a race condition between the ufx_ops_open() function and the ufx_usb_disconnect() function, which may eventually result in UAF. So, add a mutex to the ufx_ops_open() and ufx_usb_disconnect() functions to avoid race contidion of krefs. Signed-off-by: Hyunwoo Kim Cc: stable@vger.kernel.org Signed-off-by: Helge Deller Signed-off-by: Greg Kroah-Hartman --- drivers/video/fbdev/smscufx.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) --- a/drivers/video/fbdev/smscufx.c +++ b/drivers/video/fbdev/smscufx.c @@ -137,6 +137,8 @@ static int ufx_submit_urb(struct ufx_dat static int ufx_alloc_urb_list(struct ufx_data *dev, int count, size_t size= ); static void ufx_free_urb_list(struct ufx_data *dev); =20 +static DEFINE_MUTEX(disconnect_mutex); + /* reads a control register */ static int ufx_reg_read(struct ufx_data *dev, u32 index, u32 *data) { @@ -1071,9 +1073,13 @@ static int ufx_ops_open(struct fb_info * if (user =3D=3D 0 && !console) return -EBUSY; =20 + mutex_lock(&disconnect_mutex); + /* If the USB device is gone, we don't accept new opens */ - if (dev->virtualized) + if (dev->virtualized) { + mutex_unlock(&disconnect_mutex); return -ENODEV; + } =20 dev->fb_count++; =20 @@ -1097,6 +1103,8 @@ static int ufx_ops_open(struct fb_info * pr_debug("open /dev/fb%d user=3D%d fb_info=3D%p count=3D%d", info->node, user, info, dev->fb_count); =20 + mutex_unlock(&disconnect_mutex); + return 0; } =20 @@ -1741,6 +1749,8 @@ static void ufx_usb_disconnect(struct us { struct ufx_data *dev; =20 + mutex_lock(&disconnect_mutex); + dev =3D usb_get_intfdata(interface); =20 pr_debug("USB disconnect starting\n"); @@ -1761,6 +1771,8 @@ static void ufx_usb_disconnect(struct us kref_put(&dev->kref, ufx_free); =20 /* consider ufx_data freed */ + + mutex_unlock(&disconnect_mutex); } =20 static struct usb_driver ufx_driver =3D {