Skip to content

Commit c9d6b28

Browse files
Villemoesgregkh
authored andcommitted
devtmpfs: fix theoretical stale pointer deref in devtmpfsd()
After complete(&setup_done), devtmpfs_init proceeds and may actually return, invalidating the *err pointer, before devtmpfsd() proceeds to reading back *err. This is of course completely theoretical since the error conditions never trigger in practice, and even if they did, nobody cares about the exit value from a kernel thread, so it doesn't matter if we happen to read back some garbage from some other stack frame. Still, this isn't a pattern that should be copy-pasted, so fix it. Signed-off-by: Rasmus Villemoes <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0707cfa commit c9d6b28

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/base/devtmpfs.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,13 @@ static int handle(const char *name, umode_t mode, kuid_t uid, kgid_t gid,
390390

391391
static int devtmpfsd(void *p)
392392
{
393-
int *err = p;
394-
*err = ksys_unshare(CLONE_NEWNS);
395-
if (*err)
393+
int err;
394+
395+
err = ksys_unshare(CLONE_NEWNS);
396+
if (err)
396397
goto out;
397-
*err = do_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, NULL);
398-
if (*err)
398+
err = do_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, NULL);
399+
if (err)
399400
goto out;
400401
ksys_chdir("/.."); /* will traverse into overmounted root */
401402
ksys_chroot(".");
@@ -421,8 +422,9 @@ static int devtmpfsd(void *p)
421422
}
422423
return 0;
423424
out:
425+
*(int *)p = err;
424426
complete(&setup_done);
425-
return *err;
427+
return err;
426428
}
427429

428430
/*

0 commit comments

Comments
 (0)