From patchwork Sat Aug 13 20:36:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 9279313 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1010760231 for ; Sun, 14 Aug 2016 11:49:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00A4C289E6 for ; Sun, 14 Aug 2016 11:49:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E977128A5D; Sun, 14 Aug 2016 11:49:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CEF5289E6 for ; Sun, 14 Aug 2016 11:49:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934785AbcHNLtT (ORCPT ); Sun, 14 Aug 2016 07:49:19 -0400 Received: from nm45-vm7.bullet.mail.bf1.yahoo.com ([216.109.115.78]:40790 "EHLO nm45-vm7.bullet.mail.bf1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934780AbcHNLtS (ORCPT ); Sun, 14 Aug 2016 07:49:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1471120576; bh=BbHCwNx1DAjLM/pAeli28HxnoLTWI3fAPhVDd+TrfeA=; h=Subject:To:References:Cc:From:Date:In-Reply-To:From:Subject; b=Q2PinqlTvT7Nc54sim5iLCdrFAJOIgnGvNQEtp7oEwBEIRqN+vfBFSht2IHevzdujggdnuvNfBLjs4ih7hzTTT7h/Vs0wnVor44XcVZkeCqzCKzPktF/IvHUOp/JwEGANPHNA82bHVC3EF6g9pfFeA0VMA8l+HFfax7YPs0Sbh3VdW9QAxqhj8fETMAVv46XGSffaEAEBk+Fs4VjRMiowyN16w6MG2QM6WUuBso5UieLiKi6GLcd86PAW0VmueFa/wjk1W28ULbVRTzHjybbPe2PO+T1Ajp51EPUgXnzQypIfW/DnjH9G2DXyQUT2xvB2wy+FL8SCwJu3MM0+AFpkg== Received: from [66.196.81.171] by nm45.bullet.mail.bf1.yahoo.com with NNFMP; 13 Aug 2016 20:36:16 -0000 Received: from [98.139.211.199] by tm17.bullet.mail.bf1.yahoo.com with NNFMP; 13 Aug 2016 20:36:16 -0000 Received: from [127.0.0.1] by smtp208.mail.bf1.yahoo.com with NNFMP; 13 Aug 2016 20:36:16 -0000 X-Yahoo-Newman-Id: 866721.90135.bm@smtp208.mail.bf1.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: _5rUtZMVM1nR1JB_wSrZQCjU0TAggx_I02g9.GiRoivpDUn EhnHXxDrOmUrj0k8gkh5qEnsyIYXYAUczEWqGcnm3J7raJbty9dPg47z6NwB VfV0VAMHzqDu_JPUGUpX34kC1UtR0xOQm1J0h61cgW.nVPLxBPv6yZWJO4ou tt0hVIs1bp0jwHPDcYrMWcrakX_us46g4rG5WOgSEApdwdtPurJqFgfz6voe p7dNIOw8.mmLYLy_7PzImWc3Hp2u4r.2XcKPnX7ZK1fCcgO13pj1XzDodZf7 aZ6ez_p2AS9NPGllZiOD8MnpsgxmmwAjjYDjTO9eMJfZ_jz9LRDGoDNyQO5. VnlSsah7n.HdbbyfRQf6PvZfD5lvDQRmsARPYTFPINel0beCX4FHqCQSPmMk oD9G7b6n8DfsC_xINsnNiDYr4Se51WrMpL.OlKAvimCpmHT3VYK26vqWi6ED nxYgwXrzgzz1OmDLDsSLcy6zuqtX1YJmtmummz9i6cV4CwBXkalfke3QeTpq OthL8a4EkPfWmEDu6XVq8sO9ZPAo1nCbsvY0CcEUXvZG_DSVLbNlvzHkxc62 N88reBG2TShtJ X-Yahoo-SMTP: OIJXglSswBDfgLtXluJ6wiAYv6_cnw-- Subject: [PATCH 09/25] AppArmor: Abstract the file security blob To: LSM , James Morris References: <801ef9a9-e594-387c-f285-8d90879ee2bf@schaufler-ca.com> Cc: John Johansen , Tetsuo Handa , Paul Moore , Stephen Smalley From: Casey Schaufler Message-ID: Date: Sat, 13 Aug 2016 13:36:15 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <801ef9a9-e594-387c-f285-8d90879ee2bf@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Subject: [PATCH 09/25] AppArmor: Abstract the file security blob Abstract reading the file security blob. Remove abstraction when writing the file security blob. There is no change in the behavior of the code. Signed-off-by: Casey Schaufler --- security/apparmor/include/context.h | 6 ++++++ security/apparmor/lsm.c | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/security/apparmor/include/context.h b/security/apparmor/include/context.h index 07fb7a1..c140aad 100644 --- a/security/apparmor/include/context.h +++ b/security/apparmor/include/context.h @@ -24,6 +24,7 @@ #define cred_cxt(X) apparmor_cred(X) #define current_cxt() cred_cxt(current_cred()) +#define file_cxt(X) apparmor_file(X) /* struct aa_file_cxt - the AppArmor context the file was opened in * @perms: the permission the file was opened with @@ -91,6 +92,11 @@ static inline struct aa_task_cxt *apparmor_cred(const struct cred *cred) return cred->security; } +static inline struct aa_file_cxt *apparmor_file(const struct file *file) +{ + return file->f_security; +} + /** * aa_cred_profile - obtain cred's profiles * @cred: cred to obtain profiles from (NOT NULL) diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 1b26774..c91ce01 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -321,7 +321,7 @@ static int apparmor_inode_getattr(const struct path *path) static int apparmor_file_open(struct file *file, const struct cred *cred) { - struct aa_file_cxt *fcxt = file->f_security; + struct aa_file_cxt *fcxt = file_cxt(file); struct aa_profile *profile; int error = 0; @@ -364,14 +364,14 @@ static int apparmor_file_alloc_security(struct file *file) static void apparmor_file_free_security(struct file *file) { - struct aa_file_cxt *cxt = file->f_security; + struct aa_file_cxt *cxt = file_cxt(file); aa_free_file_context(cxt); } static int common_file_perm(int op, struct file *file, u32 mask) { - struct aa_file_cxt *fcxt = file->f_security; + struct aa_file_cxt *fcxt = file_cxt(file); struct aa_profile *profile, *fprofile = aa_cred_profile(file->f_cred); int error = 0; @@ -417,7 +417,7 @@ static int common_mmap(int op, struct file *file, unsigned long prot, { int mask = 0; - if (!file || !file->f_security) + if (!file || file_cxt(file) == NULL) return 0; if (prot & PROT_READ)