Skip to contentSkip to conversation

powerpc/entry: Clear TIF_SYSCALL_RET before syscall error return

PATCH Applied Shrikanth Hegde 5 participants 7 messages Aug 28 – Sep 9 PowerPC

lore
Share & tools
lore

Shrikanth Hegde

author reviewer
#0 lore raw

PATCH 1/1 powerpc/entry: Clear TIF_SYSCALL_RET before syscall error return

Shivaprasad reported a boot failure due to userspace processes crash on abort() from libc.so.6. It was bisected to merge request commit '3424d8c18a7d ("Merge tag 'core-entry-2026-08-17' of
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")'

Upon checking the merge, when syscall_enter_from_user_mode_randomize_stack fails, which could happen when a tracer like seccomp or ptrace intercepts and skips the syscall, the code returns to userspace immediately without clearing the intermediate flag which was set.

When the next syscall is made, it immediately aborts the valid syscall since the flag is still set. Hence clear the flag on occurrence of first failure.

Fixes 3424d8c18a7d ("Merge tag 'core-entry-2026-08-17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")

---
PS: I have kept the block below since earlier code was checking it regardless of result of syscall_enter_from_user_mode. If it turns out to be a redundant, it can be removed later.

 arch/powerpc/kernel/syscall.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/kernel/syscall.c +3 -1
index 4916c205c4bb..fbefe1927b10 100644
@@ -18,8 +18,10 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
 	long ret;
 	syscall_fn f;
 
-	if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0)))
+	if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0))) {
+		clear_thread_flag(TIF_SYSCALL_RET);
 		return syscall_get_error(current, regs);
+	}
 
 	if (unlikely(test_and_clear_thread_flag(TIF_SYSCALL_RET)))
 		return syscall_get_error(current, regs);
Signature · 1 line
2.47.3
Tested-by on v1 1/1
#1 lore raw
Quoted 10 lines · Shrikanth Hegde

Shivaprasad reported a boot failure due to userspace processes crash on abort() from libc.so.6. It was bisected to merge request commit '3424d8c18a7d ("Merge tag 'core-entry-2026-08-17' of
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")'

Upon checking the merge, when syscall_enter_from_user_mode_randomize_stack fails, which could happen when a tracer like seccomp or ptrace intercepts and skips the syscall, the code returns to userspace immediately without clearing the intermediate flag which was set.

Quoted 8 lines

When the next syscall is made, it immediately aborts the valid syscall since the flag is still set. Hence clear the flag on occurrence of first failure.

Fixes 3424d8c18a7d ("Merge tag 'core-entry-2026-08-17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")

Thanks,
Shivaprasad

Quoted 24 lines

---
PS: I have kept the block below since earlier code was checking it regardless of result of syscall_enter_from_user_mode. If it turns out to be a redundant, it can be removed later.

  arch/powerpc/kernel/syscall.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/kernel/syscall.c +3 -1
index 4916c205c4bb..fbefe1927b10 100644
@@ -18,8 +18,10 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
  	long ret;
  	syscall_fn f;
 
-	if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0)))
+	if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0))) {
+		clear_thread_flag(TIF_SYSCALL_RET);
  		return syscall_get_error(current, regs);
+	}
 
  	if (unlikely(test_and_clear_thread_flag(TIF_SYSCALL_RET)))
  		return syscall_get_error(current, regs);
#2 lore raw
In reply to Shrikanth Hegde
Quoted 14 lines · Shrikanth Hegde

Shivaprasad reported a boot failure due to userspace processes crash on abort() from libc.so.6. It was bisected to merge request commit '3424d8c18a7d ("Merge tag 'core-entry-2026-08-17' of
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")'

Upon checking the merge, when syscall_enter_from_user_mode_randomize_stack fails, which could happen when a tracer like seccomp or ptrace intercepts and skips the syscall, the code returns to userspace immediately without clearing the intermediate flag which was set.

When the next syscall is made, it immediately aborts the valid syscall since the flag is still set. Hence clear the flag on occurrence of first failure.

Quoted 9 lines
Fixes 3424d8c18a7d ("Merge tag 'core-entry-2026-08-17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")

