From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796383905; b=zF5GQwNpOiANFkBgLV3KGfPo2A/pFeo8OvsNiDD2hRSfYFnn5xaeAqTEtSDHOfDuxLkJ Y2CsZS0Xk0NCZf2PIOxkJ7tjxra0+xTrpzYNlQMA+++cEOBBpyXvF8WCpbXe2cXW+wj3K pU6hs/pOF3TTS1Rn5x4YIsCRkj5dEr/PiQMzIntmnnZuOvLnZRa51CcffeLYnH70t9/Rb S/m8Lu3N5AS/kKbIsZPGu9AojVtRnlWDMNgjPZHjyu2ZYMKTsCpVFRDWGE5iVceU+bk+I 767O1B+yQbkMFMT+cHkOfYjCIdl3IAhJiA2EdtLi27BLcy5GqM8mdRM/hpAgDPj5k5w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383905; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=kNXfqhWfPODouX6EDTXe48camKVodhuyOcF6NVnjEKY=; b=iAqSOpAryLteDsnPp1ZxzfKy81J5L6aKacOKFH6efwShiuKH4o+NO+qMK0/Qv/1ymjqc rGMqzIH2B82KSDy8i+r9B4RY+5vE3yVrjtkMXphdFZCpkyVOYvAQFbXFj1REIZZkH5p5U +RjhIgvKRBcUQuoxhfDxusRyicqejGijWuKsToqlGg9t1tj8lOE1jc8NReGb63KDvU9yy Nhh1KwOVPadJWwKYQU1mzAn+5Uvyxn3zGUGuCrcXgHqVn5LSR20tBajUtn+T9G0FZW+TO bqXjc/TNjED2nlFSIBW58kbhHvvYIKdJzxU/f5utMLEzB4YtbtYxYlN2gEAdZW2PICg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=J89teXXe; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49FEA60A5BFC; Fri, 4 Dec 2026 11:31:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=J89teXXe Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CF0A1F0280B; Fri, 4 Dec 2026 11:31:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383904; bh=kNXfqhWfPODouX6EDTXe48camKVodhuyOcF6NVnjEKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=J89teXXeW7RqfEKPmdwQpbIOuQpK36NUL3zscrv9C0PK4r0y/6c8DzuJbQwWz/fZE Mz0fvfprVdZzG4R0DVbWucAvEZgAK5ck5O/PXznThkaE5iydSxxLWVekaDgJ4WmQNO o0PKmzq5o+Pv59K5pPi4efGqokccCwWzUcXkLNqw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, YuanZhe Liu <25031212351@stu.xidian.edu.cn>, Helge Deller Subject: [PATCH 6.12 377/555] fbdev: smscufx: dont free registered framebuffer on probe error Date: Fri, 4 Dec 2026 19:07:00 +0900 Message-ID: <20261204100624.221950878@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: YuanZhe Liu <25031212351@stu.xidian.edu.cn> commit ed52e47133f72195f246a9f70c98e47431bb566d upstream. register_framebuffer() can return an error after the framebuffer has already been installed: do_register_framebuffer() bumps info->count, creates /dev/fbN and stores the fb_info in registered_fb[] before it returns the result of the console takeover, and that takeover may fail. ufx_usb_probe() treats any error as "nothing was registered" and unwinds through reset_active, which releases the fb_info and drops both references to struct ufx_data, freeing @dev. The framebuffer stays registered and can still be opened, so the next open() of /dev/fbN reaches ufx_ops_open() with info->par pointing at freed memory: refcount_t: addition on 0; use-after-free. WARNING: lib/refcount.c:25 at refcount_warn_saturate Call Trace: kref_get ufx_ops_open drivers/video/fbdev/smscufx.c:1033 fb_open drivers/video/fbdev/core/fb_chrdev.c:351 chrdev_open ... refcount_t: underflow; use-after-free. WARNING: lib/refcount.c:28 at refcount_warn_saturate Call Trace: ufx_ops_release drivers/video/fbdev/smscufx.c:1135 fb_release drivers/video/fbdev/core/fb_chrdev.c:378 __fput Reuse the "has this fb_info been registered" test that ufx_setup_modes() already uses: take the error path only when refcount_read(&info->count) says the core did not register the framebuffer. A failed console takeover is not fatal for the driver, so report it and keep the framebuffer registered; the disconnect callback will unregister it normally. Fixes: 3c8a63e22a08 ("Add support for SMSC UFX6000/7000 USB display adapters") Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn> Cc: stable@vger.kernel.org Signed-off-by: Helge Deller Signed-off-by: Greg Kroah-Hartman --- drivers/video/fbdev/smscufx.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/drivers/video/fbdev/smscufx.c +++ b/drivers/video/fbdev/smscufx.c @@ -1701,8 +1701,16 @@ static int ufx_usb_probe(struct usb_inte dev_dbg(dev->gdev, "registering framebuffer"); retval = register_framebuffer(info); if (retval < 0) { - dev_err(dev->gdev, "error %d register_framebuffer", retval); - goto reset_active; + /* + * info is installed before the takeover can fail; freeing @dev + * here would leave registered_fb[] and /dev/fbN pointing at + * freed memory. + */ + if (!refcount_read(&info->count)) { /* not registered */ + dev_err(dev->gdev, "error %d register_framebuffer", retval); + goto reset_active; + } + dev_warn(dev->gdev, "console takeover failed: %d\n", retval); } dev_info(dev->gdev, "SMSC UDX USB device /dev/fb%d attached. %dx%d resolution."