Skip to contentSkip to conversation

fix namespaced fscaps when !CONFIG_SECURITY

PATCH In review Serge E. Hallyn 4 participants 13 messages Nov 17, 2020 – Dec 5, 2020 1 message not in the archive Security (LSM)

lore
Share & tools
lore

Serge E. Hallyn

author maintainer
#0 lore raw

PATCH 1/1 fix namespaced fscaps when !CONFIG_SECURITY

Namespaced file capabilities were introduced in 8db6c34f1dbc . When userspace reads an xattr for a namespaced capability, a virtualized representation of it is returned if the caller is in a user namespace owned by the capability's owning rootid. The function which performs this virtualization was not hooked up if CONFIG_SECURITY=n. Therefore in that case the original xattr was shown instead of the virtualized one.

To test this using libcap-bin (*1),

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin-eip $v
$ unshare -Ur setcap -v cap_sys_admin-eip $v
/tmp/tmp.lSiIFRvt8Y: OK

"setcap -v" verifies the values instead of setting them, and will check whether the rootid value is set. Therefore, with this bug un-fixed, and with CONFIG_SECURITY=n, setcap -v will fail:

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin=eip $v
$ unshare -Ur setcap -v cap_sys_admin=eip $v
nsowner[got=1000, want=0],/tmp/tmp.HHDiOOl9fY differs in []

Fix this bug by calling cap_inode_getsecurity() in security_inode_getsecurity() instead of returning -EOPNOTSUPP, when CONFIG_SECURITY=n.

*1 - note, if libcap is too old for getcap to have the '-n' option, then use verify-caps instead.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1593431
Cc: Hervé Guillemet <[email protected]>
Cc: Andrew G. Morgan <[email protected]>
Cc: Casey Schaufler <[email protected]>

---
 include/linux/security.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/security.h +1 -1
index bc2725491560..39642626a707 100644
@@ -869,7 +869,7 @@ static inline int security_inode_killpriv(struct dentry *dentry)
 
 static inline int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc)
 {
-	return -EOPNOTSUPP;
+	return cap_inode_getsecurity(inode, name, buffer, alloc);
 }
 
 static inline int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
Signature · 1 line
2.25.1
#1 lore raw
Quoted 58 lines · Serge E. Hallyn

Namespaced file capabilities were introduced in 8db6c34f1dbc . When userspace reads an xattr for a namespaced capability, a virtualized representation of it is returned if the caller is in a user namespace owned by the capability's owning rootid. The function which performs this virtualization was not hooked up if CONFIG_SECURITY=n. Therefore in that case the original xattr was shown instead of the virtualized one.

To test this using libcap-bin (*1),

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin-eip $v
$ unshare -Ur setcap -v cap_sys_admin-eip $v
/tmp/tmp.lSiIFRvt8Y: OK

"setcap -v" verifies the values instead of setting them, and will check whether the rootid value is set. Therefore, with this bug un-fixed, and with CONFIG_SECURITY=n, setcap -v will fail:

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin=eip $v
$ unshare -Ur setcap -v cap_sys_admin=eip $v
nsowner[got=1000, want=0],/tmp/tmp.HHDiOOl9fY differs in []

Fix this bug by calling cap_inode_getsecurity() in security_inode_getsecurity() instead of returning -EOPNOTSUPP, when CONFIG_SECURITY=n.

*1 - note, if libcap is too old for getcap to have the '-n' option, then use verify-caps instead.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1593431
Cc: Hervé Guillemet <[email protected]>
Cc: Andrew G. Morgan <[email protected]>
Cc: Casey Schaufler <[email protected]>

---
 include/linux/security.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/security.h +1 -2
index bc2725491560..39642626a707 100644
@@ -869,7 +869,7 @@ static inline int security_inode_killpriv(struct dentry *dentry)
 
 static inline int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc)
 {
-       return -EOPNOTSUPP;
+       return cap_inode_getsecurity(inode, name, buffer, alloc);
 }
 
 static inline int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
--

2.25.1

Acked-by on v1 1/1
#4 lore raw
In reply to Serge E. Hallyn
Quoted 29 lines · Serge E. Hallyn

