From patchwork Mon May 16 14:45:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mimi Zohar X-Patchwork-Id: 788272 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4GEmFBB004538 for ; Mon, 16 May 2011 14:48:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756165Ab1EPOrh (ORCPT ); Mon, 16 May 2011 10:47:37 -0400 Received: from e32.co.us.ibm.com ([32.97.110.150]:50006 "EHLO e32.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755799Ab1EPOrf (ORCPT ); Mon, 16 May 2011 10:47:35 -0400 Received: from d03relay03.boulder.ibm.com (d03relay03.boulder.ibm.com [9.17.195.228]) by e32.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id p4GEa6KM017893; Mon, 16 May 2011 08:36:06 -0600 Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d03relay03.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p4GElKal075186; Mon, 16 May 2011 08:47:22 -0600 Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p4G8lEwj014038; Mon, 16 May 2011 02:47:16 -0600 Received: from localhost.localdomain.com (sig-9-76-29-246.mts.ibm.com [9.76.29.246]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p4G8jJsx005923; Mon, 16 May 2011 02:47:12 -0600 From: Mimi Zohar To: linux-security-module@vger.kernel.org Cc: Mimi Zohar , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, James Morris , David Safford , Andrew Morton , Greg KH , Dmitry Kasatkin , Chris Mason , Mimi Zohar Subject: [PATCH v5 12/21] evm: add evm_inode_post_init call in btrfs Date: Mon, 16 May 2011 10:45:06 -0400 Message-Id: <1305557115-15652-13-git-send-email-zohar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1305557115-15652-1-git-send-email-zohar@linux.vnet.ibm.com> References: <1305557115-15652-1-git-send-email-zohar@linux.vnet.ibm.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Mon, 16 May 2011 14:48:15 +0000 (UTC) After creating the initial LSM security extended attribute, call evm_inode_post_init_security() to create the 'security.evm' extended attribute. Signed-off-by: Mimi Zohar --- fs/btrfs/xattr.c | 39 +++++++++++++++++++++++++++++---------- 1 files changed, 29 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c index cfd6605..df07619 100644 --- a/fs/btrfs/xattr.c +++ b/fs/btrfs/xattr.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "ctree.h" #include "btrfs_inode.h" #include "transaction.h" @@ -367,31 +368,49 @@ int btrfs_xattr_security_init(struct btrfs_trans_handle *trans, const struct qstr *qstr) { int err; - size_t len; - void *value; - char *suffix; + struct xattr lsm_xattr; + struct xattr evm_xattr; char *name; - err = security_inode_init_security(inode, dir, qstr, &suffix, &value, - &len); + err = security_inode_init_security(inode, dir, qstr, &lsm_xattr.name, + &lsm_xattr.value, + &lsm_xattr.value_len); if (err) { if (err == -EOPNOTSUPP) return 0; return err; } - name = kmalloc(XATTR_SECURITY_PREFIX_LEN + strlen(suffix) + 1, + name = kmalloc(XATTR_SECURITY_PREFIX_LEN + strlen(lsm_xattr.name) + 1, GFP_NOFS); if (!name) { err = -ENOMEM; } else { strcpy(name, XATTR_SECURITY_PREFIX); - strcpy(name + XATTR_SECURITY_PREFIX_LEN, suffix); - err = __btrfs_setxattr(trans, inode, name, value, len, 0); + strcpy(name + XATTR_SECURITY_PREFIX_LEN, lsm_xattr.name); + err = __btrfs_setxattr(trans, inode, name, lsm_xattr.value, + lsm_xattr.value_len, 0); kfree(name); } + if (err) + goto out; + + err = evm_inode_post_init_security(inode, &lsm_xattr, &evm_xattr); + if (err) + goto out; - kfree(suffix); - kfree(value); + name = kasprintf(GFP_NOFS, "%s%s", XATTR_SECURITY_PREFIX, + evm_xattr.name); + if (!name) + err = -ENOMEM; + else { + err = __btrfs_setxattr(trans, inode, name, evm_xattr.value, + evm_xattr.value_len, 0); + kfree(name); + } + kfree(evm_xattr.value); +out: + kfree(lsm_xattr.name); + kfree(lsm_xattr.value); return err; }