Skip to content

Commit 275498a

Browse files
committed
exec: Add comments on check_unsafe_exec() fs counting
Add some comments about what the fs counting is doing in check_unsafe_exec() and how it relates to the call graph. Specifically, we can't force an unshare of the fs because of at least Chrome: https://lore.kernel.org/lkml/[email protected]/ Cc: Eric Biederman <[email protected]> Cc: [email protected] Signed-off-by: Kees Cook <[email protected]> Acked-by: Christian Brauner (Microsoft) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 23a7aea commit 275498a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

fs/exec.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,12 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
15731573
if (task_no_new_privs(current))
15741574
bprm->unsafe |= LSM_UNSAFE_NO_NEW_PRIVS;
15751575

1576+
/*
1577+
* If another task is sharing our fs, we cannot safely
1578+
* suid exec because the differently privileged task
1579+
* will be able to manipulate the current directory, etc.
1580+
* It would be nice to force an unshare instead...
1581+
*/
15761582
t = p;
15771583
n_fs = 1;
15781584
spin_lock(&p->fs->lock);
@@ -1753,6 +1759,7 @@ static int search_binary_handler(struct linux_binprm *bprm)
17531759
return retval;
17541760
}
17551761

1762+
/* binfmt handlers will call back into begin_new_exec() on success. */
17561763
static int exec_binprm(struct linux_binprm *bprm)
17571764
{
17581765
pid_t old_pid, old_vpid;
@@ -1811,6 +1818,11 @@ static int bprm_execve(struct linux_binprm *bprm,
18111818
if (retval)
18121819
return retval;
18131820

1821+
/*
1822+
* Check for unsafe execution states before exec_binprm(), which
1823+
* will call back into begin_new_exec(), into bprm_creds_from_file(),
1824+
* where setuid-ness is evaluated.
1825+
*/
18141826
check_unsafe_exec(bprm);
18151827
current->in_execve = 1;
18161828

0 commit comments

Comments
 (0)