Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp615341imu; Mon, 26 Nov 2018 15:51:13 -0800 (PST) X-Google-Smtp-Source: AFSGD/W1KZ/ail6SI1n841YKl+3PxsaBzlDoVBHmVboiqLvSUN4LkGh0IYotN0/KgNXq04TwIS6J X-Received: by 2002:a63:6b08:: with SMTP id g8mr26790906pgc.119.1543276273705; Mon, 26 Nov 2018 15:51:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543276273; cv=none; d=google.com; s=arc-20160816; b=m9Rc95xRjNH48MpSaHfpmGyGPYaIAXWuOEc7UL0QLG+r5OZ9FEuBFb+5Orf7BsITKx /YGvdOesONw9UHy+GvIRpyeq8anEKm3kACFRabQVdDzDZkQQi+m8JkCgk2bcSe/+rRil bJgbYGgX5EK9zT0UTaI/AxwvxKPTNFQhzoekJJaujcJm2uPfmaoW/cpBtvgLnUUbmykq zwoV+8auhU3lLEUMC4/FOCpG3Tk7b2idCGO4WJjcPWNpf25hsMiu5IbR3FuSuI7tzChN FzpyDifz2rvNGkkeEvF6u+gWCxSZrrHSsBAdYa9dv9iDvdudhsmuAF60+paQ2cFcbn8O lFMA== 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=qbpXcajJrA98ZZWDlgqmt0cbStnF49zKm903egriuBg=; b=cXPZzGotvXhPWWFDR8Ft3ISGnH0P9Ahlv7qyyaZ6z2YYc+uBlICAoFxvOpMlCMA3ak Z3SZZtdwJeYripA7ZwrET0nPJ00Biwf0WGW6i+cqczeDR7OOFnAKkI+DGt34Velsr8C9 P+AkpmguIcC6M+tbKfV1CHcuNdnUeonpcfC16vGwciDRvgXEMkP0hDYBwLGvNWqW9Amg 7CNNVWJVBxFnL+vMXQbZJnjfgivzjF3n6iHq4c7taoE4cQts90HrUbAJzWMX1uDMImAu hLKXp3bza2GDy0Bwf9lkexpYgMVab1w2P+DQgy130e5eTtcGBRalMTcqQ0JTgRpQPUF0 XSnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=KowtF5DM; 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 l33si1986059pld.142.2018.11.26.15.50.58; Mon, 26 Nov 2018 15:51:13 -0800 (PST) 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=KowtF5DM; 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 S1728030AbeK0Koi (ORCPT + 99 others); Tue, 27 Nov 2018 05:44:38 -0500 Received: from sonic315-27.consmr.mail.ne1.yahoo.com ([66.163.190.153]:44815 "EHLO sonic315-27.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727652AbeK0Koi (ORCPT ); Tue, 27 Nov 2018 05:44:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1543276126; bh=qbpXcajJrA98ZZWDlgqmt0cbStnF49zKm903egriuBg=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=KowtF5DMSc298/qt2gWvaYu22JFcylgEW2xik0Bl4lMS/P1BiJY4sQMza8STTf2Moe2g0C9R+nTASF7xpgrqB4JxSiCJvnG1qJX7omximaTs2pGYtixJbr2TRl9tHGiWfn2g8Z2oUyHtZNhgxV9y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Tf7uXK96AK5VZxELhJLyyVXNUz0AFBMalm1 3wll2aX_iQ62I9_4rkaTG2osn3chNZw8UPwJFYUx6HeCNUnq.LEaXoKSNC071KjiG6jimigyxPRt ZjWlo9HW2fl2kjCA9wl7D5a5yM7exx7TKGvBiTBl_v0QykoKWbQ.E0FpjbYRem80ecQHxoxOFA1u .t2fdQF1Et4_Zypmx..IJJDWoMfGMDEonSD.14YirWPzeGgT4K7Cy5hOiVRLQCZzFs3eUCA_DVXh zpe8MIqeWUdc2.qxZvyEXQLJYHHETGvDOHLUeug-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.ne1.yahoo.com with HTTP; Mon, 26 Nov 2018 23:48:46 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO [192.168.0.105]) ([67.169.65.224]) by smtp425.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID f5346034b70e818e7690c08090f23b62; Mon, 26 Nov 2018 23:48:45 +0000 (UTC) Subject: [PATCH v5 28/38] SELinux: Abstract use of file security blob To: James Morris , LSM , LKLM , SE Linux Cc: John Johansen , Kees Cook , Tetsuo Handa , Paul Moore , "linux-fsdevel@vger.kernel.org" , Stephen Smalley , Alexey Dobriyan , =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= , Salvatore Mesoraca References: <50db058a-7dde-441b-a7f9-f6837fe8b69f@schaufler-ca.com> From: Casey Schaufler Message-ID: Date: Mon, 26 Nov 2018 15:48:42 -0800 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: <50db058a-7dde-441b-a7f9-f6837fe8b69f@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 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 Signed-off-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 ac6d8a2d00f1..ce1d37378eb5 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -393,7 +393,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); } @@ -1881,7 +1881,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); @@ -2225,7 +2225,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; @@ -3537,7 +3537,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(); @@ -3572,7 +3572,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; @@ -3824,7 +3824,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(); } @@ -3839,7 +3839,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 */ @@ -3863,7 +3863,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 c2974b031d05..e0ac2992e059 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 + selinux_blob_sizes.lbs_cred; } +static inline struct file_security_struct *selinux_file(const struct file *file) +{ + return file->f_security; +} + #endif /* _SELINUX_OBJSEC_H_ */ -- 2.14.5