Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2639096imm; Mon, 16 Jul 2018 11:24:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd1fVPs3BMoFBpYcvnxpJYhtNGmN2r1sejWTAO2nnQjCqdXd7rHSo+/VkfoXX/n/hBgm0J6 X-Received: by 2002:a17:902:622:: with SMTP id 31-v6mr17576379plg.135.1531765440863; Mon, 16 Jul 2018 11:24:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531765440; cv=none; d=google.com; s=arc-20160816; b=fMNckR/m93xCZQT9o+d5+pANe7/BTtYBkVmX4zoLpX7fyghDrEt8UN06tPHTgBQQKr /e2vCUy694nfE9BWKfk5clU+1b2s759hUCviNU44OtoKxckFpWYB4l6HwmJIwvc5xB91 KX8gGhKuYPFo/lXwTEau5GrmhxU+CUuecePYkP4KjiHiJcwXlPR3MSqblJZohiOgMfgz ZYa8XW/5yNFEus0RUeJ51IzzqRtcgg9xuwi18s1AYz60+l0WL2TgOCIgglBJt31ttDp3 SFv0U+tK0Sdaz9h07wA5j1WCI8qe7nvHmNh7xFBxZvezncDUON4AwmUcRqcCMIHp+MtV 9/Yg== 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 :arc-authentication-results; bh=MlGGKoQYr7U5v6wDGI5gi2EIDQu/aB102bB9SZNJHvA=; b=eeGcy/iAcHXwjpblQBzaiS37rxzHsaGXkSGyl6iePvTKjLJUxxR7gBhl5ZUm+sehWD G47+CCzEu9vPiE3ySu6yU5AO/VBXybg7ezCCqt7Tyn7jhrA856PMfXQs4kidYQlOE0OY alDunfDjHM9ixD0gAIkfGY9N54awEvYqowunf/PJTIXEiuAfKwn4lMoBSFuwatFqwS/o K0G7keSEj/Svo5svFEuYXhuuAtSXI3BIBg1KrVq32UX6EIsZBCBMwp8L5PfdQrFGsraj oCdI7xxQb3npsTCEODGn+T/nQF97yj8nMMf4/+R4ZD/9LDSpS+RBhdvtCdSanJ2AezXh Tq1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b="tQD9/tJR"; 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 g4-v6si30238768pgl.139.2018.07.16.11.23.45; Mon, 16 Jul 2018 11:24: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="tQD9/tJR"; 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 S1730029AbeGPSv1 (ORCPT + 99 others); Mon, 16 Jul 2018 14:51:27 -0400 Received: from sonic306-26.consmr.mail.gq1.yahoo.com ([98.137.68.89]:35660 "EHLO sonic306-26.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729969AbeGPSv1 (ORCPT ); Mon, 16 Jul 2018 14:51:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1531765370; bh=MlGGKoQYr7U5v6wDGI5gi2EIDQu/aB102bB9SZNJHvA=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=tQD9/tJRA6JtgkrTuLEvpjzE7Sz2yCo0Z66wFRtIvhAL3ZVLTxmMAZfwlOtXnjhcOxmq1saWxdBGrebxH9QX87GFMQt9/MzuhKW1xPrDb+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5H64w i1AhE7WKPGBK3bHNZ4iqZsMm50byxbclfcMV2hpz52Ht9k5EKw6At8y3dXV3iaNpLTGagWAqC_9f 4uO2qDjiWh.QVUFe3U87g.TBH.GT89CxA5hytgDR.oUAi4sURd4VqSIoe8WzP.Yj_CGdWSImLXNI qBcemnkWiXAWwzQUm_1YXrZVVZNVG96AGah0Z2mRo1uMYMXSjnLkvrQXxplhrQ7zKDIRNYweVppc yGspdPgukl4VqOr9L.4kP Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.gq1.yahoo.com with HTTP; Mon, 16 Jul 2018 18:22:50 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO [192.168.0.100]) ([67.169.65.224]) by smtp413.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID c21abde1eafbd1d358aefd50f46dd47e; Mon, 16 Jul 2018 18:22:49 +0000 (UTC) Subject: [PATCH v1 05/22] SELinux: Abstract use of file security blob To: LSM , LKLM , Paul Moore , Stephen Smalley , SE Linux , "SMACK-discuss@lists.01.org" , John Johansen , Kees Cook , Tetsuo Handa , James Morris Cc: "Schaufler, Casey" , Casey Schaufler References: <8a325db8-e7eb-9581-2b77-fc987a165df7@schaufler-ca.com> From: Casey Schaufler Message-ID: <0ce8deed-d89d-5d88-a609-eeca6ccf5520@schaufler-ca.com> Date: Mon, 16 Jul 2018 11:22:46 -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: <8a325db8-e7eb-9581-2b77-fc987a165df7@schaufler-ca.com> 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 SELinux: Abstract use of file security blob 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 1d2487f8e88b..98ee88156e11 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); } @@ -1882,7 +1882,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); @@ -2226,7 +2226,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; @@ -3538,7 +3538,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(); @@ -3573,7 +3573,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; @@ -3825,7 +3825,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(); } @@ -3840,7 +3840,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 */ @@ -3864,7 +3864,7 @@ static int selinux_file_open(struct file *file, const struct cred *cred) 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 @@ -4004,7 +4004,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