mirror of https://gitee.com/openkylin/linux.git
exec: Simplify unshare_files
Now that exec no longer needs to return the unshared files to their previous value there is no reason to return displaced. Instead when unshare_fd creates a copy of the file table, call put_files_struct before returning from unshare_files. Acked-by: Christian Brauner <christian.brauner@ubuntu.com> v1: https://lkml.kernel.org/r/20200817220425.9389-2-ebiederm@xmission.com Link: https://lkml.kernel.org/r/20201120231441.29911-2-ebiederm@xmission.com Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
This commit is contained in:
parent
b604350128
commit
1f702603e7
|
@ -585,7 +585,6 @@ void do_coredump(const kernel_siginfo_t *siginfo)
|
||||||
int ispipe;
|
int ispipe;
|
||||||
size_t *argv = NULL;
|
size_t *argv = NULL;
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
struct files_struct *displaced;
|
|
||||||
/* require nonrelative corefile path and be extra careful */
|
/* require nonrelative corefile path and be extra careful */
|
||||||
bool need_suid_safe = false;
|
bool need_suid_safe = false;
|
||||||
bool core_dumped = false;
|
bool core_dumped = false;
|
||||||
|
@ -791,11 +790,9 @@ void do_coredump(const kernel_siginfo_t *siginfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get us an unshared descriptor table; almost always a no-op */
|
/* get us an unshared descriptor table; almost always a no-op */
|
||||||
retval = unshare_files(&displaced);
|
retval = unshare_files();
|
||||||
if (retval)
|
if (retval)
|
||||||
goto close_fail;
|
goto close_fail;
|
||||||
if (displaced)
|
|
||||||
put_files_struct(displaced);
|
|
||||||
if (!dump_interrupted()) {
|
if (!dump_interrupted()) {
|
||||||
/*
|
/*
|
||||||
* umh disabled with CONFIG_STATIC_USERMODEHELPER_PATH="" would
|
* umh disabled with CONFIG_STATIC_USERMODEHELPER_PATH="" would
|
||||||
|
|
|
@ -1238,7 +1238,6 @@ void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec)
|
||||||
int begin_new_exec(struct linux_binprm * bprm)
|
int begin_new_exec(struct linux_binprm * bprm)
|
||||||
{
|
{
|
||||||
struct task_struct *me = current;
|
struct task_struct *me = current;
|
||||||
struct files_struct *displaced;
|
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
/* Once we are committed compute the creds */
|
/* Once we are committed compute the creds */
|
||||||
|
@ -1259,11 +1258,9 @@ int begin_new_exec(struct linux_binprm * bprm)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/* Ensure the files table is not shared. */
|
/* Ensure the files table is not shared. */
|
||||||
retval = unshare_files(&displaced);
|
retval = unshare_files();
|
||||||
if (retval)
|
if (retval)
|
||||||
goto out;
|
goto out;
|
||||||
if (displaced)
|
|
||||||
put_files_struct(displaced);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Must be called _before_ exec_mmap() as bprm->mm is
|
* Must be called _before_ exec_mmap() as bprm->mm is
|
||||||
|
|
|
@ -109,7 +109,7 @@ struct task_struct;
|
||||||
struct files_struct *get_files_struct(struct task_struct *);
|
struct files_struct *get_files_struct(struct task_struct *);
|
||||||
void put_files_struct(struct files_struct *fs);
|
void put_files_struct(struct files_struct *fs);
|
||||||
void reset_files_struct(struct files_struct *);
|
void reset_files_struct(struct files_struct *);
|
||||||
int unshare_files(struct files_struct **);
|
int unshare_files(void);
|
||||||
struct files_struct *dup_fd(struct files_struct *, unsigned, int *) __latent_entropy;
|
struct files_struct *dup_fd(struct files_struct *, unsigned, int *) __latent_entropy;
|
||||||
void do_close_on_exec(struct files_struct *);
|
void do_close_on_exec(struct files_struct *);
|
||||||
int iterate_fd(struct files_struct *, unsigned,
|
int iterate_fd(struct files_struct *, unsigned,
|
||||||
|
|
|
@ -3023,21 +3023,21 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
|
||||||
* the exec layer of the kernel.
|
* the exec layer of the kernel.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int unshare_files(struct files_struct **displaced)
|
int unshare_files(void)
|
||||||
{
|
{
|
||||||
struct task_struct *task = current;
|
struct task_struct *task = current;
|
||||||
struct files_struct *copy = NULL;
|
struct files_struct *old, *copy = NULL;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
error = unshare_fd(CLONE_FILES, NR_OPEN_MAX, ©);
|
error = unshare_fd(CLONE_FILES, NR_OPEN_MAX, ©);
|
||||||
if (error || !copy) {
|
if (error || !copy)
|
||||||
*displaced = NULL;
|
|
||||||
return error;
|
return error;
|
||||||
}
|
|
||||||
*displaced = task->files;
|
old = task->files;
|
||||||
task_lock(task);
|
task_lock(task);
|
||||||
task->files = copy;
|
task->files = copy;
|
||||||
task_unlock(task);
|
task_unlock(task);
|
||||||
|
put_files_struct(old);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue