• Eric W. Biederman's avatar
    exec: Move initialization of bprm->filename into alloc_bprm · 60d9ad1d
    Eric W. Biederman authored
    Currently it is necessary for the usermode helper code and the code
    that launches init to use set_fs so that pages coming from the kernel
    look like they are coming from userspace.
    
    To allow that usage of set_fs to be removed cleanly the argument
    copying from userspace needs to happen earlier.  Move the computation
    of bprm->filename and possible allocation of a name in the case
    of execveat into alloc_bprm to make that possible.
    
    The exectuable name, the arguments, and the environment are
    copied into the new usermode stack which is stored in bprm
    until exec passes the point of no return.
    
    As the executable name is copied first onto the usermode stack
    it needs to be known.  As there are no dependencies to computing
    the executable name, compute it early in alloc_bprm.
    
    As an implementation detail if the filename needs to be generated
    because it embeds a file descriptor store that filename in a new field
    bprm->fdpath, and free it in free_bprm.  Previously this was done in
    an independent variable pathbuf.  I have renamed pathbuf fdpath
    because fdpath is more suggestive of what kind of path is in the
    variable.  I moved fdpath into struct linux_binprm because it is
    tightly tied to the other variables in struct linux_binprm, and as
    such is needed to allow the call alloc_binprm to move.
    Reviewed-by: default avatarKees Cook <keescook@chromium.org>
    Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
    Link: https://lkml.kernel.org/r/87k0z66x8f.fsf@x220.int.ebiederm.orgSigned-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
    60d9ad1d
exec.c 48.9 KB