fdinfo: Option for public fdinfo
Subsystems (4)
RFC PATCH 1/1 fdinfo: Option for public fdinfo
We want some GPU information to be publicly available to all processes for basic system-wide profiling (think GPU versions of top).
This information is available in fdinfo and not easily exposed by other interfaces.
Add fd_op flag FOP_PUBLIC_FDINFO, which, if set, makes the fdinfo for that file available to read for processes without ptrace permissions.
Note that this makes public how many files each process has open, and what their fds are.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +- fs/proc/fd.c | 24 ++++++++++++++++++++++-- include/linux/fs.h | 2 ++ 3 files changed, 25 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -1
@@ -3022,7 +3022,7 @@ static const struct file_operations amdgpu_driver_kms_fops = {#ifdef CONFIG_PROC_FS .show_fdinfo = drm_show_fdinfo, #endif - .fop_flags = FOP_UNSIGNED_OFFSET, + .fop_flags = FOP_UNSIGNED_OFFSET | FOP_PUBLIC_FDINFO, };int amdgpu_file_to_fpriv (struct file *filp,struct amdgpu_fpriv **fpriv)
fs/proc/fd.c +22 -2
@@ -86,13 +86,34 @@ static int proc_fdinfo_permission(struct mnt_idmap *idmap, struct inode *inode, int mask) {bool allowed = false; +struct file *file =NULL ; +struct files_struct *files =NULL ;struct task_struct *task =get_proc_task (inode);if (!task)return -ESRCH ; - allowed =ptrace_may_access (task,PTRACE_MODE_READ_FSCREDS ); +task_lock (task); + files = task->files; +if (files) { +unsigned int fd =proc_fd (inode); + +spin_lock (&files->file_lock); + file =files_lookup_fd_locked (files, fd); +if (file) +get_file (file); +spin_unlock (&files->file_lock); + } +task_unlock (task); + +if (file) + allowed = file->f_op->fop_flags &FOP_PUBLIC_FDINFO ; + +if (!allowed) + allowed =ptrace_may_access (task,PTRACE_MODE_READ_FSCREDS ); +put_task_struct (task); +fput (file);if (!allowed)return -EACCES ;
@@ -401,7 +422,6 @@ static int proc_fdinfo_iterate(struct file *file, struct dir_context *ctx)const struct inode_operations proc_fdinfo_inode_operations = { .lookup = proc_lookupfdinfo, - .permission = proc_fdinfo_permission, .setattr = proc_setattr, };
include/linux/fs.h +2 -0
@@ -2327,6 +2327,8 @@ struct file_operations {#define FOP_ASYNC_LOCK ((__force fop_flags_t)(1 << 6))/* File system supports uncached read/write buffered IO */ #define FOP_DONTCACHE ((__force fop_flags_t)(1 << 7)) +/* fdinfo readable without ptrace access */ +#define FOP_PUBLIC_FDINFO ((__force fop_flags_t)(1 << 8))/* Wrap a directory iterator that needs exclusive inode access */ int wrap_directory_iterator(struct file *, struct dir_context *,
Signature · 1 line
2.34.1
Christian Brauner
maintainerQuoted 11 lines · David Francis
We want some GPU information to be publicly available to all processes for basic system-wide profiling (think GPU versions of top).
This information is available in fdinfo and not easily exposed by other interfaces.
Add
fd_opflagFOP_PUBLIC_FDINFO, which, if set, makes the fdinfo for that file available to read for processes without ptrace permissions.
Quoted 5 lines
Note that this makes public how many files each process has open, and what their fds are.
Signed-off-by David Francis <[email protected]>---
Eew, please let's not. Add an ioctl if you need to be able to retrieve that info.
Christian König
maintainerQuoted 12 lines · Christian Brauner
Quoted 11 lines · David Francis
We want some GPU information to be publicly available to all processes for basic system-wide profiling (think GPU versions of top).
This information is available in fdinfo and not easily exposed by other interfaces.
Add
fd_opflagFOP_PUBLIC_FDINFO, which, if set, makes the fdinfo for that file available to read for processes without ptrace permissions.
Quoted 8 lines
Quoted 5 lines
Note that this makes public how many files each process has open, and what their fds are.
Signed-off-by David Francis <[email protected]>---
Eew, please let's not. Add an ioctl if you need to be able to retrieve that info.
Yeah the problem is an IOCTL is even worse from the security pov.
This is for an tool which doesn't have access to the file descriptor which provides that information.
So using pidfd_getfd() or similar to get the FD and then call an IOCTL on it would be a security violation.
The real question is how should we make this information public available in the system?
Regards,
Christian.
Christian Brauner
maintainerQuoted 22 lines · Christian König
Quoted 12 lines · Christian Brauner
Quoted 11 lines · David Francis
We want some GPU information to be publicly available to all processes for basic system-wide profiling (think GPU versions of top).
This information is available in fdinfo and not easily exposed by other interfaces.
Add
fd_opflagFOP_PUBLIC_FDINFO, which, if set, makes the fdinfo for that file available to read for processes without ptrace permissions.Quoted 8 lines
Quoted 5 lines
Note that this makes public how many files each process has open, and what their fds are.
Signed-off-by David Francis <[email protected]>---
Eew, please let's not. Add an ioctl if you need to be able to retrieve that info.
Quoted 7 lines
Yeah the problem is an IOCTL is even worse from the security pov.
This is for an tool which doesn't have access to the file descriptor which provides that information.
So using
pidfd_getfd()or similar to get the FD and then call an IOCTL on it would be a security violation.The real question is how should we make this information public available in the system?
Don't you have a way to make this info available in sysfs? Just like networking exposes info about network devices in there that may come and go?
Christian König
maintainerQuoted 27 lines · Christian Brauner
Quoted 26 lines · Christian König
Quoted 12 lines · Christian Brauner
Quoted 11 lines · David Francis
We want some GPU information to be publicly available to all processes for basic system-wide profiling (think GPU versions of top).
This information is available in fdinfo and not easily exposed by other interfaces.
Add
fd_opflagFOP_PUBLIC_FDINFO, which, if set, makes the fdinfo for that file available to read for processes without ptrace permissions.Quoted 8 lines
Quoted 5 lines
Note that this makes public how many files each process has open, and what their fds are.
Signed-off-by David Francis <[email protected]>---
Eew, please let's not. Add an ioctl if you need to be able to retrieve that info.
Yeah the problem is an IOCTL is even worse from the security pov.
This is for an tool which doesn't have access to the file descriptor which provides that information.
Quoted 7 lines
Quoted 3 lines
So using
pidfd_getfd()or similar to get the FD and then call an IOCTL on it would be a security violation.The real question is how should we make this information public available in the system?
Don't you have a way to make this info available in sysfs? Just like networking exposes info about network devices in there that may come and go?
Yeah that was already tried as well and Greg summarized it as "sometimes you don't know how horrible something is until you tried it".
So the memory accounting parts for DMA-buf files in sysfs were deprecated and removed again just a few weeks ago. And that was basically just a subset of what David tries to do here.
The requirement is that you want to be able to access the stats for accelerators/GPUs drivers similar to how tools like "top" or "htop" work. E.g. everybody can access /proc/*/stat as well, it's just that some security related information are left out.
As far as I can see we have only a couple of different options to fulfill that requirement and lowering the security for fdinfo like David's patch here suggests still looks like the most defensive one to me.
Regards,
Christian.
Christian Brauner
maintainerQuoted 36 lines · Christian König
Quoted 27 lines · Christian Brauner
Quoted 26 lines · Christian König
Quoted 12 lines · Christian Brauner
Quoted 11 lines · David Francis
We want some GPU information to be publicly available to all processes for basic system-wide profiling (think GPU versions of top).
This information is available in fdinfo and not easily exposed by other interfaces.
Add
fd_opflagFOP_PUBLIC_FDINFO, which, if set, makes the fdinfo for that file available to read for processes without ptrace permissions.Quoted 8 lines
Quoted 5 lines
Note that this makes public how many files each process has open, and what their fds are.
Signed-off-by David Francis <[email protected]>---
Eew, please let's not. Add an ioctl if you need to be able to retrieve that info.
Yeah the problem is an IOCTL is even worse from the security pov.
This is for an tool which doesn't have access to the file descriptor which provides that information.
Quoted 7 lines
Quoted 3 lines
So using
pidfd_getfd()or similar to get the FD and then call an IOCTL on it would be a security violation.The real question is how should we make this information public available in the system?
Don't you have a way to make this info available in sysfs? Just like networking exposes info about network devices in there that may come and go?
Quoted 7 lines
Yeah that was already tried as well and Greg summarized it as "sometimes you don't know how horrible something is until you tried it".
So the memory accounting parts for DMA-buf files in sysfs were deprecated and removed again just a few weeks ago. And that was basically just a subset of what David tries to do here.
The requirement is that you want to be able to access the stats for accelerators/GPUs drivers similar to how tools like "top" or "htop" work. E.g. everybody can access
/proc/*/statas well, it's just that some security related information are left out.As far as I can see we have only a couple of different options to fulfill that requirement and lowering the security for fdinfo like David's patch here suggests still looks like the most defensive one to me.
It's not acceptable to make /proc/<pid>/fdinfo accessible just to carve out an exception for you. You can look at implementing something like taskstats based on netlink transpart if you want to.
Christian König
maintainerQuoted 41 lines · Christian Brauner
Quoted 40 lines · Christian König
Quoted 27 lines · Christian Brauner
Quoted 26 lines · Christian König
Quoted 12 lines · Christian Brauner
Quoted 11 lines · David Francis
We want some GPU information to be publicly available to all processes for basic system-wide profiling (think GPU versions of top).
This information is available in fdinfo and not easily exposed by other interfaces.
Add
fd_opflagFOP_PUBLIC_FDINFO, which, if set, makes the fdinfo for that file available to read for processes without ptrace permissions.Quoted 8 lines
Quoted 5 lines
Note that this makes public how many files each process has open, and what their fds are.
Signed-off-by David Francis <[email protected]>---
Eew, please let's not. Add an ioctl if you need to be able to retrieve that info.
Yeah the problem is an IOCTL is even worse from the security pov.
This is for an tool which doesn't have access to the file descriptor which provides that information.
Quoted 7 lines
Quoted 3 lines
So using
pidfd_getfd()or similar to get the FD and then call an IOCTL on it would be a security violation.The real question is how should we make this information public available in the system?
Don't you have a way to make this info available in sysfs? Just like networking exposes info about network devices in there that may come and go?
Yeah that was already tried as well and Greg summarized it as "sometimes you don't know how horrible something is until you tried it".
So the memory accounting parts for DMA-buf files in sysfs were deprecated and removed again just a few weeks ago. And that was basically just a subset of what David tries to do here.
Quoted 7 lines
Quoted 3 lines
The requirement is that you want to be able to access the stats for accelerators/GPUs drivers similar to how tools like "top" or "htop" work. E.g. everybody can access
/proc/*/statas well, it's just that some security related information are left out.As far as I can see we have only a couple of different options to fulfill that requirement and lowering the security for fdinfo like David's patch here suggests still looks like the most defensive one to me.
It's not acceptable to make /proc/<pid>/fdinfo accessible just to carve out an exception for you. You can look at implementing something like taskstats based on netlink transpart if you want to.
What exactly do you mean with that? As far as I can see we can't expose per file descriptor information through netlink.
What's actually the problem exposing things through fdinfo? As far as I can see it shouldn't be much of a problem exposing the directory for everybody and letting each file decide what the security checks should be.
Regards,
Christian.
Christian Brauner
maintainerQuoted 50 lines · Christian König
Quoted 41 lines · Christian Brauner
Quoted 40 lines · Christian König
Quoted 27 lines · Christian Brauner
Quoted 26 lines · Christian König
Quoted 12 lines · Christian Brauner
Quoted 11 lines · David Francis
We want some GPU information to be publicly available to all processes for basic system-wide profiling (think GPU versions of top).
This information is available in fdinfo and not easily exposed by other interfaces.
Add
fd_opflagFOP_PUBLIC_FDINFO, which, if set, makes the fdinfo for that file available to read for processes without ptrace permissions.Quoted 8 lines
Quoted 5 lines
Note that this makes public how many files each process has open, and what their fds are.
Signed-off-by David Francis <[email protected]>---
Eew, please let's not. Add an ioctl if you need to be able to retrieve that info.
Yeah the problem is an IOCTL is even worse from the security pov.
This is for an tool which doesn't have access to the file descriptor which provides that information.
Quoted 7 lines
Quoted 3 lines
So using
pidfd_getfd()or similar to get the FD and then call an IOCTL on it would be a security violation.The real question is how should we make this information public available in the system?
Don't you have a way to make this info available in sysfs? Just like networking exposes info about network devices in there that may come and go?
Yeah that was already tried as well and Greg summarized it as "sometimes you don't know how horrible something is until you tried it".
So the memory accounting parts for DMA-buf files in sysfs were deprecated and removed again just a few weeks ago. And that was basically just a subset of what David tries to do here.
Quoted 7 lines
Quoted 3 lines
The requirement is that you want to be able to access the stats for accelerators/GPUs drivers similar to how tools like "top" or "htop" work. E.g. everybody can access
/proc/*/statas well, it's just that some security related information are left out.As far as I can see we have only a couple of different options to fulfill that requirement and lowering the security for fdinfo like David's patch here suggests still looks like the most defensive one to me.
It's not acceptable to make /proc/<pid>/fdinfo accessible just to carve out an exception for you. You can look at implementing something like taskstats based on netlink transpart if you want to.
Quoted 6 lines
What exactly do you mean with that? As far as I can see we can't expose per file descriptor information through netlink.
What's actually the problem exposing things through fdinfo? As far as I can see it shouldn't be much of a problem exposing the directory for everybody and letting each file decide what the security checks should be.
To me it looks like this: you want to force a uapi change on all of userspace without any clear idea what will or will not break for a single-consumer for a very special use-case. This will need strong arguments why we need to alter ancient procfs behavior. And note that ownership of all of these directories can change under you because of dumpability settings. Why should a random user be able to list fds of pid 1 suddenly.