From patchwork Sat Oct 22 07:19:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7305 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1093219wrr; Sat, 22 Oct 2022 00:56:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5tRTGle+01HmDQeTaYnkfEkrZ3JihzLy0lLqQzXG1rG/z+jSySZjnZ8yKLOiUda1/od/yY X-Received: by 2002:a05:6a00:1ace:b0:565:f52a:d998 with SMTP id f14-20020a056a001ace00b00565f52ad998mr23203434pfv.25.1666425388970; Sat, 22 Oct 2022 00:56:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425388; cv=none; d=google.com; s=arc-20160816; b=HFEGiTeMbVCywOgv0np9iBPv2/jAAD8vSGZVDoa2kauj6C9YcxmCEl+YiZF+AymHTZ iI1lvHHhQ/xJBmd9KpGr/2CelC4nYVJNud7jiCiN84FDmKo5RinrFqAG1EssjjpoVMdL Fipn3MfI2i8hxerVVcIVmo3XHJT5altsu5Lv3C+33WglQGRC/R+/O8/b06y1ObtaXcS9 h+TprOdAYXv85tFOTAnoBtrL60gxhUTGbydlEtpV9egRVjVk1Q+RIoCc25Eaciag4AiK xQapHCA8RbZsa+w/dOysn70NlAYqWypQ8laIRkjADfkw3cyx+wc9XjkGnwwEmLJ/mvCn 8yzA== 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=Iz+Aav3JxKzOw/1KysJEyZG6FWOjZdfKSipw5zbDu0/eINConBubZC7+qgKlTkqcUa pm+tRDZxHeSzBhKbR3LEW7oN+BlgS1NfOiLmwxi7O9PxmijXG54a1zRs/pgvDNHPdL6t 9hkxvdJoQK7q9jAbZkyHdNyLCv7CHKH2Cr4J5ifIeFwvQ6gP8Q/tNA5fQf+I/uBrhpE7 ekqDx2UNGmMTq2YJXG4gir6cPan6sBg652prIHBRB6KfJUi0hVJW2wYm/4SHcKv6zEFV szO59DHlmxhow+RYH+q5OtzsOstyTiMKiHcx+Zqcr6wKB7+KDI9zw5cW1XN9oM7TRkGg QILg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cRWEdXUs; 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 h6-20020a17090aa88600b001fe30c193c1si8056668pjq.185.2022.10.22.00.56.15; Sat, 22 Oct 2022 00:56:28 -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=cRWEdXUs; 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 S232198AbiJVHz7 (ORCPT + 99 others); Sat, 22 Oct 2022 03:55:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231760AbiJVHwi (ORCPT ); Sat, 22 Oct 2022 03:52:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF0A12CA7C1; Sat, 22 Oct 2022 00:46:51 -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 9F66F60B36; Sat, 22 Oct 2022 07:39:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4BE4C433C1; Sat, 22 Oct 2022 07:39:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424397; bh=dGaokMN2ZM66MraQW54O4r/eFRtqHnwl58/YQQQdXYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cRWEdXUs4zgUuA7Z36N8RF+DjrlYRgSZiP46g5AmS4Jun+SEUuN/HYQ36hRFi0/a3 sFhmlVV7gUQ03vV66sy62e/JTkuoOiLrDMljyq8tJi1H9L5SDQNC/Tfi1Dcv4Aatt+ owUHajaonDaEtKlDhVf1da4WDdH9ap9LaLL4J5d0= 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.19 099/717] fbdev: smscufx: Fix use-after-free in ufx_ops_open() Date: Sat, 22 Oct 2022 09:19:38 +0200 Message-Id: <20221022072432.894878650@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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?1747373668437386864?= X-GMAIL-MSGID: =?utf-8?q?1747373668437386864?= 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 = {