Re: [RFC PATCH] ptrace: add PTRACE_GETFD request

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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.





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux