Skip to contentSkip to conversation

driver core: add TAINT_FORCED_BIND for when userspace manually messes with devices and drivers

PATCH In review Greg Kroah-Hartman 12 participants 40 messages Sep 14 – Oct 28

Subsystems (6)
Documentation USB PCI Tracing +2 more subsystems
lore
Share & tools
lore

Greg Kroah-Hartman

author maintainer
#0 lore raw

v4 cover driver core: add TAINT_FORCED_BIND for when userspace manually messes with devices and drivers

The ability to add and remove devices from a driver through the sysfs "bind" and "unbind" files was created all those decades ago as a way that kernel developers can iterate faster, and provide a debugging way for users to attempt to add a new device to a driver without having to rebuild their kernel.

This api over the years has been abused and recently come under a major fuzzing "attack" through tools like syzbot which decided that it would attempt to just randomly bind any driver to any type of device, causing loads of unneeded errors and pointless kernel patches to be generated by unsuspecting new developers.

Handle all of this by adding a new taint flag, TAINT_FORCED_BIND, which will be set on the driver if the bind/unbind sysfs files are ever written to. This lets kernel developers "know" that a user is attempting to do something that is not normal, and as such, if the kernel breaks they get to keep the shiny pieces laying around on the floor.

The flag is 'Y' which was unused, and can remembered as the user is "yeeting" the device being operated on here (thrown with force without regard for the thing being thrown).

Note, the taint flag gets set _BEFORE_ the bind/unbind callback happens, as many times crashes/oops/warnings/failures happen within the callback, and the taint flag needs to be there to show what was being attempted. If it were to be set after the callback happens, the oops report would not properly reflect what foolishness was being attempted.

Fuzzing tools like syzbot, that doesn't have hand-crafted rules to keep the tool from hitting bind/unbind, should be run with panic_on_taint enabled so that they fall over and don't continue on, thinking that they actually found a real issue.

Userspace operations that rely on the bind/unbind files to work around the lack of will to upgrade a kernel image to a newer version with proper support for new devices, or the lack of will to submit valid device ids to driver authors, will still work properly, but now the kernel will be flagged in a way that will show that perhaps those users should reconsider their behavior and work to have the drivers properly support these devices in a "native" manner.

Finally, the bind/unbind files can find real use-after-free issues with some drivers by forcing the process to happen virtually without having to rely on manual removal processes. Those real bugs should still be worked on, but by adding this taint flag, developers can more easily determine bug reports that are actually worth looking at.

---
Changes in v4:
- add documentation fixup for add_taint() and add_taint_module()
- Link to v3: https://patch.msgid.link/[email protected]

Changes in v3:
- Fixes based on sashiko review:
- Fix up prototype for when CONFIG_MODULES is disabled so it will
build properly, AGAIN.
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- rebase on 7.3-rc1
- Add changelog text to describe panic_on_taint and how it should be set
for tools like syzbot.
- Add changelog text to describe why 'Y' was picked.
- Fixes based on sashiko review:
- Make add_taint_module() handle a NULL for module pointer, fixing a
problem with built-in drivers.
- Fix up prototype for when CONFIG_MODULES is disabled so it will
actually build properly.
- rst table header fixes.
- Link to v1: https://patch.msgid.link/[email protected]

To: Luis Chamberlain <[email protected]>
To: Petr Pavlu <[email protected]>
To: Daniel Gomez <[email protected]>
To: Sami Tolvanen <[email protected]>
To: Aaron Tomlin <[email protected]>
To: Jonathan Corbet <[email protected]>
To: Shuah Khan <[email protected]>
To: Randy Dunlap <[email protected]>
To: Greg Kroah-Hartman <[email protected]>
To: "Rafael J. Wysocki" <[email protected]>
To: Danilo Krummrich <[email protected]>
To: Steven Rostedt <[email protected]>
To: Masami Hiramatsu <[email protected]>
To: Mathieu Desnoyers <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
Greg Kroah-Hartman (3):
module: pull out add_taint_module() to be public
module: fix up documentation for add_taint() and add_taint_module()
driver core: add TAINT_FORCED_BIND for when userspace manually messes with devices and drivers

 Documentation/admin-guide/tainted-kernels.rst | 52 ++++++++++++++-------------
 drivers/base/bus.c                            |  3 ++
 include/linux/module.h                        | 10 ++++++
 include/linux/panic.h                         |  3 +-
 include/trace/events/module.h                 |  3 +-
 kernel/module/main.c                          | 17 +++++++--
 kernel/panic.c                                | 10 +++---
 tools/debugging/kernel-chktaint               |  8 +++++
 8 files changed, 73 insertions(+), 33 deletions(-)

---
base-commit: 704340f1cd0dcef829eb62f5b48ae95a2ce17bdf
change-id: 20260825-bind_taint-d4077b870bc4

Best regards,

Signature · 1 line
Greg Kroah-Hartman <[email protected]>
author maintainer
#1 lore raw

PATCH v4 1/3 module: pull out add_taint_module() to be public

Other kernel code might want to call add_taint_module() so pull it out and make it global. If modules are not enabled, this defaults to a call to add_taint(), so all is fine.

---
 include/linux/module.h | 10 ++++++++++
 kernel/module/main.c   | 16 +++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)
include/linux/module.h +10 -0
index 96cc98568eea..f6f90cd88f15 100644
@@ -29,6 +29,7 @@
 #include <linux/srcu.h>
 #include <linux/static_call_types.h>
 #include <linux/dynamic_debug.h>
+#include <linux/panic.h>
 
 #include <linux/percpu.h>
 #include <asm/module.h>
@@ -770,6 +771,9 @@ static inline bool is_livepatch_module(struct module *mod)
 
 void module_for_each_mod(int(*func)(struct module *mod, void *data), void *data);
 
+void add_taint_module(struct module *mod, unsigned flag,
+		      enum lockdep_ok lockdep_ok);
+
 #else /* !CONFIG_MODULES... */
 
 static inline struct module *__module_address(unsigned long addr)
@@ -877,6 +881,12 @@ static inline bool module_is_coming(struct module *mod)
 static inline void module_for_each_mod(int(*func)(struct module *mod, void *data), void *data)
 {
 }
+
+static inline void add_taint_module(struct module *mod, unsigned flag,
+				    enum lockdep_ok lockdep_ok)
+{
+	add_taint(flag, lockdep_ok);
+}
 #endif /* CONFIG_MODULES */
 
 #ifdef CONFIG_SYSFS
kernel/module/main.c +13 -3
index d0e1e0bd2ad0..444d990c9983 100644
@@ -191,11 +191,21 @@ static inline int strong_try_module_get(struct module *mod)
 		return -ENOENT;
 }
 
-static inline void add_taint_module(struct module *mod, unsigned flag,
-				    enum lockdep_ok lockdep_ok)
+/**
+ * add_taint_module: add a taint flag if not already set for a specific module
+ * @mod: pointer to the module that caused the problem
+ * @flag: one of the TAINT_* constants.
+ * @lockdep_ok: whether lock debugging is still OK.
+ *
+ * If something bad has gone wrong, you'll want @lockdebug_ok = false, but for
+ * some noteworthy-but-not-corrupting cases, it can be set to true.
+ */
+void add_taint_module(struct module *mod, unsigned flag,
+		      enum lockdep_ok lockdep_ok)
 {
 	add_taint(flag, lockdep_ok);
-	set_bit(flag, &mod->taints);
+	if (mod)
+		set_bit(flag, &mod->taints);
 }
 
 /*
Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH v4 1/3] module: pull out add_taint_module() to be public

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Missing EXPORT_SYMBOL for add_taint_module() causes link failures for loadable modules. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Missing EXPORT_SYMBOL for add_taint_module() causes link failures for loadable modules. --

commit af64416dcd45d326037820ed7ffd035efeed6ec0
Author: Greg Kroah-Hartman <[email protected]>

module: pull out add_taint_module() to be public

This commit extracts add_taint_module() and makes it a globally accessible function so that other kernel code can call it to taint specific modules.

Quoted 4 lines
kernel/module/main.c +0 -0
index d0e1e0bd2ad06..444d990c99832 100644

[ ... ]

Quoted 13 lines
kernel/module/main.c +7 -2
@@ -191,11 +191,21 @@ static inline int strong_try_module_get(struct module *mod)
 		return -ENOENT;
 }
 
-static inline void add_taint_module(struct module *mod, unsigned flag,
-				    enum lockdep_ok lockdep_ok)
+/**
+ * add_taint_module: add a taint flag if not already set for a specific module
+ * @mod: pointer to the module that caused the problem
+ * @flag: one of the TAINT_* constants.
+ * @lockdep_ok: whether lock debugging is still OK.
+ *
+ * If something bad has gone wrong, you'll want @lockdebug_ok = false, but for

kernel/module/main.c static inline int strong_try_module_get(struct module *mod) · line 209

Quoted 10 lines
kernel/module/main.c +6 -1
+ * some noteworthy-but-not-corrupting cases, it can be set to true.
+ */
+void add_taint_module(struct module *mod, unsigned flag,
+		      enum lockdep_ok lockdep_ok)
 {
 	add_taint(flag, lockdep_ok);
-	set_bit(flag, &mod->taints);
+	if (mod)
+		set_bit(flag, &mod->taints);
 }

[Severity: Low]
Since the commit message mentions that other kernel code might want to call add_taint_module(), does this function need an EXPORT_SYMBOL() declaration?

Without an export, if a loadable module attempts to use this function as a module-aware counterpart to add_taint(), it will cause a build error due to an undefined reference during the modpost stage.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author maintainer
#3 lore raw

PATCH v4 2/3 module: fix up documentation for add_taint() and add_taint_module()

In reply to Greg Kroah-Hartman

When add_taint_module() was added, the documentation for it was copied directly from add_taint(). But that documentation was a bit wrong (wrong variable name, and misleading boolean reference.) Fix up both functions to have the correct documentation for how to use the lockdep_ok parameter to these functions.

---
 kernel/module/main.c | 5 +++--
 kernel/panic.c       | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)
kernel/module/main.c +3 -2
index 444d990c9983..369794876c3e 100644
@@ -197,8 +197,9 @@ static inline int strong_try_module_get(struct module *mod)
  * @flag: one of the TAINT_* constants.
  * @lockdep_ok: whether lock debugging is still OK.
  *
- * If something bad has gone wrong, you'll want @lockdebug_ok = false, but for
- * some noteworthy-but-not-corrupting cases, it can be set to true.
+ * If something bad has gone wrong, you'll want
+ * @lockdep_ok = LOCKDEP_NOW_UNRELIABLE, but for some
+ * noteworthy-but-not-corrupting cases, it can be set to LOCKDEP_STILL_OK.
  */
 void add_taint_module(struct module *mod, unsigned flag,
 		      enum lockdep_ok lockdep_ok)
kernel/panic.c +3 -2
index 213725b612aa..892045d8409e 100644
@@ -948,8 +948,9 @@ unsigned long get_taint(void)
  * @flag: one of the TAINT_* constants.
  * @lockdep_ok: whether lock debugging is still OK.
  *
