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=1795620815; b=B8wZpLgw0Bb2B4+tjQDNgHMh7GMl5kIwyUT6N/W0HmuCXlOI+MZXwCvJ3Xk0LYGiKZZS uNB0ShJ45sIhNUwLNbW4WesXmCGeQ2ldF/sGJfMZ0rmjFrJIdRaKXlxe4nZqmUJqndvgA IqGiDsZDCNnFOPTjPlT6QUzCWeK25Gr2zfmoJBMH2Jt5FBzUFpkVxDtu7FbhGP43kizJa fAwr7QRMATLtGXgGQo+4AL24txk5lXgTJHFabF5+nrG6Q+S7qtRr7DL7MQcqwetCuYYAD yYuwthvt1FZRBhzNEGLrdht2tX7ruRsq4rRmaVV0QjlDzbQhnrGLZWZGdHuSQ95yXWQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795620815; 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=2B6/X6qmriSibtbgMgso9yMsXcnVS7lDTQpdQUZs9ko=; b=MM4nUxRq7p3HlVFuNWWGbOVYkevmzfLvNWnsTdTxk0PSCTm/Fvx3GLmhPCsuvoNw+nre qoUrTf1M6piQm+cyPaDuJxMyDEZUxReXRcTZL/5cavQqotrC4sSfaze7YwzIy3Kc0ztr6 TcPQz8USUk7q5y+yalCpD+OkZDC6Ns2x8jgO5jcFcOIq9+zUKYaWycYf8sZUpwyIdInpV R4jBEv+7N9VW2/9GdNzBiwS8i+0lCc4lnulcB2IMUG87kELDEClVGK/3EWDcUfV/vc/qe UI6zbBDTeNKW2Msyh7IykmgDaNvlAfeEFRADKaWSZqKSs7lqGqoitouhCbyqqesZILQ== 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=FCb8ONI5; 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 172ED606A31E; Wed, 25 Nov 2026 15:33:34 +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=FCb8ONI5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F5EF1F000C4; Wed, 25 Nov 2026 15:33:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795620814; bh=2B6/X6qmriSibtbgMgso9yMsXcnVS7lDTQpdQUZs9ko=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FCb8ONI54eyZ9WTiGB9RNbGamzvjgp4nPKZ0mljESP71MasulbsWdpSeSxSCGr0Uq jXKqStQ2C3AZcqOHh9Yz12zixYgitfVjSCUzy5DcqqicyBGO15smT6lao0gKEJGfOJ /d8uNxI5xLZtcFxwZGW/u5gZl5+wWlIE0cAF69OQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Melbin K Mathew , Helge Deller , Sasha Levin Subject: [PATCH 6.18 032/990] fbdev: serialize mode sysfs access with lock_fb_info() Date: Wed, 25 Nov 2026 15:23:19 +0100 Message-ID: <20261125143822.841241261@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125143822.072087159@linuxfoundation.org> References: <20261125143822.072087159@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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Melbin K Mathew [ Upstream commit 061db6b7a910b8378f3b2df64f8c0a3ddc6e85f2 ] show_mode(), show_modes(), and store_mode() access fb_info->modelist and fb_info->mode without holding lock_fb_info(). store_modes() takes lock_fb_info() while replacing the modelist and freeing the old one. A concurrent reader or writer can load a pointer to an old modelist entry before store_modes() frees it, then dereference freed memory or store a stale freed pointer in fb_info->mode. Take lock_fb_info() in show_mode(), show_modes(), and store_mode() to serialize with store_modes(). In show_mode(), copy the mode to the stack and format after dropping the lock. In store_mode(), split activate() into a _locked variant to avoid double-locking, and hold the locks for the modelist walk, mode conversion, activation, and fb_info->mode assignment together. Cc: stable@vger.kernel.org # v7.1+ Signed-off-by: Melbin K Mathew Signed-off-by: Helge Deller Signed-off-by: Sasha Levin --- drivers/video/fbdev/core/fbsysfs.c | 46 ++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/drivers/video/fbdev/core/fbsysfs.c b/drivers/video/fbdev/core/fbsysfs.c index 49d886c2dd7c8..c32dd71a38e1c 100644 --- a/drivers/video/fbdev/core/fbsysfs.c +++ b/drivers/video/fbdev/core/fbsysfs.c @@ -13,19 +13,24 @@ #include "fb_internal.h" #include "fbcon.h" +static int activate_locked(struct fb_info *fb_info, + struct fb_var_screeninfo *var) +{ + var->activate |= FB_ACTIVATE_FORCE; + return fb_set_var_from_user(fb_info, var); +} + static int activate(struct fb_info *fb_info, struct fb_var_screeninfo *var) { int err; - var->activate |= FB_ACTIVATE_FORCE; console_lock(); lock_fb_info(fb_info); - err = fb_set_var_from_user(fb_info, var); + err = activate_locked(fb_info, var); unlock_fb_info(fb_info); console_unlock(); - if (err) - return err; - return 0; + + return err; } static int mode_string(char *buf, size_t size, unsigned int offset, @@ -66,6 +71,9 @@ static ssize_t store_mode(struct device *device, struct device_attribute *attr, memset(&var, 0, sizeof(var)); + console_lock(); + lock_fb_info(fb_info); + list_for_each_entry(modelist, &fb_info->modelist, list) { mode = &modelist->mode; i = mode_string(mstr, sizeof(mstr), 0, mode); @@ -73,12 +81,22 @@ static ssize_t store_mode(struct device *device, struct device_attribute *attr, var = fb_info->var; fb_videomode_to_var(&var, mode); - if ((err = activate(fb_info, &var))) + err = activate_locked(fb_info, &var); + if (err) { + unlock_fb_info(fb_info); + console_unlock(); return err; + } fb_info->mode = mode; + unlock_fb_info(fb_info); + console_unlock(); return count; } } + + unlock_fb_info(fb_info); + console_unlock(); + return -EINVAL; } @@ -86,11 +104,20 @@ static ssize_t show_mode(struct device *device, struct device_attribute *attr, char *buf) { struct fb_info *fb_info = dev_get_drvdata(device); + struct fb_videomode mode; + bool have_mode = false; - if (!fb_info->mode) + lock_fb_info(fb_info); + if (fb_info->mode) { + mode = *fb_info->mode; + have_mode = true; + } + unlock_fb_info(fb_info); + + if (!have_mode) return 0; - return mode_string(buf, PAGE_SIZE, 0, fb_info->mode); + return mode_string(buf, PAGE_SIZE, 0, &mode); } static ssize_t store_modes(struct device *device, @@ -138,12 +165,15 @@ static ssize_t show_modes(struct device *device, struct device_attribute *attr, const struct fb_videomode *mode; i = 0; + lock_fb_info(fb_info); list_for_each_entry(modelist, &fb_info->modelist, list) { mode = &modelist->mode; i += mode_string(buf, PAGE_SIZE, i, mode); if (i >= PAGE_SIZE - 1) break; } + unlock_fb_info(fb_info); + return i; } -- 2.53.0