From patchwork Mon Oct 24 11:29:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8718 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp423502wru; Mon, 24 Oct 2022 05:25:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5UbeXeHdEfZrq2oZ5P+5oQj+6pK4L4uHRP1aKKncGRoBqY1qG8noR4ey7TRKt8R6c9PgdS X-Received: by 2002:a17:90b:33d1:b0:212:f02a:e5c7 with SMTP id lk17-20020a17090b33d100b00212f02ae5c7mr11645400pjb.137.1666614306505; Mon, 24 Oct 2022 05:25:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666614306; cv=none; d=google.com; s=arc-20160816; b=SehWWuIe4ZXFHXIS22vbuIB8t9rzh3GWnW1XkIEWhL9OHmJs+SjSTKucg5EkwICtYE LDmT7UwU23fmWkblXfUwQsZrFch1ItUGUGSRF/XEqc7dh2ZAf5q6q1kHEQ9Wvwn6QDWG PVR47AlZDCLVrXZLWLoQcyG9eVza5JMIpUlDEZ0NBKmUBHY34SnFFs5EDQf0bMA+h2lp cJONP4+VFdJpEaqamTcdxhIgbYUzBYUmDCN/fHuiMtvVNhrF9IIH7CZeXWw1UekCyybr jl/G9oqE8omCnsNHAZYXgR8DLAVqZ5cP+Qv7vlAtCeP2fFQJUuA5NfPqSTg9CSdHwtKH 69YA== 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=nRHpU740LS9V9UMb0MfjYNqTsPZnci7Mtri2ge1QOws=; b=J5a06GpdHonHqNU/FJzXZ3EIo5GsbF++aB4DQJQD9U1PoLaHZ4El0McAYmiWAW62aZ xg/fFBOQ1Imy46jzGAwNCIFgYI0ecJzTYXpoI03oMdhgFBvga48esRFBWZsIOVNB2R9/ 4d2rzbyLvUH+WXFIyUxZQ0hOWzTGPtvdrEYOuCNSDklOdKigAdCGjwsbqAZ5cw6o1ZbN gMMSte8wGV6nyOCl2uFg5ZwVjrN6ymRiu7e6+2H08uJnmgUy+z/IaoiicDHibiRRwIqt q2ACiAAwvQi5umHpcVe/LjfRL11df8BoIREuPCpsrJbgLK8RRAHgKWuJ0aOgiw4GAkeM FwKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="d7H/ZAn8"; 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 a3-20020a1709027d8300b0017f7dc60325si20022714plm.555.2022.10.24.05.24.52; Mon, 24 Oct 2022 05:25:06 -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="d7H/ZAn8"; 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 S233613AbiJXMXu (ORCPT + 99 others); Mon, 24 Oct 2022 08:23:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233525AbiJXMWm (ORCPT ); Mon, 24 Oct 2022 08:22:42 -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 0BEFD8323A; Mon, 24 Oct 2022 04:59:06 -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 9798B61297; Mon, 24 Oct 2022 11:58:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A90AAC4347C; Mon, 24 Oct 2022 11:58:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612693; bh=HWA7feJirUMvz4SMFoo8EJ7PDp2OxwPuFBriGn26Axk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d7H/ZAn8cAl76yLWLD4YBpzEE6dQinFAI/ASPuU6weJ2kXB8bB42hu8aQEzCy0Mpj uEXLVzMew2jo/YeZrbufq27hjfT/Ua8VjTsxKg8vuIVW593+CnGG0ZFGfYgc3cWGLf 40coMLb3WJv1IwStmMGKkFJfJRcBXHhprqPzXt44= 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.19 054/229] fbdev: smscufx: Fix use-after-free in ufx_ops_open() Date: Mon, 24 Oct 2022 13:29:33 +0200 Message-Id: <20221024113000.821981870@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@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?1747571763029858405?= X-GMAIL-MSGID: =?utf-8?q?1747571763029858405?= 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++; @@ -1099,6 +1105,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; } @@ -1746,6 +1754,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"); @@ -1766,6 +1776,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 = {