- * If something bad has gone wrong, you'll want @lockdebug_ok = false, but for
- * some notewortht-but-not-corrupting cases, it can be set to true.
+ * If something bad has gone wrong, you'll want
+ * @lockdep_ok = LOCKDEP_NOW_UNRELIABLE, but for some
+ * noteworthy-but-not-corrupting cases, it can be set to LOCKDEP_STILL_OK.
  */
 void add_taint(unsigned flag, enum lockdep_ok lockdep_ok)
 {
Signature · 1 line
2.55.0
Reviewed-by on v4 2/3
#4 lore raw

Re: [PATCH v4 2/3] module: fix up documentation for add_taint() and add_taint_module()

Quoted 37 lines · Greg Kroah-Hartman

When add_taint_module() was added, the documentation for it was copied directly from add_taint(). But that documentation was a bit wrong (wrong variable name, and misleading boolean reference.) Fix up both functions to have the correct documentation for how to use the lockdep_ok parameter to these functions.

---
kernel/module/main.c | 5 +++--
kernel/panic.c | 5 +++--

2 files changed, 6 insertions(+), 4 deletions(-)
kernel/module/main.c +3 -2
index 444d990c9983..369794876c3e 100644
@@ -197,8 +197,9 @@ static inline int strong_try_module_get(struct module *mod)
 * @flag: one of the TAINT_* constants.
 * @lockdep_ok: whether lock debugging is still OK.
 *
- * If something bad has gone wrong, you'll want @lockdebug_ok = false, but for
- * some noteworthy-but-not-corrupting cases, it can be set to true.
+ * If something bad has gone wrong, you'll want
+ * @lockdep_ok = LOCKDEP_NOW_UNRELIABLE, but for some
+ * noteworthy-but-not-corrupting cases, it can be set to LOCKDEP_STILL_OK.
 */
 void add_taint_module(struct module *mod, unsigned flag,
 		      enum lockdep_ok lockdep_ok)
kernel/panic.c +0 -0
index 213725b612aa..892045d8409e 100644
@@ -948,8 +948,9 @@ unsigned long get_taint(void)
 * @flag: one of the TAINT_* constants.

kernel/panic.c unsigned long get_taint(void) · line 956

Quoted 10 lines
kernel/panic.c +3 -2
 * @lockdep_ok: whether lock debugging is still OK.
 *
- * If something bad has gone wrong, you'll want @lockdebug_ok = false, but for
- * some notewortht-but-not-corrupting cases, it can be set to true.
+ * If something bad has gone wrong, you'll want
+ * @lockdep_ok = LOCKDEP_NOW_UNRELIABLE, but for some
+ * noteworthy-but-not-corrupting cases, it can be set to LOCKDEP_STILL_OK.
 */
 void add_taint(unsigned flag, enum lockdep_ok lockdep_ok)
 {

Thanks.
--- Thanks!
https://lore.kernel.org/all/[email protected]/

reviewer Reviewed-by on v4 2/3
#5 lore raw

Re: [PATCH v4 2/3] module: fix up documentation for add_taint() and add_taint_module()

In reply to Greg Kroah-Hartman
Quoted 49 lines · Greg Kroah-Hartman

When add_taint_module() was added, the documentation for it was copied directly from add_taint(). But that documentation was a bit wrong (wrong variable name, and misleading boolean reference.) Fix up both functions to have the correct documentation for how to use the lockdep_ok parameter to these functions.

---
 kernel/module/main.c | 5 +++--
 kernel/panic.c       | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)
kernel/module/main.c +3 -2
index 444d990c9983..369794876c3e 100644
@@ -197,8 +197,9 @@ static inline int strong_try_module_get(struct module *mod)
  * @flag: one of the TAINT_* constants.
  * @lockdep_ok: whether lock debugging is still OK.
  *
- * If something bad has gone wrong, you'll want @lockdebug_ok = false, but for
- * some noteworthy-but-not-corrupting cases, it can be set to true.
+ * If something bad has gone wrong, you'll want
+ * @lockdep_ok = LOCKDEP_NOW_UNRELIABLE, but for some
+ * noteworthy-but-not-corrupting cases, it can be set to LOCKDEP_STILL_OK.
  */
 void add_taint_module(struct module *mod, unsigned flag,
 		      enum lockdep_ok lockdep_ok)
kernel/panic.c +3 -2
index 213725b612aa..892045d8409e 100644
@@ -948,8 +948,9 @@ unsigned long get_taint(void)
  * @flag: one of the TAINT_* constants.
  * @lockdep_ok: whether lock debugging is still OK.
  *
- * If something bad has gone wrong, you'll want @lockdebug_ok = false, but for
- * some notewortht-but-not-corrupting cases, it can be set to true.
+ * If something bad has gone wrong, you'll want
+ * @lockdep_ok = LOCKDEP_NOW_UNRELIABLE, but for some
+ * noteworthy-but-not-corrupting cases, it can be set to LOCKDEP_STILL_OK.
  */
 void add_taint(unsigned flag, enum lockdep_ok lockdep_ok)
 {
Signature · 2 lines
-- 
2.55.0
Signature · 1 line
Aaron Tomlin
author maintainer
#6 lore raw

PATCH v4 3/3 driver core: add TAINT_FORCED_BIND for when userspace manually messes with devices and drivers

In reply to Greg Kroah-Hartman

The ability to add and remove devices from a driver through the sysfs "bind" and "unbind" files was created all those decades ago as a way that kernel developers can iterate faster, and provide a debugging way for users to attempt to add a new device to a driver without having to rebuild their kernel.

This api over the years has been abused and recently come under a major fuzzing "attack" through tools like syzbot which decided that it would attempt to just randomly bind any driver to any type of device, causing loads of unneeded errors and pointless kernel patches to be generated by unsuspecting new developers.

Handle all of this by adding a new taint flag, TAINT_FORCED_BIND, which will be set on the driver if the bind/unbind sysfs files are ever written to. This lets kernel developers "know" that a user is attempting to do something that is not normal, and as such, if the kernel breaks they get to keep the shiny pieces laying around on the floor.

The flag is 'Y' which was unused, and can remembered as the user is "yeeting" the device being operated on here (thrown with force without regard for the thing being thrown).

Note, the taint flag gets set _BEFORE_ the bind/unbind callback happens, as many times crashes/oops/warnings/failures happen within the callback, and the taint flag needs to be there to show what was being attempted. If it were to be set after the callback happens, the oops report would not properly reflect what foolishness was being attempted.

Fuzzing tools like syzbot, that doesn't have hand-crafted rules to keep the tool from hitting bind/unbind, should be run with panic_on_taint enabled so that they fall over and don't continue on, thinking that they actually found a real issue.

Userspace operations that rely on the bind/unbind files to work around the lack of will to upgrade a kernel image to a newer version with proper support for new devices, or the lack of will to submit valid device ids to driver authors, will still work properly, but now the kernel will be flagged in a way that will show that perhaps those users should reconsider their behavior and work to have the drivers properly support these devices in a "native" manner.

Finally, the bind/unbind files can find real use-after-free issues with some drivers by forcing the process to happen virtually without having to rely on manual removal processes. Those real bugs should still be worked on, but by adding this taint flag, developers can more easily determine bug reports that are actually worth looking at.

---
 Documentation/admin-guide/tainted-kernels.rst | 52 ++++++++++++++-------------
 drivers/base/bus.c                            |  3 ++
 include/linux/panic.h                         |  3 +-
 include/trace/events/module.h                 |  3 +-
 kernel/panic.c                                |  5 +--
 tools/debugging/kernel-chktaint               |  8 +++++
 6 files changed, 46 insertions(+), 28 deletions(-)
Documentation/admin-guide/tainted-kernels.rst +28 -24
index 9ead927a37c0..abbf5e3dd749 100644
@@ -79,30 +79,31 @@ which bits are set::
 Table for decoding tainted state
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-===  ===  ======  ========================================================
-Bit  Log  Number  Reason that got the kernel tainted
-===  ===  ======  ========================================================
-  0  G/P       1  proprietary module was loaded
-  1  _/F       2  module was force loaded
-  2  _/S       4  kernel running on an out of specification system
-  3  _/R       8  module was force unloaded
-  4  _/M      16  processor reported a Machine Check Exception (MCE)
-  5  _/B      32  bad page referenced or some unexpected page flags
-  6  _/U      64  taint requested by userspace application
-  7  _/D     128  kernel died recently, i.e. there was an OOPS or BUG
-  8  _/A     256  ACPI table overridden by user
-  9  _/W     512  kernel issued warning
- 10  _/C    1024  staging driver was loaded
- 11  _/I    2048  workaround for bug in platform firmware applied
- 12  _/O    4096  externally-built ("out-of-tree") module was loaded
- 13  _/E    8192  unsigned module was loaded
- 14  _/L   16384  soft lockup occurred
- 15  _/K   32768  kernel has been live patched
- 16  _/X   65536  auxiliary taint, defined for and used by distros
- 17  _/T  131072  kernel was built with the struct randomization plugin
- 18  _/N  262144  an in-kernel test has been run
- 19  _/J  524288  userspace used a mutating debug operation in fwctl
-===  ===  ======  ========================================================
+===  ===  =======  ========================================================
+Bit  Log  Number   Reason that got the kernel tainted
+===  ===  =======  ========================================================
+  0  G/P        1  proprietary module was loaded
+  1  _/F        2  module was force loaded
+  2  _/S        4  kernel running on an out of specification system
+  3  _/R        8  module was force unloaded
+  4  _/M       16  processor reported a Machine Check Exception (MCE)
+  5  _/B       32  bad page referenced or some unexpected page flags
+  6  _/U       64  taint requested by userspace application
+  7  _/D      128  kernel died recently, i.e. there was an OOPS or BUG
+  8  _/A      256  ACPI table overridden by user
+  9  _/W      512  kernel issued warning
+ 10  _/C     1024  staging driver was loaded
+ 11  _/I     2048  workaround for bug in platform firmware applied
+ 12  _/O     4096  externally-built ("out-of-tree") module was loaded
+ 13  _/E     8192  unsigned module was loaded
+ 14  _/L    16384  soft lockup occurred
+ 15  _/K    32768  kernel has been live patched
+ 16  _/X    65536  auxiliary taint, defined for and used by distros
+ 17  _/T   131072  kernel was built with the struct randomization plugin
+ 18  _/N   262144  an in-kernel test has been run
+ 19  _/J   524288  userspace used a mutating debug operation in fwctl
+ 20  _/Y  1048576  device was manually bound or unbound from a driver
+===  ===  =======  ========================================================
 
 Note: The character ``_`` is representing a blank in this table to make reading
 easier.
@@ -189,3 +190,6 @@ More detailed explanation for tainting
  19) ``J`` if userspace opened /dev/fwctl/* and performed a FWTCL_RPC_DEBUG_WRITE
      to use the devices debugging features. Device debugging features could
      cause the device to malfunction in undefined ways.
+
+ 20) ``Y`` If userspace wrote to the `bind` or `unbind` sysfs files and
+     successfully bound or removed a device from a driver.
drivers/base/bus.c +3 -0
index d17bd91490ee..c51ad96d4de4 100644
@@ -19,6 +19,7 @@
 #include <linux/string.h>
 #include <linux/mutex.h>
 #include <linux/sysfs.h>
+#include <linux/panic.h>
 #include "base.h"
 #include "power/power.h"
 
@@ -241,6 +242,7 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf,
 
 	dev = bus_find_device_by_name(bus, NULL, buf);
 	if (dev && dev->driver == drv) {
+		add_taint_module(drv->owner, TAINT_FORCED_BIND, LOCKDEP_STILL_OK);
 		device_driver_detach(dev);
 		err = count;
 	}
@@ -264,6 +266,7 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf,
 
 	dev = bus_find_device_by_name(bus, NULL, buf);
 	if (dev && driver_match_device(drv, dev)) {
+		add_taint_module(drv->owner, TAINT_FORCED_BIND, LOCKDEP_STILL_OK);
 		err = device_driver_attach(drv, dev);
 		if (!err) {
 			/* success */
include/linux/panic.h +2 -1
index f1dd417e54b2..8e7250b0e913 100644
@@ -88,7 +88,8 @@ static inline void set_arch_panic_timeout(int timeout, int arch_default_timeout)
 #define TAINT_RANDSTRUCT		17
 #define TAINT_TEST			18
 #define TAINT_FWCTL			19
-#define TAINT_FLAGS_COUNT		20
+#define TAINT_FORCED_BIND		20
+#define TAINT_FLAGS_COUNT		21
 #define TAINT_FLAGS_MAX			((1UL << TAINT_FLAGS_COUNT) - 1)
 
 struct taint_flag {
include/trace/events/module.h +2 -1
index e5a006be9dc6..19df3e39bba4 100644
@@ -26,7 +26,8 @@ struct module;
 	{ (1UL << TAINT_OOT_MODULE),		"O" },		\
 	{ (1UL << TAINT_FORCED_MODULE),		"F" },		\
 	{ (1UL << TAINT_CRAP),			"C" },		\
-	{ (1UL << TAINT_UNSIGNED_MODULE),	"E" })
+	{ (1UL << TAINT_UNSIGNED_MODULE),	"E" },		\
+	{ (1UL << TAINT_FORCED_BIND),		"Y" })
 
 TRACE_EVENT(module_load,
 
kernel/panic.c +3 -2
index 892045d8409e..a4dbb6b8cd2b 100644
@@ -826,6 +826,7 @@ const struct taint_flag taint_flags[TAINT_FLAGS_COUNT] = {
 	TAINT_FLAG(RANDSTRUCT,			'T', ' '),
 	TAINT_FLAG(TEST,			'N', ' '),
 	TAINT_FLAG(FWCTL,			'J', ' '),
+	TAINT_FLAG(FORCED_BIND,			'Y', ' '),
 };
 
 #undef TAINT_FLAG
@@ -862,9 +863,9 @@ static void print_tainted_seq(struct seq_buf *s, bool verbose)
  * exact size is allocated dynamically; the initial buffer remains
  * as a fallback if allocation fails.
  *
- * The verbose taint string currently requires up to 327 characters.
+ * The verbose taint string currently requires up to 344 characters.
  */
-#define INIT_TAINT_BUF_MAX 350
+#define INIT_TAINT_BUF_MAX 370
 
 static char init_taint_buf[INIT_TAINT_BUF_MAX] __initdata;
 static char *taint_buf __refdata = init_taint_buf;
tools/debugging/kernel-chktaint +8 -0
index e1571c04afb5..d8628be37214 100755
@@ -211,6 +211,14 @@ else
 	addout "J"
 	echo " * fwctl's mutating debug interface was used (#19)"
 fi
+
+T=`expr $T / 2`
+if [ `expr $T % 2` -eq 0 ]; then
+	addout " "
+else
+	addout "Y"
+	echo " * device was manually bound or unbound from a driver (#20)"
+fi
 echo "Raw taint value as int/string: $taint/'$out'"
 
 # report on any tainted loadable modules
Signature · 1 line
2.55.0
#7 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Medium] The documentation incorrectly states that the kernel is tainted only when a device is 'successfully' bound or removed, but the code taints the kernel before the operation, even if it fails.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but a TOCTOU race in unbind_store allows detaching the wrong driver from a device due to a lockless check followed by an unconditional detach. --

commit ab4daed0c54fee77e3c6d683fc2a55fadc4aaef3
Author: Greg Kroah-Hartman <[email protected]>

driver core: add TAINT_FORCED_BIND for when userspace manually messes with devices and drivers

This commit adds a new taint flag, TAINT_FORCED_BIND, which is set when userspace manually binds or unbinds a device from a driver via sysfs. The taint is added before the callback runs to ensure oops reports reflect the attempted manual manipulation. This aims to help kernel developers identify when crashes result from abnormal userspace driver binding operations.

Quoted 4 lines
Documentation/admin-guide/tainted-kernels.rst +0 -0
index 9ead927a37c0f..abbf5e3dd7495 100644

[ ... ]

Documentation/admin-guide/tainted-kernels.rst More detailed explanation for tainting · line 195

Quoted 7 lines
Documentation/admin-guide/tainted-kernels.rst +3 -0
@@ -189,3 +190,6 @@ More detailed explanation for tainting
  19) ``J`` if userspace opened /dev/fwctl/* and performed a FWTCL_RPC_DEBUG_WRITE
      to use the devices debugging features. Device debugging features could
      cause the device to malfunction in undefined ways.
+
+ 20) ``Y`` If userspace wrote to the `bind` or `unbind` sysfs files and
+     successfully bound or removed a device from a driver.

[Severity: Medium]
The documentation here explicitly says "successfully bound or removed", but looking at the code in bind_store() and unbind_store() in drivers/base/bus.c, the kernel is tainted before the operation is attempted. Does this mean the kernel remains permanently tainted even if the attach or detach operation fails, making this documentation inaccurate?

Quoted 4 lines
drivers/base/bus.c +0 -0
index d17bd91490ee4..c51ad96d4de4b 100644

[ ... ]

drivers/base/bus.c static ssize_t unbind_store(struct device_driver *drv, const char *buf, · line 244

Quoted 4 lines
drivers/base/bus.c +0 -0
@@ -241,6 +242,7 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf,
 
 	dev = bus_find_device_by_name(bus, NULL, buf);
 	if (dev && dev->driver == drv) {

[Severity: High]
This isn't a bug introduced by this patch, but looking at unbind_store(), is there a TOCTOU race window here?

The check dev->driver == drv evaluates without holding a lock. If Thread A evaluates this check, and concurrently Thread B unbinds the driver and binds a new driver to the same device:

Thread A
unbind_store()

    if (dev && dev->driver == drv) { // true

Thread B
unbinds original driver
binds new unrelated driver

Thread A then continues:

drivers/base/bus.c static ssize_t unbind_store(struct device_driver *drv, const char *buf, · line 246

Quoted 2 lines
drivers/base/bus.c +1 -0
+		add_taint_module(drv->owner, TAINT_FORCED_BIND, LOCKDEP_STILL_OK);
 		device_driver_detach(dev);

and calls device_driver_detach(dev). Since device_driver_detach() in drivers/base/dd.c calls device_release_driver_internal(dev, NULL, dev->parent), the NULL passed as the driver argument bypasses the specific driver match validation inside device_release_driver_internal.

Does this mean the new, unrelated driver could be unconditionally detached by Thread A?

drivers/base/bus.c static ssize_t bind_store(struct device_driver *drv, const char *buf, · line 270

Quoted 9 lines
drivers/base/bus.c +0 -0
 		err = count;
 	}
drivers/base/bus.c +1 -0
 	put_device(dev);
@@ -264,6 +266,7 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf,
 
 	dev = bus_find_device_by_name(bus, NULL, buf);
 	if (dev && driver_match_device(drv, dev)) {
+		add_taint_module(drv->owner, TAINT_FORCED_BIND, LOCKDEP_STILL_OK);
 		err = device_driver_attach(drv, dev);

[Severity: Medium]
This matches the observation above: if device_driver_attach(drv, dev) fails, the kernel is already tainted, which contradicts the documentation stating it only happens on success. Could the documentation be updated to clarify that the taint is applied on the attempt, regardless of success?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
maintainer Acked-by on the v4 series
#8 lore raw
In reply to Greg Kroah-Hartman
Quoted 29 lines · Greg Kroah-Hartman

The ability to add and remove devices from a driver through the sysfs "bind" and "unbind" files was created all those decades ago as a way that kernel developers can iterate faster, and provide a debugging way for users to attempt to add a new device to a driver without having to rebuild their kernel.

This api over the years has been abused and recently come under a major fuzzing "attack" through tools like syzbot which decided that it would attempt to just randomly bind any driver to any type of device, causing loads of unneeded errors and pointless kernel patches to be generated by unsuspecting new developers.

Handle all of this by adding a new taint flag, TAINT_FORCED_BIND, which will be set on the driver if the bind/unbind sysfs files are ever written to. This lets kernel developers "know" that a user is attempting to do something that is not normal, and as such, if the kernel breaks they get to keep the shiny pieces laying around on the floor.

The flag is 'Y' which was unused, and can remembered as the user is "yeeting" the device being operated on here (thrown with force without regard for the thing being thrown).

Note, the taint flag gets set _BEFORE_ the bind/unbind callback happens, as many times crashes/oops/warnings/failures happen within the callback, and the taint flag needs to be there to show what was being attempted. If it were to be set after the callback happens, the oops report would not properly reflect what foolishness was being attempted.

Quoted 6 lines

Fuzzing tools like syzbot, that doesn't have hand-crafted rules to keep the tool from hitting bind/unbind, should be run with panic_on_taint enabled so that they fall over and don't continue on, thinking that they actually found a real issue.

Userspace operations that rely on the bind/unbind files

I agree that this should be avoided.

But I also think the biggest offender really is driver_override. Specifically, on a hot-pluggable bus a driver must be complient with the device driver lifecycle rules and hence shouldn't break on bind/unbind. I think it would be nice to not taint the kernel for such busses, and only taint on driver_override, as I think we'd still want the bug reports for such cases.

But I think this is fine to leave for a follow-up.

Quoted 15 lines

to work around
the lack of will to upgrade a kernel image to a newer version with proper support for new devices, or the lack of will to submit valid device ids to driver authors, will still work properly, but now the kernel will be flagged in a way that will show that perhaps those users should reconsider their behavior and work to have the drivers properly support these devices in a "native" manner.

Finally, the bind/unbind files can find real use-after-free issues with some drivers by forcing the process to happen virtually without having to rely on manual removal processes. Those real bugs should still be worked on, but by adding this taint flag, developers can more easily determine bug reports that are actually worth looking at.

author maintainer
#9 lore raw
Quoted 39 lines · Danilo Krummrich
Quoted 29 lines · Greg Kroah-Hartman

The ability to add and remove devices from a driver through the sysfs "bind" and "unbind" files was created all those decades ago as a way that kernel developers can iterate faster, and provide a debugging way for users to attempt to add a new device to a driver without having to rebuild their kernel.

This api over the years has been abused and recently come under a major fuzzing "attack" through tools like syzbot which decided that it would attempt to just randomly bind any driver to any type of device, causing loads of unneeded errors and pointless kernel patches to be generated by unsuspecting new developers.

Handle all of this by adding a new taint flag, TAINT_FORCED_BIND, which will be set on the driver if the bind/unbind sysfs files are ever written to. This lets kernel developers "know" that a user is attempting to do something that is not normal, and as such, if the kernel breaks they get to keep the shiny pieces laying around on the floor.

The flag is 'Y' which was unused, and can remembered as the user is "yeeting" the device being operated on here (thrown with force without regard for the thing being thrown).

Note, the taint flag gets set _BEFORE_ the bind/unbind callback happens, as many times crashes/oops/warnings/failures happen within the callback, and the taint flag needs to be there to show what was being attempted. If it were to be set after the callback happens, the oops report would not properly reflect what foolishness was being attempted.

Quoted 6 lines

Fuzzing tools like syzbot, that doesn't have hand-crafted rules to keep the tool from hitting bind/unbind, should be run with panic_on_taint enabled so that they fall over and don't continue on, thinking that they actually found a real issue.

Userspace operations that rely on the bind/unbind files

I agree that this should be avoided.

Quoted 7 lines

But I also think the biggest offender really is driver_override. Specifically, on a hot-pluggable bus a driver must be complient with the device driver lifecycle rules and hence shouldn't break on bind/unbind. I think it would be nice to not taint the kernel for such busses, and only taint on driver_override, as I think we'd still want the bug reports for such cases.

But I think this is fine to leave for a follow-up.

Yeah, let's see how this goes, thanks for the review!

greg k-h

#10 lore raw
Quoted 52 lines · Greg Kroah-Hartman
Quoted 8 lines · Danilo Krummrich
Quoted 7 lines · Greg Kroah-Hartman

The ability to add and remove devices from a driver through the sysfs "bind" and "unbind" files was created all those decades ago as a way that kernel developers can iterate faster, and provide a debugging way for users to attempt to add a new device to a driver without having to rebuild their kernel.

This api over the years has been abused and recently come under a

major

Quoted 2 lines
Quoted 2 lines

fuzzing "attack" through tools like syzbot which decided that it would attempt to just randomly bind any driver to any type of device,

causing

Quoted 1 line
Quoted 1 line

loads of unneeded errors and pointless kernel patches to be generated

by

Quoted 3 lines
Quoted 3 lines

unsuspecting new developers.

Handle all of this by adding a new taint flag, TAINT_FORCED_BIND,

which

Quoted 11 lines
Quoted 11 lines

will be set on the driver if the bind/unbind sysfs files are ever written to. This lets kernel developers "know" that a user is attempting to do something that is not normal, and as such, if the kernel breaks they get to keep the shiny pieces laying around on the floor.

The flag is 'Y' which was unused, and can remembered as the user is "yeeting" the device being operated on here (thrown with force without regard for the thing being thrown).

Note, the taint flag gets set _BEFORE_ the bind/unbind callback

happens,

Quoted 1 line
Quoted 1 line

as many times crashes/oops/warnings/failures happen within the

callback,

Quoted 5 lines
Quoted 5 lines

and the taint flag needs to be there to show what was being attempted. If it were to be set after the callback happens, the oops report would not properly reflect what foolishness was being attempted.

Fuzzing tools like syzbot, that doesn't have hand-crafted rules to

keep

Quoted 2 lines
Quoted 2 lines

the tool from hitting bind/unbind, should be run with panic_on_taint enabled so that they fall over and don't continue on, thinking that

they

Quoted 7 lines
Quoted 3 lines

actually found a real issue.

Userspace operations that rely on the bind/unbind files

I agree that this should be avoided.

But I also think the biggest offender really is driver_override.

Specifically,

Quoted 2 lines

on a hot-pluggable bus a driver must be complient with the device driver lifecycle rules and hence shouldn't break on bind/unbind. I think it

Quoted 9 lines

would be

Quoted 1 line

nice to not taint the kernel for such busses, and only taint on

driver_override,

Quoted 3 lines

as I think we'd still want the bug reports for such cases.

But I think this is fine to leave for a follow-up.

Yeah, let's see how this goes, thanks for the review!

Famous last words :)

(I see no regression but AI finds mysteries)

Quoted 1 line

greg k-h

--- Thanks!
https://lore.kernel.org/all/[email protected]/

#11 lore raw
In reply to Danilo Krummrich
Quoted 39 lines · Danilo Krummrich
Quoted 29 lines · Greg Kroah-Hartman

The ability to add and remove devices from a driver through the sysfs "bind" and "unbind" files was created all those decades ago as a way that kernel developers can iterate faster, and provide a debugging way for users to attempt to add a new device to a driver without having to rebuild their kernel.

This api over the years has been abused and recently come under a major fuzzing "attack" through tools like syzbot which decided that it would attempt to just randomly bind any driver to any type of device, causing loads of unneeded errors and pointless kernel patches to be generated by unsuspecting new developers.

Handle all of this by adding a new taint flag, TAINT_FORCED_BIND, which will be set on the driver if the bind/unbind sysfs files are ever written to. This lets kernel developers "know" that a user is attempting to do something that is not normal, and as such, if the kernel breaks they get to keep the shiny pieces laying around on the floor.

The flag is 'Y' which was unused, and can remembered as the user is "yeeting" the device being operated on here (thrown with force without regard for the thing being thrown).

Note, the taint flag gets set _BEFORE_ the bind/unbind callback happens, as many times crashes/oops/warnings/failures happen within the callback, and the taint flag needs to be there to show what was being attempted. If it were to be set after the callback happens, the oops report would not properly reflect what foolishness was being attempted.

Quoted 6 lines

Fuzzing tools like syzbot, that doesn't have hand-crafted rules to keep the tool from hitting bind/unbind, should be run with panic_on_taint enabled so that they fall over and don't continue on, thinking that they actually found a real issue.

Userspace operations that rely on the bind/unbind files

I agree that this should be avoided.

Quoted 7 lines

But I also think the biggest offender really is driver_override. Specifically, on a hot-pluggable bus a driver must be complient with the device driver lifecycle rules and hence shouldn't break on bind/unbind. I think it would be nice to not taint the kernel for such busses, and only taint on driver_override, as I think we'd still want the bug reports for such cases.

But I think this is fine to leave for a follow-up.

I fully agree. I'm fine and support tainting on driver_override, but bind/unbind are used occasionally in my bubble and I consider drivers not handling that properly buggy.

So please let's do

drivers/base/bus.c +1 -2
index c51ad96d4de4..ce8fb14ea19a 100644
@@ -242,7 +242,6 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf,
 
 	dev = bus_find_device_by_name(bus, NULL, buf);
 	if (dev && dev->driver == drv) {
-		add_taint_module(drv->owner, TAINT_FORCED_BIND, LOCKDEP_STILL_OK);
 		device_driver_detach(dev);
 		err = count;
 	}
@@ -266,7 +265,6 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf,
 
 	dev = bus_find_device_by_name(bus, NULL, buf);
 	if (dev && driver_match_device(drv, dev)) {
-		add_taint_module(drv->owner, TAINT_FORCED_BIND, LOCKDEP_STILL_OK);
 		err = device_driver_attach(drv, dev);
 		if (!err) {
 			/* success */
