From nobody Sat Aug 1 21:31:44 2026 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 045BF1F2380 for ; Sat, 1 Aug 2026 20:02:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785614526; cv=none; b=efSCE2sYaeq/TeS34J8GrVnwuky97CV0Nqzc8IyXe+Jj7jXJ8gvY51t7dDz8XHj9wpn55OCk874lrUhHAu6kR0yhr8BwQHoJsCxFXjBprnI+BljvnDkwPzBgEACflPEq80qjlcWRnl/2nKLB6e+nwKYQ3o2S8QWYeHsmnehsc/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785614526; c=relaxed/simple; bh=PqIlCkJmtkmh7wSB8OP4i87rwCMmMANIsCJcEfZ1JPk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=InnTclyJAAurI4Y/CR3pJVR4BTF4tkmwXyjLk4wlPfDYE7twEAHqnn41P95lsPE5NlwmhCgBSVOC9SW055YE589lhP81wotXc4flAkqGRZ2LEgwtwl28JON9QSns+hWaBWdxyD2EGmmkePpakN4us6Gh6RRQR3TbzZN1LcIARfQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MT8YAk4s; arc=none smtp.client-ip=209.85.215.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MT8YAk4s" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-ca7bea5e5b3so1616324a12.1 for ; Sat, 01 Aug 2026 13:02:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785614524; x=1786219324; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=1ggmpKDlBjCfXFEH2bmuD64+8X7Nry2xQnXVVBJHK/A=; b=MT8YAk4svxTvLj8Fx8Dr3CJzxdal/95Hq25uzCgAjjVta7kyAytjEQPLUlGGTtdKX4 zVM+m5tzr6BULVF11p82h/wQciUHpcjODS7GFojtnNfuRgUrZRtia+LmHtq8gchDLbWA xl1sqdIXRf2r6yB3CHqBRkoOC3n+ZULBF29rW+G60oAsUNXd1NgVtD6jbwtXC9/XKumw Q/2tOJNMHsYOKjMQqvgQBbKaHc+DVcHjn2tsRtR1i/yUCUzQx7qENLQJbA6VKUDnCVKr z+F040JbR0XMf3qzlo5bNZGSOm2UNS/kMzYnPAaWK1opuSSQx2FuIy4xYUShgbN1imis K2dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785614524; x=1786219324; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=1ggmpKDlBjCfXFEH2bmuD64+8X7Nry2xQnXVVBJHK/A=; b=cV6ZK4XEHCDydpkfmTPqVlM+w+u6PiM3GxlwaQm8Y5PcxDqopC1J2Fz6LzWF+uFO8x MzKaKt1ikrr3nqDoJzwYMCkbGfKhqLztJXMxkchuR7MwOOxWSbVa6XxLVZpl+I4sPd52 mJEHIAyGxL/1iVvffLzL12QphvGwywDQwHal7nAnxpECeZSfVN36UBrLmGHoF05hArAH WcVxGSQUbd6C2/ELnw0qp/4k7FjRuZWwga10igIgipQIBrhOKqjfLTKNM2YMIt+NsfEn v5U6gbpAZ8BUQ082ns/I+m1lL6ExIEMiMf01vV/0QGyAmu1QpMRDG6VHc9DwZfAuayEy JZsg== X-Forwarded-Encrypted: i=1; AHgh+RqDm1nCKp48J5JmVZP29zL8ZfPtkCCwyFAZZy0ZqDTfgOL02I5Z7KtsPay9p7M/k85/S6cIgAFVhrRkHj8=@vger.kernel.org X-Gm-Message-State: AOJu0YzwHqn7/suFITluIlYj+kz25uRUE6WwjFBxAyZuINVA+k2NxERC IwqSq+cZL007CoAvsaKCX0TpV/KI2a5ctEOm0C2TTWMGPOqiAOUnbkJn X-Gm-Gg: AR+sD10hJgvINSkrJBw6GJnOoKiBZ5uab41BbqLKFIj+/2LYQGAFotC+FhssuRUJYmS 2+QnqV7EwrCD53PMFE3FvYNvOOgQ6NNx/Aq+iSxAnZs8cdmCI2aItE5eQ17cCG2FzC+yeFTONYZ x0KsUOdGLqzhWxqzHsbtpUxJR0lZD3PO5TEYxpY3uXC0zY0pUvmBpqAjxfgqAQtk1tvhZ6LhjXs IWzN+AsK+k7WEIAKxn4CYiyzx5zHhVQtvpMZ/s8eHMo5S6pWPsrpc/GTEz5WbpaudAVT8HzdhqL vol3pS6v2ayU8w2v3hX0C9PYBJ24E9IDi+Tt4vJB0XTc0VoSyLO1q7bvngrIs84cS+y8mleZtbR 63v5e43yG6CxWfrjX7HC3Kik99getp8XXQ9kWg8gdPPadrjSG9lVxWd12npFaSSzvScyxUjbReH uNnv4xvN2S40KgnJbGLENGfIXmFiDAj1AFUnmiWh2udjj8Nf/YpTK/UZrIr6wduOFgxpqkpx2pj Vhg9JzJsAUzo2fz2Yfc/tpOMbSQngU/Vv60I8ZQf6Oi66sklGrh8+cVmJpnU0PiZerVzcVAmMyf 6Gb3EdUbAy5b4u5Up5t0 X-Received: by 2002:a05:6300:2206:b0:3c4:4272:b400 with SMTP id adf61e73a8af0-3c92a5bc504mr4747990637.18.1785614524305; Sat, 01 Aug 2026 13:02:04 -0700 (PDT) Received: from localhost.localdomain ([2405:acc0:1306:9d5b:7865:f907:f2bf:8664]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3153e04506csm20980095eec.17.2026.08.01.13.02.01 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 01 Aug 2026 13:02:03 -0700 (PDT) From: Laxman Acharya Padhya To: Andy Shevchenko Cc: Geert Uytterhoeven , linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] auxdisplay: linedisp: serialize sysfs message updates Date: Sun, 2 Aug 2026 01:46:50 +0545 Message-ID: <20260801200150.60098-1-acharyalaxman8848@gmail.com> X-Mailer: git-send-email 2.51.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" message_store() frees and replaces linedisp->message, restarts the scroll timer, and may immediately read the new buffer again to update the display. message_show() and scroll_step_ms_store() can run concurrently through separate sysfs opens, because kernfs only serializes operations per open file. That leaves the display state vulnerable to concurrent readers and writers. A racing write can free a message buffer that another sysfs write is still copying from, and a sysfs read can format a message pointer while another thread frees and replaces it. Serialize sysfs access to the display state with a mutex. Keep the timer callback lockless, and use timer_delete_sync() under the mutex so sysfs writers wait for any in-flight scroll callback before changing the message, scroll position, or scroll rate. Fixes: 7e76aece6f03 ("auxdisplay: Extract character line display core suppo= rt") Cc: stable@vger.kernel.org Signed-off-by: Laxman Acharya Padhya --- drivers/auxdisplay/line-display.c | 7 +++++++ drivers/auxdisplay/line-display.h | 3 +++ 2 files changed, 10 insertions(+) diff --git a/drivers/auxdisplay/line-display.c b/drivers/auxdisplay/line-di= splay.c index 915eb5cd9..fbac10668 100644 --- a/drivers/auxdisplay/line-display.c +++ b/drivers/auxdisplay/line-display.c @@ -164,6 +164,7 @@ static void linedisp_scroll(struct timer_list *t) static int linedisp_display(struct linedisp *linedisp, const char *msg, ssize_t count) { + guard(mutex)(&linedisp->lock); char *new_msg; =20 /* stop the scroll timer */ @@ -226,6 +227,7 @@ static ssize_t message_show(struct device *dev, struct = device_attribute *attr, { struct linedisp *linedisp =3D to_linedisp(dev); =20 + guard(mutex)(&linedisp->lock); return sysfs_emit(buf, "%s\n", linedisp->message); } =20 @@ -267,6 +269,7 @@ static ssize_t scroll_step_ms_show(struct device *dev, { struct linedisp *linedisp =3D to_linedisp(dev); =20 + guard(mutex)(&linedisp->lock); return sysfs_emit(buf, "%u\n", jiffies_to_msecs(linedisp->scroll_rate)); } =20 @@ -282,6 +285,8 @@ static ssize_t scroll_step_ms_store(struct device *dev, if (err) return err; =20 + guard(mutex)(&linedisp->lock); + timer_delete_sync(&linedisp->timer); =20 linedisp->scroll_rate =3D msecs_to_jiffies(ms); @@ -444,6 +449,7 @@ int linedisp_attach(struct linedisp *linedisp, struct d= evice *dev, linedisp->ops =3D ops; linedisp->num_chars =3D num_chars; linedisp->scroll_rate =3D DEFAULT_SCROLL_RATE; + mutex_init(&linedisp->lock); =20 linedisp->buf =3D kzalloc(linedisp->num_chars, GFP_KERNEL); if (!linedisp->buf) @@ -531,6 +537,7 @@ int linedisp_register(struct linedisp *linedisp, struct= device *parent, linedisp->ops =3D ops; linedisp->num_chars =3D num_chars; linedisp->scroll_rate =3D DEFAULT_SCROLL_RATE; + mutex_init(&linedisp->lock); =20 err =3D ida_alloc(&linedisp_id, GFP_KERNEL); if (err < 0) diff --git a/drivers/auxdisplay/line-display.h b/drivers/auxdisplay/line-di= splay.h index 36853b639..13b56fe3b 100644 --- a/drivers/auxdisplay/line-display.h +++ b/drivers/auxdisplay/line-display.h @@ -13,6 +13,7 @@ #define _LINEDISP_H =20 #include +#include #include =20 #include @@ -58,6 +59,7 @@ struct linedisp_ops { /** * struct linedisp - character line display private data structure * @dev: the line display device + * @lock: serializes sysfs access to the display state * @timer: timer used to implement scrolling * @ops: character line display operations * @buf: pointer to the buffer for the string currently displayed @@ -70,6 +72,7 @@ struct linedisp_ops { */ struct linedisp { struct device dev; + struct mutex lock; /* serializes sysfs access to the display state */ struct timer_list timer; const struct linedisp_ops *ops; struct linedisp_map *map; --=20 2.51.2