Namespaced file capabilities were introduced in 8db6c34f1dbc . When userspace reads an xattr for a namespaced capability, a virtualized representation of it is returned if the caller is in a user namespace owned by the capability's owning rootid. The function which performs this virtualization was not hooked up if CONFIG_SECURITY=n. Therefore in that case the original xattr was shown instead of the virtualized one.

To test this using libcap-bin (*1),

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin-eip $v
$ unshare -Ur setcap -v cap_sys_admin-eip $v
/tmp/tmp.lSiIFRvt8Y: OK

"setcap -v" verifies the values instead of setting them, and will check whether the rootid value is set. Therefore, with this bug un-fixed, and with CONFIG_SECURITY=n, setcap -v will fail:

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin=eip $v
$ unshare -Ur setcap -v cap_sys_admin=eip $v
nsowner[got=1000, want=0],/tmp/tmp.HHDiOOl9fY differs in []

Fix this bug by calling cap_inode_getsecurity() in security_inode_getsecurity() instead of returning -EOPNOTSUPP, when CONFIG_SECURITY=n.

Quoted 8 lines

*1 - note, if libcap is too old for getcap to have the '-n' option, then use verify-caps instead.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1593431
Cc: Hervé Guillemet <[email protected]>
Cc: Andrew G. Morgan <[email protected]>
Cc: Casey Schaufler <[email protected]>

Quoted 17 lines
---
 include/linux/security.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/security.h +1 -1
index bc2725491560..39642626a707 100644
@@ -869,7 +869,7 @@ static inline int security_inode_killpriv(struct dentry *dentry)
 
 static inline int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc)
 {
-	return -EOPNOTSUPP;
+	return cap_inode_getsecurity(inode, name, buffer, alloc);
 }
 
 static inline int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
maintainer
#5 lore raw
In reply to Serge E. Hallyn

[Adding LSM list]

Quoted 55 lines · Serge E. Hallyn

Namespaced file capabilities were introduced in 8db6c34f1dbc . When userspace reads an xattr for a namespaced capability, a virtualized representation of it is returned if the caller is in a user namespace owned by the capability's owning rootid. The function which performs this virtualization was not hooked up if CONFIG_SECURITY=n. Therefore in that case the original xattr was shown instead of the virtualized one.

To test this using libcap-bin (*1),

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin-eip $v
$ unshare -Ur setcap -v cap_sys_admin-eip $v
/tmp/tmp.lSiIFRvt8Y: OK

"setcap -v" verifies the values instead of setting them, and will check whether the rootid value is set. Therefore, with this bug un-fixed, and with CONFIG_SECURITY=n, setcap -v will fail:

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin=eip $v
$ unshare -Ur setcap -v cap_sys_admin=eip $v
nsowner[got=1000, want=0],/tmp/tmp.HHDiOOl9fY differs in []

Fix this bug by calling cap_inode_getsecurity() in security_inode_getsecurity() instead of returning -EOPNOTSUPP, when CONFIG_SECURITY=n.

*1 - note, if libcap is too old for getcap to have the '-n' option, then use verify-caps instead.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1593431
Cc: Hervé Guillemet <[email protected]>
Cc: Andrew G. Morgan <[email protected]>
Cc: Casey Schaufler <[email protected]>

---
 include/linux/security.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/security.h +1 -1
index bc2725491560..39642626a707 100644
@@ -869,7 +869,7 @@ static inline int security_inode_killpriv(struct dentry *dentry)
 
 static inline int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc)
 {
-	return -EOPNOTSUPP;
+	return cap_inode_getsecurity(inode, name, buffer, alloc);
 }
 
 static inline int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
Signature · 2 lines
James Morris
<[email protected]>
author maintainer
#8 lore raw
In reply to a message not in the archive

Hi James,

