linux/arch
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
..
alpha io_uring-worker.v3-2021-02-25 2021-02-27 08:29:02 -08:00
arc arch: setup PF_IO_WORKER threads like PF_KTHREAD 2021-02-21 17:25:22 -07:00
arm ARM: SoC fixes for v5.12 2021-03-26 11:19:38 -07:00
arm64 ARM: SoC fixes for v5.12 2021-03-26 11:19:38 -07:00
csky ftrace: Fix spelling mistake "disabed" -> "disabled" 2021-03-16 21:19:40 -07:00
h8300 arch: setup PF_IO_WORKER threads like PF_KTHREAD 2021-02-21 17:25:22 -07:00
hexagon io_uring-worker.v3-2021-02-25 2021-02-27 08:29:02 -08:00
ia64 ia64: fix format strings for err_inject 2021-03-25 09:22:55 -07:00
m68k m68k: Fix virt_addr_valid() W=1 compiler warnings 2021-03-06 14:15:07 +01:00
microblaze io_uring-worker.v3-2021-02-25 2021-02-27 08:29:02 -08:00
mips MIPS: vmlinux.lds.S: Fix appended dtb not properly aligned 2021-03-16 22:53:08 +01:00
nds32 io_uring-worker.v3-2021-02-25 2021-02-27 08:29:02 -08:00
nios2 io_uring-worker.v3-2021-02-25 2021-02-27 08:29:02 -08:00
openrisc io_uring-worker.v3-2021-02-25 2021-02-27 08:29:02 -08:00
parisc arch/parisc/kernel: remove duplicate include in ptrace 2021-03-04 09:12:29 +01:00
powerpc powerpc: Force inlining of cpu_has_feature() to avoid build failure 2021-03-14 20:32:24 +11:00
riscv riscv: evaluate put_user() arg before enabling user access 2021-04-01 21:37:04 -07:00
s390 s390/pci: fix leak of PCI device structure 2021-03-15 19:10:56 +01:00
sh io_uring-worker.v3-2021-02-25 2021-02-27 08:29:02 -08:00
sparc Merge git://git.kernel.org:/pub/scm/linux/kernel/git/davem/sparc 2021-03-09 17:08:41 -08:00
um io_uring-worker.v3-2021-02-25 2021-02-27 08:29:02 -08:00
x86 Two fixes: 2021-03-28 12:19:16 -07:00
xtensa io_uring-worker.v3-2021-02-25 2021-02-27 08:29:02 -08:00
.gitignore
Kconfig kbuild: remove LLVM=1 test from HAS_LTO_CLANG 2021-03-11 14:52:55 +09:00