lkml.org 
[lkml]   [2019]   [Dec]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [RFC PATCH] ptrace: add PTRACE_GETFD request
> 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.

\
 
 \ /
  Last update: 2019-12-06 13:24    [W:0.054 / U:0.472 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site