summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorRichard Weinberger <richard@nod.at>2016-09-21 12:21:29 +0200
committerRichard Weinberger <richard@nod.at>2016-12-12 23:07:38 +0100
commit43b113fea2d427e17e7663494fc70c4e93e83d5e (patch)
tree7ba1c37358d90bd2f351e7d32a866fcbe1303b4c /fs
parentubifs: Add skeleton for fscrypto (diff)
downloadlinux-43b113fea2d427e17e7663494fc70c4e93e83d5e.tar.xz
linux-43b113fea2d427e17e7663494fc70c4e93e83d5e.zip
ubifs: Massage ubifs_listxattr() for encryption context
We have to make sure that we don't expose our internal crypto context to userspace. Signed-off-by: Richard Weinberger <richard@nod.at>
Diffstat (limited to 'fs')
-rw-r--r--fs/ubifs/xattr.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/fs/ubifs/xattr.c b/fs/ubifs/xattr.c
index 95a16028bbdb..77ffc9788f45 100644
--- a/fs/ubifs/xattr.c
+++ b/fs/ubifs/xattr.c
@@ -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;
}