selftests/seccomp: fix pointer type mismatch in UPROBE test
Subsystems (3)
PATCH 1/1 selftests/seccomp: fix pointer type mismatch in UPROBE test
Fix compilation error in UPROBE_setup caused by pointer type mismatch in ternary expression. The probed_uretprobe and probed_uprobe function pointers have different type attributes (__attribute__((nocf_check))), which causes the conditional operator to fail with:
seccomp_bpf.c:5175:74: error: pointer type mismatch in conditional expression [-Wincompatible-pointer-types]
Cast both function pointers to 'const void *' to match the expected parameter type of get_uprobe_offset(), resolving the type mismatch while preserving the function selection logic.
--- tools/testing/selftests/seccomp/seccomp_bpf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/seccomp/seccomp_bpf.c +2 -1
@@ -5172,7 +5172,8 @@ FIXTURE_SETUP(UPROBE)ASSERT_GE (bit,0 ); } - offset =get_uprobe_offset (variant->uretprobe ? probed_uretprobe : probed_uprobe); + offset =get_uprobe_offset (variant->uretprobe ? + (const void *)probed_uretprobe : (const void *)probed_uprobe);ASSERT_GE (offset,0 );if (variant->uretprobe)
Signature · 1 line
2.48.1
Quoted 3 lines · Nirbhay Sharma
Fix compilation error in
UPROBE_setupcaused by pointer type mismatch in ternary expression. Theprobed_uretprobeandprobed_uprobefunction pointers have different type attributes (__attribute__((nocf_check))),
just probed_uprobe right?
Quoted 4 lines
which causes the conditional operator to fail with:
seccomp_bpf.c:5175:74: error: pointer type mismatch in conditional expression [-Wincompatible-pointer-types]
curious what compiler do you see that with? gcc-15 is silent, the change looks good to me
thanks,
jirka
Quoted 28 lines
Cast both function pointers to 'const void *' to match the expected parameter type of
get_uprobe_offset(), resolving the type mismatch while preserving the function selection logic.Signed-off-by Nirbhay Sharma <[email protected]>--- tools/testing/selftests/seccomp/seccomp_bpf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/testing/selftests/seccomp/seccomp_bpf.c +2
-1@@ -5172,7 +5172,8 @@ FIXTURE_SETUP(UPROBE)ASSERT_GE (bit,0 ); } - offset =get_uprobe_offset (variant->uretprobe ? probed_uretprobe : probed_uprobe); + offset =get_uprobe_offset (variant->uretprobe ? + (const void *)probed_uretprobe : (const void *)probed_uprobe);ASSERT_GE (offset,0 );if (variant->uretprobe)Signature · 1 line
2.48.1
I tried to reproduce it with a small testcase and I could reproduce the error with -fcf-protection and not without (where I get a warning that the nocf_check attribute is ignored b/c of no flag).
Hi Jiri,
Thank you for the review and for catching that inaccuracy!
Quoted 1 line · Jiri Olsa
just
probed_uproberight?
Yes, you're absolutely correct. Only probed_uprobe has the __attribute__((nocf_check)) attribute. I apologize for the confusion in my original commit message. I'll fix this in v2.
Quoted 1 line
curious what compiler do you see that with?
I am seeing this error with Clang 19.1.2 on Fedora, which enables -fcf-protection=full by default. As Sam confirmed, the error occurs specifically when CFI protection is enabled via -fcf-protection. GCC without this flag treats it as a warning or ignores the nocf_check attribute entirely.
I'll send v2 with the corrected commit message.
Thanks again for the review!
Best regards,
Nirbhay
PATCH v2 1/1 selftests/seccomp: fix pointer type mismatch in UPROBE test
In reply to Jiri OlsaFix compilation error in UPROBE_setup caused by pointer type mismatch in the ternary expression when compiled with -fcf-protection. The probed_uprobe function pointer has the __attribute__((nocf_check)) attribute, which causes the conditional operator to fail when combined with the regular probed_uretprobe function pointer:
seccomp_bpf.c:5175:74: error: pointer type mismatch in conditional expression [-Wincompatible-pointer-types]
Cast both function pointers to 'const void *' to match the expected parameter type of get_uprobe_offset(), resolving the type mismatch while preserving the function selection logic.
This error appears with compilers that enable Control Flow Integrity (CFI) protection via -fcf-protection, such as Clang 19.1.2 (default on Fedora).
--- tools/testing/selftests/seccomp/seccomp_bpf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/seccomp/seccomp_bpf.c +2 -1
@@ -5172,7 +5172,8 @@ FIXTURE_SETUP(UPROBE)ASSERT_GE (bit,0 ); } - offset =get_uprobe_offset (variant->uretprobe ? probed_uretprobe : probed_uprobe); + offset =get_uprobe_offset (variant->uretprobe ? + (const void *)probed_uretprobe : (const void *)probed_uprobe);ASSERT_GE (offset,0 );if (variant->uretprobe)
Signature · 1 line
2.48.1
Quoted 6 lines · Nirbhay Sharma
Fix compilation error in
UPROBE_setupcaused by pointer type mismatch in the ternary expression when compiled with -fcf-protection. Theprobed_uprobefunction pointer has the __attribute__((nocf_check)) attribute, which causes the conditional operator to fail when combined with the regularprobed_uretprobefunction pointer:
Just as a curiosity to share: I found a few tangential issues and reported them as https://gcc.gnu.org/PR122427.
Quoted 11 lines
seccomp_bpf.c:5175:74: error: pointer type mismatch in conditional expression [-Wincompatible-pointer-types]
Cast both function pointers to 'const void *' to match the expected parameter type of
get_uprobe_offset(), resolving the type mismatch while preserving the function selection logic.This error appears with compilers that enable Control Flow Integrity (CFI) protection via -fcf-protection, such as Clang 19.1.2 (default on Fedora).
Quoted 19 lines
Signed-off-by Nirbhay Sharma <[email protected]>--- tools/testing/selftests/seccomp/seccomp_bpf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/testing/selftests/seccomp/seccomp_bpf.c +2
-1@@ -5172,7 +5172,8 @@ FIXTURE_SETUP(UPROBE)ASSERT_GE (bit,0 ); } - offset =get_uprobe_offset (variant->uretprobe ? probed_uretprobe : probed_uprobe); + offset =get_uprobe_offset (variant->uretprobe ? + (const void *)probed_uretprobe : (const void *)probed_uprobe);ASSERT_GE (offset,0 );if (variant->uretprobe)
Quoted 13 lines · Nirbhay Sharma
Fix compilation error in
UPROBE_setupcaused by pointer type mismatch in the ternary expression when compiled with -fcf-protection. Theprobed_uprobefunction pointer has the __attribute__((nocf_check)) attribute, which causes the conditional operator to fail when combined with the regularprobed_uretprobefunction pointer:seccomp_bpf.c:5175:74: error: pointer type mismatch in conditional expression [-Wincompatible-pointer-types]
Cast both function pointers to 'const void *' to match the expected parameter type of
get_uprobe_offset(), resolving the type mismatch while preserving the function selection logic.
Quoted 5 lines
This error appears with compilers that enable Control Flow Integrity (CFI) protection via -fcf-protection, such as Clang 19.1.2 (default on Fedora).
Signed-off-by Nirbhay Sharma <[email protected]>
thanks,
jirka
Quoted 21 lines
--- tools/testing/selftests/seccomp/seccomp_bpf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/testing/selftests/seccomp/seccomp_bpf.c +2
-1@@ -5172,7 +5172,8 @@ FIXTURE_SETUP(UPROBE)ASSERT_GE (bit,0 ); } - offset =get_uprobe_offset (variant->uretprobe ? probed_uretprobe : probed_uprobe); + offset =get_uprobe_offset (variant->uretprobe ? + (const void *)probed_uretprobe : (const void *)probed_uprobe);ASSERT_GE (offset,0 );if (variant->uretprobe)Signature · 1 line
2.48.1
Quoted 27 lines · Nirbhay Sharma
Fix compilation error in
UPROBE_setupcaused by pointer type mismatch in the ternary expression when compiled with -fcf-protection. Theprobed_uprobefunction pointer has the __attribute__((nocf_check)) attribute, which causes the conditional operator to fail when combined with the regularprobed_uretprobefunction pointer:seccomp_bpf.c:5175:74: error: pointer type mismatch in conditional expression [-Wincompatible-pointer-types]
Cast both function pointers to 'const void *' to match the expected parameter type of
get_uprobe_offset(), resolving the type mismatch while preserving the function selection logic.This error appears with compilers that enable Control Flow Integrity (CFI) protection via -fcf-protection, such as Clang 19.1.2 (default on Fedora).
Signed-off-by Nirbhay Sharma <[email protected]>--- tools/testing/selftests/seccomp/seccomp_bpf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/testing/selftests/seccomp/seccomp_bpf.c +0
-0
tools/testing/selftests/seccomp/seccomp_bpf.c FIXTURE_SETUP(UPROBE) · line 5179
Quoted 9 lines
tools/testing/selftests/seccomp/seccomp_bpf.c +2
-1@@ -5172,7 +5172,8 @@ FIXTURE_SETUP(UPROBE)ASSERT_GE (bit,0 ); } - offset =get_uprobe_offset (variant->uretprobe ? probed_uretprobe : probed_uprobe); + offset =get_uprobe_offset (variant->uretprobe ? + (const void *)probed_uretprobe : (const void *)probed_uprobe);ASSERT_GE (offset,0 );if (variant->uretprobe)
Hi all,
I'm following up on this patch that fixes the pointer type mismatch in UPROBE_setup when building with -fcf-protection. It resolves the incompatible-pointer-types error seen with Clang 19.
Please let me know if there are any comments or some changes needed.
Thanks,
Nirbhay Sharma
Shuah Khan
maintainerQuoted 40 lines · Nirbhay Sharma
Quoted 27 lines · Nirbhay Sharma
Fix compilation error in
UPROBE_setupcaused by pointer type mismatch in the ternary expression when compiled with -fcf-protection. Theprobed_uprobefunction pointer has the __attribute__((nocf_check)) attribute, which causes the conditional operator to fail when combined with the regularprobed_uretprobefunction pointer:seccomp_bpf.c:5175:74: error: pointer type mismatch in conditional expression [-Wincompatible-pointer-types]
Cast both function pointers to 'const void *' to match the expected parameter type of
get_uprobe_offset(), resolving the type mismatch while preserving the function selection logic.This error appears with compilers that enable Control Flow Integrity (CFI) protection via -fcf-protection, such as Clang 19.1.2 (default on Fedora).
Signed-off-by Nirbhay Sharma <[email protected]>---
tools/testing/selftests/seccomp/seccomp_bpf.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)tools/testing/selftests/seccomp/seccomp_bpf.c +0
-0tools/testing/selftests/seccomp/seccomp_bpf.c FIXTURE_SETUP(UPROBE) · line 5177
Quoted 7 lines
tools/testing/selftests/seccomp/seccomp_bpf.c +2
-1@@ -5172,7 +5172,8 @@ FIXTURE_SETUP(UPROBE) ASSERT_GE(bit, 0); } - offset = get_uprobe_offset(variant->uretprobe ? probed_uretprobe : probed_uprobe); + offset = get_uprobe_offset(variant->uretprobe ? + (const void *)probed_uretprobe : (const void *)probed_uprobe); ASSERT_GE(offset, 0); if (variant->uretprobe)Hi all,
Quoted 6 lines
I'm following up on this patch that fixes the pointer type mismatch in
UPROBE_setupwhen building with -fcf-protection. It resolves the incompatible-pointer-types error seen with Clang 19.Please let me know if there are any comments or some changes needed.
Hi Kees,
Is it okay to take this patch through my tree?
thanks,
-- Shuah