From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB2A913DBA0; Sun, 7 Jun 2026 10:26:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780828011; cv=none; b=dYP7wesSFvuttYLJgqICSZPv80D8AEEzEzbaTtNBUFWO7XAfeeZZvadsGXNyudsMiKSjTXD0TVrqhbnH2xxtx7ncPzfGRH6aYgYEOgf2HxHZaIhX4n+V6Pj3KxS0fOXc4MjnZJU8uX02LveF4vRmDal1UKonreKjHLw9xVotUYA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780828011; c=relaxed/simple; bh=9Xjg8iStobOl1cPj7zdjV8McHULpfdRpoRogh2qWn9g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ARfcxuMA2EdjsjBMkCAoH6kQF6YZeSpaj9cB2UHIVGL8LH/5vFLKDfWJqd/esZlUJmlMbvP27Qv46mCNdZRz6iL4PKrMKqfMPq5Z6KKgtzuxJ9ysn0rMDUkJ7vVNop06VbPEycayvUo/OtC7z3LKsdubvqkAn45LcUtV6jcma5I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=VdjfFGaU; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="VdjfFGaU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E0291F00893; Sun, 7 Jun 2026 10:26:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780828010; bh=2KrR1a6pfZPIsr56uFlxu73HaLgk+UkCzwstWeJ1Ofk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VdjfFGaUWSZuQb4vNVLpSX5NMdYOOOR7Hnkbew3UXKMLj2dhMYRnqWwTopBgSiZpD fzKTuUkBfBxj9UoHHbM4lQiHvAUmB5SM4vgiIsjovNH9dvWn95x7xQieJC4l6UXtpX lWgzbUdOFkxUbo2+A0VTDohA2/S9DKUEwQVI35es= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Stepan Ionichev , Andy Shevchenko Subject: [PATCH 7.0 144/332] auxdisplay: line-display: fix OOB read on zero-length message_store() Date: Sun, 7 Jun 2026 11:58:33 +0200 Message-ID: <20260607095733.387819859@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260607095728.031258202@linuxfoundation.org> References: <20260607095728.031258202@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.0-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stepan Ionichev commit a7511dcd9dd4bc55d123f9b800c8a4ed2662e5c6 upstream. linedisp_display() unconditionally reads msg[count - 1] before checking whether count is zero, so a write of zero bytes to the message sysfs attribute hits msg[-1]: write(fd, "", 0); -> message_store(..., buf, count=0) -> linedisp_display(linedisp, buf, count=0) -> msg[count - 1] == '\n' ; OOB read The kernfs write buffer for that store is a 1-byte allocation (kernfs_fop_write_iter() does kmalloc(len + 1) with len == 0), so msg[-1] is a 1-byte read before the slab object. On a KASAN-enabled kernel this trips an out-of-bounds report and panics; on stock kernels it silently reads adjacent slab data and, if that byte happens to be '\n', the following count-- wraps ssize_t 0 to -1 and is then passed to kmemdup_nul(). linedisp_display() is reached from the message_store() sysfs callback (drivers/auxdisplay/line-display.c message attribute, mode 0644) and from the in-tree initial-message setup with count == -1, so the OOB path is only userspace-triggerable via zero-byte writes; vfs_write() does not short-circuit on count == 0 and kernfs_fop_write_iter() dispatches the store callback regardless. Guard the trailing-newline trim with a count check. The existing if (!count) block then takes the clear-display path unchanged. Affects every auxdisplay driver that registers via linedisp_register() / linedisp_attach(): ht16k33, max6959, img-ascii-lcd, seg-led-gpio. Fixes: 7e76aece6f03 ("auxdisplay: Extract character line display core support") Signed-off-by: Stepan Ionichev Signed-off-by: Andy Shevchenko Signed-off-by: Greg Kroah-Hartman --- drivers/auxdisplay/line-display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/auxdisplay/line-display.c +++ b/drivers/auxdisplay/line-display.c @@ -173,7 +173,7 @@ static int linedisp_display(struct lined count = strlen(msg); /* if the string ends with a newline, trim it */ - if (msg[count - 1] == '\n') + if (count && msg[count - 1] == '\n') count--; if (!count) {