Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp28454imm; Fri, 21 Sep 2018 17:23:48 -0700 (PDT) X-Google-Smtp-Source: ACcGV613c7U7Ii6Q5A48shM6LKOVDEMHJfz5EdMqUVcQ2pVb7GXpwbhSegyW1dZG6LEWrrmYmw+z X-Received: by 2002:a17:902:d703:: with SMTP id w3-v6mr129645ply.132.1537575828708; Fri, 21 Sep 2018 17:23:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537575828; cv=none; d=google.com; s=arc-20160816; b=HvawDDahKQPlovEDS9J1BEkAy7sg3k8HDEf5tPaYU1oPPPm09TYCDy8Yd4vrd6P/qw pmwo+YHhQWA//xYYnHEHlwHDTbuh3qjnBw990BtcHUQKxs7wxgEYoE8CE3uRzCD8Uxvv UqlxNnyjvh9j833q18TgBoX00EhAdMIWYC6VbSdXPhrkQheIZR0Cekl5xPl0rc/VDBeF 8uJghNhNNoZfRSS2xU3/sOF/BY+BxwuhvUv5QKfmmFBHq7mLsYbmOx/mu74Tz/L/5PNK 646C9fQE3pTf3kIcLtnq9zBjx/PdSJWnH50CcrYB66xbZOVVrg4uH6SMlszr5fag9dUa QRzw== 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=Iu+tSavlo7t7q7n3Olg0VNVdtV/eWmeqFaZXnw9uMGQ=; b=PQCGvDLm/18DXh2G1cVi7Gg/4jWx9QBv4VmByUC6eB0+aUeNr8l3tGrtOEnA34zYmf GZ23mYgkk/FXg/rzspqOhzDe+Ob6pAuAAGoR92vpETnnTs+NdsCbGjdaQpcK3uPKamOt hRM1l7xi3H2t1sEGtKUR4IAA+CJNCOfmV+xdN5DFW0H9QqjhB1hwFHdkcLJCRP8DO/aA 8MRhQmunfpuuC1RqMDSOd8Glob05iUikO3k371SCwSF2KIWaWWY/EBGEgtlGTRGVVuaq Y9kT4ep2hNDLIfhgk+rv6L5JSKfEueNc6dBfw4UWvZrlVvkV0OuRUnDq1MnHoL/3rnUF DhqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b="EwHK/SiG"; 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 c128-v6si29598734pfg.347.2018.09.21.17.23.32; Fri, 21 Sep 2018 17:23:48 -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="EwHK/SiG"; 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 S2391995AbeIVGN5 (ORCPT + 99 others); Sat, 22 Sep 2018 02:13:57 -0400 Received: from sonic304-18.consmr.mail.bf2.yahoo.com ([74.6.128.41]:37786 "EHLO sonic304-18.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725800AbeIVGN4 (ORCPT ); Sat, 22 Sep 2018 02:13:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1537575757; bh=Iu+tSavlo7t7q7n3Olg0VNVdtV/eWmeqFaZXnw9uMGQ=; h=Subject:To:References:From:Date:In-Reply-To:From:Subject; b=EwHK/SiGqCVb80ePHfMiMED/MFmPWaBRkh9xrsSXR5KKAhFXTTlisAuTAMljWj7DtJmkcGBoh3QbVoEWiTVoaa2+1SJ0p5UP09qMi4hh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FzSICcRTiLdLBj HVhBvn2TWJQwbLhXPhaEeUNpLiP9Qw.LlLBrPTXAeEWYiJOOfxLXoch5KSOM47ZQYOUrM7HxfNv5 t1O5_lSRm2BxOrhbYnluZHzbMvV3_lk_LR3KiRpLk03J1dRHgkJmuy3CdmIQO9EL7UyfctJUJB4o TgCHptZeB7zsb.omxCjwi2liIECwebkprXmk0k1f3txVYLATleqKzxjxAfWOv3EInWeLFdy5k8v0 _l0HoE79_22emyxpXIQCa17eWOtxXoVerw9GJ6q9cLQ-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.bf2.yahoo.com with HTTP; Sat, 22 Sep 2018 00:22:37 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO [192.168.0.102]) ([67.169.65.224]) by smtp408.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID b48542295dd1eb116f37600aab27ad1d; Sat, 22 Sep 2018 00:22:37 +0000 (UTC) Subject: [PATCH v4 09/19] SELinux: Abstract use of file 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: <3acc0eab-7081-fcc4-f146-1b17772cc97d@schaufler-ca.com> Date: Fri, 21 Sep 2018 17:22:32 -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 Reviewed-by: Kees Cook --- 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 b629cc302088..641a8ce726ff 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -396,7 +396,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); } @@ -1879,7 +1879,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); @@ -2223,7 +2223,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; @@ -3535,7 +3535,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(); @@ -3570,7 +3570,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; @@ -3822,7 +3822,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(); } @@ -3837,7 +3837,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 */ @@ -3861,7 +3861,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 @@ -4000,7 +4000,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 ad511c3d2eb7..cad8b765f6dd 100644 --- a/security/selinux/include/objsec.h +++ b/security/selinux/include/objsec.h @@ -165,4 +165,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