Skip to contentSkip to conversation

bpf: introduce TAINT_UNSAFE_BPF for mutating helpers

RFC PATCH Superseded Aaron Tomlin 4 participants 6 messages May 3

Subsystems (5)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 bpf: introduce TAINT_UNSAFE_BPF for mutating helpers

The primary remit of the eBPF verifier is to ensure that eBPF programs can neither crash the kernel nor corrupt memory. Nevertheless, administrative utilities such as "bpftrace --unsafe" permit the loading of programs that employ destructive or mutating helpers, most notably bpf_probe_write_user() and bpf_override_return().

Since commit b28573ebfabe ("bpf: Remove bpf_probe_write_user() warning message"), the kernel no longer issues a warning when an attempt is made to invoke such destructive helpers.

Consequently, this patch introduces a novel kernel taint flag, TAINT_UNSAFE_BPF ("V"). Tainting the kernel establishes a permanent and readily auditable indicator (i.e., /proc/sys/kernel/tainted) to alert maintainers and that the kernel's execution flow or user memory may have been compromised by an eBPF program.

---
 Documentation/admin-guide/tainted-kernels.rst | 54 ++++++++++---------
 include/linux/panic.h                         |  3 +-
 kernel/panic.c                                |  1 +
 kernel/trace/bpf_trace.c                      |  3 ++
 4 files changed, 36 insertions(+), 25 deletions(-)
Documentation/admin-guide/tainted-kernels.rst +30 -24
index 9ead927a37c0..630f24996e7b 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  _/V  1048576  an unsafe eBPF program (mutating helper) was loaded
+===  ===  =======  ========================================================
 
 Note: The character ``_`` is representing a blank in this table to make reading
 easier.
@@ -189,3 +190,8 @@ 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) ``V`` if an eBPF program utilising unsafe, mutating helpers (such as
+     bpf_probe_write_user() or bpf_override_return()) was loaded. These helpers
+     bypass standard eBPF safety guarantees and can alter execution flow or
+     corrupt memory.
include/linux/panic.h +2 -1
index f1dd417e54b2..8622c02c2c24 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_UNSAFE_BPF		20
+#define TAINT_FLAGS_COUNT		21
 #define TAINT_FLAGS_MAX			((1UL << TAINT_FLAGS_COUNT) - 1)
 
 struct taint_flag {
kernel/panic.c +1 -0
index 20feada5319d..1ae19bd8fc1d 100644
@@ -825,6 +825,7 @@ const struct taint_flag taint_flags[TAINT_FLAGS_COUNT] = {
 	TAINT_FLAG(RANDSTRUCT,			'T', ' '),
 	TAINT_FLAG(TEST,			'N', ' '),
 	TAINT_FLAG(FWCTL,			'J', ' '),
+	TAINT_FLAG(UNSAFE_BPF,			'V', ' '),
 };
 
 #undef TAINT_FLAG
kernel/trace/bpf_trace.c +3 -0
index af7079aa0f36..4e7e5bf76dcb 100644
@@ -155,6 +155,7 @@ unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
 #ifdef CONFIG_BPF_KPROBE_OVERRIDE
 BPF_CALL_2(bpf_override_return, struct pt_regs *, regs, unsigned long, rc)
 {
+	add_taint(TAINT_UNSAFE_BPF, LOCKDEP_STILL_OK);
 	regs_set_return_value(regs, rc);
 	override_function_with_return(regs);
 	return 0;
@@ -344,6 +345,8 @@ BPF_CALL_3(bpf_probe_write_user, void __user *, unsafe_ptr, const void *, src,
 	if (unlikely(!nmi_uaccess_okay()))
 		return -EPERM;
 
+	add_taint(TAINT_UNSAFE_BPF, LOCKDEP_STILL_OK);
+
 	return copy_to_user_nofault(unsafe_ptr, src, size);
 }
 
Signature · 1 line
2.51.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] add_taint() is called unconditionally in hot eBPF helper execution paths, causing severe…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] add_taint() is called unconditionally in hot eBPF helper execution paths, causing severe cache-line bouncing and a logic mismatch.
- [Low] Malformed simple table syntax in reStructuredText documentation.
--

