Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp28503imm; Fri, 21 Sep 2018 17:23:55 -0700 (PDT) X-Google-Smtp-Source: ACcGV62m/VSONaTutzmqpoCB3RygiAxuf0uy/kaKPZs7fui3azCogtLjwwKYlSWGGmiH4ORe3udY X-Received: by 2002:a17:902:be08:: with SMTP id r8-v6mr96835pls.265.1537575834976; Fri, 21 Sep 2018 17:23:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537575834; cv=none; d=google.com; s=arc-20160816; b=ARgPRtNH4tcb99gTGOEkJS83xNi41uANjhoX/Np25egLs60Ezg39mtgT0qArylqj0K X3sbFqEb9j+Yq55xGy3vWa4cK0FmUIXXHRbg4SGqfl7z1SCBt3D03iOR21/24H9/BFC9 5VslJJUCqg7v2qbKb8oD/riR9GFpGtgg+KwhqEPjrpHFJDiyXkpMebsuZ7sCYbgMqRo+ 90eVcHpAMEINJrN4P+zmfcZjiqGj1fOULLIetd5BCV/+zXdJqO465DwGO2TWUcJH6gJc eh/4hVxRISMH8maFovS2GCDDsGhykdqfBhKvCQukiWwUMQsEHJ53C4j+3VYGpkoWQuZM RGPA== 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=E+xftFukhBH2PD5ag0UlILOyM4DZR2qb/6Vf+qMNozlMYOXM1V4SI4HW+QcFzuDECs QRJ69EpBxFP/qR7KgI8q7Jqzqt0V/Vepg+xKdYNNVdBhumhhZwcp25Rs6SmR394I9Uud BI/ejX9gk7bKeTL9c/saMEGzlbM8ynu68YzzkPOe6w+FfX4yvCqJTXUnrqw0/O8m1YGy tRDoATYhnLkQI29i2zpdrBewsnePGJio5ybFOIj+lQnwV4BvlExsOOMLOv7WnnmtUOHn rNgl7E5ng0ZspQzownn7gK7ltIiYrQxDrPZ5r0ASzfE3qfSAcrYPpXqPzEYc20hb4yQ3 w8Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=XCXtLMHl; 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 q2-v6si5194882pli.392.2018.09.21.17.23.38; Fri, 21 Sep 2018 17:23:54 -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=XCXtLMHl; 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 S2392133AbeIVGOF (ORCPT + 99 others); Sat, 22 Sep 2018 02:14:05 -0400 Received: from sonic303-31.consmr.mail.bf2.yahoo.com ([74.6.131.230]:38496 "EHLO sonic303-31.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391738AbeIVGOF (ORCPT ); Sat, 22 Sep 2018 02:14:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1537575766; bh=Iu+tSavlo7t7q7n3Olg0VNVdtV/eWmeqFaZXnw9uMGQ=; h=Subject:To:References:From:Date:In-Reply-To:From:Subject; b=XCXtLMHlb1lXs3t2Byw4S2DsvMgkepJKuUweTsROByhGo6mI8jCYN7jfCTbOcIUFiAPt2XERCPSjTyznHXsfQeriN/gylduK2N7fkI6Q2d1c0yd1lZkYCAx9qecjHt03GF1sHEKp5/5ATYyoS/uYGW2zkI3sASZFMlvmc3TUNi1r+2UhgwO0PmFOGOqD1FNg1wMLrLFWfvTHcCDkaGnJr2eeYq07Os4p264O8LR+rMUKL9IDw2BSq6syGfXd3EyweCckusujaMjOfFlxsssstqV7cY3qlWd+xgsS2H8NF+JVrjojiHgGrmpgaPPuf8edFGfek1nyzl4i9X++tqtXGw== X-YMail-OSG: 7VFgqxcVM1nm.9gcjV9vMlvcbGz1c7AIl.2HQJE1rgxu1zXuBiemUHvs4iEI.Tn A7PsuiS_org-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.bf2.yahoo.com with HTTP; Sat, 22 Sep 2018 00:22:46 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO [192.168.0.102]) ([67.169.65.224]) by smtp425.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0841caf00ea79cb44958c74ce7010a8d; Sat, 22 Sep 2018 00:18:45 +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: Date: Fri, 21 Sep 2018 17:18:40 -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