Skip to content

Commit 8ac6f5d

Browse files
arndbRussell King (Oracle)
authored andcommitted
ARM: 9113/1: uaccess: remove set_fs() implementation
There are no remaining callers of set_fs(), so just remove it along with all associated code that operates on thread_info->addr_limit. There are still further optimizations that can be done: - In get_user(), the address check could be moved entirely into the out of line code, rather than passing a constant as an argument, - I assume the DACR handling can be simplified as we now only change it during user access when CONFIG_CPU_SW_DOMAIN_PAN is set, but not during set_fs(). Acked-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
1 parent 2df4c9a commit 8ac6f5d

File tree

11 files changed

+7
-86
lines changed

11 files changed

+7
-86
lines changed

arch/arm/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ config ARM
126126
select PCI_SYSCALL if PCI
127127
select PERF_USE_VMALLOC
128128
select RTC_LIB
129-
select SET_FS
130129
select SYS_SUPPORTS_APM_EMULATION
131130
# Above selects are sorted alphabetically; please add new ones
132131
# according to that. Thanks.

arch/arm/include/asm/ptrace.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ struct pt_regs {
1919
struct svc_pt_regs {
2020
struct pt_regs regs;
2121
u32 dacr;
22-
u32 addr_limit;
2322
};
2423

2524
#define to_svc_pt_regs(r) container_of(r, struct svc_pt_regs, regs)

arch/arm/include/asm/thread_info.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ struct task_struct;
3131

3232
#include <asm/types.h>
3333

34-
typedef unsigned long mm_segment_t;
35-
3634
struct cpu_context_save {
3735
__u32 r4;
3836
__u32 r5;
@@ -54,7 +52,6 @@ struct cpu_context_save {
5452
struct thread_info {
5553
unsigned long flags; /* low level flags */
5654
int preempt_count; /* 0 => preemptable, <0 => bug */
57-
mm_segment_t addr_limit; /* address limit */
5855
struct task_struct *task; /* main task structure */
5956
__u32 cpu; /* cpu */
6057
__u32 cpu_domain; /* cpu domain */
@@ -80,7 +77,6 @@ struct thread_info {
8077
.task = &tsk, \
8178
.flags = 0, \
8279
.preempt_count = INIT_PREEMPT_COUNT, \
83-
.addr_limit = KERNEL_DS, \
8480
}
8581

8682
/*

arch/arm/include/asm/uaccess-asm.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,8 @@
8484
* if \disable is set.
8585
*/
8686
.macro uaccess_entry, tsk, tmp0, tmp1, tmp2, disable
87-
ldr \tmp1, [\tsk, #TI_ADDR_LIMIT]
88-
ldr \tmp2, =TASK_SIZE
89-
str \tmp2, [\tsk, #TI_ADDR_LIMIT]
9087
DACR( mrc p15, 0, \tmp0, c3, c0, 0)
9188
DACR( str \tmp0, [sp, #SVC_DACR])
92-
str \tmp1, [sp, #SVC_ADDR_LIMIT]
9389
.if \disable && IS_ENABLED(CONFIG_CPU_SW_DOMAIN_PAN)
9490
/* kernel=client, user=no access */
9591
mov \tmp2, #DACR_UACCESS_DISABLE
@@ -106,9 +102,7 @@
106102

107103
/* Restore the user access state previously saved by uaccess_entry */
108104
.macro uaccess_exit, tsk, tmp0, tmp1
109-
ldr \tmp1, [sp, #SVC_ADDR_LIMIT]
110105
DACR( ldr \tmp0, [sp, #SVC_DACR])
111-
str \tmp1, [\tsk, #TI_ADDR_LIMIT]
112106
DACR( mcr p15, 0, \tmp0, c3, c0, 0)
113107
.endm
114108

arch/arm/include/asm/uaccess.h

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,32 +52,8 @@ static __always_inline void uaccess_restore(unsigned int flags)
5252
extern int __get_user_bad(void);
5353
extern int __put_user_bad(void);
5454

55-
/*
56-
* Note that this is actually 0x1,0000,0000
57-
*/
58-
#define KERNEL_DS 0x00000000
59-
6055
#ifdef CONFIG_MMU
6156

62-
#define USER_DS TASK_SIZE
63-
#define get_fs() (current_thread_info()->addr_limit)
64-
65-
static inline void set_fs(mm_segment_t fs)
66-
{
67-
current_thread_info()->addr_limit = fs;
68-
69-
/*
70-
* Prevent a mispredicted conditional call to set_fs from forwarding
71-
* the wrong address limit to access_ok under speculation.
72-
*/
73-
dsb(nsh);
74-
isb();
75-
76-
modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
77-
}
78-
79-
#define uaccess_kernel() (get_fs() == KERNEL_DS)
80-
8157
/*
8258
* We use 33-bit arithmetic here. Success returns zero, failure returns
8359
* addr_limit. We take advantage that addr_limit will be zero for KERNEL_DS,
@@ -89,7 +65,7 @@ static inline void set_fs(mm_segment_t fs)
8965
__asm__(".syntax unified\n" \
9066
"adds %1, %2, %3; sbcscc %1, %1, %0; movcc %0, #0" \
9167
: "=&r" (flag), "=&r" (roksum) \
92-
: "r" (addr), "Ir" (size), "0" (current_thread_info()->addr_limit) \
68+
: "r" (addr), "Ir" (size), "0" (TASK_SIZE) \
9369
: "cc"); \
9470
flag; })
9571

@@ -120,7 +96,7 @@ static inline void __user *__uaccess_mask_range_ptr(const void __user *ptr,
12096
" subshs %1, %1, %2\n"
12197
" movlo %0, #0\n"
12298
: "+r" (safe_ptr), "=&r" (tmp)
123-
: "r" (size), "r" (current_thread_info()->addr_limit)
99+
: "r" (size), "r" (TASK_SIZE)
124100
: "cc");
125101

126102
csdb();
@@ -194,7 +170,7 @@ extern int __get_user_64t_4(void *);
194170

195171
#define __get_user_check(x, p) \
196172
({ \
197-
unsigned long __limit = current_thread_info()->addr_limit - 1; \
173+
unsigned long __limit = TASK_SIZE - 1; \
198174
register typeof(*(p)) __user *__p asm("r0") = (p); \
199175
register __inttype(x) __r2 asm("r2"); \
200176
register unsigned long __l asm("r1") = __limit; \
@@ -245,7 +221,7 @@ extern int __put_user_8(void *, unsigned long long);
245221

246222
#define __put_user_check(__pu_val, __ptr, __err, __s) \
247223
({ \
248-
unsigned long __limit = current_thread_info()->addr_limit - 1; \
224+
unsigned long __limit = TASK_SIZE - 1; \
249225
register typeof(__pu_val) __r2 asm("r2") = __pu_val; \
250226
register const void __user *__p asm("r0") = __ptr; \
251227
register unsigned long __l asm("r1") = __limit; \
@@ -262,19 +238,8 @@ extern int __put_user_8(void *, unsigned long long);
262238

263239
#else /* CONFIG_MMU */
264240

265-
/*
266-
* uClinux has only one addr space, so has simplified address limits.
267-
*/
268-
#define USER_DS KERNEL_DS
269-
270-
#define uaccess_kernel() (true)
271241
#define __addr_ok(addr) ((void)(addr), 1)
272242
#define __range_ok(addr, size) ((void)(addr), 0)
273-
#define get_fs() (KERNEL_DS)
274-
275-
static inline void set_fs(mm_segment_t fs)
276-
{
277-
}
278243

279244
#define get_user(x, p) __get_user(x, p)
280245
#define __put_user_check __put_user_nocheck
@@ -283,9 +248,6 @@ static inline void set_fs(mm_segment_t fs)
283248

284249
#define access_ok(addr, size) (__range_ok(addr, size) == 0)
285250

286-
#define user_addr_max() \
287-
(uaccess_kernel() ? ~0UL : get_fs())
288-
289251
#ifdef CONFIG_CPU_SPECTRE
290252
/*
291253
* When mitigating Spectre variant 1, it is not worth fixing the non-

arch/arm/kernel/asm-offsets.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ int main(void)
4343
BLANK();
4444
DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
4545
DEFINE(TI_PREEMPT, offsetof(struct thread_info, preempt_count));
46-
DEFINE(TI_ADDR_LIMIT, offsetof(struct thread_info, addr_limit));
4746
DEFINE(TI_TASK, offsetof(struct thread_info, task));
4847
DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
4948
DEFINE(TI_CPU_DOMAIN, offsetof(struct thread_info, cpu_domain));
@@ -92,7 +91,6 @@ int main(void)
9291
DEFINE(S_OLD_R0, offsetof(struct pt_regs, ARM_ORIG_r0));
9392
DEFINE(PT_REGS_SIZE, sizeof(struct pt_regs));
9493
DEFINE(SVC_DACR, offsetof(struct svc_pt_regs, dacr));
95-
DEFINE(SVC_ADDR_LIMIT, offsetof(struct svc_pt_regs, addr_limit));
9694
DEFINE(SVC_REGS_SIZE, sizeof(struct svc_pt_regs));
9795
BLANK();
9896
DEFINE(SIGFRAME_RC3_OFFSET, offsetof(struct sigframe, retcode[3]));

arch/arm/kernel/entry-common.S

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ __ret_fast_syscall:
4949
UNWIND(.fnstart )
5050
UNWIND(.cantunwind )
5151
disable_irq_notrace @ disable interrupts
52-
ldr r2, [tsk, #TI_ADDR_LIMIT]
53-
ldr r1, =TASK_SIZE
54-
cmp r2, r1
55-
blne addr_limit_check_failed
5652
ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing
5753
movs r1, r1, lsl #16
5854
bne fast_work_pending
@@ -87,10 +83,6 @@ __ret_fast_syscall:
8783
bl do_rseq_syscall
8884
#endif
8985
disable_irq_notrace @ disable interrupts
90-
ldr r2, [tsk, #TI_ADDR_LIMIT]
91-
ldr r1, =TASK_SIZE
92-
cmp r2, r1
93-
blne addr_limit_check_failed
9486
ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing
9587
movs r1, r1, lsl #16
9688
beq no_work_pending
@@ -129,10 +121,6 @@ ret_slow_syscall:
129121
#endif
130122
disable_irq_notrace @ disable interrupts
131123
ENTRY(ret_to_user_from_irq)
132-
ldr r2, [tsk, #TI_ADDR_LIMIT]
133-
ldr r1, =TASK_SIZE
134-
cmp r2, r1
135-
blne addr_limit_check_failed
136124
ldr r1, [tsk, #TI_FLAGS]
137125
movs r1, r1, lsl #16
138126
bne slow_work_pending

arch/arm/kernel/process.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void __show_regs(struct pt_regs *regs)
108108
unsigned long flags;
109109
char buf[64];
110110
#ifndef CONFIG_CPU_V7M
111-
unsigned int domain, fs;
111+
unsigned int domain;
112112
#ifdef CONFIG_CPU_SW_DOMAIN_PAN
113113
/*
114114
* Get the domain register for the parent context. In user
@@ -117,14 +117,11 @@ void __show_regs(struct pt_regs *regs)
117117
*/
118118
if (user_mode(regs)) {
119119
domain = DACR_UACCESS_ENABLE;
120-
fs = get_fs();
121120
} else {
122121
domain = to_svc_pt_regs(regs)->dacr;
123-
fs = to_svc_pt_regs(regs)->addr_limit;
124122
}
125123
#else
126124
domain = get_domain();
127-
fs = get_fs();
128125
#endif
129126
#endif
130127

@@ -160,8 +157,6 @@ void __show_regs(struct pt_regs *regs)
160157
if ((domain & domain_mask(DOMAIN_USER)) ==
161158
domain_val(DOMAIN_USER, DOMAIN_NOACCESS))
162159
segment = "none";
163-
else if (fs == KERNEL_DS)
164-
segment = "kernel";
165160
else
166161
segment = "user";
167162

arch/arm/kernel/signal.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -711,14 +711,6 @@ struct page *get_signal_page(void)
711711
return page;
712712
}
713713

714-
/* Defer to generic check */
715-
asmlinkage void addr_limit_check_failed(void)
716-
{
717-
#ifdef CONFIG_MMU
718-
addr_limit_user_check();
719-
#endif
720-
}
721-
722714
#ifdef CONFIG_DEBUG_RSEQ
723715
asmlinkage void do_rseq_syscall(struct pt_regs *regs)
724716
{

arch/arm/lib/copy_from_user.S

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@
109109

110110
ENTRY(arm_copy_from_user)
111111
#ifdef CONFIG_CPU_SPECTRE
112-
get_thread_info r3
113-
ldr r3, [r3, #TI_ADDR_LIMIT]
112+
ldr r3, =TASK_SIZE
114113
uaccess_mask_range_ptr r1, r2, r3, ip
115114
#endif
116115

0 commit comments

Comments
 (0)