Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp26807imm; Fri, 21 Sep 2018 17:21:22 -0700 (PDT) X-Google-Smtp-Source: ACcGV60SppfWDty6eYxtJIJqjW+fh5GgulaSV9fvz8TX8VWVi3LwGG932wjgtYgiufrdpr9zEz2C X-Received: by 2002:a63:4281:: with SMTP id p123-v6mr107753pga.91.1537575682200; Fri, 21 Sep 2018 17:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537575682; cv=none; d=google.com; s=arc-20160816; b=0boREKDNOdAiLxdBW1yuKgc85o8aS/d03mUJ984FU1KNaghZmPhfyTbdjLnIfvaLKB 2TfAPOWsz0HoX1xCmtWz5pPEDKfjk5NTe4+wWQTw+4RLNBaU4QxoxSwKyG23mIUIpanB 8C1h2axFB1KtvmChmp4FI5XAfBzbnpS9uLFnzk59mxyzfZeuzjWFmp/0M68ZUE4o2ZhC sd+80KbRkvmpDOznss+pUlsa4wCHOYVPMNF1u1Rdn/LNrycvdRyg7HWsGHeszrDVnWSk GN/CBSQdO9aUNqJiA1DceODVsRbDcWhXw1C+K2vtSgP+KT54H98sV9IWGBrzBWrTirrS POCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature; bh=e5xnuvmG768OyriYI2Q3ymRBgxIuzqd5VowbgFQFpQs=; b=cqWzbvEtWvk3pxJT+XNvVC96ptROiEHeKzsxitqgi53jG1qDJaWZ9W6BEJgpl2fNK0 XL4dBw9zWSX/xiYsZAzhwh29/MI1z3RPKBdyV1RuIAFEpZHd9PufImXvmp5Ewt8FQqzV K6rqsffTXoN0URAgI0gVRGfEPNPeVJhLwxCJuqecmXlURiDPBpnEmW1yvvpTVk5NuDmy gkKEIWRfQsAfjJVNyrJslWtNyLZWxd09Ik91qw/QqvQmE8kRFN0CYISTT6FjisZ1Gs3T coLIgGAHK2Tu1uKT7Et4lPd3zHA/HjLtHbgP4uMsnkZvtx0cdHkqZAYZOkKC5FvkD3lo WjGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=U8LYwSsr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e26-v6si4849616pgb.161.2018.09.21.17.21.06; Fri, 21 Sep 2018 17:21:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=U8LYwSsr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391834AbeIVGKh (ORCPT + 99 others); Sat, 22 Sep 2018 02:10:37 -0400 Received: from sonic305-10.consmr.mail.bf2.yahoo.com ([74.6.133.49]:42733 "EHLO sonic305-10.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391823AbeIVGKg (ORCPT ); Sat, 22 Sep 2018 02:10:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1537575558; bh=e5xnuvmG768OyriYI2Q3ymRBgxIuzqd5VowbgFQFpQs=; h=Subject:To:References:From:Date:In-Reply-To:From:Subject; b=U8LYwSsrlGYsVnrJodiQXH601VhkjYWXBE0sW5S3GZwABtsd7G6KrNcVPUL0b7yeY9eOLuwfcR+JgPRMf1NODQDjwTo4K2s82b6NGl8YMOoaizuqb12tP+UuZhGhEusULc4z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sm5_ui7yR_OCOxEQ52nBlbZXvxRAckv.2vcNmx62yCSceE qkrfdfOsZYLkBnF2R_YOt1IaU8CyiDIGhVK8J9F6PBSgadfVMI63lqUN6VqZlUhbrC5L.81GtI28 GnS3Oksec5lAWyhmfo3PmSEQbCUdkisvdgktoy5fgBf9LhmoD.9jYiZVnN242Rd.PUhrcAYkijmq ARNwJb68a7szmJzNwrFfa_MgjyHEbhMq6iwLJVW2z8Q-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.bf2.yahoo.com with HTTP; Sat, 22 Sep 2018 00:19:18 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO [192.168.0.102]) ([67.169.65.224]) by smtp424.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID fa508117aad77ec105d372d13cfd6c60; Sat, 22 Sep 2018 00:19:16 +0000 (UTC) Subject: [PATCH v4 12/19] SELinux: Abstract use of inode security blob To: LSM , James Morris , SE Linux , LKLM , John Johansen , Kees Cook , Tetsuo Handa , Paul Moore , Stephen Smalley , "linux-fsdevel@vger.kernel.org" , Alexey Dobriyan , =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= , Salvatore Mesoraca References: From: Casey Schaufler Message-ID: <0a85567d-fde1-8272-d79e-b15d5b094b47@schaufler-ca.com> Date: Fri, 21 Sep 2018 17:19:11 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Don't use the inode->i_security pointer directly. Provide a helper function that provides the security blob pointer. Signed-off-by: Casey Schaufler Reviewed-by: Kees Cook --- security/selinux/hooks.c | 26 +++++++++++++------------- security/selinux/include/objsec.h | 6 ++++++ security/selinux/selinuxfs.c | 4 ++-- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index fdda53552224..248ae907320f 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -275,7 +275,7 @@ static int __inode_security_revalidate(struct inode *inode, struct dentry *dentry, bool may_sleep) { - struct inode_security_struct *isec = inode->i_security; + struct inode_security_struct *isec = selinux_inode(inode); might_sleep_if(may_sleep); @@ -296,7 +296,7 @@ static int __inode_security_revalidate(struct inode *inode, static struct inode_security_struct *inode_security_novalidate(struct inode *inode) { - return inode->i_security; + return selinux_inode(inode); } static struct inode_security_struct *inode_security_rcu(struct inode *inode, bool rcu) @@ -306,7 +306,7 @@ static struct inode_security_struct *inode_security_rcu(struct inode *inode, boo error = __inode_security_revalidate(inode, NULL, !rcu); if (error) return ERR_PTR(error); - return inode->i_security; + return selinux_inode(inode); } /* @@ -315,14 +315,14 @@ static struct inode_security_struct *inode_security_rcu(struct inode *inode, boo static struct inode_security_struct *inode_security(struct inode *inode) { __inode_security_revalidate(inode, NULL, true); - return inode->i_security; + return selinux_inode(inode); } static struct inode_security_struct *backing_inode_security_novalidate(struct dentry *dentry) { struct inode *inode = d_backing_inode(dentry); - return inode->i_security; + return selinux_inode(inode); } /* @@ -333,7 +333,7 @@ static struct inode_security_struct *backing_inode_security(struct dentry *dentr struct inode *inode = d_backing_inode(dentry); __inode_security_revalidate(inode, dentry, true); - return inode->i_security; + return selinux_inode(inode); } static void inode_free_rcu(struct rcu_head *head) @@ -346,7 +346,7 @@ static void inode_free_rcu(struct rcu_head *head) static void inode_free_security(struct inode *inode) { - struct inode_security_struct *isec = inode->i_security; + struct inode_security_struct *isec = selinux_inode(inode); struct superblock_security_struct *sbsec = inode->i_sb->s_security; /* @@ -1500,7 +1500,7 @@ static int selinux_genfs_get_sid(struct dentry *dentry, static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dentry) { struct superblock_security_struct *sbsec = NULL; - struct inode_security_struct *isec = inode->i_security; + struct inode_security_struct *isec = selinux_inode(inode); u32 task_sid, sid = 0; u16 sclass; struct dentry *dentry; @@ -1800,7 +1800,7 @@ static int inode_has_perm(const struct cred *cred, return 0; sid = cred_sid(cred); - isec = inode->i_security; + isec = selinux_inode(inode); return avc_has_perm(&selinux_state, sid, isec->sid, isec->sclass, perms, adp); @@ -3028,7 +3028,7 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir, /* Possibly defer initialization to selinux_complete_init. */ if (sbsec->flags & SE_SBINITIALIZED) { - struct inode_security_struct *isec = inode->i_security; + struct inode_security_struct *isec = selinux_inode(inode); isec->sclass = inode_mode_to_security_class(inode->i_mode); isec->sid = newsid; isec->initialized = LABEL_INITIALIZED; @@ -3128,7 +3128,7 @@ static noinline int audit_inode_permission(struct inode *inode, unsigned flags) { struct common_audit_data ad; - struct inode_security_struct *isec = inode->i_security; + struct inode_security_struct *isec = selinux_inode(inode); int rc; ad.type = LSM_AUDIT_DATA_INODE; @@ -4148,7 +4148,7 @@ static int selinux_task_kill(struct task_struct *p, struct siginfo *info, static void selinux_task_to_inode(struct task_struct *p, struct inode *inode) { - struct inode_security_struct *isec = inode->i_security; + struct inode_security_struct *isec = selinux_inode(inode); u32 sid = task_sid(p); spin_lock(&isec->lock); @@ -6527,7 +6527,7 @@ static void selinux_release_secctx(char *secdata, u32 seclen) static void selinux_inode_invalidate_secctx(struct inode *inode) { - struct inode_security_struct *isec = inode->i_security; + struct inode_security_struct *isec = selinux_inode(inode); spin_lock(&isec->lock); isec->initialized = LABEL_INVALID; diff --git a/security/selinux/include/objsec.h b/security/selinux/include/objsec.h index cad8b765f6dd..ea1687e737ad 100644 --- a/security/selinux/include/objsec.h +++ b/security/selinux/include/objsec.h @@ -170,4 +170,10 @@ static inline struct file_security_struct *selinux_file(const struct file *file) return file->f_security; } +static inline struct inode_security_struct *selinux_inode( + const struct inode *inode) +{ + return inode->i_security; +} + #endif /* _SELINUX_OBJSEC_H_ */ diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c index f3a5a138a096..145ee62f205a 100644 --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c @@ -1378,7 +1378,7 @@ static int sel_make_bools(struct selinux_fs_info *fsi) goto out; } - isec = (struct inode_security_struct *)inode->i_security; + isec = selinux_inode(inode); ret = security_genfs_sid(fsi->state, "selinuxfs", page, SECCLASS_FILE, &sid); if (ret) { @@ -1953,7 +1953,7 @@ static int sel_fill_super(struct super_block *sb, void *data, int silent) } inode->i_ino = ++fsi->last_ino; - isec = (struct inode_security_struct *)inode->i_security; + isec = selinux_inode(inode); isec->sid = SECINITSID_DEVNULL; isec->sclass = SECCLASS_CHR_FILE; isec->initialized = LABEL_INITIALIZED; -- 2.17.1