Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7150767rwi; Mon, 24 Oct 2022 10:25:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM75dUlvIOruJSsq6FPOXGN6P5DJx5KG6FzFqilxvqlXY3pC4qE8G/JbaKVseHymWk5NoBmu X-Received: by 2002:a17:907:a042:b0:7a0:3323:2883 with SMTP id gz2-20020a170907a04200b007a033232883mr12459549ejc.37.1666632338721; Mon, 24 Oct 2022 10:25:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666632338; cv=none; d=google.com; s=arc-20160816; b=gzm77xo2RiuoD5QNrzCH9IgOMGPtFUnbEDafAvN74wGznDukDzD2Pig7uDDIj9hVqI +vX3198nOe8wVQUiYOMQyf3Vrz9i0TYAQpqL7wPxJEjnnRc+dZ78+LxsadFam/1fQ8l+ vCfENZLmuJWfKdFCM5wCScLhy1+TSexm5nHRKJCWGAVX8+T0OvzOIwPEYi7oFWY6CMnN bZ3bA0nPjSVCipFmWZ1Vh97tVL+IJH2w+Zs8KDtGL5L1AsxiprdPgIgZwZ4rXywgaRsr RKpkW0dZHem0fGhQ6OgXjZGn08clyNBfs8ZD9oq/RqCWjxoYqaTYZDypzduODn+5XoZ9 Aueg== 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=R1nuOcBaVMow6jMJ7eiDkRk+iYDx50eTA4qclaF4Ud4=; b=xXA3bpeKCNVp8WuE4Gy4tkTAMXBdMc7ylPAcxalDjiS86CGJR3wDRHGGZnvqXs74mS in3gBctd07+9PrfHzcjrpLpQB1n/25lrgOKnnrwEUDbjpgwQ+CQUXcBHv9MJHdTl8SnM 2SDHOhLKd34Uv2XyeOJKi51GfGOk9KGpkzpRUk+jbaWKTbSyMAFVjaxbkeI8INcKIbfP Pb9eHwy/rbTJjL8gW0iq9VLp73KwP4bNYWPf8rjBf1pCkAFVNP70WXwm0r6Rpq2a+HdG jeX1diO8wcGcUM/HZlKZe2QSpGVJHMOmP0jyTCmaMnioMtej+1G3pfxFjLuc9NgS/xv5 gfLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kQMoKOsD; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg32-20020a170907a42000b0078d3a35e181si283859ejc.871.2022.10.24.10.25.13; Mon, 24 Oct 2022 10:25:38 -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=kQMoKOsD; 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 S234316AbiJXQiL (ORCPT + 99 others); Mon, 24 Oct 2022 12:38:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231331AbiJXQhl (ORCPT ); Mon, 24 Oct 2022 12:37:41 -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 B95DD90835; Mon, 24 Oct 2022 08:25:25 -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 D0BB0B81731; Mon, 24 Oct 2022 12:36:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B6F0C433D6; Mon, 24 Oct 2022 12:36:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614973; bh=+xNnPHy9Ia7x9ClVvk0qMD1ZQWrB9NkkQ9bqD48pXi4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kQMoKOsDuMUXyXKrCQR9aCr356i8l76aLsk6SOJgf2irpERAUlMAhNAZRDwGFfa81 Mk7wConw+VLgPNvlq2xKr6OS1GwZYjfm14/1h51fgoUeDJbJchywq+cOo79Tmibd5q sJeDtWVnuBgbHhN9pLkFuXdqgItx43vJJxY7JnvE= 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.15 074/530] fbdev: smscufx: Fix use-after-free in ufx_ops_open() Date: Mon, 24 Oct 2022 13:26:58 +0200 Message-Id: <20221024113048.369996421@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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; } @@ -1740,6 +1748,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"); @@ -1760,6 +1770,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 = {