Skip to contentSkip to conversation

Yama: verify inode is symlink to avoid bind mounts

PATCH Superseded Kees Cook 2 participants 4 messages Jul 13, 2010 – Jul 14, 2010

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 Yama: verify inode is symlink to avoid bind mounts

The inode_follow_link LSM hook is called in bind mount situations as well as for symlink situations, so we must explicitly check for the inode being a symlink to not reject bind mounts in 1777 directories, which seems to be a common NFSv4 configuration.

---
 security/yama/yama_lsm.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
security/yama/yama_lsm.c +4 -0
index 3b76386..c70eb10 100644
@@ -116,6 +116,10 @@ static int yama_inode_follow_link(struct dentry *dentry,
 	if (!protected_sticky_symlinks)
 		return 0;
 
+	/* if inode isn't a symlink, don't try to evaluate blocking it */
+	if (!S_ISLNK(inode->i_mode))
+		return 0;
+
 	/* owner and follower match? */
 	cred = current_cred();
 	inode = dentry->d_inode;
Signature · 6 lines
1.7.1


-- 
Kees Cook
Ubuntu Security Team
maintainer
#1 lore raw
Quoted 3 lines · Kees Cook

The inode_follow_link LSM hook is called in bind mount situations as well as for symlink situations, so we must explicitly check for the inode being a symlink to not reject bind mounts in 1777 directories,

Are you sure about that??

If that's true, you might also expand the comment in include/linux/security.h.

Quoted 33 lines

which seems to be a common NFSv4 configuration.

---
 security/yama/yama_lsm.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
security/yama/yama_lsm.c +4 -0
index 3b76386..c70eb10 100644
@@ -116,6 +116,10 @@ static int yama_inode_follow_link(struct dentry *dentry,
 	if (!protected_sticky_symlinks)
 		return 0;
 
+	/* if inode isn't a symlink, don't try to evaluate blocking it */
+	if (!S_ISLNK(inode->i_mode))
+		return 0;
+
 	/* owner and follower match? */
 	cred = current_cred();
 	inode = dentry->d_inode;
Signature · 10 lines
1.7.1


-- 
Kees Cook
Ubuntu Security Team
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#2 lore raw
Quoted 11 lines · Serge E. Hallyn
Quoted 3 lines · Kees Cook

The inode_follow_link LSM hook is called in bind mount situations as well as for symlink situations, so we must explicitly check for the inode being a symlink to not reject bind mounts in 1777 directories,

Are you sure about that??

If that's true, you might also expand the comment in include/linux/security.h.

Quoted 1 line

which seems to be a common NFSv4 configuration.

Well, the issue is how the NFSv4 client deals with it. It seems to treat the mounts from the NFSv4 root as a symlink when the server is using bind mounts. It's kind of weird:
https://launchpad.net/bugs/604407

Signature · 2 lines
Kees Cook
Ubuntu Security Team
author
#3 lore raw
In reply to Kees Cook
Quoted 15 lines · Kees Cook

The inode_follow_link LSM hook is called in bind mount situations as well as for symlink situations, so we must explicitly check for the inode being a symlink to not reject bind mounts in 1777 directories, which seems to be a common NFSv4 configuration.

---
 security/yama/yama_lsm.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
security/yama/yama_lsm.c +0 -0
index 3b76386..c70eb10 100644

security/yama/yama_lsm.c static int yama_inode_follow_link(struct dentry *dentry, · line 125

Quoted 10 lines
security/yama/yama_lsm.c +4 -0
@@ -116,6 +116,10 @@ static int yama_inode_follow_link(struct dentry *dentry,
 	if (!protected_sticky_symlinks)
 		return 0;
 
+	/* if inode isn't a symlink, don't try to evaluate blocking it */
+	if (!S_ISLNK(inode->i_mode))
+		return 0;
+
 	/* owner and follower match? */
 	cred = current_cred();
 	inode = dentry->d_inode;

Erg, please ignore this -- I tested a slightly different version of this patch. This version doesn't have inode set yet. I will follow up with the correct one in a moment...

-Kees

Signature · 2 lines
Kees Cook
Ubuntu Security Team