lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 6 Dec 2019 13:23:11 +0100
From:   Oleg Nesterov <oleg@...hat.com>
To:     Christian Brauner <christian.brauner@...ntu.com>
Cc:     Sargun Dhillon <sargun@...gun.me>, linux-kernel@...r.kernel.org,
        containers@...ts.linux-foundation.org, linux-api@...r.kernel.org,
        tycho@...ho.ws
Subject: Re: [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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