From: Seth Forshee Date: Tue, 30 Aug 2016 04:35:00 +0000 (-0400) Subject: fs: Check for invalid i_uid in may_follow_link() X-Git-Tag: firefly_0821_release~176^2~4^2~31^2~56 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=6a90aa44065afb34ad4f37676b734c0e3eeafe6a;p=firefly-linux-kernel-4.4.55.git fs: Check for invalid i_uid in may_follow_link() [ Upstream commit 2d7f9e2ad35e4e7a3086231f19bfab33c6a8a64a ] 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. Signed-off-by: Seth Forshee Acked-by: Serge Hallyn Signed-off-by: Eric W. Biederman Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/namei.c b/fs/namei.c index 209ca7737cb2..0b0acba72a71 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -887,6 +887,7 @@ static inline int may_follow_link(struct nameidata *nd) { const struct inode *inode; const struct inode *parent; + kuid_t puid; if (!sysctl_protected_symlinks) return 0; @@ -902,7 +903,8 @@ static inline int may_follow_link(struct nameidata *nd) return 0; /* Allowed if parent directory and link owner match. */ - if (uid_eq(parent->i_uid, inode->i_uid)) + puid = parent->i_uid; + if (uid_valid(puid) && uid_eq(puid, inode->i_uid)) return 0; if (nd->flags & LOOKUP_RCU)