commit 212777c34ad78febee399b801b573989a50d8cca
Author: Aaron Tomlin <[email protected]>

bpf: introduce TAINT_UNSAFE_BPF for mutating helpers

This commit introduces a new kernel taint flag, TAINT_UNSAFE_BPF ("V"), which indicates that an eBPF program utilizing unsafe or mutating helpers has been loaded.

Quoted 11 lines
Documentation/admin-guide/tainted-kernels.rst +0 -3
index 9ead927a37c0..630f24996e7b 100644
@@ -79,30 +79,31 @@ which bits are set::
 Table for decoding tainted state
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-===  ===  ======  ========================================================
-Bit  Log  Number  Reason that got the kernel tainted
-===  ===  ======  ========================================================

[ ... ]

Quoted 3 lines
+===  ===   ======  ========================================================
+Bit  Log   Number  Reason that got the kernel tainted
+===  ===   ======  ========================================================

[ ... ]

Quoted 3 lines
+ 19  _/J   524288  userspace used a mutating debug operation in fwctl
+ 20  _/V  1048576  an unsafe eBPF program (mutating helper) was loaded
+===  ===  =======  ========================================================

This isn't a bug, but the bottom border has 7 characters (=======) for the Number column while the top and header borders have 6 (======). Will this cause a Sphinx 'Malformed table' warning when rendering the documentation?

kernel/trace/bpf_trace.c unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx) · line 160

Quoted 11 lines
kernel/trace/bpf_trace.c +1 -0
index af7079aa0f36..4e7e5bf76dcb 100644
@@ -155,6 +155,7 @@ unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
 #ifdef CONFIG_BPF_KPROBE_OVERRIDE
 BPF_CALL_2(bpf_override_return, struct pt_regs *, regs, unsigned long, rc)
 {
+	add_taint(TAINT_UNSAFE_BPF, LOCKDEP_STILL_OK);
 	regs_set_return_value(regs, rc);
 	override_function_with_return(regs);

Since bpf_override_return is a helper invoked at runtime and can execute frequently on hot kprobes, will calling add_taint() here cause severe cache line bouncing?

Looking at add_taint(), it unconditionally calls set_bit() on the global tainted_mask:

kernel/panic.c:add_taint() {
    ...
    set_bit(flag, &tainted_mask);
    ...
}

Also, the commit message and documentation mention the system is tainted when an unsafe eBPF program "was loaded". By applying the taint here during execution instead of at program load time (e.g., in the verifier), could this allow an unsafe BPF program to remain dormant and avoid detection until a specific trigger occurs?

[ ... ]

kernel/trace/bpf_trace.c BPF_CALL_3(bpf_probe_write_user, void __user *, unsafe_ptr, const void *, src, · line 351

Quoted 8 lines
kernel/trace/bpf_trace.c +2 -0
@@ -344,6 +345,8 @@ BPF_CALL_3(bpf_probe_write_user, void __user *, unsafe_ptr, const void *, src,
 	if (unlikely(!nmi_uaccess_okay()))
 		return -EPERM;
 
+	add_taint(TAINT_UNSAFE_BPF, LOCKDEP_STILL_OK);
+
 	return copy_to_user_nofault(unsafe_ptr, src, size);
 }

Similarly here, will invoking add_taint() on every execution of bpf_probe_write_user() cause significant performance degradation when executed concurrently across multiple CPUs?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
reviewer
#2 lore raw
In reply to Aaron Tomlin

Hi,

Quoted 85 lines · Aaron Tomlin

The primary remit of the eBPF verifier is to ensure that eBPF programs can neither crash the kernel nor corrupt memory. Nevertheless, administrative utilities such as "bpftrace --unsafe" permit the loading of programs that employ destructive or mutating helpers, most notably bpf_probe_write_user() and bpf_override_return().

Since commit b28573ebfabe ("bpf: Remove bpf_probe_write_user() warning message"), the kernel no longer issues a warning when an attempt is made to invoke such destructive helpers.

Consequently, this patch introduces a novel kernel taint flag, TAINT_UNSAFE_BPF ("V"). Tainting the kernel establishes a permanent and readily auditable indicator (i.e., /proc/sys/kernel/tainted) to alert maintainers and that the kernel's execution flow or user memory may have been compromised by an eBPF program.

---
 Documentation/admin-guide/tainted-kernels.rst | 54 ++++++++++---------
 include/linux/panic.h                         |  3 +-
 kernel/panic.c                                |  1 +
 kernel/trace/bpf_trace.c                      |  3 ++
 4 files changed, 36 insertions(+), 25 deletions(-)
Documentation/admin-guide/tainted-kernels.rst +25 -24
index 9ead927a37c0..630f24996e7b 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  _/V  1048576  an unsafe eBPF program (mutating helper) was loaded
+===  ===  =======  ========================================================
 
 Note: The character ``_`` is representing a blank in this table to make reading
 easier.

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

Quoted 8 lines
Documentation/admin-guide/tainted-kernels.rst +5 -0
@@ -189,3 +190,8 @@ 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) ``V`` if an eBPF program utilising unsafe, mutating helpers (such as
+     bpf_probe_write_user() or bpf_override_return()) was loaded. These helpers
+     bypass standard eBPF safety guarantees and can alter execution flow or
+     corrupt memory.

(If this patch goes forward:)

In this same file (above), there is a little script around line 77 where it should be changed:
s/20/21/

Also please update tools/debugging/kernel-chktaint for this taint flag.

Signature · 1 line
~Randy
#3 lore raw
Quoted 5 lines · Randy Dunlap

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

Quoted 4 lines

+ 20) ``V`` if an eBPF program utilising unsafe, mutating helpers (such as

Documentation/admin-guide/tainted-kernels.rst +3 -0
+     bpf_probe_write_user() or bpf_override_return()) was loaded. These helpers
+     bypass standard eBPF safety guarantees and can alter execution flow or
+     corrupt memory.
Quoted 8 lines

