]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
ubifs: Massage ubifs_listxattr() for encryption context
authorRichard Weinberger <richard@nod.at>
Wed, 21 Sep 2016 10:21:29 +0000 (12:21 +0200)
committerRichard Weinberger <richard@nod.at>
Mon, 12 Dec 2016 22:07:38 +0000 (23:07 +0100)
We have to make sure that we don't expose our internal
crypto context to userspace.

Signed-off-by: Richard Weinberger <richard@nod.at>
fs/ubifs/xattr.c

index 95a16028bbdb8ec324466b5c6eb0e9954127ef93..77ffc9788f45141e51d494b5199466ca08c0684c 100644 (file)
@@ -397,6 +397,20 @@ out_unlock:
        return err;
 }
 
+static bool xattr_visible(const char *name)
+{
+       /* File encryption related xattrs are for internal use only */
+       if (strcmp(name, UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT) == 0)
+               return false;
+
+       /* Show trusted namespace only for "power" users */
+       if (strncmp(name, XATTR_TRUSTED_PREFIX,
+                   XATTR_TRUSTED_PREFIX_LEN) == 0 && !capable(CAP_SYS_ADMIN))
+               return false;
+
+       return true;
+}
+
 ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size)
 {
        union ubifs_key key;
@@ -432,10 +446,7 @@ ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size)
                nm.name = xent->name;
                nm.len = le16_to_cpu(xent->nlen);
 
-               /* Show trusted namespace only for "power" users */
-               if (strncmp(xent->name, XATTR_TRUSTED_PREFIX,
-                           XATTR_TRUSTED_PREFIX_LEN) ||
-                   capable(CAP_SYS_ADMIN)) {
+               if (xattr_visible(xent->name)) {
                        memcpy(buffer + written, nm.name, nm.len + 1);
                        written += nm.len + 1;
                }