Files
linux/arch/riscv/include/asm
Ben Dooks 285a76bb2c riscv: evaluate put_user() arg before enabling user access
The <asm/uaccess.h> header has a problem with put_user(a, ptr) if
the 'a' is not a simple variable, such as a function. This can lead
to the compiler producing code as so:

1:	enable_user_access()
2:	evaluate 'a' into register 'r'
3:	put 'r' to 'ptr'
4:	disable_user_acess()

The issue is that 'a' is now being evaluated with the user memory
protections disabled. So we try and force the evaulation by assigning
'x' to __val at the start, and hoping the compiler barriers in
 enable_user_access() do the job of ordering step 2 before step 1.

This has shown up in a bug where 'a' sleeps and thus schedules out
and loses the SR_SUM flag. This isn't sufficient to fully fix, but
should reduce the window of opportunity. The first instance of this
we found is in scheudle_tail() where the code does:

$ less -N kernel/sched/core.c

4263  if (current->set_child_tid)
4264         put_user(task_pid_vnr(current), current->set_child_tid);

Here, the task_pid_vnr(current) is called within the block that has
enabled the user memory access. This can be made worse with KASAN
which makes task_pid_vnr() a rather large call with plenty of
opportunity to sleep.

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
Reported-by: syzbot+e74b94fe601ab9552d69@syzkaller.appspotmail.com
Suggested-by: Arnd Bergman <arnd@arndb.de>

--
Changes since v1:
- fixed formatting and updated the patch description with more info

Changes since v2:
- fixed commenting on __put_user() (schwab@linux-m68k.org)

Change since v3:
- fixed RFC in patch title. Should be ready to merge.

Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2021-04-01 21:37:04 -07:00
..
2021-01-14 15:09:11 -08:00
2019-11-17 15:17:39 -08:00
2020-03-31 11:28:30 -07:00
2021-02-18 23:18:06 -08:00
2020-10-02 14:31:03 -07:00
2020-10-02 14:31:03 -07:00
2021-03-09 20:46:00 -08:00
2021-02-22 18:44:53 -08:00
2020-05-18 11:38:10 -07:00
2021-01-14 15:09:06 -08:00
2021-02-18 23:18:06 -08:00
2021-02-18 23:18:06 -08:00
2021-01-14 15:09:06 -08:00
2020-06-03 20:09:50 -07:00
2021-03-09 19:23:11 -08:00
2021-01-07 19:00:50 -08:00
2020-12-10 17:27:54 -08:00
2021-01-14 15:09:08 -08:00
2019-11-17 15:17:39 -08:00
2021-01-14 15:09:08 -08:00