From patchwork Thu Jun 2 12:23:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mimi Zohar X-Patchwork-Id: 843652 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 p52CSasq020174 for ; Thu, 2 Jun 2011 12:28:38 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933631Ab1FBM2Q (ORCPT ); Thu, 2 Jun 2011 08:28:16 -0400 Received: from e7.ny.us.ibm.com ([32.97.182.137]:52500 "EHLO e7.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161089Ab1FBMZa (ORCPT ); Thu, 2 Jun 2011 08:25:30 -0400 Received: from d01relay05.pok.ibm.com (d01relay05.pok.ibm.com [9.56.227.237]) by e7.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p52C1kEp007035; Thu, 2 Jun 2011 08:01:46 -0400 Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay05.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p52CPTQl095238; Thu, 2 Jun 2011 08:25:29 -0400 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p528PFiJ018123; Thu, 2 Jun 2011 05:25:17 -0300 Received: from localhost.localdomain.com (sig-9-65-99-133.mts.ibm.com [9.65.99.133]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p528NwCL011471; Thu, 2 Jun 2011 05:25:15 -0300 From: Mimi Zohar To: linux-security-module@vger.kernel.org Cc: Mimi Zohar , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, James Morris , David Safford , Andrew Morton , Greg KH , Dmitry Kasatkin , Chris Mason , linux-btrfs@vger.kernel.org, Mimi Zohar Subject: [PATCH v6 11/20] evm: add evm_inode_post_init call in btrfs Date: Thu, 2 Jun 2011 08:23:34 -0400 Message-Id: <1307017423-15093-12-git-send-email-zohar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1307017423-15093-1-git-send-email-zohar@linux.vnet.ibm.com> References: <1307017423-15093-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]); Thu, 02 Jun 2011 12:28:38 +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 f3107e4..8e9afcb2 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; }