Skip to content

Commit bb58559

Browse files
amir73ilbrauner
authored andcommitted
fhandle: use more consistent rules for decoding file handle from userns
Commit 620c266 ("fhandle: relax open_by_handle_at() permission checks") relaxed the coditions for decoding a file handle from non init userns. The conditions are that that decoded dentry is accessible from the user provided mountfd (or to fs root) and that all the ancestors along the path have a valid id mapping in the userns. These conditions are intentionally more strict than the condition that the decoded dentry should be "lookable" by path from the mountfd. For example, the path /home/amir/dir/subdir is lookable by path from unpriv userns of user amir, because /home perms is 755, but the owner of /home does not have a valid id mapping in unpriv userns of user amir. The current code did not check that the decoded dentry itself has a valid id mapping in the userns. There is no security risk in that, because that final open still performs the needed permission checks, but this is inconsistent with the checks performed on the ancestors, so the behavior can be a bit confusing. Add the check for the decoded dentry itself, so that the entire path, including the last component has a valid id mapping in the userns. Fixes: 620c266 ("fhandle: relax open_by_handle_at() permission checks") Signed-off-by: Amir Goldstein <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent be1e028 commit bb58559

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

fs/fhandle.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ static int vfs_dentry_acceptable(void *context, struct dentry *dentry)
207207
if (!ctx->flags)
208208
return 1;
209209

210+
/*
211+
* Verify that the decoded dentry itself has a valid id mapping.
212+
* In case the decoded dentry is the mountfd root itself, this
213+
* verifies that the mountfd inode itself has a valid id mapping.
214+
*/
215+
if (!privileged_wrt_inode_uidgid(user_ns, idmap, d_inode(dentry)))
216+
return 0;
217+
210218
/*
211219
* It's racy as we're not taking rename_lock but we're able to ignore
212220
* permissions and we just need an approximation whether we were able

0 commit comments

Comments
 (0)