Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933850AbcJUM7Q (ORCPT ); Fri, 21 Oct 2016 08:59:16 -0400 Received: from mail.sigma-star.at ([95.130.255.111]:46003 "EHLO mail.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933144AbcJUMtQ (ORCPT ); Fri, 21 Oct 2016 08:49:16 -0400 From: Richard Weinberger To: linux-mtd@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, dedekind1@gmail.com, adrian.hunter@intel.com, tytso@mit.edu, jaegeuk@kernel.org, david@sigma-star.at, wd@denx.de, sbabic@denx.de, dengler@linutronix.de, Richard Weinberger Subject: [PATCH 07/26] ubifs: Massage ubifs_listxattr() for encryption context Date: Fri, 21 Oct 2016 14:48:22 +0200 Message-Id: <1477054121-10198-8-git-send-email-richard@nod.at> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1477054121-10198-1-git-send-email-richard@nod.at> References: <1477054121-10198-1-git-send-email-richard@nod.at> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1379 Lines: 47 We have to make sure that we don't expose our internal crypto context to userspace. Signed-off-by: Richard Weinberger --- fs/ubifs/xattr.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/fs/ubifs/xattr.c b/fs/ubifs/xattr.c index b390902c48aa..54ec2b9fd506 100644 --- a/fs/ubifs/xattr.c +++ b/fs/ubifs/xattr.c @@ -394,6 +394,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; @@ -429,10 +443,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; } -- 2.7.3