Skip to contentSkip to conversation

Allow access to /proc/$PID/fd after setuid()

RFC Superseded Alexey Dobriyan 2 participants 2 messages Feb 1, 2007 Proc filesystem

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

RFC 1/1 Allow access to /proc/$PID/fd after setuid()

/proc/$PID/fd has r-x------ permissions, so if process does setuid(), it will not be able to access /proc/*/fd/. This breaks fstatat() emulation in glibc.

open("foo", O_RDONLY|O_DIRECTORY) = 4
setuid32(65534) = 0
stat64("/proc/self/fd/4/bar", 0xbfafb298) = -1 EACCES (Permission denied)

---

 fs/proc/base.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)
fs/proc/base.c +16 -0
@@ -1413,11 +1413,27 @@ static struct file_operations proc_fd_op
 	.readdir	= proc_readfd,
 };
 
+static int proc_fd_permission(struct inode *inode, int mask, struct nameidata *nd)
+{
+	struct task_struct *tsk;
+	int rv;
+
+	rv = generic_permission(inode, mask, NULL);
+	if (rv == 0)
+		return 0;
+	tsk = get_proc_task(inode);
+	if (tsk == current)
+		rv = 0;
+	put_task_struct(tsk);
+	return rv;
+}
+
 /*
  * proc directories can do almost nothing..
  */
 static struct inode_operations proc_fd_inode_operations = {
 	.lookup		= proc_lookupfd,
+	.permission	= proc_fd_permission,
 	.setattr	= proc_setattr,
 };
 
Acked-by on v1 1/1
#1 lore raw
Quoted 50 lines

/proc/$PID/fd has r-x------ permissions, so if process does setuid(), it will not be able to access /proc/*/fd/. This breaks fstatat() emulation in glibc.

open("foo", O_RDONLY|O_DIRECTORY) = 4
setuid32(65534) = 0
stat64("/proc/self/fd/4/bar", 0xbfafb298) = -1 EACCES (Permission denied)

---

 fs/proc/base.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)
fs/proc/base.c +16 -0
@@ -1413,11 +1413,27 @@ static struct file_operations proc_fd_op
 	.readdir	= proc_readfd,
 };
 
+static int proc_fd_permission(struct inode *inode, int mask, struct nameidata *nd)
+{
+	struct task_struct *tsk;
+	int rv;
+
+	rv = generic_permission(inode, mask, NULL);
+	if (rv == 0)
+		return 0;
+	tsk = get_proc_task(inode);
+	if (tsk == current)
+		rv = 0;
+	put_task_struct(tsk);
+	return rv;
+}
+
 /*
  * proc directories can do almost nothing..
  */
 static struct inode_operations proc_fd_inode_operations = {
 	.lookup		= proc_lookupfd,
+	.permission	= proc_fd_permission,
 	.setattr	= proc_setattr,
 };
 

_______________________________________________
Devel mailing list
[email protected]
https://openvz.org/mailman/listinfo/devel