Thread (11 messages) flat view 11 messages, 7 authors, 2019-12-06

Re: [RFC PATCH] ptrace: add PTRACE_GETFD request

From: Oleg Nesterov <oleg@redhat.com>
Date: 2019-12-06 12:23:25
Also in: lkml

On Thu, Dec 05, 2019 at 11:44:53PM +0000, Sargun Dhillon wrote:
quoted
+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.
quoted
+
+	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);

?
quoted
@@ -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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help