Debug replace_fd() From: Pavel Roskin --- fs/coredump.c | 4 +++- fs/file.c | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index fd37fac..2a5ce3c 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -440,6 +440,7 @@ static void wait_for_dump_helpers(struct file *file) * is a special value that we use to trap recursive * core dumps */ +int replace_fd_debug(unsigned fd, struct file *file, unsigned flags); static int umh_pipe_setup(struct subprocess_info *info, struct cred *new) { struct file *files[2]; @@ -450,7 +451,8 @@ static int umh_pipe_setup(struct subprocess_info *info, struct cred *new) cp->file = files[1]; - replace_fd(0, files[0], 0); + err = replace_fd_debug(0, files[0], 0); + printk("%s: replace_fd_debug returned %d\n", __func__, err); /* and disallow core files too */ current->signal->rlim[RLIMIT_CORE] = (struct rlimit){1, 1}; diff --git a/fs/file.c b/fs/file.c index d3b5fa8..e209b3c 100644 --- a/fs/file.c +++ b/fs/file.c @@ -913,6 +913,33 @@ out_unlock: return err; } +int replace_fd_debug(unsigned fd, struct file *file, unsigned flags); +int replace_fd_debug(unsigned fd, struct file *file, unsigned flags) +{ + int err; + struct files_struct *files = current->files; + + printk("%s: rlimit(RLIMIT_NOFILE) = %ld\n", __func__, rlimit(RLIMIT_NOFILE)); + printk("%s: file = %p\n", __func__, file); + + if (!file) + return __close_fd(files, fd); + + if (fd >= rlimit(RLIMIT_NOFILE)) + return -EMFILE; + + spin_lock(&files->file_lock); + err = expand_files(files, fd); + printk("%s: expand_files returned %d\n", __func__, err); + if (unlikely(err < 0)) + goto out_unlock; + return do_dup2(files, file, fd, flags); + +out_unlock: + spin_unlock(&files->file_lock); + return err; +} + SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags) { int err = -EBADF;