vdso: fix NULL deference in vdso_join_timens() when vfork
PATCH 1/1 vdso: fix NULL deference in vdso_join_timens() when vfork
Testing tools/testing/selftests/timens/vfork_exec.c got below kernel log:
[ 6.838454] Unable to handle kernel access to user memory without uaccess routines at virtual address 0000000000000020 [ 6.842255] Oops [#1] [ 6.842871] Modules linked in: [ 6.844249] CPU: 1 PID: 64 Comm: vfork_exec Not tainted 6.0.0-rc3-rt15+ #8 [ 6.845861] Hardware name: riscv-virtio,qemu (DT) [ 6.848009] epc : vdso_join_timens+0xd2/0x110 [ 6.850097] ra : vdso_join_timens+0xd2/0x110 [ 6.851164] epc : ffffffff8000635c ra : ffffffff8000635c sp : ff6000000181fbf0 [ 6.852562] gp : ffffffff80cff648 tp : ff60000000fdb700 t0 : 3030303030303030 [ 6.853852] t1 : 0000000000000030 t2 : 3030303030303030 s0 : ff6000000181fc40 [ 6.854984] s1 : ff60000001e6c000 a0 : 0000000000000010 a1 : ffffffff8005654c [ 6.856221] a2 : 00000000ffffefff a3 : 0000000000000000 a4 : 0000000000000000 [ 6.858114] a5 : 0000000000000000 a6 : 0000000000000008 a7 : 0000000000000038 [ 6.859484] s2 : ff60000001e6c068 s3 : ff6000000108abb0 s4 : 0000000000000000 [ 6.860751] s5 : 0000000000001000 s6 : ffffffff8089dc40 s7 : ffffffff8089dc38 [ 6.862029] s8 : ffffffff8089dc30 s9 : ff60000000fdbe38 s10: 000000000000005e [ 6.863304] s11: ffffffff80cc3510 t3 : ffffffff80d1112f t4 : ffffffff80d1112f [ 6.864565] t5 : ffffffff80d11130 t6 : ff6000000181fa00 [ 6.865561] status: 0000000000000120 badaddr: 0000000000000020 cause: 000000000000000d [ 6.868046] [<ffffffff8008dc94>] timens_commit+0x38/0x11a [ 6.869089] [<ffffffff8008dde8>] timens_on_fork+0x72/0xb4 [ 6.870055] [<ffffffff80190096>] begin_new_exec+0x3c6/0x9f0 [ 6.871231] [<ffffffff801d826c>] load_elf_binary+0x628/0x1214 [ 6.872304] [<ffffffff8018ee7a>] bprm_execve+0x1f2/0x4e4 [ 6.873243] [<ffffffff8018f90c>] do_execveat_common+0x16e/0x1ee [ 6.874258] [<ffffffff8018f9c8>] sys_execve+0x3c/0x48 [ 6.875162] [<ffffffff80003556>] ret_from_syscall+0x0/0x2 [ 6.877484] ---[ end trace 0000000000000000 ]---
This is due to the mm->context.vdso_info is NULL in vfork case. From another side, mm->context.vdso_info either points to vdso info for RV64 or vdso info for compat, there's no need to bloat riscv's mm_context_t, we can handle the difference when setup the additional page for vdso.
--- arch/riscv/include/asm/mmu.h | 1 - arch/riscv/kernel/vdso.c | 177 +++++++++++++++++++---------------- 2 files changed, 94 insertions(+), 84 deletions(-)
arch/riscv/include/asm/mmu.h +0 -1
@@ -16,7 +16,6 @@ typedef struct {atomic_long_t id;#endif void *vdso; -void *vdso_info;#ifdef CONFIG_SMP /* A local icache flush is needed before user execution can resume. */ cpumask_t icache_stale_mask;
arch/riscv/kernel/vdso.c +94 -83
247 lines not on this page · raw message
Signature · 1 line
2.34.1
kernel test robot
build botI love your patch! Yet something to improve:
Hi Jisheng,
I love your patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v6.0-rc4]
[cannot apply to next-20220907]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Jisheng-Zhang/vdso-fix-NULL-deference-in-vdso_join_timens-when-vfork/20220908-011001 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 0066f1b0e27556381402db3ff31f85d2a2265858 config: riscv-randconfig-r006-20220907 (https://download.01.org/0day-ci/archive/20220908/[email protected]/config) compiler: riscv64-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/247635b442c42937dc9f0c0a04711fb3f86df2a9
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jisheng-Zhang/vdso-fix-NULL-deference-in-vdso_join_timens-when-vfork/20220908-011001 git checkout 247635b442c42937dc9f0c0a04711fb3f86df2a9
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash arch/riscv/kernel/
If you fix the issue, kindly add following tag where applicable
All errors (new ones prefixed by >>):
>> arch/riscv/kernel/vdso.c:158:24: error: 'rv_compat_vdso_maps' undeclared here (not in a function); did you mean 'rv_vdso_maps'?
158 | .dm = &rv_compat_vdso_maps[RV_VDSO_MAP_VVAR],
| ^~~~~~~~~~~~~~~~~~~
| rv_vdso_maps
arch/riscv/kernel/vdso.c:165:34: warning: 'rv_compat_vdso_maps' defined but not used [-Wunused-variable]
165 | static struct vm_special_mapping rv_compat_vdso_maps[] __ro_after_init = {
| ^~~~~~~~~~~~~~~~~~~vim +158 arch/riscv/kernel/vdso.c
144
145 static struct __vdso_info vdso_info[] __ro_after_init = {
146 [VDSO_ABI_RV64] = {
147 .name = "vdso",
148 .vdso_code_start = vdso_start,
149 .vdso_code_end = vdso_end,
150 .dm = &rv_vdso_maps[RV_VDSO_MAP_VVAR],
151 .cm = &rv_vdso_maps[RV_VDSO_MAP_VDSO],
152 },
153 #ifdef CONFIG_COMPAT
154 [VDSO_ABI_RV32] = {
155 .name = "compat_vdso",
156 .vdso_code_start = compat_vdso_start,
157 .vdso_code_end = compat_vdso_end,
> 158 .dm = &rv_compat_vdso_maps[RV_VDSO_MAP_VVAR],
159 .cm = &rv_compat_vdso_maps[RV_VDSO_MAP_VDSO],
160 },
161 #endif
162 };
163
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
kernel test robot
build botI love your patch! Yet something to improve:
Hi Jisheng,
I love your patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v6.0-rc4]
[cannot apply to next-20220908]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Jisheng-Zhang/vdso-fix-NULL-deference-in-vdso_join_timens-when-vfork/20220908-011001 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 0066f1b0e27556381402db3ff31f85d2a2265858 config: riscv-randconfig-r012-20220907 (https://download.01.org/0day-ci/archive/20220909/[email protected]/config) compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 1546df49f5a6d09df78f569e4137ddb365a3e827)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/247635b442c42937dc9f0c0a04711fb3f86df2a9
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jisheng-Zhang/vdso-fix-NULL-deference-in-vdso_join_timens-when-vfork/20220908-011001 git checkout 247635b442c42937dc9f0c0a04711fb3f86df2a9
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash arch/riscv/kernel/
If you fix the issue, kindly add following tag where applicable
All errors (new ones prefixed by >>):
>> arch/riscv/kernel/vdso.c:158:10: error: use of undeclared identifier 'rv_compat_vdso_maps'
.dm = &rv_compat_vdso_maps[RV_VDSO_MAP_VVAR],
^
arch/riscv/kernel/vdso.c:159:10: error: use of undeclared identifier 'rv_compat_vdso_maps'
.cm = &rv_compat_vdso_maps[RV_VDSO_MAP_VDSO],
^2 errors generated.
vim +/rv_compat_vdso_maps +158 arch/riscv/kernel/vdso.c
144
145 static struct __vdso_info vdso_info[] __ro_after_init = {
146 [VDSO_ABI_RV64] = {
147 .name = "vdso",
148 .vdso_code_start = vdso_start,
149 .vdso_code_end = vdso_end,
150 .dm = &rv_vdso_maps[RV_VDSO_MAP_VVAR],
151 .cm = &rv_vdso_maps[RV_VDSO_MAP_VDSO],
152 },
153 #ifdef CONFIG_COMPAT
154 [VDSO_ABI_RV32] = {
155 .name = "compat_vdso",
156 .vdso_code_start = compat_vdso_start,
157 .vdso_code_end = compat_vdso_end,
> 158 .dm = &rv_compat_vdso_maps[RV_VDSO_MAP_VVAR],
159 .cm = &rv_compat_vdso_maps[RV_VDSO_MAP_VDSO],
160 },
161 #endif
162 };
163
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp