Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4296765imm; Tue, 11 Sep 2018 09:44:00 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYgWquXVVye9NQluR7ATreqGNkfW6MpFN96n1/7TJRd3kNYUAkLfGOJW4DQqIrm0i8jSTB+ X-Received: by 2002:a17:902:b089:: with SMTP id p9-v6mr28106404plr.254.1536684240915; Tue, 11 Sep 2018 09:44:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536684240; cv=none; d=google.com; s=arc-20160816; b=ogVKypHETOrLCH8xpoeOuyuuBq6XGVyCXsCq4QiwRt+i48jr+LlQqCl9dcbxQFqoh4 X7ZX0MZQkhXzmONR4NsMw3LA/Vp1kooGpj6E20EgOTRuXW+WZ/6lQBNl11pJ8gVSHEc9 +wai7IzcVnItKjBGqmjsvhYcIvMTOf2pxLKa/j+n5+ylc4AI5JR6RM9QJ/G2war+20Ve qu6tKc/3NRA0uMvpKjibiU9FOs0YriPuUSjAN/6bM3MCU5vXKNuMMUGpw8u3+Gni7atG ITwdGu63Lwsmr64yromZwkjZxDGaWWRXNgnMWR2s8rAh8T3ZR9Ki6+PbNPNsBjH3OfBg OkZA== 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:cc:to:subject:dkim-signature; bh=4ClzVXf1c1vpYtXQSRli2QiS1/B1yPxp/XJLpx83RE4=; b=Xe/EJ3HsZj/VCEBrqgauBU8Vl6KziqIDxLdwp/1H71w6P0P8zyBJwRc1VWL20zmaL5 QUp+2aGf2qhmPM8MDNEIRyGxqqkP4cAVtdKq+B8q4eyyr2SZeOLfb4R3E1MIPZldfFXl ghYm8hQgHoHzkGO+LsBMry5PH7yAnyGnDc7F4fS8JlzpCoNGZ8k6FeQxejHqCxkyZiHK fZLmsRUTTIQxfI+Z4pt+JTRLuuUNT4v5ZLfEogiJHniyW727XzbItSg265PDEx3/+NHe F/PoW/eKZPEkeXu2LM6hs9L9aR3TJyvba2jZZXes9mEc3uaMknRl8gsj7/g3hSD6RJ+5 vcDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=NOQLHU2W; 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 71-v6si20481005pla.92.2018.09.11.09.43.45; Tue, 11 Sep 2018 09:44:00 -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=NOQLHU2W; 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 S1728125AbeIKVmO (ORCPT + 99 others); Tue, 11 Sep 2018 17:42:14 -0400 Received: from sonic304-27.consmr.mail.ne1.yahoo.com ([66.163.191.153]:44294 "EHLO sonic304-27.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728111AbeIKVmM (ORCPT ); Tue, 11 Sep 2018 17:42:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1536684124; bh=4ClzVXf1c1vpYtXQSRli2QiS1/B1yPxp/XJLpx83RE4=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=NOQLHU2WEBVGd+KCIdBFuayYNSCLu+XTn9qEt735RL789OIiAHNfySu7yZrEAdGe3OVms54e2Lc1BSdS536uCvdM2pvueoV0UOxaRlIYg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RxlVQL.dGduRp68yqEZx55bUJdFjZdzGEQQeaZG4spXqTfjgLnoGE4.n0aqBAR0kPyBxvK Cfphi8lfiG8xR3LjkS6IBtK8i2i.KeLVnHfJCRHK93yX8leI8ar0BNJTXEa3ylE93PVVVmisoL89 nt3iY8wgwTnJGLznmWUck9yB37Yed5t7.dUyZC9UdGoXosFFdTlKvAZuCRyDkkPtOJWqx11fw6ut ShS6rfinXqeyEI0e729ygTYWP_Gy8FiAnQ9KQ Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Tue, 11 Sep 2018 16:42:04 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO [192.168.0.102]) ([67.169.65.224]) by smtp415.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID fa9305f2bb603b002ee5198a503b0a13; Tue, 11 Sep 2018 16:42:01 +0000 (UTC) Subject: [PATCH 05/10] SELinux: Abstract use of file security blob To: LSM , James Morris , LKLM , SE Linux , John Johansen , Kees Cook , Tetsuo Handa , Paul Moore , Stephen Smalley , "linux-fsdevel@vger.kernel.org" , Alexey Dobriyan Cc: "Schaufler, Casey" References: From: Casey Schaufler Message-ID: <65bccad6-5669-9f4a-a645-35e0da301817@schaufler-ca.com> Date: Tue, 11 Sep 2018 09:41:58 -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 file->f_security pointer directly. Provide a helper function that provides the security blob pointer. Signed-off-by: Casey Schaufler --- security/selinux/hooks.c | 18 +++++++++--------- security/selinux/include/objsec.h | 5 +++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 9b49698754a7..94b3123c237b 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -397,7 +397,7 @@ static int file_alloc_security(struct file *file) static void file_free_security(struct file *file) { - struct file_security_struct *fsec = file->f_security; + struct file_security_struct *fsec = selinux_file(file); file->f_security = NULL; kmem_cache_free(file_security_cache, fsec); } @@ -1880,7 +1880,7 @@ static int file_has_perm(const struct cred *cred, struct file *file, u32 av) { - struct file_security_struct *fsec = file->f_security; + struct file_security_struct *fsec = selinux_file(file); struct inode *inode = file_inode(file); struct common_audit_data ad; u32 sid = cred_sid(cred); @@ -2224,7 +2224,7 @@ static int selinux_binder_transfer_file(struct task_struct *from, struct file *file) { u32 sid = task_sid(to); - struct file_security_struct *fsec = file->f_security; + struct file_security_struct *fsec = selinux_file(file); struct dentry *dentry = file->f_path.dentry; struct inode_security_struct *isec; struct common_audit_data ad; @@ -3536,7 +3536,7 @@ static int selinux_revalidate_file_permission(struct file *file, int mask) static int selinux_file_permission(struct file *file, int mask) { struct inode *inode = file_inode(file); - struct file_security_struct *fsec = file->f_security; + struct file_security_struct *fsec = selinux_file(file); struct inode_security_struct *isec; u32 sid = current_sid(); @@ -3571,7 +3571,7 @@ static int ioctl_has_perm(const struct cred *cred, struct file *file, u32 requested, u16 cmd) { struct common_audit_data ad; - struct file_security_struct *fsec = file->f_security; + struct file_security_struct *fsec = selinux_file(file); struct inode *inode = file_inode(file); struct inode_security_struct *isec; struct lsm_ioctlop_audit ioctl; @@ -3823,7 +3823,7 @@ static void selinux_file_set_fowner(struct file *file) { struct file_security_struct *fsec; - fsec = file->f_security; + fsec = selinux_file(file); fsec->fown_sid = current_sid(); } @@ -3838,7 +3838,7 @@ static int selinux_file_send_sigiotask(struct task_struct *tsk, /* struct fown_struct is never outside the context of a struct file */ file = container_of(fown, struct file, f_owner); - fsec = file->f_security; + fsec = selinux_file(file); if (!signum) perm = signal_to_av(SIGIO); /* as per send_sigio_to_task */ @@ -3862,7 +3862,7 @@ static int selinux_file_open(struct file *file) struct file_security_struct *fsec; struct inode_security_struct *isec; - fsec = file->f_security; + fsec = selinux_file(file); isec = inode_security(file_inode(file)); /* * Save inode label and policy sequence number @@ -4002,7 +4002,7 @@ static int selinux_kernel_module_from_file(struct file *file) ad.type = LSM_AUDIT_DATA_FILE; ad.u.file = file; - fsec = file->f_security; + fsec = selinux_file(file); if (sid != fsec->sid) { rc = avc_has_perm(&selinux_state, sid, fsec->sid, SECCLASS_FD, FD__USE, &ad); diff --git a/security/selinux/include/objsec.h b/security/selinux/include/objsec.h index db1c7000ada3..2586fbc7e38c 100644 --- a/security/selinux/include/objsec.h +++ b/security/selinux/include/objsec.h @@ -167,4 +167,9 @@ static inline struct task_security_struct *selinux_cred(const struct cred *cred) return cred->security; } +static inline struct file_security_struct *selinux_file(const struct file *file) +{ + return file->f_security; +} + #endif /* _SELINUX_OBJSEC_H_ */ -- 2.17.1