would you mind adding this to the security tree? (You can cherrypick
from https://git.kernel.org/pub/scm/linux/kernel/git/sergeh/linux.git/commit/?h=2020-11-29/fix-nscaps )

thanks,
-serge

Quoted 66 lines · Andrew G. Morgan
Quoted 61 lines · Serge E. Hallyn

Namespaced file capabilities were introduced in 8db6c34f1dbc . When userspace reads an xattr for a namespaced capability, a virtualized representation of it is returned if the caller is in a user namespace owned by the capability's owning rootid. The function which performs this virtualization was not hooked up if CONFIG_SECURITY=n. Therefore in that case the original xattr was shown instead of the virtualized one.

To test this using libcap-bin (*1),

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin-eip $v
$ unshare -Ur setcap -v cap_sys_admin-eip $v
/tmp/tmp.lSiIFRvt8Y: OK

"setcap -v" verifies the values instead of setting them, and will check whether the rootid value is set. Therefore, with this bug un-fixed, and with CONFIG_SECURITY=n, setcap -v will fail:

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin=eip $v
$ unshare -Ur setcap -v cap_sys_admin=eip $v
nsowner[got=1000, want=0],/tmp/tmp.HHDiOOl9fY differs in []

Fix this bug by calling cap_inode_getsecurity() in security_inode_getsecurity() instead of returning -EOPNOTSUPP, when CONFIG_SECURITY=n.

*1 - note, if libcap is too old for getcap to have the '-n' option, then use verify-caps instead.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1593431
Cc: Hervé Guillemet <[email protected]>
Cc: Andrew G. Morgan <[email protected]>
Cc: Casey Schaufler <[email protected]>

---
 include/linux/security.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/security.h +1 -1
index bc2725491560..39642626a707 100644
@@ -869,7 +869,7 @@ static inline int security_inode_killpriv(struct
 dentry *dentry)
 
 static inline int security_inode_getsecurity(struct inode *inode, const
 char *name, void **buffer, bool alloc)
 {
-       return -EOPNOTSUPP;
+       return cap_inode_getsecurity(inode, name, buffer, alloc);
 }

static inline int security_inode_setsecurity(struct inode *inode, const
char *name, const void *value, size_t size, int flags)
--
2.25.1

maintainer
#9 lore raw
Quoted 4 lines · Serge E. Hallyn

Hi James,

would you mind adding this to the security tree? (You can cherrypick
from https://git.kernel.org/pub/scm/linux/kernel/git/sergeh/linux.git/commit/?h=2020-11-29/fix-nscaps )

Sure.

Quoted 72 lines

thanks,
-serge

Quoted 66 lines · Andrew G. Morgan
Quoted 61 lines · Serge E. Hallyn

Namespaced file capabilities were introduced in 8db6c34f1dbc . When userspace reads an xattr for a namespaced capability, a virtualized representation of it is returned if the caller is in a user namespace owned by the capability's owning rootid. The function which performs this virtualization was not hooked up if CONFIG_SECURITY=n. Therefore in that case the original xattr was shown instead of the virtualized one.

To test this using libcap-bin (*1),

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin-eip $v
$ unshare -Ur setcap -v cap_sys_admin-eip $v
/tmp/tmp.lSiIFRvt8Y: OK

"setcap -v" verifies the values instead of setting them, and will check whether the rootid value is set. Therefore, with this bug un-fixed, and with CONFIG_SECURITY=n, setcap -v will fail:

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin=eip $v
$ unshare -Ur setcap -v cap_sys_admin=eip $v
nsowner[got=1000, want=0],/tmp/tmp.HHDiOOl9fY differs in []

Fix this bug by calling cap_inode_getsecurity() in security_inode_getsecurity() instead of returning -EOPNOTSUPP, when CONFIG_SECURITY=n.

*1 - note, if libcap is too old for getcap to have the '-n' option, then use verify-caps instead.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1593431
Cc: Hervé Guillemet <[email protected]>
Cc: Andrew G. Morgan <[email protected]>
Cc: Casey Schaufler <[email protected]>

---
 include/linux/security.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/security.h +1 -1
index bc2725491560..39642626a707 100644
@@ -869,7 +869,7 @@ static inline int security_inode_killpriv(struct
 dentry *dentry)
 
 static inline int security_inode_getsecurity(struct inode *inode, const
 char *name, void **buffer, bool alloc)
 {
-       return -EOPNOTSUPP;
+       return cap_inode_getsecurity(inode, name, buffer, alloc);
 }

static inline int security_inode_setsecurity(struct inode *inode, const
char *name, const void *value, size_t size, int flags)
--
2.25.1

Signature · 2 lines
James Morris
<[email protected]>
Reviewed-by
#10 lore raw

The correct bug reference for this patch is:

https://bugzilla.kernel.org/show_bug.cgi?id=209689

Quoted 86 lines · James Morris
Quoted 4 lines · Serge E. Hallyn

Hi James,

would you mind adding this to the security tree? (You can cherrypick
from https://git.kernel.org/pub/scm/linux/kernel/git/sergeh/linux.git/commit/?h=2020-11-29/fix-nscaps )

Sure.

Quoted 65 lines

thanks,
-serge

Quoted 60 lines · Andrew G. Morgan
Quoted 55 lines · Serge E. Hallyn

Namespaced file capabilities were introduced in 8db6c34f1dbc . When userspace reads an xattr for a namespaced capability, a virtualized representation of it is returned if the caller is in a user namespace owned by the capability's owning rootid. The function which performs this virtualization was not hooked up if CONFIG_SECURITY=n. Therefore in that case the original xattr was shown instead of the virtualized one.

To test this using libcap-bin (*1),

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin-eip $v
$ unshare -Ur setcap -v cap_sys_admin-eip $v
/tmp/tmp.lSiIFRvt8Y: OK

"setcap -v" verifies the values instead of setting them, and will check whether the rootid value is set. Therefore, with this bug un-fixed, and with CONFIG_SECURITY=n, setcap -v will fail:

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin=eip $v
$ unshare -Ur setcap -v cap_sys_admin=eip $v
nsowner[got=1000, want=0],/tmp/tmp.HHDiOOl9fY differs in []

Fix this bug by calling cap_inode_getsecurity() in security_inode_getsecurity() instead of returning -EOPNOTSUPP, when CONFIG_SECURITY=n.

*1 - note, if libcap is too old for getcap to have the '-n' option, then use verify-caps instead.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1593431
Cc: Hervé Guillemet <[email protected]>
Cc: Andrew G. Morgan <[email protected]>
Cc: Casey Schaufler <[email protected]>

---
 include/linux/security.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/security.h +1 -1
index bc2725491560..39642626a707 100644
@@ -869,7 +869,7 @@ static inline int security_inode_killpriv(struct
 dentry *dentry)
 
 static inline int security_inode_getsecurity(struct inode *inode, const
 char *name, void **buffer, bool alloc)
 {
-       return -EOPNOTSUPP;
+       return cap_inode_getsecurity(inode, name, buffer, alloc);
 }
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines

static inline int security_inode_setsecurity(struct inode *inode, const
char *name, const void *value, size_t size, int flags)
--
2.25.1

--
James Morris
<[email protected]>

author maintainer
#12 lore raw
In reply to Andrew G. Morgan

How odd - where did that come from?

James, I force-pushed that with corrected bugzilla link to 2020-11-29/fix-nscaps. Sorry about that.

Quoted 93 lines · Andrew G. Morgan

The correct bug reference for this patch is:

https://bugzilla.kernel.org/show_bug.cgi?id=209689

Quoted 86 lines · James Morris
Quoted 4 lines · Serge E. Hallyn

Hi James,

would you mind adding this to the security tree? (You can cherrypick
from https://git.kernel.org/pub/scm/linux/kernel/git/sergeh/linux.git/commit/?h=2020-11-29/fix-nscaps )

Sure.

Quoted 65 lines

thanks,
-serge

Quoted 60 lines · Andrew G. Morgan
Quoted 55 lines · Serge E. Hallyn

Namespaced file capabilities were introduced in 8db6c34f1dbc . When userspace reads an xattr for a namespaced capability, a virtualized representation of it is returned if the caller is in a user namespace owned by the capability's owning rootid. The function which performs this virtualization was not hooked up if CONFIG_SECURITY=n. Therefore in that case the original xattr was shown instead of the virtualized one.

To test this using libcap-bin (*1),

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin-eip $v
$ unshare -Ur setcap -v cap_sys_admin-eip $v
/tmp/tmp.lSiIFRvt8Y: OK

"setcap -v" verifies the values instead of setting them, and will check whether the rootid value is set. Therefore, with this bug un-fixed, and with CONFIG_SECURITY=n, setcap -v will fail:

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin=eip $v
$ unshare -Ur setcap -v cap_sys_admin=eip $v
nsowner[got=1000, want=0],/tmp/tmp.HHDiOOl9fY differs in []

Fix this bug by calling cap_inode_getsecurity() in security_inode_getsecurity() instead of returning -EOPNOTSUPP, when CONFIG_SECURITY=n.

*1 - note, if libcap is too old for getcap to have the '-n' option, then use verify-caps instead.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1593431
Cc: Hervé Guillemet <[email protected]>
Cc: Andrew G. Morgan <[email protected]>
Cc: Casey Schaufler <[email protected]>

---
 include/linux/security.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/security.h +1 -1
index bc2725491560..39642626a707 100644
@@ -869,7 +869,7 @@ static inline int security_inode_killpriv(struct
 dentry *dentry)
 
 static inline int security_inode_getsecurity(struct inode *inode, const
 char *name, void **buffer, bool alloc)
 {
-       return -EOPNOTSUPP;
+       return cap_inode_getsecurity(inode, name, buffer, alloc);
 }
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines

static inline int security_inode_setsecurity(struct inode *inode, const
char *name, const void *value, size_t size, int flags)
--
2.25.1

--
James Morris
<[email protected]>

author maintainer
#13 lore raw

Oh, I see you'd changed it inline :) Thanks

Quoted 99 lines · Serge E. Hallyn

How odd - where did that come from?

James, I force-pushed that with corrected bugzilla link to 2020-11-29/fix-nscaps. Sorry about that.

Quoted 93 lines · Andrew G. Morgan

The correct bug reference for this patch is:

https://bugzilla.kernel.org/show_bug.cgi?id=209689

Quoted 86 lines · James Morris
Quoted 4 lines · Serge E. Hallyn

Hi James,

would you mind adding this to the security tree? (You can cherrypick
from https://git.kernel.org/pub/scm/linux/kernel/git/sergeh/linux.git/commit/?h=2020-11-29/fix-nscaps )

Sure.

Quoted 65 lines

thanks,
-serge

Quoted 60 lines · Andrew G. Morgan
Quoted 55 lines · Serge E. Hallyn

Namespaced file capabilities were introduced in 8db6c34f1dbc . When userspace reads an xattr for a namespaced capability, a virtualized representation of it is returned if the caller is in a user namespace owned by the capability's owning rootid. The function which performs this virtualization was not hooked up if CONFIG_SECURITY=n. Therefore in that case the original xattr was shown instead of the virtualized one.

To test this using libcap-bin (*1),

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin-eip $v
$ unshare -Ur setcap -v cap_sys_admin-eip $v
/tmp/tmp.lSiIFRvt8Y: OK

"setcap -v" verifies the values instead of setting them, and will check whether the rootid value is set. Therefore, with this bug un-fixed, and with CONFIG_SECURITY=n, setcap -v will fail:

$ v=$(mktemp)
$ unshare -Ur setcap cap_sys_admin=eip $v
$ unshare -Ur setcap -v cap_sys_admin=eip $v
nsowner[got=1000, want=0],/tmp/tmp.HHDiOOl9fY differs in []

Fix this bug by calling cap_inode_getsecurity() in security_inode_getsecurity() instead of returning -EOPNOTSUPP, when CONFIG_SECURITY=n.

*1 - note, if libcap is too old for getcap to have the '-n' option, then use verify-caps instead.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1593431
Cc: Hervé Guillemet <[email protected]>
Cc: Andrew G. Morgan <[email protected]>
Cc: Casey Schaufler <[email protected]>

---
 include/linux/security.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/security.h +1 -1
index bc2725491560..39642626a707 100644
@@ -869,7 +869,7 @@ static inline int security_inode_killpriv(struct
 dentry *dentry)
 
 static inline int security_inode_getsecurity(struct inode *inode, const
 char *name, void **buffer, bool alloc)
 {
-       return -EOPNOTSUPP;
+       return cap_inode_getsecurity(inode, name, buffer, alloc);
 }
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines

static inline int security_inode_setsecurity(struct inode *inode, const
char *name, const void *value, size_t size, int flags)
--
2.25.1

--
James Morris
<[email protected]>