Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp169199imm; Thu, 10 May 2018 17:55:15 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq4FcKAS2HRH+a6MTvPgT5ShkXeteZqTrOTlb5PH9u6lWmMfkTbVbvm/4FlFbdGvgRxLm6u X-Received: by 2002:a62:aa18:: with SMTP id e24-v6mr3334115pff.107.1526000115777; Thu, 10 May 2018 17:55:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526000115; cv=none; d=google.com; s=arc-20160816; b=g6Lz9LtFJ+OkrgEyyok2jOi/a8ZtRfHqZlGTOc5fMHxhMg/KQ7iUcYdDjHeTIE+vId uvdsjxBiUJW4uXeDgP41oQBW9CPW6cB55+enp37dnz29HUIQkk1DU94Kx6Hk8LG0m8BP TugAI/JnPXqwe7DjTLtyv1nValdCRrueXGWs4giaK7pymfK+bAP9RTO9L2186oemLW/o NR+xoyMQeS9aqea2BDLQAxh2nU+bQrpEo6rxkSM7wermA13x98QiqzulayJBiWr7VqDr Rcw6cIbANULusqwBbx6MADXvwjYgvW/Hm6QCYNouWL07ls29Z4p7+GNm20YQjtxZoNvU sf/A== 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 :arc-authentication-results; bh=fuWPBsPpeE7lOMZPTp2ysQ2DzHZcFiIavdIVU5rBTvE=; b=H+dlXwtqekwzXTx+VXwy7cuu4vw04IY8bFdsvgT/NT9jJRz0OXOwVfgbhzaTdvxsiQ Plkfju3y3R9FTaNqThTKFKAKUBeRhkjiqyKMUtTF8ckbZ8lzj8KiB54Qrjt9OzwXa/OC lOZZoxREkQRQLeK15Qwp+fM8RSFu5IAskIxWI51z/Z6sO92uFicr9B4Ewf4y7RQll3nw 39s3AZ6iqEyzDWS/L9uTf+V8A/VC93hu1Y9vqQfJf3B4AQcjeaJqsYNirE2hMOfFYEoS GwC9TtEytv/BCx5D2wj3sw0/s55hf6W8tGBXZSOOWzbcB+ypTv2O7TLFBWJx12uXoOlR Fx3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=MMSVqcNz; 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 75-v6si2071024pfv.262.2018.05.10.17.55.01; Thu, 10 May 2018 17:55:15 -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=MMSVqcNz; 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 S1752111AbeEKAxH (ORCPT + 99 others); Thu, 10 May 2018 20:53:07 -0400 Received: from sonic306-28.consmr.mail.ne1.yahoo.com ([66.163.189.90]:35253 "EHLO sonic306-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752083AbeEKAxE (ORCPT ); Thu, 10 May 2018 20:53:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1525999983; bh=fuWPBsPpeE7lOMZPTp2ysQ2DzHZcFiIavdIVU5rBTvE=; h=Subject:To:References:From:Date:In-Reply-To:From:Subject; b=MMSVqcNzjY6mo5SBBQT7Jguq/I7Jl9j8Bakrfi4uVLLNSTcNIEvcQdNtZlLHT4WgoINGc5PYKapqybTNWbDNwmtpCwc3jwmEPRTkmTg9ntCU9SSA2b7vSYFONxNjnTvbdLH7pZRXXLf8lx4Df5O5DAe86YTStt7WCuo58DMgBBJt5O+euI/3N09Srtpyzf96l8mpvl8jnpAQ8qNS6wURUYWiLKU2AtoF55CiHGGOkY+QC5knpeE7+SeXfixWe/M290ob/NhVoaQ9YQgJvG070KnKaAuY8BbBQiv2rEVP1imSdrdGTPdV+X2i4mlYdjY9mrnbeDW/GmgBfGR4CGhA4A== X-YMail-OSG: 0njNphcVM1lWG4dtNH3flvo6XH3mn36RBxbtniOMtMpkyeWYcWBUItWfaXRj.vY __X1097RPnY45G5v2xR1N9rA.uDMRo_OoSUTd7sdRRvDyQFdpIl7pbRwrAErDoCD3toaHfjPDDPu TddBbAjTrQFY6EVk4YePZFTDyBQD.e6x5SRhpia4_OSr_5oxfBXUZkn9zsyhPkYS2xzsqdYbRozU POPagD.IDN3GOOPxyxP.fXAqlT3IMFu2BcIxL4cpViY4FuUvngkqWNkXTHsJT2i8.MJu1uG0dKs7 8CSJ5SvPHF4i_WFx5VnewUXmv4ys56RmIawhcnXtlYLV.TZu83l2Gsm8DLJfxolKaI6WvtH0.SUq 3jmNLsgv4or.aLOnkSHJQbWs03_A.3GlviryAb.MZ.2ofF9dWDFV0ihXzeHgPhE9lDxKLQgc.PRX qisIUbnlbZx.A9VRraAFIVUZN0tMWLp55CKb2P5gNsbjXqOr8a4IRQuxJXahHh5l1NiVagEjh.RL I0C62ufCjpV1czDFW0D0D2xlfz0l5BaQAbwfEqBtLpLNTdCW_TsWd8pgE7X9Gq2cLqTKmpjZYFgq 0hV6JAVPfPd0.Dxn.2LXJqDQeO.s0Ip5za6LPORpJ5fUwSpBshzImtTsXFern1sexnaJyk9u7FpI 6fmU- Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ne1.yahoo.com with HTTP; Fri, 11 May 2018 00:53:03 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO [192.168.0.105]) ([67.169.65.224]) by smtp426.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID c7b1bbb00d68476f626be55ee178449a; Fri, 11 May 2018 00:53:00 +0000 (UTC) Subject: [PATCH 05/23] 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 References: <7e8702ce-2598-e0a3-31a2-bc29157fb73d@schaufler-ca.com> From: Casey Schaufler Message-ID: <552c12d4-8254-5805-4586-34aaa5c1f389@schaufler-ca.com> Date: Thu, 10 May 2018 17:52:57 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <7e8702ce-2598-e0a3-31a2-bc29157fb73d@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 From: Casey Schaufler Date: Thu, 10 May 2018 14:01:52 -0700 Subject: [PATCH 05/23] 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 f4179eb572e8..1d0a4a9fa08b 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -398,7 +398,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); } @@ -1869,7 +1869,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); @@ -2213,7 +2213,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; @@ -3524,7 +3524,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(); @@ -3559,7 +3559,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; @@ -3811,7 +3811,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(); } @@ -3826,7 +3826,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 */ @@ -3850,7 +3850,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 @@ -3990,7 +3990,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.14.3