[PATCH] platform/x86: thinkpad_acpi: Allow unlocking unsafe LEDs via debugfs

From: Rong Zhang

Date: Fri Nov 06 2026 - 17:24:00 EST


Since commit a4d5effcc737 ("thinkpad-acpi: restrict access to some
firmware LEDs"), most LEDs are classified as unsafe and write access to
them is restricted by default.

To enable unrestricted access, users have to build the kernel on their
own with CONFIG_THINKPAD_ACPI_UNSAFE_LEDS enabled, as it's unsupported
and no distribution enables it.

The Kconfig option, for sure, acts as a gatekeeper very well, but it may
be too harsh when a user really has some sensible reasons to enable
unrestricted access. As a result, there have been several attempts to
loosen the restriction.

On the other hand, the Kconfig option has two additional flaws:

- It enables unrestricted access to all LEDs at once, rather than just
those that the user needs
- It prints a notice message on probe, but can't really tell if the user
has really tuned unsafe LEDs
- It doesn't taint the kernel to indicate the unsupported setup

To solve these issues, replace the Kconfig option with a debugfs
attribute `unlock_unsafe_led' attached to every unsafe LED. Considering
that debugfs is enabled on all major distributions, the attribute should
be widely available.

Unsafe LEDs are registered on probe, but with LED_SYSFS_DISABLE set to
disable write access. Users must write to the attribute to enable
unrestricted access per LED. This taints the kernel with TAINT_USER.

In this manner, the unlocked range is narrowed, with a tedious procedure
to enable unrestricted access on every boot. By implementing a runtime
switch and tainting the kernel, it indicates when the user is about to
tune unsafe LEDs and clearly indicate the unsupported setup.

Link: https://lore.kernel.org/all/20181113174136.58198c3a@xxxxxxxxx/
Link: https://lore.kernel.org/all/20250403040846.7834-1-martin@xxxxxxxxxx/
Link: https://lore.kernel.org/all/a14640f58be48d4912ce5808faea1402ad7f7ad0.1793906572.git.josh@xxxxxxxxxxxxxxxx/
Signed-off-by: Rong Zhang <i@xxxxxxxx>
---
.../admin-guide/laptops/thinkpad-acpi.rst | 15 ++--
drivers/platform/x86/lenovo/Kconfig | 23 ------
drivers/platform/x86/lenovo/thinkpad_acpi.c | 95 +++++++++++++++++++---
3 files changed, 92 insertions(+), 41 deletions(-)

diff --git a/Documentation/admin-guide/laptops/thinkpad-acpi.rst b/Documentation/admin-guide/laptops/thinkpad-acpi.rst
index 60bf6868b849..be5211a2412b 100644
--- a/Documentation/admin-guide/laptops/thinkpad-acpi.rst
+++ b/Documentation/admin-guide/laptops/thinkpad-acpi.rst
@@ -791,13 +791,16 @@ of the LED indicators.
Because misuse of the LEDs could induce an unaware user to perform
dangerous actions (like undocking or ejecting a bay device while the
buses are still active), or mask an important alarm (such as a nearly
-empty battery, or a broken battery), access to most LEDs is
-restricted.
+empty battery, or a broken battery), most LEDs are classified as unsafe
+and write access to them is restricted by default.

-Unrestricted access to all LEDs requires that thinkpad-acpi be
-compiled with the CONFIG_THINKPAD_ACPI_UNSAFE_LEDS option enabled.
-Distributions must never enable this option. Individual users that
-are aware of the consequences are welcome to enabling it.
+Individual users that are aware of the consequences may enable
+unrestricted access to desired unsafe LED with::
+
+ echo 1 >/sys/kernel/debug/tpacpi/led/<name>/unlock_unsafe_led
+
+This taints the kernel with TAINT_USER. Please always be aware of the
+danger of enabling unrestricted LED access.

Audio mute and microphone mute LEDs are supported, but currently not
visible to userspace. They are used by the snd-hda-intel audio driver.
diff --git a/drivers/platform/x86/lenovo/Kconfig b/drivers/platform/x86/lenovo/Kconfig
index 516594993073..369f862e0d46 100644
--- a/drivers/platform/x86/lenovo/Kconfig
+++ b/drivers/platform/x86/lenovo/Kconfig
@@ -143,29 +143,6 @@ config THINKPAD_ACPI_DEBUG

If you are not sure, say N here.

-config THINKPAD_ACPI_UNSAFE_LEDS
- bool "Allow control of important LEDs (unsafe)"
- depends on THINKPAD_ACPI
- help
- Overriding LED state on ThinkPads can mask important
- firmware alerts (like critical battery condition), or misled
- the user into damaging the hardware (undocking or ejecting
- the bay while buses are still active), etc.
-
- LED control on the ThinkPad is write-only (with very few
- exceptions on very ancient models), which makes it
- impossible to know beforehand if important information will
- be lost when one changes LED state.
-
- Users that know what they are doing can enable this option
- and the driver will allow control of every LED, including
- the ones on the dock stations.
-
- Never enable this option on a distribution kernel.
-
- Say N here, unless you are building a kernel for your own
- use, and need to control the important firmware LEDs.
-
config THINKPAD_ACPI_VIDEO
bool "Video output control support"
depends on THINKPAD_ACPI
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 4f81855ad721..564fad46f5af 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -50,6 +50,7 @@
#include <linux/input/sparse-keymap.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
+#include <linux/kstrtox.h>
#include <linux/kthread.h>
#include <linux/leds.h>
#include <linux/list.h>
@@ -57,6 +58,7 @@
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/nvram.h>
+#include <linux/panic.h>
#include <linux/pci.h>
#include <linux/platform_device.h>
#include <linux/platform_profile.h>
@@ -428,6 +430,7 @@ enum led_status_t {
/* tpacpi LED class */
struct tpacpi_led_classdev {
struct led_classdev led_classdev;
+ struct dentry *dbg;
int led;
};

@@ -5608,17 +5611,59 @@ static const char * const tpacpi_led_names[TPACPI_LED_NUMLEDS] = {
"tpacpi::unknown_led3",
"tpacpi::thinkvantage",
};
-#define TPACPI_SAFE_LEDS 0x1481U
+
+static unsigned long tpacpi_unlocked_leds = 0x1481U;

static inline bool tpacpi_is_led_restricted(const unsigned int led)
{
-#ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
- return false;
-#else
- return (1U & (TPACPI_SAFE_LEDS >> led)) == 0;
-#endif
+ return !test_bit(led, &tpacpi_unlocked_leds);
+}
+
+/* sysfs unlock_unsafe_led - accessed via debugfs ---------------------- */
+
+static struct dentry *tpacpi_led_dbg;
+
+static int unlock_unsafe_led_show(struct seq_file *s, void *unused)
+{
+ struct tpacpi_led_classdev *data = s->private;
+
+ seq_printf(s, "%u\n", !tpacpi_is_led_restricted(data->led));
+ return 0;
}

+static ssize_t unlock_unsafe_led_write(struct file *file, const char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ struct seq_file *s = file->private_data;
+ struct tpacpi_led_classdev *data = s->private;
+ struct led_classdev *led_cdev = &data->led_classdev;
+ bool unlock;
+ int ret;
+
+ ret = kstrtobool_from_user(buf, count, &unlock);
+ if (ret)
+ return ret;
+
+ /* One-way switch. */
+ if (!unlock)
+ return tpacpi_is_led_restricted(data->led) ? count : -EBUSY;
+
+ if (test_and_set_bit(data->led, &tpacpi_unlocked_leds))
+ return count;
+
+ dev_notice(led_cdev->dev,
+ "userspace override of important firmware LED is enabled - tainting kernel\n");
+ add_taint(TAINT_USER, LOCKDEP_STILL_OK);
+
+ guard(mutex)(&led_cdev->led_access);
+ led_sysfs_enable(led_cdev);
+
+ return count;
+}
+DEFINE_SHOW_STORE_ATTRIBUTE(unlock_unsafe_led);
+
+/* --------------------------------------------------------------------- */
+
static int led_get_status(const unsigned int led)
{
int status;
@@ -5752,14 +5797,19 @@ static void led_exit(void)
{
unsigned int i;

- for (i = 0; i < TPACPI_LED_NUMLEDS; i++)
+ for (i = 0; i < TPACPI_LED_NUMLEDS; i++) {
+ debugfs_remove_recursive(tpacpi_leds[i].dbg);
led_classdev_unregister(&tpacpi_leds[i].led_classdev);
+ }

kfree(tpacpi_leds);
}

static int __init tpacpi_init_led(unsigned int led)
{
+ bool restricted;
+ int ret;
+
/* LEDs with no name don't get registered */
if (!tpacpi_led_names[led])
return 0;
@@ -5773,7 +5823,30 @@ static int __init tpacpi_init_led(unsigned int led)
tpacpi_leds[led].led_classdev.flags = LED_RETAIN_AT_SHUTDOWN;
tpacpi_leds[led].led = led;

- return led_classdev_register(&tpacpi_pdev->dev, &tpacpi_leds[led].led_classdev);
+ /*
+ * Disable write access to unsafe LEDs. If the user really knows what
+ * they are doing, they can enable it at the cost of tainting the
+ * kernel.
+ *
+ * Read access on TPACPI_LED_570 should be safe.
+ */
+ restricted = tpacpi_is_led_restricted(led);
+ if (restricted)
+ tpacpi_leds[led].led_classdev.flags |= LED_SYSFS_DISABLE;
+
+ ret = led_classdev_register(&tpacpi_pdev->dev, &tpacpi_leds[led].led_classdev);
+ if (ret)
+ return ret;
+
+ if (!restricted)
+ return 0;
+
+ tpacpi_leds[led].dbg = debugfs_create_dir(dev_name(tpacpi_leds[led].led_classdev.dev),
+ tpacpi_led_dbg);
+ debugfs_create_file("unlock_unsafe_led", 0600, tpacpi_leds[led].dbg,
+ &tpacpi_leds[led], &unlock_unsafe_led_fops);
+
+ return 0;
}

static const struct tpacpi_quirk led_useful_qtable[] __initconst = {
@@ -5883,7 +5956,7 @@ static int __init led_init(struct ibm_init_struct *iibm)
for (i = 0; i < TPACPI_LED_NUMLEDS; i++) {
tpacpi_leds[i].led = -1;

- if (!tpacpi_is_led_restricted(i) && test_bit(i, &useful_leds)) {
+ if (test_bit(i, &useful_leds)) {
rc = tpacpi_init_led(i);
if (rc < 0) {
led_exit();
@@ -5892,9 +5965,6 @@ static int __init led_init(struct ibm_init_struct *iibm)
}
}

-#ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
- pr_notice("warning: userspace override of important firmware LEDs is enabled\n");
-#endif
return 0;
}

@@ -11678,6 +11748,7 @@ static struct dentry *tpacpi_dbg;
static void tpacpi_debugfs_init(void)
{
tpacpi_dbg = debugfs_create_dir("tpacpi", NULL);
+ tpacpi_led_dbg = debugfs_create_dir("led", tpacpi_dbg);

/* HWDD raw data */
debugfs_create_file("hwdd-raw", 0444, tpacpi_dbg, NULL, &hwdd_raw_fops);

---
base-commit: a91337fb5e8e0127c8b5be87be9f3027f95b48bc
change-id: 9fa95cad-tpacpi-debugfs-unlock-unsafe-led-17ad492d8f5c

Thanks,
Rong