From patchwork Mon Oct 24 11:29:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8907 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp434138wru; Mon, 24 Oct 2022 05:51:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Ppoau8VhB7N0LU806If4P9+59wZqJI3gHZgCNRkAUNtuvbQb92mAUuE2sR7WsR9J50Ncg X-Received: by 2002:a17:907:9625:b0:78d:bb06:9072 with SMTP id gb37-20020a170907962500b0078dbb069072mr27565232ejc.472.1666615889903; Mon, 24 Oct 2022 05:51:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615889; cv=none; d=google.com; s=arc-20160816; b=caNql8p8WXZFO4Ao45U6tGjxynnFvAqxux0USkOadufgxJPmHaAQ47P2Lgl+NH2xCf zaZpsnT/db2FFFHKJsa87PLK+qyHLJfDu+vpPoRqK/NwvDiUQlsoyUhUFrg3HlR15/ag oRbkNqMkmLcbWIA4F8ACsMg+ivawBtz+wYkSDamtg3zyxL4pCuGde4q21IktCYrO/nLf Ab1Msgw2C1BJdmwSDYWRi1jVoB+WosWIUTmix95ZZ6+PvcMAb4W9zsPzXmIcK+r4Zk+W 9PcBIt9JVXH3i2M1Pf+JIzMn2JMPPDj/qyZdedMmx0rNDctLwSUIB55pvsnrNgqJnpn6 4Idg== 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=FxRExeGjFJ7ykxvD39fBYbL+MhY87gQij+xDqWhDfqI=; b=twgKorCLkrQeb+3+ubSaH8T6lFBnhlOyWTjP5duki1vmpG2qywkUdby8UkT8Yk4NQv LHW88TxROhIL2ghw3JnvS6+dKrnDPfdXtZpz9HEFdO5I64gksPjwhSsQJfATtUoPQcjM Oq6r2ewzKzyplZuelIIST3ofioJkz+DFGj2ylzMODQ6IqOCjHIn5inK3bf6GUGL6Fs91 52tR4NyIWZn0g4wWGvVuOhyhKPHU3e4OszgiErY78WG0DZ88oGf6RfsMmzRA25zQLfFD CeRy21qRC4u2wFrhO79bSEZc2PTgVAsttCXWam5MqSYpBH9pGUDMFsjEn4rls1mfmCSa ZR9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RPJ24wAo; 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 mc10-20020a170906eb4a00b00767e24156dbsi24237812ejb.256.2022.10.24.05.50.59; Mon, 24 Oct 2022 05:51:29 -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=RPJ24wAo; 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 S229926AbiJXMmb (ORCPT + 99 others); Mon, 24 Oct 2022 08:42:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234603AbiJXMkS (ORCPT ); Mon, 24 Oct 2022 08:40:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC8027E821; Mon, 24 Oct 2022 05:08:16 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 2D804612D7; Mon, 24 Oct 2022 12:06:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FA09C433C1; Mon, 24 Oct 2022 12:06:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613166; bh=NC/Z+V26eeA1Z3iEnYZiVxYZPA1qrFYiKABdDWYzFEs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RPJ24wAoPhO50LMRrwk4lW5a2v2FyAzOL1lL1Df0dnzEzWVi80yi+cIyjqH4nLF13 E0oNId2qYmCiVzzmQ2D7ZKbtETtBen2hjCqrR3mey92Z/hcbfbL1Px7bpkZZ9ecXPg /3EARK5/mCqPvGHWaerB5UTRJARzlSXp1sOmSkVk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hyunwoo Kim , Helge Deller Subject: [PATCH 5.4 034/255] fbdev: smscufx: Fix use-after-free in ufx_ops_open() Date: Mon, 24 Oct 2022 13:29:04 +0200 Message-Id: <20221024113003.578841361@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@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?1747573423234469020?= X-GMAIL-MSGID: =?utf-8?q?1747573423234469020?= 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); +static DEFINE_MUTEX(disconnect_mutex); + /* reads a control register */ static int ufx_reg_read(struct ufx_data *dev, u32 index, u32 *data) { @@ -1070,9 +1072,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++; @@ -1096,6 +1102,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; } @@ -1741,6 +1749,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"); @@ -1761,6 +1771,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 = {