microblaze: remove CONFIG_SET_FS
PATCH 1/1 microblaze: remove CONFIG_SET_FS
From: Arnd Bergmann <[email protected]>
Remove the address space override API set_fs(). The microblaze user address space is now limited to TASK_SIZE.
To support this we implement and wire in __get_kernel_nofault and __set_kernel_nofault.
The function user_addr_max is removed as there is a default definition provided when CONFIG_SET_FS is not used.
--- arch/microblaze/Kconfig | 1 - arch/microblaze/include/asm/thread_info.h | 6 --- arch/microblaze/include/asm/uaccess.h | 56 ++++++++++------------- arch/microblaze/kernel/asm-offsets.c | 1 - 4 files changed, 25 insertions(+), 39 deletions(-)
arch/microblaze/Kconfig +0 -1
@@ -42,7 +42,6 @@ config MICROBLAZE select CPU_NO_EFFICIENT_FFS select MMU_GATHER_NO_RANGE select SPARSE_IRQ - select SET_FS select ZONE_DMA select TRACE_IRQFLAGS_SUPPORT
arch/microblaze/include/asm/thread_info.h +0 -6
@@ -56,17 +56,12 @@ struct cpu_context {__u32 fsr; }; -typedef struct { -unsigned long seg; -}mm_segment_t ; -struct thread_info {struct task_struct *task;/* main task structure */ unsigned long flags;/* low level flags */ unsigned long status;/* thread-synchronous flags */ __u32 cpu;/* current CPU */ __s32 preempt_count;/* 0 => preemptable,< 0 => BUG*/ -mm_segment_t addr_limit;/* thread address space */ struct cpu_context cpu_context; };
@@ -80,7 +75,6 @@ struct thread_info { .flags = 0, \ .cpu = 0, \ .preempt_count = INIT_PREEMPT_COUNT, \ - .addr_limit = KERNEL_DS, \ }/* how to get the thread information struct from C */
arch/microblaze/include/asm/uaccess.h +25 -31
76 lines not on this page · raw message
arch/microblaze/kernel/asm-offsets.c +0 -1
@@ -86,7 +86,6 @@ int main(int argc, char *argv[])/* struct thread_info */ DEFINE (TI_TASK , offsetof(struct thread_info , task));DEFINE (TI_FLAGS , offsetof(struct thread_info , flags)); -DEFINE (TI_ADDR_LIMIT , offsetof(struct thread_info , addr_limit));DEFINE (TI_CPU_CONTEXT , offsetof(struct thread_info , cpu_context));DEFINE (TI_PREEMPT_COUNT , offsetof(struct thread_info , preempt_count));BLANK ();
Signature · 1 line
2.29.2
From: Arnd
Quoted 10 lines
Sent: 09 February 2022 14:49
Remove the address space override API
set_fs(). The microblaze user address space is now limited toTASK_SIZE.To support this we implement and wire in
__get_kernel_nofaultand__set_kernel_nofault.The function
user_addr_maxis removed as there is a default definition provided whenCONFIG_SET_FSis not used.
...
Quoted 5 lines
static inline int
access_ok(const void __user *addr, unsigned long size){arch/microblaze/include/asm/uaccess.h +0
-0if (!size) goto ok;
arch/microblaze/include/asm/uaccess.h line 28
Quoted 10 lines
arch/microblaze/include/asm/uaccess.h +4
-5-if ((get_fs ().seg < ((unsigned long )addr)) || - (get_fs ().seg < ((unsigned long )addr + size -1 ))) { -pr_devel ("ACCESS fail at 0x%08x (size 0x%x), seg 0x%08x\n" , - (__force u32 )addr, (u32 )size, - (u32 )get_fs ().seg); +if ((((unsigned long )addr) >TASK_SIZE ) || + (((unsigned long )addr + size -1 ) >TASK_SIZE )) { +pr_devel ("ACCESS fail at 0x%08x (size 0x%x)" , + (__force u32 )addr, (u32 )size);return 0 ;
Isn't that the wrong check?
If 'size' is big 'addr + size' can wrap.
It needs to be (addr >= TASK_SIZE || size > TASK_SIZE - addr)
Which is pretty much a generic version. Although typical 64bit architectures can use the faster:
((addr | size) >> 62) David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 27 lines · David Laight
From: Arnd Sent: 09 February 2022 14:49
Quoted 9 lines
Remove the address space override API
set_fs(). The microblaze user address space is now limited toTASK_SIZE.To support this we implement and wire in
__get_kernel_nofaultand__set_kernel_nofault.The function
user_addr_maxis removed as there is a default definition provided whenCONFIG_SET_FSis not used....
Quoted 5 lines
static inline int
access_ok(const void __user *addr, unsigned long size){ if (!size) goto ok;arch/microblaze/include/asm/uaccess.h line 28
Quoted 10 lines
arch/microblaze/include/asm/uaccess.h +4
-5-if ((get_fs ().seg < ((unsigned long )addr)) || - (get_fs ().seg < ((unsigned long )addr + size -1 ))) { -pr_devel ("ACCESS fail at 0x%08x (size 0x%x), seg 0x%08x\n" , - (__force u32 )addr, (u32 )size, - (u32 )get_fs ().seg); +if ((((unsigned long )addr) >TASK_SIZE ) || + (((unsigned long )addr + size -1 ) >TASK_SIZE )) { +pr_devel ("ACCESS fail at 0x%08x (size 0x%x)" , + (__force u32 )addr, (u32 )size);return 0 ;
Quoted 2 lines
Isn't that the wrong check?
If 'size' is big 'addr + size' can wrap.
Ah right, that seems dangerous, and we should probably fix that first, with a backport to stable kernels before my patch. I see the same bug on csky and hexagon:
static inline int __access_ok(unsigned long addr, unsigned long size)
{
unsigned long limit = current_thread_info()->addr_limit.seg;
return ((addr < limit) && ((addr + size) < limit));
}#define __access_ok(addr, size) \
((get_fs().seg == KERNEL_DS.seg) || \
(((unsigned long)addr < get_fs().seg) && \
(unsigned long)size < (get_fs().seg - (unsigned long)addr)))ia64 and sparc skip the size check entirely but rely on an unmapped page at the beginning of the kernel address range, which avoids this problem but may also be dangerous.
m68k-coldfire-mmu has a comment about needing a check, but tests for neither address nor size.
Quoted 5 lines
It needs to be (addr >=
TASK_SIZE|| size >TASK_SIZE- addr)Which is pretty much a generic version. Although typical 64bit architectures can use the faster:
((addr | size) >> 62)
I think this is the best version, and it's already widely used:
static inline int __range_ok(unsigned long addr, unsigned long size)
{
return size <= TASK_SIZE && addr <= (TASK_SIZE - size);
}since 'size' is usually constant, so this turns into a single comparison against a compile-time constant.
Arnd
From: Arnd Bergmann
Quoted 1 line
Sent: 10 February 2022 13:30
...
Quoted 4 lines
#define __access_ok(addr, size) \
((get_fs().seg == KERNEL_DS.seg) || \
(((unsigned long)addr < get_fs().seg) && \
(unsigned long)size < (get_fs().seg - (unsigned long)addr)))That one is strange.
Seems to be optimised for kernel accesses!
Quoted 3 lines
ia64 and sparc skip the size check entirely but rely on an unmapped page at the beginning of the kernel address range, which avoids this problem but may also be dangerous.
An unmapped page requires that the kernel do sequential accesses (or, at least, not big offset) - which is normally fine. Especially for 64bit where there is plenty of address space. I guess it could be problematic for 32bit if you can/want to use 'big pages' for the kernel addresses.
Losing a single (typically) 4k page isn't a problem.
Certainly not mapping the page at TASK_SIZE is a good safety check. Actually, setting TASK_SIZE to 0xc0000000 - PAGE_SIZE and never mapping the last user page has the same effect.
Except I bet the ldso has to go there :-(
Not to mention the instruction sets where loading the constant would then be two instructions.
...
Quoted 4 lines
Quoted 2 lines
Although typical 64bit architectures can use the faster:
((addr | size) >> 62)I think this is the best version, and it's already widely used:
I just did a quick check, both clang and gcc optimise out constant values for 'size'.
Quoted 7 lines
static inline int
__range_ok(unsigned long addr, unsigned long size){ return size <= TASK_SIZE && addr <= (TASK_SIZE - size); }since 'size' is usually constant, so this turns into a single comparison against a compile-time constant.
Hmmm... maybe there should be a comment that it is the same as the more obvious:
(addr <= TASK_SIZE && addr <= TASK_SIZE - size)
but is better for constant size.
(Provided TASK_SIZE is a constant.)
I'm sure Linus was 'unhappy' about checking against 2^63 for 32bit processes on a 64bit kernel.
Hmmm compat code that has 32bit addr/size needn't even call access_ok() - it can never access kernel memory at all.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 13 lines · David Laight
From: Arnd Bergmann Sent: 10 February 2022 13:30
Quoted 7 lines
static inline int
__range_ok(unsigned long addr, unsigned long size){ return size <= TASK_SIZE && addr <= (TASK_SIZE - size); }since 'size' is usually constant, so this turns into a single comparison against a compile-time constant.
Hmmm... maybe there should be a comment that it is the same as the more obvious:
(addr <= TASK_SIZE && addr <= TASK_SIZE - size)
Quoted 8 lines
but is better for constant size.
(ProvidedTASK_SIZEis a constant.)I'm sure Linus was 'unhappy' about checking against 2^63 for 32bit processes on a 64bit kernel.
Hmmm compat code that has 32bit addr/size needn't even call
access_ok()- it can never access kernel memory at all.
I suppose the generic function should compare against TASK_SIZE_MAX or user_addr_max() then, to make it a constant while TASK_SIZE potentially depends on compat mode.
Arnd
Quoted 6 lines · David Laight
From: Arnd Bergmann
Quoted 5 lines
static inline int
__range_ok(unsigned long addr, unsigned long size){ return size <= TASK_SIZE && addr <= (TASK_SIZE - size); }
Quoted 8 lines
Quoted 2 lines
since 'size' is usually constant, so this turns into a single comparison against a compile-time constant.
Hmmm... maybe there should be a comment that it is the same as the more obvious:
(addr <= TASK_SIZE && addr <= TASK_SIZE - size)but is better for constant size.
(ProvidedTASK_SIZEis a constant.)
Ah, this makes sense that. I might as well revert the OpenRISC patch for this. Though, we shall move to the generic version in the end.
With ideal compare:
-rwxrwxr-x. 1 shorne shorne 6011932 Feb 9 17:57 vmlinux
With comparing (size <= TASK_SIZE && addr <= TASK_SIZE - size):
-rwxrwxr-x. 1 shorne shorne 6003556 Feb 11 07:18 vmlinux
-Stafford