proc: allow access in init userns for map_files with CAP_CHECKPOINT_RESTORE

Opening files in /proc/pid/map_files when the current user is
CAP_CHECKPOINT_RESTORE capable in the root namespace is useful for
checkpointing and restoring to recover files that are unreachable via
the file system such as deleted files, or memfd files.

Signed-off-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@gmail.com>
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Link: https://lore.kernel.org/r/20200719100418.2112740-5-areber@redhat.com
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Adrian Reber 2020-07-19 12:04:14 +02:00 committed by Christian Brauner
parent b9a3db92e1
commit 12886f8ab1
1 changed files with 4 additions and 4 deletions

View File

@ -2189,16 +2189,16 @@ struct map_files_info {
}; };
/* /*
* Only allow CAP_SYS_ADMIN to follow the links, due to concerns about how the * Only allow CAP_SYS_ADMIN and CAP_CHECKPOINT_RESTORE to follow the links, due
* symlinks may be used to bypass permissions on ancestor directories in the * to concerns about how the symlinks may be used to bypass permissions on
* path to the file in question. * ancestor directories in the path to the file in question.
*/ */
static const char * static const char *
proc_map_files_get_link(struct dentry *dentry, proc_map_files_get_link(struct dentry *dentry,
struct inode *inode, struct inode *inode,
struct delayed_call *done) struct delayed_call *done)
{ {
if (!capable(CAP_SYS_ADMIN)) if (!checkpoint_restore_ns_capable(&init_user_ns))
return ERR_PTR(-EPERM); return ERR_PTR(-EPERM);
return proc_pid_get_link(dentry, inode, done); return proc_pid_get_link(dentry, inode, done);