From patchwork Mon Oct 24 11:30:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8621 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp420253wru; Mon, 24 Oct 2022 05:17:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7zzXwN0/es2fINaYoFTwbGnqMTmt2kk/r0jGGhC3wxlsX9R9vPQsATdl9Gm+JwpBqN0jt3 X-Received: by 2002:a17:906:6a17:b0:794:f0e8:1918 with SMTP id qw23-20020a1709066a1700b00794f0e81918mr21793454ejc.474.1666613871410; Mon, 24 Oct 2022 05:17:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666613871; cv=none; d=google.com; s=arc-20160816; b=NbCGmDvn64h6KdeNtATnAky41T9QaR05QzUCPGq8JpauDlB9SmWnYcYELN8jlGr0q7 TMlnVxvLX7uvaO7KcasWumm5gMQY4z2+XJqRWl0R49kuy9xITGqjbrV6KcFs7hsXsw12 BTHE3G2D8ktVzxhp9F4WEplrcR9NvZzTVMR3vHWJwGa6er8EjlDvcnwE5Q6uDeaoY4OP BwfEv6HKnz6b+HI4N/jQjfphcegfU7QAW21y1t2cuHctlyTPLXlSfa7n0mvDp5IKbm58 a5tjgTHTuYdOboeFateu2ZixasfGwreWvSlKiFyVhaleEhIfaZNdK3Sf87RZpes0M1yy WN5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oAFkOlfgk2U4eZMXGrVEVXILCkNMqbza1qPpoSS74ns=; b=pi2RAgE+szXI3DJAaznpcTucWtiyjs7ksWeaqyuyZXvC7M+Ow2UUw5Cgbd6BrbeHvw HRHuZRZfldvb0XDVIc2+CmqJTNQ/vcCfB/iwovhl5nzSKCxk6I9YtFwLpofUSBM4iEVH UutL10Gz08KGU+ZuTQeQT1NVF2Fbo7no/JRI3hCUNOz6kl/ksuLCNU1F08sM1trH9i0t jEaB6YrYz7WNnkZ71+TIHkpymuIknjXJfQiH4OFYypN8k0QRjw78F3yURbwBPO5Aiwe6 fK6uZWM4/2TlBQIKCHHprOroWU8y9Ytd6jgmTgd5adEkZXs3kQqr5nyjNjdwGZzLnmlC uoJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DB5JLbN1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h16-20020a05640250d000b0045a1e2373dbsi31554887edb.44.2022.10.24.05.17.27; Mon, 24 Oct 2022 05:17:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DB5JLbN1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232802AbiJXMKt (ORCPT + 99 others); Mon, 24 Oct 2022 08:10:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232936AbiJXMJN (ORCPT ); Mon, 24 Oct 2022 08:09:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E3BD7F12B; Mon, 24 Oct 2022 04:52:27 -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 6DA5BB81133; Mon, 24 Oct 2022 11:41:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB4B9C433D7; Mon, 24 Oct 2022 11:41:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611713; bh=r506Ag79BSrfZBh8eR/bVpeZ0sWlRaZMTh3EzvetG4E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DB5JLbN1mNtRh8df+g+gaeCZ1BttWLAxgvUbosouPtcKlpKzmn7Z3dhmLmIDdTgSR n8muIO51ZG9C8Jpz0k3A8ZXDho0X4wHXO+1QLL8i8xdRe25ltzCB99SQZ2Rt7/XG+t tPukWRc33jmobld3VHdK8mPmkJP1Y4LIJ2qmuFrg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hyunwoo Kim , Helge Deller Subject: [PATCH 4.9 053/159] fbdev: smscufx: Fix use-after-free in ufx_ops_open() Date: Mon, 24 Oct 2022 13:30:07 +0200 Message-Id: <20221024112951.366575229@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747571306873867482?= X-GMAIL-MSGID: =?utf-8?q?1747571306873867482?= 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 @@ -140,6 +140,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); +static DEFINE_MUTEX(disconnect_mutex); + /* reads a control register */ static int ufx_reg_read(struct ufx_data *dev, u32 index, u32 *data) { @@ -1073,9 +1075,13 @@ static int ufx_ops_open(struct fb_info * if (user == 0 && !console) return -EBUSY; + 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; + } dev->fb_count++; @@ -1100,6 +1106,8 @@ static int ufx_ops_open(struct fb_info * pr_debug("open /dev/fb%d user=%d fb_info=%p count=%d", info->node, user, info, dev->fb_count); + mutex_unlock(&disconnect_mutex); + return 0; } @@ -1761,6 +1769,8 @@ static void ufx_usb_disconnect(struct us { struct ufx_data *dev; + mutex_lock(&disconnect_mutex); + dev = usb_get_intfdata(interface); pr_debug("USB disconnect starting\n"); @@ -1781,6 +1791,8 @@ static void ufx_usb_disconnect(struct us kref_put(&dev->kref, ufx_free); /* consider ufx_data freed */ + + mutex_unlock(&disconnect_mutex); } static struct usb_driver ufx_driver = {