(If this patch goes forward:)

In this same file (above), there is a little script around line 77 where it should be changed:
s/20/21/

Also please update tools/debugging/kernel-chktaint for this taint flag.

Hi Randy,

Acknowledged. I'll address the above within the next iteration.

Kind regards,

Signature · 1 line
Aaron Tomlin
#4 lore raw
In reply to Aaron Tomlin
This isn't a bug, but the bottom border has 7 equals signs (=======) for the Number column while the top and header borders have 6 (======). Will this cause a Sphinx 'Malformed table' warning when…
Quoted 11 lines
Documentation/admin-guide/tainted-kernels.rst +0 -3
index 9ead927a37c0..630f24996e7b 100644
@@ -79,30 +79,31 @@ which bits are set::
 Table for decoding tainted state
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-===  ===  ======  ========================================================
-Bit  Log  Number  Reason that got the kernel tainted
-===  ===  ======  ========================================================

[ ... ]

Quoted 3 lines
+ 19  _/J   524288  userspace used a mutating debug operation in fwctl
+ 20  _/V  1048576  an unsafe eBPF program (mutating helper) was loaded
+===  ===  =======  ========================================================

This isn't a bug, but the bottom border has 7 equals signs (=======) for the Number column while the top and header borders have 6 (======). Will this cause a Sphinx 'Malformed table' warning when rendering the documentation?

Earlier in the same file, around line 77, there's a shell command example for checking taint bits. With the addition of bit 20, shouldn't that command be updated from 'seq 20' to 'seq 21' so it checks all 21 bits (0-20)?

The current command only checks bits 0-19:

    $ for i in $(seq 20); do echo $(($i-1)) $(($(cat /proc/sys/kernel/tainted)>>($i-1)&1));done

Since 'seq 20' produces 1..20, and the expression uses $(($i-1)), it only computes bit positions 0..19, missing the newly added bit 20.

