Commit b7010fdb authored by Seth Forshee's avatar Seth Forshee

fs: Check for invalid i_uid in may_follow_link()

Filesystem uids which don't map into a user namespace may result
in inode->i_uid being INVALID_UID. A symlink and its parent
could have different owners in the filesystem can both get
mapped to INVALID_UID, which may result in following a symlink
when this would not have otherwise been permitted when protected
symlinks are enabled.

Add a new helper function, uid_valid_eq(), and use this to
validate that the ids in may_follow_link() are both equal and
valid. Also add an equivalent helper for gids, which is
currently unused.
Signed-off-by: default avatarSeth Forshee <seth.forshee@canonical.com>
parent a2a1f56f
...@@ -902,7 +902,7 @@ static inline int may_follow_link(struct nameidata *nd) ...@@ -902,7 +902,7 @@ static inline int may_follow_link(struct nameidata *nd)
return 0; return 0;
/* Allowed if parent directory and link owner match. */ /* Allowed if parent directory and link owner match. */
if (uid_eq(parent->i_uid, inode->i_uid)) if (uid_valid_eq(parent->i_uid, inode->i_uid))
return 0; return 0;
if (nd->flags & LOOKUP_RCU) if (nd->flags & LOOKUP_RCU)
......
...@@ -117,6 +117,16 @@ static inline bool gid_valid(kgid_t gid) ...@@ -117,6 +117,16 @@ static inline bool gid_valid(kgid_t gid)
return __kgid_val(gid) != (gid_t) -1; return __kgid_val(gid) != (gid_t) -1;
} }
static inline bool uid_valid_eq(kuid_t left, kuid_t right)
{
return uid_eq(left, right) && uid_valid(left);
}
static inline bool gid_valid_eq(kgid_t left, kgid_t right)
{
return gid_eq(left, right) && gid_valid(left);
}
#ifdef CONFIG_USER_NS #ifdef CONFIG_USER_NS
extern kuid_t make_kuid(struct user_namespace *from, uid_t uid); extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment