RE: [PATCH] microblaze: remove CONFIG_SET_FS

From: David Laight
Date: Thu Feb 10 2022 - 04:36:47 EST


From: Arnd
> Sent: 09 February 2022 14:49
>
> 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.
...
> static inline int access_ok(const void __user *addr, unsigned long size)
> {
> if (!size)
> goto ok;
>
> - 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)