From: Oleg Nesterov <oleg@redhat.com>
To: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Sargun Dhillon <sargun@sargun.me>,
linux-kernel@vger.kernel.org,
containers@lists.linux-foundation.org, linux-api@vger.kernel.org,
tycho@tycho.ws
Subject: Re: [RFC PATCH] ptrace: add PTRACE_GETFD request
Date: Fri, 6 Dec 2019 13:23:11 +0100 [thread overview]
Message-ID: <20191206122311.GA820@redhat.com> (raw)
In-Reply-To: <20191206082539.gmefytwu3ylixj5d@wittgenstein>
> On Thu, Dec 05, 2019 at 11:44:53PM +0000, Sargun Dhillon wrote:
>
> > +static int ptrace_getfd(struct task_struct *child, unsigned long fd)
> > +{
> > + struct files_struct *files;
> > + struct file *file;
> > + int ret = 0;
> > +
> > + files = get_files_struct(child);
> > + if (!files)
> > + return -ENOENT;
> > +
> > + spin_lock(&files->file_lock);
> > + file = fcheck_files(files, fd);
> > + if (!file)
> > + ret = -EBADF;
> > + else
> > + get_file(file);
> > + spin_unlock(&files->file_lock);
> > + put_files_struct(files);
may be someone can finally create a helper for this, it can have more users.
say,
struct file *get_task_file(task, fd)
{
struct file *file = NULL;
task_lock(task);
rcu_read_lock();
if (task->files) {
file = fcheck_files(task->files, fd);
if (file)
get_file(file);
}
rcu_read_unlock();
task_unlock(task);
return file;
}
no need to get/put files_struct, no need to take ->file_lock.
> > +
> > + if (ret)
> > + goto out;
> > +
> > + ret = get_unused_fd_flags(0);
> > + if (ret >= 0)
> > + fd_install(ret, file);
> > +
> > + fput(file);
this looks wrong or I am totally confused...
if (ret >= 0)
fd_install(file);
else
fput(file);
?
> > @@ -1265,7 +1299,8 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
> > }
> >
> > ret = ptrace_check_attach(child, request == PTRACE_KILL ||
> > - request == PTRACE_INTERRUPT);
> > + request == PTRACE_INTERRUPT ||
> > + request == PTRACE_GETFD);
Hmm. not sure why do you want this... But OK, we do not need to stop the tracee.
Oleg.
next prev parent reply other threads:[~2019-12-06 12:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-05 23:44 [RFC PATCH] ptrace: add PTRACE_GETFD request Sargun Dhillon
2019-12-06 2:38 ` Jann Horn
2019-12-06 6:16 ` Sargun Dhillon
2019-12-06 6:52 ` Aleksa Sarai
2019-12-06 8:25 ` Christian Brauner
2019-12-06 12:23 ` Oleg Nesterov [this message]
2019-12-06 14:10 ` Tycho Andersen
2019-12-06 19:03 ` Sargun Dhillon
2019-12-06 19:05 ` Jann Horn
2019-12-06 19:05 ` Jann Horn
2019-12-06 20:45 ` Andy Lutomirski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191206122311.GA820@redhat.com \
--to=oleg@redhat.com \
--cc=christian.brauner@ubuntu.com \
--cc=containers@lists.linux-foundation.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sargun@sargun.me \
--cc=tycho@tycho.ws \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.