---
PS: I have kept the block below since earlier code was checking it regardless of result of syscall_enter_from_user_mode. If it turns out to be a redundant, it can be removed later.

I think it is redundant as of now. The TIF_SYSCALL_RET flag is set when error is set by the ptrace or seccomp, If the error value is set then the syscall_enter_from_user_mode_randomize_stack will return false. Hence the next check will become redundant.

I also see that TIF_SYSCALL_RET is also set when processing the ptrace syscall, Which can leave the flag set for next syscall execution. Which can again trigger the same issue.

Regards,
Mukesh

Quoted 22 lines
 arch/powerpc/kernel/syscall.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/kernel/syscall.c +3 -1
index 4916c205c4bb..fbefe1927b10 100644
@@ -18,8 +18,10 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
 	long ret;
 	syscall_fn f;
 
-	if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0)))
+	if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0))) {
+		clear_thread_flag(TIF_SYSCALL_RET);
 		return syscall_get_error(current, regs);
+	}
 
 	if (unlikely(test_and_clear_thread_flag(TIF_SYSCALL_RET)))
 		return syscall_get_error(current, regs);
Signature · 1 line
2.47.3
author reviewer
#3 lore raw
Quoted 24 lines · Mukesh Kumar Chaurasiya
Quoted 14 lines · Shrikanth Hegde

Shivaprasad reported a boot failure due to userspace processes crash on abort() from libc.so.6. It was bisected to merge request commit '3424d8c18a7d ("Merge tag 'core-entry-2026-08-17' of
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")'

Upon checking the merge, when syscall_enter_from_user_mode_randomize_stack fails, which could happen when a tracer like seccomp or ptrace intercepts and skips the syscall, the code returns to userspace immediately without clearing the intermediate flag which was set.

When the next syscall is made, it immediately aborts the valid syscall since the flag is still set. Hence clear the flag on occurrence of first failure.

Quoted 9 lines
Fixes 3424d8c18a7d ("Merge tag 'core-entry-2026-08-17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")

---
PS: I have kept the block below since earlier code was checking it regardless of result of syscall_enter_from_user_mode. If it turns out to be a redundant, it can be removed later.

Quoted 9 lines

I think it is redundant as of now. The TIF_SYSCALL_RET flag is set when error is set by the ptrace or seccomp, If the error value is set then the syscall_enter_from_user_mode_randomize_stack will return false. Hence the next check will become redundant.

I also see that TIF_SYSCALL_RET is also set when processing the ptrace syscall, Which can leave the flag set for next syscall execution. Which can again trigger the same issue.

I believe it is a pre-existing bug which can be fixed independent of this issue. Since merge request broke the userspace it is better we fix it right away and this pre-existing issue fix can be done subsequently.

No?

Quoted 24 lines

Regards,
Mukesh

Quoted 22 lines
  arch/powerpc/kernel/syscall.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/kernel/syscall.c +3 -1
index 4916c205c4bb..fbefe1927b10 100644
@@ -18,8 +18,10 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
  	long ret;
  	syscall_fn f;
 
-	if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0)))
+	if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0))) {
+		clear_thread_flag(TIF_SYSCALL_RET);
  		return syscall_get_error(current, regs);
+	}
 
  	if (unlikely(test_and_clear_thread_flag(TIF_SYSCALL_RET)))
  		return syscall_get_error(current, regs);
Signature · 1 line
2.47.3
#4 lore raw
Quoted 37 lines · Shrikanth Hegde
Quoted 24 lines · Mukesh Kumar Chaurasiya
Quoted 14 lines · Shrikanth Hegde

Shivaprasad reported a boot failure due to userspace processes crash on abort() from libc.so.6. It was bisected to merge request commit '3424d8c18a7d ("Merge tag 'core-entry-2026-08-17' of
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")'

Upon checking the merge, when syscall_enter_from_user_mode_randomize_stack fails, which could happen when a tracer like seccomp or ptrace intercepts and skips the syscall, the code returns to userspace immediately without clearing the intermediate flag which was set.

When the next syscall is made, it immediately aborts the valid syscall since the flag is still set. Hence clear the flag on occurrence of first failure.

Quoted 9 lines
Fixes 3424d8c18a7d ("Merge tag 'core-entry-2026-08-17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")

---
PS: I have kept the block below since earlier code was checking it regardless of result of syscall_enter_from_user_mode. If it turns out to be a redundant, it can be removed later.

Quoted 9 lines

I think it is redundant as of now. The TIF_SYSCALL_RET flag is set when error is set by the ptrace or seccomp, If the error value is set then the syscall_enter_from_user_mode_randomize_stack will return false. Hence the next check will become redundant.

I also see that TIF_SYSCALL_RET is also set when processing the ptrace syscall, Which can leave the flag set for next syscall execution. Which can again trigger the same issue.

Quoted 6 lines

I believe it is a pre-existing bug which can be fixed independent of this issue. Since merge request broke the userspace it is better we fix it right away and this pre-existing issue fix can be done subsequently.

No?

Agreed.
Sure we can send that as a separate fix.
With that,

Regards
Mukesh.

Quoted 23 lines
Quoted 22 lines

Regards,
Mukesh

Quoted 20 lines
  arch/powerpc/kernel/syscall.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/kernel/syscall.c +3 -1
index 4916c205c4bb..fbefe1927b10 100644
@@ -18,8 +18,10 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
  	long ret;
  	syscall_fn f;
-	if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0)))
+	if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0))) {
+		clear_thread_flag(TIF_SYSCALL_RET);
  		return syscall_get_error(current, regs);
+	}
  	if (unlikely(test_and_clear_thread_flag(TIF_SYSCALL_RET)))
  		return syscall_get_error(current, regs);
Signature · 1 line
2.47.3
Tested-by on v1 1/1
#5 lore raw
In reply to Shrikanth Hegde
Quoted 18 lines · Shrikanth Hegde

Shivaprasad reported a boot failure due to userspace processes crash on abort() from libc.so.6. It was bisected to merge request commit '3424d8c18a7d ("Merge tag 'core-entry-2026-08-17' of
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")'

Upon checking the merge, when syscall_enter_from_user_mode_randomize_stack fails, which could happen when a tracer like seccomp or ptrace intercepts and skips the syscall, the code returns to userspace immediately without clearing the intermediate flag which was set.

When the next syscall is made, it immediately aborts the valid syscall since the flag is still set. Hence clear the flag on occurrence of first failure.

Quoted 5 lines
Fixes 3424d8c18a7d ("Merge tag 'core-entry-2026-08-17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")

---

Regards,
Venkat.

Quoted 26 lines

PS: I have kept the block below since earlier code was checking it regardless of result of syscall_enter_from_user_mode. If it turns out to be a redundant, it can be removed later.

arch/powerpc/kernel/syscall.c | 4 +++-

1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/kernel/syscall.c +3 -1
index 4916c205c4bb..fbefe1927b10 100644
@@ -18,8 +18,10 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
 long ret;
 syscall_fn f;
 
- if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0)))
+ if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0))) {
+ clear_thread_flag(TIF_SYSCALL_RET);
 return syscall_get_error(current, regs);
+ }
 
 if (unlikely(test_and_clear_thread_flag(TIF_SYSCALL_RET)))
 return syscall_get_error(current, regs);
Signature · 1 line
2.47.3
maintainer Applied
#6 lore raw
In reply to Shrikanth Hegde
Quoted 11 lines · Shrikanth Hegde

Shivaprasad reported a boot failure due to userspace processes crash on abort() from libc.so.6. It was bisected to merge request commit '3424d8c18a7d ("Merge tag 'core-entry-2026-08-17' of
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")'

Upon checking the merge, when syscall_enter_from_user_mode_randomize_stack fails, which could happen when a tracer like seccomp or ptrace intercepts and skips the syscall, the code returns to userspace immediately without clearing the intermediate flag which was set.

[...]

Applied to powerpc/fixes.

[1/1] powerpc/entry: Clear TIF_SYSCALL_RET before syscall error return

      https://git.kernel.org/powerpc/c/2c1dde8a69a3a7d64425a6de0add6e289a5a402f

cheers