Andrii Nakryiko 17ed6448b0 fs: fix NULL dereference due to data race in prepend_path()
[ Upstream commit 09cad07547445bf3a41683e4d3abcd154c123ef5 ]

Fix data race in prepend_path() with re-reading mnt->mnt_ns twice
without holding the lock.

is_mounted() does check for NULL, but is_anon_ns(mnt->mnt_ns) might
re-read the pointer again which could be NULL already, if in between
reads one of kern_unmount()/kern_unmount_array()/umount_tree() sets
mnt->mnt_ns to NULL.

This is seen in production with the following stack trace:

  BUG: kernel NULL pointer dereference, address: 0000000000000048
  ...
  RIP: 0010:prepend_path.isra.4+0x1ce/0x2e0
  Call Trace:
    d_path+0xe6/0x150
    proc_pid_readlink+0x8f/0x100
    vfs_readlink+0xf8/0x110
    do_readlinkat+0xfd/0x120
    __x64_sys_readlinkat+0x1a/0x20
    do_syscall_64+0x42/0x110
    entry_SYSCALL_64_after_hwframe+0x44/0xa9

Fixes: f2683bd8d5bd ("[PATCH] fix d_absolute_path() interplay with fsmount()")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-10-29 09:57:45 +01:00
..
2020-08-19 08:16:24 +02:00
2019-09-19 09:42:37 -07:00
2020-08-19 08:16:21 +02:00
2019-09-19 09:42:37 -07:00
2020-08-26 10:40:56 +02:00
2019-09-19 09:42:37 -07:00
2019-07-03 17:52:09 -04:00
2020-10-17 10:11:23 +02:00
2020-06-17 16:40:24 +02:00
2020-09-03 11:26:57 +02:00
2020-03-05 16:43:36 +01:00
2020-10-01 13:17:19 +02:00
2019-08-07 21:51:47 -04:00
2020-03-25 08:25:58 +01:00
2019-12-17 19:55:30 +01:00
2019-09-18 16:59:14 -07:00
2019-09-18 16:59:14 -07:00
2020-05-06 08:15:15 +02:00
2019-08-01 20:51:23 +02:00