Skip to content

Commit a8616d2

Browse files
xhackerustcpalmer-dabbelt
authored andcommitted
riscv: 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 because 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. Signed-off-by: Jisheng Zhang <[email protected]> Suggested-by: Palmer Dabbelt <[email protected]> Fixes: 3092eb4 ("riscv: compat: vdso: Add setup additional pages implementation") Link: https://lore.kernel.org/r/[email protected] Cc: [email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 1a5a2cb commit a8616d2

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

arch/riscv/include/asm/mmu.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ typedef struct {
1616
atomic_long_t id;
1717
#endif
1818
void *vdso;
19-
void *vdso_info;
2019
#ifdef CONFIG_SMP
2120
/* A local icache flush is needed before user execution can resume. */
2221
cpumask_t icache_stale_mask;

arch/riscv/kernel/vdso.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ struct __vdso_info {
6060
struct vm_special_mapping *cm;
6161
};
6262

63+
static struct __vdso_info vdso_info;
64+
#ifdef CONFIG_COMPAT
65+
static struct __vdso_info compat_vdso_info;
66+
#endif
67+
6368
static int vdso_mremap(const struct vm_special_mapping *sm,
6469
struct vm_area_struct *new_vma)
6570
{
@@ -114,15 +119,18 @@ int vdso_join_timens(struct task_struct *task, struct time_namespace *ns)
114119
{
115120
struct mm_struct *mm = task->mm;
116121
struct vm_area_struct *vma;
117-
struct __vdso_info *vdso_info = mm->context.vdso_info;
118122

119123
mmap_read_lock(mm);
120124

121125
for (vma = mm->mmap; vma; vma = vma->vm_next) {
122126
unsigned long size = vma->vm_end - vma->vm_start;
123127

124-
if (vma_is_special_mapping(vma, vdso_info->dm))
128+
if (vma_is_special_mapping(vma, vdso_info.dm))
125129
zap_page_range(vma, vma->vm_start, size);
130+
#ifdef CONFIG_COMPAT
131+
if (vma_is_special_mapping(vma, compat_vdso_info.dm))
132+
zap_page_range(vma, vma->vm_start, size);
133+
#endif
126134
}
127135

128136
mmap_read_unlock(mm);
@@ -264,7 +272,6 @@ static int __setup_additional_pages(struct mm_struct *mm,
264272

265273
vdso_base += VVAR_SIZE;
266274
mm->context.vdso = (void *)vdso_base;
267-
mm->context.vdso_info = (void *)vdso_info;
268275

269276
ret =
270277
_install_special_mapping(mm, vdso_base, vdso_text_len,

0 commit comments

Comments
 (0)