Skip to contentSkip to conversation

entry: remove empty addr_limit_user_check()

PATCH Applied Mark Rutland 2 participants 2 messages Aug 21, 2023 – Aug 23, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 entry: remove empty addr_limit_user_check()

Back when set_fs() was a generic API for altering the address limit, addr_limit_user_check() was a safety measure to prevent userspace being able to issue syscalls with an unbound limit.

With the the removal of set_fs() as a generic API, the last user of addr_limit_user_check() was removed in commit:

b5a5a01d8e9a44ec ("arm64: uaccess: remove addr_limit_user_check()")

... as since that commit, no architecture defines TIF_FSCHECK, and hence addr_limit_user_check() always expands to nothing.

Remove addr_limit_user_check(), updating the comment in exit_to_user_mode_prepare() to no longer refer to it. At the same time, the comment is reworded to be a little more generic so as to cover kmap_assert_nomap() in addition to lockdep_sys_exit().

There should be no functional change as a result of this patch.

Cc Andy Lutomirski <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 include/linux/syscalls.h | 16 ----------------
 kernel/entry/common.c    |  3 +--
 2 files changed, 1 insertion(+), 18 deletions(-)
include/linux/syscalls.h +0 -16
index 03e3d0121d5e3..c4b9b66b0d053 100644
@@ -283,22 +283,6 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event)
 #define SYSCALL32_DEFINE6 SYSCALL_DEFINE6
 #endif
 
-/*
- * Called before coming back to user-mode. Returning to user-mode with an
- * address limit different than USER_DS can allow to overwrite kernel memory.
- */
-static inline void addr_limit_user_check(void)
-{
-#ifdef TIF_FSCHECK
-	if (!test_thread_flag(TIF_FSCHECK))
-		return;
-#endif
-
-#ifdef TIF_FSCHECK
-	clear_thread_flag(TIF_FSCHECK);
-#endif
-}
-
 /*
  * These syscall function prototypes are kept in the same order as
  * include/uapi/asm-generic/unistd.h. Architecture specific entries go below,
kernel/entry/common.c +1 -2
index be61332c66b54..d7ee4bc3f2ba3 100644
@@ -205,8 +205,7 @@ static void exit_to_user_mode_prepare(struct pt_regs *regs)
 
 	arch_exit_to_user_mode_prepare(regs, ti_work);
 
-	/* Ensure that the address limit is intact and no locks are held */
-	addr_limit_user_check();
+	/* Ensure that kernel state is sane for a return to userspace */
 	kmap_assert_nomap();
 	lockdep_assert_irqs_disabled();
 	lockdep_sys_exit();
Signature · 1 line
2.30.2
merge bot Applied
#1 lore raw

[tip: core/entry] entry: Remove empty addr_limit_user_check()

The following commit has been merged into the core/entry branch of tip:

The following commit has been merged into the core/entry branch of tip:

Commit-ID:     1dfe3a5a7cefbe2162cecb759f3933baea22c393
Gitweb:        https://git.kernel.org/tip/1dfe3a5a7cefbe2162cecb759f3933baea22c393
Author:        Mark Rutland <[email protected]>
AuthorDate:    Mon, 21 Aug 2023 17:35:26 +01:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Wed, 23 Aug 2023 10:32:39 +02:00

entry: Remove empty addr_limit_user_check()

Back when set_fs() was a generic API for altering the address limit, addr_limit_user_check() was a safety measure to prevent userspace being able to issue syscalls with an unbound limit.

With the the removal of set_fs() as a generic API, the last user of addr_limit_user_check() was removed in commit:

b5a5a01d8e9a44ec ("arm64: uaccess: remove addr_limit_user_check()")

... as since that commit, no architecture defines TIF_FSCHECK, and hence addr_limit_user_check() always expands to nothing.

Remove addr_limit_user_check(), updating the comment in exit_to_user_mode_prepare() to no longer refer to it. At the same time, the comment is reworded to be a little more generic so as to cover kmap_assert_nomap() in addition to lockdep_sys_exit().

No functional change.

---
 include/linux/syscalls.h | 16 ----------------
 kernel/entry/common.c    |  3 +--
 2 files changed, 1 insertion(+), 18 deletions(-)
include/linux/syscalls.h +0 -16
index 03e3d01..c4b9b66 100644
@@ -284,22 +284,6 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event)
 #endif
 
 /*
- * Called before coming back to user-mode. Returning to user-mode with an
- * address limit different than USER_DS can allow to overwrite kernel memory.
- */
-static inline void addr_limit_user_check(void)
-{
-#ifdef TIF_FSCHECK
-	if (!test_thread_flag(TIF_FSCHECK))
-		return;
-#endif
-
-#ifdef TIF_FSCHECK
-	clear_thread_flag(TIF_FSCHECK);
-#endif
-}
-
-/*
  * These syscall function prototypes are kept in the same order as
  * include/uapi/asm-generic/unistd.h. Architecture specific entries go below,
  * followed by deprecated or obsolete system calls.
kernel/entry/common.c +1 -2
index be61332..d7ee4bc 100644
@@ -205,8 +205,7 @@ static void exit_to_user_mode_prepare(struct pt_regs *regs)
 
 	arch_exit_to_user_mode_prepare(regs, ti_work);
 
-	/* Ensure that the address limit is intact and no locks are held */
-	addr_limit_user_check();
+	/* Ensure that kernel state is sane for a return to userspace */
 	kmap_assert_nomap();
 	lockdep_assert_irqs_disabled();
 	lockdep_sys_exit();