@@ -513,6 +511,7 @@ static ssize_t driver_override_store(struct device *dev,
 {
 	int ret;
 
+	add_taint_module(drv->owner, TAINT_FORCED_BIND, LOCKDEP_STILL_OK);
 	ret = __device_set_driver_override(dev, buf, count);
 	if (ret)
 		return ret;

(plus the needed documentation adaptions and maybe a rename s/TAINT_FORCED_BIND/TAINT_DRIVER_OVERRIDE/).

Best regards
Uwe

#12 lore raw
Quoted 46 lines · Uwe Kleine-König
Quoted 45 lines · Danilo Krummrich
Quoted 29 lines · Greg Kroah-Hartman

The ability to add and remove devices from a driver through the sysfs "bind" and "unbind" files was created all those decades ago as a way that kernel developers can iterate faster, and provide a debugging way for users to attempt to add a new device to a driver without having to rebuild their kernel.

This api over the years has been abused and recently come under a major fuzzing "attack" through tools like syzbot which decided that it would attempt to just randomly bind any driver to any type of device, causing loads of unneeded errors and pointless kernel patches to be generated by unsuspecting new developers.

Handle all of this by adding a new taint flag, TAINT_FORCED_BIND, which will be set on the driver if the bind/unbind sysfs files are ever written to. This lets kernel developers "know" that a user is attempting to do something that is not normal, and as such, if the kernel breaks they get to keep the shiny pieces laying around on the floor.

The flag is 'Y' which was unused, and can remembered as the user is "yeeting" the device being operated on here (thrown with force without regard for the thing being thrown).

Note, the taint flag gets set _BEFORE_ the bind/unbind callback happens, as many times crashes/oops/warnings/failures happen within the callback, and the taint flag needs to be there to show what was being attempted. If it were to be set after the callback happens, the oops report would not properly reflect what foolishness was being attempted.

Quoted 6 lines

Fuzzing tools like syzbot, that doesn't have hand-crafted rules to keep the tool from hitting bind/unbind, should be run with panic_on_taint enabled so that they fall over and don't continue on, thinking that they actually found a real issue.

Userspace operations that rely on the bind/unbind files

I agree that this should be avoided.

But I also think the biggest offender really is driver_override. Specifically, on a hot-pluggable bus a driver must be complient with the device driver lifecycle rules and hence shouldn't break on bind/unbind. I think it would be nice to not taint the kernel for such busses, and only taint on driver_override, as I think we'd still want the bug reports for such cases.

Quoted 5 lines
Quoted 1 line

But I think this is fine to leave for a follow-up.

I fully agree. I'm fine and support tainting on driver_override, but bind/unbind are used occasionally in my bubble and I consider drivers not handling that properly buggy.

In the IIO subsystem, unbind/rebind is the de-facto way to reset a wedged chip.

A few examples where other reset methods were reject in favor of unbind/bind:

https://lore.kernel.org/linux-iio/20240727160216.2488ed29@jic23-huawei/

This needs documenting as it's custom ABI. Note that we don't often accept custom ABI. Particularly not a hook that seems to reset the device. If you want to do that, unbind and rebind the whole drive[r] so we are in a known state etc.

https://lore.kernel.org/linux-iio/20240720163440.03c713dc@jic23-huawei/

Firstly as stated below, we don't provide interfaces for this because it's a heavy weight process that is most of the effort of unbinding and rebinding the driver. So if you need to reset, do that.

https://lore.kernel.org/linux-iio/20250505200609.54756520@jic23-huawei/

The solution is to run it once at driver bind. Similar to reset below, if the usecase needs to re do it then unbinding and rebinding the driver reflects the fact we are taking it effectively offline for a while.

Quoted 37 lines

So please let's do

drivers/base/bus.c +1 -2
index c51ad96d4de4..ce8fb14ea19a 100644
@@ -242,7 +242,6 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf,
 
 	dev = bus_find_device_by_name(bus, NULL, buf);
 	if (dev && dev->driver == drv) {
-		add_taint_module(drv->owner, TAINT_FORCED_BIND, LOCKDEP_STILL_OK);
 		device_driver_detach(dev);
 		err = count;
 	}
@@ -266,7 +265,6 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf,
 
 	dev = bus_find_device_by_name(bus, NULL, buf);
 	if (dev && driver_match_device(drv, dev)) {
-		add_taint_module(drv->owner, TAINT_FORCED_BIND, LOCKDEP_STILL_OK);
 		err = device_driver_attach(drv, dev);
 		if (!err) {
 			/* success */
@@ -513,6 +511,7 @@ static ssize_t driver_override_store(struct device *dev,
 {
 	int ret;
 
+	add_taint_module(drv->owner, TAINT_FORCED_BIND, LOCKDEP_STILL_OK);
 	ret = __device_set_driver_override(dev, buf, count);
 	if (ret)
 		return ret;

(plus the needed documentation adaptions and maybe a rename s/TAINT_FORCED_BIND/TAINT_DRIVER_OVERRIDE/).

Best regards
Uwe

#13 lore raw

Am 22.09.26 um 15:40 schrieb David Lechner:

Quoted 46 lines · Uwe Kleine-König
Quoted 45 lines · Danilo Krummrich
Quoted 44 lines · Greg Kroah-Hartman
Quoted 29 lines

The ability to add and remove devices from a driver through the sysfs "bind" and "unbind" files was created all those decades ago as a way that kernel developers can iterate faster, and provide a debugging way for users to attempt to add a new device to a driver without having to rebuild their kernel.

This api over the years has been abused and recently come under a major fuzzing "attack" through tools like syzbot which decided that it would attempt to just randomly bind any driver to any type of device, causing loads of unneeded errors and pointless kernel patches to be generated by unsuspecting new developers.

Handle all of this by adding a new taint flag, TAINT_FORCED_BIND, which will be set on the driver if the bind/unbind sysfs files are ever written to. This lets kernel developers "know" that a user is attempting to do something that is not normal, and as such, if the kernel breaks they get to keep the shiny pieces laying around on the floor.

The flag is 'Y' which was unused, and can remembered as the user is "yeeting" the device being operated on here (thrown with force without regard for the thing being thrown).

Note, the taint flag gets set _BEFORE_ the bind/unbind callback happens, as many times crashes/oops/warnings/failures happen within the callback, and the taint flag needs to be there to show what was being attempted. If it were to be set after the callback happens, the oops report would not properly reflect what foolishness was being attempted.

Quoted 6 lines

Fuzzing tools like syzbot, that doesn't have hand-crafted rules to keep the tool from hitting bind/unbind, should be run with panic_on_taint enabled so that they fall over and don't continue on, thinking that they actually found a real issue.

Userspace operations that rely on the bind/unbind files

I agree that this should be avoided.

But I also think the biggest offender really is driver_override. Specifically, on a hot-pluggable bus a driver must be complient with the device driver lifecycle rules and hence shouldn't break on bind/unbind. I think it would be nice to not taint the kernel for such busses, and only taint on driver_override, as I think we'd still want the bug reports for such cases.

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

But I think this is fine to leave for a follow-up.

I fully agree. I'm fine and support tainting on driver_override, but bind/unbind are used occasionally in my bubble and I consider drivers not handling that properly buggy.

I fully agree with this, drivers should correctly implement the lifecycle model and not just break when being unbound at a improper time. Drivers suffering from this can easily break this way when unloading the associated kernel module, so this taint is no solution.

Quoted 18 lines

In the IIO subsystem, unbind/rebind is the de-facto way to reset a wedged chip.

A few examples where other reset methods were reject in favor of unbind/bind:

https://lore.kernel.org/linux-iio/20240727160216.2488ed29@jic23-huawei/

This needs documenting as it's custom ABI. Note that we don't often accept custom ABI. Particularly not a hook that seems to reset the device. If you want to do that, unbind and rebind the whole drive[r] so we are in a known state etc.

https://lore.kernel.org/linux-iio/20240720163440.03c713dc@jic23-huawei/

Firstly as stated below, we don't provide interfaces for this because it's a heavy weight process that is most of the effort of unbinding and rebinding the driver. So if you need to reset, do that.

Quoted 7 lines

https://lore.kernel.org/linux-iio/20250505200609.54756520@jic23-huawei/

The solution is to run it once at driver bind. Similar to reset below, if the usecase needs to re do it then unbinding and rebinding the driver reflects the fact we are taking it effectively offline for a while.

I also consider bind/unbind to be an official API to interact with devices, so i want to use them in the future with the WMI subsystem.

AFAIK the underlying reason for this series is that some drivers break when being bound to unsupported devices. However IMHO drivers should verify that they support a given device inside their .probe callback, and the associated bus should only match devices with drivers that explicitly claim support for those devices (ignoring driver_override).

Can we get some example bugs uncovered this way?

Thanks,
Armin Wolf

Quoted 36 lines
Quoted 36 lines

So please let's do

drivers/base/bus.c +1 -2
index c51ad96d4de4..ce8fb14ea19a 100644
@@ -242,7 +242,6 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf,
 
  	dev = bus_find_device_by_name(bus, NULL, buf);
  	if (dev && dev->driver == drv) {
-		add_taint_module(drv->owner, TAINT_FORCED_BIND, LOCKDEP_STILL_OK);
  		device_driver_detach(dev);
  		err = count;
  	}
@@ -266,7 +265,6 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf,
 
  	dev = bus_find_device_by_name(bus, NULL, buf);
  	if (dev && driver_match_device(drv, dev)) {
-		add_taint_module(drv->owner, TAINT_FORCED_BIND, LOCKDEP_STILL_OK);
  		err = device_driver_attach(drv, dev);
  		if (!err) {
  			/* success */
@@ -513,6 +511,7 @@ static ssize_t driver_override_store(struct device *dev,
  {
  	int ret;
 
+	add_taint_module(drv->owner, TAINT_FORCED_BIND, LOCKDEP_STILL_OK);
  	ret = __device_set_driver_override(dev, buf, count);
  	if (ret)
  		return ret;

(plus the needed documentation adaptions and maybe a rename s/TAINT_FORCED_BIND/TAINT_DRIVER_OVERRIDE/).

Best regards
Uwe

#14 lore raw
Quoted 86 lines · Armin Wolf

Am 22.09.26 um 15:40 schrieb David Lechner:

Quoted 46 lines · Uwe Kleine-König
Quoted 45 lines · Danilo Krummrich
Quoted 44 lines · Greg Kroah-Hartman
Quoted 29 lines

The ability to add and remove devices from a driver through the sysfs "bind" and "unbind" files was created all those decades ago as a way that kernel developers can iterate faster, and provide a debugging way for users to attempt to add a new device to a driver without having to rebuild their kernel.

This api over the years has been abused and recently come under a major fuzzing "attack" through tools like syzbot which decided that it would attempt to just randomly bind any driver to any type of device, causing loads of unneeded errors and pointless kernel patches to be generated by unsuspecting new developers.

Handle all of this by adding a new taint flag, TAINT_FORCED_BIND, which will be set on the driver if the bind/unbind sysfs files are ever written to. This lets kernel developers "know" that a user is attempting to do something that is not normal, and as such, if the kernel breaks they get to keep the shiny pieces laying around on the floor.

The flag is 'Y' which was unused, and can remembered as the user is "yeeting" the device being operated on here (thrown with force without regard for the thing being thrown).

Note, the taint flag gets set _BEFORE_ the bind/unbind callback happens, as many times crashes/oops/warnings/failures happen within the callback, and the taint flag needs to be there to show what was being attempted. If it were to be set after the callback happens, the oops report would not properly reflect what foolishness was being attempted.

Quoted 6 lines

Fuzzing tools like syzbot, that doesn't have hand-crafted rules to keep the tool from hitting bind/unbind, should be run with panic_on_taint enabled so that they fall over and don't continue on, thinking that they actually found a real issue.

Userspace operations that rely on the bind/unbind files

I agree that this should be avoided.

But I also think the biggest offender really is driver_override. Specifically, on a hot-pluggable bus a driver must be complient with the device driver lifecycle rules and hence shouldn't break on bind/unbind. I think it would be nice to not taint the kernel for such busses, and only taint on driver_override, as I think we'd still want the bug reports for such cases.

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

But I think this is fine to leave for a follow-up.

I fully agree. I'm fine and support tainting on driver_override, but bind/unbind are used occasionally in my bubble and I consider drivers not handling that properly buggy.

I fully agree with this, drivers should correctly implement the lifecycle model and not just break when being unbound at a improper time. Drivers suffering from this can easily break this way when unloading the associated kernel module, so this taint is no solution.

Quoted 18 lines

In the IIO subsystem, unbind/rebind is the de-facto way to reset a wedged chip.

A few examples where other reset methods were reject in favor of unbind/bind:

https://lore.kernel.org/linux-iio/20240727160216.2488ed29@jic23-huawei/

This needs documenting as it's custom ABI. Note that we don't often accept custom ABI. Particularly not a hook that seems to reset the device. If you want to do that, unbind and rebind the whole drive[r] so we are in a known state etc.

https://lore.kernel.org/linux-iio/20240720163440.03c713dc@jic23-huawei/

Firstly as stated below, we don't provide interfaces for this because it's a heavy weight process that is most of the effort of unbinding and rebinding the driver. So if you need to reset, do that.

Quoted 7 lines

https://lore.kernel.org/linux-iio/20250505200609.54756520@jic23-huawei/

The solution is to run it once at driver bind. Similar to reset below, if the usecase needs to re do it then unbinding and rebinding the driver reflects the fact we are taking it effectively offline for a while.

I also consider bind/unbind to be an official API to interact with devices, so i want to use them in the future with the WMI subsystem.

Quoted 7 lines

AFAIK the underlying reason for this series is that some drivers break when being bound to unsupported devices. However IMHO drivers should verify that they support a given device inside their .probe callback, and the associated bus should only match devices with drivers that explicitly claim support for those devices (ignoring driver_override).

Can we get some example bugs uncovered this way?

There is a related set of mail threads, that however are not the trigger for Greg's effort.

Initially I suggested to protect the pwm-tegra driver from attaching to unexpected devices via a check in .probe():

https://lore.kernel.org/linux-pwm/ed943d9be3b785514e0f65a5b8c13a78aba7a090.1789741839.git.u.kleine-koenig@baylibre.com/

Thierry suggested a dedicated flag in struct device_driver instead allowing to opt out of the driver_override mechanism:

https://lore.kernel.org/linux-pwm/[email protected]/

I think Greg was motivated by syzcaller triggering various exceptions using driver_override.

So my opinion on the right way forward is:

- Given that there are only very few drivers that are supposed to be used for a driver override, there should be an opt-in (instead of the opt-out that Thierry suggested).

- The changes from this thread (i.e. make usage of bind/unbind result in a taint) should be dropped. I wrote earlier that I'm ok with a taint for a usage of driver_override, but with the previous item implemented, I don't think that is necessary.

Best regards
Uwe

author maintainer
#15 lore raw
In reply to Armin Wolf
Quoted 49 lines · Armin Wolf

Am 22.09.26 um 15:40 schrieb David Lechner:

Quoted 47 lines · Uwe Kleine-König
Quoted 46 lines · Danilo Krummrich
Quoted 45 lines · Greg Kroah-Hartman
Quoted 29 lines

The ability to add and remove devices from a driver through the sysfs "bind" and "unbind" files was created all those decades ago as a way that kernel developers can iterate faster, and provide a debugging way for users to attempt to add a new device to a driver without having to rebuild their kernel.

This api over the years has been abused and recently come under a major fuzzing "attack" through tools like syzbot which decided that it would attempt to just randomly bind any driver to any type of device, causing loads of unneeded errors and pointless kernel patches to be generated by unsuspecting new developers.

Handle all of this by adding a new taint flag, TAINT_FORCED_BIND, which will be set on the driver if the bind/unbind sysfs files are ever written to. This lets kernel developers "know" that a user is attempting to do something that is not normal, and as such, if the kernel breaks they get to keep the shiny pieces laying around on the floor.

The flag is 'Y' which was unused, and can remembered as the user is "yeeting" the device being operated on here (thrown with force without regard for the thing being thrown).

Note, the taint flag gets set _BEFORE_ the bind/unbind callback happens, as many times crashes/oops/warnings/failures happen within the callback, and the taint flag needs to be there to show what was being attempted. If it were to be set after the callback happens, the oops report would not properly reflect what foolishness was being attempted.

Quoted 6 lines

Fuzzing tools like syzbot, that doesn't have hand-crafted rules to keep the tool from hitting bind/unbind, should be run with panic_on_taint enabled so that they fall over and don't continue on, thinking that they actually found a real issue.

Userspace operations that rely on the bind/unbind files

I agree that this should be avoided.

But I also think the biggest offender really is driver_override. Specifically, on a hot-pluggable bus a driver must be complient with the device driver lifecycle rules and hence shouldn't break on bind/unbind. I think it would be nice to not taint the kernel for such busses, and only taint on driver_override, as I think we'd still want the bug reports for such cases.

But I think this is fine to leave for a follow-up.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

I fully agree. I'm fine and support tainting on driver_override, but bind/unbind are used occasionally in my bubble and I consider drivers not handling that properly buggy.

I fully agree with this, drivers should correctly implement the lifecycle model and not just break when being unbound at a improper time. Drivers suffering from this can easily break this way when unloading the associated kernel module, so this taint is no solution.

It's a "solution" in that it tells the developer "hey, the user did something odd and unsupported". rmmod is also not a normal operation, there's no requirement that it actually work as it's usually a "best effort" type of thing.

Quoted 20 lines
Quoted 20 lines

In the IIO subsystem, unbind/rebind is the de-facto way to reset a wedged chip.

A few examples where other reset methods were reject in favor of unbind/bind:

https://lore.kernel.org/linux-iio/20240727160216.2488ed29@jic23-huawei/

This needs documenting as it's custom ABI. Note that we don't often accept custom ABI. Particularly not a hook that seems to reset the device. If you want to do that, unbind and rebind the whole drive[r] so we are in a known state etc.

https://lore.kernel.org/linux-iio/20240720163440.03c713dc@jic23-huawei/

Firstly as stated below, we don't provide interfaces for this because it's a heavy weight process that is most of the effort of unbinding and rebinding the driver. So if you need to reset, do that.

https://lore.kernel.org/linux-iio/20250505200609.54756520@jic23-huawei/

Quoted 7 lines
Quoted 5 lines

The solution is to run it once at driver bind. Similar to reset below, if the usecase needs to re do it then unbinding and rebinding the driver reflects the fact we are taking it effectively offline for a while.

I also consider bind/unbind to be an official API to interact with devices, so i want to use them in the future with the WMI subsystem.

Why?

Quoted 5 lines

AFAIK the underlying reason for this series is that some drivers break when being bound to unsupported devices. However IMHO drivers should verify that they support a given device inside their .probe callback, and the associated bus should only match devices with drivers that explicitly claim support for those devices (ignoring driver_override).

No, drivers should NOT have to do that in their .probe() function, that's what we moved away from decades ago! The match function should handle all of that for you, otherwise it's contant duplication everywhere that is unneeded.

Please, learn from our history, don't make the same mistakes.

Now I might be convinced that driver_override is the way to go here, but it still feels really odd as again, bind/unbind was created as a driver debugging option only, it should NOT be a normal operation that any user should rely on. The driver should "just work" properly instead, without requiring manual bind work, as that's not a good model at all.

thanks,

greg k-h

#16 lore raw

Hello Greg,

Quoted 100 lines · Greg Kroah-Hartman
Quoted 49 lines · Armin Wolf

Am 22.09.26 um 15:40 schrieb David Lechner:

Quoted 47 lines · Uwe Kleine-König
Quoted 46 lines · Danilo Krummrich
Quoted 45 lines · Greg Kroah-Hartman
Quoted 29 lines

The ability to add and remove devices from a driver through the sysfs "bind" and "unbind" files was created all those decades ago as a way that kernel developers can iterate faster, and provide a debugging way for users to attempt to add a new device to a driver without having to rebuild their kernel.

This api over the years has been abused and recently come under a major fuzzing "attack" through tools like syzbot which decided that it would attempt to just randomly bind any driver to any type of device, causing loads of unneeded errors and pointless kernel patches to be generated by unsuspecting new developers.

Handle all of this by adding a new taint flag, TAINT_FORCED_BIND, which will be set on the driver if the bind/unbind sysfs files are ever written to. This lets kernel developers "know" that a user is attempting to do something that is not normal, and as such, if the kernel breaks they get to keep the shiny pieces laying around on the floor.

The flag is 'Y' which was unused, and can remembered as the user is "yeeting" the device being operated on here (thrown with force without regard for the thing being thrown).

Note, the taint flag gets set _BEFORE_ the bind/unbind callback happens, as many times crashes/oops/warnings/failures happen within the callback, and the taint flag needs to be there to show what was being attempted. If it were to be set after the callback happens, the oops report would not properly reflect what foolishness was being attempted.

Quoted 6 lines

Fuzzing tools like syzbot, that doesn't have hand-crafted rules to keep the tool from hitting bind/unbind, should be run with panic_on_taint enabled so that they fall over and don't continue on, thinking that they actually found a real issue.

Userspace operations that rely on the bind/unbind files

I agree that this should be avoided.

But I also think the biggest offender really is driver_override. Specifically, on a hot-pluggable bus a driver must be complient with the device driver lifecycle rules and hence shouldn't break on bind/unbind. I think it would be nice to not taint the kernel for such busses, and only taint on driver_override, as I think we'd still want the bug reports for such cases.

But I think this is fine to leave for a follow-up.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

I fully agree. I'm fine and support tainting on driver_override, but bind/unbind are used occasionally in my bubble and I consider drivers not handling that properly buggy.

I fully agree with this, drivers should correctly implement the lifecycle model and not just break when being unbound at a improper time. Drivers suffering from this can easily break this way when unloading the associated kernel module, so this taint is no solution.

It's a "solution" in that it tells the developer "hey, the user did something odd and unsupported". rmmod is also not a normal operation, there's no requirement that it actually work as it's usually a "best effort" type of thing.

Quoted 20 lines
Quoted 20 lines

In the IIO subsystem, unbind/rebind is the de-facto way to reset a wedged chip.

A few examples where other reset methods were reject in favor of unbind/bind:

https://lore.kernel.org/linux-iio/20240727160216.2488ed29@jic23-huawei/

This needs documenting as it's custom ABI. Note that we don't often accept custom ABI. Particularly not a hook that seems to reset the device. If you want to do that, unbind and rebind the whole drive[r] so we are in a known state etc.

https://lore.kernel.org/linux-iio/20240720163440.03c713dc@jic23-huawei/

Firstly as stated below, we don't provide interfaces for this because it's a heavy weight process that is most of the effort of unbinding and rebinding the driver. So if you need to reset, do that.

https://lore.kernel.org/linux-iio/20250505200609.54756520@jic23-huawei/

Quoted 7 lines
Quoted 5 lines

The solution is to run it once at driver bind. Similar to reset below, if the usecase needs to re do it then unbinding and rebinding the driver reflects the fact we are taking it effectively offline for a while.

I also consider bind/unbind to be an official API to interact with devices, so i want to use them in the future with the WMI subsystem.

Why?

Quoted 5 lines

AFAIK the underlying reason for this series is that some drivers break when being bound to unsupported devices. However IMHO drivers should verify that they support a given device inside their .probe callback, and the associated bus should only match devices with drivers that explicitly claim support for those devices (ignoring driver_override).

Quoted 4 lines

No, drivers should NOT have to do that in their .probe() function, that's what we moved away from decades ago! The match function should handle all of that for you, otherwise it's contant duplication everywhere that is unneeded.

Well then you have to accept that root can provoke a null pointer exception (e.g. by forcing the pwm-tegra driver on a device) because at least with today's platform bus match function such a match is ok.

Quoted 7 lines

Please, learn from our history, don't make the same mistakes.

Now I might be convinced that driver_override is the way to go here, but it still feels really odd as again, bind/unbind was created as a driver debugging option only, it should NOT be a normal operation that any user should rely on. The driver should "just work" properly instead, without requiring manual bind work, as that's not a good model at all.

I agree in principle, but (in my case wifi) drivers are buggy sometimes (due to missing documentation and/or engineering effort) and being able to rebind the driver instead of rebooting to get a working device again is very useful.

So yes, theoretically bind/unbind isn't needed, but theory and practise differ in practise.

OK, as a compromise: Let's keep the taint (after all that's not destroying any functionality, just adding a hint for bug reports), and make driver_override opt-in, which should close an attack surface (mostly for fuzzers?) and so reduce the amount of bug reports instead of marking a part of them as tainted only.

Best regards
Uwe

author maintainer
#17 lore raw
Quoted 8 lines · Uwe Kleine-König
Quoted 4 lines

No, drivers should NOT have to do that in their .probe() function, that's what we moved away from decades ago! The match function should handle all of that for you, otherwise it's contant duplication everywhere that is unneeded.

Well then you have to accept that root can provoke a null pointer exception (e.g. by forcing the pwm-tegra driver on a device) because at least with today's platform bus match function such a match is ok.

Agreed, yes, root can cause a crash and can do tons of horrible things much worse than this, that's not the issue.

That's why this taint is there, to make it obvious that this is not a "real" bug at all.

Quoted 8 lines
Quoted 7 lines

Please, learn from our history, don't make the same mistakes.

Now I might be convinced that driver_override is the way to go here, but it still feels really odd as again, bind/unbind was created as a driver debugging option only, it should NOT be a normal operation that any user should rely on. The driver should "just work" properly instead, without requiring manual bind work, as that's not a good model at all.

Quoted 4 lines

I agree in principle, but (in my case wifi) drivers are buggy sometimes (due to missing documentation and/or engineering effort) and being able to rebind the driver instead of rebooting to get a working device again is very useful.

Fine, use it! Just don't expect that to be "normal".

Quoted 2 lines

So yes, theoretically bind/unbind isn't needed, but theory and practise differ in practise.

Agreed, but again, don't rely on this as a "real" solution fo ranything.

Quoted 5 lines

OK, as a compromise: Let's keep the taint (after all that's not destroying any functionality, just adding a hint for bug reports), and make driver_override opt-in, which should close an attack surface (mostly for fuzzers?) and so reduce the amount of bug reports instead of marking a part of them as tainted only.

How is that going to change anything? Confused.

greg k-h

#18 lore raw
Quoted 29 lines · On Wed, 23 Sep 2026 12:29:56 +0200 Greg Kroah-Hartman…
Quoted 8 lines · Uwe Kleine-König
Quoted 4 lines

No, drivers should NOT have to do that in their .probe() function, that's what we moved away from decades ago! The match function should handle all of that for you, otherwise it's contant duplication everywhere that is unneeded.

Well then you have to accept that root can provoke a null pointer exception (e.g. by forcing the pwm-tegra driver on a device) because at least with today's platform bus match function such a match is ok.

Agreed, yes, root can cause a crash and can do tons of horrible things much worse than this, that's not the issue.

That's why this taint is there, to make it obvious that this is not a "real" bug at all.

Quoted 8 lines
Quoted 7 lines

Please, learn from our history, don't make the same mistakes.

Now I might be convinced that driver_override is the way to go here, but it still feels really odd as again, bind/unbind was created as a driver debugging option only, it should NOT be a normal operation that any user should rely on. The driver should "just work" properly instead, without requiring manual bind work, as that's not a good model at all.

Quoted 4 lines

I agree in principle, but (in my case wifi) drivers are buggy sometimes (due to missing documentation and/or engineering effort) and being able to rebind the driver instead of rebooting to get a working device again is very useful.

Quoted 6 lines

Fine, use it! Just don't expect that to be "normal".

Quoted 2 lines

So yes, theoretically bind/unbind isn't needed, but theory and practise differ in practise.

Agreed, but again, don't rely on this as a "real" solution fo ranything.

Sorry, late to the party, but this isn't a few user scripts that rely on this behavior. Effectively every use case of vfio relies on this behavior. We rely on unbinding the default driver from the device before using driver_override and drivers_probe. That means every hypervisor with device assignment and every userspace driver use case now experiences a tainted kernel. That seems like a significant regression.

There is currently no alternative for this process. It's not a matter of upgrading to a newer kernel where the drivers claim the device IDs. We can't claim the device ID, vfio drivers represent a secondary use case for the device.

A production use case of panic_on_taint now results in a hard failure for a scenario that has been allowed and documented as best practice for many years.

What's the solution we can pursue for the scenario where devices have dual use cases between in-kernel drivers and userspace drivers? Thanks,

Alex

author maintainer
#19 lore raw
Quoted 39 lines · Alex Williamson
Quoted 29 lines · On Wed, 23 Sep 2026 12:29:56 +0200 Greg Kroah-Hartman…
Quoted 8 lines · Uwe Kleine-König
Quoted 4 lines

No, drivers should NOT have to do that in their .probe() function, that's what we moved away from decades ago! The match function should handle all of that for you, otherwise it's contant duplication everywhere that is unneeded.

Well then you have to accept that root can provoke a null pointer exception (e.g. by forcing the pwm-tegra driver on a device) because at least with today's platform bus match function such a match is ok.

Agreed, yes, root can cause a crash and can do tons of horrible things much worse than this, that's not the issue.

That's why this taint is there, to make it obvious that this is not a "real" bug at all.

Quoted 8 lines
Quoted 7 lines

Please, learn from our history, don't make the same mistakes.

Now I might be convinced that driver_override is the way to go here, but it still feels really odd as again, bind/unbind was created as a driver debugging option only, it should NOT be a normal operation that any user should rely on. The driver should "just work" properly instead, without requiring manual bind work, as that's not a good model at all.

Quoted 4 lines

I agree in principle, but (in my case wifi) drivers are buggy sometimes (due to missing documentation and/or engineering effort) and being able to rebind the driver instead of rebooting to get a working device again is very useful.

Quoted 6 lines

Fine, use it! Just don't expect that to be "normal".

Quoted 2 lines

So yes, theoretically bind/unbind isn't needed, but theory and practise differ in practise.

Agreed, but again, don't rely on this as a "real" solution fo ranything.

Quoted 7 lines

Sorry, late to the party, but this isn't a few user scripts that rely on this behavior. Effectively every use case of vfio relies on this behavior. We rely on unbinding the default driver from the device before using driver_override and drivers_probe. That means every hypervisor with device assignment and every userspace driver use case now experiences a tainted kernel. That seems like a significant regression.

Or finally, a real bugfix :)

Quoted 4 lines

There is currently no alternative for this process. It's not a matter of upgrading to a newer kernel where the drivers claim the device IDs. We can't claim the device ID, vfio drivers represent a secondary use case for the device.

How can vfio know that it can properly talk to any device like this? Surely you have a list of real device ids that you know will work, otherwise all bets are off.

Quoted 3 lines

A production use case of panic_on_taint now results in a hard failure for a scenario that has been allowed and documented as best practice for many years.

It was never "best practice", you took a debugging option and somehow thought it was a valid use case. Yes, I'm being harsh but I am sure I complained about this in the past and obviously never followed up on it, so that's on me.

Quoted 2 lines

What's the solution we can pursue for the scenario where devices have dual use cases between in-kernel drivers and userspace drivers? Thanks,

So what is the real use case here, taking any type of any device and thinking you can bind a random kernel driver to it and it will work ok? You all have specific platform and pci vfio drivers, why not use the proper device ids there instead, or better yet, bake-in this type of functionality into the bus-specific logic so that you can have generic userspace control of a device (like usbfs and uio does today)?

We have real problems with random "bind/unbind" attempts that this taint is here to help resolve as it was creating hundreds of false-positive bug reports on developers all across the tree now that the fuzzers decided to think this was a valid action to take. Without this taint, people were being forced to add hacks to all drivers for this which is not an acceptable solution.

thanks,

greg k-h

#20 lore raw

Hello Greg,

Quoted 6 lines · Greg Kroah-Hartman

We have real problems with random "bind/unbind" attempts that this taint is here to help resolve as it was creating hundreds of false-positive bug reports on developers all across the tree now that the fuzzers decided to think this was a valid action to take. Without this taint, people were being forced to add hacks to all drivers for this which is not an acceptable solution.

Why is it false positive? IMHO unless it involves a driver_override it is a bug to fix. So have you considered tainting on driver_override instead of bind/unbind? You did, I'm sure because several peoplel voiced that approach already, but unless I missed something, you didn't share your thoughts about it yet.

https://lore.kernel.org/all/[email protected]/
would be a suitable thread to share your opinion.

Best regards
Uwe

maintainer
#21 lore raw
Quoted 2 lines · Uwe Kleine-König

Why is it false positive? IMHO unless it involves a driver_override it is a bug to fix.

In an earlier reply I mentioned that we can leave it as a follow-up to limit this to buses that do not support hotplug (will send a series soon), as we have quite some drivers - for devices on buses where it is not expected that they ever go away - where those drivers don't implement a proper teardown sequence; for buses that support hotplug we should only taint on driver_override.

One can argue that they should be fixed then, and I would certainly love to have all drivers to properly implement the full driver lifecycle, but it would also mean to write a bunch of code that in practice is just dead code.

bind/unbind sysfs attributes (as well as module unload) can break such drivers, which, under the premise that those drivers don't have to write this "dead code" in the first place, is a false positive.

But again, I'd still always recommend to properly implement the driver lifecycle for new drivers for various reasons (portability to other buses, general driver design, etc.), and I'd love to see existing drivers be "fixed", but I don't see how it is reasonable to expect this to happen.

(Luckily, in Rust that's at least partially never going to be an issue, as the core APIs can fully enforce a proper driver lifecycle statically without drivers having to write extra code for it. It obviously can't enfoce to leave the device in a defined state though.)

#22 lore raw
In reply to Greg Kroah-Hartman
Quoted 50 lines · On Sat, 24 Oct 2026 06:56:34 +0200 Greg Kroah-Hartman…
Quoted 39 lines · Alex Williamson
Quoted 29 lines · On Wed, 23 Sep 2026 12:29:56 +0200 Greg Kroah-Hartman…
Quoted 8 lines · Uwe Kleine-König
Quoted 4 lines

No, drivers should NOT have to do that in their .probe() function, that's what we moved away from decades ago! The match function should handle all of that for you, otherwise it's contant duplication everywhere that is unneeded.

Well then you have to accept that root can provoke a null pointer exception (e.g. by forcing the pwm-tegra driver on a device) because at least with today's platform bus match function such a match is ok.

Agreed, yes, root can cause a crash and can do tons of horrible things much worse than this, that's not the issue.

That's why this taint is there, to make it obvious that this is not a "real" bug at all.

Quoted 8 lines
Quoted 7 lines

Please, learn from our history, don't make the same mistakes.

Now I might be convinced that driver_override is the way to go here, but it still feels really odd as again, bind/unbind was created as a driver debugging option only, it should NOT be a normal operation that any user should rely on. The driver should "just work" properly instead, without requiring manual bind work, as that's not a good model at all.

Quoted 4 lines

I agree in principle, but (in my case wifi) drivers are buggy sometimes (due to missing documentation and/or engineering effort) and being able to rebind the driver instead of rebooting to get a working device again is very useful.

Quoted 6 lines

Fine, use it! Just don't expect that to be "normal".

Quoted 2 lines

So yes, theoretically bind/unbind isn't needed, but theory and practise differ in practise.

Agreed, but again, don't rely on this as a "real" solution fo ranything.

Quoted 7 lines

Sorry, late to the party, but this isn't a few user scripts that rely on this behavior. Effectively every use case of vfio relies on this behavior. We rely on unbinding the default driver from the device before using driver_override and drivers_probe. That means every hypervisor with device assignment and every userspace driver use case now experiences a tainted kernel. That seems like a significant regression.

Or finally, a real bugfix :)

Quoted 8 lines
Quoted 4 lines

There is currently no alternative for this process. It's not a matter of upgrading to a newer kernel where the drivers claim the device IDs. We can't claim the device ID, vfio drivers represent a secondary use case for the device.

How can vfio know that it can properly talk to any device like this? Surely you have a list of real device ids that you know will work, otherwise all bets are off.

There's not a list of real device IDs. PCI, in particular, is a self-describing bus. Devices are discovered via bus walk, their resources are probed via standard mechanisms, they support interrupts and resets as described by capabilities defined in a specification. The vfio-pci driver just provides a generic way to represent a device as resources mapped to file offsets with ioctls to discover those offsets and interact with things like resets and interrupts. For example, PCI config space and BAR regions are just defined indexes into the table of file offsets. This works with any endpoint device, where even that distinction is based on the discoverable PCI header type rather than a table of device IDs.

Even if we could come up with a set of device IDs, it's a policy decision whether a given device is intended by the admin to be used by the default in-kernel driver or a userspace driver. This policy changes over time, within the same host session. That means that at one point we want the default driver bound and at another we want a vfio driver bound. Coordinating this is exactly why we have driver_override and, building on that, match IDs that require driver_override. This allows drivers to describe themselves as vfio-pci compatible drivers via modules.alias while requiring userspace to enable the match via driver_override.

This is how vfio-pci variant drivers work. These drivers contain device specific knowledge, for instance the ability to serialize and expose device state for migration, but they're still a secondary use case to the in-kernel drivers. This is effort and coordination with subsystems and driver-core over many years and relied on by every hypervisor, now deemed unsupported through a kernel taint before we can even bind the driver.

Quoted 8 lines
Quoted 3 lines

A production use case of panic_on_taint now results in a hard failure for a scenario that has been allowed and documented as best practice for many years.

It was never "best practice", you took a debugging option and somehow thought it was a valid use case. Yes, I'm being harsh but I am sure I complained about this in the past and obviously never followed up on it, so that's on me.

I won't doubt that you know more about the history and intent of these interfaces than nearly anyone, but I don't find any documentation or comments that specifically declare these as debug interfaces. In fact, Documentation/ABI/testing/sysfs-bus-pci has documented the bind and unbind ABI for over 20 years.

You've certainly expressed more than once that users get to keep all the broken pieces if they bind devices to drivers that don't support the hardware. This is the first that it's been formalized in a taint without warning or an escape hatch for drivers like vfio-pci that do in fact intend to work with all hardware. It affects the industries that depend on this usage model. It's a regression.

Quoted 10 lines
Quoted 2 lines

What's the solution we can pursue for the scenario where devices have dual use cases between in-kernel drivers and userspace drivers? Thanks,

So what is the real use case here, taking any type of any device and thinking you can bind a random kernel driver to it and it will work ok? You all have specific platform and pci vfio drivers, why not use the proper device ids there instead, or better yet, bake-in this type of functionality into the bus-specific logic so that you can have generic userspace control of a device (like usbfs and uio does today)?

Quoted 6 lines

We have real problems with random "bind/unbind" attempts that this taint is here to help resolve as it was creating hundreds of false-positive bug reports on developers all across the tree now that the fuzzers decided to think this was a valid action to take. Without this taint, people were being forced to add hacks to all drivers for this which is not an acceptable solution.

At its core, vfio is describing the fundamental aspects of a device, regions and interrupts, without purporting to know anything about the specific programming model of the hardware. In the case of PCI, the vfio-pci driver effectively decomposes the PCI representation of the device into a set of ioctls and a file descriptor. A userspace driver, for example QEMU, recomposes that representation back into a virtual PCI device to the VM with virtualization, emulation, and direct access wired through to the physical device.

There are no devices deemed only for vfio use by default. Often we're unbinding a device from the host, exporting it to a userspace driver through vfio, exposing it to a VM, only to bind the same driver to it in the guest that it was previously using in the host. Binding to a vfio driver is always a secondary use case governed by the policy of the system. We cannot create scenarios where there are competing drivers for a device. The vfio driver is always brought into the picture via driver_override, and except in the rare case where no host driver exists, unbind must be used to release the device for drivers_probe.

Is there some way instead that we can resolve the string written to driver_override and only taint for non-vfio drivers? It's a much more confined problem if vfio drivers filter hardware outside their scope of support in their .probe function, and I think we largely do that already. Thanks,

Alex

author maintainer
#23 lore raw
Quoted 58 lines · Alex Williamson
Quoted 55 lines · On Sat, 24 Oct 2026 06:56:34 +0200 Greg Kroah-Hartman…
Quoted 39 lines · Alex Williamson
Quoted 29 lines · On Wed, 23 Sep 2026 12:29:56 +0200 Greg Kroah-Hartman…
Quoted 8 lines · Uwe Kleine-König
Quoted 4 lines

No, drivers should NOT have to do that in their .probe() function, that's what we moved away from decades ago! The match function should handle all of that for you, otherwise it's contant duplication everywhere that is unneeded.

Well then you have to accept that root can provoke a null pointer exception (e.g. by forcing the pwm-tegra driver on a device) because at least with today's platform bus match function such a match is ok.

Agreed, yes, root can cause a crash and can do tons of horrible things much worse than this, that's not the issue.

That's why this taint is there, to make it obvious that this is not a "real" bug at all.

Quoted 8 lines
Quoted 7 lines

Please, learn from our history, don't make the same mistakes.

Now I might be convinced that driver_override is the way to go here, but it still feels really odd as again, bind/unbind was created as a driver debugging option only, it should NOT be a normal operation that any user should rely on. The driver should "just work" properly instead, without requiring manual bind work, as that's not a good model at all.

Quoted 4 lines

I agree in principle, but (in my case wifi) drivers are buggy sometimes (due to missing documentation and/or engineering effort) and being able to rebind the driver instead of rebooting to get a working device again is very useful.

Quoted 6 lines

Fine, use it! Just don't expect that to be "normal".

Quoted 2 lines

So yes, theoretically bind/unbind isn't needed, but theory and practise differ in practise.

Agreed, but again, don't rely on this as a "real" solution fo ranything.

Quoted 7 lines

Sorry, late to the party, but this isn't a few user scripts that rely on this behavior. Effectively every use case of vfio relies on this behavior. We rely on unbinding the default driver from the device before using driver_override and drivers_probe. That means every hypervisor with device assignment and every userspace driver use case now experiences a tainted kernel. That seems like a significant regression.

Or finally, a real bugfix :)

Quoted 4 lines

There is currently no alternative for this process. It's not a matter of upgrading to a newer kernel where the drivers claim the device IDs. We can't claim the device ID, vfio drivers represent a secondary use case for the device.

Quoted 8 lines
Quoted 3 lines

How can vfio know that it can properly talk to any device like this? Surely you have a list of real device ids that you know will work, otherwise all bets are off.

There's not a list of real device IDs. PCI, in particular, is a self-describing bus. Devices are discovered via bus walk, their resources are probed via standard mechanisms, they support interrupts and resets as described by capabilities defined in a specification.

I know how PCI works, I used to be the PCI maintainer all those years ago :)

Quoted 3 lines

The vfio-pci driver just provides a generic way to represent a device as resources mapped to file offsets with ioctls to discover those offsets and interact with things like resets and interrupts.

Great, then just have that driver attach to the specific device you want by having it contain the device ids for what it wants to control. Or have it say it wants to control all devices and be "last" on the list to bind.

Quoted 5 lines

For
example, PCI config space and BAR regions are just defined indexes into the table of file offsets. This works with any endpoint device, where even that distinction is based on the discoverable PCI header type rather than a table of device IDs.

I don't understand what you are trying to say here, sorry. Yes I know how PCI config space works, again, I was the maintainer and still have access to the PCI sig through various means.

Quoted 3 lines

Even if we could come up with a set of device IDs, it's a policy decision whether a given device is intended by the admin to be used by the default in-kernel driver or a userspace driver.

Great, then have the admin never allow the in-kernel driver to be on the system, or be loaded (modprobe has deny lists) and all is fine.

Quoted 1 line

This policy changes over time, within the same host session.

what are you defining as a "session" here?

Quoted 6 lines

That means that at one point we want the default driver bound and at another we want a vfio driver bound. Coordinating this is exactly why we have driver_override and, building on that, match IDs that require driver_override. This allows drivers to describe themselves as vfio-pci compatible drivers via modules.alias while requiring userspace to enable the match via driver_override.

And as said before, that's a horrid hack and one that is breaking things today in all sorts of ways, which is why the taint was added.

If you wish to override the kernel, then great, a taint flag is added and all is fine. All this means is that now developers know what you did and can decide to ignore your bug report or not. No functionality changed at all.

Quoted 15 lines
Quoted 8 lines
Quoted 3 lines

A production use case of panic_on_taint now results in a hard failure for a scenario that has been allowed and documented as best practice for many years.

It was never "best practice", you took a debugging option and somehow thought it was a valid use case. Yes, I'm being harsh but I am sure I complained about this in the past and obviously never followed up on it, so that's on me.

I won't doubt that you know more about the history and intent of these interfaces than nearly anyone, but I don't find any documentation or comments that specifically declare these as debug interfaces. In fact, Documentation/ABI/testing/sysfs-bus-pci has documented the bind and unbind ABI for over 20 years.

Quoted 6 lines

You've certainly expressed more than once that users get to keep all the broken pieces if they bind devices to drivers that don't support the hardware. This is the first that it's been formalized in a taint without warning or an escape hatch for drivers like vfio-pci that do in fact intend to work with all hardware. It affects the industries that depend on this usage model. It's a regression.

No functionality changed, just an informational flag is now in the system when this happens. The systems still obviously work just fine, otherwise all testing so far of linux-next would have caught this, right?

Quoted 5 lines

Is there some way instead that we can resolve the string written to driver_override and only taint for non-vfio drivers? It's a much more confined problem if vfio drivers filter hardware outside their scope of support in their .probe function, and I think we largely do that already. Thanks,

Why are you worried about a taint flag? So many servers run with taint flags enabled due to out-of-tree or questionable licenses with no problems, what's one more informational bit here?

thanks,

greg k-h

#24 lore raw
Quoted 6 lines · Greg Kroah-Hartman
Quoted 3 lines

Even if we could come up with a set of device IDs, it's a policy decision whether a given device is intended by the admin to be used by the default in-kernel driver or a userspace driver.

Great, then have the admin never allow the in-kernel driver to be on the system, or be loaded (modprobe has deny lists) and all is fine.

As some maintainers like to say, it's not the '90s anymore :)

Users don't reboot systems to kick a kernel driver off a PCI device to try something in a disposable VM on a whim.

Even if they did, it's completely normal for desktop users to have two GPUs from the same vendor or two xHCI controllers and pass only one of them to Windows/macOS while using the other on the host.

bind/unbind feature prominently on every distribution wiki and forum, this cat is absolutely out of the bag at this point.

Quoted 9 lines
Quoted 6 lines

That means that at one point we want the default driver bound and at another we want a vfio driver bound. Coordinating this is exactly why we have driver_override and, building on that, match IDs that require driver_override. This allows drivers to describe themselves as vfio-pci compatible drivers via modules.alias while requiring userspace to enable the match via driver_override.

And as said before, that's a horrid hack and one that is breaking things today in all sorts of ways, which is why the taint was added.

Are you aware of bind/unbind breaking things for PCI specifically?

Without also involving 'driver_override' or 'new_id'? Everyone agrees that these APIs used for anything other than pci-stub or vfio are foot guns. But your patch targets something different.

We can even bind PCI drivers to wrong devices *without* using bind and hence, I presume but don't care to test, without tripping this taint.

Quoted 4 lines

If you wish to override the kernel, then great, a taint flag is added and all is fine. All this means is that now developers know what you did and can decide to ignore your bug report or not. No functionality changed at all.

I believe people pointed out that it's a functional change for users of panic_on_taint who also use bind without being idiots.

Does this taint even solve a "real" problem? Those bug reports weren't coming from users, they were coming from "abusers" like syzbot looking for trouble. They were quite obvious even without a taint message.

And at least on linux-usb, they seem to have stopped after Google and one other copycat were told to stop sending them, and before this taint reaches released kernels.

I even told them to block not only bind but also new_id, so there will be no second wave of reports caused by syzbot discovering that it can bypass the taint by using new_id intsead of driver_override.

Quoted 3 lines

Why are you worried about a taint flag? So many servers run with taint flags enabled due to out-of-tree or questionable licenses with no problems, what's one more informational bit here?

And what's the point of a flag which is always set on countless normal systems in the wild? If this feature survives to April 1st, I will send a patch to rename it to "VM passthrough taint" because everybody (or at least those dealing with desktop users) knows what it *really* means.

Regards,
Michal

author maintainer
#25 lore raw
Quoted 4 lines · Michal Pecio
Quoted 2 lines

And as said before, that's a horrid hack and one that is breaking things today in all sorts of ways, which is why the taint was added.

Are you aware of bind/unbind breaking things for PCI specifically?

Yes, we had reports of this happening for many PCI drivers where unbind would be triggered and a random pci device would then be "bound" to the driver and the kernel would crash. See the zillion syzbot reports of a few months ago, which caused all of this to happen.

Quoted 3 lines

Without also involving 'driver_override' or 'new_id'? Everyone agrees that these APIs used for anything other than pci-stub or vfio are foot guns. But your patch targets something different.

Yes, driver_override and/or new_id was being used for most of these, BUT unbind for other busses was also causing problems (specifically many platform drivers.)

Quoted 8 lines

We can even bind PCI drivers to wrong devices *without* using bind and hence, I presume but don't care to test, without tripping this taint.

Quoted 4 lines

If you wish to override the kernel, then great, a taint flag is added and all is fine. All this means is that now developers know what you did and can decide to ignore your bug report or not. No functionality changed at all.

Quoted 6 lines

I believe people pointed out that it's a functional change for users of panic_on_taint who also use bind without being idiots.

Does this taint even solve a "real" problem? Those bug reports weren't coming from users, they were coming from "abusers" like syzbot looking for trouble. They were quite obvious even without a taint message.

They were not obvious at all, see the patches that many maintainers "accidentally" took to fix a bug that really wasn't a bug at all. This was forcing additional code into all drivers for no good reason, hence the taint flag.

Let me reconsider this and think about just doing it for the additional id and allowing busses to trip it when their unbind is hit for busses that should not be normally handling unbind (i.e. platform devices.)

thanks,

greg k-h

#26 lore raw
In reply to Greg Kroah-Hartman

Hello,

Quoted 6 lines · Greg Kroah-Hartman

So what is the real use case here, taking any type of any device and thinking you can bind a random kernel driver to it and it will work ok? You all have specific platform and pci vfio drivers, why not use the proper device ids there instead, or better yet, bake-in this type of functionality into the bus-specific logic so that you can have generic userspace control of a device (like usbfs and uio does today)?

Also note that even if the platform and pci busses implement bus-specific code to pass a given device to userspace and/or a VM, you need proper unbind support in the driver currently managing the device (or cripple the mechanism to only work for devices that were not bound to a host driver before).

The more I think about this taint, the more I believe the commit should be reverted and replaced by a some stop gaps for driver_override. (Be it a taint or better yet
https://lore.kernel.org/all/0f7446324f6a0c8f0153d6532d92a6eeecd6a308.1790612298.git.u.kleine-koenig@baylibre.com/
.)

Best regards
Uwe

#27 lore raw
Quoted 5 lines · Uwe Kleine-König

The more I think about this taint, the more I believe the commit should be reverted and replaced by a some stop gaps for driver_override. (Be it a taint or better yet
https://lore.kernel.org/all/0f7446324f6a0c8f0153d6532d92a6eeecd6a308.1790612298.git.u.kleine-koenig@baylibre.com/
.)

I also think this patch is way too broad and should be reverted until something better is designed.

To me this is very similar to the filesystem issue with syzkaller fuzzing the block device and crashing filesystems. They said filesystems touching untrusted block devices is out of scope.

Same here, kernel drivers touching untrusted HW are out of scope, we have never supported that.

I think a taint from force binding outside a match entry and using new_id are probably about as far as this idea should go.

Even this would still regress most common VFIO instructions though, so some kind of disable for VFIO would be needed. I don't agree with the assertion 'servers are already always tainted' that doesn't match my experience at all.

unbind should not taint, we support hotplug, and manually binding an authentic match'd driver should not taint.

Jason

author maintainer
#28 lore raw
Quoted 10 lines · Jason Gunthorpe
Quoted 5 lines · Uwe Kleine-König

The more I think about this taint, the more I believe the commit should be reverted and replaced by a some stop gaps for driver_override. (Be it a taint or better yet
https://lore.kernel.org/all/0f7446324f6a0c8f0153d6532d92a6eeecd6a308.1790612298.git.u.kleine-koenig@baylibre.com/
.)

I also think this patch is way too broad and should be reverted until something better is designed.

Fair enough, I've sent a revert for now, will get it merged before -rc1 is out. I'll rework this for a later release, thanks.

greg k-h

#29 lore raw
Quoted 9 lines · Greg Kroah-Hartman
Quoted 8 lines · Jason Gunthorpe
Quoted 5 lines · Uwe Kleine-König

The more I think about this taint, the more I believe the commit should be reverted and replaced by a some stop gaps for driver_override. (Be it a taint or better yet
https://lore.kernel.org/all/0f7446324f6a0c8f0153d6532d92a6eeecd6a308.1790612298.git.u.kleine-koenig@baylibre.com/
.)

Quoted 5 lines
Quoted 2 lines

I also think this patch is way too broad and should be reverted until something better is designed.

Fair enough, I've sent a revert for now, will get it merged before -rc1 is out.

\o/, thanks

Quoted 1 line

I'll rework this for a later release, thanks.

Please look at the series behind the link above before investing time here. I think most of the ideas are already implemented there. If you voice your preferences there, I can rework accordingly and rebase on top of your revert.

Best regards
Uwe

author maintainer
#30 lore raw
Quoted 16 lines · Uwe Kleine-König
Quoted 9 lines · Greg Kroah-Hartman
Quoted 8 lines · Jason Gunthorpe
Quoted 5 lines · Uwe Kleine-König

The more I think about this taint, the more I believe the commit should be reverted and replaced by a some stop gaps for driver_override. (Be it a taint or better yet
https://lore.kernel.org/all/0f7446324f6a0c8f0153d6532d92a6eeecd6a308.1790612298.git.u.kleine-koenig@baylibre.com/
.)

Quoted 5 lines
Quoted 2 lines

I also think this patch is way too broad and should be reverted until something better is designed.

Fair enough, I've sent a revert for now, will get it merged before -rc1 is out.

Quoted 8 lines

\o/, thanks

Quoted 1 line

I'll rework this for a later release, thanks.

Please look at the series behind the link above before investing time here. I think most of the ideas are already implemented there. If you voice your preferences there, I can rework accordingly and rebase on top of your revert.

How about rebasing now and submitting it and I can look at it that way? That would be easier for me at least given my current workload...

thanks,

greg k-h

#31 lore raw
In reply to Uwe Kleine-König
Quoted 16 lines · On Wed, 28 Oct 2026 15:50:44 +0100 Uwe Kleine-König…
Quoted 9 lines · Greg Kroah-Hartman
Quoted 8 lines · Jason Gunthorpe
Quoted 5 lines · Uwe Kleine-König

The more I think about this taint, the more I believe the commit should be reverted and replaced by a some stop gaps for driver_override. (Be it a taint or better yet
https://lore.kernel.org/all/0f7446324f6a0c8f0153d6532d92a6eeecd6a308.1790612298.git.u.kleine-koenig@baylibre.com/
.)

Quoted 5 lines
Quoted 2 lines

I also think this patch is way too broad and should be reverted until something better is designed.

Fair enough, I've sent a revert for now, will get it merged before -rc1 is out.

Quoted 8 lines

\o/, thanks

Quoted 1 line

I'll rework this for a later release, thanks.

Please look at the series behind the link above before investing time here. I think most of the ideas are already implemented there. If you voice your preferences there, I can rework accordingly and rebase on top of your revert.

From a vfio perspective, the concern with the linked series is that driver_override always taints. That's the same regression we have here; vfio use cases rely on driver_override. Introducing a driver flag that allows a driver to opt-in to declare support for driver_override, but then taints if it actually generates a match is contradictory.

I had been working on a series that allowed match to return a match type classification, for example 1 as a static match (for compatibility), 2 for a dynamic match, and 3 for a driver_override match. Anything other than a static match that reaches driver probe generates a taint. Also note that generating a match doesn't necessarily result in a driver probe callback, in at least one flow we haven't even tested that the device isn't already bound to a driver.

The bus level match function can filter and downgrade the classification, for example PCI has an override_only flag in its match ID. vfio-pci and variant drivers thereof make use of this to avoid becoming the default driver for devices. A driver_override that matches the override_only match ID in the driver table can be demoted to a static match and avoid tainting.

I'm not sure I understand the rationale for focusing only on driver_override though, new_id has just as much ability to generate bogus driver matches. It's also racy to use new_id if you're trying to get a specific device bound to a driver, which is why driver_override was invented. So we end up placing barriers to the use of the interface that we've now long recommended as the better alternative to new_id, while leaving the gaps in new_id wide open. Thanks,

Alex

#32 lore raw
In reply to Alex Williamson
Quoted 39 lines · Alex Williamson
Quoted 29 lines · On Wed, 23 Sep 2026 12:29:56 +0200 Greg Kroah-Hartman…
Quoted 8 lines · Uwe Kleine-König
Quoted 4 lines

No, drivers should NOT have to do that in their .probe() function, that's what we moved away from decades ago! The match function should handle all of that for you, otherwise it's contant duplication everywhere that is unneeded.

Well then you have to accept that root can provoke a null pointer exception (e.g. by forcing the pwm-tegra driver on a device) because at least with today's platform bus match function such a match is ok.

Agreed, yes, root can cause a crash and can do tons of horrible things much worse than this, that's not the issue.

That's why this taint is there, to make it obvious that this is not a "real" bug at all.

Quoted 8 lines
Quoted 7 lines

Please, learn from our history, don't make the same mistakes.

Now I might be convinced that driver_override is the way to go here, but it still feels really odd as again, bind/unbind was created as a driver debugging option only, it should NOT be a normal operation that any user should rely on. The driver should "just work" properly instead, without requiring manual bind work, as that's not a good model at all.

Quoted 4 lines

I agree in principle, but (in my case wifi) drivers are buggy sometimes (due to missing documentation and/or engineering effort) and being able to rebind the driver instead of rebooting to get a working device again is very useful.

Quoted 6 lines

Fine, use it! Just don't expect that to be "normal".

Quoted 2 lines

So yes, theoretically bind/unbind isn't needed, but theory and practise differ in practise.

Agreed, but again, don't rely on this as a "real" solution fo ranything.

Quoted 7 lines

Sorry, late to the party, but this isn't a few user scripts that rely on this behavior. Effectively every use case of vfio relies on this behavior. We rely on unbinding the default driver from the device before using driver_override and drivers_probe. That means every hypervisor with device assignment and every userspace driver use case now experiences a tainted kernel. That seems like a significant regression.

Sorry, I was on vacation and missed this change earlier. This change will affect SR-IOV deployments around the world, which *rely* on being able to bind a driver manually *after* virtual functions are created but before they are used.

This is needed for two reasons: to save hardware and software resources when creating a large number of VFs, and to allow the PCI config space to be configured *before* the driver starts using it.

There is no in-kernel alternative.

Thanks

#33 lore raw
Quoted 5 lines · Leon Romanovsky

This is needed for two reasons: to save hardware and software resources when creating a large number of VFs, and to allow the PCI config space to be configured *before* the driver starts using it.

There is no in-kernel alternative.

Having userspace involved in driver binding has also always been the plan for confidential computing needs. We cannot have a device driver bound across some of the HW transitions like TDISP shared/private, so there has always been an expectation of bind/unbind.

For this case the existing sysf drivers_probe is good enough for bind, but we must have taint-free unbind for PCI devices too.

I think this patch should be reverted ASAP, it is a pretty major regression for a lot of users.

Jason

author maintainer
#34 lore raw
Quoted 6 lines · Jason Gunthorpe
Quoted 4 lines · Leon Romanovsky

This is needed for two reasons: to save hardware and software resources when creating a large number of VFs, and to allow the PCI config space to be configured *before* the driver starts using it.

Quoted 6 lines
Quoted 1 line

There is no in-kernel alternative.

Having userspace involved in driver binding has also always been the plan for confidential computing needs. We cannot have a device driver bound across some of the HW transitions like TDISP shared/private, so there has always been an expectation of bind/unbind.

What, why? What forces that decision? What's wrong with the proper driver for the hardware being bound automatically to the device?

Quoted 2 lines

For this case the existing sysf drivers_probe is good enough for bind, but we must have taint-free unbind for PCI devices too.

Why?

Quoted 2 lines

I think this patch should be reverted ASAP, it is a pretty major regression for a lot of users.

But this use case hasn't even happened yet, so what would regress?

I'm not talking about the vfio thing, that's different here...

thanks,

greg k-h

#35 lore raw
Quoted 9 lines · Greg Kroah-Hartman
Quoted 8 lines · Jason Gunthorpe
Quoted 5 lines · Leon Romanovsky

This is needed for two reasons: to save hardware and software resources when creating a large number of VFs, and to allow the PCI config space to be configured *before* the driver starts using it.

There is no in-kernel alternative.

Quoted 7 lines
Quoted 4 lines

Having userspace involved in driver binding has also always been the plan for confidential computing needs. We cannot have a device driver bound across some of the HW transitions like TDISP shared/private, so there has always been an expectation of bind/unbind.

What, why? What forces that decision? What's wrong with the proper driver for the hardware being bound automatically to the device?

It would be a proper driver, with a real match. I would expect this to be done with sysfs driver_probe, which is like bind, except it doesn't override the matches, AFAIK.

There are two sort of related isues. Userspace is in charge of sequencing the new PCI features like link encryption and TDISP. They have complex authentication policies tied to them so the kernel can't reasonably do it. These features change how the CPU does address translation, effectively it adds/removes the iommu - and that can't be changed while the DMA API is active or it breaks every translation in effect.

So.. We need a gap a system boot when the driver is not bound so the PCI stuff can be done prior to driver_probe, and a gap if there is a PCIe error of some kind to do error recovery and go back to the start to reauthenticate and reload.

Quoted 4 lines
Quoted 2 lines

For this case the existing sysf drivers_probe is good enough for bind, but we must have taint-free unbind for PCI devices too.

Why?

See above. That should be the easiest thing to ask for! PCI is hot plug, disabling unbind makes zero sense from any way you look at it.

Quoted 4 lines
Quoted 2 lines

I think this patch should be reverted ASAP, it is a pretty major regression for a lot of users.

But this use case hasn't even happened yet, so what would regress?

I'm reflecting the other commentators, I care about VFIO too. I think tainting every hypervisor is unacceptable.

But for CC I find myself one of the maintainers for that now and many people have been diligently working on this bind/unbind direction for a long time now. If it goes away I have no idea what could replace it.

Jason

author maintainer
#36 lore raw
In reply to Leon Romanovsky
Quoted 48 lines · Leon Romanovsky
Quoted 39 lines · Alex Williamson
Quoted 29 lines · On Wed, 23 Sep 2026 12:29:56 +0200 Greg Kroah-Hartman…
Quoted 8 lines · Uwe Kleine-König
Quoted 4 lines

No, drivers should NOT have to do that in their .probe() function, that's what we moved away from decades ago! The match function should handle all of that for you, otherwise it's contant duplication everywhere that is unneeded.

Well then you have to accept that root can provoke a null pointer exception (e.g. by forcing the pwm-tegra driver on a device) because at least with today's platform bus match function such a match is ok.

Agreed, yes, root can cause a crash and can do tons of horrible things much worse than this, that's not the issue.

That's why this taint is there, to make it obvious that this is not a "real" bug at all.

Quoted 8 lines
Quoted 7 lines

Please, learn from our history, don't make the same mistakes.

Now I might be convinced that driver_override is the way to go here, but it still feels really odd as again, bind/unbind was created as a driver debugging option only, it should NOT be a normal operation that any user should rely on. The driver should "just work" properly instead, without requiring manual bind work, as that's not a good model at all.

Quoted 4 lines

I agree in principle, but (in my case wifi) drivers are buggy sometimes (due to missing documentation and/or engineering effort) and being able to rebind the driver instead of rebooting to get a working device again is very useful.

Quoted 6 lines

Fine, use it! Just don't expect that to be "normal".

Quoted 2 lines

So yes, theoretically bind/unbind isn't needed, but theory and practise differ in practise.

Agreed, but again, don't rely on this as a "real" solution fo ranything.

Quoted 7 lines

Sorry, late to the party, but this isn't a few user scripts that rely on this behavior. Effectively every use case of vfio relies on this behavior. We rely on unbinding the default driver from the device before using driver_override and drivers_probe. That means every hypervisor with device assignment and every userspace driver use case now experiences a tainted kernel. That seems like a significant regression.

Quoted 4 lines

Sorry, I was on vacation and missed this change earlier. This change will affect SR-IOV deployments around the world, which *rely* on being able to bind a driver manually *after* virtual functions are created but before they are used.

Why can't a real driver bind to those virtual functions? Like is happening in the rust apis?

Quoted 3 lines

This is needed for two reasons: to save hardware and software resources when creating a large number of VFs, and to allow the PCI config space to be configured *before* the driver starts using it.

How is hardware and software resources an issue here at all? And you can write to PCI config space from userspace today, no driver needed anywhere at all, that's always been allowed.

Quoted 1 line

There is no in-kernel alternative.

Then just don't have a in-kernel driver for the device and all is good?

thanks,

greg k-h

#37 lore raw
Quoted 8 lines · Greg Kroah-Hartman
Quoted 8 lines
Quoted 7 lines

Sorry, late to the party, but this isn't a few user scripts that rely on this behavior. Effectively every use case of vfio relies on this behavior. We rely on unbinding the default driver from the device before using driver_override and drivers_probe. That means every hypervisor with device assignment and every userspace driver use case now experiences a tainted kernel. That seems like a significant regression.

Quoted 7 lines
Quoted 4 lines

Sorry, I was on vacation and missed this change earlier. This change will affect SR-IOV deployments around the world, which *rely* on being able to bind a driver manually *after* virtual functions are created but before they are used.

Why can't a real driver bind to those virtual functions? Like is happening in the rust apis?

Most people using SRIOV will bind the VFs to the VFIO driver.

The rest, it is the same as the CC case, there needs to be a gap after creating the PCI VF functions and before binding a real driver, with a proper match and a correct id.

This is usually managed by clearing drivers_autoprobe

Ie look at commit b8c5cec23d5c ("Driver core: udev triggered device-<>driver binding") from 2007 explaining this workflow.

The taint on sysfs unbind makes zero sense here because we can trigger unbind of those VFs just by disabling SRIOV through sysfs. Should we taint that too?

Quoted 5 lines
Quoted 3 lines

This is needed for two reasons: to save hardware and software resources when creating a large number of VFs, and to allow the PCI config space to be configured *before* the driver starts using it.

How is hardware and software resources an issue here at all?

If you create a 1024 VFs, which is what people on big servers seem to do, then that can use 1024 x megabytes of resources to load all those drivers which will memory exhaust a hypervisor.

This is a real case actual users run into, I saw the support requests go by :|

Quoted 1 line

And you can write to PCI config space from userspace today,

Not allowed in lockdown, triggered by secure boot, which pretty much every server uses.

Quoted 3 lines
Quoted 1 line

There is no in-kernel alternative.

Then just don't have a in-kernel driver for the device and all is good?

What? How do you use the HW then? Is this a serious reply?

Jason

#38 lore raw
In reply to Greg Kroah-Hartman
Quoted 49 lines · Greg Kroah-Hartman
Quoted 48 lines · Leon Romanovsky
Quoted 46 lines · Alex Williamson
Quoted 29 lines · On Wed, 23 Sep 2026 12:29:56 +0200 Greg Kroah-Hartman…
Quoted 8 lines · Uwe Kleine-König
Quoted 4 lines

No, drivers should NOT have to do that in their .probe() function, that's what we moved away from decades ago! The match function should handle all of that for you, otherwise it's contant duplication everywhere that is unneeded.

Well then you have to accept that root can provoke a null pointer exception (e.g. by forcing the pwm-tegra driver on a device) because at least with today's platform bus match function such a match is ok.

Agreed, yes, root can cause a crash and can do tons of horrible things much worse than this, that's not the issue.

That's why this taint is there, to make it obvious that this is not a "real" bug at all.

Quoted 8 lines
Quoted 7 lines

Please, learn from our history, don't make the same mistakes.

Now I might be convinced that driver_override is the way to go here, but it still feels really odd as again, bind/unbind was created as a driver debugging option only, it should NOT be a normal operation that any user should rely on. The driver should "just work" properly instead, without requiring manual bind work, as that's not a good model at all.

Quoted 4 lines

I agree in principle, but (in my case wifi) drivers are buggy sometimes (due to missing documentation and/or engineering effort) and being able to rebind the driver instead of rebooting to get a working device again is very useful.

Quoted 6 lines

Fine, use it! Just don't expect that to be "normal".

Quoted 2 lines

So yes, theoretically bind/unbind isn't needed, but theory and practise differ in practise.

Agreed, but again, don't rely on this as a "real" solution fo ranything.

Sorry, late to the party, but this isn't a few user scripts that rely on this behavior. Effectively every use case of vfio relies on this behavior. We rely on unbinding the default driver from the device before using driver_override and drivers_probe. That means every hypervisor with device assignment and every userspace driver use case now experiences a tainted kernel. That seems like a significant regression.

Quoted 7 lines
Quoted 4 lines

Sorry, I was on vacation and missed this change earlier. This change will affect SR-IOV deployments around the world, which *rely* on being able to bind a driver manually *after* virtual functions are created but before they are used.

Why can't a real driver bind to those virtual functions? Like is happening in the rust apis?

The actual driver is also bound, but at a later stage. I'm not sure what you mean by “Rust APIs.”

Quoted 8 lines
Quoted 4 lines

This is needed for two reasons: to save hardware and software resources when creating a large number of VFs, and to allow the PCI config space to be configured *before* the driver starts using it.

How is hardware and software resources an issue here at all? And you can write to PCI config space from userspace today, no driver needed anywhere at all, that's always been allowed.

According to the PCI spec—or, at least, the common interpretation of it— newly created VFs should have equivalent hardware-resource partitions. For most hardware resources, this is not an issue. One resource, however, is critical to partition correctly: the number of MSI-X vectors per VF. These vectors are backed by physical resources and directly affect performance and utilization.

In a correctly configured system, the number of MSI-X vectors should match the number of CPUs assigned to the VM. More vectors can leave hardware underutilized; fewer can degrade performance.

The workflow for cloud operators is therefore:

1. Create a large number of VFs, but do not assign them yet.
2. Lease a VM to a user and determine how many CPUs they requested.
3. Repartition the internal MSI-X table allocation.
4. Assign the VF to the user.
5. Check how many MSI-X vectors remain available, then return to step 2.

The MSI-X table size is read near the beginning of driver initialization and cannot be changed afterward.

So, no—you cannot change those PCI values without breaking the driver and OS that are already running.

Quoted 4 lines
Quoted 2 lines

There is no in-kernel alternative.

Then just don't have a in-kernel driver for the device and all is good?

In addition to Jason's comments, the PF and VF share the same driver because they are nearly identical, apart from a few differences in PCI configuration space.

Please revert the series ASAP, you are clearly breaking existing deployments.

Thanks

Quoted 5 lines

thanks,

greg k-h

#39 lore raw
In reply to Greg Kroah-Hartman

Am 23.09.26 um 11:27 schrieb Greg Kroah-Hartman:

Quoted 53 lines · Armin Wolf
Quoted 52 lines

Am 22.09.26 um 15:40 schrieb David Lechner:

Quoted 50 lines · Uwe Kleine-König
Quoted 49 lines · Danilo Krummrich
Quoted 38 lines · Greg Kroah-Hartman
Quoted 29 lines

The ability to add and remove devices from a driver through the sysfs "bind" and "unbind" files was created all those decades ago as a way that kernel developers can iterate faster, and provide a debugging way for users to attempt to add a new device to a driver without having to rebuild their kernel.

This api over the years has been abused and recently come under a major fuzzing "attack" through tools like syzbot which decided that it would attempt to just randomly bind any driver to any type of device, causing loads of unneeded errors and pointless kernel patches to be generated by unsuspecting new developers.

Handle all of this by adding a new taint flag, TAINT_FORCED_BIND, which will be set on the driver if the bind/unbind sysfs files are ever written to. This lets kernel developers "know" that a user is attempting to do something that is not normal, and as such, if the kernel breaks they get to keep the shiny pieces laying around on the floor.

The flag is 'Y' which was unused, and can remembered as the user is "yeeting" the device being operated on here (thrown with force without regard for the thing being thrown).

Note, the taint flag gets set _BEFORE_ the bind/unbind callback happens, as many times crashes/oops/warnings/failures happen within the callback, and the taint flag needs to be there to show what was being attempted. If it were to be set after the callback happens, the oops report would not properly reflect what foolishness was being attempted.

Quoted 6 lines

Fuzzing tools like syzbot, that doesn't have hand-crafted rules to keep the tool from hitting bind/unbind, should be run with panic_on_taint enabled so that they fall over and don't continue on, thinking that they actually found a real issue.

Userspace operations that rely on the bind/unbind files

I agree that this should be avoided.

Quoted 7 lines

But I also think the biggest offender really is driver_override. Specifically, on a hot-pluggable bus a driver must be complient with the device driver lifecycle rules and hence shouldn't break on bind/unbind. I think it would be nice to not taint the kernel for such busses, and only taint on driver_override, as I think we'd still want the bug reports for such cases.

But I think this is fine to leave for a follow-up.

I fully agree. I'm fine and support tainting on driver_override, but bind/unbind are used occasionally in my bubble and I consider drivers not handling that properly buggy.

Quoted 8 lines
Quoted 4 lines

I fully agree with this, drivers should correctly implement the lifecycle model and not just break when being unbound at a improper time. Drivers suffering from this can easily break this way when unloading the associated kernel module, so this taint is no solution.

It's a "solution" in that it tells the developer "hey, the user did something odd and unsupported". rmmod is also not a normal operation, there's no requirement that it actually work as it's usually a "best effort" type of thing.

From my perspective rmmod and friends are at least expected to not crash the kernel.

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines

In the IIO subsystem, unbind/rebind is the de-facto way to reset a wedged chip.

A few examples where other reset methods were reject in favor of unbind/bind:

https://lore.kernel.org/linux-iio/20240727160216.2488ed29@jic23-huawei/

This needs documenting as it's custom ABI. Note that we don't often accept custom ABI. Particularly not a hook that seems to reset the device. If you want to do that, unbind and rebind the whole drive[r] so we are in a known state etc.

https://lore.kernel.org/linux-iio/20240720163440.03c713dc@jic23-huawei/

Firstly as stated below, we don't provide interfaces for this because it's a heavy weight process that is most of the effort of unbinding and rebinding the driver. So if you need to reset, do that.

https://lore.kernel.org/linux-iio/20250505200609.54756520@jic23-huawei/

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

The solution is to run it once at driver bind. Similar to reset below, if the usecase needs to re do it then unbinding and rebinding the driver reflects the fact we are taking it effectively offline for a while.

I also consider bind/unbind to be an official API to interact with devices, so i want to use them in the future with the WMI subsystem.

Why?

Netlink UAPI <-> generic driver <-> WMI device

User will need to manually bind the generic driver (it really supports all WMI devices!) to a given WMI device, something that is only possible with bind/unbind.

Quoted 11 lines
Quoted 5 lines

AFAIK the underlying reason for this series is that some drivers break when being bound to unsupported devices. However IMHO drivers should verify that they support a given device inside their .probe callback, and the associated bus should only match devices with drivers that explicitly claim support for those devices (ignoring driver_override).

No, drivers should NOT have to do that in their .probe() function, that's what we moved away from decades ago! The match function should handle all of that for you, otherwise it's contant duplication everywhere that is unneeded.

Please, learn from our history, don't make the same mistakes.

I meant with that, that drivers should be prepared that for example of_device_get_match_data() returns a NULL pointer. In Rust drivers would have to check for this anyway, so i see little reason why drivers written in C should skip this check and as a result break as soon as someone uses driver_override (or they are matched against a non-OF device).

Quoted 9 lines

Now I might be convinced that driver_override is the way to go here, but it still feels really odd as again, bind/unbind was created as a driver debugging option only, it should NOT be a normal operation that any user should rely on. The driver should "just work" properly instead, without requiring manual bind work, as that's not a good model at all.

thanks,

greg k-h

I understand your concerns, but IMHO it turned out that bind/unbind are useful outside of debugging. I agree that userspace using bind/unbind should not be considered normal, but in my opinion its far from being suspicious. Manually unbinding a specific drivers in order to bind a generic driver is unusual, but understandable.

I agree with you that driver_override should be the correct place for such a taint, because using driver_override indeed overrides the bus-specific matching logic and can therefore be dangerous.

Thanks,
Armin Wolf