Quoted 28 lines
Documentation/admin-guide/tainted-kernels.rst +5 -0
@@ -189,3 +190,8 @@ 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) ``V`` if an eBPF program utilising unsafe, mutating helpers (such as
+     bpf_probe_write_user() or bpf_override_return()) was loaded. These helpers
+     bypass standard eBPF safety guarantees and can alter execution flow or
+     corrupt memory.
include/linux/panic.h +2 -1
index f1dd417e54b2..8622c02c2c24 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_UNSAFE_BPF		20
+#define TAINT_FLAGS_COUNT		21
 #define TAINT_FLAGS_MAX			((1UL << TAINT_FLAGS_COUNT) - 1)
 
 struct taint_flag {
kernel/panic.c +0 -0
index 20feada5319d..1ae19bd8fc1d 100644

kernel/panic.c const struct taint_flag taint_flags[TAINT_FLAGS_COUNT] = { · line 831

Quoted 7 lines
kernel/panic.c +1 -0
@@ -825,6 +825,7 @@ const struct taint_flag taint_flags[TAINT_FLAGS_COUNT] = {
 	TAINT_FLAG(RANDSTRUCT,			'T', ' '),
 	TAINT_FLAG(TEST,			'N', ' '),
 	TAINT_FLAG(FWCTL,			'J', ' '),
+	TAINT_FLAG(UNSAFE_BPF,			'V', ' '),
 };
 
 #undef TAINT_FLAG

There's a comment earlier in this file that explicitly states: "if you modify the taint_flags or TAINT_FLAGS_COUNT, please also modify tools/debugging/kernel-chktaint and Documentation/admin-guide/tainted-kernels.rst".

While the Documentation was updated, was tools/debugging/kernel-chktaint also updated? The script currently processes flags 0-19 and ends with the J flag check. Without adding a section to check bit 20, the script won't decode the 'V' character in the taint string output when TAINT_UNSAFE_BPF is set.

The script would need something like:

T=expr $T / 2
if [ expr $T % 2 -eq 0 ]; then
addout " "
else
addout "V"
echo " * an unsafe eBPF program (mutating helper) was loaded (#20)"
fi

kernel/trace/bpf_trace.c unsigned int trace_call_bpf_faultable(struct trace_event_call *call, void *ctx) · line 189

Quoted 12 lines
kernel/trace/bpf_trace.c +1 -0
index a822c589c9bd..3f893d9ea764 100644
@@ -183,6 +183,7 @@ unsigned int trace_call_bpf_faultable(struct trace_event_call *call, void *ctx)
 #ifdef CONFIG_BPF_KPROBE_OVERRIDE
 BPF_CALL_2(bpf_override_return, struct pt_regs *, regs, unsigned long, rc)
 {
+	add_taint(TAINT_UNSAFE_BPF, LOCKDEP_STILL_OK);
 	regs_set_return_value(regs, rc);
 	override_function_with_return(regs);
 	return 0;

Since bpf_override_return is a helper invoked at runtime and can execute frequently on hot kprobes, will calling add_taint() here cause severe cache line bouncing?

Looking at add_taint(), it unconditionally calls set_bit() on the global tainted_mask.

Also, the commit message and documentation mention the system is tainted when an unsafe eBPF program 'was loaded'. By applying the taint here during execution instead of at program load time (e.g., in the verifier), could this allow an unsafe BPF program to remain dormant and avoid detection until a specific trigger occurs?

kernel/trace/bpf_trace.c BPF_CALL_3(bpf_probe_write_user, void __user *, unsafe_ptr, const void *, src, · line 379

Quoted 8 lines
kernel/trace/bpf_trace.c +2 -0
@@ -372,6 +373,8 @@ BPF_CALL_3(bpf_probe_write_user, void __user *, unsafe_ptr, const void *, src,
 	if (unlikely(!nmi_uaccess_okay()))
 		return -EPERM;
 
+	add_taint(TAINT_UNSAFE_BPF, LOCKDEP_STILL_OK);
+
 	return copy_to_user_nofault(unsafe_ptr, src, size);
 }

Similarly here, will invoking add_taint() on every execution of bpf_probe_write_user() cause significant performance degradation when executed concurrently across multiple CPUs?

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/25269516443

#5 lore raw
Quoted 22 lines · On Sun, May 03, 2026 at 04:44:33AM +0000, [email protected] wrote:
Quoted 11 lines
Documentation/admin-guide/tainted-kernels.rst +0 -3
index 9ead927a37c0..630f24996e7b 100644
@@ -79,30 +79,31 @@ which bits are set::
 Table for decoding tainted state
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-===  ===  ======  ========================================================
-Bit  Log  Number  Reason that got the kernel tainted
-===  ===  ======  ========================================================

[ ... ]

Quoted 3 lines
+ 19  _/J   524288  userspace used a mutating debug operation in fwctl
+ 20  _/V  1048576  an unsafe eBPF program (mutating helper) was loaded
+===  ===  =======  ========================================================

This isn't a bug, but the bottom border has 7 equals signs (=======) for the Number column while the top and header borders have 6 (======). Will this cause a Sphinx 'Malformed table' warning when rendering the documentation?

[ ... ]

Quoted 4 lines

Earlier in the same file, around line 77, there's a shell command example for checking taint bits. With the addition of bit 20, shouldn't that command be updated from 'seq 20' to 'seq 21' so it checks all 21 bits (0-20)?

[ ... ]

Quoted 6 lines

The current command only checks bits 0-19:

    $ for i in $(seq 20); do echo $(($i-1)) $(($(cat /proc/sys/kernel/tainted)>>($i-1)&1));done

Since 'seq 20' produces 1..20, and the expression uses $(($i-1)), it only computes bit positions 0..19, missing the newly added bit 20.

Acknowledged. This will be resolved in the next iteration.

Quoted 13 lines

There's a comment earlier in this file that explicitly states: "if you modify the taint_flags or TAINT_FLAGS_COUNT, please also modify tools/debugging/kernel-chktaint and Documentation/admin-guide/tainted-kernels.rst".

While the Documentation was updated, was tools/debugging/kernel-chktaint also updated? The script currently processes flags 0-19 and ends with the J flag check. Without adding a section to check bit 20, the script won't decode the 'V' character in the taint string output when TAINT_UNSAFE_BPF is set.

The script would need something like:

Quoted 7 lines

T=expr $T / 2
if [ expr $T % 2 -eq 0 ]; then
addout " "
else
addout "V"
echo " * an unsafe eBPF program (mutating helper) was loaded (#20)"
fi

Acknowledged. I will incorporate the suggested check for the "V" flag into tools/debugging/kernel-chktaint.

Quoted 19 lines

kernel/trace/bpf_trace.c unsigned int trace_call_bpf_faultable(struct trace_event_call *call, void *ctx) · line 189

Quoted 12 lines
kernel/trace/bpf_trace.c +1 -0
index a822c589c9bd..3f893d9ea764 100644
@@ -183,6 +183,7 @@ unsigned int trace_call_bpf_faultable(struct trace_event_call *call, void *ctx)
 #ifdef CONFIG_BPF_KPROBE_OVERRIDE
 BPF_CALL_2(bpf_override_return, struct pt_regs *, regs, unsigned long, rc)
 {
+	add_taint(TAINT_UNSAFE_BPF, LOCKDEP_STILL_OK);
 	regs_set_return_value(regs, rc);
 	override_function_with_return(regs);
 	return 0;

Since bpf_override_return is a helper invoked at runtime and can execute frequently on hot kprobes, will calling add_taint() here cause severe cache line bouncing?

Looking at add_taint(), it unconditionally calls set_bit() on the global tainted_mask.

[ ... ]

Quoted 5 lines

Also, the commit message and documentation mention the system is tainted when an unsafe eBPF program 'was loaded'. By applying the taint here during execution instead of at program load time (e.g., in the verifier), could this allow an unsafe BPF program to remain dormant and avoid detection until a specific trigger occurs?

Acknowledged. I'll move the taint application to check_helper_call().

Kind regards,

Signature · 1 line
Aaron Tomlin