From patchwork Wed Oct 19 08:23:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4603 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp206527wrs; Wed, 19 Oct 2022 01:52:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5l7sLoocF1/civudqiQp2xliDrjrwpztrYGi2W4mLEU5bGxO7O4gWc4Mrvig9uxGoFK2SE X-Received: by 2002:a17:90b:3912:b0:20d:4151:1b65 with SMTP id ob18-20020a17090b391200b0020d41511b65mr44791928pjb.233.1666169557998; Wed, 19 Oct 2022 01:52:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666169557; cv=none; d=google.com; s=arc-20160816; b=AGKTsdwtQchU2hJSgEEKKKgQ455LfqgUt9uJP+GCKSyPMXX2qGRIVaq3YWBi8dRrmo 8DgF6XLFNskKixRd97pgdyf9jUFMaz8qVfi90tXdshHtNYqlA9yBzrqsmbH2AZikaS5y MRYReABlX42qfgEgKUjmKtyMDBd2EVeaA/YNiVMCD5/MVIxaiUi+X8YyrtqLcCd3b/sa /Z2/QmzqWco/gJRITk9leCaxxgsJLEHwREIXOKkRYpq/+T1+llefJTeLZlO/3Q0gVA6B JNHlX5uJ2i0xZbKf4NX0lQQxTgJ41+7FBmf8p7jczP34GmhGqCOKYv4QNARNpNwvOIa5 aHSw== 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=PV4g9GkHPMStXQq4RaBQAvlc8UkY57kOOWttNC1fAgo=; b=KxbnHF6G4MViuX7mp2kZvxwZHzB8Za5fuy7sS1KhsYxpc9AnEpC6VG5rm5nkkjYx6d FWAW/kUka0OtU4/4XePLnSKmth8+cK866eoLsj0WAwIMYOJc+NlPxPdyc26MHiA7wvHp eQUOTfFB4rpC6s6lfwxckb4BMEr8GE+0T4FzD4S1EaskmkxIBNzTk3JrU/QjEMg+naXH mSh6Wyezt1arh86qddcIb4S4pm4+90ABv5jY2ETk8Ppd0uKIoJi1epnU5DxZdowCOFXP e2Y7jowiDz6LLTv1iMalrX4b7uHguACXKAi21MJKVhyWXQrkUvcUAvKDx5if4ZlKuQl1 axpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mJd1s1nO; 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 a68-20020a636647000000b0045ce0eba520si16927516pgc.751.2022.10.19.01.52.25; Wed, 19 Oct 2022 01:52:37 -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=mJd1s1nO; 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 S231766AbiJSIwK (ORCPT + 99 others); Wed, 19 Oct 2022 04:52:10 -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 X-Spam-Status: No, score=-7.4 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?1747105410322214903?= X-GMAIL-MSGID: =?utf-8?q?1747105410322214903?= 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) { @@ -1071,9 +1073,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++; @@ -1097,6 +1103,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 = {