From patchwork Sun Jun 2 16:50:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971797 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4564718A6 for ; Sun, 2 Jun 2019 16:51:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35B4328703 for ; Sun, 2 Jun 2019 16:51:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A43628A08; Sun, 2 Jun 2019 16:51:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00132289FA for ; Sun, 2 Jun 2019 16:51:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726633AbfFBQvK (ORCPT ); Sun, 2 Jun 2019 12:51:10 -0400 Received: from sonic303-8.consmr.mail.bf2.yahoo.com ([74.6.131.47]:36457 "EHLO sonic303-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726695AbfFBQvK (ORCPT ); Sun, 2 Jun 2019 12:51:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494267; bh=Il1LofQJbqDTPd0nbutoh9rZauAEn/qc57mVVqdyysM=; h=From:To:Cc:Subject:Date:In-Reply-To:References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60VIVxlpME.iK.d_LijvbdagkAXw.lHovcfPIueHPs UNTUlzeyXuu2qNPZLDvzY0oTea98X.J9EzKgkmzNtLF5KDN1wo_esbpoCt65Ke4cZtpqjLn2uN0Z liNb8brCUlx1Qff3Q1mz3UD8Qf0wcB56a9xu.ECBQtLDXHPvw3bWQZ3uKO.rR6MowADgk65p5n4v IVmt.C5epBSnoSCYMn7kiiko9riQ0kQ3h5ks3NPkLfgxli9RO8LkHrZFRZqwMvZN2ApyJqW3Z09h 1J_Wdv90TZHuP0hCsAPf9bJxpXaOVNm2ByXP5zFetllvOznqihGmdpqxXqy01SnkVQfCjIH0ooHw rharqvRwDp.tKAy1_VKOmMrRe6waeCgXXZUPEP0KvuwiB_ltj76D0npAjnpw35hpA2sSTtl7JRk9 B7MCkwt_kgxdiAFhc3XTIGq_IuI7QolHno5e7USMSf5t7bTi9cBUpHQhskNx3B0KSXAB2Xhgde7D 8iqDRqz34XpjvsYrsVOPWVxIpR9SBrbLlBr0A2xU0ONXislscFIZOz_5kgrZhTrLTBRm5G60rmxv dUyZXXTkZ3RN4eVAgOKL2nOjGfpCkH9njXO.FeQ1wNw.2euXg Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:51:07 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp429.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 844f659d1e234107537a664739855744; Sun, 02 Jun 2019 16:51:05 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 01/58] LSM: Infrastructure management of the superblock Date: Sun, 2 Jun 2019 09:50:04 -0700 Message-Id: <20190602165101.25079-2-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move management of the superblock->sb_security blob out of the individual security modules and into the security infrastructure. Instead of allocating the blobs from within the modules the modules tell the infrastructure how much space is required, and the space is allocated there. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 1 + security/security.c | 46 ++++++++++++++++++++---- security/selinux/hooks.c | 58 ++++++++++++------------------- security/selinux/include/objsec.h | 6 ++++ security/selinux/ss/services.c | 3 +- security/smack/smack.h | 6 ++++ security/smack/smack_lsm.c | 35 +++++-------------- 7 files changed, 85 insertions(+), 70 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index a240a3fc5fc4..f9222a04968d 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -2047,6 +2047,7 @@ struct lsm_blob_sizes { int lbs_cred; int lbs_file; int lbs_inode; + int lbs_superblock; int lbs_ipc; int lbs_msg_msg; int lbs_task; diff --git a/security/security.c b/security/security.c index 23cbb1a295a3..550988a0f024 100644 --- a/security/security.c +++ b/security/security.c @@ -172,6 +172,7 @@ static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed) lsm_set_blob_size(&needed->lbs_inode, &blob_sizes.lbs_inode); lsm_set_blob_size(&needed->lbs_ipc, &blob_sizes.lbs_ipc); lsm_set_blob_size(&needed->lbs_msg_msg, &blob_sizes.lbs_msg_msg); + lsm_set_blob_size(&needed->lbs_superblock, &blob_sizes.lbs_superblock); lsm_set_blob_size(&needed->lbs_task, &blob_sizes.lbs_task); } @@ -300,12 +301,13 @@ static void __init ordered_lsm_init(void) for (lsm = ordered_lsms; *lsm; lsm++) prepare_lsm(*lsm); - init_debug("cred blob size = %d\n", blob_sizes.lbs_cred); - init_debug("file blob size = %d\n", blob_sizes.lbs_file); - init_debug("inode blob size = %d\n", blob_sizes.lbs_inode); - init_debug("ipc blob size = %d\n", blob_sizes.lbs_ipc); - init_debug("msg_msg blob size = %d\n", blob_sizes.lbs_msg_msg); - init_debug("task blob size = %d\n", blob_sizes.lbs_task); + init_debug("cred blob size = %d\n", blob_sizes.lbs_cred); + init_debug("file blob size = %d\n", blob_sizes.lbs_file); + init_debug("inode blob size = %d\n", blob_sizes.lbs_inode); + init_debug("ipc blob size = %d\n", blob_sizes.lbs_ipc); + init_debug("msg_msg blob size = %d\n", blob_sizes.lbs_msg_msg); + init_debug("superblock blob size = %d\n", blob_sizes.lbs_superblock); + init_debug("task blob size = %d\n", blob_sizes.lbs_task); /* * Create any kmem_caches needed for blobs @@ -603,6 +605,27 @@ static void __init lsm_early_task(struct task_struct *task) panic("%s: Early task alloc failed.\n", __func__); } +/** + * lsm_superblock_alloc - allocate a composite superblock blob + * @sb: the superblock that needs a blob + * + * Allocate the superblock blob for all the modules + * + * Returns 0, or -ENOMEM if memory can't be allocated. + */ +int lsm_superblock_alloc(struct super_block *sb) +{ + if (blob_sizes.lbs_superblock == 0) { + sb->s_security = NULL; + return 0; + } + + sb->s_security = kzalloc(blob_sizes.lbs_superblock, GFP_KERNEL); + if (sb->s_security == NULL) + return -ENOMEM; + return 0; +} + /* * Hook list operation macros. * @@ -776,12 +799,21 @@ int security_fs_context_parse_param(struct fs_context *fc, struct fs_parameter * int security_sb_alloc(struct super_block *sb) { - return call_int_hook(sb_alloc_security, 0, sb); + int rc = lsm_superblock_alloc(sb); + + if (unlikely(rc)) + return rc; + rc = call_int_hook(sb_alloc_security, 0, sb); + if (unlikely(rc)) + security_sb_free(sb); + return rc; } void security_sb_free(struct super_block *sb) { call_void_hook(sb_free_security, sb); + kfree(sb->s_security); + sb->s_security = NULL; } void security_free_mnt_opts(void **mnt_opts) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 1d0b37af2444..7478d8eda00a 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -335,7 +335,7 @@ static void inode_free_security(struct inode *inode) if (!isec) return; - sbsec = inode->i_sb->s_security; + sbsec = selinux_superblock(inode->i_sb); /* * As not all inode security structures are in a list, we check for * empty list outside of the lock to make sure that we won't waste @@ -366,11 +366,7 @@ static int file_alloc_security(struct file *file) static int superblock_alloc_security(struct super_block *sb) { - struct superblock_security_struct *sbsec; - - sbsec = kzalloc(sizeof(struct superblock_security_struct), GFP_KERNEL); - if (!sbsec) - return -ENOMEM; + struct superblock_security_struct *sbsec = selinux_superblock(sb); mutex_init(&sbsec->lock); INIT_LIST_HEAD(&sbsec->isec_head); @@ -379,18 +375,10 @@ static int superblock_alloc_security(struct super_block *sb) sbsec->sid = SECINITSID_UNLABELED; sbsec->def_sid = SECINITSID_FILE; sbsec->mntpoint_sid = SECINITSID_UNLABELED; - sb->s_security = sbsec; return 0; } -static void superblock_free_security(struct super_block *sb) -{ - struct superblock_security_struct *sbsec = sb->s_security; - sb->s_security = NULL; - kfree(sbsec); -} - struct selinux_mnt_opts { const char *fscontext, *context, *rootcontext, *defcontext; }; @@ -507,7 +495,7 @@ static int selinux_is_genfs_special_handling(struct super_block *sb) static int selinux_is_sblabel_mnt(struct super_block *sb) { - struct superblock_security_struct *sbsec = sb->s_security; + struct superblock_security_struct *sbsec = selinux_superblock(sb); /* * IMPORTANT: Double-check logic in this function when adding a new @@ -535,7 +523,7 @@ static int selinux_is_sblabel_mnt(struct super_block *sb) static int sb_finish_set_opts(struct super_block *sb) { - struct superblock_security_struct *sbsec = sb->s_security; + struct superblock_security_struct *sbsec = selinux_superblock(sb); struct dentry *root = sb->s_root; struct inode *root_inode = d_backing_inode(root); int rc = 0; @@ -648,7 +636,7 @@ static int selinux_set_mnt_opts(struct super_block *sb, unsigned long *set_kern_flags) { const struct cred *cred = current_cred(); - struct superblock_security_struct *sbsec = sb->s_security; + struct superblock_security_struct *sbsec = selinux_superblock(sb); struct dentry *root = sbsec->sb->s_root; struct selinux_mnt_opts *opts = mnt_opts; struct inode_security_struct *root_isec; @@ -881,8 +869,8 @@ static int selinux_set_mnt_opts(struct super_block *sb, static int selinux_cmp_sb_context(const struct super_block *oldsb, const struct super_block *newsb) { - struct superblock_security_struct *old = oldsb->s_security; - struct superblock_security_struct *new = newsb->s_security; + struct superblock_security_struct *old = selinux_superblock(oldsb); + struct superblock_security_struct *new = selinux_superblock(newsb); char oldflags = old->flags & SE_MNTMASK; char newflags = new->flags & SE_MNTMASK; @@ -914,8 +902,9 @@ static int selinux_sb_clone_mnt_opts(const struct super_block *oldsb, unsigned long *set_kern_flags) { int rc = 0; - const struct superblock_security_struct *oldsbsec = oldsb->s_security; - struct superblock_security_struct *newsbsec = newsb->s_security; + const struct superblock_security_struct *oldsbsec = + selinux_superblock(oldsb); + struct superblock_security_struct *newsbsec = selinux_superblock(newsb); int set_fscontext = (oldsbsec->flags & FSCONTEXT_MNT); int set_context = (oldsbsec->flags & CONTEXT_MNT); @@ -1085,7 +1074,7 @@ static int show_sid(struct seq_file *m, u32 sid) static int selinux_sb_show_options(struct seq_file *m, struct super_block *sb) { - struct superblock_security_struct *sbsec = sb->s_security; + struct superblock_security_struct *sbsec = selinux_superblock(sb); int rc; if (!(sbsec->flags & SE_SBINITIALIZED)) @@ -1377,7 +1366,7 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent if (isec->sclass == SECCLASS_FILE) isec->sclass = inode_mode_to_security_class(inode->i_mode); - sbsec = inode->i_sb->s_security; + sbsec = selinux_superblock(inode->i_sb); if (!(sbsec->flags & SE_SBINITIALIZED)) { /* Defer initialization until selinux_complete_init, after the initial policy is loaded and the security @@ -1767,7 +1756,8 @@ selinux_determine_inode_label(const struct task_security_struct *tsec, const struct qstr *name, u16 tclass, u32 *_new_isid) { - const struct superblock_security_struct *sbsec = dir->i_sb->s_security; + const struct superblock_security_struct *sbsec = + selinux_superblock(dir->i_sb); if ((sbsec->flags & SE_SBINITIALIZED) && (sbsec->behavior == SECURITY_FS_USE_MNTPOINT)) { @@ -1798,7 +1788,7 @@ static int may_create(struct inode *dir, int rc; dsec = inode_security(dir); - sbsec = dir->i_sb->s_security; + sbsec = selinux_superblock(dir->i_sb); sid = tsec->sid; @@ -1947,7 +1937,7 @@ static int superblock_has_perm(const struct cred *cred, struct superblock_security_struct *sbsec; u32 sid = cred_sid(cred); - sbsec = sb->s_security; + sbsec = selinux_superblock(sb); return avc_has_perm(&selinux_state, sid, sbsec->sid, SECCLASS_FILESYSTEM, perms, ad); } @@ -2578,11 +2568,6 @@ static int selinux_sb_alloc_security(struct super_block *sb) return superblock_alloc_security(sb); } -static void selinux_sb_free_security(struct super_block *sb) -{ - superblock_free_security(sb); -} - static inline int opt_len(const char *s) { bool open_quote = false; @@ -2653,7 +2638,7 @@ static int selinux_sb_eat_lsm_opts(char *options, void **mnt_opts) static int selinux_sb_remount(struct super_block *sb, void *mnt_opts) { struct selinux_mnt_opts *opts = mnt_opts; - struct superblock_security_struct *sbsec = sb->s_security; + struct superblock_security_struct *sbsec = selinux_superblock(sb); u32 sid; int rc; @@ -2877,7 +2862,7 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir, int rc; char *context; - sbsec = dir->i_sb->s_security; + sbsec = selinux_superblock(dir->i_sb); newsid = tsec->create_sid; @@ -3115,7 +3100,7 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name, return dentry_has_perm(current_cred(), dentry, FILE__SETATTR); } - sbsec = inode->i_sb->s_security; + sbsec = selinux_superblock(inode->i_sb); if (!(sbsec->flags & SBLABEL_MNT)) return -EOPNOTSUPP; @@ -3296,13 +3281,14 @@ static int selinux_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags) { struct inode_security_struct *isec = inode_security_novalidate(inode); - struct superblock_security_struct *sbsec = inode->i_sb->s_security; + struct superblock_security_struct *sbsec; u32 newsid; int rc; if (strcmp(name, XATTR_SELINUX_SUFFIX)) return -EOPNOTSUPP; + sbsec = selinux_superblock(inode->i_sb); if (!(sbsec->flags & SBLABEL_MNT)) return -EOPNOTSUPP; @@ -6647,6 +6633,7 @@ struct lsm_blob_sizes selinux_blob_sizes __lsm_ro_after_init = { .lbs_inode = sizeof(struct inode_security_struct), .lbs_ipc = sizeof(struct ipc_security_struct), .lbs_msg_msg = sizeof(struct msg_security_struct), + .lbs_superblock = sizeof(struct superblock_security_struct), }; static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = { @@ -6675,7 +6662,6 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = { LSM_HOOK_INIT(fs_context_parse_param, selinux_fs_context_parse_param), LSM_HOOK_INIT(sb_alloc_security, selinux_sb_alloc_security), - LSM_HOOK_INIT(sb_free_security, selinux_sb_free_security), LSM_HOOK_INIT(sb_eat_lsm_opts, selinux_sb_eat_lsm_opts), LSM_HOOK_INIT(sb_free_mnt_opts, selinux_free_mnt_opts), LSM_HOOK_INIT(sb_remount, selinux_sb_remount), diff --git a/security/selinux/include/objsec.h b/security/selinux/include/objsec.h index 231262d8eac9..d08d7e5d2f93 100644 --- a/security/selinux/include/objsec.h +++ b/security/selinux/include/objsec.h @@ -188,4 +188,10 @@ static inline struct ipc_security_struct *selinux_ipc( return ipc->security + selinux_blob_sizes.lbs_ipc; } +static inline struct superblock_security_struct *selinux_superblock( + const struct super_block *superblock) +{ + return superblock->s_security + selinux_blob_sizes.lbs_superblock; +} + #endif /* _SELINUX_OBJSEC_H_ */ diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c index ec62918521b1..e3f5d6aece66 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include "flask.h" @@ -2751,7 +2752,7 @@ int security_fs_use(struct selinux_state *state, struct super_block *sb) struct sidtab *sidtab; int rc = 0; struct ocontext *c; - struct superblock_security_struct *sbsec = sb->s_security; + struct superblock_security_struct *sbsec = selinux_superblock(sb); const char *fstype = sb->s_type->name; read_lock(&state->ss->policy_rwlock); diff --git a/security/smack/smack.h b/security/smack/smack.h index cf52af77d15e..caecbcba9942 100644 --- a/security/smack/smack.h +++ b/security/smack/smack.h @@ -375,6 +375,12 @@ static inline struct smack_known **smack_ipc(const struct kern_ipc_perm *ipc) return ipc->security + smack_blob_sizes.lbs_ipc; } +static inline struct superblock_smack *smack_superblock( + const struct super_block *superblock) +{ + return superblock->s_security + smack_blob_sizes.lbs_superblock; +} + /* * Is the directory transmuting? */ diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 5c1613519d5a..807eff2ccce9 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -540,12 +540,7 @@ static int smack_syslog(int typefrom_file) */ static int smack_sb_alloc_security(struct super_block *sb) { - struct superblock_smack *sbsp; - - sbsp = kzalloc(sizeof(struct superblock_smack), GFP_KERNEL); - - if (sbsp == NULL) - return -ENOMEM; + struct superblock_smack *sbsp = smack_superblock(sb); sbsp->smk_root = &smack_known_floor; sbsp->smk_default = &smack_known_floor; @@ -554,22 +549,10 @@ static int smack_sb_alloc_security(struct super_block *sb) /* * SMK_SB_INITIALIZED will be zero from kzalloc. */ - sb->s_security = sbsp; return 0; } -/** - * smack_sb_free_security - free a superblock blob - * @sb: the superblock getting the blob - * - */ -static void smack_sb_free_security(struct super_block *sb) -{ - kfree(sb->s_security); - sb->s_security = NULL; -} - struct smack_mnt_opts { const char *fsdefault, *fsfloor, *fshat, *fsroot, *fstransmute; }; @@ -781,7 +764,7 @@ static int smack_set_mnt_opts(struct super_block *sb, { struct dentry *root = sb->s_root; struct inode *inode = d_backing_inode(root); - struct superblock_smack *sp = sb->s_security; + struct superblock_smack *sp = smack_superblock(sb); struct inode_smack *isp; struct smack_known *skp; struct smack_mnt_opts *opts = mnt_opts; @@ -880,7 +863,7 @@ static int smack_set_mnt_opts(struct super_block *sb, */ static int smack_sb_statfs(struct dentry *dentry) { - struct superblock_smack *sbp = dentry->d_sb->s_security; + struct superblock_smack *sbp = smack_superblock(dentry->d_sb); int rc; struct smk_audit_info ad; @@ -917,7 +900,7 @@ static int smack_bprm_set_creds(struct linux_binprm *bprm) if (isp->smk_task == NULL || isp->smk_task == bsp->smk_task) return 0; - sbsp = inode->i_sb->s_security; + sbsp = smack_superblock(inode->i_sb); if ((sbsp->smk_flags & SMK_SB_UNTRUSTED) && isp->smk_task != sbsp->smk_root) return 0; @@ -1168,7 +1151,7 @@ static int smack_inode_rename(struct inode *old_inode, */ static int smack_inode_permission(struct inode *inode, int mask) { - struct superblock_smack *sbsp = inode->i_sb->s_security; + struct superblock_smack *sbsp = smack_superblock(inode->i_sb); struct smk_audit_info ad; int no_block = mask & MAY_NOT_BLOCK; int rc; @@ -1410,7 +1393,7 @@ static int smack_inode_removexattr(struct dentry *dentry, const char *name) */ if (strcmp(name, XATTR_NAME_SMACK) == 0) { struct super_block *sbp = dentry->d_sb; - struct superblock_smack *sbsp = sbp->s_security; + struct superblock_smack *sbsp = smack_superblock(sbp); isp->smk_inode = sbsp->smk_default; } else if (strcmp(name, XATTR_NAME_SMACKEXEC) == 0) @@ -1680,7 +1663,7 @@ static int smack_mmap_file(struct file *file, isp = smack_inode(file_inode(file)); if (isp->smk_mmap == NULL) return 0; - sbsp = file_inode(file)->i_sb->s_security; + sbsp = smack_superblock(file_inode(file)->i_sb); if (sbsp->smk_flags & SMK_SB_UNTRUSTED && isp->smk_mmap != sbsp->smk_root) return -EACCES; @@ -3288,7 +3271,7 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode) goto unlockandout; sbp = inode->i_sb; - sbsp = sbp->s_security; + sbsp = smack_superblock(sbp); /* * We're going to use the superblock default label * if there's no label on the file. @@ -4575,6 +4558,7 @@ struct lsm_blob_sizes smack_blob_sizes __lsm_ro_after_init = { .lbs_inode = sizeof(struct inode_smack), .lbs_ipc = sizeof(struct smack_known *), .lbs_msg_msg = sizeof(struct smack_known *), + .lbs_superblock = sizeof(struct superblock_smack), }; static struct security_hook_list smack_hooks[] __lsm_ro_after_init = { @@ -4586,7 +4570,6 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = { LSM_HOOK_INIT(fs_context_parse_param, smack_fs_context_parse_param), LSM_HOOK_INIT(sb_alloc_security, smack_sb_alloc_security), - LSM_HOOK_INIT(sb_free_security, smack_sb_free_security), LSM_HOOK_INIT(sb_free_mnt_opts, smack_free_mnt_opts), LSM_HOOK_INIT(sb_eat_lsm_opts, smack_sb_eat_lsm_opts), LSM_HOOK_INIT(sb_statfs, smack_sb_statfs), From patchwork Sun Jun 2 16:50:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971927 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 945A26C5 for ; Sun, 2 Jun 2019 16:53:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81D801FF40 for ; Sun, 2 Jun 2019 16:53:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75B20289FA; Sun, 2 Jun 2019 16:53:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71FC41FF40 for ; Sun, 2 Jun 2019 16:53:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726789AbfFBQxN (ORCPT ); Sun, 2 Jun 2019 12:53:13 -0400 Received: from sonic302-36.consmr.mail.bf2.yahoo.com ([74.6.135.235]:38202 "EHLO sonic302-36.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727005AbfFBQxM (ORCPT ); Sun, 2 Jun 2019 12:53:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494388; bh=2X36VmaAWfYHV1ONv3rUfK/va4ULO7J09FbNzHopExQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=oo6B/OSuZPnZTlVF38wOsEMBgFyJPG6+kaEilQ9Np8Pd3HwClFWi0OuYvO7f5nXIq/Q11QfYeswOChpxwcodHSCXHfc+vpF+oTxXMilAONMUU+noRxAgnwe0ykVU7hfjl0DUnV0NTiRaFGEphXb6iJQQXrV1i/CGCerVvzc8TB55dzqo0236PGQVcdfcQdq4ZnienntfEoYs5MKlgjVuash+R4uMh8lHz4jtLeeVX5L2SwgP3keaaefRBRIyfn+77Ef/Xy3SRRtNc12hT3EIv84A1BjeSe6umNLZ+tIJE4kuEQbL42RTAGZU9FEiAzEeBStxuEv/caILu+xh98P68Q== X-YMail-OSG: 71kxv_4VM1mkRIHnSyWwHKCjhzaUAMJ2_8_5TSmCXNkgCx3QPZ6g9U424C37Gip 8ttxp7FEbt6QuOjc7yOLoE4HfxKUkxMGut94lyZc0k3ngyEp_WCeA.GtYxC8vFetLzEDR2rJs5rf bfnYZWzw87kYp1q3lHVbKh6EMofrWkz2uzvsEJW0K4qSkBd69OpktKAazeFsU0w5T.wvjE4NqMed Gr5YCbsHo_7g.a5TMcdQCzogldmI1dotBzV_Lamzi0a5rh.3QhCS_hRypdbF1eD9y0gn.jQkywCU dxNdgF5c6m6KZ73_Z5YP2xohnPo0B.5F5.g_sIqRqe0otgz_vOyEFCUXfM0wcl5SMtTgcw85abTB bpoWDRE.MZRzG4OPzidCbU62yzUbkE5.VHXx_1kCdJfKPa29cLzRMmqQE5kKqoNrpkoPaaEFQ.p8 jl6aASihnFOpkAszWLCTy27nWxTPZ9t8E_axQySShAFTAc94Ks8g2cQ1Xv9xhlxIRX3NbNiL9WHa mp6pHEoOSNyMs9bTDERXbo0.wG6nsGhatSQDSEleU81IvX1G31HAXtXy.6e0XKb4vz12D5PGkQYZ 1Z3QflwsJfQlTLHuqjotvPhCnf4dZaV_ycno5ZgETaIUURkY_HSb2pZMbM_9dzgnaH0GtmBpnKKj g9NBzrMBxmPu68l1dX.ROJUjbW9Y0g68UQaSU6ArOznpnhRNDEAfFqsHLc9BuaQm4x8O3UjfNiLo SoJdR2S77GeOHTH09jww8h8sBlX_aMWjf_JWeTYSeSV5d5XwD9RZmBabU4_InDg_NLFWN0WI4TWw bERpdGB_dPKYMkLFadreIZ.yupVq.9QN.pLwFHonXbR9NJG39s0sxe3.YV9rf9xQwIGUgpWkWEC9 yDSU5VCo36Vc1J5MyWMvpNHQ7fxJzjnrBnuK1ZYEdZd9XIAZ3m9nLJrY_lcm7WCg6eTigrI7TA_r r_FZbwP5nUxRc94.3tvy0oaG.0YXJiYYwffzV3KXrHL8u22apLpxPPExT965DMpqIkB5x8x1WnYI lvCfx_kNxiQ5I_lTuYa26mpl5YcspSO3uDVwySgrIbDlwqJeOqbFe5y9jQJNcxDEd2j5smiNswG7 u8NrJw1H6ZLzhiL9C4kMZzNXgKqsKMxjqiPUQ0OcRHkFmrV2PVo9TJIJONyPT2610iwMOKvFq5xC 4YSVTVpooCqT8CeWdQSwcqF0juMd4OQEHCuA1cAF0TY1BUOCnCLZ9UHjIP2gfbj_vwMS9MVil2zB ZDrTQmeQh1ad6U.vuycy_qTidRpAmYjUoFYiE3qR1wMr8qLfPSg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:53:08 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp429.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 844f659d1e234107537a664739855744; Sun, 02 Jun 2019 16:51:07 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 02/58] LSM: Infrastructure management of the sock security Date: Sun, 2 Jun 2019 09:50:05 -0700 Message-Id: <20190602165101.25079-3-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move management of the sock->sk_security blob out of the individual security modules and into the security infrastructure. Instead of allocating the blobs from within the modules the modules tell the infrastructure how much space is required, and the space is allocated there. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 1 + security/apparmor/include/net.h | 6 ++- security/apparmor/lsm.c | 38 ++++----------- security/security.c | 36 +++++++++++++- security/selinux/hooks.c | 78 +++++++++++++++---------------- security/selinux/include/objsec.h | 5 ++ security/selinux/netlabel.c | 23 ++++----- security/smack/smack.h | 5 ++ security/smack/smack_lsm.c | 64 ++++++++++++------------- security/smack/smack_netfilter.c | 8 ++-- 10 files changed, 144 insertions(+), 120 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index f9222a04968d..b353482ea348 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -2047,6 +2047,7 @@ struct lsm_blob_sizes { int lbs_cred; int lbs_file; int lbs_inode; + int lbs_sock; int lbs_superblock; int lbs_ipc; int lbs_msg_msg; diff --git a/security/apparmor/include/net.h b/security/apparmor/include/net.h index 7334ac966d01..adac04e3b3cc 100644 --- a/security/apparmor/include/net.h +++ b/security/apparmor/include/net.h @@ -55,7 +55,11 @@ struct aa_sk_ctx { struct aa_label *peer; }; -#define SK_CTX(X) ((X)->sk_security) +static inline struct aa_sk_ctx *aa_sock(const struct sock *sk) +{ + return sk->sk_security + apparmor_blob_sizes.lbs_sock; +} + #define SOCK_ctx(X) SOCK_INODE(X)->i_security #define DEFINE_AUDIT_NET(NAME, OP, SK, F, T, P) \ struct lsm_network_audit NAME ## _net = { .sk = (SK), \ diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 49d664ddff44..2716e7731279 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -757,33 +757,15 @@ static int apparmor_task_kill(struct task_struct *target, struct kernel_siginfo return error; } -/** - * apparmor_sk_alloc_security - allocate and attach the sk_security field - */ -static int apparmor_sk_alloc_security(struct sock *sk, int family, gfp_t flags) -{ - struct aa_sk_ctx *ctx; - - ctx = kzalloc(sizeof(*ctx), flags); - if (!ctx) - return -ENOMEM; - - SK_CTX(sk) = ctx; - - return 0; -} - /** * apparmor_sk_free_security - free the sk_security field */ static void apparmor_sk_free_security(struct sock *sk) { - struct aa_sk_ctx *ctx = SK_CTX(sk); + struct aa_sk_ctx *ctx = aa_sock(sk); - SK_CTX(sk) = NULL; aa_put_label(ctx->label); aa_put_label(ctx->peer); - kfree(ctx); } /** @@ -792,8 +774,8 @@ static void apparmor_sk_free_security(struct sock *sk) static void apparmor_sk_clone_security(const struct sock *sk, struct sock *newsk) { - struct aa_sk_ctx *ctx = SK_CTX(sk); - struct aa_sk_ctx *new = SK_CTX(newsk); + struct aa_sk_ctx *ctx = aa_sock(sk); + struct aa_sk_ctx *new = aa_sock(newsk); new->label = aa_get_label(ctx->label); new->peer = aa_get_label(ctx->peer); @@ -844,7 +826,7 @@ static int apparmor_socket_post_create(struct socket *sock, int family, label = aa_get_current_label(); if (sock->sk) { - struct aa_sk_ctx *ctx = SK_CTX(sock->sk); + struct aa_sk_ctx *ctx = aa_sock(sock->sk); aa_put_label(ctx->label); ctx->label = aa_get_label(label); @@ -1029,7 +1011,7 @@ static int apparmor_socket_shutdown(struct socket *sock, int how) */ static int apparmor_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) { - struct aa_sk_ctx *ctx = SK_CTX(sk); + struct aa_sk_ctx *ctx = aa_sock(sk); if (!skb->secmark) return 0; @@ -1042,7 +1024,7 @@ static int apparmor_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) static struct aa_label *sk_peer_label(struct sock *sk) { - struct aa_sk_ctx *ctx = SK_CTX(sk); + struct aa_sk_ctx *ctx = aa_sock(sk); if (ctx->peer) return ctx->peer; @@ -1126,7 +1108,7 @@ static int apparmor_socket_getpeersec_dgram(struct socket *sock, */ static void apparmor_sock_graft(struct sock *sk, struct socket *parent) { - struct aa_sk_ctx *ctx = SK_CTX(sk); + struct aa_sk_ctx *ctx = aa_sock(sk); if (!ctx->label) ctx->label = aa_get_current_label(); @@ -1136,7 +1118,7 @@ static void apparmor_sock_graft(struct sock *sk, struct socket *parent) static int apparmor_inet_conn_request(struct sock *sk, struct sk_buff *skb, struct request_sock *req) { - struct aa_sk_ctx *ctx = SK_CTX(sk); + struct aa_sk_ctx *ctx = aa_sock(sk); if (!skb->secmark) return 0; @@ -1153,6 +1135,7 @@ struct lsm_blob_sizes apparmor_blob_sizes __lsm_ro_after_init = { .lbs_cred = sizeof(struct aa_task_ctx *), .lbs_file = sizeof(struct aa_file_ctx), .lbs_task = sizeof(struct aa_task_ctx), + .lbs_sock = sizeof(struct aa_sk_ctx), }; static struct security_hook_list apparmor_hooks[] __lsm_ro_after_init = { @@ -1189,7 +1172,6 @@ static struct security_hook_list apparmor_hooks[] __lsm_ro_after_init = { LSM_HOOK_INIT(getprocattr, apparmor_getprocattr), LSM_HOOK_INIT(setprocattr, apparmor_setprocattr), - LSM_HOOK_INIT(sk_alloc_security, apparmor_sk_alloc_security), LSM_HOOK_INIT(sk_free_security, apparmor_sk_free_security), LSM_HOOK_INIT(sk_clone_security, apparmor_sk_clone_security), @@ -1581,7 +1563,7 @@ static unsigned int apparmor_ip_postroute(void *priv, if (sk == NULL) return NF_ACCEPT; - ctx = SK_CTX(sk); + ctx = aa_sock(sk); if (!apparmor_secmark_check(ctx->label, OP_SENDMSG, AA_MAY_SEND, skb->secmark, sk)) return NF_ACCEPT; diff --git a/security/security.c b/security/security.c index 550988a0f024..e32b7180282e 100644 --- a/security/security.c +++ b/security/security.c @@ -32,6 +32,7 @@ #include #include #include +#include #define MAX_LSM_EVM_XATTR 2 @@ -172,6 +173,7 @@ static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed) lsm_set_blob_size(&needed->lbs_inode, &blob_sizes.lbs_inode); lsm_set_blob_size(&needed->lbs_ipc, &blob_sizes.lbs_ipc); lsm_set_blob_size(&needed->lbs_msg_msg, &blob_sizes.lbs_msg_msg); + lsm_set_blob_size(&needed->lbs_sock, &blob_sizes.lbs_sock); lsm_set_blob_size(&needed->lbs_superblock, &blob_sizes.lbs_superblock); lsm_set_blob_size(&needed->lbs_task, &blob_sizes.lbs_task); } @@ -306,6 +308,7 @@ static void __init ordered_lsm_init(void) init_debug("inode blob size = %d\n", blob_sizes.lbs_inode); init_debug("ipc blob size = %d\n", blob_sizes.lbs_ipc); init_debug("msg_msg blob size = %d\n", blob_sizes.lbs_msg_msg); + init_debug("sock blob size = %d\n", blob_sizes.lbs_sock); init_debug("superblock blob size = %d\n", blob_sizes.lbs_superblock); init_debug("task blob size = %d\n", blob_sizes.lbs_task); @@ -605,6 +608,28 @@ static void __init lsm_early_task(struct task_struct *task) panic("%s: Early task alloc failed.\n", __func__); } +/** + * lsm_sock_alloc - allocate a composite sock blob + * @sock: the sock that needs a blob + * @priority: allocation mode + * + * Allocate the sock blob for all the modules + * + * Returns 0, or -ENOMEM if memory can't be allocated. + */ +int lsm_sock_alloc(struct sock *sock, gfp_t priority) +{ + if (blob_sizes.lbs_sock == 0) { + sock->sk_security = NULL; + return 0; + } + + sock->sk_security = kzalloc(blob_sizes.lbs_sock, priority); + if (sock->sk_security == NULL) + return -ENOMEM; + return 0; +} + /** * lsm_superblock_alloc - allocate a composite superblock blob * @sb: the superblock that needs a blob @@ -2048,12 +2073,21 @@ EXPORT_SYMBOL(security_socket_getpeersec_dgram); int security_sk_alloc(struct sock *sk, int family, gfp_t priority) { - return call_int_hook(sk_alloc_security, 0, sk, family, priority); + int rc = lsm_sock_alloc(sk, priority); + + if (unlikely(rc)) + return rc; + rc = call_int_hook(sk_alloc_security, 0, sk, family, priority); + if (unlikely(rc)) + security_sk_free(sk); + return rc; } void security_sk_free(struct sock *sk) { call_void_hook(sk_free_security, sk); + kfree(sk->sk_security); + sk->sk_security = NULL; } void security_sk_clone(const struct sock *sk, struct sock *newsk) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 7478d8eda00a..f38a6f484613 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -4319,7 +4319,7 @@ static int socket_sockcreate_sid(const struct task_security_struct *tsec, static int sock_has_perm(struct sock *sk, u32 perms) { - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); struct common_audit_data ad; struct lsm_network_audit net = {0,}; @@ -4376,7 +4376,7 @@ static int selinux_socket_post_create(struct socket *sock, int family, isec->initialized = LABEL_INITIALIZED; if (sock->sk) { - sksec = sock->sk->sk_security; + sksec = selinux_sock(sock->sk); sksec->sclass = sclass; sksec->sid = sid; /* Allows detection of the first association on this socket */ @@ -4392,8 +4392,8 @@ static int selinux_socket_post_create(struct socket *sock, int family, static int selinux_socket_socketpair(struct socket *socka, struct socket *sockb) { - struct sk_security_struct *sksec_a = socka->sk->sk_security; - struct sk_security_struct *sksec_b = sockb->sk->sk_security; + struct sk_security_struct *sksec_a = selinux_sock(socka->sk); + struct sk_security_struct *sksec_b = selinux_sock(sockb->sk); sksec_a->peer_sid = sksec_b->sid; sksec_b->peer_sid = sksec_a->sid; @@ -4408,7 +4408,7 @@ static int selinux_socket_socketpair(struct socket *socka, static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen) { struct sock *sk = sock->sk; - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); u16 family; int err; @@ -4540,7 +4540,7 @@ static int selinux_socket_connect_helper(struct socket *sock, struct sockaddr *address, int addrlen) { struct sock *sk = sock->sk; - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); int err; err = sock_has_perm(sk, SOCKET__CONNECT); @@ -4711,9 +4711,9 @@ static int selinux_socket_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk) { - struct sk_security_struct *sksec_sock = sock->sk_security; - struct sk_security_struct *sksec_other = other->sk_security; - struct sk_security_struct *sksec_new = newsk->sk_security; + struct sk_security_struct *sksec_sock = selinux_sock(sock); + struct sk_security_struct *sksec_other = selinux_sock(other); + struct sk_security_struct *sksec_new = selinux_sock(newsk); struct common_audit_data ad; struct lsm_network_audit net = {0,}; int err; @@ -4745,8 +4745,8 @@ static int selinux_socket_unix_stream_connect(struct sock *sock, static int selinux_socket_unix_may_send(struct socket *sock, struct socket *other) { - struct sk_security_struct *ssec = sock->sk->sk_security; - struct sk_security_struct *osec = other->sk->sk_security; + struct sk_security_struct *ssec = selinux_sock(sock->sk); + struct sk_security_struct *osec = selinux_sock(other->sk); struct common_audit_data ad; struct lsm_network_audit net = {0,}; @@ -4788,7 +4788,7 @@ static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb, u16 family) { int err = 0; - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); u32 sk_sid = sksec->sid; struct common_audit_data ad; struct lsm_network_audit net = {0,}; @@ -4821,7 +4821,7 @@ static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb, static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) { int err; - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); u16 family = sk->sk_family; u32 sk_sid = sksec->sid; struct common_audit_data ad; @@ -4889,13 +4889,15 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) return err; } -static int selinux_socket_getpeersec_stream(struct socket *sock, char __user *optval, - int __user *optlen, unsigned len) +static int selinux_socket_getpeersec_stream(struct socket *sock, + __user char *optval, + __user int *optlen, + unsigned int len) { int err = 0; char *scontext; u32 scontext_len; - struct sk_security_struct *sksec = sock->sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sock->sk); u32 peer_sid = SECSID_NULL; if (sksec->sclass == SECCLASS_UNIX_STREAM_SOCKET || @@ -4955,34 +4957,27 @@ static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff * static int selinux_sk_alloc_security(struct sock *sk, int family, gfp_t priority) { - struct sk_security_struct *sksec; - - sksec = kzalloc(sizeof(*sksec), priority); - if (!sksec) - return -ENOMEM; + struct sk_security_struct *sksec = selinux_sock(sk); sksec->peer_sid = SECINITSID_UNLABELED; sksec->sid = SECINITSID_UNLABELED; sksec->sclass = SECCLASS_SOCKET; selinux_netlbl_sk_security_reset(sksec); - sk->sk_security = sksec; return 0; } static void selinux_sk_free_security(struct sock *sk) { - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); - sk->sk_security = NULL; selinux_netlbl_sk_security_free(sksec); - kfree(sksec); } static void selinux_sk_clone_security(const struct sock *sk, struct sock *newsk) { - struct sk_security_struct *sksec = sk->sk_security; - struct sk_security_struct *newsksec = newsk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); + struct sk_security_struct *newsksec = selinux_sock(newsk); newsksec->sid = sksec->sid; newsksec->peer_sid = sksec->peer_sid; @@ -4996,7 +4991,7 @@ static void selinux_sk_getsecid(struct sock *sk, u32 *secid) if (!sk) *secid = SECINITSID_ANY_SOCKET; else { - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); *secid = sksec->sid; } @@ -5006,7 +5001,7 @@ static void selinux_sock_graft(struct sock *sk, struct socket *parent) { struct inode_security_struct *isec = inode_security_novalidate(SOCK_INODE(parent)); - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); if (sk->sk_family == PF_INET || sk->sk_family == PF_INET6 || sk->sk_family == PF_UNIX) @@ -5021,7 +5016,7 @@ static void selinux_sock_graft(struct sock *sk, struct socket *parent) static int selinux_sctp_assoc_request(struct sctp_endpoint *ep, struct sk_buff *skb) { - struct sk_security_struct *sksec = ep->base.sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(ep->base.sk); struct common_audit_data ad; struct lsm_network_audit net = {0,}; u8 peerlbl_active; @@ -5172,8 +5167,8 @@ static int selinux_sctp_bind_connect(struct sock *sk, int optname, static void selinux_sctp_sk_clone(struct sctp_endpoint *ep, struct sock *sk, struct sock *newsk) { - struct sk_security_struct *sksec = sk->sk_security; - struct sk_security_struct *newsksec = newsk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); + struct sk_security_struct *newsksec = selinux_sock(newsk); /* If policy does not support SECCLASS_SCTP_SOCKET then call * the non-sctp clone version. @@ -5190,7 +5185,7 @@ static void selinux_sctp_sk_clone(struct sctp_endpoint *ep, struct sock *sk, static int selinux_inet_conn_request(struct sock *sk, struct sk_buff *skb, struct request_sock *req) { - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); int err; u16 family = req->rsk_ops->family; u32 connsid; @@ -5211,7 +5206,7 @@ static int selinux_inet_conn_request(struct sock *sk, struct sk_buff *skb, static void selinux_inet_csk_clone(struct sock *newsk, const struct request_sock *req) { - struct sk_security_struct *newsksec = newsk->sk_security; + struct sk_security_struct *newsksec = selinux_sock(newsk); newsksec->sid = req->secid; newsksec->peer_sid = req->peer_secid; @@ -5228,7 +5223,7 @@ static void selinux_inet_csk_clone(struct sock *newsk, static void selinux_inet_conn_established(struct sock *sk, struct sk_buff *skb) { u16 family = sk->sk_family; - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); /* handle mapped IPv4 packets arriving via IPv6 sockets */ if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP)) @@ -5312,7 +5307,7 @@ static int selinux_tun_dev_attach_queue(void *security) static int selinux_tun_dev_attach(struct sock *sk, void *security) { struct tun_security_struct *tunsec = security; - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); /* we don't currently perform any NetLabel based labeling here and it * isn't clear that we would want to do so anyway; while we could apply @@ -5353,7 +5348,7 @@ static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb) int err = 0; u32 perm; struct nlmsghdr *nlh; - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); if (skb->len < NLMSG_HDRLEN) { err = -EINVAL; @@ -5494,7 +5489,7 @@ static unsigned int selinux_ip_output(struct sk_buff *skb, return NF_ACCEPT; /* standard practice, label using the parent socket */ - sksec = sk->sk_security; + sksec = selinux_sock(sk); sid = sksec->sid; } else sid = SECINITSID_KERNEL; @@ -5533,7 +5528,7 @@ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb, if (sk == NULL) return NF_ACCEPT; - sksec = sk->sk_security; + sksec = selinux_sock(sk); ad.type = LSM_AUDIT_DATA_NET; ad.u.net = &net; @@ -5625,7 +5620,7 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, u32 skb_sid; struct sk_security_struct *sksec; - sksec = sk->sk_security; + sksec = selinux_sock(sk); if (selinux_skb_peerlbl_sid(skb, family, &skb_sid)) return NF_DROP; /* At this point, if the returned skb peerlbl is SECSID_NULL @@ -5654,7 +5649,7 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, } else { /* Locally generated packet, fetch the security label from the * associated socket. */ - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); peer_sid = sksec->sid; secmark_perm = PACKET__SEND; } @@ -6633,6 +6628,7 @@ struct lsm_blob_sizes selinux_blob_sizes __lsm_ro_after_init = { .lbs_inode = sizeof(struct inode_security_struct), .lbs_ipc = sizeof(struct ipc_security_struct), .lbs_msg_msg = sizeof(struct msg_security_struct), + .lbs_sock = sizeof(struct sk_security_struct), .lbs_superblock = sizeof(struct superblock_security_struct), }; diff --git a/security/selinux/include/objsec.h b/security/selinux/include/objsec.h index d08d7e5d2f93..29f02b8f8f31 100644 --- a/security/selinux/include/objsec.h +++ b/security/selinux/include/objsec.h @@ -194,4 +194,9 @@ static inline struct superblock_security_struct *selinux_superblock( return superblock->s_security + selinux_blob_sizes.lbs_superblock; } +static inline struct sk_security_struct *selinux_sock(const struct sock *sock) +{ + return sock->sk_security + selinux_blob_sizes.lbs_sock; +} + #endif /* _SELINUX_OBJSEC_H_ */ diff --git a/security/selinux/netlabel.c b/security/selinux/netlabel.c index 186e727b737b..c40914a157b7 100644 --- a/security/selinux/netlabel.c +++ b/security/selinux/netlabel.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -81,7 +82,7 @@ static int selinux_netlbl_sidlookup_cached(struct sk_buff *skb, static struct netlbl_lsm_secattr *selinux_netlbl_sock_genattr(struct sock *sk) { int rc; - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); struct netlbl_lsm_secattr *secattr; if (sksec->nlbl_secattr != NULL) @@ -114,7 +115,7 @@ static struct netlbl_lsm_secattr *selinux_netlbl_sock_getattr( const struct sock *sk, u32 sid) { - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); struct netlbl_lsm_secattr *secattr = sksec->nlbl_secattr; if (secattr == NULL) @@ -249,7 +250,7 @@ int selinux_netlbl_skbuff_setsid(struct sk_buff *skb, * being labeled by it's parent socket, if it is just exit */ sk = skb_to_full_sk(skb); if (sk != NULL) { - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); if (sksec->nlbl_state != NLBL_REQSKB) return 0; @@ -287,7 +288,7 @@ int selinux_netlbl_sctp_assoc_request(struct sctp_endpoint *ep, { int rc; struct netlbl_lsm_secattr secattr; - struct sk_security_struct *sksec = ep->base.sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(ep->base.sk); struct sockaddr *addr; struct sockaddr_in addr4; #if IS_ENABLED(CONFIG_IPV6) @@ -370,7 +371,7 @@ int selinux_netlbl_inet_conn_request(struct request_sock *req, u16 family) */ void selinux_netlbl_inet_csk_clone(struct sock *sk, u16 family) { - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); if (family == PF_INET) sksec->nlbl_state = NLBL_LABELED; @@ -388,8 +389,8 @@ void selinux_netlbl_inet_csk_clone(struct sock *sk, u16 family) */ void selinux_netlbl_sctp_sk_clone(struct sock *sk, struct sock *newsk) { - struct sk_security_struct *sksec = sk->sk_security; - struct sk_security_struct *newsksec = newsk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); + struct sk_security_struct *newsksec = selinux_sock(newsk); newsksec->nlbl_state = sksec->nlbl_state; } @@ -407,7 +408,7 @@ void selinux_netlbl_sctp_sk_clone(struct sock *sk, struct sock *newsk) int selinux_netlbl_socket_post_create(struct sock *sk, u16 family) { int rc; - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); struct netlbl_lsm_secattr *secattr; if (family != PF_INET && family != PF_INET6) @@ -522,7 +523,7 @@ int selinux_netlbl_socket_setsockopt(struct socket *sock, { int rc = 0; struct sock *sk = sock->sk; - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); struct netlbl_lsm_secattr secattr; if (selinux_netlbl_option(level, optname) && @@ -560,7 +561,7 @@ static int selinux_netlbl_socket_connect_helper(struct sock *sk, struct sockaddr *addr) { int rc; - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); struct netlbl_lsm_secattr *secattr; /* connected sockets are allowed to disconnect when the address family @@ -599,7 +600,7 @@ static int selinux_netlbl_socket_connect_helper(struct sock *sk, int selinux_netlbl_socket_connect_locked(struct sock *sk, struct sockaddr *addr) { - struct sk_security_struct *sksec = sk->sk_security; + struct sk_security_struct *sksec = selinux_sock(sk); if (sksec->nlbl_state != NLBL_REQSKB && sksec->nlbl_state != NLBL_CONNLABELED) diff --git a/security/smack/smack.h b/security/smack/smack.h index caecbcba9942..4ac4bf3310d7 100644 --- a/security/smack/smack.h +++ b/security/smack/smack.h @@ -375,6 +375,11 @@ static inline struct smack_known **smack_ipc(const struct kern_ipc_perm *ipc) return ipc->security + smack_blob_sizes.lbs_ipc; } +static inline struct socket_smack *smack_sock(const struct sock *sock) +{ + return sock->sk_security + smack_blob_sizes.lbs_sock; +} + static inline struct superblock_smack *smack_superblock( const struct super_block *superblock) { diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 807eff2ccce9..fd69e1bd841b 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -1439,7 +1439,7 @@ static int smack_inode_getsecurity(struct inode *inode, if (sock == NULL || sock->sk == NULL) return -EOPNOTSUPP; - ssp = sock->sk->sk_security; + ssp = smack_sock(sock->sk); if (strcmp(name, XATTR_SMACK_IPIN) == 0) isp = ssp->smk_in; @@ -1821,7 +1821,7 @@ static int smack_file_receive(struct file *file) if (inode->i_sb->s_magic == SOCKFS_MAGIC) { sock = SOCKET_I(inode); - ssp = sock->sk->sk_security; + ssp = smack_sock(sock->sk); tsp = smack_cred(current_cred()); /* * If the receiving process can't write to the @@ -2231,11 +2231,7 @@ static void smack_task_to_inode(struct task_struct *p, struct inode *inode) static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags) { struct smack_known *skp = smk_of_current(); - struct socket_smack *ssp; - - ssp = kzalloc(sizeof(struct socket_smack), gfp_flags); - if (ssp == NULL) - return -ENOMEM; + struct socket_smack *ssp = smack_sock(sk); /* * Sockets created by kernel threads receive web label. @@ -2249,11 +2245,10 @@ static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags) } ssp->smk_packet = NULL; - sk->sk_security = ssp; - return 0; } +#ifdef SMACK_IPV6_PORT_LABELING /** * smack_sk_free_security - Free a socket blob * @sk: the socket @@ -2262,7 +2257,6 @@ static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags) */ static void smack_sk_free_security(struct sock *sk) { -#ifdef SMACK_IPV6_PORT_LABELING struct smk_port_label *spp; if (sk->sk_family == PF_INET6) { @@ -2275,9 +2269,8 @@ static void smack_sk_free_security(struct sock *sk) } rcu_read_unlock(); } -#endif - kfree(sk->sk_security); } +#endif /** * smack_ipv4host_label - check host based restrictions @@ -2395,7 +2388,7 @@ static struct smack_known *smack_ipv6host_label(struct sockaddr_in6 *sip) static int smack_netlabel(struct sock *sk, int labeled) { struct smack_known *skp; - struct socket_smack *ssp = sk->sk_security; + struct socket_smack *ssp = smack_sock(sk); int rc = 0; /* @@ -2440,7 +2433,7 @@ static int smack_netlabel_send(struct sock *sk, struct sockaddr_in *sap) int rc; int sk_lbl; struct smack_known *hkp; - struct socket_smack *ssp = sk->sk_security; + struct socket_smack *ssp = smack_sock(sk); struct smk_audit_info ad; rcu_read_lock(); @@ -2516,7 +2509,7 @@ static void smk_ipv6_port_label(struct socket *sock, struct sockaddr *address) { struct sock *sk = sock->sk; struct sockaddr_in6 *addr6; - struct socket_smack *ssp = sock->sk->sk_security; + struct socket_smack *ssp = smack_sock(sock->sk); struct smk_port_label *spp; unsigned short port = 0; @@ -2603,7 +2596,7 @@ static int smk_ipv6_port_check(struct sock *sk, struct sockaddr_in6 *address, int act) { struct smk_port_label *spp; - struct socket_smack *ssp = sk->sk_security; + struct socket_smack *ssp = smack_sock(sk); struct smack_known *skp = NULL; unsigned short port; struct smack_known *object; @@ -2697,7 +2690,7 @@ static int smack_inode_setsecurity(struct inode *inode, const char *name, if (sock == NULL || sock->sk == NULL) return -EOPNOTSUPP; - ssp = sock->sk->sk_security; + ssp = smack_sock(sock->sk); if (strcmp(name, XATTR_SMACK_IPIN) == 0) ssp->smk_in = skp; @@ -2745,7 +2738,7 @@ static int smack_socket_post_create(struct socket *sock, int family, * Sockets created by kernel threads receive web label. */ if (unlikely(current->flags & PF_KTHREAD)) { - ssp = sock->sk->sk_security; + ssp = smack_sock(sock->sk); ssp->smk_in = &smack_known_web; ssp->smk_out = &smack_known_web; } @@ -2770,8 +2763,8 @@ static int smack_socket_post_create(struct socket *sock, int family, static int smack_socket_socketpair(struct socket *socka, struct socket *sockb) { - struct socket_smack *asp = socka->sk->sk_security; - struct socket_smack *bsp = sockb->sk->sk_security; + struct socket_smack *asp = smack_sock(socka->sk); + struct socket_smack *bsp = smack_sock(sockb->sk); asp->smk_packet = bsp->smk_out; bsp->smk_packet = asp->smk_out; @@ -2825,7 +2818,7 @@ static int smack_socket_connect(struct socket *sock, struct sockaddr *sap, return 0; #ifdef SMACK_IPV6_SECMARK_LABELING - ssp = sock->sk->sk_security; + ssp = smack_sock(sock->sk); #endif switch (sock->sk->sk_family) { @@ -3566,9 +3559,9 @@ static int smack_unix_stream_connect(struct sock *sock, { struct smack_known *skp; struct smack_known *okp; - struct socket_smack *ssp = sock->sk_security; - struct socket_smack *osp = other->sk_security; - struct socket_smack *nsp = newsk->sk_security; + struct socket_smack *ssp = smack_sock(sock); + struct socket_smack *osp = smack_sock(other); + struct socket_smack *nsp = smack_sock(newsk); struct smk_audit_info ad; int rc = 0; #ifdef CONFIG_AUDIT @@ -3614,8 +3607,8 @@ static int smack_unix_stream_connect(struct sock *sock, */ static int smack_unix_may_send(struct socket *sock, struct socket *other) { - struct socket_smack *ssp = sock->sk->sk_security; - struct socket_smack *osp = other->sk->sk_security; + struct socket_smack *ssp = smack_sock(sock->sk); + struct socket_smack *osp = smack_sock(other->sk); struct smk_audit_info ad; int rc; @@ -3652,7 +3645,7 @@ static int smack_socket_sendmsg(struct socket *sock, struct msghdr *msg, struct sockaddr_in6 *sap = (struct sockaddr_in6 *) msg->msg_name; #endif #ifdef SMACK_IPV6_SECMARK_LABELING - struct socket_smack *ssp = sock->sk->sk_security; + struct socket_smack *ssp = smack_sock(sock->sk); struct smack_known *rsp; #endif int rc = 0; @@ -3817,7 +3810,7 @@ static int smk_skb_to_addr_ipv6(struct sk_buff *skb, struct sockaddr_in6 *sip) static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) { struct netlbl_lsm_secattr secattr; - struct socket_smack *ssp = sk->sk_security; + struct socket_smack *ssp = smack_sock(sk); struct smack_known *skp = NULL; int rc = 0; struct smk_audit_info ad; @@ -3934,7 +3927,7 @@ static int smack_socket_getpeersec_stream(struct socket *sock, int slen = 1; int rc = 0; - ssp = sock->sk->sk_security; + ssp = smack_sock(sock->sk); if (ssp->smk_packet != NULL) { rcp = ssp->smk_packet->smk_known; slen = strlen(rcp) + 1; @@ -3984,7 +3977,7 @@ static int smack_socket_getpeersec_dgram(struct socket *sock, switch (family) { case PF_UNIX: - ssp = sock->sk->sk_security; + ssp = smack_sock(sock->sk); s = ssp->smk_out->smk_secid; break; case PF_INET: @@ -3997,7 +3990,7 @@ static int smack_socket_getpeersec_dgram(struct socket *sock, * Translate what netlabel gave us. */ if (sock != NULL && sock->sk != NULL) - ssp = sock->sk->sk_security; + ssp = smack_sock(sock->sk); netlbl_secattr_init(&secattr); rc = netlbl_skbuff_getattr(skb, family, &secattr); if (rc == 0) { @@ -4035,7 +4028,7 @@ static void smack_sock_graft(struct sock *sk, struct socket *parent) (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)) return; - ssp = sk->sk_security; + ssp = smack_sock(sk); ssp->smk_in = skp; ssp->smk_out = skp; /* cssp->smk_packet is already set in smack_inet_csk_clone() */ @@ -4055,7 +4048,7 @@ static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb, { u16 family = sk->sk_family; struct smack_known *skp; - struct socket_smack *ssp = sk->sk_security; + struct socket_smack *ssp = smack_sock(sk); struct netlbl_lsm_secattr secattr; struct sockaddr_in addr; struct iphdr *hdr; @@ -4154,7 +4147,7 @@ static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb, static void smack_inet_csk_clone(struct sock *sk, const struct request_sock *req) { - struct socket_smack *ssp = sk->sk_security; + struct socket_smack *ssp = smack_sock(sk); struct smack_known *skp; if (req->peer_secid != 0) { @@ -4558,6 +4551,7 @@ struct lsm_blob_sizes smack_blob_sizes __lsm_ro_after_init = { .lbs_inode = sizeof(struct inode_smack), .lbs_ipc = sizeof(struct smack_known *), .lbs_msg_msg = sizeof(struct smack_known *), + .lbs_sock = sizeof(struct socket_smack), .lbs_superblock = sizeof(struct superblock_smack), }; @@ -4667,7 +4661,9 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = { LSM_HOOK_INIT(socket_getpeersec_stream, smack_socket_getpeersec_stream), LSM_HOOK_INIT(socket_getpeersec_dgram, smack_socket_getpeersec_dgram), LSM_HOOK_INIT(sk_alloc_security, smack_sk_alloc_security), +#ifdef SMACK_IPV6_PORT_LABELING LSM_HOOK_INIT(sk_free_security, smack_sk_free_security), +#endif LSM_HOOK_INIT(sock_graft, smack_sock_graft), LSM_HOOK_INIT(inet_conn_request, smack_inet_conn_request), LSM_HOOK_INIT(inet_csk_clone, smack_inet_csk_clone), diff --git a/security/smack/smack_netfilter.c b/security/smack/smack_netfilter.c index e36d17835d4f..701a1cc1bdcc 100644 --- a/security/smack/smack_netfilter.c +++ b/security/smack/smack_netfilter.c @@ -31,8 +31,8 @@ static unsigned int smack_ipv6_output(void *priv, struct socket_smack *ssp; struct smack_known *skp; - if (sk && sk->sk_security) { - ssp = sk->sk_security; + if (sk && smack_sock(sk)) { + ssp = smack_sock(sk); skp = ssp->smk_out; skb->secmark = skp->smk_secid; } @@ -49,8 +49,8 @@ static unsigned int smack_ipv4_output(void *priv, struct socket_smack *ssp; struct smack_known *skp; - if (sk && sk->sk_security) { - ssp = sk->sk_security; + if (sk && smack_sock(sk)) { + ssp = smack_sock(sk); skp = ssp->smk_out; skb->secmark = skp->smk_secid; } From patchwork Sun Jun 2 16:50:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971801 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 87EB317DF for ; Sun, 2 Jun 2019 16:51:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7439B286E4 for ; Sun, 2 Jun 2019 16:51:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 685E328A00; Sun, 2 Jun 2019 16:51:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71AE028703 for ; Sun, 2 Jun 2019 16:51:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726695AbfFBQvN (ORCPT ); Sun, 2 Jun 2019 12:51:13 -0400 Received: from sonic302-8.consmr.mail.bf2.yahoo.com ([74.6.135.47]:38396 "EHLO sonic302-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726842AbfFBQvN (ORCPT ); Sun, 2 Jun 2019 12:51:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494270; bh=VQcY1jM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tbjCTYtzBPUznFkR3ubolEEJ6aeg_DXqVGhfVZra_ Ono3Ganwz0f8bX3hySL6K7nCqhzaLmPGAAbeO4jPZZGabeuGYxYDtgrKRr0imLxRX4fBSZJjpG4U Mr9mD1BHenyOohkBS0izKetYTrIC_dKFrlFAz93nKmtPHm1T6pbW93XfjHL6q.EG.zOvE1xzx30s qysqW3edVe407rJYoIg087ztYO6lolyt4EqxypABq5hMjyW8rvxH2IIJ1RrQiqQalTQXDEvnYEJV zHRSEz2zHPy9vomRNAs_m_vUp2Ria2nQDxVzv4x_oQ40QWOvSUzLBC4pcPPUqxN79ydPHLP1WgF2 Q1m6F8C9FkRoJGbIz9ueIn1B0rmZiiACZegjtqPK3k3nNfnciNVNEgXgiwGtw._ykUOTbaLPdbT_ jg4.zuaX_VeYATdJmO61MbPSaM3Ez4DDWqNELhetZsqx8tQTPl0vVjXtm6pm83B2G7LcM0C6dAMo SlLV_j9JLko4vy_QKOkc3DsCQuontL1qwHXHg5ueLemXsqWT9FnMXtEKMVwQAW6yvFp61EbJS9L8 L_7AE7NoicdDxc.PB80HRLCrhKKoZT.uuU9v.znOGTYbZrRl8_AiBnpN5MPDm5oOrCoD2xhTGuOm GXx8nz4B4JOjSR0a7h9nZDUkoelfDWb9dmoc8iEu8Lwi8Mw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:51:10 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp429.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 844f659d1e234107537a664739855744; Sun, 02 Jun 2019 16:51:09 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 03/58] LSM: Infrastructure management of the key security blob Date: Sun, 2 Jun 2019 09:50:06 -0700 Message-Id: <20190602165101.25079-4-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Casey Schaufler Move management of the key->security blob out of the individual security modules and into the security infrastructure. Instead of allocating the blobs from within the modules the modules tell the infrastructure how much space is required, and the space is allocated there. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 1 + security/security.c | 40 ++++++++++++++++++++++++++++++- security/selinux/hooks.c | 23 +++++------------- security/selinux/include/objsec.h | 7 ++++++ security/smack/smack.h | 7 ++++++ security/smack/smack_lsm.c | 33 ++++++++++++------------- 6 files changed, 75 insertions(+), 36 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index b353482ea348..3fe39abccc8f 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -2050,6 +2050,7 @@ struct lsm_blob_sizes { int lbs_sock; int lbs_superblock; int lbs_ipc; + int lbs_key; int lbs_msg_msg; int lbs_task; }; diff --git a/security/security.c b/security/security.c index e32b7180282e..d05f00a40e82 100644 --- a/security/security.c +++ b/security/security.c @@ -172,6 +172,9 @@ static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed) blob_sizes.lbs_inode = sizeof(struct rcu_head); lsm_set_blob_size(&needed->lbs_inode, &blob_sizes.lbs_inode); lsm_set_blob_size(&needed->lbs_ipc, &blob_sizes.lbs_ipc); +#ifdef CONFIG_KEYS + lsm_set_blob_size(&needed->lbs_key, &blob_sizes.lbs_key); +#endif lsm_set_blob_size(&needed->lbs_msg_msg, &blob_sizes.lbs_msg_msg); lsm_set_blob_size(&needed->lbs_sock, &blob_sizes.lbs_sock); lsm_set_blob_size(&needed->lbs_superblock, &blob_sizes.lbs_superblock); @@ -307,6 +310,9 @@ static void __init ordered_lsm_init(void) init_debug("file blob size = %d\n", blob_sizes.lbs_file); init_debug("inode blob size = %d\n", blob_sizes.lbs_inode); init_debug("ipc blob size = %d\n", blob_sizes.lbs_ipc); +#ifdef CONFIG_KEYS + init_debug("key blob size = %d\n", blob_sizes.lbs_key); +#endif /* CONFIG_KEYS */ init_debug("msg_msg blob size = %d\n", blob_sizes.lbs_msg_msg); init_debug("sock blob size = %d\n", blob_sizes.lbs_sock); init_debug("superblock blob size = %d\n", blob_sizes.lbs_superblock); @@ -573,6 +579,29 @@ static int lsm_ipc_alloc(struct kern_ipc_perm *kip) return 0; } +#ifdef CONFIG_KEYS +/** + * lsm_key_alloc - allocate a composite key blob + * @key: the key that needs a blob + * + * Allocate the key blob for all the modules + * + * Returns 0, or -ENOMEM if memory can't be allocated. + */ +int lsm_key_alloc(struct key *key) +{ + if (blob_sizes.lbs_key == 0) { + key->security = NULL; + return 0; + } + + key->security = kzalloc(blob_sizes.lbs_key, GFP_KERNEL); + if (key->security == NULL) + return -ENOMEM; + return 0; +} +#endif /* CONFIG_KEYS */ + /** * lsm_msg_msg_alloc - allocate a composite msg_msg blob * @mp: the msg_msg that needs a blob @@ -2339,12 +2368,21 @@ EXPORT_SYMBOL(security_skb_classify_flow); int security_key_alloc(struct key *key, const struct cred *cred, unsigned long flags) { - return call_int_hook(key_alloc, 0, key, cred, flags); + int rc = lsm_key_alloc(key); + + if (unlikely(rc)) + return rc; + rc = call_int_hook(key_alloc, 0, key, cred, flags); + if (unlikely(rc)) + security_key_free(key); + return rc; } void security_key_free(struct key *key) { call_void_hook(key_free, key); + kfree(key->security); + key->security = NULL; } int security_key_permission(key_ref_t key_ref, diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index f38a6f484613..ee840fecfebb 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6353,11 +6353,7 @@ static int selinux_key_alloc(struct key *k, const struct cred *cred, unsigned long flags) { const struct task_security_struct *tsec; - struct key_security_struct *ksec; - - ksec = kzalloc(sizeof(struct key_security_struct), GFP_KERNEL); - if (!ksec) - return -ENOMEM; + struct key_security_struct *ksec = selinux_key(k); tsec = selinux_cred(cred); if (tsec->keycreate_sid) @@ -6365,18 +6361,9 @@ static int selinux_key_alloc(struct key *k, const struct cred *cred, else ksec->sid = tsec->sid; - k->security = ksec; return 0; } -static void selinux_key_free(struct key *k) -{ - struct key_security_struct *ksec = k->security; - - k->security = NULL; - kfree(ksec); -} - static int selinux_key_permission(key_ref_t key_ref, const struct cred *cred, unsigned perm) @@ -6394,7 +6381,7 @@ static int selinux_key_permission(key_ref_t key_ref, sid = cred_sid(cred); key = key_ref_to_ptr(key_ref); - ksec = key->security; + ksec = selinux_key(key); return avc_has_perm(&selinux_state, sid, ksec->sid, SECCLASS_KEY, perm, NULL); @@ -6402,7 +6389,7 @@ static int selinux_key_permission(key_ref_t key_ref, static int selinux_key_getsecurity(struct key *key, char **_buffer) { - struct key_security_struct *ksec = key->security; + struct key_security_struct *ksec = selinux_key(key); char *context = NULL; unsigned len; int rc; @@ -6627,6 +6614,9 @@ struct lsm_blob_sizes selinux_blob_sizes __lsm_ro_after_init = { .lbs_file = sizeof(struct file_security_struct), .lbs_inode = sizeof(struct inode_security_struct), .lbs_ipc = sizeof(struct ipc_security_struct), +#ifdef CONFIG_KEYS + .lbs_key = sizeof(struct key_security_struct), +#endif /* CONFIG_KEYS */ .lbs_msg_msg = sizeof(struct msg_security_struct), .lbs_sock = sizeof(struct sk_security_struct), .lbs_superblock = sizeof(struct superblock_security_struct), @@ -6842,7 +6832,6 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = { #ifdef CONFIG_KEYS LSM_HOOK_INIT(key_alloc, selinux_key_alloc), - LSM_HOOK_INIT(key_free, selinux_key_free), LSM_HOOK_INIT(key_permission, selinux_key_permission), LSM_HOOK_INIT(key_getsecurity, selinux_key_getsecurity), #endif diff --git a/security/selinux/include/objsec.h b/security/selinux/include/objsec.h index 29f02b8f8f31..3b78aa4ee98f 100644 --- a/security/selinux/include/objsec.h +++ b/security/selinux/include/objsec.h @@ -194,6 +194,13 @@ static inline struct superblock_security_struct *selinux_superblock( return superblock->s_security + selinux_blob_sizes.lbs_superblock; } +#ifdef CONFIG_KEYS +static inline struct key_security_struct *selinux_key(const struct key *key) +{ + return key->security + selinux_blob_sizes.lbs_key; +} +#endif /* CONFIG_KEYS */ + static inline struct sk_security_struct *selinux_sock(const struct sock *sock) { return sock->sk_security + selinux_blob_sizes.lbs_sock; diff --git a/security/smack/smack.h b/security/smack/smack.h index 4ac4bf3310d7..7cc3a3382fee 100644 --- a/security/smack/smack.h +++ b/security/smack/smack.h @@ -386,6 +386,13 @@ static inline struct superblock_smack *smack_superblock( return superblock->s_security + smack_blob_sizes.lbs_superblock; } +#ifdef CONFIG_KEYS +static inline struct smack_known **smack_key(const struct key *key) +{ + return key->security + smack_blob_sizes.lbs_key; +} +#endif /* CONFIG_KEYS */ + /* * Is the directory transmuting? */ diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index fd69e1bd841b..e9560b078efe 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4179,23 +4179,13 @@ static void smack_inet_csk_clone(struct sock *sk, static int smack_key_alloc(struct key *key, const struct cred *cred, unsigned long flags) { + struct smack_known **blob = smack_key(key); struct smack_known *skp = smk_of_task(smack_cred(cred)); - key->security = skp; + *blob = skp; return 0; } -/** - * smack_key_free - Clear the key security blob - * @key: the object - * - * Clear the blob pointer - */ -static void smack_key_free(struct key *key) -{ - key->security = NULL; -} - /** * smack_key_permission - Smack access on a key * @key_ref: gets to the object @@ -4208,6 +4198,8 @@ static void smack_key_free(struct key *key) static int smack_key_permission(key_ref_t key_ref, const struct cred *cred, unsigned perm) { + struct smack_known **blob; + struct smack_known *skp; struct key *keyp; struct smk_audit_info ad; struct smack_known *tkp = smk_of_task(smack_cred(cred)); @@ -4227,7 +4219,9 @@ static int smack_key_permission(key_ref_t key_ref, * If the key hasn't been initialized give it access so that * it may do so. */ - if (keyp->security == NULL) + blob = smack_key(keyp); + skp = *blob; + if (skp == NULL) return 0; /* * This should not occur @@ -4247,8 +4241,8 @@ static int smack_key_permission(key_ref_t key_ref, request |= MAY_READ; if (perm & (KEY_NEED_WRITE | KEY_NEED_LINK | KEY_NEED_SETATTR)) request |= MAY_WRITE; - rc = smk_access(tkp, keyp->security, request, &ad); - rc = smk_bu_note("key access", tkp, keyp->security, request, rc); + rc = smk_access(tkp, skp, request, &ad); + rc = smk_bu_note("key access", tkp, skp, request, rc); return rc; } @@ -4263,11 +4257,12 @@ static int smack_key_permission(key_ref_t key_ref, */ static int smack_key_getsecurity(struct key *key, char **_buffer) { - struct smack_known *skp = key->security; + struct smack_known **blob = smack_key(key); + struct smack_known *skp = *blob; size_t length; char *copy; - if (key->security == NULL) { + if (skp == NULL) { *_buffer = NULL; return 0; } @@ -4550,6 +4545,9 @@ struct lsm_blob_sizes smack_blob_sizes __lsm_ro_after_init = { .lbs_file = sizeof(struct smack_known *), .lbs_inode = sizeof(struct inode_smack), .lbs_ipc = sizeof(struct smack_known *), +#ifdef CONFIG_KEYS + .lbs_key = sizeof(struct smack_known *), +#endif /* CONFIG_KEYS */ .lbs_msg_msg = sizeof(struct smack_known *), .lbs_sock = sizeof(struct socket_smack), .lbs_superblock = sizeof(struct superblock_smack), @@ -4671,7 +4669,6 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = { /* key management security hooks */ #ifdef CONFIG_KEYS LSM_HOOK_INIT(key_alloc, smack_key_alloc), - LSM_HOOK_INIT(key_free, smack_key_free), LSM_HOOK_INIT(key_permission, smack_key_permission), LSM_HOOK_INIT(key_getsecurity, smack_key_getsecurity), #endif /* CONFIG_KEYS */ From patchwork Sun Jun 2 16:50:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971805 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 015A817DF for ; Sun, 2 Jun 2019 16:51:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5063286E4 for ; Sun, 2 Jun 2019 16:51:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D72CA28703; Sun, 2 Jun 2019 16:51:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 825B81FF40 for ; Sun, 2 Jun 2019 16:51:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726875AbfFBQv0 (ORCPT ); Sun, 2 Jun 2019 12:51:26 -0400 Received: from sonic310-30.consmr.mail.ne1.yahoo.com ([66.163.186.211]:43546 "EHLO sonic310-30.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726858AbfFBQv0 (ORCPT ); Sun, 2 Jun 2019 12:51:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494285; bh=is2u5Y0DRwzBY1W00Se6/XMCwBAVUpvFG8LStFYaqTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=AjbZdcI0d+8eSkp8NmA98Zlyn7gq6xguZrWlL/j9xkztJEH7q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nXEIOFrBA24V1Snn7qcAh2TEptMaqdKOVQ6XyxDXDlA8K4mUNX.CMI_W _nyrI5z309FTF7aw9_L14Z3a69ObEt7Hh0YB7452FT_9fGGl60PGZbcejDBYz4XiYcQxVfdrNAXG 5jFqbkpCW6LZfNKv5jez1fJhfuJrq25HuhxahHnFtLIlfcjPBtZxE_.MARqoxhXnUxPstLBzjeW3 Oa5qlizVpFid0DjZdKiJo5UXJlTPRyZ0qt2u8lq0PbY_IL6kKIhCaWjo4MaXh5WjEB8JkdHjPlQ1 z7eriBmo2clLEIIMwV7GgPSZp8pX.SjFtutMatZ83jVP2gpiSy.xrTnfQCPxZZU0dTBOoVL8bvAq PuMAKVN4X48s1QKQrtMA4ckrj2giBOEqvAz0kw53mu9IH3zdiKGHOayjU.BmBC81RmEUTOQvFiHl H1f6Og_U353yun26AtDzBsaO47h.fE3vll6C.6LF02I6X9_EMlu0D290vhCRmTKkArXS02caotmU 1FnbhUvzQ.OSvnpAbXysSV44JP3mZtFJArDnsgAPO Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:51:25 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp429.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID eaaddcf00ddf2fd5d1fdcb38c64db575; Sun, 02 Jun 2019 16:51:20 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 04/58] LSM: Create an lsm_export data structure. Date: Sun, 2 Jun 2019 09:50:07 -0700 Message-Id: <20190602165101.25079-5-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When more than one security module is exporting data to audit and networking sub-systems a single 32 bit integer is no longer sufficient to represent the data. Add a structure to be used instead. Signed-off-by: Casey Schaufler --- include/linux/security.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/security.h b/include/linux/security.h index 49f2685324b0..81f9f79f9a1e 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -76,6 +76,18 @@ enum lsm_event { LSM_POLICY_CHANGE, }; +/* Data exported by the security modules */ +struct lsm_export { + u32 selinux; + u32 smack; + u32 apparmor; + u32 flags; +}; +#define LSM_EXPORT_NONE 0x00 +#define LSM_EXPORT_SELINUX 0x01 +#define LSM_EXPORT_SMACK 0x02 +#define LSM_EXPORT_APPARMOR 0x04 + /* These functions are in security/commoncap.c */ extern int cap_capable(const struct cred *cred, struct user_namespace *ns, int cap, unsigned int opts); From patchwork Sun Jun 2 16:50:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971811 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C7AD18E8 for ; Sun, 2 Jun 2019 16:51:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B8F828703 for ; Sun, 2 Jun 2019 16:51:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FDFF28A00; Sun, 2 Jun 2019 16:51:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCD4028703 for ; Sun, 2 Jun 2019 16:51:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726849AbfFBQv1 (ORCPT ); Sun, 2 Jun 2019 12:51:27 -0400 Received: from sonic303-27.consmr.mail.ne1.yahoo.com ([66.163.188.153]:42575 "EHLO sonic303-27.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726879AbfFBQv1 (ORCPT ); Sun, 2 Jun 2019 12:51:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494285; bh=ULSoD1nkXTL2vFKNMUIKbyfgweGG6c5B3nCQi8z/MPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=i2L55iVl7Nj9e5x8Yj9opZRK8MABXRM9jm9YQKDvcThhMxzSA63Rvr2Xoi39up5QQ+Ccf1ZdOW662cGPsEkAXo6vWc2Cn82XW19XWi52LjoIfglAUHnq04oPzC0fdhrht7dKh+QAEcl1vL3k9X9iAF8hUGFpccKpr2bGtI3S9HIuaafH2XlQBvJCF9a+HB1xDnMhHddYp9Rgr0JMxTSb6yGptsC9fTVGLpLoZL15TD2wi8zES1ZTtTZ6G/b9eSk9d0FrVbXSpbXlofxzYaeiCJSwxcD0619QBHIo0hdW7+f9gKEDmiFRRpupKtwd22zyRDLnpN13HkZfj/vbShM5YA== X-YMail-OSG: MDv9RtoVM1kDd1Y1IaBiu46LIt6WMAnJV4WX6wvXQ1xQB0fkfXLTBq8.EXSbrnv .l0Z.PJXLrZhCxLSqXj4k5bo3U0Jih15N7.GIfTd4UsfYP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KytDh4St_B3hX0seMCfO7XJ0rZ ce4zZGEwFyX52s5uwIhtvFffpzFNxhW1OMuhA012nueCN5bFIgBxnuI1THbsURpCt9CMSJKA1Jk1 wJYmC3l1dxORZF.BQbR276_uLmIOsFtpC9HQ7ff5eqg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:51:25 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp429.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID eaaddcf00ddf2fd5d1fdcb38c64db575; Sun, 02 Jun 2019 16:51:21 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 05/58] LSM: Use lsm_export in the inode_getsecid hooks Date: Sun, 2 Jun 2019 09:50:08 -0700 Message-Id: <20190602165101.25079-6-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the inode_getsecid hooks to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when security_inode_getsecid() is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 4 ++-- include/linux/security.h | 5 +++++ security/security.c | 35 ++++++++++++++++++++++++++++++++++- security/selinux/hooks.c | 21 ++++++++++++++++----- security/smack/smack_lsm.c | 13 +++++++++++-- 5 files changed, 68 insertions(+), 10 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 3fe39abccc8f..09573c55e535 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -425,7 +425,7 @@ * @inode_getsecid: * Get the secid associated with the node. * @inode contains a pointer to the inode. - * @secid contains a pointer to the location where result will be saved. + * @data contains a pointer to the location where result will be saved. * In case of failure, @secid will be set to zero. * @inode_copy_up: * A file is about to be copied up from lower layer to upper layer of @@ -1566,7 +1566,7 @@ union security_list_options { int flags); int (*inode_listsecurity)(struct inode *inode, char *buffer, size_t buffer_size); - void (*inode_getsecid)(struct inode *inode, u32 *secid); + void (*inode_getsecid)(struct inode *inode, struct lsm_export *data); int (*inode_copy_up)(struct dentry *src, struct cred **new); int (*inode_copy_up_xattr)(const char *name); diff --git a/include/linux/security.h b/include/linux/security.h index 81f9f79f9a1e..fb19f41d630b 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -88,6 +88,11 @@ struct lsm_export { #define LSM_EXPORT_SMACK 0x02 #define LSM_EXPORT_APPARMOR 0x04 +static inline void lsm_export_init(struct lsm_export *l) +{ + memset(l, 0, sizeof(*l)); +} + /* These functions are in security/commoncap.c */ extern int cap_capable(const struct cred *cred, struct user_namespace *ns, int cap, unsigned int opts); diff --git a/security/security.c b/security/security.c index d05f00a40e82..a1f28a5e582b 100644 --- a/security/security.c +++ b/security/security.c @@ -712,6 +712,36 @@ int lsm_superblock_alloc(struct super_block *sb) RC; \ }) +/** + * lsm_export_secid - pull the useful secid out of a lsm_export + * @data: the containing data structure + * @secid: where to put the one that matters. + * + * Shim that will disappear when all lsm_export conversions are done. + */ +static inline void lsm_export_secid(struct lsm_export *data, u32 *secid) +{ + switch (data->flags) { + case LSM_EXPORT_NONE: + *secid = 0; + break; + case LSM_EXPORT_SELINUX: + *secid = data->selinux; + break; + case LSM_EXPORT_SMACK: + *secid = data->smack; + break; + case LSM_EXPORT_APPARMOR: + *secid = data->apparmor; + break; + default: + pr_warn("%s flags=0x%u - not a valid set\n", __func__, + data->flags); + *secid = 0; + break; + } +} + /* Security operations */ int security_binder_set_context_mgr(struct task_struct *mgr) @@ -1389,7 +1419,10 @@ EXPORT_SYMBOL(security_inode_listsecurity); void security_inode_getsecid(struct inode *inode, u32 *secid) { - call_void_hook(inode_getsecid, inode, secid); + struct lsm_export data = { .flags = LSM_EXPORT_NONE }; + + call_void_hook(inode_getsecid, inode, &data); + lsm_export_secid(&data, secid); } int security_inode_copy_up(struct dentry *src, struct cred **new) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index ee840fecfebb..0e31be22d9bb 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -213,6 +213,15 @@ static void cred_init_security(void) tsec->osid = tsec->sid = SECINITSID_KERNEL; } +/* + * Set the SELinux secid in an lsm_export structure + */ +static inline void selinux_export_secid(struct lsm_export *l, u32 secid) +{ + l->selinux = secid; + l->flags |= LSM_EXPORT_SELINUX; +} + /* * get the security ID of a set of credentials */ @@ -3316,15 +3325,16 @@ static int selinux_inode_listsecurity(struct inode *inode, char *buffer, size_t return len; } -static void selinux_inode_getsecid(struct inode *inode, u32 *secid) +static void selinux_inode_getsecid(struct inode *inode, struct lsm_export *l) { struct inode_security_struct *isec = inode_security_novalidate(inode); - *secid = isec->sid; + + selinux_export_secid(l, isec->sid); } static int selinux_inode_copy_up(struct dentry *src, struct cred **new) { - u32 sid; + struct lsm_export l; struct task_security_struct *tsec; struct cred *new_creds = *new; @@ -3336,8 +3346,9 @@ static int selinux_inode_copy_up(struct dentry *src, struct cred **new) tsec = selinux_cred(new_creds); /* Get label from overlay inode and set it in create_sid */ - selinux_inode_getsecid(d_inode(src), &sid); - tsec->create_sid = sid; + lsm_export_init(&l); + selinux_inode_getsecid(d_inode(src), &l); + tsec->create_sid = l.selinux; *new = new_creds; return 0; } diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index e9560b078efe..5e345122ccb1 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -466,6 +466,15 @@ static int smk_ptrace_rule_check(struct task_struct *tracer, return rc; } +/* + * Set the Smack secid in an lsm_export structure + */ +static inline void smack_export_secid(struct lsm_export *l, u32 secid) +{ + l->smack = secid; + l->flags |= LSM_EXPORT_SMACK; +} + /* * LSM hooks. * We he, that is fun! @@ -1481,11 +1490,11 @@ static int smack_inode_listsecurity(struct inode *inode, char *buffer, * @inode: inode to extract the info from * @secid: where result will be saved */ -static void smack_inode_getsecid(struct inode *inode, u32 *secid) +static void smack_inode_getsecid(struct inode *inode, struct lsm_export *l) { struct smack_known *skp = smk_of_inode(inode); - *secid = skp->smk_secid; + smack_export_secid(l, skp->smk_secid); } /* From patchwork Sun Jun 2 16:50:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971815 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 09A0B18A6 for ; Sun, 2 Jun 2019 16:51:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED99F286E4 for ; Sun, 2 Jun 2019 16:51:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1C0D28A28; Sun, 2 Jun 2019 16:51:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8578228A08 for ; Sun, 2 Jun 2019 16:51:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726836AbfFBQv1 (ORCPT ); Sun, 2 Jun 2019 12:51:27 -0400 Received: from sonic310-30.consmr.mail.ne1.yahoo.com ([66.163.186.211]:33512 "EHLO sonic310-30.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726853AbfFBQv0 (ORCPT ); Sun, 2 Jun 2019 12:51:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494285; bh=dwbKmDfRWBch8TA3RWmr5v6f3rBIx/+49c84tS3OSyo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=k8UxniClHJw7qwznu/CfXPfsSfKP9GufMMywp/KP5UyTdv2FKJzRfLmciHlF5+pPsb6g1m50kFwecRgq7TGVytjKc0AwtF5FalYNvALX624k22VYzro1iL/uIXBLLf68BAcJNlBiMCHKp4sfJrp4L3il6QGtfJjw9E4au3fboJu+rF/s8Ln719Y7CgZ+EkYa0dmYjzU7EC2IWNdUhyhDSxsxWcnXaOJJZi7dnU8x8VGrW7Vi50JiC191QckaRawB0Ppi9BaWWNfHcWPH4qZWpT+QvXMdwzfxAsTR8QYnEd5IRMp7LNjJc4LPQyMxqcSGpKyvEDZNApZrXM2Wu/48tQ== X-YMail-OSG: ojKavEEVM1lB9LmWtfTPUEFUIfUp43MlzCyZvZJ8S3LRCZWh6rhDl_eRc4cz5.K v.O_w52_u12VCsnu3L0YSRfIbmLh8m6gOE4kjtCIZXuunrQRuBq_zbFndhawwQE7m80zs2p2M2VJ qQi6wtt.b61tIFrIKBNFMauYV26BWenEkoq8qBgQXUsy.jDgsSr2wek51q.OUJv6YGg_AfAfWise BQ6d0Z46f7uw.JwemoXIFasAnr8zJM40hFvUbSaU4qmm25F2z7ybxhVykGVjjXwMYnx8zb1dmmJz yWl5jcojYuTJbzIORwdDJhzOFb6PaAe0tPtYKePMJmIFXKYxfeYb6vG102GwpMlLRomxSw.SiWhG KrbrL_chFj6zHD8MF2RivTi5cRRleHhcXDhCCOriRTO3pY9.l9_nUUpX086vMpZousnsJtNeHxAD xbhQ6ONw2PuuIZ2xN14Rk.J7.d6UL5aI6sWe2yMFxCb6kjl__3L9GjjBOD9SQHn8JLfQReqQtyTN X6ZVEILtPWGfmJ7.Y_PYpj6WvqtaElR0A.NPev1ffHKioRMspD7tSa2ttLMh__EQ75Lk6b8xDq5r arf8_J5bZwNwn3W.Etb.quXEqxBAjcXmbbijdhZ6Zpl5KDGLwOm13Df0LdQX8mukJvIrhQbAI2KG lyn3i4nCNK2QTtXkvxjgI7Qs1TCIXyzzdu1WMbBMBQZVzC8UBlBFP29CpVrtGa0dj9oJ1nWhpr9g HyAHIehIgpx7qbfZGbyUKLFtWGcJRVHBNeSL.ZEN36dBYJKDdWQpmj9OiitTjdGiuJBCbkaeissh Jyq40gcLaRFtV6L3EWSC2O7K408_No90iojzWWI5hV_hkJlJWYtm5uGybi2TD8voEHIKeVmoaDRu Uc1GNVMENg_K3C01F.vhd0kqXIkNmN7o7MEu6HaIv2_vJc9eXsc_eQbBnrBbt_tYbLrvEMaf4pgv MYb9oTv1F6yj73RnZWt99sREYwkQZISbgWMG_eqEXhTkd3aHFsCFVqhc.kpxR3zf2LgW6fSf4zgJ OAiUjFFn_4dzEJ0oBs02Hw6O1hOpPzR1lXmQZIbn66nsPOVNOEc0sY_VC_42HfpZAUNNuNTC3Z5h J2IPncXm8WSD.FOI8.aTu.H4XJpapsobB5zNnRGxOKDc7v1mHJ5I0fYGTpCKw8YxAk7L11yUSY9t wn11J.Cyl1uwhgAF3wf.iA8PP2fcE4iacCpoSq_xZr_7IZgdHyFOwV6uhQhfBn3ccqo5KP8y__y5 2NY78KHIsP78OBh.BLghPNbTfbT01OBZGqYPnYNKi_Ys7PSLc Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:51:25 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp429.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID eaaddcf00ddf2fd5d1fdcb38c64db575; Sun, 02 Jun 2019 16:51:22 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 06/58] LSM: Use lsm_export in the cred_getsecid hooks Date: Sun, 2 Jun 2019 09:50:09 -0700 Message-Id: <20190602165101.25079-7-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the cred_getsecid hooks to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when security_cred_getsecid() is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 5 +++-- security/security.c | 6 ++++-- security/selinux/hooks.c | 4 ++-- security/smack/smack_lsm.c | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 09573c55e535..0f9d4174bb6e 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -572,7 +572,8 @@ * Transfer data from original creds to new creds * @cred_getsecid: * Retrieve the security identifier of the cred structure @c - * @c contains the credentials, secid will be placed into @secid. + * @c contains the credentials + * @l contains a pointer to the location where result will be saved. * In case of failure, @secid will be set to zero. * @kernel_act_as: * Set the credentials for a kernel service to act as (subjective context). @@ -1596,7 +1597,7 @@ union security_list_options { int (*cred_prepare)(struct cred *new, const struct cred *old, gfp_t gfp); void (*cred_transfer)(struct cred *new, const struct cred *old); - void (*cred_getsecid)(const struct cred *c, u32 *secid); + void (*cred_getsecid)(const struct cred *c, struct lsm_export *l); int (*kernel_act_as)(struct cred *new, u32 secid); int (*kernel_create_files_as)(struct cred *new, struct inode *inode); int (*kernel_module_request)(char *kmod_name); diff --git a/security/security.c b/security/security.c index a1f28a5e582b..ca485a777ca1 100644 --- a/security/security.c +++ b/security/security.c @@ -1638,8 +1638,10 @@ void security_transfer_creds(struct cred *new, const struct cred *old) void security_cred_getsecid(const struct cred *c, u32 *secid) { - *secid = 0; - call_void_hook(cred_getsecid, c, secid); + struct lsm_export data = { .flags = LSM_EXPORT_NONE }; + + call_void_hook(cred_getsecid, c, &data); + lsm_export_secid(&data, secid); } EXPORT_SYMBOL(security_cred_getsecid); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 0e31be22d9bb..f97dd414ac8d 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3764,9 +3764,9 @@ static void selinux_cred_transfer(struct cred *new, const struct cred *old) *tsec = *old_tsec; } -static void selinux_cred_getsecid(const struct cred *c, u32 *secid) +static void selinux_cred_getsecid(const struct cred *c, struct lsm_export *l) { - *secid = cred_sid(c); + selinux_export_secid(l, cred_sid(c)); } /* diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 5e345122ccb1..15579bdd7244 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -1980,13 +1980,13 @@ static void smack_cred_transfer(struct cred *new, const struct cred *old) * * Sets the secid to contain a u32 version of the smack label. */ -static void smack_cred_getsecid(const struct cred *cred, u32 *secid) +static void smack_cred_getsecid(const struct cred *cred, struct lsm_export *l) { struct smack_known *skp; rcu_read_lock(); skp = smk_of_task(smack_cred(cred)); - *secid = skp->smk_secid; + smack_export_secid(l, skp->smk_secid); rcu_read_unlock(); } From patchwork Sun Jun 2 16:50:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971817 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1970015E6 for ; Sun, 2 Jun 2019 16:51:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0767C28A00 for ; Sun, 2 Jun 2019 16:51:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E90FE289FA; Sun, 2 Jun 2019 16:51:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B84C286E4 for ; Sun, 2 Jun 2019 16:51:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726884AbfFBQv1 (ORCPT ); Sun, 2 Jun 2019 12:51:27 -0400 Received: from sonic317-38.consmr.mail.ne1.yahoo.com ([66.163.184.49]:35288 "EHLO sonic317-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726836AbfFBQv0 (ORCPT ); Sun, 2 Jun 2019 12:51:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494284; bh=cb378cxqvPaulkSS7n2iQ2M2+2lKAprXYeun9wbD1fs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=DRErV1oJzFjxEj86oe4cWv4d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liEn5sMI1IS isXMP7Ppkxq33yms8KmSWqL6VM4YPYpZEmeFNtYyU3K9bZREFdqKoW0S6flTKR4jS8PkeUyXAj5Y s3U205V_3FIh8NveahQUm8ACOoshD71YA5oFaXl.lIDX8ySzar8.WTxJq7lAHUxq05V.9IvmJjb6 60Ub2pM3mdGB01uC8yUAD8F6dH9nEkqDcN6WOUnsGzWXnhUXuOqLnfRVYvvg6tAAPKKSyf1k2Gku 7rEOqOuAnzsJ27TWvhv3Bz3YRU0Qu2_1kzYD3eILPIQwx.ksOWlHpbWPMPpQAVD019YkKJKf1sRQ U5PmQXLavv.DILwHlvFepk.Fm_zC0Z3pNP_2kV9F8dRT_QId_uN8G.D8rEYAKaNA7L.sjRuRqcGL vCr0Sr23Ime4KV2_v.wFUEu9yJ7Ss5QUzksWEwB4MVhRuuMjTqWybJO_DYenT1u92Rd_RsbHSHSm DrbAcXv3GIxfvNftraaEDdfk3PgAq4kQzLoCtygFnOuUdPqIYUJf9Fhm4C9hwVOstpYCZP5iU2Te sXjzsCpTHM.MKErixQQke4lP8.s_gmSMsp6dzI1ots6M- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:51:24 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp429.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID eaaddcf00ddf2fd5d1fdcb38c64db575; Sun, 02 Jun 2019 16:51:22 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 07/58] LSM: Use lsm_export in the ipc_getsecid and task_getsecid hooks Date: Sun, 2 Jun 2019 09:50:10 -0700 Message-Id: <20190602165101.25079-8-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the cred_getsecid and task_getsecid hooks to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when security_ipc_getsecid() and security_task_getsecid() are updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 8 ++++---- security/apparmor/lsm.c | 12 ++++++++++-- security/security.c | 12 ++++++++---- security/selinux/hooks.c | 10 ++++++---- security/smack/smack_lsm.c | 8 ++++---- 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 0f9d4174bb6e..62783a923136 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -638,7 +638,7 @@ * Return 0 if permission is granted. * @task_getsecid: * Retrieve the security identifier of the process @p. - * @p contains the task_struct for the process and place is into @secid. + * @p contains the task_struct for the process and place is into @l. * In case of failure, @secid will be set to zero. * * @task_setnice: @@ -1094,7 +1094,7 @@ * @ipc_getsecid: * Get the secid associated with the ipc object. * @ipcp contains the kernel IPC permission structure. - * @secid contains a pointer to the location where result will be saved. + * @l contains a pointer to the location where result will be saved. * In case of failure, @secid will be set to zero. * * Security hooks for individual messages held in System V IPC message queues @@ -1610,7 +1610,7 @@ union security_list_options { int (*task_setpgid)(struct task_struct *p, pid_t pgid); int (*task_getpgid)(struct task_struct *p); int (*task_getsid)(struct task_struct *p); - void (*task_getsecid)(struct task_struct *p, u32 *secid); + void (*task_getsecid)(struct task_struct *p, struct lsm_export *l); int (*task_setnice)(struct task_struct *p, int nice); int (*task_setioprio)(struct task_struct *p, int ioprio); int (*task_getioprio)(struct task_struct *p); @@ -1628,7 +1628,7 @@ union security_list_options { void (*task_to_inode)(struct task_struct *p, struct inode *inode); int (*ipc_permission)(struct kern_ipc_perm *ipcp, short flag); - void (*ipc_getsecid)(struct kern_ipc_perm *ipcp, u32 *secid); + void (*ipc_getsecid)(struct kern_ipc_perm *ipcp, struct lsm_export *l); int (*msg_msg_alloc_security)(struct msg_msg *msg); void (*msg_msg_free_security)(struct msg_msg *msg); diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 2716e7731279..706e5ae09170 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -49,6 +49,14 @@ int apparmor_initialized; DEFINE_PER_CPU(struct aa_buffers, aa_buffers); +/* + * Set the AppArmor secid in an lsm_export structure + */ +static inline void apparmor_export_secid(struct lsm_export *l, u32 secid) +{ + l->apparmor = secid; + l->flags |= LSM_EXPORT_APPARMOR; +} /* * LSM hook functions @@ -710,10 +718,10 @@ static void apparmor_bprm_committed_creds(struct linux_binprm *bprm) return; } -static void apparmor_task_getsecid(struct task_struct *p, u32 *secid) +static void apparmor_task_getsecid(struct task_struct *p, struct lsm_export *l) { struct aa_label *label = aa_get_task_label(p); - *secid = label->secid; + apparmor_export_secid(l, label->secid); aa_put_label(label); } diff --git a/security/security.c b/security/security.c index ca485a777ca1..802557ff6f60 100644 --- a/security/security.c +++ b/security/security.c @@ -1722,8 +1722,10 @@ int security_task_getsid(struct task_struct *p) void security_task_getsecid(struct task_struct *p, u32 *secid) { - *secid = 0; - call_void_hook(task_getsecid, p, secid); + struct lsm_export data = { .flags = LSM_EXPORT_NONE }; + + call_void_hook(task_getsecid, p, &data); + lsm_export_secid(&data, secid); } EXPORT_SYMBOL(security_task_getsecid); @@ -1805,8 +1807,10 @@ int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag) void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid) { - *secid = 0; - call_void_hook(ipc_getsecid, ipcp, secid); + struct lsm_export data = { .flags = LSM_EXPORT_NONE }; + + call_void_hook(ipc_getsecid, ipcp, &data); + lsm_export_secid(&data, secid); } int security_msg_msg_alloc(struct msg_msg *msg) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index f97dd414ac8d..c82108793fb5 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3911,9 +3911,9 @@ static int selinux_task_getsid(struct task_struct *p) PROCESS__GETSESSION, NULL); } -static void selinux_task_getsecid(struct task_struct *p, u32 *secid) +static void selinux_task_getsecid(struct task_struct *p, struct lsm_export *l) { - *secid = task_sid(p); + selinux_export_secid(l, task_sid(p)); } static int selinux_task_setnice(struct task_struct *p, int nice) @@ -6094,10 +6094,12 @@ static int selinux_ipc_permission(struct kern_ipc_perm *ipcp, short flag) return ipc_has_perm(ipcp, av); } -static void selinux_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid) +static void selinux_ipc_getsecid(struct kern_ipc_perm *ipcp, + struct lsm_export *l) { struct ipc_security_struct *isec = selinux_ipc(ipcp); - *secid = isec->sid; + + selinux_export_secid(l, isec->sid); } static void selinux_d_instantiate(struct dentry *dentry, struct inode *inode) diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 15579bdd7244..13ac3045a388 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -2087,11 +2087,11 @@ static int smack_task_getsid(struct task_struct *p) * * Sets the secid to contain a u32 version of the smack label. */ -static void smack_task_getsecid(struct task_struct *p, u32 *secid) +static void smack_task_getsecid(struct task_struct *p, struct lsm_export *l) { struct smack_known *skp = smk_of_task_struct(p); - *secid = skp->smk_secid; + smack_export_secid(l, skp->smk_secid); } /** @@ -3231,12 +3231,12 @@ static int smack_ipc_permission(struct kern_ipc_perm *ipp, short flag) * @ipp: the object permissions * @secid: where result will be saved */ -static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, u32 *secid) +static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, struct lsm_export *l) { struct smack_known **blob = smack_ipc(ipp); struct smack_known *iskp = *blob; - *secid = iskp->smk_secid; + smack_export_secid(l, iskp->smk_secid); } /** From patchwork Sun Jun 2 16:50:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971823 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 46F2F17DF for ; Sun, 2 Jun 2019 16:51:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36333286E4 for ; Sun, 2 Jun 2019 16:51:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A19E28A08; Sun, 2 Jun 2019 16:51:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 580F4289FA for ; Sun, 2 Jun 2019 16:51:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726608AbfFBQvj (ORCPT ); Sun, 2 Jun 2019 12:51:39 -0400 Received: from sonic303-8.consmr.mail.bf2.yahoo.com ([74.6.131.47]:39545 "EHLO sonic303-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726892AbfFBQvi (ORCPT ); Sun, 2 Jun 2019 12:51:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494297; bh=vW0GJVqmcxCQIdr1rEmD04j1RR8RMpPnwm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 8XKmgOuIHQFsDy6iWgBuMM8plndGAlLbf4ModgFApDlUWB67BcCcz2EgW2bO2V8h3eyjRjcc880q _ccV1lz87GX5uqpRUuZah5Pp6lrr.uHgIGUOnBosVwwA4k4vILAto2dNVIH.Wpk9PEdreOwukg8K CcLTJeIlD0iQT1_60k8xnlCtmBtvAg4DoT6RU8T_21XfsmbJKoJnthng4TnjO.S3iNE14oqIh0UJ VVWRBYmvF.2t96nXdbwmYN9hNW54MqSofrHu2isD5m2cYUrBmTtjujfC_NN91U8PsciyUmk..jeZ QPt.5B64uCFqprGaaJ0hJ5naBLVvoFiRRucz9QWSpHDlwvkTI7QI06PrWnqCyGlOXIzVDkwaZXk7 jGPGQt1bs7uFI7KH5yUBI8Vedh6U.W2WcIXzUhQsT2MoE30AV9phpmYMks0wNj3b0UAb0pivjZmD rxRDNtEW1GbW40xGlNfd6asv.4cmxCg46p6hk_0FWUBmUjSN6wRtO8IpTk3zJmnD9f1yUgGFBS0S 5bq53_v9j2afPAciKdt.79p1hMMk5Cr15S8HYHBDdBJ_kPfviO.G1F6AhsKrMDqecxjFDL2GiyyU l8I7FaAMtmT4.RWACy3X7a3gK3TbBkXeqCBQjRPioN_uG8A-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:51:37 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp413.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID b3a8ad7d79501e3c392fdc3d79d8fa55; Sun, 02 Jun 2019 16:51:35 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 08/58] LSM: Use lsm_export in the kernel_ask_as hooks Date: Sun, 2 Jun 2019 09:50:11 -0700 Message-Id: <20190602165101.25079-9-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the kernel_ask_as hooks to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when security_kernel_ask_as() is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 4 ++-- security/security.c | 15 ++++++++++++++- security/selinux/hooks.c | 17 ++++++++++++++--- security/smack/smack_lsm.c | 12 +++++++++++- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 62783a923136..800040050032 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -578,7 +578,7 @@ * @kernel_act_as: * Set the credentials for a kernel service to act as (subjective context). * @new points to the credentials to be modified. - * @secid specifies the security ID to be set + * @l specifies the security data to be set * The current task must be the one that nominated @secid. * Return 0 if successful. * @kernel_create_files_as: @@ -1598,7 +1598,7 @@ union security_list_options { gfp_t gfp); void (*cred_transfer)(struct cred *new, const struct cred *old); void (*cred_getsecid)(const struct cred *c, struct lsm_export *l); - int (*kernel_act_as)(struct cred *new, u32 secid); + int (*kernel_act_as)(struct cred *new, struct lsm_export *l); int (*kernel_create_files_as)(struct cred *new, struct inode *inode); int (*kernel_module_request)(char *kmod_name); int (*kernel_load_data)(enum kernel_load_data_id id); diff --git a/security/security.c b/security/security.c index 802557ff6f60..3a766755b722 100644 --- a/security/security.c +++ b/security/security.c @@ -742,6 +742,15 @@ static inline void lsm_export_secid(struct lsm_export *data, u32 *secid) } } +static inline void lsm_export_to_all(struct lsm_export *data, u32 secid) +{ + data->selinux = secid; + data->smack = secid; + data->apparmor = secid; + data->flags = LSM_EXPORT_SELINUX | LSM_EXPORT_SMACK | + LSM_EXPORT_APPARMOR; +} + /* Security operations */ int security_binder_set_context_mgr(struct task_struct *mgr) @@ -1647,7 +1656,11 @@ EXPORT_SYMBOL(security_cred_getsecid); int security_kernel_act_as(struct cred *new, u32 secid) { - return call_int_hook(kernel_act_as, 0, new, secid); + struct lsm_export data = { .flags = LSM_EXPORT_NONE }; + + lsm_export_to_all(&data, secid); + + return call_int_hook(kernel_act_as, 0, new, &data); } int security_kernel_create_files_as(struct cred *new, struct inode *inode) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index c82108793fb5..b88a51b6ca41 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -222,6 +222,14 @@ static inline void selinux_export_secid(struct lsm_export *l, u32 secid) l->flags |= LSM_EXPORT_SELINUX; } +static inline void selinux_import_secid(struct lsm_export *l, u32 *secid) +{ + if (l->flags & LSM_EXPORT_SELINUX) + *secid = l->selinux; + else + *secid = SECSID_NULL; +} + /* * get the security ID of a set of credentials */ @@ -3773,19 +3781,22 @@ static void selinux_cred_getsecid(const struct cred *c, struct lsm_export *l) * set the security data for a kernel service * - all the creation contexts are set to unlabelled */ -static int selinux_kernel_act_as(struct cred *new, u32 secid) +static int selinux_kernel_act_as(struct cred *new, struct lsm_export *l) { struct task_security_struct *tsec = selinux_cred(new); + u32 nsid; u32 sid = current_sid(); int ret; + selinux_import_secid(l, &nsid); + ret = avc_has_perm(&selinux_state, - sid, secid, + sid, nsid, SECCLASS_KERNEL_SERVICE, KERNEL_SERVICE__USE_AS_OVERRIDE, NULL); if (ret == 0) { - tsec->sid = secid; + tsec->sid = nsid; tsec->create_sid = 0; tsec->keycreate_sid = 0; tsec->sockcreate_sid = 0; diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 13ac3045a388..3b77a0324c3d 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -475,6 +475,14 @@ static inline void smack_export_secid(struct lsm_export *l, u32 secid) l->flags |= LSM_EXPORT_SMACK; } +static inline void smack_import_secid(struct lsm_export *l, u32 *secid) +{ + if (l->flags & LSM_EXPORT_SMACK) + *secid = l->smack; + else + *secid = 0; +} + /* * LSM hooks. * We he, that is fun! @@ -1997,10 +2005,12 @@ static void smack_cred_getsecid(const struct cred *cred, struct lsm_export *l) * * Set the security data for a kernel service. */ -static int smack_kernel_act_as(struct cred *new, u32 secid) +static int smack_kernel_act_as(struct cred *new, struct lsm_export *l) { + u32 secid; struct task_smack *new_tsp = smack_cred(new); + smack_import_secid(l, &secid); new_tsp->smk_task = smack_from_secid(secid); return 0; } From patchwork Sun Jun 2 16:50:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971827 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A5DF213AD for ; Sun, 2 Jun 2019 16:51:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 967B91FF40 for ; Sun, 2 Jun 2019 16:51:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8ADB828703; Sun, 2 Jun 2019 16:51:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2EC11FF40 for ; Sun, 2 Jun 2019 16:51:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726572AbfFBQvi (ORCPT ); Sun, 2 Jun 2019 12:51:38 -0400 Received: from sonic303-8.consmr.mail.bf2.yahoo.com ([74.6.131.47]:46220 "EHLO sonic303-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726608AbfFBQvi (ORCPT ); Sun, 2 Jun 2019 12:51:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494297; bh=7nhZ/zEyM+j0a1Luk+r19dVtPBLiOzXmF2b9tX24TkE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=Lq1Nt1X5WZ/nAO+4+9oXo459tlz9c2zoJIDsgDTIpq2EDsd5RhNb98nHPUV3LBP8gnYfVUkw3YCXNvBmYDdWhklUqbsueIktHNwdTNM2wMUJ3FLpHI5h8isjwWeGGlM9RxnV/I/4q6EhdznOrJCHGTBDmkfm/gussbr+EG2DS/d5BC6NGTnvRQ8HfAuPJQDhuCLYpeJCWS91WwtLT7gx/UeW4jFI1GFgd6A9I6+RqM2NjPUV39BEbNXJ1+YLDUviyCPskG/xNOZymsi3geFNxW3iJopSmeJSeZS8U4C/iVx0BfA6fi87HnSh1vZVnmn4Ps6jgkBmXvfq0RFBfoJjoA== X-YMail-OSG: 9drs37oVM1kYwhdJ38NZvL40ooWFUJm6WNMIriyyWOr2u.tQvvhXu_B356emIuG lWhJKDsTstPPJ8HXRFqaxaArIVE.eYi1XWr0wg3f6exwnYXXXkr4GrIIbczaXOhsEJwjW1GQocIo i6CZ26eQoLztNJYV0CitYH6e8twwfgXlFUk1J7JE56vaezUSHY25Ejz5XUBkiONKw2klG9NJBYnM ernAnsADVTWABp8.qsSeUjNCs_yLpj7TgrHNd29OWCup7E4SBCR1IWFcq0OQ3P6WdIE0ToMeexi3 XOvzrM6lZgRP0NzjHOnRez2vx7k6L11qusT8a3Obq.isBBoi5SuVI2dG4JbSIauAOT5TmeaQYoh9 zUB2aDUJNoBOb9iZ4pIisedSBCF4viV.DvcSDgtTQLemZEeokHLlmiHSPcdHDAi2x3WIpAc54cJT N0uE0ywPTvWXiBqJZwTC0pY5Sf5L9xWYdkTlBbeksVgvoRVw57av2l3e6c1lPctmVudltvqvUUy_ KEYLjSv8cx_sqQ8vE1XG1ndt2R_dD5VICxupgXYkp7lLrsfZ7zWTkKjQcVYXM_zJLP3xSCxD9bwL mv3zUlBL9b8JBoc20yIDpCBvSGCL6lb08sUtZrd3cxVINn462pVh3LR5LXAhLFdzXJG.yCK_qNhN 6IJcRjUFFNH4FuHpHvSrB5KIY7gwkVeIzubbyKtHyS84iOM4U9B6sSsrTAQ59csH0f1zv1P57Pzc MvKRVXfUfDPwQkQA9w60YbrFiW7.4cB2MgzbvKjfqzBsmAuwC0f2DnHH0p36Nt9uB5VxUhsMUN7H 8wZf3PzrRJx8B_xZvUmq5ZjmaEOCgmGOA15RNC9SJh7xz0oneUBRxqoiHwpqgK.KMWgz.IAT7bE_ 7JeOouJvg6uA_6AYFuyIElKSx8ie8XRCzsOFHe2MIYMQNWTRU11565yfqI.k0SzDYKKsEwRkoZzA R16MHAUkZvajWhyWwUtHX_feyCcfv.mtsuKmK3ARIHUMaCZ22S0Lthq.vRUw7.0EKu6ZFb3sRqTz YyRJXRmBfX5x26GxPJzQ4wLtO06_yD_qQperwsxw715tOg6tEXJUanTxW_UkjEO.r7iDWKXSOisl FR_eKHSYd275vS8Rxpo0s9XRLzdYfI0ae99povykHdzQycLZt6zBaGxeBwHxuIYgFH_t.CIHshds 8rBy2qDF2mSdbWpLzWfRsmmyAH2qmca8V5my9ij_boykRAbsJ_uLGhs8aEr1x.ZVEyLvP_hYp6CO 4AX_8yA.9lH2j2pwlWEcuAjle1G0rXUThcPVB8WYTcA-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:51:37 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp413.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID b3a8ad7d79501e3c392fdc3d79d8fa55; Sun, 02 Jun 2019 16:51:36 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 09/58] LSM: Use lsm_export in the getpeersec_dgram hooks Date: Sun, 2 Jun 2019 09:50:12 -0700 Message-Id: <20190602165101.25079-10-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the getpeersec_dgram hooks to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when security_getpeersec_dgram() is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 5 +++-- security/apparmor/lsm.c | 3 ++- security/security.c | 13 ++++++++++--- security/selinux/hooks.c | 6 ++++-- security/smack/smack_lsm.c | 5 +++-- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 800040050032..bcc628cffe6a 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -881,7 +881,7 @@ * ancillary message type. * @sock contains the peer socket. May be NULL. * @skb is the sk_buff for the packet being queried. May be NULL. - * @secid pointer to store the secid of the packet. + * @l is a pointer to a buffer in which to copy the security data * Return 0 on success, error on failure. * @sk_alloc_security: * Allocate and attach a security structure to the sk->sk_security field, @@ -1702,7 +1702,8 @@ union security_list_options { char __user *optval, int __user *optlen, unsigned len); int (*socket_getpeersec_dgram)(struct socket *sock, - struct sk_buff *skb, u32 *secid); + struct sk_buff *skb, + struct lsm_export *l); int (*sk_alloc_security)(struct sock *sk, int family, gfp_t priority); void (*sk_free_security)(struct sock *sk); void (*sk_clone_security)(const struct sock *sk, struct sock *newsk); diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 706e5ae09170..24b638bd4305 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -1096,7 +1096,8 @@ static int apparmor_socket_getpeersec_stream(struct socket *sock, * Sets the netlabel socket state on sk from parent */ static int apparmor_socket_getpeersec_dgram(struct socket *sock, - struct sk_buff *skb, u32 *secid) + struct sk_buff *skb, + struct lsm_export *l) { /* TODO: requires secid support */ diff --git a/security/security.c b/security/security.c index 3a766755b722..2f1355d10e0d 100644 --- a/security/security.c +++ b/security/security.c @@ -2145,10 +2145,17 @@ int security_socket_getpeersec_stream(struct socket *sock, char __user *optval, optval, optlen, len); } -int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid) +int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, + u32 *secid) { - return call_int_hook(socket_getpeersec_dgram, -ENOPROTOOPT, sock, - skb, secid); + int rc; + struct lsm_export data = { .flags = LSM_EXPORT_NONE }; + + rc = call_int_hook(socket_getpeersec_dgram, -ENOPROTOOPT, sock, skb, + &data); + + lsm_export_secid(&data, secid); + return rc; } EXPORT_SYMBOL(security_socket_getpeersec_dgram); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index b88a51b6ca41..9db12f6b1221 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -4949,7 +4949,9 @@ static int selinux_socket_getpeersec_stream(struct socket *sock, return err; } -static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid) +static int selinux_socket_getpeersec_dgram(struct socket *sock, + struct sk_buff *skb, + struct lsm_export *l) { u32 peer_secid = SECSID_NULL; u16 family; @@ -4971,7 +4973,7 @@ static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff * selinux_skb_peerlbl_sid(skb, family, &peer_secid); out: - *secid = peer_secid; + selinux_export_secid(l, peer_secid); if (peer_secid == SECSID_NULL) return -EINVAL; return 0; diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 3b77a0324c3d..3e3724bbd6ea 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -3973,7 +3973,8 @@ static int smack_socket_getpeersec_stream(struct socket *sock, * Sets the netlabel socket state on sk from parent */ static int smack_socket_getpeersec_dgram(struct socket *sock, - struct sk_buff *skb, u32 *secid) + struct sk_buff *skb, + struct lsm_export *l) { struct netlbl_lsm_secattr secattr; @@ -4024,7 +4025,7 @@ static int smack_socket_getpeersec_dgram(struct socket *sock, #endif break; } - *secid = s; + smack_export_secid(l, s); if (s == 0) return -EINVAL; return 0; From patchwork Sun Jun 2 16:50:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971831 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5C95918E8 for ; Sun, 2 Jun 2019 16:51:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CEA5286E4 for ; Sun, 2 Jun 2019 16:51:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4088D28A28; Sun, 2 Jun 2019 16:51:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88ABF286E4 for ; Sun, 2 Jun 2019 16:51:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726895AbfFBQvn (ORCPT ); Sun, 2 Jun 2019 12:51:43 -0400 Received: from sonic302-8.consmr.mail.bf2.yahoo.com ([74.6.135.47]:37563 "EHLO sonic302-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726892AbfFBQvn (ORCPT ); Sun, 2 Jun 2019 12:51:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494300; bh=ZCT9uElDRTx+ICdatyCuPDJ03LmAmILNxQZ9h703pNY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=EFJ2/pW5zx3z7UHz+G2zDr7PIj+8c3khTV6O5ZR8ActVZWQX55yCnO293OX2j6kQRblMvtTqoprhbBlDhMLODYa91xe7RLMUOvBEbkeSHIby5c0rCWtO2Sd99y8FXRGT9ytOuuHP/q3HRIve2u/fJTAJuPC3Zg5LfwY2T/Ef6Py05b7m6WcavxtrN0yrxmmysL7FL+5RPaGtOZfYEu1/QUh5sz1q6St12EbxcVVLO6jlgWFWcHRQP/vyXZBIGT7n7N8dFQU+FA+LS9uWyIfvS7iGXRYnkaxtJNiEgiUTNZPUbAY1xu4immW5O7gbPw7JkeCSz2+cn/Wo1pDWTdgqHA== X-YMail-OSG: DBu7cNQVM1kS.02FOC4sBkTeeiLj3K1mm6fe_Z3VIxcsqLcV3e2UTEno8upxUHB pOAgykkNcE1bdiyrmz00UjpB.AdZhseI.yfzHZJ4hX_FyT3IHq8n2yinzldtnS4stQ5sMAkRRHac US9J1z7EnJnpT6NT2F_7dwkwQ7rR8H8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rnhNlHnrPEImop0L4Bom2.IWkdP1mk 0tQx_IizHlgySZP9tWseY5QzxM8Ml_2GrlSIZxL9NtRg- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:51:40 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp413.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID b3a8ad7d79501e3c392fdc3d79d8fa55; Sun, 02 Jun 2019 16:51:38 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 10/58] LSM: Use lsm_export in the audit_rule_match hooks Date: Sun, 2 Jun 2019 09:50:13 -0700 Message-Id: <20190602165101.25079-11-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the audit_rule_match hooks to use the lsm_export structure instead of a u32 secid. There is quite a bit of scaffolding involved that will be removed when security_audit_rule_match() is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 5 +++-- security/apparmor/audit.c | 4 ++-- security/apparmor/include/audit.h | 2 +- security/apparmor/include/secid.h | 2 +- security/apparmor/secid.c | 17 +++++++++++++++-- security/security.c | 7 ++++++- security/selinux/hooks.c | 17 ----------------- security/selinux/include/audit.h | 5 +++-- security/selinux/include/objsec.h | 17 +++++++++++++++++ security/selinux/ss/services.c | 6 +++++- security/smack/smack_lsm.c | 7 +++++-- 11 files changed, 58 insertions(+), 31 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index bcc628cffe6a..01296e4ce474 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1354,7 +1354,7 @@ * @audit_rule_match: * Determine if given @secid matches a rule previously approved * by @audit_rule_known. - * @secid contains the security id in question. + * @l points to the security data in question. * @field contains the field which relates to current LSM. * @op contains the operator that will be used for matching. * @lrule points to the audit rule that will be checked against. @@ -1778,7 +1778,8 @@ union security_list_options { int (*audit_rule_init)(u32 field, u32 op, char *rulestr, void **lsmrule); int (*audit_rule_known)(struct audit_krule *krule); - int (*audit_rule_match)(u32 secid, u32 field, u32 op, void *lsmrule); + int (*audit_rule_match)(struct lsm_export *l, u32 field, u32 op, + void *lsmrule); void (*audit_rule_free)(void *lsmrule); #endif /* CONFIG_AUDIT */ diff --git a/security/apparmor/audit.c b/security/apparmor/audit.c index 5a8b9cded4f2..bea59bfad332 100644 --- a/security/apparmor/audit.c +++ b/security/apparmor/audit.c @@ -225,13 +225,13 @@ int aa_audit_rule_known(struct audit_krule *rule) return 0; } -int aa_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule) +int aa_audit_rule_match(struct lsm_export *l, u32 field, u32 op, void *vrule) { struct aa_audit_rule *rule = vrule; struct aa_label *label; int found = 0; - label = aa_secid_to_label(sid); + label = aa_secid_to_label(l); if (!label) return -ENOENT; diff --git a/security/apparmor/include/audit.h b/security/apparmor/include/audit.h index ee559bc2acb8..372ba4fada9c 100644 --- a/security/apparmor/include/audit.h +++ b/security/apparmor/include/audit.h @@ -192,6 +192,6 @@ static inline int complain_error(int error) void aa_audit_rule_free(void *vrule); int aa_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule); int aa_audit_rule_known(struct audit_krule *rule); -int aa_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule); +int aa_audit_rule_match(struct lsm_export *l, u32 field, u32 op, void *vrule); #endif /* __AA_AUDIT_H */ diff --git a/security/apparmor/include/secid.h b/security/apparmor/include/secid.h index fa2062711b63..c283c620efe3 100644 --- a/security/apparmor/include/secid.h +++ b/security/apparmor/include/secid.h @@ -25,7 +25,7 @@ struct aa_label; /* secid value that matches any other secid */ #define AA_SECID_WILDCARD 1 -struct aa_label *aa_secid_to_label(u32 secid); +struct aa_label *aa_secid_to_label(struct lsm_export *l); int apparmor_secid_to_secctx(u32 secid, char **secdata, u32 *seclen); int apparmor_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid); void apparmor_release_secctx(char *secdata, u32 seclen); diff --git a/security/apparmor/secid.c b/security/apparmor/secid.c index 05373d9a3d6a..1546c45a2a18 100644 --- a/security/apparmor/secid.c +++ b/security/apparmor/secid.c @@ -61,9 +61,12 @@ void aa_secid_update(u32 secid, struct aa_label *label) * * see label for inverse aa_label_to_secid */ -struct aa_label *aa_secid_to_label(u32 secid) +struct aa_label *aa_secid_to_label(struct lsm_export *l) { struct aa_label *label; + u32 secid; + + secid = (l->flags & LSM_EXPORT_APPARMOR) ? l->apparmor : 0; rcu_read_lock(); label = idr_find(&aa_secids, secid); @@ -72,12 +75,22 @@ struct aa_label *aa_secid_to_label(u32 secid) return label; } +static inline void aa_import_secid(struct lsm_export *l, u32 secid) +{ + l->flags = LSM_EXPORT_APPARMOR; + l->apparmor = secid; +} + int apparmor_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) { /* TODO: cache secctx and ref count so we don't have to recreate */ - struct aa_label *label = aa_secid_to_label(secid); + struct lsm_export data; + struct aa_label *label; int len; + aa_import_secid(&data, secid); + label = aa_secid_to_label(&data); + AA_BUG(!seclen); if (!label) diff --git a/security/security.c b/security/security.c index 2f1355d10e0d..60dd064c0531 100644 --- a/security/security.c +++ b/security/security.c @@ -2477,7 +2477,12 @@ void security_audit_rule_free(void *lsmrule) int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule) { - return call_int_hook(audit_rule_match, 0, secid, field, op, lsmrule); + int rc; + struct lsm_export data = { .flags = LSM_EXPORT_NONE }; + + rc = call_int_hook(audit_rule_match, 0, &data, field, op, lsmrule); + lsm_export_secid(&data, &secid); + return rc; } #endif /* CONFIG_AUDIT */ diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 9db12f6b1221..bfd0f1f5979f 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -213,23 +213,6 @@ static void cred_init_security(void) tsec->osid = tsec->sid = SECINITSID_KERNEL; } -/* - * Set the SELinux secid in an lsm_export structure - */ -static inline void selinux_export_secid(struct lsm_export *l, u32 secid) -{ - l->selinux = secid; - l->flags |= LSM_EXPORT_SELINUX; -} - -static inline void selinux_import_secid(struct lsm_export *l, u32 *secid) -{ - if (l->flags & LSM_EXPORT_SELINUX) - *secid = l->selinux; - else - *secid = SECSID_NULL; -} - /* * get the security ID of a set of credentials */ diff --git a/security/selinux/include/audit.h b/security/selinux/include/audit.h index 682e2b5de2a4..92dd5ab15fb2 100644 --- a/security/selinux/include/audit.h +++ b/security/selinux/include/audit.h @@ -39,7 +39,7 @@ void selinux_audit_rule_free(void *rule); /** * selinux_audit_rule_match - determine if a context ID matches a rule. - * @sid: the context ID to check + * @l: points to the context ID to check * @field: the field this rule refers to * @op: the operater the rule uses * @rule: pointer to the audit rule to check against @@ -47,7 +47,8 @@ void selinux_audit_rule_free(void *rule); * Returns 1 if the context id matches the rule, 0 if it does not, and * -errno on failure. */ -int selinux_audit_rule_match(u32 sid, u32 field, u32 op, void *rule); +int selinux_audit_rule_match(struct lsm_export *l, u32 field, u32 op, + void *rule); /** * selinux_audit_rule_known - check to see if rule contains selinux fields. diff --git a/security/selinux/include/objsec.h b/security/selinux/include/objsec.h index 3b78aa4ee98f..59a3b1cd5ba9 100644 --- a/security/selinux/include/objsec.h +++ b/security/selinux/include/objsec.h @@ -50,6 +50,23 @@ static inline u32 current_sid(void) return tsec->sid; } +/* + * Set the SELinux secid in an lsm_export structure + */ +static inline void selinux_export_secid(struct lsm_export *l, u32 secid) +{ + l->selinux = secid; + l->flags |= LSM_EXPORT_SELINUX; +} + +static inline void selinux_import_secid(struct lsm_export *l, u32 *secid) +{ + if (l->flags & LSM_EXPORT_SELINUX) + *secid = l->selinux; + else + *secid = SECSID_NULL; +} + enum label_initialized { LABEL_INVALID, /* invalid or not initialized */ LABEL_INITIALIZED, /* initialized */ diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c index e3f5d6aece66..626b877363fb 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c @@ -3395,13 +3395,15 @@ int selinux_audit_rule_known(struct audit_krule *rule) return 0; } -int selinux_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule) +int selinux_audit_rule_match(struct lsm_export *l, u32 field, u32 op, + void *vrule) { struct selinux_state *state = &selinux_state; struct context *ctxt; struct mls_level *level; struct selinux_audit_rule *rule = vrule; int match = 0; + u32 sid; if (unlikely(!rule)) { WARN_ONCE(1, "selinux_audit_rule_match: missing rule\n"); @@ -3415,6 +3417,8 @@ int selinux_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule) goto out; } + selinux_import_secid(l, &sid); + ctxt = sidtab_search(state->ss->sidtab, sid); if (unlikely(!ctxt)) { WARN_ONCE(1, "selinux_audit_rule_match: unrecognized SID %d\n", diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 3e3724bbd6ea..a3776501965d 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4369,7 +4369,7 @@ static int smack_audit_rule_known(struct audit_krule *krule) /** * smack_audit_rule_match - Audit given object ? - * @secid: security id for identifying the object to test + * @l: security id for identifying the object to test * @field: audit rule flags given from user-space * @op: required testing operator * @vrule: smack internal rule presentation @@ -4377,10 +4377,12 @@ static int smack_audit_rule_known(struct audit_krule *krule) * The core Audit hook. It's used to take the decision of * whether to audit or not to audit a given object. */ -static int smack_audit_rule_match(u32 secid, u32 field, u32 op, void *vrule) +static int smack_audit_rule_match(struct lsm_export *l, u32 field, u32 op, + void *vrule) { struct smack_known *skp; char *rule = vrule; + u32 secid; if (unlikely(!rule)) { WARN_ONCE(1, "Smack: missing rule\n"); @@ -4390,6 +4392,7 @@ static int smack_audit_rule_match(u32 secid, u32 field, u32 op, void *vrule) if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER) return 0; + smack_import_secid(l, &secid); skp = smack_from_secid(secid); /* From patchwork Sun Jun 2 16:50:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971833 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9148B17DF for ; Sun, 2 Jun 2019 16:51:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80A061FF40 for ; Sun, 2 Jun 2019 16:51:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 74C0C2873A; Sun, 2 Jun 2019 16:51:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE33A1FF40 for ; Sun, 2 Jun 2019 16:51:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726918AbfFBQvq (ORCPT ); Sun, 2 Jun 2019 12:51:46 -0400 Received: from sonic305-8.consmr.mail.bf2.yahoo.com ([74.6.133.47]:33350 "EHLO sonic305-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726911AbfFBQvq (ORCPT ); Sun, 2 Jun 2019 12:51:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494304; bh=e+8uXyTo2CH/SxRFMxOILZ2iZwykcjjY1wTO6Nmz4rg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=Dt8YPhjmgYlBnREPoVAO+dDzPY2Y9Kvtw/liALf3CB4S68G7yJI82tkMojCGnaAfvsT60+EVtoR2Wt0wydqTMYUsLKviHr4vFSo46HcaH9Ne9MMYFALD5Rt2ZaZu9tm8P9Y/VYCLuUb2rrzi4pAq++5jPYdnkoBoW4t4Jt3h723arweP4Hm5ABedZ1cvIj3SrB402jwKF9uZHVq2bCMifZ6KNe8AO28jYnxXiM9jXxIeHy0aMVV0VlVLZMOFckNEmMCpTyCAjihkO+ExZnu6X8sB5QTahVi5FKCrw9Pa9qz1K62Ps55DcjtBkwPQJa/ZxVLeXcplYjVHAjGD85geXQ== X-YMail-OSG: TfbWB0oVM1n0IEpLScnIT9wXcBoL2eplGeluOKD.jGl3hUqhVRYjJxzyXCLmj6e oaa4VHiAbH7lhZJyqV75JLFGPQv30ORPKO1mdvyiUeZZIjNNxQvnL9Xc38S4eaPMLk5_QYhfL95p HvWh3EppyQXJ_j7IHPte0xiKkSnCiKXtwawF7MMG9Q5dZN.Q.4pfEbEPLd8nk7gXZmFF59pNKSTF qwADo0cFM8MBxVP6V0QjI8dbjNCQh0PWBRjmpOomo9tb1bRQdk3VM26j1nnj7sPJ_c0wJeD4LkUI zIq3BOF0kLx8pscCPJk.XZwWkZ38.b0jLaimU4KsIP2uuruYFRjRqegT6K6RV.Q38en0ktZcYbjI 3hYgj.hKG8DzjIOkxFoUWsqQy9Ui_T0AWwv2Qrz.N3ZikXr47DPwpwrlFxMaMi.M1UKGVsnDzm0l NmDGIsjiXBLp7ONubuYYrkng8aY1O043Q7yCRNKSngFBjDNK37vYjOb2VRTcolNei0A1_zAZEziZ oCCtrSXs_R6dbx28OAl1ZP9G0MCLBIeK7WbKJ_r3OoS0L9HuDDQz.BY4_k1mR07bRbjr65itUBpX dkFIDT4CxFaas06EL9NIkKaW0dGga1nwr9NgCUndBxdScjeiW3JQP6FLVWRWcSSdKYoX8fg6A7S5 CM3rT0JaeJc.3GyO6LEo.daCOdfU.DJ1AM96bgkY3yZyheQQrV7n546codLAajZcTJhdYxsDjxut ILF_bf8VCtsx3Fh3JkX753RO269Ef..TtUzuVXKuIInmkfe.JBAjq2_fdO.SQ7r1H33GZ3PxlBk1 _z7jeaLu0ZzB15ZLfhbfearTrBG_qeS7WqqBNEXvmf3ht2dlUex2NpfHRNjLlz3IDrdVW3jzqt9w j3GIMoiyR7e0IttA5B2xSv8gRHcXSC8bajy72orAwLU1pVftJNNDCpctm4rhdVItk9SVE_ApB_d_ eyfIlb1OvvSEPQiOVs0RbMzeUXXKduo_wpz_VF9nE95rTvmxRVFsac4GtoKBZgJze68FR2joNYjK N.L108jS77dyX.WWTR0fVVGNdt02Y85kRMNzUClR0fSDGi5nT3Ha253AFiEW7ob5SnTi0Oxv1.Z. ucInCldBbnlH7e_zsHku7PePmNtyAlKivgJPaYWaNw7ATBH4q0JWgthhERO.BouhTXauWlRqXQJ4 RtcJC3FOzK4Gw9Wc8TW6jUkZwzPhFzxtwT0OkTY2ApGF07Nr01qS5f9gpqmI.P2CBs8tRZvgmCiS D4vr1.Z7nLM1iiHnaxAKi0peAuuaLtNAJTpjq.t_BSsiR Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:51:44 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp413.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID b3a8ad7d79501e3c392fdc3d79d8fa55; Sun, 02 Jun 2019 16:51:40 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 11/58] LSM: Use lsm_export in the secid_to_secctx hooks Date: Sun, 2 Jun 2019 09:50:14 -0700 Message-Id: <20190602165101.25079-12-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the secid_to_secctx hooks to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when security_secid_to_secctx() is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 5 +++-- security/apparmor/include/secid.h | 2 +- security/apparmor/secid.c | 6 ++---- security/security.c | 5 ++++- security/selinux/hooks.c | 6 +++++- security/smack/smack_lsm.c | 9 +++++++-- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 01296e4ce474..433d98dcb928 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1319,7 +1319,7 @@ * This does mean that the length could change between calls to check the * length and the next call which actually allocates and returns the * secdata. - * @secid contains the security ID. + * @l points to the security information. * @secdata contains the pointer that stores the converted security * context. * @seclen pointer which contains the length of the data @@ -1664,7 +1664,8 @@ union security_list_options { int (*getprocattr)(struct task_struct *p, char *name, char **value); int (*setprocattr)(const char *name, void *value, size_t size); int (*ismaclabel)(const char *name); - int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen); + int (*secid_to_secctx)(struct lsm_export *l, char **secdata, + u32 *seclen); int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid); void (*release_secctx)(char *secdata, u32 seclen); diff --git a/security/apparmor/include/secid.h b/security/apparmor/include/secid.h index c283c620efe3..03369183f512 100644 --- a/security/apparmor/include/secid.h +++ b/security/apparmor/include/secid.h @@ -26,7 +26,7 @@ struct aa_label; #define AA_SECID_WILDCARD 1 struct aa_label *aa_secid_to_label(struct lsm_export *l); -int apparmor_secid_to_secctx(u32 secid, char **secdata, u32 *seclen); +int apparmor_secid_to_secctx(struct lsm_export *l, char **secdata, u32 *seclen); int apparmor_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid); void apparmor_release_secctx(char *secdata, u32 seclen); diff --git a/security/apparmor/secid.c b/security/apparmor/secid.c index 1546c45a2a18..ab4dc165e43e 100644 --- a/security/apparmor/secid.c +++ b/security/apparmor/secid.c @@ -81,15 +81,13 @@ static inline void aa_import_secid(struct lsm_export *l, u32 secid) l->apparmor = secid; } -int apparmor_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) +int apparmor_secid_to_secctx(struct lsm_export *l, char **secdata, u32 *seclen) { /* TODO: cache secctx and ref count so we don't have to recreate */ - struct lsm_export data; struct aa_label *label; int len; - aa_import_secid(&data, secid); - label = aa_secid_to_label(&data); + label = aa_secid_to_label(l); AA_BUG(!seclen); diff --git a/security/security.c b/security/security.c index 60dd064c0531..adf4cb768665 100644 --- a/security/security.c +++ b/security/security.c @@ -2002,7 +2002,10 @@ EXPORT_SYMBOL(security_ismaclabel); int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) { - return call_int_hook(secid_to_secctx, -EOPNOTSUPP, secid, secdata, + struct lsm_export data; + + lsm_export_to_all(&data, secid); + return call_int_hook(secid_to_secctx, -EOPNOTSUPP, &data, secdata, seclen); } EXPORT_SYMBOL(security_secid_to_secctx); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index bfd0f1f5979f..16d902158e8a 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6301,8 +6301,12 @@ static int selinux_ismaclabel(const char *name) return (strcmp(name, XATTR_SELINUX_SUFFIX) == 0); } -static int selinux_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) +static int selinux_secid_to_secctx(struct lsm_export *l, char **secdata, + u32 *seclen) { + u32 secid; + + selinux_import_secid(l, &secid); return security_sid_to_context(&selinux_state, secid, secdata, seclen); } diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index a3776501965d..809af981f14c 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4433,9 +4433,14 @@ static int smack_ismaclabel(const char *name) * * Exists for networking code. */ -static int smack_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) +static int smack_secid_to_secctx(struct lsm_export *l, char **secdata, + u32 *seclen) { - struct smack_known *skp = smack_from_secid(secid); + struct smack_known *skp; + u32 secid; + + smack_import_secid(l, &secid); + skp = smack_from_secid(secid); if (secdata) *secdata = skp->smk_known; From patchwork Sun Jun 2 16:50:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971843 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E1F1B13AD for ; Sun, 2 Jun 2019 16:51:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D129328703 for ; Sun, 2 Jun 2019 16:51:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C24C82873A; Sun, 2 Jun 2019 16:51:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C74828A28 for ; Sun, 2 Jun 2019 16:51:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726935AbfFBQv5 (ORCPT ); Sun, 2 Jun 2019 12:51:57 -0400 Received: from sonic316-12.consmr.mail.gq1.yahoo.com ([98.137.69.36]:32870 "EHLO sonic316-12.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726911AbfFBQv5 (ORCPT ); Sun, 2 Jun 2019 12:51:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494316; bh=xCs5ko0ljATg/F1vIduV+zjbu+Bg+Z+duHwS3Dwapdk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=ulxjI/J60+FCkSFx5Tcx+2rYPTY61TtBgrEKvAjFqnd/Y8q/+eGFNsJI8ILE7N2LpsQNEnUHkzarCTH68Sc9C3f4hSzIdCunYDhS2/snb0vKjNbCC4fUyB1t+mSAY8eiJ6T+5hnsGArmp2qkhoz44DKdkpiKFtpU7cqqJIqpP4rxQWMMLip/6dABJnd2LkdNqrI9bylb6AIrr0k967cZGvJxZ/eu4R7HbhOUa+dvRbTznPASgShQ/H07/NmPXR291mrMl860NQo31OPcu+EctlQXXtOCFozqX1EfhS4/SBipYqzlFYuy24oAfutH79LytdM1SfuD8mryLFE5919tHQ== X-YMail-OSG: mZwHyWAVM1mWjCBhrDh0rTXLMqX_QdBEzrzdlqatznEjJc3JGoF6nZd_j0oI4IH BA2beRBoTnRkLrWnnUi3YeK8nCrBEWSizr4VUdfKNB0UJnQM.3AUTC5K3JE_G8KouzoAeC0QrIMV 2QM.922MRCW._8UHw2Ci9FbiX60UvJJeqZR_efpugMlMBhas5OPDTfZ_jixZtRN4QIH4plDkH4iH zDEvwgBXlWszuC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eiYZe_fQ-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic316.consmr.mail.gq1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:51:56 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp420.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID aa88b96425a9713222d71be7c480dcea; Sun, 02 Jun 2019 16:51:51 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 12/58] LSM: Use lsm_export in the secctx_to_secid hooks Date: Sun, 2 Jun 2019 09:50:15 -0700 Message-Id: <20190602165101.25079-13-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the secctx_to_secid hooks to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when security_secctx_to_secid() is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 7 ++++--- security/apparmor/include/secid.h | 3 ++- security/apparmor/secid.c | 9 +++++---- security/security.c | 8 ++++++-- security/selinux/hooks.c | 12 +++++++++--- security/smack/smack_lsm.c | 7 ++++--- 6 files changed, 30 insertions(+), 16 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 433d98dcb928..0837c214cc17 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1324,8 +1324,8 @@ * context. * @seclen pointer which contains the length of the data * @secctx_to_secid: - * Convert security context to secid. - * @secid contains the pointer to the generated security ID. + * Convert security context to exported lsm data. + * @l contains the pointer to the generated security data. * @secdata contains the security context. * * @release_secctx: @@ -1666,7 +1666,8 @@ union security_list_options { int (*ismaclabel)(const char *name); int (*secid_to_secctx)(struct lsm_export *l, char **secdata, u32 *seclen); - int (*secctx_to_secid)(const char *secdata, u32 seclen, u32 *secid); + int (*secctx_to_secid)(const char *secdata, u32 seclen, + struct lsm_export *l); void (*release_secctx)(char *secdata, u32 seclen); void (*inode_invalidate_secctx)(struct inode *inode); diff --git a/security/apparmor/include/secid.h b/security/apparmor/include/secid.h index 03369183f512..5381eff03d4f 100644 --- a/security/apparmor/include/secid.h +++ b/security/apparmor/include/secid.h @@ -27,7 +27,8 @@ struct aa_label; struct aa_label *aa_secid_to_label(struct lsm_export *l); int apparmor_secid_to_secctx(struct lsm_export *l, char **secdata, u32 *seclen); -int apparmor_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid); +int apparmor_secctx_to_secid(const char *secdata, u32 seclen, + struct lsm_export *l); void apparmor_release_secctx(char *secdata, u32 seclen); diff --git a/security/apparmor/secid.c b/security/apparmor/secid.c index ab4dc165e43e..69d98a89db75 100644 --- a/security/apparmor/secid.c +++ b/security/apparmor/secid.c @@ -75,9 +75,9 @@ struct aa_label *aa_secid_to_label(struct lsm_export *l) return label; } -static inline void aa_import_secid(struct lsm_export *l, u32 secid) +static inline void aa_export_secid(struct lsm_export *l, u32 secid) { - l->flags = LSM_EXPORT_APPARMOR; + l->flags |= LSM_EXPORT_APPARMOR; l->apparmor = secid; } @@ -111,7 +111,8 @@ int apparmor_secid_to_secctx(struct lsm_export *l, char **secdata, u32 *seclen) return 0; } -int apparmor_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid) +int apparmor_secctx_to_secid(const char *secdata, u32 seclen, + struct lsm_export *l) { struct aa_label *label; @@ -119,7 +120,7 @@ int apparmor_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid) seclen, GFP_KERNEL, false, false); if (IS_ERR(label)) return PTR_ERR(label); - *secid = label->secid; + aa_export_secid(l, label->secid); return 0; } diff --git a/security/security.c b/security/security.c index adf4cb768665..1645ebe06715 100644 --- a/security/security.c +++ b/security/security.c @@ -2012,8 +2012,12 @@ EXPORT_SYMBOL(security_secid_to_secctx); int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid) { - *secid = 0; - return call_int_hook(secctx_to_secid, 0, secdata, seclen, secid); + struct lsm_export data = { .flags = LSM_EXPORT_NONE }; + int rc; + + rc = call_int_hook(secctx_to_secid, 0, secdata, seclen, &data); + lsm_export_secid(&data, secid); + return rc; } EXPORT_SYMBOL(security_secctx_to_secid); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 16d902158e8a..7dd333f133db 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6311,10 +6311,16 @@ static int selinux_secid_to_secctx(struct lsm_export *l, char **secdata, secdata, seclen); } -static int selinux_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid) +static int selinux_secctx_to_secid(const char *secdata, u32 seclen, + struct lsm_export *l) { - return security_context_to_sid(&selinux_state, secdata, seclen, - secid, GFP_KERNEL); + u32 secid; + int rc; + + rc = security_context_to_sid(&selinux_state, secdata, seclen, + &secid, GFP_KERNEL); + selinux_export_secid(l, secid); + return rc; } static void selinux_release_secctx(char *secdata, u32 seclen) diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 809af981f14c..ecd636e5c75c 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4456,14 +4456,15 @@ static int smack_secid_to_secctx(struct lsm_export *l, char **secdata, * * Exists for audit and networking code. */ -static int smack_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid) +static int smack_secctx_to_secid(const char *secdata, u32 seclen, + struct lsm_export *l) { struct smack_known *skp = smk_find_entry(secdata); if (skp) - *secid = skp->smk_secid; + smack_export_secid(l, skp->smk_secid); else - *secid = 0; + smack_export_secid(l, 0); return 0; } From patchwork Sun Jun 2 16:50:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971849 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7CB3E17DF for ; Sun, 2 Jun 2019 16:52:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A7E0286E4 for ; Sun, 2 Jun 2019 16:52:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E3B22873A; Sun, 2 Jun 2019 16:52:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8D93286E4 for ; Sun, 2 Jun 2019 16:51:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726942AbfFBQv7 (ORCPT ); Sun, 2 Jun 2019 12:51:59 -0400 Received: from sonic316-12.consmr.mail.gq1.yahoo.com ([98.137.69.36]:43646 "EHLO sonic316-12.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726940AbfFBQv6 (ORCPT ); Sun, 2 Jun 2019 12:51:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494316; bh=kBs6xavdKLksOJrpeyZAKYy1l7B4qvl4+o1ibk1YtLg=; h=From:To:Cc:Subject:Date:In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y8kTsD.ffkuoUQVbqGWfjW.bwKWp3vl8k7mXj BxGPotoS1YehguH2pf8i611Vrl17EVXU0l8WA2unS3g70Vdb.jXe2VrgtAjfGqrOFBm3dWX5HNS1 eW0HZjJWusSOAV0oFL_HOELsQO_th5GlId0VSFDUiqsz9_r.KnSjfKY87LyBOLXeMUyHSwQ.qrgR tgesK1GNdgT.nx6eGOKCG_z.oJMBoFFLI.AC5w3IfszYtAX2tQwj6WatkaJyz93snWqtFugd6Op1 z6uJ9LQKM5dHQ0.OFaJfnI50bQwmXVALBhF7XZRBWl9rq7C4fbNDTJLgz56bEpt51Ake2I3nuurd tVtMrsht1xMZ8uw8zt_UqxGGsAUPSMm8Xp0xt1Ak4yUpCDizcmRZe7lBupZss_t.F79E9Dis2TA4 Gs92Kgi3ntKz55li_OFnSr8kNwAwz15ytdeQb7nPN6asayMGNfCgij4oZ5MCx74vv_RMpgQTHFqt v7aFlL0T2.cFPwNuEJnNzwlh05T0bEzUyH.eC6adTkX5Z34XCDcxERC4fc2UQy0guJhZpJDHk7.6 JqWaE1cmvUBbbamMI.5NlAZRjuznv47.WQ1zyL8wi6xk- Received: from sonic.gate.mail.ne1.yahoo.com by sonic316.consmr.mail.gq1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:51:56 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp420.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID aa88b96425a9713222d71be7c480dcea; Sun, 02 Jun 2019 16:51:52 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 13/58] LSM: Use lsm_export in security_audit_rule_match Date: Sun, 2 Jun 2019 09:50:16 -0700 Message-Id: <20190602165101.25079-14-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_audit_rule_match to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/security.h | 46 +++++++++++++++++++++++++-- kernel/auditfilter.c | 4 ++- kernel/auditsc.c | 13 +++++--- security/integrity/ima/ima_policy.c | 7 +++-- security/security.c | 48 ++--------------------------- 5 files changed, 63 insertions(+), 55 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index fb19f41d630b..ea2c6c4e88db 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -93,6 +93,45 @@ static inline void lsm_export_init(struct lsm_export *l) memset(l, 0, sizeof(*l)); } +/** + * lsm_export_secid - pull the useful secid out of a lsm_export + * @data: the containing data structure + * @secid: where to put the one that matters. + * + * Shim that will disappear when all lsm_export conversions are done. + */ +static inline void lsm_export_secid(struct lsm_export *data, u32 *secid) +{ + switch (data->flags) { + case LSM_EXPORT_NONE: + *secid = 0; + break; + case LSM_EXPORT_SELINUX: + *secid = data->selinux; + break; + case LSM_EXPORT_SMACK: + *secid = data->smack; + break; + case LSM_EXPORT_APPARMOR: + *secid = data->apparmor; + break; + default: + pr_warn("%s flags=0x%u - not a valid set\n", __func__, + data->flags); + *secid = 0; + break; + } +} + +static inline void lsm_export_to_all(struct lsm_export *data, u32 secid) +{ + data->selinux = secid; + data->smack = secid; + data->apparmor = secid; + data->flags = LSM_EXPORT_SELINUX | LSM_EXPORT_SMACK | + LSM_EXPORT_APPARMOR; +} + /* These functions are in security/commoncap.c */ extern int cap_capable(const struct cred *cred, struct user_namespace *ns, int cap, unsigned int opts); @@ -1712,7 +1751,8 @@ static inline int security_key_getsecurity(struct key *key, char **_buffer) #ifdef CONFIG_SECURITY int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule); int security_audit_rule_known(struct audit_krule *krule); -int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule); +int security_audit_rule_match(struct lsm_export *l, u32 field, u32 op, + void *lsmrule); void security_audit_rule_free(void *lsmrule); #else @@ -1728,8 +1768,8 @@ static inline int security_audit_rule_known(struct audit_krule *krule) return 0; } -static inline int security_audit_rule_match(u32 secid, u32 field, u32 op, - void *lsmrule) +static inline int security_audit_rule_match(struct lsm_export *l, u32 field, + u32 op, void *lsmrule) { return 0; } diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c index 63f8b3f26fab..15771102919d 100644 --- a/kernel/auditfilter.c +++ b/kernel/auditfilter.c @@ -1324,6 +1324,7 @@ int audit_filter(int msgtype, unsigned int listtype) struct audit_field *f = &e->rule.fields[i]; pid_t pid; u32 sid; + struct lsm_export le; switch (f->type) { case AUDIT_PID: @@ -1354,7 +1355,8 @@ int audit_filter(int msgtype, unsigned int listtype) case AUDIT_SUBJ_CLR: if (f->lsm_rule) { security_task_getsecid(current, &sid); - result = security_audit_rule_match(sid, + lsm_export_to_all(&le, sid); + result = security_audit_rule_match(&le, f->type, f->op, f->lsm_rule); } break; diff --git a/kernel/auditsc.c b/kernel/auditsc.c index d1eab1d4a930..822ba35e4e64 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -445,6 +445,7 @@ static int audit_filter_rules(struct task_struct *tsk, const struct cred *cred; int i, need_sid = 1; u32 sid; + struct lsm_export le; unsigned int sessionid; cred = rcu_dereference_check(tsk->cred, tsk == current || task_creation); @@ -630,7 +631,8 @@ static int audit_filter_rules(struct task_struct *tsk, security_task_getsecid(tsk, &sid); need_sid = 0; } - result = security_audit_rule_match(sid, f->type, + lsm_export_to_all(&le, sid); + result = security_audit_rule_match(&le, f->type, f->op, f->lsm_rule); } @@ -645,15 +647,17 @@ static int audit_filter_rules(struct task_struct *tsk, if (f->lsm_rule) { /* Find files that match */ if (name) { + lsm_export_to_all(&le, name->osid); result = security_audit_rule_match( - name->osid, + &le, f->type, f->op, f->lsm_rule); } else if (ctx) { list_for_each_entry(n, &ctx->names_list, list) { + lsm_export_to_all(&le, n->osid); if (security_audit_rule_match( - n->osid, + &le, f->type, f->op, f->lsm_rule)) { @@ -665,7 +669,8 @@ static int audit_filter_rules(struct task_struct *tsk, /* Find ipc objects that match */ if (!ctx || ctx->type != AUDIT_IPC) break; - if (security_audit_rule_match(ctx->ipc.osid, + lsm_export_to_all(&le, ctx->ipc.osid); + if (security_audit_rule_match(&le, f->type, f->op, f->lsm_rule)) ++result; diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index e0cc323f948f..090ef8ceb116 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -327,6 +327,7 @@ static bool ima_match_rules(struct ima_rule_entry *rule, struct inode *inode, for (i = 0; i < MAX_LSM_RULES; i++) { int rc = 0; u32 osid; + struct lsm_export le; int retried = 0; if (!rule->lsm[i].rule) @@ -337,7 +338,8 @@ static bool ima_match_rules(struct ima_rule_entry *rule, struct inode *inode, case LSM_OBJ_ROLE: case LSM_OBJ_TYPE: security_inode_getsecid(inode, &osid); - rc = security_filter_rule_match(osid, + lsm_export_to_all(&le, osid); + rc = security_filter_rule_match(&le, rule->lsm[i].type, Audit_equal, rule->lsm[i].rule); @@ -345,7 +347,8 @@ static bool ima_match_rules(struct ima_rule_entry *rule, struct inode *inode, case LSM_SUBJ_USER: case LSM_SUBJ_ROLE: case LSM_SUBJ_TYPE: - rc = security_filter_rule_match(secid, + lsm_export_to_all(&le, secid); + rc = security_filter_rule_match(&le, rule->lsm[i].type, Audit_equal, rule->lsm[i].rule); diff --git a/security/security.c b/security/security.c index 1645ebe06715..1e819ecf26ff 100644 --- a/security/security.c +++ b/security/security.c @@ -712,45 +712,6 @@ int lsm_superblock_alloc(struct super_block *sb) RC; \ }) -/** - * lsm_export_secid - pull the useful secid out of a lsm_export - * @data: the containing data structure - * @secid: where to put the one that matters. - * - * Shim that will disappear when all lsm_export conversions are done. - */ -static inline void lsm_export_secid(struct lsm_export *data, u32 *secid) -{ - switch (data->flags) { - case LSM_EXPORT_NONE: - *secid = 0; - break; - case LSM_EXPORT_SELINUX: - *secid = data->selinux; - break; - case LSM_EXPORT_SMACK: - *secid = data->smack; - break; - case LSM_EXPORT_APPARMOR: - *secid = data->apparmor; - break; - default: - pr_warn("%s flags=0x%u - not a valid set\n", __func__, - data->flags); - *secid = 0; - break; - } -} - -static inline void lsm_export_to_all(struct lsm_export *data, u32 secid) -{ - data->selinux = secid; - data->smack = secid; - data->apparmor = secid; - data->flags = LSM_EXPORT_SELINUX | LSM_EXPORT_SMACK | - LSM_EXPORT_APPARMOR; -} - /* Security operations */ int security_binder_set_context_mgr(struct task_struct *mgr) @@ -2482,14 +2443,11 @@ void security_audit_rule_free(void *lsmrule) call_void_hook(audit_rule_free, lsmrule); } -int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule) +int security_audit_rule_match(struct lsm_export *l, u32 field, u32 op, + void *lsmrule) { - int rc; - struct lsm_export data = { .flags = LSM_EXPORT_NONE }; - rc = call_int_hook(audit_rule_match, 0, &data, field, op, lsmrule); - lsm_export_secid(&data, &secid); - return rc; + return call_int_hook(audit_rule_match, 0, l, field, op, lsmrule); } #endif /* CONFIG_AUDIT */ From patchwork Sun Jun 2 16:50:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971837 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 324C513AD for ; Sun, 2 Jun 2019 16:51:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 206221FF40 for ; Sun, 2 Jun 2019 16:51:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13ECC28A1B; Sun, 2 Jun 2019 16:51:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E196B1FF40 for ; Sun, 2 Jun 2019 16:51:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726945AbfFBQv4 (ORCPT ); Sun, 2 Jun 2019 12:51:56 -0400 Received: from sonic310-27.consmr.mail.gq1.yahoo.com ([98.137.69.153]:37371 "EHLO sonic310-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726925AbfFBQv4 (ORCPT ); Sun, 2 Jun 2019 12:51:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494315; bh=kPEVpSTXbzStzk2RRdBr0uzp0UqHYw8ZEJtQ2z8HYS0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=bjEsYmg8mUyUxMo86dOhp3oKiFOX+nZxDYTIcJ9BSV48CLxP8hyzEgyeZkmPZkOSr+UmQyEFXWjEdGm8Cu4i1L8fMZ+6FXld0F3NMX69SaDcziM4Pjnqj8ttj/J9fwbDg9g+0TnlOoSJQedmOMhfcb4SGF+MCqWbzX3dvRkI2DPCW6TV3Bfq5dUGrgs7UeCvlD5iBNRXFwCwcoW33NkGovkXqfB5UrXs0iVUhlYRZbGqzmhhwUqrq2cyXnfDZ6N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Ah7rU 1rkMUWyYpkgQuAfiUWUHlHTFPgL83ImnWY9L5hK_nGPQJ3GoECr89zMHlPb_N3H1FVV0FZPNAhkO 0C_7L4ttuwoOoE_sx1Jd8pkLC_YT1sqIjarnwenaXmMnACfHm_tFauDM4LbpXVs8cmK4wCH.QPbV Dmn8fKBmGtcylFIZPansZVsg8ktxToeWim2FIYXYS0rxchzpf.mOFgKvaCS0GKjZ0qIwafiWRFdP ZI7pqVV0R2SWex7CiiU38NrvuYiJrpfKEv9WM3uflsHBwrVig_2qXX8YT3yPffLfnMgTx0WG5CYz 1gMKpqa56tjQ3C.K5vZR753FdpuQsLbbW2ga3tVxM3oE- Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.gq1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:51:55 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp420.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID aa88b96425a9713222d71be7c480dcea; Sun, 02 Jun 2019 16:51:53 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 14/58] LSM: Use lsm_export in security_kernel_act_as Date: Sun, 2 Jun 2019 09:50:17 -0700 Message-Id: <20190602165101.25079-15-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Casey Schaufler Convert security_kernel_act_as to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/cred.h | 3 ++- include/linux/security.h | 5 +++-- kernel/cred.c | 10 ++++++---- security/security.c | 8 ++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/linux/cred.h b/include/linux/cred.h index efb6edf32de7..9305298eca17 100644 --- a/include/linux/cred.h +++ b/include/linux/cred.h @@ -22,6 +22,7 @@ struct cred; struct inode; +struct lsm_export; /* * COW Supplementary groups list @@ -165,7 +166,7 @@ extern const struct cred *override_creds(const struct cred *); extern void revert_creds(const struct cred *); extern struct cred *prepare_kernel_cred(struct task_struct *); extern int change_create_files_as(struct cred *, struct inode *); -extern int set_security_override(struct cred *, u32); +extern int set_security_override(struct cred *, struct lsm_export *); extern int set_security_override_from_ctx(struct cred *, const char *); extern int set_create_files_as(struct cred *, struct inode *); extern int cred_fscmp(const struct cred *, const struct cred *); diff --git a/include/linux/security.h b/include/linux/security.h index ea2c6c4e88db..7369cdc3a681 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -378,7 +378,7 @@ void security_cred_free(struct cred *cred); int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp); void security_transfer_creds(struct cred *new, const struct cred *old); void security_cred_getsecid(const struct cred *c, u32 *secid); -int security_kernel_act_as(struct cred *new, u32 secid); +int security_kernel_act_as(struct cred *new, struct lsm_export *l); int security_kernel_create_files_as(struct cred *new, struct inode *inode); int security_kernel_module_request(char *kmod_name); int security_kernel_load_data(enum kernel_load_data_id id); @@ -961,7 +961,8 @@ static inline void security_transfer_creds(struct cred *new, { } -static inline int security_kernel_act_as(struct cred *cred, u32 secid) +static inline int security_kernel_act_as(struct cred *cred, + struct lsm_export *l) { return 0; } diff --git a/kernel/cred.c b/kernel/cred.c index 45d77284aed0..40a3fde22667 100644 --- a/kernel/cred.c +++ b/kernel/cred.c @@ -701,14 +701,14 @@ EXPORT_SYMBOL(prepare_kernel_cred); /** * set_security_override - Set the security ID in a set of credentials * @new: The credentials to alter - * @secid: The LSM security ID to set + * @l: The LSM security information to set * * Set the LSM security ID in a set of credentials so that the subjective * security is overridden when an alternative set of credentials is used. */ -int set_security_override(struct cred *new, u32 secid) +int set_security_override(struct cred *new, struct lsm_export *l) { - return security_kernel_act_as(new, secid); + return security_kernel_act_as(new, l); } EXPORT_SYMBOL(set_security_override); @@ -724,6 +724,7 @@ EXPORT_SYMBOL(set_security_override); */ int set_security_override_from_ctx(struct cred *new, const char *secctx) { + struct lsm_export le; u32 secid; int ret; @@ -731,7 +732,8 @@ int set_security_override_from_ctx(struct cred *new, const char *secctx) if (ret < 0) return ret; - return set_security_override(new, secid); + lsm_export_to_all(&le, secid); + return set_security_override(new, &le); } EXPORT_SYMBOL(set_security_override_from_ctx); diff --git a/security/security.c b/security/security.c index 1e819ecf26ff..edaaaef54239 100644 --- a/security/security.c +++ b/security/security.c @@ -1615,13 +1615,9 @@ void security_cred_getsecid(const struct cred *c, u32 *secid) } EXPORT_SYMBOL(security_cred_getsecid); -int security_kernel_act_as(struct cred *new, u32 secid) +int security_kernel_act_as(struct cred *new, struct lsm_export *l) { - struct lsm_export data = { .flags = LSM_EXPORT_NONE }; - - lsm_export_to_all(&data, secid); - - return call_int_hook(kernel_act_as, 0, new, &data); + return call_int_hook(kernel_act_as, 0, new, l); } int security_kernel_create_files_as(struct cred *new, struct inode *inode) From patchwork Sun Jun 2 16:50:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971841 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9A90018E8 for ; Sun, 2 Jun 2019 16:51:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A37028A69 for ; Sun, 2 Jun 2019 16:51:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EA0428703; Sun, 2 Jun 2019 16:51:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E23828703 for ; Sun, 2 Jun 2019 16:51:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726925AbfFBQv5 (ORCPT ); Sun, 2 Jun 2019 12:51:57 -0400 Received: from sonic310-27.consmr.mail.gq1.yahoo.com ([98.137.69.153]:42013 "EHLO sonic310-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726933AbfFBQv4 (ORCPT ); Sun, 2 Jun 2019 12:51:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494315; bh=wTEQTvklkThW7Dll4nUn/vb0sTDbloo0pZigu96CHzg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=kpF/+Mk252RQJYlUoCSvKS0ludUnH5RbeFVpg05iVrfEpuiF87ITAfjTwueRCIujzxrSHc/eiSULZ57Vt43toD3kGIZ/p6WQ+aOooZrGyYYVauBzFkTeqwrrdc+Dma+wNovaz61IRXwzJPE9dpu6Kr/2BQlgmbhxUG48TSj8GOq1zQE0QDcDGTyZ1pKL7GzoaM2UQMUaW2pOsDEUChCNNFLpV5IWObAyXCSnfUn/CYzDYk3IZ2PAMEn5K3OrldHrvyAMMYT5hmGPZbRu2OhLno4knipUgpVoY2TsMjZcGT4I5NJUq8e2IAacGjwWs56/6Und3HxsXmGcmkAA87X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lerC29N2.Z8o8Th0KY3OPeSmzPyhJyTNSlXvN37JqrHtV3g1H2hyaIAkNLUsL7ALQGIHkmN yl_vfVBefg5pS5wpYT4kk.I5miTVU0Td0vJaibxb2brcPVkVOAAhT7vQTZtnMK9cwIQF9b6ex_Ft sQyIha385UiOjbV5Im6DHLjxBW6GUqkch2pIfD1xZ..tIlF.UUaVPd1K_UQD1aCqneGw84vX8JHS wLPigfVKPAevVt5d1.vLEt2Ja4tVgxYXQbwrfc5A8isUw Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.gq1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:51:55 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp420.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID aa88b96425a9713222d71be7c480dcea; Sun, 02 Jun 2019 16:51:53 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 15/58] LSM: Use lsm_export in security_socket_getpeersec_dgram Date: Sun, 2 Jun 2019 09:50:18 -0700 Message-Id: <20190602165101.25079-16-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_socket_getpeersec_dgram to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when the related data is updated. In particular, the le entry in scm_cookie includes the secid data. The secid will go away. Signed-off-by: Casey Schaufler --- include/linux/security.h | 7 +++++-- include/net/scm.h | 4 +++- net/ipv4/ip_sockglue.c | 4 +++- security/security.c | 13 ++++--------- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 7369cdc3a681..e3f5c61b9b2c 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -1270,7 +1270,8 @@ int security_socket_shutdown(struct socket *sock, int how); int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb); int security_socket_getpeersec_stream(struct socket *sock, char __user *optval, int __user *optlen, unsigned len); -int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid); +int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, + struct lsm_export *l); int security_sk_alloc(struct sock *sk, int family, gfp_t priority); void security_sk_free(struct sock *sk); void security_sk_clone(const struct sock *sk, struct sock *newsk); @@ -1408,7 +1409,9 @@ static inline int security_socket_getpeersec_stream(struct socket *sock, char __ return -ENOPROTOOPT; } -static inline int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid) +static inline int security_socket_getpeersec_dgram(struct socket *sock, + struct sk_buff *skb, + struct lsm_export *l) { return -ENOPROTOOPT; } diff --git a/include/net/scm.h b/include/net/scm.h index 1ce365f4c256..13b8a369fd89 100644 --- a/include/net/scm.h +++ b/include/net/scm.h @@ -34,6 +34,7 @@ struct scm_cookie { struct scm_creds creds; /* Skb credentials */ #ifdef CONFIG_SECURITY_NETWORK u32 secid; /* Passed security ID */ + struct lsm_export le; /* Passed LSM data */ #endif }; @@ -46,7 +47,8 @@ struct scm_fp_list *scm_fp_dup(struct scm_fp_list *fpl); #ifdef CONFIG_SECURITY_NETWORK static __inline__ void unix_get_peersec_dgram(struct socket *sock, struct scm_cookie *scm) { - security_socket_getpeersec_dgram(sock, NULL, &scm->secid); + security_socket_getpeersec_dgram(sock, NULL, &scm->le); + lsm_export_secid(&scm->le, &scm->secid); } #else static __inline__ void unix_get_peersec_dgram(struct socket *sock, struct scm_cookie *scm) diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c index 82f341e84fae..b8ef7677a7e5 100644 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c @@ -130,14 +130,16 @@ static void ip_cmsg_recv_checksum(struct msghdr *msg, struct sk_buff *skb, static void ip_cmsg_recv_security(struct msghdr *msg, struct sk_buff *skb) { + struct lsm_export le; char *secdata; u32 seclen, secid; int err; - err = security_socket_getpeersec_dgram(NULL, skb, &secid); + err = security_socket_getpeersec_dgram(NULL, skb, &le); if (err) return; + lsm_export_secid(&le, &secid); err = security_secid_to_secctx(secid, &secdata, &seclen); if (err) return; diff --git a/security/security.c b/security/security.c index edaaaef54239..d8300a6400c3 100644 --- a/security/security.c +++ b/security/security.c @@ -2110,16 +2110,11 @@ int security_socket_getpeersec_stream(struct socket *sock, char __user *optval, } int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, - u32 *secid) + struct lsm_export *l) { - int rc; - struct lsm_export data = { .flags = LSM_EXPORT_NONE }; - - rc = call_int_hook(socket_getpeersec_dgram, -ENOPROTOOPT, sock, skb, - &data); - - lsm_export_secid(&data, secid); - return rc; + lsm_export_init(l); + return call_int_hook(socket_getpeersec_dgram, -ENOPROTOOPT, sock, skb, + l); } EXPORT_SYMBOL(security_socket_getpeersec_dgram); From patchwork Sun Jun 2 16:50:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971853 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CD2417DF for ; Sun, 2 Jun 2019 16:52:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 185602873A for ; Sun, 2 Jun 2019 16:52:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 09928289FA; Sun, 2 Jun 2019 16:52:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69A6C1FF40 for ; Sun, 2 Jun 2019 16:52:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726961AbfFBQwM (ORCPT ); Sun, 2 Jun 2019 12:52:12 -0400 Received: from sonic310-30.consmr.mail.ne1.yahoo.com ([66.163.186.211]:43676 "EHLO sonic310-30.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726952AbfFBQwL (ORCPT ); Sun, 2 Jun 2019 12:52:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494330; bh=nhyQ5HEMViXMwzj11P6PbXR0lPC7xmZwGngBq91che4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=GlmiNJBbrRNxNsIQZdKDNahk0ZrLgz8Yxy7X9wdFZtgWpBqKgWfcR585Egcvxr4IYr1p+BzG7BJkL6Tas0+5o2NBJD/kqE6rOtx3lKvSKjN+VjeGX7npnwTPAvFD/07MjV4NeamvL0koCcUu/6ArtzcJDfUN3NgBUq5RjFrH3c4QvGmmAGM1C5B5e8iSINYtNzgpnSiF5wFfT0dM7iyu41Ndsg2DaQho5OPrXppeUnOfeeMC78yrlhncWgnxbT4KxWGwhcWY7i9bj05mXGrSORmyXpICH/QpE0EXulWkWkh3mjAubQyaMcriiSTffPhL+cRt2J1tTxEArHQn0xrKbA== X-YMail-OSG: 1lIHSD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aIsHYAhsVvEYobANMBgWS2.Lat04 AaNZCT9BJMVGBpAztyUiUZou_UpjOW1YlhGYMau5jXJ6IX4H.cElsDXy_Ncdpbrs73Nn_ub3CgpH BWqDphD3LuAEgo.sIAzMffJleWIiOLJmUSWRZw33zsXQLWFu.izgXQ6FVuIlL0FmPvnRDYEruSue 7o9JK2nMyB5ilg2BW2JMjwLQYjUImMfxRYmqkQTek78iEjcgAJ6PZHaD112qr9CQ- Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:52:10 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp423.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID fe9f27128ba4a09bc4aa17914eac4de2; Sun, 02 Jun 2019 16:52:05 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 16/58] LSM: Use lsm_export in security_secctx_to_secid Date: Sun, 2 Jun 2019 09:50:19 -0700 Message-Id: <20190602165101.25079-17-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_secctx_to_secid to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/security.h | 5 +++-- kernel/cred.c | 4 +--- net/netfilter/nft_meta.c | 4 +++- net/netfilter/xt_SECMARK.c | 5 +++-- net/netlabel/netlabel_unlabeled.c | 8 ++++++-- security/security.c | 11 ++++------- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index e3f5c61b9b2c..991d2d2e290e 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -437,7 +437,8 @@ int security_setprocattr(const char *lsm, const char *name, void *value, int security_netlink_send(struct sock *sk, struct sk_buff *skb); int security_ismaclabel(const char *name); int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen); -int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid); +int security_secctx_to_secid(const char *secdata, u32 seclen, + struct lsm_export *l); void security_release_secctx(char *secdata, u32 seclen); void security_inode_invalidate_secctx(struct inode *inode); @@ -1220,7 +1221,7 @@ static inline int security_secid_to_secctx(u32 secid, char **secdata, u32 *secle static inline int security_secctx_to_secid(const char *secdata, u32 seclen, - u32 *secid) + struct lsm_export *l) { return -EOPNOTSUPP; } diff --git a/kernel/cred.c b/kernel/cred.c index 40a3fde22667..7792538b1ca6 100644 --- a/kernel/cred.c +++ b/kernel/cred.c @@ -725,14 +725,12 @@ EXPORT_SYMBOL(set_security_override); int set_security_override_from_ctx(struct cred *new, const char *secctx) { struct lsm_export le; - u32 secid; int ret; - ret = security_secctx_to_secid(secctx, strlen(secctx), &secid); + ret = security_secctx_to_secid(secctx, strlen(secctx), &le); if (ret < 0) return ret; - lsm_export_to_all(&le, secid); return set_security_override(new, &le); } EXPORT_SYMBOL(set_security_override_from_ctx); diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c index 987d2d6ce624..598bea8e4799 100644 --- a/net/netfilter/nft_meta.c +++ b/net/netfilter/nft_meta.c @@ -576,13 +576,15 @@ static const struct nla_policy nft_secmark_policy[NFTA_SECMARK_MAX + 1] = { static int nft_secmark_compute_secid(struct nft_secmark *priv) { + struct lsm_export le; u32 tmp_secid = 0; int err; - err = security_secctx_to_secid(priv->ctx, strlen(priv->ctx), &tmp_secid); + err = security_secctx_to_secid(priv->ctx, strlen(priv->ctx), &le); if (err) return err; + lsm_export_secid(&le, &tmp_secid); if (!tmp_secid) return -ENOENT; diff --git a/net/netfilter/xt_SECMARK.c b/net/netfilter/xt_SECMARK.c index f16202d26c20..2def8d8898e6 100644 --- a/net/netfilter/xt_SECMARK.c +++ b/net/netfilter/xt_SECMARK.c @@ -49,13 +49,13 @@ secmark_tg(struct sk_buff *skb, const struct xt_action_param *par) static int checkentry_lsm(struct xt_secmark_target_info *info) { + struct lsm_export le; int err; info->secctx[SECMARK_SECCTX_MAX - 1] = '\0'; info->secid = 0; - err = security_secctx_to_secid(info->secctx, strlen(info->secctx), - &info->secid); + err = security_secctx_to_secid(info->secctx, strlen(info->secctx), &le); if (err) { if (err == -EINVAL) pr_info_ratelimited("invalid security context \'%s\'\n", @@ -63,6 +63,7 @@ static int checkentry_lsm(struct xt_secmark_target_info *info) return err; } + lsm_export_secid(&le, &info->secid); if (!info->secid) { pr_info_ratelimited("unable to map security context \'%s\'\n", info->secctx); diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c index c92894c3e40a..fc38934ccb35 100644 --- a/net/netlabel/netlabel_unlabeled.c +++ b/net/netlabel/netlabel_unlabeled.c @@ -896,6 +896,7 @@ static int netlbl_unlabel_staticadd(struct sk_buff *skb, void *mask; u32 addr_len; u32 secid; + struct lsm_export le; struct netlbl_audit audit_info; /* Don't allow users to add both IPv4 and IPv6 addresses for a @@ -919,10 +920,11 @@ static int netlbl_unlabel_staticadd(struct sk_buff *skb, ret_val = security_secctx_to_secid( nla_data(info->attrs[NLBL_UNLABEL_A_SECCTX]), nla_len(info->attrs[NLBL_UNLABEL_A_SECCTX]), - &secid); + &le); if (ret_val != 0) return ret_val; + lsm_export_secid(&le, &secid); return netlbl_unlhsh_add(&init_net, dev_name, addr, mask, addr_len, secid, &audit_info); @@ -947,6 +949,7 @@ static int netlbl_unlabel_staticadddef(struct sk_buff *skb, void *mask; u32 addr_len; u32 secid; + struct lsm_export le; struct netlbl_audit audit_info; /* Don't allow users to add both IPv4 and IPv6 addresses for a @@ -968,10 +971,11 @@ static int netlbl_unlabel_staticadddef(struct sk_buff *skb, ret_val = security_secctx_to_secid( nla_data(info->attrs[NLBL_UNLABEL_A_SECCTX]), nla_len(info->attrs[NLBL_UNLABEL_A_SECCTX]), - &secid); + &le); if (ret_val != 0) return ret_val; + lsm_export_secid(&le, &secid); return netlbl_unlhsh_add(&init_net, NULL, addr, mask, addr_len, secid, &audit_info); diff --git a/security/security.c b/security/security.c index d8300a6400c3..868e9ae6b48c 100644 --- a/security/security.c +++ b/security/security.c @@ -1967,14 +1967,11 @@ int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) } EXPORT_SYMBOL(security_secid_to_secctx); -int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid) +int security_secctx_to_secid(const char *secdata, u32 seclen, + struct lsm_export *l) { - struct lsm_export data = { .flags = LSM_EXPORT_NONE }; - int rc; - - rc = call_int_hook(secctx_to_secid, 0, secdata, seclen, &data); - lsm_export_secid(&data, secid); - return rc; + lsm_export_init(l); + return call_int_hook(secctx_to_secid, 0, secdata, seclen, l); } EXPORT_SYMBOL(security_secctx_to_secid); From patchwork Sun Jun 2 16:50:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971865 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7C12C17DF for ; Sun, 2 Jun 2019 16:52:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6ABDB1FF40 for ; Sun, 2 Jun 2019 16:52:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F09528703; Sun, 2 Jun 2019 16:52:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C908286E4 for ; Sun, 2 Jun 2019 16:52:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726957AbfFBQwN (ORCPT ); Sun, 2 Jun 2019 12:52:13 -0400 Received: from sonic303-27.consmr.mail.ne1.yahoo.com ([66.163.188.153]:46377 "EHLO sonic303-27.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726956AbfFBQwN (ORCPT ); Sun, 2 Jun 2019 12:52:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494331; bh=7li7tkNnxiLkHtu/0oyIewmS2h9OYS5xrTRq2nlRU0I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=tSjdUew1bRwz3B+HjrUcXbAXD03epnx4ioLkDRlydvfcs31Ifvi2OSTKwUHLUWbOcdZabzm5lJy9L7wNLPFCocZpfOdYcv90f1m1B6CHaVQHpQ1JLz7RoAIEeT193FGaMsTiVRvZqLbIkuHy1mhwQOQR6Zsg+ZM0FwIwW/J9QO7odDnIJTyWfq/NcqtskLlpzyYjQEeYTIj7IjpncelyfkCRMZI7Ks0orTI3mp1HlDwkte+2Y0znp9v9waXDga4K9A9SPVme63Zv6z9rMlQG3RziYaj5gPjesaFgY5y2FVZFgmVQMRzDVn/b6zGm1JHdxe6tDeF+qJ9gTkqMNC8HDQ== X-YMail-OSG: t2EWdUcVM1mPDqAkvz9CMsuJx7DAiUxhdyfRvpX7P5Ur_jcH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e6TDN0neYmCE28uuHYIBO3.Nzzu oBoaYtS_SNZg7hSTJSoRHah2mwk0S4PpmAuZg5NilYZnoIKf2PzzC0z7rFCrnU_zhucymFRlrCKm tzoQLrw.WSBJQmOXCPtKFy8V6wGwDG2qY.ZM741KafBQRmLz31uaGkqoAPiatHrO7IYRBEjVjv1Y 8k5oU5ccU1wJPuP.FDenyoXspgUj1H5V9Z.xuge.pUIY9_Ds- Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:52:11 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp423.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID fe9f27128ba4a09bc4aa17914eac4de2; Sun, 02 Jun 2019 16:52:06 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 17/58] LSM: Use lsm_export in security_secid_to_secctx Date: Sun, 2 Jun 2019 09:50:20 -0700 Message-Id: <20190602165101.25079-18-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_secid_to_secctx to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- drivers/android/binder.c | 4 +++- include/linux/security.h | 9 +++++++-- include/net/scm.h | 4 +--- kernel/audit.c | 9 +++++++-- kernel/auditsc.c | 13 +++++++++---- net/ipv4/ip_sockglue.c | 5 ++--- net/netfilter/nf_conntrack_netlink.c | 8 ++++++-- net/netfilter/nf_conntrack_standalone.c | 4 +++- net/netfilter/nfnetlink_queue.c | 8 ++++++-- net/netlabel/netlabel_unlabeled.c | 18 ++++++++++++++---- net/netlabel/netlabel_user.c | 6 +++--- net/unix/af_unix.c | 9 ++++++--- security/security.c | 8 ++------ 13 files changed, 69 insertions(+), 36 deletions(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 8685882da64c..9119333f794b 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -3120,9 +3120,11 @@ static void binder_transaction(struct binder_proc *proc, if (target_node && target_node->txn_security_ctx) { u32 secid; + struct lsm_export le; security_task_getsecid(proc->tsk, &secid); - ret = security_secid_to_secctx(secid, &secctx, &secctx_sz); + lsm_export_to_all(&le, secid); + ret = security_secid_to_secctx(&le, &secctx, &secctx_sz); if (ret) { return_error = BR_FAILED_REPLY; return_error_param = ret; diff --git a/include/linux/security.h b/include/linux/security.h index 991d2d2e290e..5cea6260bbd9 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -115,6 +115,10 @@ static inline void lsm_export_secid(struct lsm_export *data, u32 *secid) case LSM_EXPORT_APPARMOR: *secid = data->apparmor; break; + case LSM_EXPORT_SELINUX | LSM_EXPORT_SMACK | LSM_EXPORT_APPARMOR: + /* For scaffolding only */ + *secid = data->selinux; + break; default: pr_warn("%s flags=0x%u - not a valid set\n", __func__, data->flags); @@ -436,7 +440,7 @@ int security_setprocattr(const char *lsm, const char *name, void *value, size_t size); int security_netlink_send(struct sock *sk, struct sk_buff *skb); int security_ismaclabel(const char *name); -int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen); +int security_secid_to_secctx(struct lsm_export *l, char **secdata, u32 *seclen); int security_secctx_to_secid(const char *secdata, u32 seclen, struct lsm_export *l); void security_release_secctx(char *secdata, u32 seclen); @@ -1214,7 +1218,8 @@ static inline int security_ismaclabel(const char *name) return 0; } -static inline int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) +static inline int security_secid_to_secctx(struct lsm_export *l, + char **secdata, u32 *seclen) { return -EOPNOTSUPP; } diff --git a/include/net/scm.h b/include/net/scm.h index 13b8a369fd89..b5d1c24318e3 100644 --- a/include/net/scm.h +++ b/include/net/scm.h @@ -33,7 +33,6 @@ struct scm_cookie { struct scm_fp_list *fp; /* Passed files */ struct scm_creds creds; /* Skb credentials */ #ifdef CONFIG_SECURITY_NETWORK - u32 secid; /* Passed security ID */ struct lsm_export le; /* Passed LSM data */ #endif }; @@ -48,7 +47,6 @@ struct scm_fp_list *scm_fp_dup(struct scm_fp_list *fpl); static __inline__ void unix_get_peersec_dgram(struct socket *sock, struct scm_cookie *scm) { security_socket_getpeersec_dgram(sock, NULL, &scm->le); - lsm_export_secid(&scm->le, &scm->secid); } #else static __inline__ void unix_get_peersec_dgram(struct socket *sock, struct scm_cookie *scm) @@ -99,7 +97,7 @@ static inline void scm_passec(struct socket *sock, struct msghdr *msg, struct sc int err; if (test_bit(SOCK_PASSSEC, &sock->flags)) { - err = security_secid_to_secctx(scm->secid, &secdata, &seclen); + err = security_secid_to_secctx(&scm->le, &secdata, &seclen); if (!err) { put_cmsg(msg, SOL_SOCKET, SCM_SECURITY, seclen, secdata); diff --git a/kernel/audit.c b/kernel/audit.c index c89ea48c70a6..b5d96a0320fb 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -1430,7 +1430,10 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) case AUDIT_SIGNAL_INFO: len = 0; if (audit_sig_sid) { - err = security_secid_to_secctx(audit_sig_sid, &ctx, &len); + struct lsm_export le; + + lsm_export_to_all(&le, audit_sig_sid); + err = security_secid_to_secctx(&le, &ctx, &len); if (err) return err; } @@ -2073,12 +2076,14 @@ int audit_log_task_context(struct audit_buffer *ab) unsigned len; int error; u32 sid; + struct lsm_export le; security_task_getsecid(current, &sid); if (!sid) return 0; - error = security_secid_to_secctx(sid, &ctx, &len); + lsm_export_to_all(&le, sid); + error = security_secid_to_secctx(&le, &ctx, &len); if (error) { if (error != -EINVAL) goto error_path; diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 822ba35e4e64..83aba0336eac 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -946,6 +946,7 @@ static int audit_log_pid_context(struct audit_context *context, pid_t pid, char *ctx = NULL; u32 len; int rc = 0; + struct lsm_export le; ab = audit_log_start(context, GFP_KERNEL, AUDIT_OBJ_PID); if (!ab) @@ -955,7 +956,8 @@ static int audit_log_pid_context(struct audit_context *context, pid_t pid, from_kuid(&init_user_ns, auid), from_kuid(&init_user_ns, uid), sessionid); if (sid) { - if (security_secid_to_secctx(sid, &ctx, &len)) { + lsm_export_to_all(&le, sid); + if (security_secid_to_secctx(&le, &ctx, &len)) { audit_log_format(ab, " obj=(none)"); rc = 1; } else { @@ -1197,7 +1199,9 @@ static void show_special(struct audit_context *context, int *call_panic) if (osid) { char *ctx = NULL; u32 len; - if (security_secid_to_secctx(osid, &ctx, &len)) { + struct lsm_export le; + lsm_export_to_all(&le, osid); + if (security_secid_to_secctx(&le, &ctx, &len)) { audit_log_format(ab, " osid=%u", osid); *call_panic = 1; } else { @@ -1348,9 +1352,10 @@ static void audit_log_name(struct audit_context *context, struct audit_names *n, if (n->osid != 0) { char *ctx = NULL; u32 len; + struct lsm_export le; - if (security_secid_to_secctx( - n->osid, &ctx, &len)) { + lsm_export_to_all(&le, n->osid); + if (security_secid_to_secctx(&le, &ctx, &len)) { audit_log_format(ab, " osid=%u", n->osid); if (call_panic) *call_panic = 2; diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c index b8ef7677a7e5..a4f37ba6dbe2 100644 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c @@ -132,15 +132,14 @@ static void ip_cmsg_recv_security(struct msghdr *msg, struct sk_buff *skb) { struct lsm_export le; char *secdata; - u32 seclen, secid; + u32 seclen; int err; err = security_socket_getpeersec_dgram(NULL, skb, &le); if (err) return; - lsm_export_secid(&le, &secid); - err = security_secid_to_secctx(secid, &secdata, &seclen); + err = security_secid_to_secctx(&le, &secdata, &seclen); if (err) return; diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c index 66c596d287a5..b069277450c5 100644 --- a/net/netfilter/nf_conntrack_netlink.c +++ b/net/netfilter/nf_conntrack_netlink.c @@ -330,8 +330,10 @@ static int ctnetlink_dump_secctx(struct sk_buff *skb, const struct nf_conn *ct) struct nlattr *nest_secctx; int len, ret; char *secctx; + struct lsm_export le; - ret = security_secid_to_secctx(ct->secmark, &secctx, &len); + lsm_export_to_all(&le, ct->secmark); + ret = security_secid_to_secctx(&le, &secctx, &len); if (ret) return 0; @@ -615,8 +617,10 @@ static inline int ctnetlink_secctx_size(const struct nf_conn *ct) { #ifdef CONFIG_NF_CONNTRACK_SECMARK int len, ret; + struct lsm_export le; - ret = security_secid_to_secctx(ct->secmark, NULL, &len); + lsm_export_to_all(&le, ct->secmark); + ret = security_secid_to_secctx(&le, NULL, &len); if (ret) return 0; diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c index c2ae14c720b4..12318026d8d4 100644 --- a/net/netfilter/nf_conntrack_standalone.c +++ b/net/netfilter/nf_conntrack_standalone.c @@ -175,8 +175,10 @@ static void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) int ret; u32 len; char *secctx; + struct lsm_export le; - ret = security_secid_to_secctx(ct->secmark, &secctx, &len); + lsm_export_to_all(&le, ct->secmark); + ret = security_secid_to_secctx(&le, &secctx, &len); if (ret) return; diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index 0dcc3592d053..4c74c383e26b 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c @@ -309,13 +309,17 @@ static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, char **secdata) { u32 seclen = 0; #if IS_ENABLED(CONFIG_NETWORK_SECMARK) + struct lsm_export le; + if (!skb || !sk_fullsock(skb->sk)) return 0; read_lock_bh(&skb->sk->sk_callback_lock); - if (skb->secmark) - security_secid_to_secctx(skb->secmark, secdata, &seclen); + if (skb->secmark) { + lsm_export_to_all(&le, skb->secmark); + security_secid_to_secctx(&le, secdata, &seclen); + } read_unlock_bh(&skb->sk->sk_callback_lock); #endif diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c index fc38934ccb35..00922f55dd9e 100644 --- a/net/netlabel/netlabel_unlabeled.c +++ b/net/netlabel/netlabel_unlabeled.c @@ -389,6 +389,7 @@ int netlbl_unlhsh_add(struct net *net, struct audit_buffer *audit_buf = NULL; char *secctx = NULL; u32 secctx_len; + struct lsm_export le; if (addr_len != sizeof(struct in_addr) && addr_len != sizeof(struct in6_addr)) @@ -451,7 +452,8 @@ int netlbl_unlhsh_add(struct net *net, unlhsh_add_return: rcu_read_unlock(); if (audit_buf != NULL) { - if (security_secid_to_secctx(secid, + lsm_export_to_all(&le, secid); + if (security_secid_to_secctx(&le, &secctx, &secctx_len) == 0) { audit_log_format(audit_buf, " sec_obj=%s", secctx); @@ -488,6 +490,7 @@ static int netlbl_unlhsh_remove_addr4(struct net *net, struct net_device *dev; char *secctx; u32 secctx_len; + struct lsm_export le; spin_lock(&netlbl_unlhsh_lock); list_entry = netlbl_af4list_remove(addr->s_addr, mask->s_addr, @@ -507,8 +510,10 @@ static int netlbl_unlhsh_remove_addr4(struct net *net, addr->s_addr, mask->s_addr); if (dev != NULL) dev_put(dev); + if (entry != NULL) + lsm_export_to_all(&le, entry->secid); if (entry != NULL && - security_secid_to_secctx(entry->secid, + security_secid_to_secctx(&le, &secctx, &secctx_len) == 0) { audit_log_format(audit_buf, " sec_obj=%s", secctx); security_release_secctx(secctx, secctx_len); @@ -550,6 +555,7 @@ static int netlbl_unlhsh_remove_addr6(struct net *net, struct net_device *dev; char *secctx; u32 secctx_len; + struct lsm_export le; spin_lock(&netlbl_unlhsh_lock); list_entry = netlbl_af6list_remove(addr, mask, &iface->addr6_list); @@ -568,8 +574,10 @@ static int netlbl_unlhsh_remove_addr6(struct net *net, addr, mask); if (dev != NULL) dev_put(dev); + if (entry != NULL) + lsm_export_to_all(&le, entry->secid); if (entry != NULL && - security_secid_to_secctx(entry->secid, + security_secid_to_secctx(&le, &secctx, &secctx_len) == 0) { audit_log_format(audit_buf, " sec_obj=%s", secctx); security_release_secctx(secctx, secctx_len); @@ -1092,6 +1100,7 @@ static int netlbl_unlabel_staticlist_gen(u32 cmd, u32 secid; char *secctx; u32 secctx_len; + struct lsm_export le; data = genlmsg_put(cb_arg->skb, NETLINK_CB(cb_arg->nl_cb->skb).portid, cb_arg->seq, &netlbl_unlabel_gnl_family, @@ -1146,7 +1155,8 @@ static int netlbl_unlabel_staticlist_gen(u32 cmd, secid = addr6->secid; } - ret_val = security_secid_to_secctx(secid, &secctx, &secctx_len); + lsm_export_to_all(&le, secid); + ret_val = security_secid_to_secctx(&le, &secctx, &secctx_len); if (ret_val != 0) goto list_cb_failure; ret_val = nla_put(cb_arg->skb, diff --git a/net/netlabel/netlabel_user.c b/net/netlabel/netlabel_user.c index 4676f5bb16ae..1079cdea872c 100644 --- a/net/netlabel/netlabel_user.c +++ b/net/netlabel/netlabel_user.c @@ -100,6 +100,7 @@ struct audit_buffer *netlbl_audit_start_common(int type, struct audit_buffer *audit_buf; char *secctx; u32 secctx_len; + struct lsm_export le; if (audit_enabled == AUDIT_OFF) return NULL; @@ -112,10 +113,9 @@ struct audit_buffer *netlbl_audit_start_common(int type, from_kuid(&init_user_ns, audit_info->loginuid), audit_info->sessionid); + lsm_export_to_all(&le, audit_info->secid); if (audit_info->secid != 0 && - security_secid_to_secctx(audit_info->secid, - &secctx, - &secctx_len) == 0) { + security_secid_to_secctx(&le, &secctx, &secctx_len) == 0) { audit_log_format(audit_buf, " subj=%s", secctx); security_release_secctx(secctx, secctx_len); } diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index ddb838a1b74c..4d4107927ba2 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -143,17 +143,20 @@ static struct hlist_head *unix_sockets_unbound(void *addr) #ifdef CONFIG_SECURITY_NETWORK static void unix_get_secdata(struct scm_cookie *scm, struct sk_buff *skb) { - UNIXCB(skb).secid = scm->secid; + lsm_export_secid(&scm->le, &(UNIXCB(skb).secid)); } static inline void unix_set_secdata(struct scm_cookie *scm, struct sk_buff *skb) { - scm->secid = UNIXCB(skb).secid; + lsm_export_to_all(&scm->le, UNIXCB(skb).secid); } static inline bool unix_secdata_eq(struct scm_cookie *scm, struct sk_buff *skb) { - return (scm->secid == UNIXCB(skb).secid); + u32 best_secid; + + lsm_export_secid(&scm->le, &best_secid); + return (best_secid == UNIXCB(skb).secid); } #else static inline void unix_get_secdata(struct scm_cookie *scm, struct sk_buff *skb) diff --git a/security/security.c b/security/security.c index 868e9ae6b48c..b6a096be95ac 100644 --- a/security/security.c +++ b/security/security.c @@ -1957,13 +1957,9 @@ int security_ismaclabel(const char *name) } EXPORT_SYMBOL(security_ismaclabel); -int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) +int security_secid_to_secctx(struct lsm_export *l, char **secdata, u32 *seclen) { - struct lsm_export data; - - lsm_export_to_all(&data, secid); - return call_int_hook(secid_to_secctx, -EOPNOTSUPP, &data, secdata, - seclen); + return call_int_hook(secid_to_secctx, -EOPNOTSUPP, l, secdata, seclen); } EXPORT_SYMBOL(security_secid_to_secctx); From patchwork Sun Jun 2 16:50:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971863 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5C40F17DF for ; Sun, 2 Jun 2019 16:52:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D71D1FF40 for ; Sun, 2 Jun 2019 16:52:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41D7628A08; Sun, 2 Jun 2019 16:52:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D44CC28703 for ; Sun, 2 Jun 2019 16:52:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726949AbfFBQwM (ORCPT ); Sun, 2 Jun 2019 12:52:12 -0400 Received: from sonic303-27.consmr.mail.ne1.yahoo.com ([66.163.188.153]:39521 "EHLO sonic303-27.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726958AbfFBQwM (ORCPT ); Sun, 2 Jun 2019 12:52:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494331; bh=affcoRY2PaaUmEgcqS6C9HybTLSyjRteSCEEdycSbI0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=H3B65eLcQdW5ThivYODY2ixkPmLegalA9QHXVkxATe9EEX2EtccpAdi5fdo/lGYfl0QsEWF9A5jcWHxDGo7dpB/XulENPi+7sakxvcNyseaFqd+ipW9AO3HOfVZEeaxUabeRRSHTKulnhhSeKZwqEve5DQxMDKUg3KHTFMbwZ2Dl0Ul7/QOFqWIu/0nsMr5+7ivEqHZgjtiPCg6jGCw4l2g5IjiT7PwlSb6oa7x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9cqHOHDxb7lY JcgiL9hqvVPcnvSG.aheweGhaL4hPe1mxIQIRadwT6ocLQNRxpTqplN91Srsy9wFOBmO7unI3x6R IQnd0lVFaAk4lQydRVEt8FlBCEo9tRulb8rwTNxQW5AKFDBeaXVzsGn58AIyi88TgyVhNEDmiFm4 ZaylV87mozqj2EtWVge9._XPSf4zSYYRHr6QhSuOI46ve3mJ5JWjPrlMcjsDySzx55ys1F0t8vdL i23FIdesTzruaqgY8wgC69E.JAHJIewXyteHahq5zs_qbbXeKsz7fk8jpXYqIPsdjI4tomRW2kw6 TfstI7pQSp2EFFjoDrOEVG5AXgGn9e9_1u091gOFPJKqlz4WnZoh_ANs060o- Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:52:11 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp423.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID fe9f27128ba4a09bc4aa17914eac4de2; Sun, 02 Jun 2019 16:52:06 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 18/58] LSM: Use lsm_export in security_ipc_getsecid Date: Sun, 2 Jun 2019 09:50:21 -0700 Message-Id: <20190602165101.25079-19-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_ipc_getsecid to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/security.h | 7 ++++--- kernel/auditsc.c | 4 +++- security/security.c | 8 +++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 5cea6260bbd9..6ac48c7c4a41 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -411,7 +411,7 @@ int security_task_prctl(int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5); void security_task_to_inode(struct task_struct *p, struct inode *inode); int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag); -void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid); +void security_ipc_getsecid(struct kern_ipc_perm *ipcp, struct lsm_export *l); int security_msg_msg_alloc(struct msg_msg *msg); void security_msg_msg_free(struct msg_msg *msg); int security_msg_queue_alloc(struct kern_ipc_perm *msq); @@ -1096,9 +1096,10 @@ static inline int security_ipc_permission(struct kern_ipc_perm *ipcp, return 0; } -static inline void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid) +static inline void security_ipc_getsecid(struct kern_ipc_perm *ipcp, + struct lsm_export *l) { - *secid = 0; + lsm_export_init(l); } static inline int security_msg_msg_alloc(struct msg_msg *msg) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 83aba0336eac..eabbf78fee96 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2266,11 +2266,13 @@ void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat) void __audit_ipc_obj(struct kern_ipc_perm *ipcp) { struct audit_context *context = audit_context(); + struct lsm_export le; context->ipc.uid = ipcp->uid; context->ipc.gid = ipcp->gid; context->ipc.mode = ipcp->mode; context->ipc.has_perm = 0; - security_ipc_getsecid(ipcp, &context->ipc.osid); + security_ipc_getsecid(ipcp, &le); + lsm_export_secid(&le, &context->ipc.osid); context->type = AUDIT_IPC; } diff --git a/security/security.c b/security/security.c index b6a096be95ac..6ba1187c9655 100644 --- a/security/security.c +++ b/security/security.c @@ -1775,12 +1775,10 @@ int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag) return call_int_hook(ipc_permission, 0, ipcp, flag); } -void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid) +void security_ipc_getsecid(struct kern_ipc_perm *ipcp, struct lsm_export *l) { - struct lsm_export data = { .flags = LSM_EXPORT_NONE }; - - call_void_hook(ipc_getsecid, ipcp, &data); - lsm_export_secid(&data, secid); + lsm_export_init(l); + call_void_hook(ipc_getsecid, ipcp, l); } int security_msg_msg_alloc(struct msg_msg *msg) From patchwork Sun Jun 2 16:50:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971857 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EAE3D13AD for ; Sun, 2 Jun 2019 16:52:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC1852873A for ; Sun, 2 Jun 2019 16:52:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0149289FA; Sun, 2 Jun 2019 16:52:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01C7728703 for ; Sun, 2 Jun 2019 16:52:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726950AbfFBQwM (ORCPT ); Sun, 2 Jun 2019 12:52:12 -0400 Received: from sonic317-38.consmr.mail.ne1.yahoo.com ([66.163.184.49]:43678 "EHLO sonic317-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726949AbfFBQwM (ORCPT ); Sun, 2 Jun 2019 12:52:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494329; bh=rnYFo5ZRZDk+OWS44zRZyocobFLx6h6kqTHu/9Enlaw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=YCJfnEJq+vp8Qa0CuFmQ5KLjV94mLMvKWuKH0PrJE1GXZ0UKBYWWESJd/PG0COylTWeGNh1ERSs/VP7Vj0d4hJKuDqciy/ZTMMeOtLlbr7X5vPOvopMATRNjTS3pqL+wgdx+hetv+VJ9cllkipbeLIG3jBM742pdZMTH/zwhHiVU750PHb3BMX5scpt29RMiv2xmWWWqCWQR8Mf/rOv9CAkpR61G3JwL+5L9ZKIRgIgPYwtJtEExTARokGY5NMi8jjCeS4yssq0axswWqf4ldtx89XUVTjIRu0eio5S+Hlp5xoDKgPBKHVoU4oiKqBwmlMODMXNt7I258OM20sIuVg== X-YMail-OSG: s36hTBoVM1kwVu1145uge3hJ9u5k7Qm51oo_gTEkI9mKOZPzl1bocUTZfrcYkUo LxqmJH86TnwjT0Q_lGbllhsdOgI2Cg4CHlkX7OBhi4b8F1HFP1RgFsDSP.a6idPsDrFecdsR6mh0 f47iaeaeGcEDIzWkNHue9I_QnyVg2otfpjU8AcBiUlCYu31jAIbymkB1S66QDvbreQ0RSjR4KR7C ES2LVBTTT5S6m1lvtBuzrx0EAdEQAmLU.P5i_PCxKSKj.WVGQ6STY8Z4mZNamXpgBYotnk_V974h NNZgaLbL3ugkTMpUuQtWLTVg9Oy.MnelMLFyiEqEArbKopiBhUAqMhpjrt0XdXn0YJGfkplXpToN SKnOx.OrJZMwu2mf6r7_rN6fhFje6Y.XlQ49ccRdUBVfrWL9k.ihN.sjlgl.uUDZ6GBmULTy9_qr wDwiEKZTBZjhUT9SSBj04OxFYyfHNKOBh2DnPSZwKl1W8PwxU.LLiLzXzKnuxnQvzZpZFNBEKZyj DbEQIj3b2ing5aZSps4EwGH7GRakxelotnKCM7z2DlQi9uKBFvn3Hjl3q80FzPCmueCnCfGoezsO VSsBksVuyoSx4n7gNj_v9Fo2Wo6jNbjlqXQBMQVZUQVpjWArGI0RlpLFCkUw68uafUO3dxEOJW1Z 5nWy5HKGoonk.N5TWeCM3oick5Pl20TLAWhIhedC.O1mI6i7nunMcqYRnNsmyRPuLZ7CFYQunxs4 yAUR2a5rOefAhbpBvJod2ruou53q.AvZ5zP8DL4PWnlJ2RhTM4nS0avKKh9Yfbli7CU_MDOVpy7b d43pF9vJnicihL9uojrKxWKxtcAWxxA55ff4oQlZ.FuVl.LoZ5dNg_30EhscD65nQ_IZgZttejya CeBtsl0zJ4lM651w4pJkbBxEdFel_o0rw6RWUKyqzOSnJV15bGPVgjiKePIFcxFks_BNkkllj47t FuA2Mg.r45KKUDY.eITGMSnZxmuVoYVuzn6ZLMBmNem_UyuY7SclLyJk4Ax0bqzWVrXn6fnCdvgC pnSEKPp6n0xMcEZyJYzztu47Y86ZPpXpA1iyd06h02aVFFk.rDU6YyzDUMkrZmCb1smZnlU8._Be J8MqhJXBXZMVdhphAwv.v_M91wFD58snUkR00v8p5OCKV91Kw4wo0xI.OmGbaMJWporx3sycr9U4 mg0qVEzU.PE8Xz5Y3._88uy3nsizGZmUopXmuKeC5uhTbm6RvJLMkzOMVdq_cyYwHH..WGrBHT7y ATMBwZVN9g9ZLV2eMj9PiFajnqqqz6ZVxSq1_GWfP_aIgelix4cb0GQ-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:52:09 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp423.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID fe9f27128ba4a09bc4aa17914eac4de2; Sun, 02 Jun 2019 16:52:07 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 19/58] LSM: Use lsm_export in security_task_getsecid Date: Sun, 2 Jun 2019 09:50:22 -0700 Message-Id: <20190602165101.25079-20-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_task_getsecid to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- drivers/android/binder.c | 4 +--- include/linux/security.h | 7 ++++--- kernel/audit.c | 4 ++-- kernel/auditfilter.c | 4 +--- kernel/auditsc.c | 18 +++++++++++------- net/netlabel/netlabel_unlabeled.c | 4 +++- net/netlabel/netlabel_user.h | 5 ++++- security/integrity/ima/ima_appraise.c | 4 +++- security/integrity/ima/ima_main.c | 16 ++++++++++++---- security/security.c | 8 +++----- 10 files changed, 44 insertions(+), 30 deletions(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 9119333f794b..0eeb5b75da5b 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -3119,11 +3119,9 @@ static void binder_transaction(struct binder_proc *proc, t->priority = task_nice(current); if (target_node && target_node->txn_security_ctx) { - u32 secid; struct lsm_export le; - security_task_getsecid(proc->tsk, &secid); - lsm_export_to_all(&le, secid); + security_task_getsecid(proc->tsk, &le); ret = security_secid_to_secctx(&le, &secctx, &secctx_sz); if (ret) { return_error = BR_FAILED_REPLY; diff --git a/include/linux/security.h b/include/linux/security.h index 6ac48c7c4a41..ae4c058abc5e 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -394,7 +394,7 @@ int security_task_fix_setuid(struct cred *new, const struct cred *old, int security_task_setpgid(struct task_struct *p, pid_t pgid); int security_task_getpgid(struct task_struct *p); int security_task_getsid(struct task_struct *p); -void security_task_getsecid(struct task_struct *p, u32 *secid); +void security_task_getsecid(struct task_struct *p, struct lsm_export *l); int security_task_setnice(struct task_struct *p, int nice); int security_task_setioprio(struct task_struct *p, int ioprio); int security_task_getioprio(struct task_struct *p); @@ -1023,9 +1023,10 @@ static inline int security_task_getsid(struct task_struct *p) return 0; } -static inline void security_task_getsecid(struct task_struct *p, u32 *secid) +static inline void security_task_getsecid(struct task_struct *p, + struct lsm_export *l) { - *secid = 0; + lsm_export_init(l); } static inline int security_task_setnice(struct task_struct *p, int nice) diff --git a/kernel/audit.c b/kernel/audit.c index b5d96a0320fb..fa4c5544eb37 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -2078,11 +2078,11 @@ int audit_log_task_context(struct audit_buffer *ab) u32 sid; struct lsm_export le; - security_task_getsecid(current, &sid); + security_task_getsecid(current, &le); + lsm_export_secid(&le, &sid); if (!sid) return 0; - lsm_export_to_all(&le, sid); error = security_secid_to_secctx(&le, &ctx, &len); if (error) { if (error != -EINVAL) diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c index 15771102919d..468dac2bdce5 100644 --- a/kernel/auditfilter.c +++ b/kernel/auditfilter.c @@ -1323,7 +1323,6 @@ int audit_filter(int msgtype, unsigned int listtype) for (i = 0; i < e->rule.field_count; i++) { struct audit_field *f = &e->rule.fields[i]; pid_t pid; - u32 sid; struct lsm_export le; switch (f->type) { @@ -1354,8 +1353,7 @@ int audit_filter(int msgtype, unsigned int listtype) case AUDIT_SUBJ_SEN: case AUDIT_SUBJ_CLR: if (f->lsm_rule) { - security_task_getsecid(current, &sid); - lsm_export_to_all(&le, sid); + security_task_getsecid(current, &le); result = security_audit_rule_match(&le, f->type, f->op, f->lsm_rule); } diff --git a/kernel/auditsc.c b/kernel/auditsc.c index eabbf78fee96..b06ffcf9bb9f 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -444,7 +444,6 @@ static int audit_filter_rules(struct task_struct *tsk, { const struct cred *cred; int i, need_sid = 1; - u32 sid; struct lsm_export le; unsigned int sessionid; @@ -628,10 +627,9 @@ static int audit_filter_rules(struct task_struct *tsk, logged upon error */ if (f->lsm_rule) { if (need_sid) { - security_task_getsecid(tsk, &sid); + security_task_getsecid(tsk, &le); need_sid = 0; } - lsm_export_to_all(&le, sid); result = security_audit_rule_match(&le, f->type, f->op, f->lsm_rule); @@ -2362,12 +2360,14 @@ int __audit_sockaddr(int len, void *a) void __audit_ptrace(struct task_struct *t) { struct audit_context *context = audit_context(); + struct lsm_export le; context->target_pid = task_tgid_nr(t); context->target_auid = audit_get_loginuid(t); context->target_uid = task_uid(t); context->target_sessionid = audit_get_sessionid(t); - security_task_getsecid(t, &context->target_sid); + security_task_getsecid(t, &le); + lsm_export_secid(&le, &context->target_sid); memcpy(context->target_comm, t->comm, TASK_COMM_LEN); } @@ -2384,6 +2384,7 @@ int audit_signal_info(int sig, struct task_struct *t) struct audit_aux_data_pids *axp; struct audit_context *ctx = audit_context(); kuid_t uid = current_uid(), auid, t_uid = task_uid(t); + struct lsm_export le; if (auditd_test_task(t) && (sig == SIGTERM || sig == SIGHUP || @@ -2394,7 +2395,8 @@ int audit_signal_info(int sig, struct task_struct *t) audit_sig_uid = auid; else audit_sig_uid = uid; - security_task_getsecid(current, &audit_sig_sid); + security_task_getsecid(current, &le); + lsm_export_secid(&le, &audit_sig_sid); } if (!audit_signals || audit_dummy_context()) @@ -2407,7 +2409,8 @@ int audit_signal_info(int sig, struct task_struct *t) ctx->target_auid = audit_get_loginuid(t); ctx->target_uid = t_uid; ctx->target_sessionid = audit_get_sessionid(t); - security_task_getsecid(t, &ctx->target_sid); + security_task_getsecid(t, &le); + lsm_export_secid(&le, &ctx->target_sid); memcpy(ctx->target_comm, t->comm, TASK_COMM_LEN); return 0; } @@ -2428,7 +2431,8 @@ int audit_signal_info(int sig, struct task_struct *t) axp->target_auid[axp->pid_count] = audit_get_loginuid(t); axp->target_uid[axp->pid_count] = t_uid; axp->target_sessionid[axp->pid_count] = audit_get_sessionid(t); - security_task_getsecid(t, &axp->target_sid[axp->pid_count]); + security_task_getsecid(t, &le); + lsm_export_secid(&le, &axp->target_sid[axp->pid_count]); memcpy(axp->target_comm[axp->pid_count], t->comm, TASK_COMM_LEN); axp->pid_count++; diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c index 00922f55dd9e..7f245d593c8f 100644 --- a/net/netlabel/netlabel_unlabeled.c +++ b/net/netlabel/netlabel_unlabeled.c @@ -1554,11 +1554,13 @@ int __init netlbl_unlabel_defconf(void) int ret_val; struct netlbl_dom_map *entry; struct netlbl_audit audit_info; + struct lsm_export le; /* Only the kernel is allowed to call this function and the only time * it is called is at bootup before the audit subsystem is reporting * messages so don't worry to much about these values. */ - security_task_getsecid(current, &audit_info.secid); + security_task_getsecid(current, &le); + lsm_export_secid(&le, &audit_info.secid); audit_info.loginuid = GLOBAL_ROOT_UID; audit_info.sessionid = 0; diff --git a/net/netlabel/netlabel_user.h b/net/netlabel/netlabel_user.h index 4a397cde1a48..2dbc4276bdcc 100644 --- a/net/netlabel/netlabel_user.h +++ b/net/netlabel/netlabel_user.h @@ -48,7 +48,10 @@ static inline void netlbl_netlink_auditinfo(struct sk_buff *skb, struct netlbl_audit *audit_info) { - security_task_getsecid(current, &audit_info->secid); + struct lsm_export le; + + security_task_getsecid(current, &le); + lsm_export_secid(&le, &audit_info->secid); audit_info->loginuid = audit_get_loginuid(current); audit_info->sessionid = audit_get_sessionid(current); } diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c index 5fb7127bbe68..be714afc9fd2 100644 --- a/security/integrity/ima/ima_appraise.c +++ b/security/integrity/ima/ima_appraise.c @@ -51,11 +51,13 @@ bool is_ima_appraise_enabled(void) int ima_must_appraise(struct inode *inode, int mask, enum ima_hooks func) { u32 secid; + struct lsm_export le; if (!ima_appraise) return 0; - security_task_getsecid(current, &secid); + security_task_getsecid(current, &le); + lsm_export_secid(&le, &secid); return ima_match_policy(inode, current_cred(), secid, func, mask, IMA_APPRAISE | IMA_HASH, NULL); } diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index 357edd140c09..1e3cfaf0ee5c 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -336,9 +336,11 @@ static int process_measurement(struct file *file, const struct cred *cred, int ima_file_mmap(struct file *file, unsigned long prot) { u32 secid; + struct lsm_export le; if (file && (prot & PROT_EXEC)) { - security_task_getsecid(current, &secid); + security_task_getsecid(current, &le); + lsm_export_secid(&le, &secid); return process_measurement(file, current_cred(), secid, NULL, 0, MAY_EXEC, MMAP_CHECK); } @@ -363,8 +365,10 @@ int ima_bprm_check(struct linux_binprm *bprm) { int ret; u32 secid; + struct lsm_export le; - security_task_getsecid(current, &secid); + security_task_getsecid(current, &le); + lsm_export_secid(&le, &secid); ret = process_measurement(bprm->file, current_cred(), secid, NULL, 0, MAY_EXEC, BPRM_CHECK); if (ret) @@ -388,8 +392,10 @@ int ima_bprm_check(struct linux_binprm *bprm) int ima_file_check(struct file *file, int mask) { u32 secid; + struct lsm_export le; - security_task_getsecid(current, &secid); + security_task_getsecid(current, &le); + lsm_export_secid(&le, &secid); return process_measurement(file, current_cred(), secid, NULL, 0, mask & (MAY_READ | MAY_WRITE | MAY_EXEC | MAY_APPEND), FILE_CHECK); @@ -500,6 +506,7 @@ int ima_post_read_file(struct file *file, void *buf, loff_t size, { enum ima_hooks func; u32 secid; + struct lsm_export le; if (!file && read_id == READING_FIRMWARE) { if ((ima_appraise & IMA_APPRAISE_FIRMWARE) && @@ -521,7 +528,8 @@ int ima_post_read_file(struct file *file, void *buf, loff_t size, } func = read_idmap[read_id] ?: FILE_CHECK; - security_task_getsecid(current, &secid); + security_task_getsecid(current, &le); + lsm_export_secid(&le, &secid); return process_measurement(file, current_cred(), secid, buf, size, MAY_READ, func); } diff --git a/security/security.c b/security/security.c index 6ba1187c9655..22ea709593f3 100644 --- a/security/security.c +++ b/security/security.c @@ -1690,12 +1690,10 @@ int security_task_getsid(struct task_struct *p) return call_int_hook(task_getsid, 0, p); } -void security_task_getsecid(struct task_struct *p, u32 *secid) +void security_task_getsecid(struct task_struct *p, struct lsm_export *l) { - struct lsm_export data = { .flags = LSM_EXPORT_NONE }; - - call_void_hook(task_getsecid, p, &data); - lsm_export_secid(&data, secid); + lsm_export_init(l); + call_void_hook(task_getsecid, p, l); } EXPORT_SYMBOL(security_task_getsecid); From patchwork Sun Jun 2 16:50:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971869 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2030F18A6 for ; Sun, 2 Jun 2019 16:52:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F49D1FF40 for ; Sun, 2 Jun 2019 16:52:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0314C2873A; Sun, 2 Jun 2019 16:52:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86DFC1FF40 for ; Sun, 2 Jun 2019 16:52:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726956AbfFBQw1 (ORCPT ); Sun, 2 Jun 2019 12:52:27 -0400 Received: from sonic302-8.consmr.mail.bf2.yahoo.com ([74.6.135.47]:44844 "EHLO sonic302-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726084AbfFBQw1 (ORCPT ); Sun, 2 Jun 2019 12:52:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494345; bh=GPvWJDPXSClM26o50qIJxfLTG9C4Dy1cxsnhyj+//zw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=BsjqrDscnkX10X+9vdFINt+Qqxxd3DhvWRMczJg0O5F7lWdNnNgCU+pxvrnShGVoHJApULUCMZbU4kr/of44TPh6wwuADAtHpOWxl/jq8cCBAVsOTG5ERVjY31yxa/WwPxzz8GbYbOkfRGvNYCLhF350N1vKigBKkWclhk8juL6WV7jt12dmybmuvODITAuVzFnIOhapzV22vn6KtmVpTSgwzZi+2MXFW1ZYp+6cHeG1CRJZGVf4sbqJOSBGhW+fKG2lQERUfDRHIAVn3EWm/fV4uH4vodg6tBmE9TCu8SYTFaUyu2rPa2hR8UM/G0VmV5OqntUFcvRQXDRFUwEBaw== X-YMail-OSG: P61FTtQVM1l6Kw8KHRZD04agvBf.51QU..DOS41thBcGghX3dKIJmMddR_9Cyop mYEwnxCp5yE3YRysRuQAEeL8WZgnmlr2wzaolMwfbq_E6xcnbb0o72XPVQdcFRfIW_gQBQsWgt.Y gBYSpoi8rJQuidRbK2ZXL8ooVWueKs.o6qI1I7YzVxZqxz77thmGBcYKiH1Q4CyO0zqNgcH3LLQA 3eBKNG7jUUh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6I5KLgXsjskkhLSjgd0o2mOpFje0CLsPOAntybCtvGLZ5Zg- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:52:25 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp403.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID f0b498552947f6b5133c1cce9fc77f09; Sun, 02 Jun 2019 16:52:20 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 20/58] LSM: Use lsm_export in security_inode_getsecid Date: Sun, 2 Jun 2019 09:50:23 -0700 Message-Id: <20190602165101.25079-21-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_inode_getsecid to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/security.h | 7 ++++--- kernel/auditsc.c | 5 ++++- security/integrity/ima/ima_policy.c | 4 +--- security/security.c | 8 +++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index ae4c058abc5e..2d04687c3fa9 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -356,7 +356,7 @@ int security_inode_killpriv(struct dentry *dentry); int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc); int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags); int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size); -void security_inode_getsecid(struct inode *inode, u32 *secid); +void security_inode_getsecid(struct inode *inode, struct lsm_export *l); int security_inode_copy_up(struct dentry *src, struct cred **new); int security_inode_copy_up_xattr(const char *name); int security_file_permission(struct file *file, int mask); @@ -852,9 +852,10 @@ static inline int security_inode_listsecurity(struct inode *inode, char *buffer, return 0; } -static inline void security_inode_getsecid(struct inode *inode, u32 *secid) +static inline void security_inode_getsecid(struct inode *inode, + struct lsm_export *l) { - *secid = 0; + lsm_export_init(l); } static inline int security_inode_copy_up(struct dentry *src, struct cred **new) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index b06ffcf9bb9f..71daead619e5 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -1908,13 +1908,16 @@ static inline int audit_copy_fcaps(struct audit_names *name, void audit_copy_inode(struct audit_names *name, const struct dentry *dentry, struct inode *inode, unsigned int flags) { + struct lsm_export le; + name->ino = inode->i_ino; name->dev = inode->i_sb->s_dev; name->mode = inode->i_mode; name->uid = inode->i_uid; name->gid = inode->i_gid; name->rdev = inode->i_rdev; - security_inode_getsecid(inode, &name->osid); + security_inode_getsecid(inode, &le); + lsm_export_secid(&le, &name->osid); if (flags & AUDIT_INODE_NOEVAL) { name->fcap_ver = -1; return; diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 090ef8ceb116..280f2410e551 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -326,7 +326,6 @@ static bool ima_match_rules(struct ima_rule_entry *rule, struct inode *inode, return false; for (i = 0; i < MAX_LSM_RULES; i++) { int rc = 0; - u32 osid; struct lsm_export le; int retried = 0; @@ -337,8 +336,7 @@ static bool ima_match_rules(struct ima_rule_entry *rule, struct inode *inode, case LSM_OBJ_USER: case LSM_OBJ_ROLE: case LSM_OBJ_TYPE: - security_inode_getsecid(inode, &osid); - lsm_export_to_all(&le, osid); + security_inode_getsecid(inode, &le); rc = security_filter_rule_match(&le, rule->lsm[i].type, Audit_equal, diff --git a/security/security.c b/security/security.c index 22ea709593f3..e12ce930dfd9 100644 --- a/security/security.c +++ b/security/security.c @@ -1387,12 +1387,10 @@ int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer } EXPORT_SYMBOL(security_inode_listsecurity); -void security_inode_getsecid(struct inode *inode, u32 *secid) +void security_inode_getsecid(struct inode *inode, struct lsm_export *l) { - struct lsm_export data = { .flags = LSM_EXPORT_NONE }; - - call_void_hook(inode_getsecid, inode, &data); - lsm_export_secid(&data, secid); + lsm_export_init(l); + call_void_hook(inode_getsecid, inode, l); } int security_inode_copy_up(struct dentry *src, struct cred **new) From patchwork Sun Jun 2 16:50:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971873 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 35F0B92A for ; Sun, 2 Jun 2019 16:52:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 268211FF40 for ; Sun, 2 Jun 2019 16:52:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B11B289FA; Sun, 2 Jun 2019 16:52:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B38941FF40 for ; Sun, 2 Jun 2019 16:52:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726965AbfFBQw2 (ORCPT ); Sun, 2 Jun 2019 12:52:28 -0400 Received: from sonic303-8.consmr.mail.bf2.yahoo.com ([74.6.131.47]:43025 "EHLO sonic303-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726844AbfFBQw2 (ORCPT ); Sun, 2 Jun 2019 12:52:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494347; bh=0JVMKDcgnflVCRGzj1eTsOgE9xKpgnePntpCQbXL9EQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=b2lE4dr+Q14NzwuX65FI+K0VFVCfB5mWEdMlBBIXayfvtxLNXohQllbmC7m47iDJis4t09i4zmRe5EDtQBFy5BQWvC4XK9DFLlWAQM0fsyzk1hYUEGH7YZc0vfyHzjl7gu/KVConH7ZR3Gu2eKZL0JyxL3KGBn1TQQ6PNr9fvTG3ZQWwEo0KF8GW6mTZnIKH7zqYoGB2QJ++lWkVKtp5CrLLBxMVp1SZQJffWI5pptB/Szb9ujgIe1UePBwbha3uLvXleDo+ZSGol45aRMpoO89rbgdnely94kP/RtFj0uUPEEgvvz7yg1t6RYIKedH23xKYzx0pFQzY8B3jOXQaEA== X-YMail-OSG: qqeJGaYVM1mE.zRqwBtPCTnpFdW8duBtY2n61MTVjHPXYEYee10QXEmWksl52Gl 1o.U.s6BbIU9swYVcA3oJkQnaEflMu_wyALu4zOPBrp.5Q0CXkI4rChKWczRmOHt9Gx3rvuQaTtu y2zdejHsTtUgVhFdKyCnob04NxJgRI5GmtOtVunYyQo9dR5DiUXo4l3rzVxXRLwzc5n9fsjFwzoe rwu2JM159vg5zfpN2OE6irgsDSN0LgcvUv2Q6eS2vzKEtOB2iWYaxkNuz4ZWMPUuO4WyvGDtXVA7 sSPY12VNRn8B.rMPfZ1E7.RN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com with HTTP; Sun, 2 Jun 2019 16:52:27 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp403.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID f0b498552947f6b5133c1cce9fc77f09; Sun, 02 Jun 2019 16:52:22 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 21/58] LSM: Use lsm_export in security_cred_getsecid Date: Sun, 2 Jun 2019 09:50:24 -0700 Message-Id: <20190602165101.25079-22-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_cred_getsecid to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/security.h | 2 +- security/integrity/ima/ima_main.c | 3 ++- security/security.c | 8 +++----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 2d04687c3fa9..40aa7b9f3c83 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -381,7 +381,7 @@ int security_cred_alloc_blank(struct cred *cred, gfp_t gfp); void security_cred_free(struct cred *cred); int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp); void security_transfer_creds(struct cred *new, const struct cred *old); -void security_cred_getsecid(const struct cred *c, u32 *secid); +void security_cred_getsecid(const struct cred *c, struct lsm_export *l); int security_kernel_act_as(struct cred *new, struct lsm_export *l); int security_kernel_create_files_as(struct cred *new, struct inode *inode); int security_kernel_module_request(char *kmod_name); diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index 1e3cfaf0ee5c..f5efa9ef270d 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -374,7 +374,8 @@ int ima_bprm_check(struct linux_binprm *bprm) if (ret) return ret; - security_cred_getsecid(bprm->cred, &secid); + security_cred_getsecid(bprm->cred, &le); + lsm_export_secid(&le, &secid); return process_measurement(bprm->file, bprm->cred, secid, NULL, 0, MAY_EXEC, CREDS_CHECK); } diff --git a/security/security.c b/security/security.c index e12ce930dfd9..69983ad68233 100644 --- a/security/security.c +++ b/security/security.c @@ -1604,12 +1604,10 @@ void security_transfer_creds(struct cred *new, const struct cred *old) call_void_hook(cred_transfer, new, old); } -void security_cred_getsecid(const struct cred *c, u32 *secid) +void security_cred_getsecid(const struct cred *c, struct lsm_export *l) { - struct lsm_export data = { .flags = LSM_EXPORT_NONE }; - - call_void_hook(cred_getsecid, c, &data); - lsm_export_secid(&data, secid); + lsm_export_init(l); + call_void_hook(cred_getsecid, c, l); } EXPORT_SYMBOL(security_cred_getsecid); From patchwork Sun Jun 2 16:50:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971883 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3384492A for ; Sun, 2 Jun 2019 16:52:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24A5E1FF40 for ; Sun, 2 Jun 2019 16:52:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18CBC286E4; Sun, 2 Jun 2019 16:52:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB07028703 for ; Sun, 2 Jun 2019 16:52:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726963AbfFBQw3 (ORCPT ); Sun, 2 Jun 2019 12:52:29 -0400 Received: from sonic303-8.consmr.mail.bf2.yahoo.com ([74.6.131.47]:35866 "EHLO sonic303-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726964AbfFBQw3 (ORCPT ); Sun, 2 Jun 2019 12:52:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494347; bh=j+cuqymh91xxGIirxxPJDUSMb0L9mw21aX8dKstwmqI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=g1TvDWKq2FlNsBjvpG/3aJk8ntBgcTqfcsjq+a0O91O19awkRtjC2PYe30iz6o1GaVJMrk8Hil2ed5jW00RrKiiiHd4m+0PEqXxBSZmO+uVyA8gJ8zV43lGqRPwBS8GDnKQPlACRkn6Uoof+0Ko54Jy42iBBZGbu+LMO/jLPAZBBhdxRsGKBVytiUdAE23GMgZGdiuU+qMnwWf2bDJkZROMVEHMK1thjn5RR9tHkmyp4E3TKpzRJOV5KUH6t1gjA1IfNTEv31KRjKBDRjQKgmEvOOs+um4p3Bgl95qVWJc02rnA5PP6aNp/KFCWF2UlvwiCwRI+Y0OJqGmSiTb2h1g== X-YMail-OSG: lo2cAu8VM1ldz7jGL0GTnRbU2cz3LqiNtBf5_NSsc8lw9k_rdt3gkInaYw6ePZi pxayQhbWC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n.ZVxyU.iSB5AErmnd3ZLaAWMiwGbSoVuc73 912IkNn2zcavbiq0Nr3mC6wbw7nWvbhpD9DtS0gpBjdQFL7hAkaM4PwvmtGAF.5gv3.3zo5HlAJX cXPjAXtH7BMxmA4hBIPx1StDV59WWGmU55VOd8Ez1Dvf23JmfyAh_MK6_3w-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:52:27 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp403.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID f0b498552947f6b5133c1cce9fc77f09; Sun, 02 Jun 2019 16:52:24 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 22/58] Audit: Change audit_sig_sid to audit_sig_lsm Date: Sun, 2 Jun 2019 09:50:25 -0700 Message-Id: <20190602165101.25079-23-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Remove lsm_export scaffolding around audit_sig_sid by changing the u32 secid into an lsm_export structure named audit_sig_lsm. Signed-off-by: Casey Schaufler --- include/linux/security.h | 7 +++++++ kernel/audit.c | 18 ++++++++---------- kernel/audit.h | 2 +- kernel/auditsc.c | 3 +-- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 40aa7b9f3c83..e76d7a9dbe50 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -93,6 +93,13 @@ static inline void lsm_export_init(struct lsm_export *l) memset(l, 0, sizeof(*l)); } +static inline bool lsm_export_any(struct lsm_export *l) +{ + return (((l->flags & LSM_EXPORT_SELINUX) && l->selinux) || + ((l->flags & LSM_EXPORT_SMACK) && l->smack) || + ((l->flags & LSM_EXPORT_APPARMOR) && l->apparmor)); +} + /** * lsm_export_secid - pull the useful secid out of a lsm_export * @data: the containing data structure diff --git a/kernel/audit.c b/kernel/audit.c index fa4c5544eb37..5226e2af9498 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -135,9 +135,9 @@ static u32 audit_backlog_limit = 64; static u32 audit_backlog_wait_time = AUDIT_BACKLOG_WAIT_TIME; /* The identity of the user shutting down the audit system. */ -kuid_t audit_sig_uid = INVALID_UID; -pid_t audit_sig_pid = -1; -u32 audit_sig_sid = 0; +kuid_t audit_sig_uid = INVALID_UID; +pid_t audit_sig_pid = -1; +struct lsm_export audit_sig_lsm; /* Records can be lost in several ways: 0) [suppressed in audit_alloc] @@ -1429,23 +1429,21 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) } case AUDIT_SIGNAL_INFO: len = 0; - if (audit_sig_sid) { - struct lsm_export le; - - lsm_export_to_all(&le, audit_sig_sid); - err = security_secid_to_secctx(&le, &ctx, &len); + if (lsm_export_any(&audit_sig_lsm)) { + err = security_secid_to_secctx(&audit_sig_lsm, &ctx, + &len); if (err) return err; } sig_data = kmalloc(sizeof(*sig_data) + len, GFP_KERNEL); if (!sig_data) { - if (audit_sig_sid) + if (lsm_export_any(&audit_sig_lsm)) security_release_secctx(ctx, len); return -ENOMEM; } sig_data->uid = from_kuid(&init_user_ns, audit_sig_uid); sig_data->pid = audit_sig_pid; - if (audit_sig_sid) { + if (lsm_export_any(&audit_sig_lsm)) { memcpy(sig_data->ctx, ctx, len); security_release_secctx(ctx, len); } diff --git a/kernel/audit.h b/kernel/audit.h index 958d5b8fc1b3..64498850c52b 100644 --- a/kernel/audit.h +++ b/kernel/audit.h @@ -338,7 +338,7 @@ extern char *audit_unpack_string(void **bufp, size_t *remain, size_t len); extern pid_t audit_sig_pid; extern kuid_t audit_sig_uid; -extern u32 audit_sig_sid; +extern struct lsm_export audit_sig_lsm; extern int audit_filter(int msgtype, unsigned int listtype); diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 71daead619e5..41f540037a93 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2398,8 +2398,7 @@ int audit_signal_info(int sig, struct task_struct *t) audit_sig_uid = auid; else audit_sig_uid = uid; - security_task_getsecid(current, &le); - lsm_export_secid(&le, &audit_sig_sid); + security_task_getsecid(current, &audit_sig_lsm); } if (!audit_signals || audit_dummy_context()) From patchwork Sun Jun 2 16:50:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971881 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C077D14DB for ; Sun, 2 Jun 2019 16:52:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0CBC1FF40 for ; Sun, 2 Jun 2019 16:52:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5178289FA; Sun, 2 Jun 2019 16:52:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06D90286E4 for ; Sun, 2 Jun 2019 16:52:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726959AbfFBQw3 (ORCPT ); Sun, 2 Jun 2019 12:52:29 -0400 Received: from sonic303-8.consmr.mail.bf2.yahoo.com ([74.6.131.47]:40228 "EHLO sonic303-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726631AbfFBQw3 (ORCPT ); Sun, 2 Jun 2019 12:52:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494347; bh=V6rKCyElicKZF/0fKwJbU08oHRiI1KUrOSjj+nGJXW4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=eav5+bSojuVq1NDxIbxwTMl4MicQpAfi0MtatlV4KE3SKLYcCqRpDpPYNRQPk8Wd13rpIAXvy11TtKhBpG3918CLYvxYlCX2sgrYMH7eWq9RTnN8hEyxOP/QyMb63U18hz2ZXmK5fAJXlchDaLl+b4AKS4kw4ifdqw//TBp6zVkUKgoT7nsXhcHkLvMjxd+rnBy3udgo4fMYNk5TaD33+V81aRNp14pUh3usPYCbx7Vm/nWuJlr0WF1bzgM5zE0+pA3Hyvx+tdhzNuF5oU44ipYVTHTbszG0NWWtebrGIrTvI+ZDmVKknudPhsMft/+FdHqT3uZQCHFVeeSuf5ke2g== X-YMail-OSG: z2oBVSQVM1nDZ0uVkeUn935NhnBZqy6I23osLCQdSSgBCkZOYzvop2Z5zyVKeeQ SKuyygCs2jHXtk7BZkrqmNcEh9g1FYUx1y6.M8dSIypN8glQ_WyOl3MDkVHX31KjNPqt11.E0YKB fk6CgfnfaI4f33CKt0oMzGVc._LCPvubzj.uEC3wDEyXVcISFARH8gzG4T_VBCXuTbrj7UvkfNYI U5aSX_2fUWc47.tzvX2YayPD1CU4xXflUhl.d6eLeiMFlmhABmo5WKjqK7NyKexB9Sl4gHAE6Lxi p1jnSGlL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2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:52:27 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp403.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID f0b498552947f6b5133c1cce9fc77f09; Sun, 02 Jun 2019 16:52:25 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 23/58] Audit: Convert target_sid to an lsm_export structure Date: Sun, 2 Jun 2019 09:50:26 -0700 Message-Id: <20190602165101.25079-24-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert target_sid to be an lsm_export structure instead of a u32 secid. Clean out the associated scaffolding. Change the name to target_lsm to be descriptive. Signed-off-by: Casey Schaufler --- kernel/audit.h | 3 ++- kernel/auditsc.c | 30 ++++++++++++------------------ 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/kernel/audit.h b/kernel/audit.h index 64498850c52b..e2e6fa911f9c 100644 --- a/kernel/audit.h +++ b/kernel/audit.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -147,7 +148,7 @@ struct audit_context { kuid_t target_auid; kuid_t target_uid; unsigned int target_sessionid; - u32 target_sid; + struct lsm_export target_lsm; char target_comm[TASK_COMM_LEN]; struct audit_tree_refs *trees, *first_trees; diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 41f540037a93..75d181029d40 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -112,7 +112,7 @@ struct audit_aux_data_pids { kuid_t target_auid[AUDIT_AUX_PIDS]; kuid_t target_uid[AUDIT_AUX_PIDS]; unsigned int target_sessionid[AUDIT_AUX_PIDS]; - u32 target_sid[AUDIT_AUX_PIDS]; + struct lsm_export target_lsm[AUDIT_AUX_PIDS]; char target_comm[AUDIT_AUX_PIDS][TASK_COMM_LEN]; int pid_count; }; @@ -937,14 +937,14 @@ static inline void audit_free_context(struct audit_context *context) } static int audit_log_pid_context(struct audit_context *context, pid_t pid, - kuid_t auid, kuid_t uid, unsigned int sessionid, - u32 sid, char *comm) + kuid_t auid, kuid_t uid, + unsigned int sessionid, + struct lsm_export *l, char *comm) { struct audit_buffer *ab; char *ctx = NULL; u32 len; int rc = 0; - struct lsm_export le; ab = audit_log_start(context, GFP_KERNEL, AUDIT_OBJ_PID); if (!ab) @@ -953,9 +953,8 @@ static int audit_log_pid_context(struct audit_context *context, pid_t pid, audit_log_format(ab, "opid=%d oauid=%d ouid=%d oses=%d", pid, from_kuid(&init_user_ns, auid), from_kuid(&init_user_ns, uid), sessionid); - if (sid) { - lsm_export_to_all(&le, sid); - if (security_secid_to_secctx(&le, &ctx, &len)) { + if (lsm_export_any(l)) { + if (security_secid_to_secctx(l, &ctx, &len)) { audit_log_format(ab, " obj=(none)"); rc = 1; } else { @@ -1525,7 +1524,7 @@ static void audit_log_exit(void) axs->target_auid[i], axs->target_uid[i], axs->target_sessionid[i], - axs->target_sid[i], + &axs->target_lsm[i], axs->target_comm[i])) call_panic = 1; } @@ -1534,7 +1533,7 @@ static void audit_log_exit(void) audit_log_pid_context(context, context->target_pid, context->target_auid, context->target_uid, context->target_sessionid, - context->target_sid, context->target_comm)) + &context->target_lsm, context->target_comm)) call_panic = 1; if (context->pwd.dentry && context->pwd.mnt) { @@ -1711,7 +1710,7 @@ void __audit_syscall_exit(int success, long return_code) context->aux = NULL; context->aux_pids = NULL; context->target_pid = 0; - context->target_sid = 0; + lsm_export_init(&context->target_lsm); context->sockaddr_len = 0; context->type = 0; context->fds[0] = -1; @@ -2363,14 +2362,12 @@ int __audit_sockaddr(int len, void *a) void __audit_ptrace(struct task_struct *t) { struct audit_context *context = audit_context(); - struct lsm_export le; context->target_pid = task_tgid_nr(t); context->target_auid = audit_get_loginuid(t); context->target_uid = task_uid(t); context->target_sessionid = audit_get_sessionid(t); - security_task_getsecid(t, &le); - lsm_export_secid(&le, &context->target_sid); + security_task_getsecid(t, &context->target_lsm); memcpy(context->target_comm, t->comm, TASK_COMM_LEN); } @@ -2387,7 +2384,6 @@ int audit_signal_info(int sig, struct task_struct *t) struct audit_aux_data_pids *axp; struct audit_context *ctx = audit_context(); kuid_t uid = current_uid(), auid, t_uid = task_uid(t); - struct lsm_export le; if (auditd_test_task(t) && (sig == SIGTERM || sig == SIGHUP || @@ -2411,8 +2407,7 @@ int audit_signal_info(int sig, struct task_struct *t) ctx->target_auid = audit_get_loginuid(t); ctx->target_uid = t_uid; ctx->target_sessionid = audit_get_sessionid(t); - security_task_getsecid(t, &le); - lsm_export_secid(&le, &ctx->target_sid); + security_task_getsecid(t, &ctx->target_lsm); memcpy(ctx->target_comm, t->comm, TASK_COMM_LEN); return 0; } @@ -2433,8 +2428,7 @@ int audit_signal_info(int sig, struct task_struct *t) axp->target_auid[axp->pid_count] = audit_get_loginuid(t); axp->target_uid[axp->pid_count] = t_uid; axp->target_sessionid[axp->pid_count] = audit_get_sessionid(t); - security_task_getsecid(t, &le); - lsm_export_secid(&le, &axp->target_sid[axp->pid_count]); + security_task_getsecid(t, &axp->target_lsm[axp->pid_count]); memcpy(axp->target_comm[axp->pid_count], t->comm, TASK_COMM_LEN); axp->pid_count++; From patchwork Sun Jun 2 16:50:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971885 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C61092A for ; Sun, 2 Jun 2019 16:52:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A3AF1FF40 for ; Sun, 2 Jun 2019 16:52:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EAD3289FA; Sun, 2 Jun 2019 16:52:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E80EF1FF40 for ; Sun, 2 Jun 2019 16:52:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726977AbfFBQwk (ORCPT ); Sun, 2 Jun 2019 12:52:40 -0400 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:41461 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726968AbfFBQwk (ORCPT ); Sun, 2 Jun 2019 12:52:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494359; bh=NLJ9WRLN3mqnoEKmIr7GkqEF3TZIbdXheKniGVooL5g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=QQZcn3HIGH5lFNHVaJbpPUXuG0TQA7F+B9BZ76foR43HrSPC56vqV99T1SkyBY36ZXQmT8sBa9t7SnBdxbfrpmRwUX1BI/spfBjDsiHy1xhwXn2507GQQ0kXvqVTYMw3cdHiwELAYuqUn2hH5X7rALL1m9XSu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jJfCANsNV1mPZJUcPDGI8geTFzDw7 ekg9oc1B0G6c1XhW3N_B_W_lb4ZClHxgp9El4DYmcLYYNRJPVJGnme5D0ZJXdn3R1wAlP11ZZslk A4JenZT.pIJZFK.rkNyRscEUv25KInP3P2RWuKgA1ojfYH2XRIdrsTCRTUGWFGjLC9WlKTuqdRxm Gl8mf3vshdzfBnjZ.tIX_njSfIb.5HYqmc1l9Lvau3Mqtkqqi7p0MAIs98CYq51yymJJHj4PzeOh pOJ7pdWriSKeRbubZ4c56RyjCsasj6XimWy736eUz2pX2G7BnwVsn6oIQG6fU6YxBQ2n8KmeslxM hTB0ZHL.LkIzX.w3DQUNqDkwGz.q6ZjDzsoeAyFlUL85itm7gCka4rB2plRuv1O2BRoHt1h8HqcR ji_4wul9DyBtXnWnNO6o49vGtORArHzgH9g49di_a7PFSj55BgHA8 Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:52:39 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp408.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 225d748664d0767f72d028f09ace7268; Sun, 02 Jun 2019 16:52:37 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 24/58] Audit: Convert osid to an lsm_export structure Date: Sun, 2 Jun 2019 09:50:27 -0700 Message-Id: <20190602165101.25079-25-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert osid to be an lsm_export structure instead of a u32 secid. Clean out the associated scaffolding. Change the name to olsm to be descriptive. Signed-off-by: Casey Schaufler --- kernel/audit.c | 4 +--- kernel/audit.h | 4 ++-- kernel/auditsc.c | 36 ++++++++++++------------------------ 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/kernel/audit.c b/kernel/audit.c index 5226e2af9498..d83d1f05c95d 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -2073,12 +2073,10 @@ int audit_log_task_context(struct audit_buffer *ab) char *ctx = NULL; unsigned len; int error; - u32 sid; struct lsm_export le; security_task_getsecid(current, &le); - lsm_export_secid(&le, &sid); - if (!sid) + if (!lsm_export_any(&le)) return 0; error = security_secid_to_secctx(&le, &ctx, &len); diff --git a/kernel/audit.h b/kernel/audit.h index e2e6fa911f9c..7d2fcdf0bc94 100644 --- a/kernel/audit.h +++ b/kernel/audit.h @@ -91,7 +91,7 @@ struct audit_names { kuid_t uid; kgid_t gid; dev_t rdev; - u32 osid; + struct lsm_export olsm; struct audit_cap_data fcap; unsigned int fcap_ver; unsigned char type; /* record type */ @@ -165,7 +165,7 @@ struct audit_context { kuid_t uid; kgid_t gid; umode_t mode; - u32 osid; + struct lsm_export olsm; int has_perm; uid_t perm_uid; gid_t perm_gid; diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 75d181029d40..d64775f4bb1b 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -645,17 +645,15 @@ static int audit_filter_rules(struct task_struct *tsk, if (f->lsm_rule) { /* Find files that match */ if (name) { - lsm_export_to_all(&le, name->osid); result = security_audit_rule_match( - &le, + &name->olsm, f->type, f->op, f->lsm_rule); } else if (ctx) { list_for_each_entry(n, &ctx->names_list, list) { - lsm_export_to_all(&le, n->osid); if (security_audit_rule_match( - &le, + &n->olsm, f->type, f->op, f->lsm_rule)) { @@ -667,8 +665,7 @@ static int audit_filter_rules(struct task_struct *tsk, /* Find ipc objects that match */ if (!ctx || ctx->type != AUDIT_IPC) break; - lsm_export_to_all(&le, ctx->ipc.osid); - if (security_audit_rule_match(&le, + if (security_audit_rule_match(&ctx->ipc.olsm, f->type, f->op, f->lsm_rule)) ++result; @@ -1187,19 +1184,17 @@ static void show_special(struct audit_context *context, int *call_panic) context->socketcall.args[i]); break; } case AUDIT_IPC: { - u32 osid = context->ipc.osid; + struct lsm_export *l = &context->ipc.olsm; audit_log_format(ab, "ouid=%u ogid=%u mode=%#ho", from_kuid(&init_user_ns, context->ipc.uid), from_kgid(&init_user_ns, context->ipc.gid), context->ipc.mode); - if (osid) { + if (lsm_export_any(l)) { char *ctx = NULL; u32 len; - struct lsm_export le; - lsm_export_to_all(&le, osid); - if (security_secid_to_secctx(&le, &ctx, &len)) { - audit_log_format(ab, " osid=%u", osid); + if (security_secid_to_secctx(l, &ctx, &len)) { + audit_log_format(ab, " osid=(unknown)"); *call_panic = 1; } else { audit_log_format(ab, " obj=%s", ctx); @@ -1346,14 +1341,12 @@ static void audit_log_name(struct audit_context *context, struct audit_names *n, from_kgid(&init_user_ns, n->gid), MAJOR(n->rdev), MINOR(n->rdev)); - if (n->osid != 0) { + if (lsm_export_any(&n->olsm)) { char *ctx = NULL; u32 len; - struct lsm_export le; - lsm_export_to_all(&le, n->osid); - if (security_secid_to_secctx(&le, &ctx, &len)) { - audit_log_format(ab, " osid=%u", n->osid); + if (security_secid_to_secctx(&n->olsm, &ctx, &len)) { + audit_log_format(ab, " osid=(unknown)"); if (call_panic) *call_panic = 2; } else { @@ -1907,16 +1900,13 @@ static inline int audit_copy_fcaps(struct audit_names *name, void audit_copy_inode(struct audit_names *name, const struct dentry *dentry, struct inode *inode, unsigned int flags) { - struct lsm_export le; - name->ino = inode->i_ino; name->dev = inode->i_sb->s_dev; name->mode = inode->i_mode; name->uid = inode->i_uid; name->gid = inode->i_gid; name->rdev = inode->i_rdev; - security_inode_getsecid(inode, &le); - lsm_export_secid(&le, &name->osid); + security_inode_getsecid(inode, &name->olsm); if (flags & AUDIT_INODE_NOEVAL) { name->fcap_ver = -1; return; @@ -2266,13 +2256,11 @@ void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat) void __audit_ipc_obj(struct kern_ipc_perm *ipcp) { struct audit_context *context = audit_context(); - struct lsm_export le; context->ipc.uid = ipcp->uid; context->ipc.gid = ipcp->gid; context->ipc.mode = ipcp->mode; context->ipc.has_perm = 0; - security_ipc_getsecid(ipcp, &le); - lsm_export_secid(&le, &context->ipc.osid); + security_ipc_getsecid(ipcp, &context->ipc.olsm); context->type = AUDIT_IPC; } From patchwork Sun Jun 2 16:50:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971893 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E21C992A for ; Sun, 2 Jun 2019 16:52:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D19FE1FF40 for ; Sun, 2 Jun 2019 16:52:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5E2928A1B; Sun, 2 Jun 2019 16:52:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BA9F1FF40 for ; Sun, 2 Jun 2019 16:52:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726631AbfFBQwm (ORCPT ); Sun, 2 Jun 2019 12:52:42 -0400 Received: from sonic310-27.consmr.mail.gq1.yahoo.com ([98.137.69.153]:40094 "EHLO sonic310-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726973AbfFBQwm (ORCPT ); Sun, 2 Jun 2019 12:52:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494360; bh=WdnFJNhqMM887DyLRoNCsL62MRkkEDeoMEYJROIA3Sw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=tSgpz2+BAsfq0MQyu3X+1RwAVC3OpGtfmO3b7HSj1pVohKrENyKUVRU0/dIQIU1jRD7LobubbDv2PvuZN4kh8s910nAhAS8G1dKCdPm0jjnb/pZgMGc7+iaNG5kFvhvHIYE/EZtKyw7iQQlRgkMepm80g8fYzOq6OzTqum+bWzg1EP/GEz8sRNabIc34H0ARk6ULnD36+J5C1x6FCoOxzpuHm8tNakvlzuIVaalExsWZNehl3LD6+GHeTuRHH+ifBfOqjHPtHEz9CUqXhEjW8QoHm36df4V0kulrGtSd+pDrKoq8JFtIbJHsA25/NbzMmL4dlFs+IMRREOKdz7qrFQ== X-YMail-OSG: dUqoG4sVM1lA4cND2AF_bvq8.o_5KHIP6gYUVDCdG2sZONnKdhh3EBIRsp8ChzQ jqX8bm6u9C.R4CrgJO3JhAiUXDoNdGnTX2nfIPjQ6m3Hd_eYyBpUc8PpnXXk.pmsGgUtK.jhmh7x izza8p_APjNeHenSsLPlPvBdPBrF.7ATIYlf6JZn_AU1xkqGXWw_ZjjM3MeqKlFJO4m7gGW98oN3 gF8k9yqT43M_gvGrhnpnXWwBnUDctICwaTAxVUuhNp72vahOeTYn0ybzoX36cO8bBUq_LV8_Rzl_ 7GyuIponsDwapUAXwTSi1woao9JfSmWlFRYYi8lU2jChHlubABfaIvAJMw6M0TeDWAjyDS47cUJX viaEDi3Q59G6ifqHV520pO.ScF3wkhHzm6e7k4aMWM5zijEDIXucd4gCzWrV01dsWHed4du0RsaB OrWEdcv73IgE05RKCbsMsQFaoYSy0Bhpv_iL2aFHbSr1p1Z4G4redJCwyofEutDQ1pAzL5oMKYUF Y_J.3lijYaUUovAAU1mXI9XMaVm.hKcBDMChmxMZZiIHh4HXMhylE.0EM_MYPhoTDzzpsXhigTOO 4XYlEM46MS6I3PmB2NeHg4FaB8QB_FCpTztcmZKMf6kA6REzOvV91XgGJYcg5iMXK0Vx8HPP2HWH jKACICwT4meW3_4H.zz.naGd58OeSafNQmhstdamFjc5MH.wDwuiYmrJK1kD3SM7UOUDjUbI_Sxe kDqsIPDCseUYN9BL2NFfE_V6jq9nBPNJrV7XtoaOqcMfgAkF.r_cVR2xgUiSLwqsKTZLIsfALAHc IKDsK3kVicS71bO1PucUT_VL63czuTURDnjGno0ZhgZxCTXVXbMA4p4hWN1tE.chfWpRxw7U8zj5 VEKT97zKQVYiNZ0LQrCViwhcifdmjCjL2xPkQHX0Y6HANhkXZnzdv_u4zswtLIFu8rzcf63vUa_c qV2VhFPPcmLEHIVQRAA3p13XEnRTe3J9sW2eRTuF5NClSGgTajW0gQ0JEBJ3LyoYynoVwcYle8qg 9KHRHPaL6yUOxyTcCLLnJ7sp1sSp29so3xJxSqh0n0Ar.RtnIskL6esIRge9x5YvS1ZCxH81oXi9 m40SKEIhapUCtiqFLsbMBouyzUxMW85YqaeHA1fixFz1e5kkrkkWCop_cIJwbyxO27Lu5I67rPFO 02IcGYUvDS6YYCA8UV3SmqRjyejKdkZEEPCJW5PU.4phRSi0MXgZr0jAcWl7CI6sEZ4.l91d21HS xviR8JiGnnPLH3tfPKXj5NBwdZWIG5YlOUe0Sv1p6XH7BV95ASr3zwtE- Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.gq1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:52:40 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp408.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 225d748664d0767f72d028f09ace7268; Sun, 02 Jun 2019 16:52:37 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 25/58] IMA: Clean out lsm_export scaffolding Date: Sun, 2 Jun 2019 09:50:28 -0700 Message-Id: <20190602165101.25079-26-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Clean out the scaffolding used in the lsm_export transition. This requires changing some of the IMA internal interfaces from u32 to struct lsm_export pointers. Signed-off-by: Casey Schaufler --- security/integrity/ima/ima.h | 10 ++++++---- security/integrity/ima/ima_api.c | 9 +++++---- security/integrity/ima/ima_appraise.c | 4 +--- security/integrity/ima/ima_main.c | 25 ++++++++----------------- security/integrity/ima/ima_policy.c | 14 +++++++------- 5 files changed, 27 insertions(+), 35 deletions(-) diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index d213e835c498..8b109ad0de2e 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -192,8 +192,9 @@ enum ima_hooks { }; /* LIM API function definitions */ -int ima_get_action(struct inode *inode, const struct cred *cred, u32 secid, - int mask, enum ima_hooks func, int *pcr); +int ima_get_action(struct inode *inode, const struct cred *cred, + struct lsm_export *l, int mask, enum ima_hooks func, + int *pcr); int ima_must_measure(struct inode *inode, int mask, enum ima_hooks func); int ima_collect_measurement(struct integrity_iint_cache *iint, struct file *file, void *buf, loff_t size, @@ -213,8 +214,9 @@ void ima_free_template_entry(struct ima_template_entry *entry); const char *ima_d_path(const struct path *path, char **pathbuf, char *filename); /* IMA policy related functions */ -int ima_match_policy(struct inode *inode, const struct cred *cred, u32 secid, - enum ima_hooks func, int mask, int flags, int *pcr); +int ima_match_policy(struct inode *inode, const struct cred *cred, + struct lsm_export *l, enum ima_hooks func, int mask, + int flags, int *pcr); void ima_init_policy(void); void ima_update_policy(void); void ima_update_policy_flag(void); diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c index c7505fb122d4..7e493af96134 100644 --- a/security/integrity/ima/ima_api.c +++ b/security/integrity/ima/ima_api.c @@ -159,7 +159,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename, * ima_get_action - appraise & measure decision based on policy. * @inode: pointer to inode to measure * @cred: pointer to credentials structure to validate - * @secid: secid of the task being validated + * @l: LAM data of the task being validated * @mask: contains the permission mask (MAY_READ, MAY_WRITE, MAY_EXEC, * MAY_APPEND) * @func: caller identifier @@ -175,14 +175,15 @@ void ima_add_violation(struct file *file, const unsigned char *filename, * Returns IMA_MEASURE, IMA_APPRAISE mask. * */ -int ima_get_action(struct inode *inode, const struct cred *cred, u32 secid, - int mask, enum ima_hooks func, int *pcr) +int ima_get_action(struct inode *inode, const struct cred *cred, + struct lsm_export *l, int mask, enum ima_hooks func, + int *pcr) { int flags = IMA_MEASURE | IMA_AUDIT | IMA_APPRAISE | IMA_HASH; flags &= ima_policy_flag; - return ima_match_policy(inode, cred, secid, func, mask, flags, pcr); + return ima_match_policy(inode, cred, l, func, mask, flags, pcr); } /* diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c index be714afc9fd2..ba64b0b61383 100644 --- a/security/integrity/ima/ima_appraise.c +++ b/security/integrity/ima/ima_appraise.c @@ -50,15 +50,13 @@ bool is_ima_appraise_enabled(void) */ int ima_must_appraise(struct inode *inode, int mask, enum ima_hooks func) { - u32 secid; struct lsm_export le; if (!ima_appraise) return 0; security_task_getsecid(current, &le); - lsm_export_secid(&le, &secid); - return ima_match_policy(inode, current_cred(), secid, func, mask, + return ima_match_policy(inode, current_cred(), &le, func, mask, IMA_APPRAISE | IMA_HASH, NULL); } diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index f5efa9ef270d..22b973e743fe 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -169,8 +169,8 @@ void ima_file_free(struct file *file) } static int process_measurement(struct file *file, const struct cred *cred, - u32 secid, char *buf, loff_t size, int mask, - enum ima_hooks func) + struct lsm_export *l, char *buf, loff_t size, + int mask, enum ima_hooks func) { struct inode *inode = file_inode(file); struct integrity_iint_cache *iint = NULL; @@ -192,7 +192,7 @@ static int process_measurement(struct file *file, const struct cred *cred, * bitmask based on the appraise/audit/measurement policy. * Included is the appraise submask. */ - action = ima_get_action(inode, cred, secid, mask, func, &pcr); + action = ima_get_action(inode, cred, l, mask, func, &pcr); violation_check = ((func == FILE_CHECK || func == MMAP_CHECK) && (ima_policy_flag & IMA_MEASURE)); if (!action && !violation_check) @@ -335,13 +335,11 @@ static int process_measurement(struct file *file, const struct cred *cred, */ int ima_file_mmap(struct file *file, unsigned long prot) { - u32 secid; struct lsm_export le; if (file && (prot & PROT_EXEC)) { security_task_getsecid(current, &le); - lsm_export_secid(&le, &secid); - return process_measurement(file, current_cred(), secid, NULL, + return process_measurement(file, current_cred(), &le, NULL, 0, MAY_EXEC, MMAP_CHECK); } @@ -364,19 +362,16 @@ int ima_file_mmap(struct file *file, unsigned long prot) int ima_bprm_check(struct linux_binprm *bprm) { int ret; - u32 secid; struct lsm_export le; security_task_getsecid(current, &le); - lsm_export_secid(&le, &secid); - ret = process_measurement(bprm->file, current_cred(), secid, NULL, 0, + ret = process_measurement(bprm->file, current_cred(), &le, NULL, 0, MAY_EXEC, BPRM_CHECK); if (ret) return ret; security_cred_getsecid(bprm->cred, &le); - lsm_export_secid(&le, &secid); - return process_measurement(bprm->file, bprm->cred, secid, NULL, 0, + return process_measurement(bprm->file, bprm->cred, &le, NULL, 0, MAY_EXEC, CREDS_CHECK); } @@ -392,12 +387,10 @@ int ima_bprm_check(struct linux_binprm *bprm) */ int ima_file_check(struct file *file, int mask) { - u32 secid; struct lsm_export le; security_task_getsecid(current, &le); - lsm_export_secid(&le, &secid); - return process_measurement(file, current_cred(), secid, NULL, 0, + return process_measurement(file, current_cred(), &le, NULL, 0, mask & (MAY_READ | MAY_WRITE | MAY_EXEC | MAY_APPEND), FILE_CHECK); } @@ -506,7 +499,6 @@ int ima_post_read_file(struct file *file, void *buf, loff_t size, enum kernel_read_file_id read_id) { enum ima_hooks func; - u32 secid; struct lsm_export le; if (!file && read_id == READING_FIRMWARE) { @@ -530,8 +522,7 @@ int ima_post_read_file(struct file *file, void *buf, loff_t size, func = read_idmap[read_id] ?: FILE_CHECK; security_task_getsecid(current, &le); - lsm_export_secid(&le, &secid); - return process_measurement(file, current_cred(), secid, buf, size, + return process_measurement(file, current_cred(), &le, buf, size, MAY_READ, func); } diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 280f2410e551..fae4718d24f9 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -286,7 +286,7 @@ static void ima_lsm_update_rules(void) * Returns true on rule match, false on failure. */ static bool ima_match_rules(struct ima_rule_entry *rule, struct inode *inode, - const struct cred *cred, u32 secid, + const struct cred *cred, struct lsm_export *l, enum ima_hooks func, int mask) { int i; @@ -345,8 +345,7 @@ static bool ima_match_rules(struct ima_rule_entry *rule, struct inode *inode, case LSM_SUBJ_USER: case LSM_SUBJ_ROLE: case LSM_SUBJ_TYPE: - lsm_export_to_all(&le, secid); - rc = security_filter_rule_match(&le, + rc = security_filter_rule_match(l, rule->lsm[i].type, Audit_equal, rule->lsm[i].rule); @@ -394,7 +393,7 @@ static int get_subaction(struct ima_rule_entry *rule, enum ima_hooks func) * @inode: pointer to an inode for which the policy decision is being made * @cred: pointer to a credentials structure for which the policy decision is * being made - * @secid: LSM secid of the task to be validated + * @l: LSM data of the task to be validated * @func: IMA hook identifier * @mask: requested action (MAY_READ | MAY_WRITE | MAY_APPEND | MAY_EXEC) * @pcr: set the pcr to extend @@ -406,8 +405,9 @@ static int get_subaction(struct ima_rule_entry *rule, enum ima_hooks func) * list when walking it. Reads are many orders of magnitude more numerous * than writes so ima_match_policy() is classical RCU candidate. */ -int ima_match_policy(struct inode *inode, const struct cred *cred, u32 secid, - enum ima_hooks func, int mask, int flags, int *pcr) +int ima_match_policy(struct inode *inode, const struct cred *cred, + struct lsm_export *l, enum ima_hooks func, int mask, + int flags, int *pcr) { struct ima_rule_entry *entry; int action = 0, actmask = flags | (flags << 1); @@ -418,7 +418,7 @@ int ima_match_policy(struct inode *inode, const struct cred *cred, u32 secid, if (!(entry->action & actmask)) continue; - if (!ima_match_rules(entry, inode, cred, secid, func, mask)) + if (!ima_match_rules(entry, inode, cred, l, func, mask)) continue; action |= entry->flags & IMA_ACTION_FLAGS; From patchwork Sun Jun 2 16:50:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971897 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A8C7692A for ; Sun, 2 Jun 2019 16:52:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 985291FF40 for ; Sun, 2 Jun 2019 16:52:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CD53289FA; Sun, 2 Jun 2019 16:52:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AA191FF40 for ; Sun, 2 Jun 2019 16:52:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726972AbfFBQwn (ORCPT ); Sun, 2 Jun 2019 12:52:43 -0400 Received: from sonic310-27.consmr.mail.gq1.yahoo.com ([98.137.69.153]:45641 "EHLO sonic310-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726970AbfFBQwl (ORCPT ); Sun, 2 Jun 2019 12:52:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494360; bh=+QxXCb9k4EN0+MlvBQu1WP28VNVY6EbCswDSvfqvDU8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=MUeiC9OmZwew75uXcY6RQjEI58kywmJ6qZdzGzy/g0dC0dpI3/W1IL36JUKGeyQnY5ftu/Jajg8/9iRiAe6oa2QRRBCSASOZ0HtR+Y/QlnKWYHb5OcUZ4fT2yKUjgcgUABG4RcpULs7YtQKBgIXyHFmmUoYSy/fd/fikbVJxdOzWqqSddZUrBF2SLrUuuTOre52t3Gt4E3qAuLJJi3HyuUzyFMaMwDW3+2RNrz/F++Uk22o384O49b/vggbmUZKH9cEueQTSN+V0kDiKnOUO04GtvqhAGlrZ6uAmQnYfSKXr7RGRLmXKVwtqPqJUuEDeoDVPHko9vSR0wQ9nUxCMgw== X-YMail-OSG: n7lNJ9wVM1kZZ5jiGK9Ufa.irin_wZVC.UGZszCGkgQzeDs5oBNq2yOB7CFTq2I 2zGuC.nTOumcCSDsogZhh5gEGag6SaNyh30LGfp9kBRWUhWTzTsyjrQmQLm4DKE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DBLGE _.bzcYkEn4QLGqrrJNmih4Of6J2J2R2pUh9lUx7aU8429p2N.wpQrIPyeLJ9IqQykYeRUPjb54VA UyBRkYTNCTm_uquZnNKRSKxBpvhhOG2lIiDIqOfOqeqGCVpVKMGPwtF4- Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.gq1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:52:40 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp408.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 225d748664d0767f72d028f09ace7268; Sun, 02 Jun 2019 16:52:38 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 26/58] NET: Change the UNIXCB from a secid to an lsm_export Date: Sun, 2 Jun 2019 09:50:29 -0700 Message-Id: <20190602165101.25079-27-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Store a lsm_export structure in the UDS control information instead of a single secid. Signed-off-by: Casey Schaufler --- include/linux/security.h | 16 ++++++++++++++++ include/net/af_unix.h | 2 +- net/unix/af_unix.c | 9 +++------ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index e76d7a9dbe50..9d8115b3d679 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -100,6 +100,22 @@ static inline bool lsm_export_any(struct lsm_export *l) ((l->flags & LSM_EXPORT_APPARMOR) && l->apparmor)); } +static inline bool lsm_export_equal(struct lsm_export *l, struct lsm_export *m) +{ + if (l->flags != m->flags || l->flags == LSM_EXPORT_NONE) + return false; + if (l->flags & LSM_EXPORT_SELINUX && + (l->selinux != m->selinux || l->selinux == 0)) + return false; + if (l->flags & LSM_EXPORT_SMACK && + (l->smack != m->smack || l->smack == 0)) + return false; + if (l->flags & LSM_EXPORT_APPARMOR && + (l->apparmor != m->apparmor || l->apparmor == 0)) + return false; + return true; +} + /** * lsm_export_secid - pull the useful secid out of a lsm_export * @data: the containing data structure diff --git a/include/net/af_unix.h b/include/net/af_unix.h index 3426d6dacc45..c1612d4b191c 100644 --- a/include/net/af_unix.h +++ b/include/net/af_unix.h @@ -36,7 +36,7 @@ struct unix_skb_parms { kgid_t gid; struct scm_fp_list *fp; /* Passed files */ #ifdef CONFIG_SECURITY_NETWORK - u32 secid; /* Security ID */ + struct lsm_export le; /* LSM data */ #endif u32 consumed; } __randomize_layout; diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 4d4107927ba2..222929693867 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -143,20 +143,17 @@ static struct hlist_head *unix_sockets_unbound(void *addr) #ifdef CONFIG_SECURITY_NETWORK static void unix_get_secdata(struct scm_cookie *scm, struct sk_buff *skb) { - lsm_export_secid(&scm->le, &(UNIXCB(skb).secid)); + UNIXCB(skb).le = scm->le; } static inline void unix_set_secdata(struct scm_cookie *scm, struct sk_buff *skb) { - lsm_export_to_all(&scm->le, UNIXCB(skb).secid); + scm->le = UNIXCB(skb).le; } static inline bool unix_secdata_eq(struct scm_cookie *scm, struct sk_buff *skb) { - u32 best_secid; - - lsm_export_secid(&scm->le, &best_secid); - return (best_secid == UNIXCB(skb).secid); + return lsm_export_equal(&scm->le, &(UNIXCB(skb).le)); } #else static inline void unix_get_secdata(struct scm_cookie *scm, struct sk_buff *skb) From patchwork Sun Jun 2 16:50:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971889 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D1D76C5 for ; Sun, 2 Jun 2019 16:52:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D88A286E4 for ; Sun, 2 Jun 2019 16:52:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81F1F28A00; Sun, 2 Jun 2019 16:52:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36B3D286E4 for ; Sun, 2 Jun 2019 16:52:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726969AbfFBQwm (ORCPT ); Sun, 2 Jun 2019 12:52:42 -0400 Received: from sonic310-27.consmr.mail.gq1.yahoo.com ([98.137.69.153]:42217 "EHLO sonic310-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726976AbfFBQwl (ORCPT ); Sun, 2 Jun 2019 12:52:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494360; bh=DXZobVlHba7NLExIjhRRZRkmastZlDIkiPrs42J8njM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=Ca6crS2AbXGqaqYcaD8ikm/maUYQox3BNJJLjfp/J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tNHjNlzG0jIfUwiD5JstVWhMxxd8XqHizV5.212TshAcKPBZJ2lQ diE14esBYO6CL6M8GDXbQrFS0GVX62LS32825p46iNOeyQr4ERoWduWU4vrjC_.xsHvMsIwF.K.f WtKLXPOM6e3TpvzvrzyKEjNj0f4ktzUeKMlZplw8Y6ukP0MyQMJUmTbPFgPUBoWkKTE4vAAdn.PT PhzvvZipHXRF99KXQuVwildUC96lAU.cKOGSPzGdaxLJyOH3FcF4gmMSnxZzcbpIjRf3ZpDeh_ht 9tW8l.SLhXSaqhaacCBiPve5Bjzzg9whzpxO0AOv3fTgE6mTLZkB0i7UcGuR_IncIYP0CTVga_h3 NfkppaFBwwHgGXAgT_ynWaWrjkpXUh9p7oTZK0Z08wflqDDaRyNQLjpnZW1XMIyJRhkR6.1.fG1e 6pVnkYaDET6sWJF4vdmhfGwvWMZHi.VbAXlsRKfoNN73RBx4UYBMge_6nycRh4TKAm4trR2LATeM GTS9x7AlUXZxmxunN5Dltg_ukA6MatyleO0aJ.opJqSpCAKPrZPwL2gQ- Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.gq1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:52:40 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp408.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 225d748664d0767f72d028f09ace7268; Sun, 02 Jun 2019 16:52:39 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 27/58] NET: Remove scaffolding on secmarks Date: Sun, 2 Jun 2019 09:50:30 -0700 Message-Id: <20190602165101.25079-28-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace the lsm_export scaffolding in xt_SECMARK.c This raises an issue, in that Smack users have been using SECMARK_MODE_SEL, which is suppoed to be exclusively for SELinux. This is worked around in the code, but not fully addressed. Signed-off-by: Casey Schaufler --- net/netfilter/xt_SECMARK.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/netfilter/xt_SECMARK.c b/net/netfilter/xt_SECMARK.c index 2def8d8898e6..9a2a97c200a2 100644 --- a/net/netfilter/xt_SECMARK.c +++ b/net/netfilter/xt_SECMARK.c @@ -55,6 +55,7 @@ static int checkentry_lsm(struct xt_secmark_target_info *info) info->secctx[SECMARK_SECCTX_MAX - 1] = '\0'; info->secid = 0; + lsm_export_init(&le); err = security_secctx_to_secid(info->secctx, strlen(info->secctx), &le); if (err) { if (err == -EINVAL) @@ -63,7 +64,12 @@ static int checkentry_lsm(struct xt_secmark_target_info *info) return err; } - lsm_export_secid(&le, &info->secid); + /* Smack is cheating, using SECMARK_MODE_SEL */ + if (le.selinux) + info->secid = le.selinux; + else + info->secid = le.smack; + if (!info->secid) { pr_info_ratelimited("unable to map security context \'%s\'\n", info->secctx); From patchwork Sun Jun 2 16:50:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971903 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CD5B414DB for ; Sun, 2 Jun 2019 16:52:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDB011FF40 for ; Sun, 2 Jun 2019 16:52:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B1C17289FA; Sun, 2 Jun 2019 16:52:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 659BE1FF40 for ; Sun, 2 Jun 2019 16:52:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726999AbfFBQwz (ORCPT ); Sun, 2 Jun 2019 12:52:55 -0400 Received: from sonic317-38.consmr.mail.ne1.yahoo.com ([66.163.184.49]:43945 "EHLO sonic317-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726990AbfFBQwz (ORCPT ); Sun, 2 Jun 2019 12:52:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494374; bh=n7o8QGFhmUAYfuuVtS2cjj7dSkuQxOxyGbWYP+SBOLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=n48gwVeFVX0n5/5KntUUwoFVWUsMxXga8a+2JtqaRqdvOKqyKVNck5raEp1VvxrLJDcsLODXX9vBdj2JzDnisoRW6uRPs3Ki397Sy2BujqeV4/qJ3AibZcP7BMJCmwNJrg+qERcx7La/oz08LKYbxBEXEqnIauxmQ2SDwpofDn8wXXGViUXCYpcYx5fvS5vfpcImVBNyfZgGXQWQEnyKhNc6NIzhKe+8r2aDiVsXui8M3XG/AeR9fRwMzRBx9whVqt46UTCyP8b5Urvmy3m9UMiuzPmJ1ZI6tpNNw8Akw+rFm5ZSVY7J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5lbE1hVw9wYW_Rh8B8O5xB3BXl6iCc302M suBQaAlm912e2M3RXGLE1CuJfjZQMs5nz4.yNBjhmS_EVOSVdveO1gGPUYqx0XpKffhB_ggxtu2a BtCu5K2fjytUKSTDpqfVBoNpKCxURGar5.ny.J4fCJSZlehdNQn.w.Kqeg5jbDmsMc6Bl4CtgjxA 0kpdNZ0BMXCCPytRK7Sj1M0AAp._CMd9GrDdHyGLDbOlwHk3O_YKZFp9rZidnXbDNybz7MCi20KG msWwAaI_li46OWPKaNMwhO..4rYGFR1kOiu3lcmumg3roTOyrYOiR Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:52:54 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp409.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0c0e3da8255eb26ca342a489fa1b8a19; Sun, 02 Jun 2019 16:52:51 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 28/58] NET: Remove scaffolding on new secmarks Date: Sun, 2 Jun 2019 09:50:31 -0700 Message-Id: <20190602165101.25079-29-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace the lsm_export scaffolding in nft_meta. Signed-off-by: Casey Schaufler --- net/netfilter/nft_meta.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c index 598bea8e4799..a1d3dab5bc25 100644 --- a/net/netfilter/nft_meta.c +++ b/net/netfilter/nft_meta.c @@ -580,11 +580,17 @@ static int nft_secmark_compute_secid(struct nft_secmark *priv) u32 tmp_secid = 0; int err; + lsm_export_init(&le); err = security_secctx_to_secid(priv->ctx, strlen(priv->ctx), &le); if (err) return err; - lsm_export_secid(&le, &tmp_secid); + /* Use the "best" secid */ + if (le.selinux) + tmp_secid = le.selinux; + else + tmp_secid = le.smack; + if (!tmp_secid) return -ENOENT; From patchwork Sun Jun 2 16:50:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971909 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 319B86C5 for ; Sun, 2 Jun 2019 16:52:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 226491FF40 for ; Sun, 2 Jun 2019 16:52:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16CA6289FA; Sun, 2 Jun 2019 16:52:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9F091FF40 for ; Sun, 2 Jun 2019 16:52:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726993AbfFBQw5 (ORCPT ); Sun, 2 Jun 2019 12:52:57 -0400 Received: from sonic310-30.consmr.mail.ne1.yahoo.com ([66.163.186.211]:45092 "EHLO sonic310-30.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726994AbfFBQw4 (ORCPT ); Sun, 2 Jun 2019 12:52:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494375; bh=KYlupIPcbLYAYHDyLLLdG0LtZrXeMUYE6GpZUguvURc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=COGJbiywFmH1VYicXCjFPRb8QmDYGRZlVLCAzu2C03hagL4GcEw9GvsfpkWlNEgNZarY+3vFG3EvqahK0MlAbCnpLBBKeQTh/q5tIBTPCpVIrMSLI+VkfriJqFjybMJfoIMSwzvgWfwNhG5KP2rgzO/6U3lO5CexvhoClnnF93TVWF7+XhuOyMMC/xxF/c9p4aZe1GJLlo7Ae+wY+IIY9TtLEKtDCy4C+IJVGnGuNkQfA9S/M7UFTVwZLvauuu2/3Jehb5V1x+XST87mQUU2VrwFCu1YeejqBDlPmQUm+HfmHTUcVruvxQLLVt0kHKztviTlY8RUn2dAdqZMPsxsBQ== X-YMail-OSG: 5.j9xC0VM1nfcPFTkCeg319lENQlPABfpFOUrvjZJ5VqT7XdWJQNC2vXZB6NSHf 9EegudsXpEhZccqS27wmDxWPgmcX3c_VFTc3w_fO_n8aK01og2uFBKXbzAChyUIFP_BtCScg5_fX KkooX6rCbQBu4_q5jRPsFq5w2Icpf4YCiL80cnYXpFK4uuRn_1XAqN5MwRK1ixV1D6vaSVe_rV8_ HMVY2ZEALZSVGcfDmpz9SR3dEG2tEZL_T24Y6iowFA57BC_IyyNRKf6MAN91gwQqpr.6b4pQ4Odk CXdHFqwV_KloCW.45ugU1H5H5Ek..mG1rpaQobvj1gDejU3woNPwNqXd3eRg3eL6UWyGgFj8bxy0 3bOZP0CoYINgh_RfeE78jwjQd4anEPBbltr4FSE5KjaLdxBiqW4Tg_o7SBZRZtbghjKymdbtnDHY fBfjG5NjhJpox3zoi9PXAiB9uBSxVwMaNMvptE_583FaSpIJujV8cX4szQK72qc_J7Y.PiN7Gs7y KsGDB1zDbjHDaIHOV7FmttcPS64Ao_Qe4wWaFuqEmXe1tm0LEpld5HoDEOILRb35y4Qv9JUVS8qT 87TYB3AnI936pOzUo5tWzLVApFaNz5Fw6X7fCcm58L7s1t.U3bUMjDsdDJI5yWuBEGTEg10EkWZK DwfIyaQpNO6TcqsK9Bd3FvQ0k15YdIsGWyKRlpB8K.MokD6KiOWa6QcOlLMoMO4x8.U5XY.Tw115 TRqyzet1r8A49acCw0r6voBAV2s9ImcEzf06FV0lFXw7CxhL54PZe8mrc2ZaYY5QUwwZwP.9GVmt pUh2RfxF6aWIzzGhwTExsWUShNsu5i9TM8TIOXOfMVcR3SYktrWY5sWYdFtbx6ai61qwH3AxPvzO GWbpd4fnydiEJvUjhNLqhsJRx1nyLGLYvehyR36de1pvZQH8gI6pcWaLZJiZ12kW5vPOrLeZk_9k 8D04gDwjwa4mSbi5SMP_MEEFDTH17Ui5p1c_EL2j0FttfjWhH26h9LxJzZijsV.CtoMuvWqTliYS gZHMlw9f_GXVYEsirZvS7Fh1S4f9c2nOUrWFKQbtOfE9jlttuLFA32fHzdlo.KKSRuCPU2l6q3G3 9DLFfana8tnN3jb1NN3accVj3zB1AroeqYg9GZcxnDAHIusRMyU6pJ3nd9URIhcT347iAX1VhYCJ TBISKpxFdh1ie7.Agpi2GJVRwPlncDCWcvlnbszVyGLPnvRJL_R5ti97kFhEWSdVoFEHqxf60UCr oehbbBVQuFnWyrB6p6GROujmvCtIUSoHdTupkjheKDCtdg3ZP6OS7BQpbrTc- Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:52:55 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp409.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0c0e3da8255eb26ca342a489fa1b8a19; Sun, 02 Jun 2019 16:52:52 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 29/58] NET: Remove netfilter scaffolding for lsm_export Date: Sun, 2 Jun 2019 09:50:32 -0700 Message-Id: <20190602165101.25079-30-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Remove scaffolding functions from the netfilter code. Replace with direct access to lsm_export fields so as to be explicit about how the secmarks are being handled. Signed-off-by: Casey Schaufler --- net/netfilter/nf_conntrack_netlink.c | 12 ++++++++++-- net/netfilter/nf_conntrack_standalone.c | 7 ++++++- net/netfilter/nfnetlink_queue.c | 6 +++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c index b069277450c5..d10cc1924e46 100644 --- a/net/netfilter/nf_conntrack_netlink.c +++ b/net/netfilter/nf_conntrack_netlink.c @@ -332,7 +332,11 @@ static int ctnetlink_dump_secctx(struct sk_buff *skb, const struct nf_conn *ct) char *secctx; struct lsm_export le; - lsm_export_to_all(&le, ct->secmark); + lsm_export_init(&le); + le.flags = LSM_EXPORT_SELINUX | LSM_EXPORT_SMACK; + le.selinux = ct->secmark; + le.smack = ct->secmark; + ret = security_secid_to_secctx(&le, &secctx, &len); if (ret) return 0; @@ -619,7 +623,11 @@ static inline int ctnetlink_secctx_size(const struct nf_conn *ct) int len, ret; struct lsm_export le; - lsm_export_to_all(&le, ct->secmark); + lsm_export_init(&le); + le.flags = LSM_EXPORT_SELINUX | LSM_EXPORT_SMACK; + le.selinux = ct->secmark; + le.smack = ct->secmark; + ret = security_secid_to_secctx(&le, NULL, &len); if (ret) return 0; diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c index 12318026d8d4..d353f3efc5a5 100644 --- a/net/netfilter/nf_conntrack_standalone.c +++ b/net/netfilter/nf_conntrack_standalone.c @@ -177,7 +177,12 @@ static void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) char *secctx; struct lsm_export le; - lsm_export_to_all(&le, ct->secmark); + /* Whichever LSM may be using the secmark */ + lsm_export_init(&le); + le.flags = LSM_EXPORT_SELINUX | LSM_EXPORT_SMACK; + le.selinux = ct->secmark; + le.smack = ct->secmark; + ret = security_secid_to_secctx(&le, &secctx, &len); if (ret) return; diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index 4c74c383e26b..a0670137477b 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c @@ -317,7 +317,11 @@ static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, char **secdata) read_lock_bh(&skb->sk->sk_callback_lock); if (skb->secmark) { - lsm_export_to_all(&le, skb->secmark); + /* Whichever LSM may be using the secmark */ + lsm_export_init(&le); + le.flags = LSM_EXPORT_SELINUX | LSM_EXPORT_SMACK; + le.selinux = skb->secmark; + le.smack = skb->secmark; security_secid_to_secctx(&le, secdata, &seclen); } From patchwork Sun Jun 2 16:50:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971913 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 888CF6C5 for ; Sun, 2 Jun 2019 16:52:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 767081FF40 for ; Sun, 2 Jun 2019 16:52:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A839289FA; Sun, 2 Jun 2019 16:52:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 404041FF40 for ; Sun, 2 Jun 2019 16:52:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726994AbfFBQw5 (ORCPT ); Sun, 2 Jun 2019 12:52:57 -0400 Received: from sonic317-38.consmr.mail.ne1.yahoo.com ([66.163.184.49]:38096 "EHLO sonic317-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726984AbfFBQw5 (ORCPT ); Sun, 2 Jun 2019 12:52:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494374; bh=ru3IBy79wwcnAZalZt5K4emNkCbgFnwqv7TisHF5r3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=rHOx+dGVFMWrh9BQvhuvFarkJbzpbk9WEoaMvtXQZcwZOQCJdGBwAUqTxyWk7Epy6mN5fkp4bzAdpeqfPjXkk9tuvw9Wv0EtLKQWrnKH2kYt0oC/0ouHnjwdjl2z5FgNPP+06NpSRnG9sft/cRWxIa8D9TaNqSbVCjjlGWNuorDhUe8aJ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TI0tUXU_M2JGtZGjz96QA_V4j8yHkdJSOi1YdOqEpSoUZk746O70acXxE8YLVZQS 2wb6kd7KkZ0Lql0Z5kPfcxbmcOGfHrACCHc9Vsmn5QeWVyHZvXM.9UUmqEKAtjDjgNehTyXQQHoe ZjhBCfnRsh7W2q54n6rr4u9fuUp3hX2lmpB3c_z9EODsu27ptde6W5LMbl1E0vvu.FMKnw1VSHBs uFGMJ9gYpMsZLP9eBfyfvqDVodWz28spXPsZ.k2q27JW1X3lHo6u36CxPz15IBKB7pP101_Wfs8n 0iPAuK0RkVyTYYy_SPcTroquQLbCakRQdijyL8fq.0AE2KD5499yjubYVTChkG81fk50LVt8_O3W muiuEkIZWNfEardF.rBVfdZ2TkCciQr0AagsaKPYlgpHWAnEIoy6bFoA0_mPgdcQ- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:52:54 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp409.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0c0e3da8255eb26ca342a489fa1b8a19; Sun, 02 Jun 2019 16:52:53 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 30/58] Netlabel: Replace secids with lsm_export Date: Sun, 2 Jun 2019 09:50:33 -0700 Message-Id: <20190602165101.25079-31-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert to lsm_export structures instead of u32 secids. Clean out the associated scaffolding. This requires changes to several internal interfaces, but no change in behavior. Change the LOC tag type to pass an lsm_export instead of a single u32. As this tag is only used locally there is no change to externally exposed interfaces. Signed-off-by: Casey Schaufler --- include/net/netlabel.h | 10 ++--- net/ipv4/cipso_ipv4.c | 13 ++++--- net/netlabel/netlabel_kapi.c | 5 +-- net/netlabel/netlabel_unlabeled.c | 65 ++++++++++++------------------- net/netlabel/netlabel_unlabeled.h | 2 +- net/netlabel/netlabel_user.c | 7 ++-- net/netlabel/netlabel_user.h | 5 +-- security/selinux/netlabel.c | 2 +- security/selinux/ss/services.c | 9 +++-- security/smack/smack_lsm.c | 5 ++- security/smack/smackfs.c | 12 ++++-- 11 files changed, 64 insertions(+), 71 deletions(-) diff --git a/include/net/netlabel.h b/include/net/netlabel.h index 72d6435fc16c..546c75f27d05 100644 --- a/include/net/netlabel.h +++ b/include/net/netlabel.h @@ -111,7 +111,7 @@ struct calipso_doi; /* NetLabel audit information */ struct netlbl_audit { - u32 secid; + struct lsm_export le; kuid_t loginuid; unsigned int sessionid; }; @@ -180,7 +180,7 @@ struct netlbl_lsm_catmap { * @attr.mls: MLS sensitivity label * @attr.mls.cat: MLS category bitmap * @attr.mls.lvl: MLS sensitivity level - * @attr.secid: LSM specific secid token + * @attr.le: LSM specific data * * Description: * This structure is used to pass security attributes between NetLabel and the @@ -215,7 +215,7 @@ struct netlbl_lsm_secattr { struct netlbl_lsm_catmap *cat; u32 lvl; } mls; - u32 secid; + struct lsm_export le; } attr; }; @@ -429,7 +429,7 @@ int netlbl_cfg_unlbl_static_add(struct net *net, const void *addr, const void *mask, u16 family, - u32 secid, + struct lsm_export *l, struct netlbl_audit *audit_info); int netlbl_cfg_unlbl_static_del(struct net *net, const char *dev_name, @@ -537,7 +537,7 @@ static inline int netlbl_cfg_unlbl_static_add(struct net *net, const void *addr, const void *mask, u16 family, - u32 secid, + struct lsm_export *l, struct netlbl_audit *audit_info) { return -ENOSYS; diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c index f0165c5f376b..1defea2488b3 100644 --- a/net/ipv4/cipso_ipv4.c +++ b/net/ipv4/cipso_ipv4.c @@ -122,13 +122,16 @@ int cipso_v4_rbm_strictvalid = 1; * * 0 8 16 24 32 * +----------+----------+----------+----------+ - * | 10000000 | 00000110 | 32-bit secid value | + * | 10000000 | 00000110 | SELinux secid | * +----------+----------+----------+----------+ - * | in (host byte order)| + * | Smack secid | AppArmor secid | + * +----------+----------+----------+----------+ + * | LSM export flags | * +----------+----------+ * + * All secid and flag fields are in host byte order. */ -#define CIPSO_V4_TAG_LOC_BLEN 6 +#define CIPSO_V4_TAG_LOC_BLEN (2 + sizeof(struct lsm_export)) /* * Helper Functions @@ -1481,7 +1484,7 @@ static int cipso_v4_gentag_loc(const struct cipso_v4_doi *doi_def, buffer[0] = CIPSO_V4_TAG_LOCAL; buffer[1] = CIPSO_V4_TAG_LOC_BLEN; - *(u32 *)&buffer[2] = secattr->attr.secid; + memcpy(&buffer[2], &secattr->attr.le, sizeof(secattr->attr.le)); return CIPSO_V4_TAG_LOC_BLEN; } @@ -1501,7 +1504,7 @@ static int cipso_v4_parsetag_loc(const struct cipso_v4_doi *doi_def, const unsigned char *tag, struct netlbl_lsm_secattr *secattr) { - secattr->attr.secid = *(u32 *)&tag[2]; + memcpy(&secattr->attr.le, &tag[2], sizeof(secattr->attr.le)); secattr->flags |= NETLBL_SECATTR_SECID; return 0; diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c index ee3e5b6471a6..849064422e0b 100644 --- a/net/netlabel/netlabel_kapi.c +++ b/net/netlabel/netlabel_kapi.c @@ -224,7 +224,7 @@ int netlbl_cfg_unlbl_static_add(struct net *net, const void *addr, const void *mask, u16 family, - u32 secid, + struct lsm_export *l, struct netlbl_audit *audit_info) { u32 addr_len; @@ -243,8 +243,7 @@ int netlbl_cfg_unlbl_static_add(struct net *net, } return netlbl_unlhsh_add(net, - dev_name, addr, mask, addr_len, - secid, audit_info); + dev_name, addr, mask, addr_len, l, audit_info); } /** diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c index 7f245d593c8f..f79ab91bf25e 100644 --- a/net/netlabel/netlabel_unlabeled.c +++ b/net/netlabel/netlabel_unlabeled.c @@ -80,7 +80,7 @@ struct netlbl_unlhsh_tbl { #define netlbl_unlhsh_addr4_entry(iter) \ container_of(iter, struct netlbl_unlhsh_addr4, list) struct netlbl_unlhsh_addr4 { - u32 secid; + struct lsm_export le; struct netlbl_af4list list; struct rcu_head rcu; @@ -88,7 +88,7 @@ struct netlbl_unlhsh_addr4 { #define netlbl_unlhsh_addr6_entry(iter) \ container_of(iter, struct netlbl_unlhsh_addr6, list) struct netlbl_unlhsh_addr6 { - u32 secid; + struct lsm_export le; struct netlbl_af6list list; struct rcu_head rcu; @@ -244,7 +244,7 @@ static struct netlbl_unlhsh_iface *netlbl_unlhsh_search_iface(int ifindex) static int netlbl_unlhsh_add_addr4(struct netlbl_unlhsh_iface *iface, const struct in_addr *addr, const struct in_addr *mask, - u32 secid) + struct lsm_export *l) { int ret_val; struct netlbl_unlhsh_addr4 *entry; @@ -256,7 +256,7 @@ static int netlbl_unlhsh_add_addr4(struct netlbl_unlhsh_iface *iface, entry->list.addr = addr->s_addr & mask->s_addr; entry->list.mask = mask->s_addr; entry->list.valid = 1; - entry->secid = secid; + entry->le = *l; spin_lock(&netlbl_unlhsh_lock); ret_val = netlbl_af4list_add(&entry->list, &iface->addr4_list); @@ -284,7 +284,7 @@ static int netlbl_unlhsh_add_addr4(struct netlbl_unlhsh_iface *iface, static int netlbl_unlhsh_add_addr6(struct netlbl_unlhsh_iface *iface, const struct in6_addr *addr, const struct in6_addr *mask, - u32 secid) + struct lsm_export *l) { int ret_val; struct netlbl_unlhsh_addr6 *entry; @@ -300,7 +300,7 @@ static int netlbl_unlhsh_add_addr6(struct netlbl_unlhsh_iface *iface, entry->list.addr.s6_addr32[3] &= mask->s6_addr32[3]; entry->list.mask = *mask; entry->list.valid = 1; - entry->secid = secid; + entry->le = *l; spin_lock(&netlbl_unlhsh_lock); ret_val = netlbl_af6list_add(&entry->list, &iface->addr6_list); @@ -379,7 +379,7 @@ int netlbl_unlhsh_add(struct net *net, const void *addr, const void *mask, u32 addr_len, - u32 secid, + struct lsm_export *l, struct netlbl_audit *audit_info) { int ret_val; @@ -389,7 +389,6 @@ int netlbl_unlhsh_add(struct net *net, struct audit_buffer *audit_buf = NULL; char *secctx = NULL; u32 secctx_len; - struct lsm_export le; if (addr_len != sizeof(struct in_addr) && addr_len != sizeof(struct in6_addr)) @@ -422,7 +421,7 @@ int netlbl_unlhsh_add(struct net *net, const struct in_addr *addr4 = addr; const struct in_addr *mask4 = mask; - ret_val = netlbl_unlhsh_add_addr4(iface, addr4, mask4, secid); + ret_val = netlbl_unlhsh_add_addr4(iface, addr4, mask4, l); if (audit_buf != NULL) netlbl_af4list_audit_addr(audit_buf, 1, dev_name, @@ -435,7 +434,7 @@ int netlbl_unlhsh_add(struct net *net, const struct in6_addr *addr6 = addr; const struct in6_addr *mask6 = mask; - ret_val = netlbl_unlhsh_add_addr6(iface, addr6, mask6, secid); + ret_val = netlbl_unlhsh_add_addr6(iface, addr6, mask6, l); if (audit_buf != NULL) netlbl_af6list_audit_addr(audit_buf, 1, dev_name, @@ -452,10 +451,7 @@ int netlbl_unlhsh_add(struct net *net, unlhsh_add_return: rcu_read_unlock(); if (audit_buf != NULL) { - lsm_export_to_all(&le, secid); - if (security_secid_to_secctx(&le, - &secctx, - &secctx_len) == 0) { + if (security_secid_to_secctx(l, &secctx, &secctx_len) == 0) { audit_log_format(audit_buf, " sec_obj=%s", secctx); security_release_secctx(secctx, secctx_len); } @@ -490,7 +486,6 @@ static int netlbl_unlhsh_remove_addr4(struct net *net, struct net_device *dev; char *secctx; u32 secctx_len; - struct lsm_export le; spin_lock(&netlbl_unlhsh_lock); list_entry = netlbl_af4list_remove(addr->s_addr, mask->s_addr, @@ -510,10 +505,8 @@ static int netlbl_unlhsh_remove_addr4(struct net *net, addr->s_addr, mask->s_addr); if (dev != NULL) dev_put(dev); - if (entry != NULL) - lsm_export_to_all(&le, entry->secid); if (entry != NULL && - security_secid_to_secctx(&le, + security_secid_to_secctx(&entry->le, &secctx, &secctx_len) == 0) { audit_log_format(audit_buf, " sec_obj=%s", secctx); security_release_secctx(secctx, secctx_len); @@ -555,7 +548,6 @@ static int netlbl_unlhsh_remove_addr6(struct net *net, struct net_device *dev; char *secctx; u32 secctx_len; - struct lsm_export le; spin_lock(&netlbl_unlhsh_lock); list_entry = netlbl_af6list_remove(addr, mask, &iface->addr6_list); @@ -574,10 +566,8 @@ static int netlbl_unlhsh_remove_addr6(struct net *net, addr, mask); if (dev != NULL) dev_put(dev); - if (entry != NULL) - lsm_export_to_all(&le, entry->secid); if (entry != NULL && - security_secid_to_secctx(&le, + security_secid_to_secctx(&entry->le, &secctx, &secctx_len) == 0) { audit_log_format(audit_buf, " sec_obj=%s", secctx); security_release_secctx(secctx, secctx_len); @@ -903,7 +893,6 @@ static int netlbl_unlabel_staticadd(struct sk_buff *skb, void *addr; void *mask; u32 addr_len; - u32 secid; struct lsm_export le; struct netlbl_audit audit_info; @@ -932,9 +921,8 @@ static int netlbl_unlabel_staticadd(struct sk_buff *skb, if (ret_val != 0) return ret_val; - lsm_export_secid(&le, &secid); return netlbl_unlhsh_add(&init_net, - dev_name, addr, mask, addr_len, secid, + dev_name, addr, mask, addr_len, &le, &audit_info); } @@ -956,7 +944,6 @@ static int netlbl_unlabel_staticadddef(struct sk_buff *skb, void *addr; void *mask; u32 addr_len; - u32 secid; struct lsm_export le; struct netlbl_audit audit_info; @@ -983,10 +970,8 @@ static int netlbl_unlabel_staticadddef(struct sk_buff *skb, if (ret_val != 0) return ret_val; - lsm_export_secid(&le, &secid); return netlbl_unlhsh_add(&init_net, - NULL, addr, mask, addr_len, secid, - &audit_info); + NULL, addr, mask, addr_len, &le, &audit_info); } /** @@ -1097,10 +1082,9 @@ static int netlbl_unlabel_staticlist_gen(u32 cmd, struct netlbl_unlhsh_walk_arg *cb_arg = arg; struct net_device *dev; void *data; - u32 secid; char *secctx; u32 secctx_len; - struct lsm_export le; + struct lsm_export *lep; data = genlmsg_put(cb_arg->skb, NETLINK_CB(cb_arg->nl_cb->skb).portid, cb_arg->seq, &netlbl_unlabel_gnl_family, @@ -1138,7 +1122,7 @@ static int netlbl_unlabel_staticlist_gen(u32 cmd, if (ret_val != 0) goto list_cb_failure; - secid = addr4->secid; + lep = (struct lsm_export *)&addr4->le; } else { ret_val = nla_put_in6_addr(cb_arg->skb, NLBL_UNLABEL_A_IPV6ADDR, @@ -1152,11 +1136,10 @@ static int netlbl_unlabel_staticlist_gen(u32 cmd, if (ret_val != 0) goto list_cb_failure; - secid = addr6->secid; + lep = (struct lsm_export *)&addr6->le; } - lsm_export_to_all(&le, secid); - ret_val = security_secid_to_secctx(&le, &secctx, &secctx_len); + ret_val = security_secid_to_secctx(lep, &secctx, &secctx_len); if (ret_val != 0) goto list_cb_failure; ret_val = nla_put(cb_arg->skb, @@ -1501,26 +1484,30 @@ int netlbl_unlabel_getattr(const struct sk_buff *skb, case PF_INET: { struct iphdr *hdr4; struct netlbl_af4list *addr4; + struct lsm_export *lep; hdr4 = ip_hdr(skb); addr4 = netlbl_af4list_search(hdr4->saddr, &iface->addr4_list); if (addr4 == NULL) goto unlabel_getattr_nolabel; - secattr->attr.secid = netlbl_unlhsh_addr4_entry(addr4)->secid; + lep = &netlbl_unlhsh_addr4_entry(addr4)->le; + secattr->attr.le = *lep; break; } #if IS_ENABLED(CONFIG_IPV6) case PF_INET6: { struct ipv6hdr *hdr6; struct netlbl_af6list *addr6; + struct lsm_export *lep; hdr6 = ipv6_hdr(skb); addr6 = netlbl_af6list_search(&hdr6->saddr, &iface->addr6_list); if (addr6 == NULL) goto unlabel_getattr_nolabel; - secattr->attr.secid = netlbl_unlhsh_addr6_entry(addr6)->secid; + lep = &netlbl_unlhsh_addr6_entry(addr6)->le; + secattr->attr.le = *lep; break; } #endif /* IPv6 */ @@ -1554,13 +1541,11 @@ int __init netlbl_unlabel_defconf(void) int ret_val; struct netlbl_dom_map *entry; struct netlbl_audit audit_info; - struct lsm_export le; /* Only the kernel is allowed to call this function and the only time * it is called is at bootup before the audit subsystem is reporting * messages so don't worry to much about these values. */ - security_task_getsecid(current, &le); - lsm_export_secid(&le, &audit_info.secid); + security_task_getsecid(current, &audit_info.le); audit_info.loginuid = GLOBAL_ROOT_UID; audit_info.sessionid = 0; diff --git a/net/netlabel/netlabel_unlabeled.h b/net/netlabel/netlabel_unlabeled.h index 3a9e5dc9511b..0803f1e6e3c1 100644 --- a/net/netlabel/netlabel_unlabeled.h +++ b/net/netlabel/netlabel_unlabeled.h @@ -225,7 +225,7 @@ int netlbl_unlhsh_add(struct net *net, const void *addr, const void *mask, u32 addr_len, - u32 secid, + struct lsm_export *l, struct netlbl_audit *audit_info); int netlbl_unlhsh_remove(struct net *net, const char *dev_name, diff --git a/net/netlabel/netlabel_user.c b/net/netlabel/netlabel_user.c index 1079cdea872c..2cc96305c841 100644 --- a/net/netlabel/netlabel_user.c +++ b/net/netlabel/netlabel_user.c @@ -100,7 +100,6 @@ struct audit_buffer *netlbl_audit_start_common(int type, struct audit_buffer *audit_buf; char *secctx; u32 secctx_len; - struct lsm_export le; if (audit_enabled == AUDIT_OFF) return NULL; @@ -113,9 +112,9 @@ struct audit_buffer *netlbl_audit_start_common(int type, from_kuid(&init_user_ns, audit_info->loginuid), audit_info->sessionid); - lsm_export_to_all(&le, audit_info->secid); - if (audit_info->secid != 0 && - security_secid_to_secctx(&le, &secctx, &secctx_len) == 0) { + if (lsm_export_any(&audit_info->le) && + security_secid_to_secctx(&audit_info->le, &secctx, + &secctx_len) == 0) { audit_log_format(audit_buf, " subj=%s", secctx); security_release_secctx(secctx, secctx_len); } diff --git a/net/netlabel/netlabel_user.h b/net/netlabel/netlabel_user.h index 2dbc4276bdcc..ee73711e0756 100644 --- a/net/netlabel/netlabel_user.h +++ b/net/netlabel/netlabel_user.h @@ -48,10 +48,7 @@ static inline void netlbl_netlink_auditinfo(struct sk_buff *skb, struct netlbl_audit *audit_info) { - struct lsm_export le; - - security_task_getsecid(current, &le); - lsm_export_secid(&le, &audit_info->secid); + security_task_getsecid(current, &audit_info->le); audit_info->loginuid = audit_get_loginuid(current); audit_info->sessionid = audit_get_sessionid(current); } diff --git a/security/selinux/netlabel.c b/security/selinux/netlabel.c index c40914a157b7..4bbd50237a8a 100644 --- a/security/selinux/netlabel.c +++ b/security/selinux/netlabel.c @@ -122,7 +122,7 @@ static struct netlbl_lsm_secattr *selinux_netlbl_sock_getattr( return NULL; if ((secattr->flags & NETLBL_SECATTR_SECID) && - (secattr->attr.secid == sid)) + (secattr->attr.le.selinux == sid)) return secattr; return NULL; diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c index 626b877363fb..8a197b387056 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c @@ -3596,8 +3596,9 @@ int security_netlbl_secattr_to_sid(struct selinux_state *state, if (secattr->flags & NETLBL_SECATTR_CACHE) *sid = *(u32 *)secattr->cache->data; - else if (secattr->flags & NETLBL_SECATTR_SECID) - *sid = secattr->attr.secid; + else if (secattr->flags & NETLBL_SECATTR_SECID && + (secattr->attr.le.flags & LSM_EXPORT_SELINUX)) + *sid = secattr->attr.le.selinux; else if (secattr->flags & NETLBL_SECATTR_MLS_LVL) { rc = -EIDRM; ctx = sidtab_search(sidtab, SECINITSID_NETMSG); @@ -3670,7 +3671,9 @@ int security_netlbl_sid_to_secattr(struct selinux_state *state, if (secattr->domain == NULL) goto out; - secattr->attr.secid = sid; + lsm_export_init(&secattr->attr.le); + secattr->attr.le.flags = LSM_EXPORT_SELINUX; + secattr->attr.le.selinux = sid; secattr->flags |= NETLBL_SECATTR_DOMAIN_CPY | NETLBL_SECATTR_SECID; mls_export_netlbl_lvl(policydb, ctx, secattr); rc = mls_export_netlbl_cat(policydb, ctx, secattr); diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index ecd636e5c75c..38ea48d22547 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -3756,11 +3756,12 @@ static struct smack_known *smack_from_secattr(struct netlbl_lsm_secattr *sap, return &smack_known_web; return &smack_known_star; } - if ((sap->flags & NETLBL_SECATTR_SECID) != 0) + if ((sap->flags & NETLBL_SECATTR_SECID) != 0 && + (sap->attr.le.flags & LSM_EXPORT_SMACK)) /* * Looks like a fallback, which gives us a secid. */ - return smack_from_secid(sap->attr.secid); + return smack_from_secid(sap->attr.le.smack); /* * Without guidance regarding the smack value * for the packet fall back on the network diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c index faf2ea3968b3..28c567465f6c 100644 --- a/security/smack/smackfs.c +++ b/security/smack/smackfs.c @@ -197,7 +197,8 @@ static void smk_netlabel_audit_set(struct netlbl_audit *nap) nap->loginuid = audit_get_loginuid(current); nap->sessionid = audit_get_sessionid(current); - nap->secid = skp->smk_secid; + nap->le.flags = LSM_EXPORT_SMACK; + nap->le.smack = skp->smk_secid; } /* @@ -1150,6 +1151,7 @@ static void smk_net4addr_insert(struct smk_net4addr *new) static ssize_t smk_write_net4addr(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { + struct lsm_export le; struct smk_net4addr *snp; struct sockaddr_in newname; char *smack; @@ -1281,10 +1283,14 @@ static ssize_t smk_write_net4addr(struct file *file, const char __user *buf, * this host so that incoming packets get labeled. * but only if we didn't get the special CIPSO option */ - if (rc == 0 && skp != NULL) + if (rc == 0 && skp != NULL) { + lsm_export_init(&le); + le.flags = LSM_EXPORT_SMACK; + le.smack = snp->smk_label->smk_secid; rc = netlbl_cfg_unlbl_static_add(&init_net, NULL, &snp->smk_host, &snp->smk_mask, PF_INET, - snp->smk_label->smk_secid, &audit_info); + &le, &audit_info); + } if (rc == 0) rc = count; From patchwork Sun Jun 2 16:50:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971901 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 793716C5 for ; Sun, 2 Jun 2019 16:52:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 693BF286E4 for ; Sun, 2 Jun 2019 16:52:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D3D828703; Sun, 2 Jun 2019 16:52:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07BB91FF40 for ; Sun, 2 Jun 2019 16:52:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726974AbfFBQwz (ORCPT ); Sun, 2 Jun 2019 12:52:55 -0400 Received: from sonic317-38.consmr.mail.ne1.yahoo.com ([66.163.184.49]:43115 "EHLO sonic317-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726994AbfFBQwz (ORCPT ); Sun, 2 Jun 2019 12:52:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494374; bh=gEWZCQzFlqcooAYwsHr2Nt701eG0L+I40RIrEVg4i3g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=fmOzxFWVFWJg0d7+w8ZCO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Rm CQzj7mIaPehV1g2wmMogfbcCz..PpyKppnIVokoE5GGY8FM2H3prlsoOEoncBVRNWouDEx4FwwCl K7pl7sxxzjh1LSPVoqtFF1ynlwivHoohW_gOsfugNBg1Q3eU0NpB5QBEM_Z29eFHNXqxVE_waVyC 7O5BvhDy22dMaFnNjCrc_W0TbskJ.FByOuUZQE.wR26CVC2Ar8mzkNBPXf.udMT1z2TDDUEr60Xi 7r1K7x2pkgwwLlM56DhvaASEIlPlj6JNzOGYjIikIe7fNA_hu0sWdL6NpEwoOdCzjz1FbWXocuP3 iCktmW7haCnQkkh_4LZVM2krlJri6dUxKE1ned1APM7NW2Z_0HhYATF29fJvl5lwWgDKRkDuQI_H P7QBkUNLCm4.kqqLpDqiINMsGMtgqljaY.AZPW6P4ovRgfsSwHWIcJKuz.yM3wCIYSY1fw4ckAMp nvVT3GxdSkqkcHxmUUck690vB7lREP53jGMHs5CK._1F5rYbHkOgqkg_qr00bsYSJAV0A3QHGp4p xVpvVMA35YWPOYBvUw1E4d69gl1GG2CSL9YJPlA4AROCzOQEW_v3zAg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:52:54 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp409.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0c0e3da8255eb26ca342a489fa1b8a19; Sun, 02 Jun 2019 16:52:54 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 31/58] LSM: Remove lsm_export scaffolding functions Date: Sun, 2 Jun 2019 09:50:34 -0700 Message-Id: <20190602165101.25079-32-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The scaffolding functions lsm_export_secid and lsm_export_to_all are no longer required. Remove them. Signed-off-by: Casey Schaufler --- include/linux/security.h | 43 ---------------------------------------- 1 file changed, 43 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 9d8115b3d679..dde36e850cf0 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -116,49 +116,6 @@ static inline bool lsm_export_equal(struct lsm_export *l, struct lsm_export *m) return true; } -/** - * lsm_export_secid - pull the useful secid out of a lsm_export - * @data: the containing data structure - * @secid: where to put the one that matters. - * - * Shim that will disappear when all lsm_export conversions are done. - */ -static inline void lsm_export_secid(struct lsm_export *data, u32 *secid) -{ - switch (data->flags) { - case LSM_EXPORT_NONE: - *secid = 0; - break; - case LSM_EXPORT_SELINUX: - *secid = data->selinux; - break; - case LSM_EXPORT_SMACK: - *secid = data->smack; - break; - case LSM_EXPORT_APPARMOR: - *secid = data->apparmor; - break; - case LSM_EXPORT_SELINUX | LSM_EXPORT_SMACK | LSM_EXPORT_APPARMOR: - /* For scaffolding only */ - *secid = data->selinux; - break; - default: - pr_warn("%s flags=0x%u - not a valid set\n", __func__, - data->flags); - *secid = 0; - break; - } -} - -static inline void lsm_export_to_all(struct lsm_export *data, u32 secid) -{ - data->selinux = secid; - data->smack = secid; - data->apparmor = secid; - data->flags = LSM_EXPORT_SELINUX | LSM_EXPORT_SMACK | - LSM_EXPORT_APPARMOR; -} - /* These functions are in security/commoncap.c */ extern int cap_capable(const struct cred *cred, struct user_namespace *ns, int cap, unsigned int opts); From patchwork Sun Jun 2 16:50:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971917 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A140D92A for ; Sun, 2 Jun 2019 16:53:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 918501FF40 for ; Sun, 2 Jun 2019 16:53:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 856A2289FA; Sun, 2 Jun 2019 16:53:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D56A1FF40 for ; Sun, 2 Jun 2019 16:53:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727006AbfFBQxI (ORCPT ); Sun, 2 Jun 2019 12:53:08 -0400 Received: from sonic303-8.consmr.mail.bf2.yahoo.com ([74.6.131.47]:44340 "EHLO sonic303-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727001AbfFBQxI (ORCPT ); Sun, 2 Jun 2019 12:53:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494387; bh=cOt9caKD/749IXNAg082OZdZ8wyzsShJ6Dne6L26IXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=V/yfTB4Bvuf0mleZIpJzrQbmnlRVqPNpn1vpSX2seKqKsA6sh4x5kiOyLcxV8aGbWzWjsWCcw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FrhA2D8m0RL32.fomRiFQyofZkQ1N K2ArVpC46bFK0xu8__4axMFEgApUd4a2tUccsNy594zyPdKxa5mlw.7vT52yqZuiCPh41IFYGJ79 NSQGVSeYLHOrp9nbA5xIrmXJGsUo4iveawMjihaLuyyOeArfT6MASQ.Nk9wguyQyU2yvXowf4A5v laGSHNDanS_sGvIRuEMq2cFLwpC9W82pgSrYoOMUoNVskd9ZWxhPil1zyGxn7OQB6kjwAt2DAXQX DL1zRBJS.KWbCSuCAOecenHxW5yfqcW1NCQ50pFOAmUxdUJE8ImO_o98Orz_P9KUZP5gQg29S8PI 9x4AifuCDMVruDD6WvgIT.92gU7fgJVekjmrjC2Un1KeGF0flxDExX8zsgJ9gj.P5qP0TGDHnzIg Gz4o8F7PYDXps_wxv7f7Y4VaCcz6oxdxomifg9PU8.Ya031X_rBfQ6U.4kctpXBNQ6zuuaBtU1x6 sAb99UY85681W_z8.X1HkxLOcUhUe8mcUW8mgjmtbZ8_YxxHVUzYXSK5V Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:53:07 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp430.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 740888a1156cdff0756b5bee8a218310; Sun, 02 Jun 2019 16:53:06 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 32/58] IMA: FIXUP prototype using lsm_export Date: Sun, 2 Jun 2019 09:50:35 -0700 Message-Id: <20190602165101.25079-33-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix the prototype on a function stub Signed-off-by: Casey Schaufler --- security/integrity/ima/ima.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index 8b109ad0de2e..7ae41218eb07 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -309,8 +309,8 @@ static inline int security_filter_rule_init(u32 field, u32 op, char *rulestr, return -EINVAL; } -static inline int security_filter_rule_match(u32 secid, u32 field, u32 op, - void *lsmrule) +static inline int security_filter_rule_match(struct lsm_export *l, u32 field, + u32 op, void *lsmrule) { return -EINVAL; } From patchwork Sun Jun 2 16:50:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971925 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E05036C5 for ; Sun, 2 Jun 2019 16:53:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC997286E4 for ; Sun, 2 Jun 2019 16:53:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCCC2289FA; Sun, 2 Jun 2019 16:53:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CFA2286E4 for ; Sun, 2 Jun 2019 16:53:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727010AbfFBQxO (ORCPT ); Sun, 2 Jun 2019 12:53:14 -0400 Received: from sonic302-8.consmr.mail.bf2.yahoo.com ([74.6.135.47]:41754 "EHLO sonic302-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727005AbfFBQxN (ORCPT ); Sun, 2 Jun 2019 12:53:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494393; bh=XFEQORQN/Rrt9xNIMHTY8NF01S7CWObpcTiWCO3b0pw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=pfpj2tyqCN+H3ssbWxeMaCDj8a52WKmVo3z12xp3ES2WKF82xJ79Cwf3z2kgvDjTvvxcN2uwfs04oNLNQOWQ2WFaDocol6/5QkYDVOlcd6AUL81rmS2ucagXxYTIt+rJx7FIbuLITYGDIpK0fo5tfMju+Y45RM9+gDLFJ7LNS48BkT0dOPJUVILB+jac522iN0PqnydjlMzOcoaIvmPlCl3j59dUJWWSt6gH3stipP1YfkxC8w5bLJ2qfG2fQ9jaV9lUmwj7WU9N2Ft0dmECe+a1hHYMbu9vDXwWF8pm7T5sCPZ4fxdI5ZgI3Ff4O71nfxFvCo3FSdLuQwyH591z0A== X-YMail-OSG: pF7O1e4VM1n9awcKFt0PD3XKR1ty60cP64ZsdOpNldjAxafV1w0E8XOxCyVj8hI j1nr67HDGJMImJSfEVrv054gfVKmRdyn5ElrahQKge68hHEH41FE5q7ZXT7dsrl_cxLyjuD6DIx1 4lvNzrg.q6HInWC.qr8hvotyaLjjoLA1pAcGgFUXSUNMLJzjOX28ComfekwH5rqf748sMqU.R61o g5fQaokr8X5sBZhQ_aIX.6v81O3LD_G47J9DR7iN2qZ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0TsEmqa1K84uALtQ Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:53:13 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp430.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 740888a1156cdff0756b5bee8a218310; Sun, 02 Jun 2019 16:53:08 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 33/58] Smack: Restore the release_secctx hook Date: Sun, 2 Jun 2019 09:50:36 -0700 Message-Id: <20190602165101.25079-34-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The secid_to_secctx() hook has to be balanced with a release_secctx hook for stacking. This hook does nothing. Signed-off-by: Casey Schaufler --- security/smack/smack_lsm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 38ea48d22547..a837af153ed9 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4470,10 +4470,11 @@ static int smack_secctx_to_secid(const char *secdata, u32 seclen, } /* - * There used to be a smack_release_secctx hook - * that did nothing back when hooks were in a vector. - * Now that there's a list such a hook adds cost. + * There smack_release_secctx hook does nothing */ +static void smack_release_secctx(char *secdata, u32 seclen) +{ +} static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) { @@ -4713,6 +4714,7 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = { LSM_HOOK_INIT(ismaclabel, smack_ismaclabel), LSM_HOOK_INIT(secid_to_secctx, smack_secid_to_secctx), LSM_HOOK_INIT(secctx_to_secid, smack_secctx_to_secid), + LSM_HOOK_INIT(release_secctx, smack_release_secctx), LSM_HOOK_INIT(inode_notifysecctx, smack_inode_notifysecctx), LSM_HOOK_INIT(inode_setsecctx, smack_inode_setsecctx), LSM_HOOK_INIT(inode_getsecctx, smack_inode_getsecctx), From patchwork Sun Jun 2 16:50:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971923 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8DD0E14DB for ; Sun, 2 Jun 2019 16:53:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EBA1286E4 for ; Sun, 2 Jun 2019 16:53:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 734DF28A08; Sun, 2 Jun 2019 16:53:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C2B8286E4 for ; Sun, 2 Jun 2019 16:53:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727001AbfFBQxL (ORCPT ); Sun, 2 Jun 2019 12:53:11 -0400 Received: from sonic305-8.consmr.mail.bf2.yahoo.com ([74.6.133.47]:37449 "EHLO sonic305-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726789AbfFBQxL (ORCPT ); Sun, 2 Jun 2019 12:53:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494390; bh=VEDYIM3R1NMqedNbn6scDMcxUUfpt0y9Ccbwl5mHx6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=BHxUuw7ir0TiQjAsxuK9YW3NBArfHpRoIYgkkYDalA+VwNbHW5P5XfspRUU+TiJM6TNn6DpXKTdWfcU3649JJ47WxfjJD5aNMnS7rXqtqY3XyaCUK9sf7joPDXctgmRSvlFAftcXuS8j/EU0yCkIlG4k2isGSvPKh1UXY9UTDmyUOEGa1ldBz0xMNhlFIbU3R/aBTqVOT1yjp37laDrQeSGpRkiLFjB7AVaz03rNR0Ur+LruUvqmtNeq0m8aiu0y60vJvciSXeBMVGGHWWZ/etXMj1/4Aa8EaHw+XNlcLngX4EtTIC70h3DqR5ry4keKgngoqELmE0xUAFE9rgxczA== X-YMail-OSG: UnHewdQVM1npGHJz0_Zujs2p_zDfigqvXyaTFxBdwvP_cdShwwsURiVO7Q7geQG bVhgjKFJ1mEZpOsi24UHrJtelqmVIIhvDdtiyBMsZr0FE7nU.VGu3O09fIOyyxzJiZZX2JyLrvNM oJpDauGX1V27ZEmUx.uedbL7tPzRG3QqspWCIR9YBYD.kEuS5VJTnpH_qGcufdE76a5nQy5EmNCw 2igF8G48Ievc_b4_3VDp6QYkUbMVLEzLL1eRtDmLmeVE.e_YbykudhrOU.pIebB609Q_BTR20j1m _IJq15C_gGC8tAaLKJu9S3CgyGk2LWUQc9rNvm5SV7IJgSB_BhBATob08Pa6pBSU8xFcHh0T4qBn 63obH6R9HD_x.w.wVzFTr3vxVAImjqzRg1J1r0dtYCiOOljLyhbvkB9xoP8BaNOPDTwvJ6_2dCmW mczKnkGtZslOI4JJjzG85UuhjBgX1QVYIjSbqB9Bxw0lkZy3jO.1lYuV3ubMbzbmNs77pFVdk1dl XxVFTijrs.YPdMXRJtfDF4s5E.1UNAzta6VUkmMKNZMARHm5iGQ19_w.9hwPF1rHtBlSi3c7dnOR y8X6lTrkcnkQcPyBe6hp0w.1FSpsfMQyp2KYxLnHfqHPIvlrbEJkEX_.YpR_r3w5ivY2b.gekLe_ NNqFqGmOyHSE855QV7HNwMt2.DN5SOmVrWy6tMrwtTbSl8urMinWRZz8ytCKx6mqowrwWsClFVYg Dugkk4LHo1j9MI1PGbjYgbveLbtsAwbQN788aGaZjK9DW6qcSI38.P15TGU150_sq0d49jF5.5Ke jCk3ng0yv7bBFNUIs35Dg9L8YfYNHlPMFqsVmKGIh41DbSwVAI5zB_S3y1qk23qa7aDLR0n6jaV1 m1HytTUZPWiISpyYBQYwroAbDZO9EXqivQS1CcT8pz9IysuLlnvIyAi1DbNmZVrLYeF14seni9WV Rlg2Yp2Dntn3WYwTlZbs26QGm1Z5pW46TC33_XCmwA.3PVQ1xLWpHhEtQOg9b7p7DfTzlVeFP5y6 UV22nzMVYY6aR31qVv9pCejPHL1TyeMlkn6TUXUApQkKrU9xeZzqMOXFglImEOHz1r44hOCN18pQ rcpoYvfF.9XWvEYGxz9_hiBXQKnfXDtv8mxWyfFMA04fsvwu3yg2TlMYYyBb_EbGdbI3OPK9TRe6 Mv8R7X1GjMMgVJ5X4jXiGgbaNF8W4uPZ6UG7kDi6oaPJC8_m.xMSfp6TSHYtzxQrCKFuTSHyA872 xOx1dORDTcB8GI6BD1bX2D7JkZfCHVikR.kfUchSu9b2FjQfTXxzKGNQ- Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:53:10 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp430.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 740888a1156cdff0756b5bee8a218310; Sun, 02 Jun 2019 16:53:09 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 34/58] AppArmor: Remove unnecessary hook stub Date: Sun, 2 Jun 2019 09:50:37 -0700 Message-Id: <20190602165101.25079-35-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Remove the getpeersec_dgram hook stub. It's unnecessary and disrupts stacking. Signed-off-by: Casey Schaufler --- security/apparmor/lsm.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 24b638bd4305..76c409737370 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -1094,15 +1094,9 @@ static int apparmor_socket_getpeersec_stream(struct socket *sock, * @secid: pointer to where to put the secid of the packet * * Sets the netlabel socket state on sk from parent + * + * The TODO stub interfered with stacking and was removed - Casey */ -static int apparmor_socket_getpeersec_dgram(struct socket *sock, - struct sk_buff *skb, - struct lsm_export *l) - -{ - /* TODO: requires secid support */ - return -ENOPROTOOPT; -} /** * apparmor_sock_graft - Initialize newly created socket @@ -1202,8 +1196,6 @@ static struct security_hook_list apparmor_hooks[] __lsm_ro_after_init = { #endif LSM_HOOK_INIT(socket_getpeersec_stream, apparmor_socket_getpeersec_stream), - LSM_HOOK_INIT(socket_getpeersec_dgram, - apparmor_socket_getpeersec_dgram), LSM_HOOK_INIT(sock_graft, apparmor_sock_graft), #ifdef CONFIG_NETWORK_SECMARK LSM_HOOK_INIT(inet_conn_request, apparmor_inet_conn_request), From patchwork Sun Jun 2 16:50:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971935 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2633C14DB for ; Sun, 2 Jun 2019 16:53:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 177571FF40 for ; Sun, 2 Jun 2019 16:53:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B77928703; Sun, 2 Jun 2019 16:53:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA0541FF40 for ; Sun, 2 Jun 2019 16:53:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727020AbfFBQxR (ORCPT ); Sun, 2 Jun 2019 12:53:17 -0400 Received: from sonic305-8.consmr.mail.bf2.yahoo.com ([74.6.133.47]:41300 "EHLO sonic305-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727003AbfFBQxQ (ORCPT ); Sun, 2 Jun 2019 12:53:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relax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DvBKBM 3cOs6aj95PC4LI.CjMrAmhSJ.UQqs.Igm8LQD4vJppvmtoJFCY_spVObDb3SPW.YHXY9RrOz1sZG rI5HbF_huT1lb58w4YYbzjoy3UyeKceTFH6OCUFsHHl7n_DyRUyRUDZATAzIwGWRY1I9cdPeCVEH vz5ElHSKnw0WaNLioSSLKWk4vJ.J_V0vajwYKUfAYSgX0.fyAVWzc5NW40bowTelqZP7qk9EKhtG VMZRfLSGpKAiOjCPIikk7US5jZOtFe6Kwq2h9Hzkd05IHV_gKqAwO_AYUF.jhPtmM1xV9Y19iSr2 f2b5zY1ScSXdLSfdmFKzNplA10bMqPx.uKE8lUGwUfqzhg2kRctdUk8EozV4PfKdtleTwy.CwSq3 YfCzSFrr1euC7DC6PcL3.JDapi0K1958_KZ1IP6tJsUVvm.4zWZEu_t8udLOZU1NBx3EtFERbT20 EIKDdNCXw_HrA8Dz9Ni3WaeI0w.ui8ggOtoxQtqadXjOW8BMhUn1xo1IaKab3.GckXO.YY4xxrBm TztwhbrZ9U_c4SKCTgRdjztg9kwhulKd2JZhFVPFwKqLFnyP.b72bS4AYjs73GLBZFRQawuykI54 _Nxt1SBHzy19iPgzphz7afxgPmsNIjiFC4Eb08y7_Kbz.YyQb_V6S6xpF94jaGCgaJro25WVCdl4 HkTVLQkQO24LfrABmmY7QXaTqLZvqb5X__Gh1jArBJklANIWkRrnLvnF0Og-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:53:15 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp430.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 740888a1156cdff0756b5bee8a218310; Sun, 02 Jun 2019 16:53:11 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 35/58] LSM: Limit calls to certain module hooks Date: Sun, 2 Jun 2019 09:50:38 -0700 Message-Id: <20190602165101.25079-36-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP LSM hooks dealing with security context strings should only be called for one security module. Add call macros that invoke a single module hook and us in for those cases. Signed-off-by: Casey Schaufler --- security/security.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/security/security.c b/security/security.c index 69983ad68233..365970f2501d 100644 --- a/security/security.c +++ b/security/security.c @@ -698,6 +698,16 @@ int lsm_superblock_alloc(struct super_block *sb) P->hook.FUNC(__VA_ARGS__); \ } while (0) +#define call_one_void_hook(FUNC, ...) \ + do { \ + struct security_hook_list *P; \ + \ + hlist_for_each_entry(P, &security_hook_heads.FUNC, list) { \ + P->hook.FUNC(__VA_ARGS__); \ + break; \ + } \ + } while (0) + #define call_int_hook(FUNC, IRC, ...) ({ \ int RC = IRC; \ do { \ @@ -712,6 +722,19 @@ int lsm_superblock_alloc(struct super_block *sb) RC; \ }) +#define call_one_int_hook(FUNC, IRC, ...) ({ \ + int RC = IRC; \ + do { \ + struct security_hook_list *P; \ + \ + hlist_for_each_entry(P, &security_hook_heads.FUNC, list) { \ + RC = P->hook.FUNC(__VA_ARGS__); \ + break; \ + } \ + } while (0); \ + RC; \ +}) + /* Security operations */ int security_binder_set_context_mgr(struct task_struct *mgr) @@ -1951,7 +1974,8 @@ EXPORT_SYMBOL(security_ismaclabel); int security_secid_to_secctx(struct lsm_export *l, char **secdata, u32 *seclen) { - return call_int_hook(secid_to_secctx, -EOPNOTSUPP, l, secdata, seclen); + return call_one_int_hook(secid_to_secctx, -EOPNOTSUPP, l, secdata, + seclen); } EXPORT_SYMBOL(security_secid_to_secctx); @@ -1959,13 +1983,13 @@ int security_secctx_to_secid(const char *secdata, u32 seclen, struct lsm_export *l) { lsm_export_init(l); - return call_int_hook(secctx_to_secid, 0, secdata, seclen, l); + return call_one_int_hook(secctx_to_secid, 0, secdata, seclen, l); } EXPORT_SYMBOL(security_secctx_to_secid); void security_release_secctx(char *secdata, u32 seclen) { - call_void_hook(release_secctx, secdata, seclen); + call_one_void_hook(release_secctx, secdata, seclen); } EXPORT_SYMBOL(security_release_secctx); @@ -2090,7 +2114,7 @@ EXPORT_SYMBOL(security_sock_rcv_skb); int security_socket_getpeersec_stream(struct socket *sock, char __user *optval, int __user *optlen, unsigned len) { - return call_int_hook(socket_getpeersec_stream, -ENOPROTOOPT, sock, + return call_one_int_hook(socket_getpeersec_stream, -ENOPROTOOPT, sock, optval, optlen, len); } From patchwork Sun Jun 2 16:50:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971941 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF2716C5 for ; Sun, 2 Jun 2019 16:53:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE3041FF40 for ; Sun, 2 Jun 2019 16:53:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2515289FA; Sun, 2 Jun 2019 16:53:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 651AD1FF40 for ; Sun, 2 Jun 2019 16:53:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727036AbfFBQx1 (ORCPT ); Sun, 2 Jun 2019 12:53:27 -0400 Received: from sonic310-27.consmr.mail.gq1.yahoo.com ([98.137.69.153]:40402 "EHLO sonic310-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727026AbfFBQx0 (ORCPT ); Sun, 2 Jun 2019 12:53:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494405; bh=K172cq+NB5Z0YjmWFKPzhzudN0HRFKrT7HKe6u3/BmU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=LVo5p4TN1N2ORA84bDvRKV4uU7w90WE8lBTggB2/TnHkVuOt3PJKWGR19QMa6JPzTYv9uvQXA0blNCjy4EYp+fRCf20+JVUs4Hgx+UJAfP4R/2wKyuCpZICV3I2DqVpL1hFumeWctc+7gdI7mF+RiOnhrlMPLKa7De5QepEnSPnW2bWle/YI0H+S7aEIxNCgkoN48AKwxzm7hH3Eg4KNLHvBRE1pBbhEdYMqGppvACiZW4QRT8fvnDKCEntUZ0eWbuJJ0wgbvogcoRRSXIO6rvaSh5OTEscgPM5c9/2OlffsE8C0w2JrQ5KE3Y/CvjSOwmRxS7k1WQadPWk24pQaqA== X-YMail-OSG: y9JupqQVM1lcoiwfRXcZhtOXqOX0lYs_su_lc8vG9XsbUo.UDGLUo8ow0yWE4PI m65dwKAsO2kGLXZKY2Q4qXBG629zcljCjY26cSpOKRFU0IOx.ePBYlZBmdzE7cUTXvCN8VbY23xH GfxwKYJPqN.s5exHbwQqcRUK8gfl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_misf7GzQY7FGy7bFnIqNwgn5VQ7kY4TXPYFu qVEtygVslk2dNWzakj1d6bDpbp9vOYq6B5pNx0bWBP8fvyV_jBMYA6g-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.gq1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:53:25 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp414.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 037f0ce5b74e0a8af50a9035f5845b74; Sun, 02 Jun 2019 16:53:23 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 36/58] LSM: Create a data structure for a security context Date: Sun, 2 Jun 2019 09:50:39 -0700 Message-Id: <20190602165101.25079-37-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A "security context" is the text representation of the information used by LSMs. This provides a structure so that the use can be made consistant. Signed-off-by: Casey Schaufler --- include/linux/security.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/security.h b/include/linux/security.h index dde36e850cf0..e12b169deed6 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -116,6 +116,17 @@ static inline bool lsm_export_equal(struct lsm_export *l, struct lsm_export *m) return true; } +/* Text representation of LSM specific security information - a "context" */ +struct lsm_context { + char *context; + u32 len; +}; + +static inline void lsm_context_init(struct lsm_context *cp) +{ + memset(cp, 0, sizeof(*cp)); +} + /* These functions are in security/commoncap.c */ extern int cap_capable(const struct cred *cred, struct user_namespace *ns, int cap, unsigned int opts); From patchwork Sun Jun 2 16:50:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971937 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AC2DD6C5 for ; Sun, 2 Jun 2019 16:53:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9AFF51FF40 for ; Sun, 2 Jun 2019 16:53:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F8B1289FA; Sun, 2 Jun 2019 16:53:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5E971FF40 for ; Sun, 2 Jun 2019 16:53:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727028AbfFBQxZ (ORCPT ); Sun, 2 Jun 2019 12:53:25 -0400 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:36361 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727003AbfFBQxZ (ORCPT ); Sun, 2 Jun 2019 12:53:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494404; bh=1xMyB3SejRKDCdQmKeBsMf7OEE0vB0tP/pBY2Hpzm7I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=S76Y3s8Fe6DqZRtPt2C2t4gR9MgIPKBPzHNdtutDlKrTwh3HzJDeTK0WQeULNF4M2XK45+BTVo/YfRvxt24GysPMZiCpaAcDG0tkbBzUqEVlvVXv76P4bQmNG+taBmOXBwToCo+Y5ABjBDTc64M3A1e5n/mqhvkFiYRA1T+0aCRW+Miy1q27FnFOSSpjM4iHw3aQ4pzrYDYZ5BfRff9zD7ySle/G0ptqmqDxuQ93cyUwvZnEEmGFo86cLQczXDmf0eoIjDdCi3C5pKBijH3BBV59Suoew/d0/Z2e6iKmLXuVTA56yqyPdjkSpe5rN6nnvmjGY7hJ3RKoJV+ZjQ1JEw== X-YMail-OSG: x.Ly5qMVM1kBQz4ix_5qE.JcmKie6rZ5pDwN61Nvp91ihu9.xuMQj2V242.pSyP N5Fbbx24Bgk4wDU2nKlgwvXQIIgJnmXN72ufzIhDXVej.soAVX29IopIFZYwV49Qs1mHrUc7MSqC JJ5ChwpM5E58ohWIWjMUH4k9q4WeBieMhpFC6vMAThi6ObcB0H.mB698uXterga.ykeeCCR6vvdu DxfJ0180hqPInw1iehK_UEtMLu0rZMi7C2qhV9J2p55gL_LxWGURCycgV8NC_NypJiJb06RUFewO cm7GxAwiocIV5JTZKjn5.jPqulEqK5EjPqW0DfTW_QLdpzfh9Hk3PdQGPAboqbLUFjzr8_8IAA0z fMkfAKpFfdvIU.GKkYo.qytzja5wlK8xkprOV570FMWmTswM24c8rkshFR6T3zdH95zRLsgY6QJO IGKUgWUZojTFitXTLbAR9jhhcLOxoEVcxcWA0h7Xe7KDEiLSl_ac.tqtWJbCQQmDySljzk3TRtUc IQolL6B3PjtKURXVePt1qEhnIQsudtChwOFkPgucts_uFoCoj9XHveutPomgC5JIAgPKyuMrYmMl W8asxjxJYqbq6p8_5E2yedfYGC7P0UU15OkQV5mzWCgZW1vtESDcF_ppLnnz8q3zvqO34nhyYKDB 7lTYElMJ2DWmIZt_y5LtBSVdvX7CBX5LInvm5NfS4UK58vk.KU0n29rTrQru8Nxk9qB0Rb5QCoPV v.a1e3bdBK2ShqZCjOB4imbS_V9ruPgMUoNND02ZF26dPrO8k69d2taviJ7XuM9YVYwsT8200RYm WcLxanmf8a9GznT.Fmti0ZrhdagEyF0FEP_Q6QR9rwI2Sch7Hyfquf.9Akd0WHjpgNyZrICyHzyY iNX2w3lG7G2cLMxR_uMNLZZMH9M135AHeDlnpVrCSDgJVmsSEHsOSr0IlFpfUjHsrrh5hm6ltana ..LvQ1yxAMZ_BpoGcUX07asnN.L7FCyVVHkY2V17jdbLQtGWv0A8USqQZYbzsc8T73Xh.jQo6NVr Yr19i_gyQxNiJMG8PmCBZ4WiRHnMu81_a13Dy1cqmpW49zpj_7a10Z706aXenkzaHPCwO5XZcO5X YuYT3EQos1.6bODZ92_d0hfLNq4xjgSL5lkZpc_YAXs2rVjS8XTanNMzV2LdvrN2GoO5XzwmNbhr 7V9eEJsurH0C_DpyxG6zuaDd01z7Ho4kiu9xYwllzsuV4_YSGDiymPxKDN8v4.A0KD3w9lCS4lXe 7o6xs0UeJunt7waM7dDXyOARJm5C.OE8NcVy5CPKGFRfSbIr63A7GSg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:53:24 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp414.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 037f0ce5b74e0a8af50a9035f5845b74; Sun, 02 Jun 2019 16:53:23 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 37/58] LSM: Use lsm_context in secid_to_secctx hooks Date: Sun, 2 Jun 2019 09:50:40 -0700 Message-Id: <20190602165101.25079-38-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert SELinux, Smack and AppArmor to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 6 ++---- security/apparmor/include/secid.h | 2 +- security/apparmor/secid.c | 11 +++++------ security/security.c | 12 ++++++++++-- security/selinux/hooks.c | 5 ++--- security/smack/smack_lsm.c | 8 +++----- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 0837c214cc17..229899452678 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1320,9 +1320,8 @@ * length and the next call which actually allocates and returns the * secdata. * @l points to the security information. - * @secdata contains the pointer that stores the converted security + * @cp contains the pointer that stores the converted security * context. - * @seclen pointer which contains the length of the data * @secctx_to_secid: * Convert security context to exported lsm data. * @l contains the pointer to the generated security data. @@ -1664,8 +1663,7 @@ union security_list_options { int (*getprocattr)(struct task_struct *p, char *name, char **value); int (*setprocattr)(const char *name, void *value, size_t size); int (*ismaclabel)(const char *name); - int (*secid_to_secctx)(struct lsm_export *l, char **secdata, - u32 *seclen); + int (*secid_to_secctx)(struct lsm_export *l, struct lsm_context *cp); int (*secctx_to_secid)(const char *secdata, u32 seclen, struct lsm_export *l); void (*release_secctx)(char *secdata, u32 seclen); diff --git a/security/apparmor/include/secid.h b/security/apparmor/include/secid.h index 5381eff03d4f..964d3dc92635 100644 --- a/security/apparmor/include/secid.h +++ b/security/apparmor/include/secid.h @@ -26,7 +26,7 @@ struct aa_label; #define AA_SECID_WILDCARD 1 struct aa_label *aa_secid_to_label(struct lsm_export *l); -int apparmor_secid_to_secctx(struct lsm_export *l, char **secdata, u32 *seclen); +int apparmor_secid_to_secctx(struct lsm_export *l, struct lsm_context *cp); int apparmor_secctx_to_secid(const char *secdata, u32 seclen, struct lsm_export *l); void apparmor_release_secctx(char *secdata, u32 seclen); diff --git a/security/apparmor/secid.c b/security/apparmor/secid.c index 69d98a89db75..4e11434605d6 100644 --- a/security/apparmor/secid.c +++ b/security/apparmor/secid.c @@ -81,7 +81,7 @@ static inline void aa_export_secid(struct lsm_export *l, u32 secid) l->apparmor = secid; } -int apparmor_secid_to_secctx(struct lsm_export *l, char **secdata, u32 *seclen) +int apparmor_secid_to_secctx(struct lsm_export *l, struct lsm_context *cp) { /* TODO: cache secctx and ref count so we don't have to recreate */ struct aa_label *label; @@ -89,13 +89,12 @@ int apparmor_secid_to_secctx(struct lsm_export *l, char **secdata, u32 *seclen) label = aa_secid_to_label(l); - AA_BUG(!seclen); - if (!label) return -EINVAL; - if (secdata) - len = aa_label_asxprint(secdata, root_ns, label, + /* scaffolding check - Casey */ + if (cp) + len = aa_label_asxprint(&cp->context, root_ns, label, FLAG_SHOW_MODE | FLAG_VIEW_SUBNS | FLAG_HIDDEN_UNCONFINED | FLAG_ABS_ROOT, GFP_ATOMIC); @@ -106,7 +105,7 @@ int apparmor_secid_to_secctx(struct lsm_export *l, char **secdata, u32 *seclen) if (len < 0) return -ENOMEM; - *seclen = len; + cp->len = len; return 0; } diff --git a/security/security.c b/security/security.c index 365970f2501d..ac0498daa49e 100644 --- a/security/security.c +++ b/security/security.c @@ -1974,8 +1974,16 @@ EXPORT_SYMBOL(security_ismaclabel); int security_secid_to_secctx(struct lsm_export *l, char **secdata, u32 *seclen) { - return call_one_int_hook(secid_to_secctx, -EOPNOTSUPP, l, secdata, - seclen); + struct lsm_context lc = { .context = NULL, .len = 0, }; + int rc; + + rc = call_one_int_hook(secid_to_secctx, -EOPNOTSUPP, l, &lc); + if (secdata) + *secdata = lc.context; + else + security_release_secctx(lc.context, lc.len); + *seclen = lc.len; + return rc; } EXPORT_SYMBOL(security_secid_to_secctx); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 7dd333f133db..6a2a82dcd948 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6301,14 +6301,13 @@ static int selinux_ismaclabel(const char *name) return (strcmp(name, XATTR_SELINUX_SUFFIX) == 0); } -static int selinux_secid_to_secctx(struct lsm_export *l, char **secdata, - u32 *seclen) +static int selinux_secid_to_secctx(struct lsm_export *l, struct lsm_context *cp) { u32 secid; selinux_import_secid(l, &secid); return security_sid_to_context(&selinux_state, secid, - secdata, seclen); + &cp->context, &cp->len); } static int selinux_secctx_to_secid(const char *secdata, u32 seclen, diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index a837af153ed9..10d6c6a1a001 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4434,8 +4434,7 @@ static int smack_ismaclabel(const char *name) * * Exists for networking code. */ -static int smack_secid_to_secctx(struct lsm_export *l, char **secdata, - u32 *seclen) +static int smack_secid_to_secctx(struct lsm_export *l, struct lsm_context *cp) { struct smack_known *skp; u32 secid; @@ -4443,9 +4442,8 @@ static int smack_secid_to_secctx(struct lsm_export *l, char **secdata, smack_import_secid(l, &secid); skp = smack_from_secid(secid); - if (secdata) - *secdata = skp->smk_known; - *seclen = strlen(skp->smk_known); + cp->context = skp->smk_known; + cp->len = strlen(skp->smk_known); return 0; } From patchwork Sun Jun 2 16:50:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971945 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 147F292A for ; Sun, 2 Jun 2019 16:53:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 049221FF40 for ; Sun, 2 Jun 2019 16:53:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED546289FA; Sun, 2 Jun 2019 16:53:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 777091FF40 for ; Sun, 2 Jun 2019 16:53:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727003AbfFBQx2 (ORCPT ); Sun, 2 Jun 2019 12:53:28 -0400 Received: from sonic316-12.consmr.mail.gq1.yahoo.com ([98.137.69.36]:43240 "EHLO sonic316-12.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727030AbfFBQx1 (ORCPT ); Sun, 2 Jun 2019 12:53:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494406; bh=eXghUWf7mncYNfyNil+VOWL4LtYvdtYwFUq87XTEKFY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=TKmzOipsbKI6thV74iSElZaYrTsc05RD7ltnaHy0pGbWEhd0u+F2ByO/YEu5fV4eNhsot8I1yDMLB45L319NEt1Q/5ExOpyTPCgdRUoHmDChKk2pLF0VNbhK8ljLszK4yBtHyGtwLIlEXcskMCsWAxWKsElDdnUNBDsGk5lEMtmxJNNDv2esuIKn98tyMlY7c6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dW3ovz18HTOD20AbRnLL9mFqveY7BaDt1WFtmZeCCTed0PbfCnpK2pA6NuPtfU0S4l14xcMSt J0u5dHKATNnhYvEHEatbocpapj7I_5a5BEY7FYh5W4qPyfgN_phZ2ma96igNgT_xw4hNLRCmVA2T 4C5Qxn7ZuM_5966BTrFYdQHYch0SpvRM0VN7to7gPKdHo_Q2sp6a4Bu_2vNqV_dH3IN8rO94CSpo kDH0BOPOt_wf95brxWUvYiDo2z6uysKVT4oNJuZXQ8KIEaXVpXnupwh_9t2JGZ.APABwPjrA_Z8T 1K27k.ICX1p7mRJ04IfqNP5BVu4cKUDomiTMgPmFsMmm0tfG7.zsRRR.ujHdbdFKI0jMNIP0sSWU cS1ijFXt145OWI2MhOGFzRYkSOkJC2cKnejJbSZ4FvpMgsLhOTCH9FA-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic316.consmr.mail.gq1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:53:26 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp414.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 037f0ce5b74e0a8af50a9035f5845b74; Sun, 02 Jun 2019 16:53:24 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 38/58] LSM: Use lsm_context in secctx_to_secid hooks Date: Sun, 2 Jun 2019 09:50:41 -0700 Message-Id: <20190602165101.25079-39-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert SELinux, Smack and AppArmor to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 4 ++-- security/apparmor/include/secid.h | 2 +- security/apparmor/secid.c | 7 +++---- security/security.c | 6 +++++- security/selinux/hooks.c | 4 ++-- security/smack/smack_lsm.c | 4 ++-- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 229899452678..c983d573a005 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1324,8 +1324,8 @@ * context. * @secctx_to_secid: * Convert security context to exported lsm data. + * @cp contains the security context. * @l contains the pointer to the generated security data. - * @secdata contains the security context. * * @release_secctx: * Release the security context. @@ -1664,7 +1664,7 @@ union security_list_options { int (*setprocattr)(const char *name, void *value, size_t size); int (*ismaclabel)(const char *name); int (*secid_to_secctx)(struct lsm_export *l, struct lsm_context *cp); - int (*secctx_to_secid)(const char *secdata, u32 seclen, + int (*secctx_to_secid)(const struct lsm_context *cp, struct lsm_export *l); void (*release_secctx)(char *secdata, u32 seclen); diff --git a/security/apparmor/include/secid.h b/security/apparmor/include/secid.h index 964d3dc92635..acfcf99bff0e 100644 --- a/security/apparmor/include/secid.h +++ b/security/apparmor/include/secid.h @@ -27,7 +27,7 @@ struct aa_label; struct aa_label *aa_secid_to_label(struct lsm_export *l); int apparmor_secid_to_secctx(struct lsm_export *l, struct lsm_context *cp); -int apparmor_secctx_to_secid(const char *secdata, u32 seclen, +int apparmor_secctx_to_secid(const struct lsm_context *cp, struct lsm_export *l); void apparmor_release_secctx(char *secdata, u32 seclen); diff --git a/security/apparmor/secid.c b/security/apparmor/secid.c index 4e11434605d6..35df38592b6e 100644 --- a/security/apparmor/secid.c +++ b/security/apparmor/secid.c @@ -110,13 +110,12 @@ int apparmor_secid_to_secctx(struct lsm_export *l, struct lsm_context *cp) return 0; } -int apparmor_secctx_to_secid(const char *secdata, u32 seclen, - struct lsm_export *l) +int apparmor_secctx_to_secid(const struct lsm_context *cp, struct lsm_export *l) { struct aa_label *label; - label = aa_label_strn_parse(&root_ns->unconfined->label, secdata, - seclen, GFP_KERNEL, false, false); + label = aa_label_strn_parse(&root_ns->unconfined->label, cp->context, + cp->len, GFP_KERNEL, false, false); if (IS_ERR(label)) return PTR_ERR(label); aa_export_secid(l, label->secid); diff --git a/security/security.c b/security/security.c index ac0498daa49e..84f27428b62d 100644 --- a/security/security.c +++ b/security/security.c @@ -1990,8 +1990,12 @@ EXPORT_SYMBOL(security_secid_to_secctx); int security_secctx_to_secid(const char *secdata, u32 seclen, struct lsm_export *l) { + struct lsm_context lc; + + lc.context = secdata; + lc.len = seclen; lsm_export_init(l); - return call_one_int_hook(secctx_to_secid, 0, secdata, seclen, l); + return call_one_int_hook(secctx_to_secid, 0, &lc, l); } EXPORT_SYMBOL(security_secctx_to_secid); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 6a2a82dcd948..a2257ccaee5c 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6310,13 +6310,13 @@ static int selinux_secid_to_secctx(struct lsm_export *l, struct lsm_context *cp) &cp->context, &cp->len); } -static int selinux_secctx_to_secid(const char *secdata, u32 seclen, +static int selinux_secctx_to_secid(const struct lsm_context *cp, struct lsm_export *l) { u32 secid; int rc; - rc = security_context_to_sid(&selinux_state, secdata, seclen, + rc = security_context_to_sid(&selinux_state, cp->context, cp->len, &secid, GFP_KERNEL); selinux_export_secid(l, secid); return rc; diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 10d6c6a1a001..78c01ef707eb 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4455,10 +4455,10 @@ static int smack_secid_to_secctx(struct lsm_export *l, struct lsm_context *cp) * * Exists for audit and networking code. */ -static int smack_secctx_to_secid(const char *secdata, u32 seclen, +static int smack_secctx_to_secid(const struct lsm_context *cp, struct lsm_export *l) { - struct smack_known *skp = smk_find_entry(secdata); + struct smack_known *skp = smk_find_entry(cp->context); if (skp) smack_export_secid(l, skp->smk_secid); From patchwork Sun Jun 2 16:50:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971949 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3CAE96C5 for ; Sun, 2 Jun 2019 16:53:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A3B3286E4 for ; Sun, 2 Jun 2019 16:53:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E8DA2873A; Sun, 2 Jun 2019 16:53:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FB3E1FF40 for ; Sun, 2 Jun 2019 16:53:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727038AbfFBQxa (ORCPT ); Sun, 2 Jun 2019 12:53:30 -0400 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:42202 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727030AbfFBQxa (ORCPT ); Sun, 2 Jun 2019 12:53:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494409; bh=zNmMomX7FtNuYn5Qpm3pclNFmgRY9BLATnDH4/IPw8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=aMpTOcLiL6ujpI5QGhUlcxkom4UoLJED/eCIlYT2G7c4q0Regke0VNaH9ksRDfZrjbd5y52824/3m1oFc/xPvGoVxSz8/IdDAqSSG1/V3xzLuDT0FNkdQYWWXdejFwWPky/VSuexn1D9ueSXgkwnv3z9kabA+YnUpD5euMcNr7X+xSAZSgv7NCuGf+d+/bPjmVgJUd080bCTyxtN0jVLxqpp33QPC9LiEurE1mJRA6etPxPBuFbdYXCVQ/IXDz24lH6f2iGTxFLQ5Tbult0xO3ywan2Sq3AAwT2qQDKpt0d5Tnx4VyLLfckSdtHP+X5T5HposhYSV86p+I5ZiVuW3g== X-YMail-OSG: l_5SAcAVM1nJIxoKOlXJ6ODQnh9GQbP8efptKpipssAffHeAdDRO8CisBOOuQdd HIOvm97oAgaVqd31kSDO0E0ycUgvBM5fV5ihoduZg7GC1U1Q3XNwHRJqLhKUcF4.lHArZSYHIabP fLt5fErWdMk2.YL8Pi3f0YSrsmvAg1m5UYF3hEZdnfrjJ0qxnKgqcXl.kQ3Y0ymmXZYzceilrdGU BwVCJl4.lQCpHoipGyIlpLCo4YiuD88TkhECS8JE9YXr4S_zFc9W2uts_uSQiufU6nQxTEvirQtT aNvAHM1Wf0cYCtWqnClgWdNDfrnbQyXYUo0sKj4Sxj1PGaa33TKDmr3_.DFFPb.xPQ.w_2mEF6yX SSKACqOihBkjuQtF76J5Cq4h_hlykGF7m0jKHo2P.AEShh.jpUqqX3.jRHaaP8buEcX7uj7DRi0A bMsEua.Uh7he9KR4rwtEuuHKrvsChjhYov.geH8sxiCq59MPHIYcoeZGaZ46c296Mt7X9iLcJV.r 5pLVSs_86NqS6Xz57_9Kn90X5AfawKWR.r53nOag4wR8PCxmLJUMde2g_hk7UP0Y5R9FPCftXJqb 2cRhis6Pl1Rr3ME_7kroeIU9Z_UbHmWYurBC0xtenakK.wUyvqSEkMGydOgKS9LvOyIKod.FqKS. OfxRrbln1Ej4iBsyAYy5C8HSsIXpEHjMxhleFkOVIFlxNMwsRkUF8ylwDNglL0f8UvR4unq6KDSa 0aukPEhcJOnO3Tkx0YX2pMopWi.grq0mOp1uIt7xe49SxsotspDprkaEqG8xNFVKfgnKsPHzZbMW AdiGx01ucHh9d92A0FmYCOLmsDDkfiz_9JR.cJ9NhlLjNYhBRyXipKRL6cEF7KmrrdiYtZhlM_X4 KoK8S9s6CkZfpYQKgAuTCfBAsF7INahPfsATM4Gx5dY3t8bnqlvYnlp8VtN5CevrR6NPg5dmaOKD N8uqVlaeWQ_7Hhaf.zHEMScit9zzg94oSjSncTXIxgbKFAo2fwIoIfWxjhFZdC0Ez8GUm.tlENCM 9GZke2bMLMve86.lO2rGDfjWB.OiQftMorDN3rqiisp0TmNt0bs1ry6lwjbWe_zCq2PXW75yfk6a WrbR.NUaooHk0A8amGx.9ZyLW00H94yYkn5jdzuYBf43wUCz_VR7xxtYRydnJW4e8ffs6CeZIJ4t xwu1kxXG6apSfJj6oXJv7LjBlIRSq6hRolxKEYEh2sC3oO3UaEvQGn23ydGWPdrQpqprReYWSeeC Lp5qBh50.YpyCC7dbVO.1Rt3UpNiIspAMFQ94hBLXk0jDXAkmozd87A-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:53:29 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp414.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 037f0ce5b74e0a8af50a9035f5845b74; Sun, 02 Jun 2019 16:53:25 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 39/58] LSM: Use lsm_context in inode_getsecctx hooks Date: Sun, 2 Jun 2019 09:50:42 -0700 Message-Id: <20190602165101.25079-40-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert SELinux and Smack to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 7 +++---- security/security.c | 11 +++++++++-- security/selinux/hooks.c | 6 +++--- security/smack/smack_lsm.c | 6 +++--- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index c983d573a005..20e59e0b775f 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1394,11 +1394,10 @@ * @ctxlen contains the length of @ctx. * * @inode_getsecctx: - * On success, returns 0 and fills out @ctx and @ctxlen with the security + * On success, returns 0 and fills out @cp with the security * context for the given @inode. * @inode we wish to get the security context of. - * @ctx is a pointer in which to place the allocated security context. - * @ctxlen points to the place to put the length of @ctx. + * @cp is a pointer in which to place the allocated security context. * * Security hooks for using the eBPF maps and programs functionalities through * eBPF syscalls. @@ -1671,7 +1670,7 @@ union security_list_options { void (*inode_invalidate_secctx)(struct inode *inode); int (*inode_notifysecctx)(struct inode *inode, void *ctx, u32 ctxlen); int (*inode_setsecctx)(struct dentry *dentry, void *ctx, u32 ctxlen); - int (*inode_getsecctx)(struct inode *inode, void **ctx, u32 *ctxlen); + int (*inode_getsecctx)(struct inode *inode, struct lsm_context *cp); #ifdef CONFIG_SECURITY_NETWORK int (*unix_stream_connect)(struct sock *sock, struct sock *other, diff --git a/security/security.c b/security/security.c index 84f27428b62d..0c23ffdd92c9 100644 --- a/security/security.c +++ b/security/security.c @@ -1992,7 +1992,7 @@ int security_secctx_to_secid(const char *secdata, u32 seclen, { struct lsm_context lc; - lc.context = secdata; + lc.context = (char *)secdata; lc.len = seclen; lsm_export_init(l); return call_one_int_hook(secctx_to_secid, 0, &lc, l); @@ -2025,7 +2025,14 @@ EXPORT_SYMBOL(security_inode_setsecctx); int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) { - return call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, ctx, ctxlen); + struct lsm_context lc = { .context = NULL, .len = 0, }; + int rc; + + rc = call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, &lc); + + *ctx = (void *)lc.context; + *ctxlen = lc.len; + return rc; } EXPORT_SYMBOL(security_inode_getsecctx); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index a2257ccaee5c..e881f42d3ff8 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6355,14 +6355,14 @@ static int selinux_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) return __vfs_setxattr_noperm(dentry, XATTR_NAME_SELINUX, ctx, ctxlen, 0); } -static int selinux_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) +static int selinux_inode_getsecctx(struct inode *inode, struct lsm_context *cp) { int len = 0; len = selinux_inode_getsecurity(inode, XATTR_SELINUX_SUFFIX, - ctx, true); + (void **)&cp->context, true); if (len < 0) return len; - *ctxlen = len; + cp->len = len; return 0; } #ifdef CONFIG_KEYS diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 78c01ef707eb..46eead699e1d 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4484,12 +4484,12 @@ static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) return __vfs_setxattr_noperm(dentry, XATTR_NAME_SMACK, ctx, ctxlen, 0); } -static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) +static int smack_inode_getsecctx(struct inode *inode, struct lsm_context *cp) { struct smack_known *skp = smk_of_inode(inode); - *ctx = skp->smk_known; - *ctxlen = strlen(skp->smk_known); + cp->context = skp->smk_known; + cp->len = strlen(skp->smk_known); return 0; } From patchwork Sun Jun 2 16:50:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971961 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 627206C5 for ; Sun, 2 Jun 2019 16:53:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50668286E4 for ; Sun, 2 Jun 2019 16:53:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4435328A00; Sun, 2 Jun 2019 16:53:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3EB3286E4 for ; Sun, 2 Jun 2019 16:53:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727040AbfFBQxn (ORCPT ); Sun, 2 Jun 2019 12:53:43 -0400 Received: from sonic303-27.consmr.mail.ne1.yahoo.com ([66.163.188.153]:46524 "EHLO sonic303-27.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727054AbfFBQxm (ORCPT ); Sun, 2 Jun 2019 12:53:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494421; bh=EacMflAD5VaKL1W6672XUiEDYF8wM5Kufsvl3z4Vcto=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=MSpIKJ0nFNK/T3q/bhaxG9U/AEnOFvlxLytdB9rrdaUxtBXLMPbIgrnSTgpCFddUgw6PxkIqGs5RUNWiR87TczxxyKaGkXo/SAYLi8K92SLV3XNJmQDHSYydiU2dEM5IKTbg7p7chae6YMV0HdfzwuhEdwyXa6lHZBfv9NX3BqxBJ3gBzJZ72hVIInV0xu4S7r8pyqcXsujDcnx0eN+GiQrYnznzC9ygvOROqLbLu1F2hmBMcnTJSBspGOZOzRhtai9eo70kj+OdSUUnlRJIu2XaOH4bU2NAbCYTkI1+RKCG4LSn6Kms5bW7sl8AXA1gvrIFMsEFN6PEHN71eHkRuA== X-YMail-OSG: ctgokzgVM1lCZ3mijAn_HOmGwCNJm6BmCv8y9Bqco6IVE9dSsXH1ZBvHst5_Wi4 fFYV_jZffHnY0m2.Q2oYVSkbq0dOW4oaWkex9WId_DRp8aezYxySu.WCsIzv3fHvTfcErwFFXkmt MjgI0NS3FlevmfUC2LWpLTRtOdMDJ1MRVdYTN1taycgOt54ulItu6hIOqGFBZBw2ZKHPkb6hE2pv SrBBAaLugq15o5Hd1FcLxeenKJRCUAp5UNwhSWc7krMy5auh_bTZJ0Y0oCbxJ9FVKH8mibq05B67 SCoSFrd3IaaBU0dEuLGI3ADhS9YV477GtWsBSeB0dUejzSYnls7uLKViORhDODDWOCL6F542KzQ_ soXX2wjMR.fbNEHI75ei2LTkmnqWd5b6r0dBryHrw2noLm_luP1mEUxLIXQhUoussn9iJzp46PfU TnCCjCifF37ZdDsyq_C8yQF6iTxlxRg2aQc3gVnnWuYiTIBC0ls2UTidmiSj0IiSvEuHVsSfcm4c UzC0iUUu_fQ2eCBnY0vWsACl2rDYnPhzuxCSvR3wYKlgcoYQhhkr42g1NSVTIQPLCCFK2SgfCiTu KZJ0LIvldVeqof5r1IjOyXUENkK7VNDMmIHvL7F2H37f0uePA6TK0KZ3DbY5LLRhxg2nD3QTNq9P KElHUq7b2oTQrdPQra2iMmQ7S1UcVWCJ8d3LlOY2.eRzhm98x9rf05c4yyukwzlQAyj.Du1Vnd0f VqWKHoyS09ghN_tlCCNhJhktgp8c1x8OwcZbHpS.y6_noNVg_oTEjL.z98e0fs8s6nnniKEs41NV XITkoznkJr6ZXWbtM32iIMNg6C0yG.9lOgGNiojOoGReuKYzELM7OL3pPxjHynEKDkWwKkSL0AfJ 56LLdeZoJMZrGTQhgsH1aavpgveTIEGHd4TP1EivG3Anto6M_nunefWNc3EHWypApCVgCiP7oStm F7UehSd7dKYdT9QJo1FUO.hU1DH1thblEBOrB.rrXPujutiPxck.rZuW3goi3dqmPEbIQItiZsOZ EHJLTTV569RIE2do6PfhQ4nPqkWQRUrnlL3z2foPA22dN5QqOZKCD6yemdoEO_9PdKk7jqq_VmVU DraA8cPoLIC.mFjONTUlzJu4T6CJ3cIAv5Pbk8C231TIA.hMfwzpIeS8qKfK0W5XUoOcy2vPDw75 cfMCI56tGjdffTNu5I3CvIqcMFC6SGJ3HYTFqQJ_O76TvIkH41ECwnGXjNkAo7TfLFrTza6WzMHf B.2zqQz1qgvFFW2F0wMqCWob5eoYpagtPqS3WXFnAjssyU4OZ8fdgLGSO01Y- Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:53:41 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp409.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 111e227deeb5369cccd8023f32784fec; Sun, 02 Jun 2019 16:53:36 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 40/58] LSM: Use lsm_context in inode_notifysecctx hooks Date: Sun, 2 Jun 2019 09:50:43 -0700 Message-Id: <20190602165101.25079-41-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert SELinux and Smack to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 5 ++--- security/security.c | 6 +++++- security/selinux/hooks.c | 5 +++-- security/smack/smack_lsm.c | 5 +++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 20e59e0b775f..eda0a1bcdf07 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1377,8 +1377,7 @@ * file's attributes to the client. * Must be called with inode->i_mutex locked. * @inode we wish to set the security context of. - * @ctx contains the string which we wish to set in the inode. - * @ctxlen contains the length of @ctx. + * @cp contains the string which we wish to set in the inode. * * @inode_setsecctx: * Change the security context of an inode. Updates the @@ -1668,7 +1667,7 @@ union security_list_options { void (*release_secctx)(char *secdata, u32 seclen); void (*inode_invalidate_secctx)(struct inode *inode); - int (*inode_notifysecctx)(struct inode *inode, void *ctx, u32 ctxlen); + int (*inode_notifysecctx)(struct inode *inode, struct lsm_context *cp); int (*inode_setsecctx)(struct dentry *dentry, void *ctx, u32 ctxlen); int (*inode_getsecctx)(struct inode *inode, struct lsm_context *cp); diff --git a/security/security.c b/security/security.c index 0c23ffdd92c9..4f443dd481bd 100644 --- a/security/security.c +++ b/security/security.c @@ -2013,7 +2013,11 @@ EXPORT_SYMBOL(security_inode_invalidate_secctx); int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) { - return call_int_hook(inode_notifysecctx, 0, inode, ctx, ctxlen); + struct lsm_context lc; + + lc.context = ctx; + lc.len = ctxlen; + return call_int_hook(inode_notifysecctx, 0, inode, &lc); } EXPORT_SYMBOL(security_inode_notifysecctx); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index e881f42d3ff8..633d62b97e90 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6339,10 +6339,11 @@ static void selinux_inode_invalidate_secctx(struct inode *inode) /* * called with inode->i_mutex locked */ -static int selinux_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) +static int selinux_inode_notifysecctx(struct inode *inode, + struct lsm_context *cp) { int rc = selinux_inode_setsecurity(inode, XATTR_SELINUX_SUFFIX, - ctx, ctxlen, 0); + cp->context, cp->len, 0); /* Do not return error when suppressing label (SBLABEL_MNT not set). */ return rc == -EOPNOTSUPP ? 0 : rc; } diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 46eead699e1d..3d24503029e5 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4474,9 +4474,10 @@ static void smack_release_secctx(char *secdata, u32 seclen) { } -static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) +static int smack_inode_notifysecctx(struct inode *inode, struct lsm_context *cp) { - return smack_inode_setsecurity(inode, XATTR_SMACK_SUFFIX, ctx, ctxlen, 0); + return smack_inode_setsecurity(inode, XATTR_SMACK_SUFFIX, cp->context, + cp->len, 0); } static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) From patchwork Sun Jun 2 16:50:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971955 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A79B14DB for ; Sun, 2 Jun 2019 16:53:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A36A289FA for ; Sun, 2 Jun 2019 16:53:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B9AC1FF40; Sun, 2 Jun 2019 16:53:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2E2B1FF40 for ; Sun, 2 Jun 2019 16:53:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727056AbfFBQxm (ORCPT ); Sun, 2 Jun 2019 12:53:42 -0400 Received: from sonic310-30.consmr.mail.ne1.yahoo.com ([66.163.186.211]:45386 "EHLO sonic310-30.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727047AbfFBQxm (ORCPT ); Sun, 2 Jun 2019 12:53:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494420; bh=Si7Q6Qio/TpjyKyKBImiMFKuwDNX1UAPNk8f8AqjWng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=NjEIdKSg16MYQRaMfEFQAY1rT2UwJ6VZ+S2ch+lTAM3uWrOoUkrg8JKDJ0WpHoDSh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kJqxHszVGt3ez5n1sioKmljPB5Rfc5Ad10YRV_0 A_bJeBz6Vi9s6MpXdmanTpQ08bx.NUyA6jjsSayeElC4gYGtWqS_s1aGK7HgUU3k50kJkRraiVpz udoQjCL1DK2DOdREfciq2mUok5m3p890kDYjSvt.m_SVJW8mMVeZOFinPvzE5iTwzxIrJIjvUFFM VgpJ3ZSo2me9m6IjA6t1GCHQ5h6i3r4ZpPsyIN9dARmPqqBnGFrpm1Z.1lonPnIgoTku2ZqAnQ_O ei.wafnu5GfMRQm3C64CLE2Hcn_dZ6r9GhGScQYyAX2CpWylfpTyIZWPcAy8JYWnlvEmyhihv5Uh 4iW_t9o_159eGnaktaTGYOpVPdda8Rmi0n4L1uW7q9V_FE5Pk8xWyG0x8x3CfJsZIdQRRN_Al63s 3N6MSgpfYyyDdSZ0xVr60vXTSYwxzz_S2y3WgoFQ412pDTIGfja8n5dSjz.KExuT7THFSZUhQrIl VCETDuT6kDUgPDw7ZzWiiNOyXEuKmOcp0Rno89Kh4sZNjWCbC2gO5pA-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:53:40 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp409.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 111e227deeb5369cccd8023f32784fec; Sun, 02 Jun 2019 16:53:37 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 41/58] LSM: Use lsm_context in dentry_init_security hooks Date: Sun, 2 Jun 2019 09:50:44 -0700 Message-Id: <20190602165101.25079-42-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Casey Schaufler Convert SELinux to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 7 +++---- security/security.c | 10 ++++++++-- security/selinux/hooks.c | 8 ++++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index eda0a1bcdf07..d4ace7af4950 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -165,8 +165,7 @@ * @dentry dentry to use in calculating the context. * @mode mode used to determine resource type. * @name name of the last path component used to create file - * @ctx pointer to place the pointer to the resulting context in. - * @ctxlen point to place the length of the resulting context. + * @cp pointer to place the pointer to the resulting context in. * @dentry_create_files_as: * Compute a context for a dentry as the inode is not yet available * and set that context in passed in creds so that new files are @@ -1492,8 +1491,8 @@ union security_list_options { int (*sb_add_mnt_opt)(const char *option, const char *val, int len, void **mnt_opts); int (*dentry_init_security)(struct dentry *dentry, int mode, - const struct qstr *name, void **ctx, - u32 *ctxlen); + const struct qstr *name, + struct lsm_context *cp); int (*dentry_create_files_as)(struct dentry *dentry, int mode, struct qstr *name, const struct cred *old, diff --git a/security/security.c b/security/security.c index 4f443dd481bd..c04b334370a5 100644 --- a/security/security.c +++ b/security/security.c @@ -1017,8 +1017,14 @@ int security_dentry_init_security(struct dentry *dentry, int mode, const struct qstr *name, void **ctx, u32 *ctxlen) { - return call_int_hook(dentry_init_security, -EOPNOTSUPP, dentry, mode, - name, ctx, ctxlen); + struct lsm_context lc = { .context = NULL, .len = 0, }; + int rc; + + rc = call_int_hook(dentry_init_security, -EOPNOTSUPP, dentry, mode, + name, &lc); + *ctx = (void *)lc.context; + *ctxlen = lc.len; + return rc; } EXPORT_SYMBOL(security_dentry_init_security); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 633d62b97e90..fe09905d013c 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -2813,8 +2813,8 @@ static void selinux_inode_free_security(struct inode *inode) } static int selinux_dentry_init_security(struct dentry *dentry, int mode, - const struct qstr *name, void **ctx, - u32 *ctxlen) + const struct qstr *name, + struct lsm_context *cp) { u32 newsid; int rc; @@ -2826,8 +2826,8 @@ static int selinux_dentry_init_security(struct dentry *dentry, int mode, if (rc) return rc; - return security_sid_to_context(&selinux_state, newsid, (char **)ctx, - ctxlen); + return security_sid_to_context(&selinux_state, newsid, &cp->context, + &cp->len); } static int selinux_dentry_create_files_as(struct dentry *dentry, int mode, From patchwork Sun Jun 2 16:50:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971953 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ECE0E6C5 for ; Sun, 2 Jun 2019 16:53:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC78F1FF40 for ; Sun, 2 Jun 2019 16:53:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0D2D2873A; Sun, 2 Jun 2019 16:53:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BFB11FF40 for ; Sun, 2 Jun 2019 16:53:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727055AbfFBQxm (ORCPT ); Sun, 2 Jun 2019 12:53:42 -0400 Received: from sonic310-30.consmr.mail.ne1.yahoo.com ([66.163.186.211]:46271 "EHLO sonic310-30.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727040AbfFBQxm (ORCPT ); Sun, 2 Jun 2019 12:53:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494420; bh=GL92BlbATLhdlRxbERwtGOiRrC+zdGB2SpJVUW1Y7c8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=ROewHKjF7dSA+7c8pDE+v2Uii00aJwYBUUDxiybmKf5VHdG8ADbiP57thOs5aQf04Ygi5Qx0zSqp5orKv3Bsqxy/ha8OILRj7HCJPrOPLFiwag0UZw3dEX0+I+D3r0pcCCx/aW0H9BUioWvpjF9zmOGba+Ty75eWEX/SIdt9JnchWUiGb9Y0hX9lW9yQ3orOAqpHeCfozyWohJrxHNJjmZ0UO42hF26Oinspsp/4PM4F047C9PSSQpqYfoTXcOo1LX6Oi7KQfWNyE/ep6ZOs+IgTrWR3KYkhvWZyV9JcBKi0KMPDpdXatIUkXIuH/xJ6J7PV1NfalEkl55zWLWp5PA== X-YMail-OSG: MEWQWqEVM1n5K_318_JHQDIkQL3YaGtljQWREA2K406VTdhnv6QVdYR1tjDcQ5R RbKQGCIvs2UppcRqtZ6ela9TvnQPtRkdBsE_0QsksYsNR9ls4KdljTWn_D_RzR7x6u0Mj1BIvJ3v 3nyvYyWCJHTNZ3raB.aNB4xUqn7n1mS.Vhbh8Mp7DNAriSikl0EAVWdUgeOf_HUVDMjYSn_6WrTf 6vuyN8fCJicjak86ZUnqMqzNTQarlabql28ze2mbvhPZKHdv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..rVXYH7otaXk5cAsiuXP2A- Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:53:40 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp409.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 111e227deeb5369cccd8023f32784fec; Sun, 02 Jun 2019 16:53:38 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 42/58] LSM: Use lsm_context in security_dentry_init_security Date: Sun, 2 Jun 2019 09:50:45 -0700 Message-Id: <20190602165101.25079-43-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Casey Schaufler Convert security_dentry_init_security to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- fs/nfs/nfs4proc.c | 5 ++++- include/linux/security.h | 7 +++---- security/security.c | 14 ++++---------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 4dbb0ee23432..de000649f9f3 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -113,6 +113,7 @@ static inline struct nfs4_label * nfs4_label_init_security(struct inode *dir, struct dentry *dentry, struct iattr *sattr, struct nfs4_label *label) { + struct lsm_context lc; /* Scaffolding -Casey */ int err; if (label == NULL) @@ -122,7 +123,9 @@ nfs4_label_init_security(struct inode *dir, struct dentry *dentry, return NULL; err = security_dentry_init_security(dentry, sattr->ia_mode, - &dentry->d_name, (void **)&label->label, &label->len); + &dentry->d_name, &lc); + label->label = lc.context; + label->len = lc.len; if (err == 0) return label; diff --git a/include/linux/security.h b/include/linux/security.h index e12b169deed6..6c3a74a44a59 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -302,8 +302,8 @@ int security_sb_clone_mnt_opts(const struct super_block *oldsb, int security_add_mnt_opt(const char *option, const char *val, int len, void **mnt_opts); int security_dentry_init_security(struct dentry *dentry, int mode, - const struct qstr *name, void **ctx, - u32 *ctxlen); + const struct qstr *name, + struct lsm_context *cp); int security_dentry_create_files_as(struct dentry *dentry, int mode, struct qstr *name, const struct cred *old, @@ -674,8 +674,7 @@ static inline void security_inode_free(struct inode *inode) static inline int security_dentry_init_security(struct dentry *dentry, int mode, const struct qstr *name, - void **ctx, - u32 *ctxlen) + struct lsm_context *cp) { return -EOPNOTSUPP; } diff --git a/security/security.c b/security/security.c index c04b334370a5..628287180ce7 100644 --- a/security/security.c +++ b/security/security.c @@ -1014,17 +1014,11 @@ void security_inode_free(struct inode *inode) } int security_dentry_init_security(struct dentry *dentry, int mode, - const struct qstr *name, void **ctx, - u32 *ctxlen) + const struct qstr *name, + struct lsm_context *cp) { - struct lsm_context lc = { .context = NULL, .len = 0, }; - int rc; - - rc = call_int_hook(dentry_init_security, -EOPNOTSUPP, dentry, mode, - name, &lc); - *ctx = (void *)lc.context; - *ctxlen = lc.len; - return rc; + return call_int_hook(dentry_init_security, -EOPNOTSUPP, dentry, mode, + name, cp); } EXPORT_SYMBOL(security_dentry_init_security); From patchwork Sun Jun 2 16:50:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971957 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BA00392A for ; Sun, 2 Jun 2019 16:53:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9ED31FF40 for ; Sun, 2 Jun 2019 16:53:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E15B289FA; Sun, 2 Jun 2019 16:53:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E34E286E4 for ; Sun, 2 Jun 2019 16:53:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727042AbfFBQxm (ORCPT ); Sun, 2 Jun 2019 12:53:42 -0400 Received: from sonic303-27.consmr.mail.ne1.yahoo.com ([66.163.188.153]:41640 "EHLO sonic303-27.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727049AbfFBQxm (ORCPT ); Sun, 2 Jun 2019 12:53:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494421; bh=xbxrTtPDT+RT3HxgpjUjOefKGXANltzkYYing08uaXc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=aXydkOVN9WenKQAFSgTGy+Pm59RXfJtAH6P0Ny5IViBe00h+hQdLKXGtk5tpSE2qtmVuOB2X6jPbI5rLDwSjA5hHXKoe5wCPOxrPRmbbsMlU8yzHgPsMZCWgliBgPbuVXhBbbG8hqS3CQ1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gynUAU5Q7fb7nFudg.zH6XmCx9SuTXOm_0f2RPLh2nmvbM1DyQ fG2eBOsfhC214wfjOjM5W4J1cIQdaRZIb8BODnUnYGz233xeSIiNnj_mR6g7TC6yqTTQ8nDysv_u AeTHdNIoTdMjwjCmRuOzTMYO78eQyQeEvNa._b8Q5JW.AHnmGN7r_1rwcWkbhX6q4qu6Fu3AF5oL Lx3FkcxUWWvcXRX24144tf5z4qrQZXmjl66ArrvPWqX1rPmtxlnGjPKDYS3nZcpMZtyhppNA.tDz 8Mxl.vqtU16NEP5evSW72LKLK5aPdGD2H435vjIApIaZrE0jUd90VkmHAHNsuE9uypq2wHciJjUO Yn3b06mbFOiAlhFbVpTquPDaMqi0yz2JUsAePNaRb4yyVAbi8AvKySPAu4jctkXBT3i8JZgQcR_I 2Xx3ePJuh7MG5oB2FJshnh8gME2frS3Hf58O7xxoiaOuh.ffZ48.2MRqD1dI- Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:53:41 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp409.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 111e227deeb5369cccd8023f32784fec; Sun, 02 Jun 2019 16:53:39 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 43/58] LSM: Use lsm_context in security_inode_notifysecctx Date: Sun, 2 Jun 2019 09:50:46 -0700 Message-Id: <20190602165101.25079-44-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_inode_notifysecctx to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- fs/kernfs/inode.c | 6 ++++-- fs/nfs/inode.c | 6 ++++-- include/linux/security.h | 5 +++-- security/security.c | 8 ++------ 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c index 0c1fd945ce42..460e611b1938 100644 --- a/fs/kernfs/inode.c +++ b/fs/kernfs/inode.c @@ -184,6 +184,7 @@ static inline void set_inode_attr(struct inode *inode, struct iattr *iattr) static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode) { struct kernfs_iattrs *attrs = kn->iattr; + struct lsm_context lc; /* Scaffolding -Casey */ inode->i_mode = kn->mode; if (attrs) { @@ -192,8 +193,9 @@ static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode) * persistent copy in kernfs_node. */ set_inode_attr(inode, &attrs->ia_iattr); - security_inode_notifysecctx(inode, attrs->ia_secdata, - attrs->ia_secdata_len); + lc.context = attrs->ia_secdata; + lc.len = attrs->ia_secdata_len; + security_inode_notifysecctx(inode, &lc); } if (kernfs_type(kn) == KERNFS_DIR) diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 414a90d48493..8d0be9767b14 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -340,14 +340,16 @@ static void nfs_clear_label_invalid(struct inode *inode) void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr, struct nfs4_label *label) { + struct lsm_context lc; /* Scaffolding -Casey */ int error; if (label == NULL) return; if ((fattr->valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL) && inode->i_security) { - error = security_inode_notifysecctx(inode, label->label, - label->len); + lc.context = label->label; + lc.len = label->len; + error = security_inode_notifysecctx(inode, &lc); if (error) printk(KERN_ERR "%s() %s %d " "security_inode_notifysecctx() %d\n", diff --git a/include/linux/security.h b/include/linux/security.h index 6c3a74a44a59..6b2fcca08a43 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -437,7 +437,7 @@ int security_secctx_to_secid(const char *secdata, u32 seclen, void security_release_secctx(char *secdata, u32 seclen); void security_inode_invalidate_secctx(struct inode *inode); -int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen); +int security_inode_notifysecctx(struct inode *inode, struct lsm_context *cp); int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen); int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen); #else /* CONFIG_SECURITY */ @@ -1232,7 +1232,8 @@ static inline void security_inode_invalidate_secctx(struct inode *inode) { } -static inline int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) +static inline int security_inode_notifysecctx(struct inode *inode, + struct lsm_context *cp); { return -EOPNOTSUPP; } diff --git a/security/security.c b/security/security.c index 628287180ce7..74f211d58e5f 100644 --- a/security/security.c +++ b/security/security.c @@ -2011,13 +2011,9 @@ void security_inode_invalidate_secctx(struct inode *inode) } EXPORT_SYMBOL(security_inode_invalidate_secctx); -int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) +int security_inode_notifysecctx(struct inode *inode, struct lsm_context *cp) { - struct lsm_context lc; - - lc.context = ctx; - lc.len = ctxlen; - return call_int_hook(inode_notifysecctx, 0, inode, &lc); + return call_int_hook(inode_notifysecctx, 0, inode, cp); } EXPORT_SYMBOL(security_inode_notifysecctx); From patchwork Sun Jun 2 16:50:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971969 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E1AE892A for ; Sun, 2 Jun 2019 16:53:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDF6F2873A for ; Sun, 2 Jun 2019 16:53:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2421289FA; Sun, 2 Jun 2019 16:53:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 433611FF40 for ; Sun, 2 Jun 2019 16:53:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727072AbfFBQx5 (ORCPT ); Sun, 2 Jun 2019 12:53:57 -0400 Received: from sonic305-8.consmr.mail.bf2.yahoo.com ([74.6.133.47]:40078 "EHLO sonic305-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727053AbfFBQx4 (ORCPT ); Sun, 2 Jun 2019 12:53:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494435; bh=wFOhNcgsx3tpKVkIF6420r+ZGM2BRdr7BpTpAqXS/b0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=PAzThKbawFsvOXbqC7ZwU8rziQvhFxolhpPRI8q4PDSZQ7VVkIDyy2PTaSQqmSZUOnJeKcDcnF6GljBpmVl/PHZrqi1U4vsJ47o430z5hwq6GFNOj3qliH56klqHDRk8dpkUq+GUSw+kTdRhGm4NrbLhkLkKZ3BbFShRutZLNcFussTAqm79a3sVFBi6V97VqPaBr/WfcBrLXe5nyKttjHQCMQX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VI7tEVHtpcF2BbnPqiIVGRx5LvtcFRsfU5La3S n0Dn51BqDVTzLPD3swlXq8D4z6REW33g0sDdfdMobs.nlzQl6s0.IPN2rOkl2dP.2pB0E3HhU4cp QJ_lp0yIvnQT0U25ZBwsa6ywRMfLdatlff4X1zyGG2lC3PWvnjPG1W7d95ZZ0A0sQruaJtVKPBTV srJiuypV.Qn2B3qh5gy3sGS9Ilx9164wKIvNeKeT2V4HDDN2yW2ruVpp8POAjBa_OnQfYX7LMweR Ns0zApgl7MvxUop3Q4dqGxQ.r_ctqyVIzxzSmP1tApMPxJrPq5F38TY1KPZZISIVoHv4.qmC8P8Z .S6JQHq_mnmTmdnT06Ks9wZ0WKH3b2uZZSBQiv6J7rVmPkvdXEZJ4j8cz Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:53:55 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp427.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 378fb4b825ee861f1e4674117ce93fdc; Sun, 02 Jun 2019 16:53:51 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 44/58] LSM: Use lsm_context in security_inode_getsecctx Date: Sun, 2 Jun 2019 09:50:47 -0700 Message-Id: <20190602165101.25079-45-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Casey Schaufler Convert security_inode_getsecctx to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- fs/kernfs/inode.c | 11 +++++------ fs/nfsd/nfs4xdr.c | 14 ++++++-------- include/linux/security.h | 5 +++-- security/security.c | 11 ++--------- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c index 460e611b1938..41c5afc698fc 100644 --- a/fs/kernfs/inode.c +++ b/fs/kernfs/inode.c @@ -351,8 +351,7 @@ static int kernfs_security_xattr_set(const struct xattr_handler *handler, { struct kernfs_node *kn = inode->i_private; struct kernfs_iattrs *attrs; - void *secdata; - u32 secdata_len = 0; + struct lsm_context lc = { .context = NULL, .len = 0, }; int error; attrs = kernfs_iattrs(kn); @@ -362,16 +361,16 @@ static int kernfs_security_xattr_set(const struct xattr_handler *handler, error = security_inode_setsecurity(inode, suffix, value, size, flags); if (error) return error; - error = security_inode_getsecctx(inode, &secdata, &secdata_len); + error = security_inode_getsecctx(inode, &lc); if (error) return error; mutex_lock(&kernfs_mutex); - error = kernfs_node_setsecdata(attrs, &secdata, &secdata_len); + error = kernfs_node_setsecdata(attrs, (void **)&lc.context, &lc.len); mutex_unlock(&kernfs_mutex); - if (secdata) - security_release_secctx(secdata, secdata_len); + if (lc.context) + security_release_secctx(lc.context, lc.len); return error; } diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 3de42a729093..1bf34730d054 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -2420,8 +2420,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, __be32 status; int err; struct nfs4_acl *acl = NULL; - void *context = NULL; - int contextlen; + struct lsm_context lc = { .context = NULL, .len = 0, }; bool contextsupport = false; struct nfsd4_compoundres *resp = rqstp->rq_resp; u32 minorversion = resp->cstate.minorversion; @@ -2477,8 +2476,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, if ((bmval2 & FATTR4_WORD2_SECURITY_LABEL) || bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) { if (exp->ex_flags & NFSEXP_SECURITY_LABEL) - err = security_inode_getsecctx(d_inode(dentry), - &context, &contextlen); + err = security_inode_getsecctx(d_inode(dentry), &lc); else err = -EOPNOTSUPP; contextsupport = (err == 0); @@ -2907,8 +2905,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, } if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) { - status = nfsd4_encode_security_label(xdr, rqstp, context, - contextlen); + status = nfsd4_encode_security_label(xdr, rqstp, lc.context, + lc.len); if (status) goto out; } @@ -2919,8 +2917,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, out: #ifdef CONFIG_NFSD_V4_SECURITY_LABEL - if (context) - security_release_secctx(context, contextlen); + if (lc.context) + security_release_secctx(lc.context, lc.len); #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ kfree(acl); if (tempfh) { diff --git a/include/linux/security.h b/include/linux/security.h index 6b2fcca08a43..90d1ff7a2fe6 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -439,7 +439,7 @@ void security_release_secctx(char *secdata, u32 seclen); void security_inode_invalidate_secctx(struct inode *inode); int security_inode_notifysecctx(struct inode *inode, struct lsm_context *cp); int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen); -int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen); +int security_inode_getsecctx(struct inode *inode, struct lsm_context *cp); #else /* CONFIG_SECURITY */ static inline int call_lsm_notifier(enum lsm_event event, void *data) @@ -1241,7 +1241,8 @@ static inline int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 { return -EOPNOTSUPP; } -static inline int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) +static inline int security_inode_getsecctx(struct inode *inode, + struct lsm_context *cp); { return -EOPNOTSUPP; } diff --git a/security/security.c b/security/security.c index 74f211d58e5f..4f999cfcf949 100644 --- a/security/security.c +++ b/security/security.c @@ -2023,16 +2023,9 @@ int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) } EXPORT_SYMBOL(security_inode_setsecctx); -int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) +int security_inode_getsecctx(struct inode *inode, struct lsm_context *cp) { - struct lsm_context lc = { .context = NULL, .len = 0, }; - int rc; - - rc = call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, &lc); - - *ctx = (void *)lc.context; - *ctxlen = lc.len; - return rc; + return call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, cp); } EXPORT_SYMBOL(security_inode_getsecctx); From patchwork Sun Jun 2 16:50:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971973 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 797C26C5 for ; Sun, 2 Jun 2019 16:53:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A1BE1FF40 for ; Sun, 2 Jun 2019 16:53:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E7DF289FA; Sun, 2 Jun 2019 16:53:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCAFA1FF40 for ; Sun, 2 Jun 2019 16:53:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727053AbfFBQx5 (ORCPT ); Sun, 2 Jun 2019 12:53:57 -0400 Received: from sonic305-8.consmr.mail.bf2.yahoo.com ([74.6.133.47]:41802 "EHLO sonic305-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727065AbfFBQx4 (ORCPT ); Sun, 2 Jun 2019 12:53:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494435; bh=mT7CWYfSqkiX5vZ0p/C8Hg9IONMlLrjlhp5TmNjwBEM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=GSHIIZitK8K1CxkGeVrYiVaI0p9/CWd45OB++MQlgsQoHj2hjiCVM7ydNRJpjgySI5zkYPEWaBRGFzJbBLLChCIKXV7fVblFaqs5ovgVe5rC7+S9k3mxUdPn+0iQq0Ue1EXfnVdhQ0dkbi+a5kBlcTdQL0uNx25ly1BKrvawN+NYrhB//SV1TP2L9OV+6yr8+fUDmS9EZXMYOtSVTH2AYNT8B5Q5Aha8y/CJiCKMHoiRPlUleDD03b6bryyTcpeeICTMLTIFYS1e+ZiUYHbpZvDB1vzoSIsn0uQdBlXO9QDYkBc/o/TBr8EnsZ3kLafRJjsmmTVv7Gh6valbqldcJA== X-YMail-OSG: awEj7x4VM1mDPESiIxPCCt3QuO7XGlH9wPkAEcR5x.vpelsOAxjEgfkMPF30e97 lPBFBS9DOkySXCiP4KvVLA1kFLAcYAXEmk3wDxuIzM0SREykoBqWtWYIdyPiuoSFUOFM8RKHpNz9 O6Kea1VBSS_6kD2ZH9xppl6rZ5AHE3WujECGUEZGctc3zQSNHCJuz4IZ7Pe7Dp8yMdn2EG4AfN9o d.1npzwBGB0lVzBUcp3gQjZl.ejDHvsW9lIXDd9sUt5Id5BeZf32FPA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0PEEtg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:53:55 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp427.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 378fb4b825ee861f1e4674117ce93fdc; Sun, 02 Jun 2019 16:53:53 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 45/58] LSM: Use lsm_context in security_secctx_to_secid Date: Sun, 2 Jun 2019 09:50:48 -0700 Message-Id: <20190602165101.25079-46-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_secctx_to_secid to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/security.h | 6 ++---- kernel/cred.c | 5 ++++- net/netfilter/nft_meta.c | 5 ++++- net/netfilter/xt_SECMARK.c | 5 ++++- net/netlabel/netlabel_unlabeled.c | 16 ++++++++-------- security/security.c | 9 ++------- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 90d1ff7a2fe6..3f757b2d8275 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -432,8 +432,7 @@ int security_setprocattr(const char *lsm, const char *name, void *value, int security_netlink_send(struct sock *sk, struct sk_buff *skb); int security_ismaclabel(const char *name); int security_secid_to_secctx(struct lsm_export *l, char **secdata, u32 *seclen); -int security_secctx_to_secid(const char *secdata, u32 seclen, - struct lsm_export *l); +int security_secctx_to_secid(struct lsm_context *cp, struct lsm_export *l); void security_release_secctx(char *secdata, u32 seclen); void security_inode_invalidate_secctx(struct inode *inode); @@ -1217,8 +1216,7 @@ static inline int security_secid_to_secctx(struct lsm_export *l, return -EOPNOTSUPP; } -static inline int security_secctx_to_secid(const char *secdata, - u32 seclen, +static inline int security_secctx_to_secid(struct lsm_context *cp, struct lsm_export *l) { return -EOPNOTSUPP; diff --git a/kernel/cred.c b/kernel/cred.c index 7792538b1ca6..ebae67fdd4d0 100644 --- a/kernel/cred.c +++ b/kernel/cred.c @@ -724,10 +724,13 @@ EXPORT_SYMBOL(set_security_override); */ int set_security_override_from_ctx(struct cred *new, const char *secctx) { + struct lsm_context lc; struct lsm_export le; int ret; - ret = security_secctx_to_secid(secctx, strlen(secctx), &le); + lc.context = secctx; + lc.len = strlen(secctx); + ret = security_secctx_to_secid(&lc, &le); if (ret < 0) return ret; diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c index a1d3dab5bc25..f25b26318d72 100644 --- a/net/netfilter/nft_meta.c +++ b/net/netfilter/nft_meta.c @@ -577,11 +577,14 @@ static const struct nla_policy nft_secmark_policy[NFTA_SECMARK_MAX + 1] = { static int nft_secmark_compute_secid(struct nft_secmark *priv) { struct lsm_export le; + struct lsm_context lc; u32 tmp_secid = 0; int err; lsm_export_init(&le); - err = security_secctx_to_secid(priv->ctx, strlen(priv->ctx), &le); + lc.context = priv->ctx; + lc.len = strlen(priv->ctx); + err = security_secctx_to_secid(&lc, &le); if (err) return err; diff --git a/net/netfilter/xt_SECMARK.c b/net/netfilter/xt_SECMARK.c index 9a2a97c200a2..a06e50535194 100644 --- a/net/netfilter/xt_SECMARK.c +++ b/net/netfilter/xt_SECMARK.c @@ -50,13 +50,16 @@ secmark_tg(struct sk_buff *skb, const struct xt_action_param *par) static int checkentry_lsm(struct xt_secmark_target_info *info) { struct lsm_export le; + struct lsm_context lc; int err; info->secctx[SECMARK_SECCTX_MAX - 1] = '\0'; info->secid = 0; lsm_export_init(&le); - err = security_secctx_to_secid(info->secctx, strlen(info->secctx), &le); + lc.context = info->secctx; + lc.len = strlen(info->secctx); + err = security_secctx_to_secid(&lc, &le); if (err) { if (err == -EINVAL) pr_info_ratelimited("invalid security context \'%s\'\n", diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c index f79ab91bf25e..707ea5a364b0 100644 --- a/net/netlabel/netlabel_unlabeled.c +++ b/net/netlabel/netlabel_unlabeled.c @@ -894,6 +894,7 @@ static int netlbl_unlabel_staticadd(struct sk_buff *skb, void *mask; u32 addr_len; struct lsm_export le; + struct lsm_context lc; struct netlbl_audit audit_info; /* Don't allow users to add both IPv4 and IPv6 addresses for a @@ -914,10 +915,9 @@ static int netlbl_unlabel_staticadd(struct sk_buff *skb, if (ret_val != 0) return ret_val; dev_name = nla_data(info->attrs[NLBL_UNLABEL_A_IFACE]); - ret_val = security_secctx_to_secid( - nla_data(info->attrs[NLBL_UNLABEL_A_SECCTX]), - nla_len(info->attrs[NLBL_UNLABEL_A_SECCTX]), - &le); + lc.context = nla_data(info->attrs[NLBL_UNLABEL_A_SECCTX]); + lc.len = nla_len(info->attrs[NLBL_UNLABEL_A_SECCTX]); + ret_val = security_secctx_to_secid(&lc, &le); if (ret_val != 0) return ret_val; @@ -945,6 +945,7 @@ static int netlbl_unlabel_staticadddef(struct sk_buff *skb, void *mask; u32 addr_len; struct lsm_export le; + struct lsm_context lc; struct netlbl_audit audit_info; /* Don't allow users to add both IPv4 and IPv6 addresses for a @@ -963,10 +964,9 @@ static int netlbl_unlabel_staticadddef(struct sk_buff *skb, ret_val = netlbl_unlabel_addrinfo_get(info, &addr, &mask, &addr_len); if (ret_val != 0) return ret_val; - ret_val = security_secctx_to_secid( - nla_data(info->attrs[NLBL_UNLABEL_A_SECCTX]), - nla_len(info->attrs[NLBL_UNLABEL_A_SECCTX]), - &le); + lc.context = nla_data(info->attrs[NLBL_UNLABEL_A_SECCTX]); + lc.len = nla_len(info->attrs[NLBL_UNLABEL_A_SECCTX]); + ret_val = security_secctx_to_secid(&lc, &le); if (ret_val != 0) return ret_val; diff --git a/security/security.c b/security/security.c index 4f999cfcf949..44a4402073d7 100644 --- a/security/security.c +++ b/security/security.c @@ -1987,15 +1987,10 @@ int security_secid_to_secctx(struct lsm_export *l, char **secdata, u32 *seclen) } EXPORT_SYMBOL(security_secid_to_secctx); -int security_secctx_to_secid(const char *secdata, u32 seclen, - struct lsm_export *l) +int security_secctx_to_secid(struct lsm_context *cp, struct lsm_export *l) { - struct lsm_context lc; - - lc.context = (char *)secdata; - lc.len = seclen; lsm_export_init(l); - return call_one_int_hook(secctx_to_secid, 0, &lc, l); + return call_one_int_hook(secctx_to_secid, 0, cp, l); } EXPORT_SYMBOL(security_secctx_to_secid); From patchwork Sun Jun 2 16:50:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971977 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 337CB92A for ; Sun, 2 Jun 2019 16:54:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23DFD1FF40 for ; Sun, 2 Jun 2019 16:54:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17572289FA; Sun, 2 Jun 2019 16:54:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FADE1FF40 for ; Sun, 2 Jun 2019 16:53:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727076AbfFBQx7 (ORCPT ); Sun, 2 Jun 2019 12:53:59 -0400 Received: from sonic303-8.consmr.mail.bf2.yahoo.com ([74.6.131.47]:37760 "EHLO sonic303-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727066AbfFBQx6 (ORCPT ); Sun, 2 Jun 2019 12:53:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494437; bh=4I+6H6t4R1PSAbDphFTCodzdmZKek818TwRA7drv09Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=sWZ1dlFac+a9Ji9YB1k9J6v/VGE73nWJC5e7a/pvB2nsOgBiKbq84bklBqEJ7CLoRXPDnpWwgw8agGGr7VDjme9Hb8DX1OTVy2R2TfL+7r1wO39Z2bfyHdTlOJm51XEI5ZBCQ11//fH/u9dBQ9PfoFxa9O8z+dK/bnyKDIAmd4eNm7YRZIuZKjXdUoOuPMgvbnZKoMnAuOetnG4FZD4NxBYSgfHnv5q0+oDQ012sjDpuuBMe1uic64QpNCNytO3roQOcp5kTtrt6prD9uZOFWFobTh7f8vv+C+GUWoNIhKHuoMC9Y/yfhof85vRjw149V4zRGfxa/4keBy8yXPFbkA== X-YMail-OSG: DH_JqVYVM1luYh81aalqSyRYHd65wPq09e8PVUVPque9o8KRevgfj3yiWnEyQYt CWCsMHWeN0hHGAUpnXLF6MTp08b8XjxvwsRFSamAHVTZnaDBzBukcX6Z4JvBMR_K7e0V87HtRk3k UHX1L1dti3jrI0v.V_Mt0RoMoQraoVNO1kjwTgxOVkQkQidXOSQbn1mtT10rsdbZ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5HeRjS8uzseSt2YMB EvkBKhXsMO2qGDyProcPUHYniq18TQkyWdiFUToT5by2Y8nMeeklWErQ- Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:53:57 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp427.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 378fb4b825ee861f1e4674117ce93fdc; Sun, 02 Jun 2019 16:53:54 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 46/58] LSM: Use lsm_context in release_secctx hooks Date: Sun, 2 Jun 2019 09:50:49 -0700 Message-Id: <20190602165101.25079-47-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert SELinux, Smack and AppAror to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 3 +-- security/apparmor/include/secid.h | 2 +- security/apparmor/secid.c | 4 ++-- security/security.c | 6 +++++- security/selinux/hooks.c | 4 ++-- security/smack/smack_lsm.c | 4 ++-- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index d4ace7af4950..3a779a0f9e15 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1329,7 +1329,6 @@ * @release_secctx: * Release the security context. * @secdata contains the security context. - * @seclen contains the length of the security context. * * Security hooks for Audit * @@ -1663,7 +1662,7 @@ union security_list_options { int (*secid_to_secctx)(struct lsm_export *l, struct lsm_context *cp); int (*secctx_to_secid)(const struct lsm_context *cp, struct lsm_export *l); - void (*release_secctx)(char *secdata, u32 seclen); + void (*release_secctx)(struct lsm_context *cp); void (*inode_invalidate_secctx)(struct inode *inode); int (*inode_notifysecctx)(struct inode *inode, struct lsm_context *cp); diff --git a/security/apparmor/include/secid.h b/security/apparmor/include/secid.h index acfcf99bff0e..a780e56d4f5b 100644 --- a/security/apparmor/include/secid.h +++ b/security/apparmor/include/secid.h @@ -29,7 +29,7 @@ struct aa_label *aa_secid_to_label(struct lsm_export *l); int apparmor_secid_to_secctx(struct lsm_export *l, struct lsm_context *cp); int apparmor_secctx_to_secid(const struct lsm_context *cp, struct lsm_export *l); -void apparmor_release_secctx(char *secdata, u32 seclen); +void apparmor_release_secctx(struct lsm_context *cp); int aa_alloc_secid(struct aa_label *label, gfp_t gfp); diff --git a/security/apparmor/secid.c b/security/apparmor/secid.c index 35df38592b6e..46c8b9a67ac7 100644 --- a/security/apparmor/secid.c +++ b/security/apparmor/secid.c @@ -123,9 +123,9 @@ int apparmor_secctx_to_secid(const struct lsm_context *cp, struct lsm_export *l) return 0; } -void apparmor_release_secctx(char *secdata, u32 seclen) +void apparmor_release_secctx(struct lsm_context *cp) { - kfree(secdata); + kfree(cp->context); } /** diff --git a/security/security.c b/security/security.c index 44a4402073d7..029d2f4fe48c 100644 --- a/security/security.c +++ b/security/security.c @@ -1996,7 +1996,11 @@ EXPORT_SYMBOL(security_secctx_to_secid); void security_release_secctx(char *secdata, u32 seclen) { - call_one_void_hook(release_secctx, secdata, seclen); + struct lsm_context lc; + + lc.context = secdata; + lc.len = seclen; + call_one_void_hook(release_secctx, &lc); } EXPORT_SYMBOL(security_release_secctx); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index fe09905d013c..332296f69f76 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6322,9 +6322,9 @@ static int selinux_secctx_to_secid(const struct lsm_context *cp, return rc; } -static void selinux_release_secctx(char *secdata, u32 seclen) +static void selinux_release_secctx(struct lsm_context *cp) { - kfree(secdata); + kfree(cp->context); } static void selinux_inode_invalidate_secctx(struct inode *inode) diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 3d24503029e5..cf27905ccaa5 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4468,9 +4468,9 @@ static int smack_secctx_to_secid(const struct lsm_context *cp, } /* - * There smack_release_secctx hook does nothing + * The smack_release_secctx hook does nothing */ -static void smack_release_secctx(char *secdata, u32 seclen) +static void smack_release_secctx(struct lsm_context *cp) { } From patchwork Sun Jun 2 16:50:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971981 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1AA336C5 for ; Sun, 2 Jun 2019 16:54:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 069CF1FF40 for ; Sun, 2 Jun 2019 16:54:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE1B82873A; Sun, 2 Jun 2019 16:54:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FC231FF40 for ; Sun, 2 Jun 2019 16:54:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727079AbfFBQyB (ORCPT ); Sun, 2 Jun 2019 12:54:01 -0400 Received: from sonic302-8.consmr.mail.bf2.yahoo.com ([74.6.135.47]:40320 "EHLO sonic302-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727075AbfFBQyA (ORCPT ); Sun, 2 Jun 2019 12:54:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494438; bh=fEFSaTJW0PhJ/+1XDLyA9EJN3fv5fqnG/83jcoBEXmU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=rO4I3WbGFTYx3FW76x/8xTUFhQzCmGtkKsxx5ZiTfSUTfIMVNl+VSSxIvr3urvu0nD6jOYI1bGw5CANLtf7ECPCfQlS/6oKpqz/cwDIjrHhQQrJUM1gENe0Tr2/RAvg87ZMwBJrLcBn5vwf79yl9ytirXrDA85Ch54t3tScTelCyr/sk8tAZK+LNE4kWCA91Fg2tTFFL9Pv4plWgH9F5McqCp3ED6e6ZEqX9fKy+DDpjV2SOeA1GWS9bGIsRZIE40cQZQTwTy+T8GPtIqm/f3MaCBZIIx1okGd8Vyt2FXy7VjXZuk7SxoESn5ygUy1QOZ0JHXOEDFciR8/BMKOu48g== X-YMail-OSG: HJtC_l4VM1nFOoK4_Y5n0gBrkvXMiVubci30ON.bxgmsLBPTvMjwTMNjSyVf2Du ZCuscXf5uJ8BIal7wQ7OSNOPQudcBBRajrpHZvrqeb8w4tLtAYZc5yxfmSVqsPctG8oPqQZqC6_Q aKxRm8ck7MPdIWhjKYivN8K9D.0f8ufTMy_7GQ6ZcT9XHlQBRYuA22LrdYYKPU51XDp_m8.jirCS t_oO9GtMoLcAoQpdfa4GmMepzTCbOPf_gfR1sg6u7HFjcs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KRA-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:53:58 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp427.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 378fb4b825ee861f1e4674117ce93fdc; Sun, 02 Jun 2019 16:53:56 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 47/58] LSM: Use lsm_context in security_release_secctx Date: Sun, 2 Jun 2019 09:50:50 -0700 Message-Id: <20190602165101.25079-48-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_release_secctx to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- drivers/android/binder.c | 21 +++++++-------- fs/kernfs/dir.c | 9 ++++--- fs/kernfs/inode.c | 2 +- fs/nfs/nfs4proc.c | 9 +++++-- fs/nfsd/nfs4xdr.c | 2 +- include/linux/security.h | 4 +-- include/net/scm.h | 10 +++---- kernel/audit.c | 27 +++++++++---------- kernel/auditsc.c | 27 +++++++++---------- net/ipv4/ip_sockglue.c | 9 +++---- net/netfilter/nf_conntrack_netlink.c | 10 +++---- net/netfilter/nf_conntrack_standalone.c | 9 +++---- net/netfilter/nfnetlink_queue.c | 28 ++++++++++--------- net/netlabel/netlabel_unlabeled.c | 36 ++++++++++++------------- net/netlabel/netlabel_user.c | 11 ++++---- security/security.c | 10 +++---- 16 files changed, 109 insertions(+), 115 deletions(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 0eeb5b75da5b..c2cfef13257c 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -2874,8 +2874,7 @@ static void binder_transaction(struct binder_proc *proc, binder_size_t last_fixup_min_off = 0; struct binder_context *context = proc->context; int t_debug_id = atomic_inc_return(&binder_last_id); - char *secctx = NULL; - u32 secctx_sz = 0; + struct lsm_context lc = { .len = 0, .context = NULL, }; e = binder_transaction_log_add(&binder_transaction_log); e->debug_id = t_debug_id; @@ -3122,14 +3121,14 @@ static void binder_transaction(struct binder_proc *proc, struct lsm_export le; security_task_getsecid(proc->tsk, &le); - ret = security_secid_to_secctx(&le, &secctx, &secctx_sz); + ret = security_secid_to_secctx(&le, &lc.context, &lc.len); if (ret) { return_error = BR_FAILED_REPLY; return_error_param = ret; return_error_line = __LINE__; goto err_get_secctx_failed; } - extra_buffers_size += ALIGN(secctx_sz, sizeof(u64)); + extra_buffers_size += ALIGN(lc.len, sizeof(u64)); } trace_binder_transaction(reply, t, target_node); @@ -3148,18 +3147,18 @@ static void binder_transaction(struct binder_proc *proc, t->buffer = NULL; goto err_binder_alloc_buf_failed; } - if (secctx) { + if (lc.context) { size_t buf_offset = ALIGN(tr->data_size, sizeof(void *)) + ALIGN(tr->offsets_size, sizeof(void *)) + ALIGN(extra_buffers_size, sizeof(void *)) - - ALIGN(secctx_sz, sizeof(u64)); + ALIGN(lc.len, sizeof(u64)); t->security_ctx = (uintptr_t)t->buffer->user_data + buf_offset; binder_alloc_copy_to_buffer(&target_proc->alloc, t->buffer, buf_offset, - secctx, secctx_sz); - security_release_secctx(secctx, secctx_sz); - secctx = NULL; + lc.context, lc.len); + security_release_secctx(&lc); + lc.context = NULL; } t->buffer->debug_id = t->debug_id; t->buffer->transaction = t; @@ -3479,8 +3478,8 @@ static void binder_transaction(struct binder_proc *proc, t->buffer->transaction = NULL; binder_alloc_free_buf(&target_proc->alloc, t->buffer); err_binder_alloc_buf_failed: - if (secctx) - security_release_secctx(secctx, secctx_sz); + if (lc.context) + security_release_secctx(&lc); err_get_secctx_failed: kfree(tcomplete); binder_stats_deleted(BINDER_STAT_TRANSACTION_COMPLETE); diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index b84d635567d3..11672c075a8b 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c @@ -532,9 +532,12 @@ void kernfs_put(struct kernfs_node *kn) kfree_const(kn->name); if (kn->iattr) { - if (kn->iattr->ia_secdata) - security_release_secctx(kn->iattr->ia_secdata, - kn->iattr->ia_secdata_len); + if (kn->iattr->ia_secdata) { + struct lsm_context lc; /* Scaffolding -Casey */ + lc.context = kn->iattr->ia_secdata; + lc.len = kn->iattr->ia_secdata_len; + security_release_secctx(&lc); + } simple_xattrs_free(&kn->iattr->xattrs); kmem_cache_free(kernfs_iattrs_cache, kn->iattr); } diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c index 41c5afc698fc..45781f0da80f 100644 --- a/fs/kernfs/inode.c +++ b/fs/kernfs/inode.c @@ -370,7 +370,7 @@ static int kernfs_security_xattr_set(const struct xattr_handler *handler, mutex_unlock(&kernfs_mutex); if (lc.context) - security_release_secctx(lc.context, lc.len); + security_release_secctx(&lc); return error; } diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index de000649f9f3..8dee01eda643 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -134,8 +134,13 @@ nfs4_label_init_security(struct inode *dir, struct dentry *dentry, static inline void nfs4_label_release_security(struct nfs4_label *label) { - if (label) - security_release_secctx(label->label, label->len); + struct lsm_context lc; /* Scaffolding -Casey */ + + if (label) { + lc.context = label->label; + lc.len = label->len; + security_release_secctx(&lc); + } } static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) { diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 1bf34730d054..3d1251bd588f 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -2918,7 +2918,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, out: #ifdef CONFIG_NFSD_V4_SECURITY_LABEL if (lc.context) - security_release_secctx(lc.context, lc.len); + security_release_secctx(&lc); #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ kfree(acl); if (tempfh) { diff --git a/include/linux/security.h b/include/linux/security.h index 3f757b2d8275..57ce9b824eef 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -433,7 +433,7 @@ int security_netlink_send(struct sock *sk, struct sk_buff *skb); int security_ismaclabel(const char *name); int security_secid_to_secctx(struct lsm_export *l, char **secdata, u32 *seclen); int security_secctx_to_secid(struct lsm_context *cp, struct lsm_export *l); -void security_release_secctx(char *secdata, u32 seclen); +void security_release_secctx(struct lsm_context *cp); void security_inode_invalidate_secctx(struct inode *inode); int security_inode_notifysecctx(struct inode *inode, struct lsm_context *cp); @@ -1222,7 +1222,7 @@ static inline int security_secctx_to_secid(struct lsm_context *cp, return -EOPNOTSUPP; } -static inline void security_release_secctx(char *secdata, u32 seclen) +static inline void security_release_secctx(struct lsm_context *cp); { } diff --git a/include/net/scm.h b/include/net/scm.h index b5d1c24318e3..7e242ebdd258 100644 --- a/include/net/scm.h +++ b/include/net/scm.h @@ -92,16 +92,16 @@ static __inline__ int scm_send(struct socket *sock, struct msghdr *msg, #ifdef CONFIG_SECURITY_NETWORK static inline void scm_passec(struct socket *sock, struct msghdr *msg, struct scm_cookie *scm) { - char *secdata; - u32 seclen; + struct lsm_context lc; int err; if (test_bit(SOCK_PASSSEC, &sock->flags)) { - err = security_secid_to_secctx(&scm->le, &secdata, &seclen); + err = security_secid_to_secctx(&scm->le, &lc.context, &lc.len); if (!err) { - put_cmsg(msg, SOL_SOCKET, SCM_SECURITY, seclen, secdata); - security_release_secctx(secdata, seclen); + put_cmsg(msg, SOL_SOCKET, SCM_SECURITY, + lc.len, lc.context); + security_release_secctx(&lc); } } } diff --git a/kernel/audit.c b/kernel/audit.c index d83d1f05c95d..269c76fefe40 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -1191,8 +1191,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) struct audit_buffer *ab; u16 msg_type = nlh->nlmsg_type; struct audit_sig_info *sig_data; - char *ctx = NULL; - u32 len; + struct lsm_context lc = { .context = NULL, .len = 0, }; err = audit_netlink_ok(skb, msg_type); if (err) @@ -1428,27 +1427,26 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) break; } case AUDIT_SIGNAL_INFO: - len = 0; if (lsm_export_any(&audit_sig_lsm)) { - err = security_secid_to_secctx(&audit_sig_lsm, &ctx, - &len); + err = security_secid_to_secctx(&audit_sig_lsm, + &lc.context, &lc.len); if (err) return err; } - sig_data = kmalloc(sizeof(*sig_data) + len, GFP_KERNEL); + sig_data = kmalloc(sizeof(*sig_data) + lc.len, GFP_KERNEL); if (!sig_data) { if (lsm_export_any(&audit_sig_lsm)) - security_release_secctx(ctx, len); + security_release_secctx(&lc); return -ENOMEM; } sig_data->uid = from_kuid(&init_user_ns, audit_sig_uid); sig_data->pid = audit_sig_pid; if (lsm_export_any(&audit_sig_lsm)) { - memcpy(sig_data->ctx, ctx, len); - security_release_secctx(ctx, len); + memcpy(sig_data->ctx, lc.context, lc.len); + security_release_secctx(&lc); } audit_send_reply(skb, seq, AUDIT_SIGNAL_INFO, 0, 0, - sig_data, sizeof(*sig_data) + len); + sig_data, sizeof(*sig_data) + lc.len); kfree(sig_data); break; case AUDIT_TTY_GET: { @@ -2070,24 +2068,23 @@ void audit_log_key(struct audit_buffer *ab, char *key) int audit_log_task_context(struct audit_buffer *ab) { - char *ctx = NULL; - unsigned len; int error; struct lsm_export le; + struct lsm_context lc = { .context = NULL, }; security_task_getsecid(current, &le); if (!lsm_export_any(&le)) return 0; - error = security_secid_to_secctx(&le, &ctx, &len); + error = security_secid_to_secctx(&le, &lc.context, &lc.len); if (error) { if (error != -EINVAL) goto error_path; return 0; } - audit_log_format(ab, " subj=%s", ctx); - security_release_secctx(ctx, len); + audit_log_format(ab, " subj=%s", lc.context); + security_release_secctx(&lc); return 0; error_path: diff --git a/kernel/auditsc.c b/kernel/auditsc.c index d64775f4bb1b..4dab81c7aca0 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -938,9 +938,8 @@ static int audit_log_pid_context(struct audit_context *context, pid_t pid, unsigned int sessionid, struct lsm_export *l, char *comm) { + struct lsm_context lc = { .context = NULL, }; struct audit_buffer *ab; - char *ctx = NULL; - u32 len; int rc = 0; ab = audit_log_start(context, GFP_KERNEL, AUDIT_OBJ_PID); @@ -951,12 +950,12 @@ static int audit_log_pid_context(struct audit_context *context, pid_t pid, from_kuid(&init_user_ns, auid), from_kuid(&init_user_ns, uid), sessionid); if (lsm_export_any(l)) { - if (security_secid_to_secctx(l, &ctx, &len)) { + if (security_secid_to_secctx(l, &lc.context, &lc.len)) { audit_log_format(ab, " obj=(none)"); rc = 1; } else { - audit_log_format(ab, " obj=%s", ctx); - security_release_secctx(ctx, len); + audit_log_format(ab, " obj=%s", lc.context); + security_release_secctx(&lc); } } audit_log_format(ab, " ocomm="); @@ -1191,14 +1190,13 @@ static void show_special(struct audit_context *context, int *call_panic) from_kgid(&init_user_ns, context->ipc.gid), context->ipc.mode); if (lsm_export_any(l)) { - char *ctx = NULL; - u32 len; - if (security_secid_to_secctx(l, &ctx, &len)) { + struct lsm_context lc = { .context = NULL, }; + if (security_secid_to_secctx(l, &lc.context, &lc.len)) { audit_log_format(ab, " osid=(unknown)"); *call_panic = 1; } else { - audit_log_format(ab, " obj=%s", ctx); - security_release_secctx(ctx, len); + audit_log_format(ab, " obj=%s", lc.context); + security_release_secctx(&lc); } } if (context->ipc.has_perm) { @@ -1342,16 +1340,15 @@ static void audit_log_name(struct audit_context *context, struct audit_names *n, MAJOR(n->rdev), MINOR(n->rdev)); if (lsm_export_any(&n->olsm)) { - char *ctx = NULL; - u32 len; + struct lsm_context lc; - if (security_secid_to_secctx(&n->olsm, &ctx, &len)) { + if (security_secid_to_secctx(&n->olsm, &lc.context, &lc.len)) { audit_log_format(ab, " osid=(unknown)"); if (call_panic) *call_panic = 2; } else { - audit_log_format(ab, " obj=%s", ctx); - security_release_secctx(ctx, len); + audit_log_format(ab, " obj=%s", lc.context); + security_release_secctx(&lc); } } diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c index a4f37ba6dbe2..18a7fab8b2d3 100644 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c @@ -131,20 +131,19 @@ static void ip_cmsg_recv_checksum(struct msghdr *msg, struct sk_buff *skb, static void ip_cmsg_recv_security(struct msghdr *msg, struct sk_buff *skb) { struct lsm_export le; - char *secdata; - u32 seclen; + struct lsm_context lc; int err; err = security_socket_getpeersec_dgram(NULL, skb, &le); if (err) return; - err = security_secid_to_secctx(&le, &secdata, &seclen); + err = security_secid_to_secctx(&le, &lc.context, &lc.len); if (err) return; - put_cmsg(msg, SOL_IP, SCM_SECURITY, seclen, secdata); - security_release_secctx(secdata, seclen); + put_cmsg(msg, SOL_IP, SCM_SECURITY, lc.len, lc.context); + security_release_secctx(&lc); } static void ip_cmsg_recv_dstaddr(struct msghdr *msg, struct sk_buff *skb) diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c index d10cc1924e46..49bce1b085ce 100644 --- a/net/netfilter/nf_conntrack_netlink.c +++ b/net/netfilter/nf_conntrack_netlink.c @@ -328,16 +328,16 @@ static int ctnetlink_dump_mark(struct sk_buff *skb, const struct nf_conn *ct) static int ctnetlink_dump_secctx(struct sk_buff *skb, const struct nf_conn *ct) { struct nlattr *nest_secctx; - int len, ret; - char *secctx; + int ret; struct lsm_export le; + struct lsm_context lc; lsm_export_init(&le); le.flags = LSM_EXPORT_SELINUX | LSM_EXPORT_SMACK; le.selinux = ct->secmark; le.smack = ct->secmark; - ret = security_secid_to_secctx(&le, &secctx, &len); + ret = security_secid_to_secctx(&le, &lc.context, &lc.len); if (ret) return 0; @@ -346,13 +346,13 @@ static int ctnetlink_dump_secctx(struct sk_buff *skb, const struct nf_conn *ct) if (!nest_secctx) goto nla_put_failure; - if (nla_put_string(skb, CTA_SECCTX_NAME, secctx)) + if (nla_put_string(skb, CTA_SECCTX_NAME, lc.context)) goto nla_put_failure; nla_nest_end(skb, nest_secctx); ret = 0; nla_put_failure: - security_release_secctx(secctx, len); + security_release_secctx(&lc); return ret; } #else diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c index d353f3efc5a5..97d16a51504b 100644 --- a/net/netfilter/nf_conntrack_standalone.c +++ b/net/netfilter/nf_conntrack_standalone.c @@ -173,9 +173,8 @@ static void ct_seq_stop(struct seq_file *s, void *v) static void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) { int ret; - u32 len; - char *secctx; struct lsm_export le; + struct lsm_context lc; /* Whichever LSM may be using the secmark */ lsm_export_init(&le); @@ -183,13 +182,13 @@ static void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) le.selinux = ct->secmark; le.smack = ct->secmark; - ret = security_secid_to_secctx(&le, &secctx, &len); + ret = security_secid_to_secctx(&le, &lc.context, &lc.len); if (ret) return; - seq_printf(s, "secctx=%s ", secctx); + seq_printf(s, "secctx=%s ", lc.context); - security_release_secctx(secctx, len); + security_release_secctx(&lc); } #else static inline void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index a0670137477b..b70871693368 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c @@ -307,9 +307,9 @@ static int nfqnl_put_sk_uidgid(struct sk_buff *skb, struct sock *sk) static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, char **secdata) { - u32 seclen = 0; #if IS_ENABLED(CONFIG_NETWORK_SECMARK) struct lsm_export le; + struct lsm_context lc = { .context = NULL, .len = 0, }; if (!skb || !sk_fullsock(skb->sk)) return 0; @@ -322,12 +322,15 @@ static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, char **secdata) le.flags = LSM_EXPORT_SELINUX | LSM_EXPORT_SMACK; le.selinux = skb->secmark; le.smack = skb->secmark; - security_secid_to_secctx(&le, secdata, &seclen); + security_secid_to_secctx(&le, &lc.context, &lc.len); + *secdata = lc.context; } read_unlock_bh(&skb->sk->sk_callback_lock); + return lc.len; +#else + return 0; #endif - return seclen; } static u32 nfqnl_get_bridge_size(struct nf_queue_entry *entry) @@ -403,8 +406,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, enum ip_conntrack_info uninitialized_var(ctinfo); struct nfnl_ct_hook *nfnl_ct; bool csum_verify; - char *secdata = NULL; - u32 seclen = 0; + struct lsm_context lc = { .context = NULL, }; size = nlmsg_total_size(sizeof(struct nfgenmsg)) + nla_total_size(sizeof(struct nfqnl_msg_packet_hdr)) @@ -470,9 +472,9 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, } if ((queue->flags & NFQA_CFG_F_SECCTX) && entskb->sk) { - seclen = nfqnl_get_sk_secctx(entskb, &secdata); - if (seclen) - size += nla_total_size(seclen); + lc.len = nfqnl_get_sk_secctx(entskb, &lc.context); + if (lc.len) + size += nla_total_size(lc.len); } skb = alloc_skb(size, GFP_ATOMIC); @@ -605,7 +607,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, nfqnl_put_sk_uidgid(skb, entskb->sk) < 0) goto nla_put_failure; - if (seclen && nla_put(skb, NFQA_SECCTX, seclen, secdata)) + if (lc.len && nla_put(skb, NFQA_SECCTX, lc.len, lc.context)) goto nla_put_failure; if (ct && nfnl_ct->build(skb, ct, ctinfo, NFQA_CT, NFQA_CT_INFO) < 0) @@ -633,8 +635,8 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, } nlh->nlmsg_len = skb->len; - if (seclen) - security_release_secctx(secdata, seclen); + if (lc.context) + security_release_secctx(&lc); return skb; nla_put_failure: @@ -642,8 +644,8 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, kfree_skb(skb); net_err_ratelimited("nf_queue: error creating packet message\n"); nlmsg_failure: - if (seclen) - security_release_secctx(secdata, seclen); + if (lc.context) + security_release_secctx(&lc); return NULL; } diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c index 707ea5a364b0..4c4a8f6df261 100644 --- a/net/netlabel/netlabel_unlabeled.c +++ b/net/netlabel/netlabel_unlabeled.c @@ -387,8 +387,6 @@ int netlbl_unlhsh_add(struct net *net, struct net_device *dev; struct netlbl_unlhsh_iface *iface; struct audit_buffer *audit_buf = NULL; - char *secctx = NULL; - u32 secctx_len; if (addr_len != sizeof(struct in_addr) && addr_len != sizeof(struct in6_addr)) @@ -451,9 +449,10 @@ int netlbl_unlhsh_add(struct net *net, unlhsh_add_return: rcu_read_unlock(); if (audit_buf != NULL) { - if (security_secid_to_secctx(l, &secctx, &secctx_len) == 0) { - audit_log_format(audit_buf, " sec_obj=%s", secctx); - security_release_secctx(secctx, secctx_len); + struct lsm_context lc; + if (security_secid_to_secctx(l, &lc.context, &lc.len) == 0) { + audit_log_format(audit_buf, " sec_obj=%s", lc.context); + security_release_secctx(&lc); } audit_log_format(audit_buf, " res=%u", ret_val == 0 ? 1 : 0); audit_log_end(audit_buf); @@ -484,8 +483,6 @@ static int netlbl_unlhsh_remove_addr4(struct net *net, struct netlbl_unlhsh_addr4 *entry; struct audit_buffer *audit_buf; struct net_device *dev; - char *secctx; - u32 secctx_len; spin_lock(&netlbl_unlhsh_lock); list_entry = netlbl_af4list_remove(addr->s_addr, mask->s_addr, @@ -499,6 +496,7 @@ static int netlbl_unlhsh_remove_addr4(struct net *net, audit_buf = netlbl_audit_start_common(AUDIT_MAC_UNLBL_STCDEL, audit_info); if (audit_buf != NULL) { + struct lsm_context lc; dev = dev_get_by_index(net, iface->ifindex); netlbl_af4list_audit_addr(audit_buf, 1, (dev != NULL ? dev->name : NULL), @@ -507,9 +505,9 @@ static int netlbl_unlhsh_remove_addr4(struct net *net, dev_put(dev); if (entry != NULL && security_secid_to_secctx(&entry->le, - &secctx, &secctx_len) == 0) { - audit_log_format(audit_buf, " sec_obj=%s", secctx); - security_release_secctx(secctx, secctx_len); + &lc.context, &lc.len) == 0) { + audit_log_format(audit_buf, " sec_obj=%s", lc.context); + security_release_secctx(&lc); } audit_log_format(audit_buf, " res=%u", entry != NULL ? 1 : 0); audit_log_end(audit_buf); @@ -560,6 +558,7 @@ static int netlbl_unlhsh_remove_addr6(struct net *net, audit_buf = netlbl_audit_start_common(AUDIT_MAC_UNLBL_STCDEL, audit_info); if (audit_buf != NULL) { + struct lsm_context lc; dev = dev_get_by_index(net, iface->ifindex); netlbl_af6list_audit_addr(audit_buf, 1, (dev != NULL ? dev->name : NULL), @@ -568,9 +567,9 @@ static int netlbl_unlhsh_remove_addr6(struct net *net, dev_put(dev); if (entry != NULL && security_secid_to_secctx(&entry->le, - &secctx, &secctx_len) == 0) { - audit_log_format(audit_buf, " sec_obj=%s", secctx); - security_release_secctx(secctx, secctx_len); + &lc.context, &lc.len) == 0) { + audit_log_format(audit_buf, " sec_obj=%s", lc.context); + security_release_secctx(&lc); } audit_log_format(audit_buf, " res=%u", entry != NULL ? 1 : 0); audit_log_end(audit_buf); @@ -1082,9 +1081,8 @@ static int netlbl_unlabel_staticlist_gen(u32 cmd, struct netlbl_unlhsh_walk_arg *cb_arg = arg; struct net_device *dev; void *data; - char *secctx; - u32 secctx_len; struct lsm_export *lep; + struct lsm_context lc; data = genlmsg_put(cb_arg->skb, NETLINK_CB(cb_arg->nl_cb->skb).portid, cb_arg->seq, &netlbl_unlabel_gnl_family, @@ -1139,14 +1137,14 @@ static int netlbl_unlabel_staticlist_gen(u32 cmd, lep = (struct lsm_export *)&addr6->le; } - ret_val = security_secid_to_secctx(lep, &secctx, &secctx_len); + ret_val = security_secid_to_secctx(lep, &lc.context, &lc.len); if (ret_val != 0) goto list_cb_failure; ret_val = nla_put(cb_arg->skb, NLBL_UNLABEL_A_SECCTX, - secctx_len, - secctx); - security_release_secctx(secctx, secctx_len); + lc.len, + lc.context); + security_release_secctx(&lc); if (ret_val != 0) goto list_cb_failure; diff --git a/net/netlabel/netlabel_user.c b/net/netlabel/netlabel_user.c index 2cc96305c841..0418f0935199 100644 --- a/net/netlabel/netlabel_user.c +++ b/net/netlabel/netlabel_user.c @@ -98,8 +98,7 @@ struct audit_buffer *netlbl_audit_start_common(int type, struct netlbl_audit *audit_info) { struct audit_buffer *audit_buf; - char *secctx; - u32 secctx_len; + struct lsm_context lc; if (audit_enabled == AUDIT_OFF) return NULL; @@ -113,10 +112,10 @@ struct audit_buffer *netlbl_audit_start_common(int type, audit_info->sessionid); if (lsm_export_any(&audit_info->le) && - security_secid_to_secctx(&audit_info->le, &secctx, - &secctx_len) == 0) { - audit_log_format(audit_buf, " subj=%s", secctx); - security_release_secctx(secctx, secctx_len); + security_secid_to_secctx(&audit_info->le, &lc.context, + &lc.len) == 0) { + audit_log_format(audit_buf, " subj=%s", lc.context); + security_release_secctx(&lc); } return audit_buf; diff --git a/security/security.c b/security/security.c index 029d2f4fe48c..3da7302d20ec 100644 --- a/security/security.c +++ b/security/security.c @@ -1981,7 +1981,7 @@ int security_secid_to_secctx(struct lsm_export *l, char **secdata, u32 *seclen) if (secdata) *secdata = lc.context; else - security_release_secctx(lc.context, lc.len); + security_release_secctx(&lc); *seclen = lc.len; return rc; } @@ -1994,13 +1994,9 @@ int security_secctx_to_secid(struct lsm_context *cp, struct lsm_export *l) } EXPORT_SYMBOL(security_secctx_to_secid); -void security_release_secctx(char *secdata, u32 seclen) +void security_release_secctx(struct lsm_context *cp) { - struct lsm_context lc; - - lc.context = secdata; - lc.len = seclen; - call_one_void_hook(release_secctx, &lc); + call_one_void_hook(release_secctx, cp); } EXPORT_SYMBOL(security_release_secctx); From patchwork Sun Jun 2 16:50:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971993 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B2F706C5 for ; Sun, 2 Jun 2019 16:54:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2FA82873A for ; Sun, 2 Jun 2019 16:54:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 976F528A08; Sun, 2 Jun 2019 16:54:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A04362873A for ; Sun, 2 Jun 2019 16:54:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727085AbfFBQyN (ORCPT ); Sun, 2 Jun 2019 12:54:13 -0400 Received: from sonic316-12.consmr.mail.gq1.yahoo.com ([98.137.69.36]:43275 "EHLO sonic316-12.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727093AbfFBQyM (ORCPT ); Sun, 2 Jun 2019 12:54:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494451; bh=20Rb5jYWo49Bap1qMEB12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0LuCDI9ryj XNw.61_sIqEVKjoeVh0RYN9O.gkIdm1hQpef4rz2XSTx6xrboHuam2enhe_GStxt_ZG1VZeegvNn wcn9ulh7C.wS_6bqwYtY7AO3dKfuVOBaZJdrjrKgylTMM1gLnrzqbH86HqZaekqGGQdqrL4jc1Fj ebY9eI3HzoVKZLcoj9odfadD_27Z.rtnITnx1Sb8oXZjedlof92ZBfX6ZUg3LZi9cz7bvfVneeg9 jMLxiN.6IIyDowTjQw2TfpH2FMY_dT5C2wxCOm5EeKMpGKlcqy1g3RVuPltHBwobWmdrhooZ75Z1 oVhHRQAPW8stedj94y8YmFxUN89DgFNBpxcz0uyzpHir3fkPsxKaAQpKZeSJKqYZHCDm1PPOTDIy nZqfL.4syztHeZyMwFWIkp7SMIDidiB_UxL4gTi0CwTF.nGqsbTZmpAzlPiAKu4duBy8hAcqQEUb 7FLLlEuxiPAhz6S_XnRxpy814bf8XIyywe0f7D1Yy1Y8jnlyafIpt7aeu3yISJtHgEQbyOpdOdGp YlSZqPFHopegZADxI7Bc.9XgiEg8DP62.1p1.AV_gZ2.0u7yFPdFFXGXBAnY10lNbfLyEk_nc0Zd fl4jGN.qs5NvB3lgDJcjESADB9ZVhMAlMH8DOjkYcSo7Z3jPY.h8- Received: from sonic.gate.mail.ne1.yahoo.com by sonic316.consmr.mail.gq1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:54:11 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp430.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e9ca3210f73b95a606016904e284b22a; Sun, 02 Jun 2019 16:54:07 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 48/58] LSM: Use lsm_context in security_secid_to_secctx Date: Sun, 2 Jun 2019 09:50:51 -0700 Message-Id: <20190602165101.25079-49-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_secid_to_secctx to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Add a flag for lsm_export to indicate that the caller of security_secid_to_secctx() is only interested in the length of the context. Signed-off-by: Casey Schaufler --- drivers/android/binder.c | 2 +- include/linux/security.h | 13 +++++++------ include/net/scm.h | 2 +- kernel/audit.c | 5 ++--- kernel/auditsc.c | 10 +++++----- net/ipv4/ip_sockglue.c | 2 +- net/netfilter/nf_conntrack_netlink.c | 11 ++++++----- net/netfilter/nf_conntrack_standalone.c | 2 +- net/netfilter/nfnetlink_queue.c | 2 +- net/netlabel/netlabel_unlabeled.c | 12 ++++-------- net/netlabel/netlabel_user.c | 3 +-- security/apparmor/secid.c | 3 +-- security/security.c | 13 ++----------- security/selinux/hooks.c | 3 +++ security/smack/smack_lsm.c | 2 +- 15 files changed, 37 insertions(+), 48 deletions(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index c2cfef13257c..58033c003cc2 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -3121,7 +3121,7 @@ static void binder_transaction(struct binder_proc *proc, struct lsm_export le; security_task_getsecid(proc->tsk, &le); - ret = security_secid_to_secctx(&le, &lc.context, &lc.len); + ret = security_secid_to_secctx(&le, &lc); if (ret) { return_error = BR_FAILED_REPLY; return_error_param = ret; diff --git a/include/linux/security.h b/include/linux/security.h index 57ce9b824eef..9a9de2bafa55 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -83,10 +83,11 @@ struct lsm_export { u32 apparmor; u32 flags; }; -#define LSM_EXPORT_NONE 0x00 -#define LSM_EXPORT_SELINUX 0x01 -#define LSM_EXPORT_SMACK 0x02 -#define LSM_EXPORT_APPARMOR 0x04 +#define LSM_EXPORT_NONE 0x00000000 +#define LSM_EXPORT_SELINUX 0x00000001 +#define LSM_EXPORT_SMACK 0x00000002 +#define LSM_EXPORT_APPARMOR 0x00000004 +#define LSM_EXPORT_LENGTH 0x80000000 /* Only the length required */ static inline void lsm_export_init(struct lsm_export *l) { @@ -431,7 +432,7 @@ int security_setprocattr(const char *lsm, const char *name, void *value, size_t size); int security_netlink_send(struct sock *sk, struct sk_buff *skb); int security_ismaclabel(const char *name); -int security_secid_to_secctx(struct lsm_export *l, char **secdata, u32 *seclen); +int security_secid_to_secctx(struct lsm_export *l, struct lsm_context *cp); int security_secctx_to_secid(struct lsm_context *cp, struct lsm_export *l); void security_release_secctx(struct lsm_context *cp); @@ -1211,7 +1212,7 @@ static inline int security_ismaclabel(const char *name) } static inline int security_secid_to_secctx(struct lsm_export *l, - char **secdata, u32 *seclen) + struct lsm_seccontext *cp) { return -EOPNOTSUPP; } diff --git a/include/net/scm.h b/include/net/scm.h index 7e242ebdd258..b25ca3b6a514 100644 --- a/include/net/scm.h +++ b/include/net/scm.h @@ -96,7 +96,7 @@ static inline void scm_passec(struct socket *sock, struct msghdr *msg, struct sc int err; if (test_bit(SOCK_PASSSEC, &sock->flags)) { - err = security_secid_to_secctx(&scm->le, &lc.context, &lc.len); + err = security_secid_to_secctx(&scm->le, &lc); if (!err) { put_cmsg(msg, SOL_SOCKET, SCM_SECURITY, diff --git a/kernel/audit.c b/kernel/audit.c index 269c76fefe40..203e5b14bea4 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -1428,8 +1428,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) } case AUDIT_SIGNAL_INFO: if (lsm_export_any(&audit_sig_lsm)) { - err = security_secid_to_secctx(&audit_sig_lsm, - &lc.context, &lc.len); + err = security_secid_to_secctx(&audit_sig_lsm, &lc); if (err) return err; } @@ -2076,7 +2075,7 @@ int audit_log_task_context(struct audit_buffer *ab) if (!lsm_export_any(&le)) return 0; - error = security_secid_to_secctx(&le, &lc.context, &lc.len); + error = security_secid_to_secctx(&le, &lc); if (error) { if (error != -EINVAL) goto error_path; diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 4dab81c7aca0..ceefd17467f9 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -938,7 +938,7 @@ static int audit_log_pid_context(struct audit_context *context, pid_t pid, unsigned int sessionid, struct lsm_export *l, char *comm) { - struct lsm_context lc = { .context = NULL, }; + struct lsm_context lc; struct audit_buffer *ab; int rc = 0; @@ -950,7 +950,7 @@ static int audit_log_pid_context(struct audit_context *context, pid_t pid, from_kuid(&init_user_ns, auid), from_kuid(&init_user_ns, uid), sessionid); if (lsm_export_any(l)) { - if (security_secid_to_secctx(l, &lc.context, &lc.len)) { + if (security_secid_to_secctx(l, &lc)) { audit_log_format(ab, " obj=(none)"); rc = 1; } else { @@ -1190,8 +1190,8 @@ static void show_special(struct audit_context *context, int *call_panic) from_kgid(&init_user_ns, context->ipc.gid), context->ipc.mode); if (lsm_export_any(l)) { - struct lsm_context lc = { .context = NULL, }; - if (security_secid_to_secctx(l, &lc.context, &lc.len)) { + struct lsm_context lc; + if (security_secid_to_secctx(l, &lc)) { audit_log_format(ab, " osid=(unknown)"); *call_panic = 1; } else { @@ -1342,7 +1342,7 @@ static void audit_log_name(struct audit_context *context, struct audit_names *n, if (lsm_export_any(&n->olsm)) { struct lsm_context lc; - if (security_secid_to_secctx(&n->olsm, &lc.context, &lc.len)) { + if (security_secid_to_secctx(&n->olsm, &lc)) { audit_log_format(ab, " osid=(unknown)"); if (call_panic) *call_panic = 2; diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c index 18a7fab8b2d3..56035b53952d 100644 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c @@ -138,7 +138,7 @@ static void ip_cmsg_recv_security(struct msghdr *msg, struct sk_buff *skb) if (err) return; - err = security_secid_to_secctx(&le, &lc.context, &lc.len); + err = security_secid_to_secctx(&le, &lc); if (err) return; diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c index 49bce1b085ce..ea83909af6db 100644 --- a/net/netfilter/nf_conntrack_netlink.c +++ b/net/netfilter/nf_conntrack_netlink.c @@ -337,7 +337,7 @@ static int ctnetlink_dump_secctx(struct sk_buff *skb, const struct nf_conn *ct) le.selinux = ct->secmark; le.smack = ct->secmark; - ret = security_secid_to_secctx(&le, &lc.context, &lc.len); + ret = security_secid_to_secctx(&le, &lc); if (ret) return 0; @@ -620,20 +620,21 @@ static inline size_t ctnetlink_acct_size(const struct nf_conn *ct) static inline int ctnetlink_secctx_size(const struct nf_conn *ct) { #ifdef CONFIG_NF_CONNTRACK_SECMARK - int len, ret; + int ret; struct lsm_export le; + struct lsm_context lc; lsm_export_init(&le); - le.flags = LSM_EXPORT_SELINUX | LSM_EXPORT_SMACK; + le.flags = LSM_EXPORT_SELINUX | LSM_EXPORT_SMACK | LSM_EXPORT_LENGTH; le.selinux = ct->secmark; le.smack = ct->secmark; - ret = security_secid_to_secctx(&le, NULL, &len); + ret = security_secid_to_secctx(&le, &lc); if (ret) return 0; return nla_total_size(0) /* CTA_SECCTX */ - + nla_total_size(sizeof(char) * len); /* CTA_SECCTX_NAME */ + + nla_total_size(sizeof(char) * lc.len); /* CTA_SECCTX_NAME */ #else return 0; #endif diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c index 97d16a51504b..797abf443a34 100644 --- a/net/netfilter/nf_conntrack_standalone.c +++ b/net/netfilter/nf_conntrack_standalone.c @@ -182,7 +182,7 @@ static void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) le.selinux = ct->secmark; le.smack = ct->secmark; - ret = security_secid_to_secctx(&le, &lc.context, &lc.len); + ret = security_secid_to_secctx(&le, &lc); if (ret) return; diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index b70871693368..4a3d4b52caef 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c @@ -322,7 +322,7 @@ static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, char **secdata) le.flags = LSM_EXPORT_SELINUX | LSM_EXPORT_SMACK; le.selinux = skb->secmark; le.smack = skb->secmark; - security_secid_to_secctx(&le, &lc.context, &lc.len); + security_secid_to_secctx(&le, &lc); *secdata = lc.context; } diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c index 4c4a8f6df261..336d315ee8eb 100644 --- a/net/netlabel/netlabel_unlabeled.c +++ b/net/netlabel/netlabel_unlabeled.c @@ -450,7 +450,7 @@ int netlbl_unlhsh_add(struct net *net, rcu_read_unlock(); if (audit_buf != NULL) { struct lsm_context lc; - if (security_secid_to_secctx(l, &lc.context, &lc.len) == 0) { + if (security_secid_to_secctx(l, &lc) == 0) { audit_log_format(audit_buf, " sec_obj=%s", lc.context); security_release_secctx(&lc); } @@ -504,8 +504,7 @@ static int netlbl_unlhsh_remove_addr4(struct net *net, if (dev != NULL) dev_put(dev); if (entry != NULL && - security_secid_to_secctx(&entry->le, - &lc.context, &lc.len) == 0) { + security_secid_to_secctx(&entry->le, &lc) == 0) { audit_log_format(audit_buf, " sec_obj=%s", lc.context); security_release_secctx(&lc); } @@ -544,8 +543,6 @@ static int netlbl_unlhsh_remove_addr6(struct net *net, struct netlbl_unlhsh_addr6 *entry; struct audit_buffer *audit_buf; struct net_device *dev; - char *secctx; - u32 secctx_len; spin_lock(&netlbl_unlhsh_lock); list_entry = netlbl_af6list_remove(addr, mask, &iface->addr6_list); @@ -566,8 +563,7 @@ static int netlbl_unlhsh_remove_addr6(struct net *net, if (dev != NULL) dev_put(dev); if (entry != NULL && - security_secid_to_secctx(&entry->le, - &lc.context, &lc.len) == 0) { + security_secid_to_secctx(&entry->le, &lc) == 0) { audit_log_format(audit_buf, " sec_obj=%s", lc.context); security_release_secctx(&lc); } @@ -1137,7 +1133,7 @@ static int netlbl_unlabel_staticlist_gen(u32 cmd, lep = (struct lsm_export *)&addr6->le; } - ret_val = security_secid_to_secctx(lep, &lc.context, &lc.len); + ret_val = security_secid_to_secctx(lep, &lc); if (ret_val != 0) goto list_cb_failure; ret_val = nla_put(cb_arg->skb, diff --git a/net/netlabel/netlabel_user.c b/net/netlabel/netlabel_user.c index 0418f0935199..11ea98525c4e 100644 --- a/net/netlabel/netlabel_user.c +++ b/net/netlabel/netlabel_user.c @@ -112,8 +112,7 @@ struct audit_buffer *netlbl_audit_start_common(int type, audit_info->sessionid); if (lsm_export_any(&audit_info->le) && - security_secid_to_secctx(&audit_info->le, &lc.context, - &lc.len) == 0) { + security_secid_to_secctx(&audit_info->le, &lc) == 0) { audit_log_format(audit_buf, " subj=%s", lc.context); security_release_secctx(&lc); } diff --git a/security/apparmor/secid.c b/security/apparmor/secid.c index 46c8b9a67ac7..9dc17903a936 100644 --- a/security/apparmor/secid.c +++ b/security/apparmor/secid.c @@ -92,8 +92,7 @@ int apparmor_secid_to_secctx(struct lsm_export *l, struct lsm_context *cp) if (!label) return -EINVAL; - /* scaffolding check - Casey */ - if (cp) + if (!(l->flags & LSM_EXPORT_LENGTH)) len = aa_label_asxprint(&cp->context, root_ns, label, FLAG_SHOW_MODE | FLAG_VIEW_SUBNS | FLAG_HIDDEN_UNCONFINED | FLAG_ABS_ROOT, diff --git a/security/security.c b/security/security.c index 3da7302d20ec..6588172b3ec8 100644 --- a/security/security.c +++ b/security/security.c @@ -1972,18 +1972,9 @@ int security_ismaclabel(const char *name) } EXPORT_SYMBOL(security_ismaclabel); -int security_secid_to_secctx(struct lsm_export *l, char **secdata, u32 *seclen) +int security_secid_to_secctx(struct lsm_export *l, struct lsm_context *cp) { - struct lsm_context lc = { .context = NULL, .len = 0, }; - int rc; - - rc = call_one_int_hook(secid_to_secctx, -EOPNOTSUPP, l, &lc); - if (secdata) - *secdata = lc.context; - else - security_release_secctx(&lc); - *seclen = lc.len; - return rc; + return call_one_int_hook(secid_to_secctx, -EOPNOTSUPP, l, cp); } EXPORT_SYMBOL(security_secid_to_secctx); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 332296f69f76..7bf73493d10d 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6306,6 +6306,9 @@ static int selinux_secid_to_secctx(struct lsm_export *l, struct lsm_context *cp) u32 secid; selinux_import_secid(l, &secid); + if (l->flags & LSM_EXPORT_LENGTH) + return security_sid_to_context(&selinux_state, secid, + NULL, &cp->len); return security_sid_to_context(&selinux_state, secid, &cp->context, &cp->len); } diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index cf27905ccaa5..1b5b3e421bff 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4442,7 +4442,7 @@ static int smack_secid_to_secctx(struct lsm_export *l, struct lsm_context *cp) smack_import_secid(l, &secid); skp = smack_from_secid(secid); - cp->context = skp->smk_known; + cp->context = (l->flags & LSM_EXPORT_LENGTH) ? NULL : skp->smk_known; cp->len = strlen(skp->smk_known); return 0; } From patchwork Sun Jun 2 16:50:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971997 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6440B92A for ; Sun, 2 Jun 2019 16:54:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5219D289FA for ; Sun, 2 Jun 2019 16:54:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4631F2873A; Sun, 2 Jun 2019 16:54:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6828C286E4 for ; Sun, 2 Jun 2019 16:54:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726229AbfFBQyN (ORCPT ); Sun, 2 Jun 2019 12:54:13 -0400 Received: from sonic316-12.consmr.mail.gq1.yahoo.com ([98.137.69.36]:38348 "EHLO sonic316-12.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727091AbfFBQyN (ORCPT ); Sun, 2 Jun 2019 12:54:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494451; bh=obxKrBiGm3LYlnlm6RakpP9K6J8LRUBE6b25/AUVMcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=GriIx00SWfM93iMZMF8sf6u8kS5lJSBLe2TRrROIhLb8a/1yVqJyVuX6b4wKDNAipL7wcA8NdVCNPTps6zGtn4ZuTjJzEux/w+ZPJ6wixyz8QBvwc6Njuk0NOjXc9VFn8imm6sxVu9+z3eNVl2GGo1QOjhhxRRBc5Et28ja0+/P2/Rj9PVzx0WhM5lW1gxXULZYd5awJtNmjbWWo7CwEC/LJ1q3qdhrVodAgv7Kz0SJauQOvdf6Rvv+ozys6HYFSKoZ2QxI5NzAEPl3fW6kLJwG+N5PUmqHO0zWlggGlnfucLwRoUfBRjbqhJ42un3l5yfl0EiSZ9tHzEPVPOimoUQ== X-YMail-OSG: RnqxIx8VM1nSzo_fVTc8TDT39_g.Zm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6zJRbEWPr2FzU57q vj3mftfR3qLRdW1NsQvl3d6nvlu1RtH0OipDV2mTI8Emu53OSamWTJ9D3S.__PwXZ_MzLZiyaH50 yj.ND1d_XQ_NYaFdT8hLzQyd68iOWtj2vvqd6XZyMXpUXi6tMuo2wAXXpiNqDAhjw22U1VyG2u0V 2XFB2jzEND9x2W7ygYFkNlCwHjxASmLyCKRLjZbYQB6z7jmTBOKY5lA-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic316.consmr.mail.gq1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:54:11 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp430.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e9ca3210f73b95a606016904e284b22a; Sun, 02 Jun 2019 16:54:08 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 49/58] fs: remove lsm_context scaffolding Date: Sun, 2 Jun 2019 09:50:52 -0700 Message-Id: <20190602165101.25079-50-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The conversion from secctx/seclen pairs to the lsm_context structure used scaffolding in kernfs and nfs. Replace the secctx/seclen pairs in the filesystem local datastructures with a lsm_context. Signed-off-by: Casey Schaufler --- fs/kernfs/dir.c | 9 +++------ fs/kernfs/inode.c | 13 +++++-------- fs/kernfs/kernfs-internal.h | 3 +-- fs/nfs/inode.c | 15 ++++++--------- fs/nfs/internal.h | 8 ++++---- fs/nfs/nfs4proc.c | 27 +++++++++++---------------- fs/nfs/nfs4xdr.c | 16 +++++++++------- include/linux/nfs4.h | 8 ++++---- 8 files changed, 43 insertions(+), 56 deletions(-) diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 11672c075a8b..48506e856573 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c @@ -532,12 +532,9 @@ void kernfs_put(struct kernfs_node *kn) kfree_const(kn->name); if (kn->iattr) { - if (kn->iattr->ia_secdata) { - struct lsm_context lc; /* Scaffolding -Casey */ - lc.context = kn->iattr->ia_secdata; - lc.len = kn->iattr->ia_secdata_len; - security_release_secctx(&lc); - } + if (kn->iattr->ia_context.context) + security_release_secctx( + &kn->iattr->ia_context); simple_xattrs_free(&kn->iattr->xattrs); kmem_cache_free(kernfs_iattrs_cache, kn->iattr); } diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c index 45781f0da80f..4c7da446d210 100644 --- a/fs/kernfs/inode.c +++ b/fs/kernfs/inode.c @@ -141,11 +141,11 @@ static int kernfs_node_setsecdata(struct kernfs_iattrs *attrs, void **secdata, void *old_secdata; size_t old_secdata_len; - old_secdata = attrs->ia_secdata; - old_secdata_len = attrs->ia_secdata_len; + old_secdata = attrs->ia_context.context; + old_secdata_len = attrs->ia_context.len; - attrs->ia_secdata = *secdata; - attrs->ia_secdata_len = *secdata_len; + attrs->ia_context.context = *secdata; + attrs->ia_context.len = *secdata_len; *secdata = old_secdata; *secdata_len = old_secdata_len; @@ -184,7 +184,6 @@ static inline void set_inode_attr(struct inode *inode, struct iattr *iattr) static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode) { struct kernfs_iattrs *attrs = kn->iattr; - struct lsm_context lc; /* Scaffolding -Casey */ inode->i_mode = kn->mode; if (attrs) { @@ -193,9 +192,7 @@ static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode) * persistent copy in kernfs_node. */ set_inode_attr(inode, &attrs->ia_iattr); - lc.context = attrs->ia_secdata; - lc.len = attrs->ia_secdata_len; - security_inode_notifysecctx(inode, &lc); + security_inode_notifysecctx(inode, &attrs->ia_context); } if (kernfs_type(kn) == KERNFS_DIR) diff --git a/fs/kernfs/kernfs-internal.h b/fs/kernfs/kernfs-internal.h index 0b7d197a904c..2a870795bb3e 100644 --- a/fs/kernfs/kernfs-internal.h +++ b/fs/kernfs/kernfs-internal.h @@ -21,8 +21,7 @@ struct kernfs_iattrs { struct iattr ia_iattr; - void *ia_secdata; - u32 ia_secdata_len; + struct lsm_context ia_context; struct simple_xattrs xattrs; }; diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 8d0be9767b14..a9a3ec40a90c 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -340,22 +340,19 @@ static void nfs_clear_label_invalid(struct inode *inode) void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr, struct nfs4_label *label) { - struct lsm_context lc; /* Scaffolding -Casey */ int error; if (label == NULL) return; if ((fattr->valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL) && inode->i_security) { - lc.context = label->label; - lc.len = label->len; - error = security_inode_notifysecctx(inode, &lc); + error = security_inode_notifysecctx(inode, &label->context); if (error) printk(KERN_ERR "%s() %s %d " "security_inode_notifysecctx() %d\n", __func__, - (char *)label->label, - label->len, error); + label->context.context, + label->context.len, error); nfs_clear_label_invalid(inode); } } @@ -375,12 +372,12 @@ struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) if (label == NULL) return ERR_PTR(-ENOMEM); - label->label = kzalloc(NFS4_MAXLABELLEN, flags); - if (label->label == NULL) { + label->context.context = kzalloc(NFS4_MAXLABELLEN, flags); + if (label->context.context == NULL) { kfree(label); return ERR_PTR(-ENOMEM); } - label->len = NFS4_MAXLABELLEN; + label->context.len = NFS4_MAXLABELLEN; return label; } diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index c7cf23ae6597..63de73024b5f 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h @@ -307,20 +307,20 @@ nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src) if (!dst || !src) return NULL; - if (src->len > NFS4_MAXLABELLEN) + if (src->context.len > NFS4_MAXLABELLEN) return NULL; dst->lfs = src->lfs; dst->pi = src->pi; - dst->len = src->len; - memcpy(dst->label, src->label, src->len); + dst->context.len = src->context.len; + memcpy(dst->context.context, src->context.context, src->context.len); return dst; } static inline void nfs4_label_free(struct nfs4_label *label) { if (label) { - kfree(label->label); + kfree(label->context.context); kfree(label); } return; diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 8dee01eda643..b2480d0341f1 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -113,7 +113,6 @@ static inline struct nfs4_label * nfs4_label_init_security(struct inode *dir, struct dentry *dentry, struct iattr *sattr, struct nfs4_label *label) { - struct lsm_context lc; /* Scaffolding -Casey */ int err; if (label == NULL) @@ -123,9 +122,7 @@ nfs4_label_init_security(struct inode *dir, struct dentry *dentry, return NULL; err = security_dentry_init_security(dentry, sattr->ia_mode, - &dentry->d_name, &lc); - label->label = lc.context; - label->len = lc.len; + &dentry->d_name, &label->context); if (err == 0) return label; @@ -134,13 +131,8 @@ nfs4_label_init_security(struct inode *dir, struct dentry *dentry, static inline void nfs4_label_release_security(struct nfs4_label *label) { - struct lsm_context lc; /* Scaffolding -Casey */ - - if (label) { - lc.context = label->label; - lc.len = label->len; - security_release_secctx(&lc); - } + if (label) + security_release_secctx(&label->context); } static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label) { @@ -3556,7 +3548,9 @@ nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, int open_flags, struct iattr *attr, int *opened) { struct nfs4_state *state; - struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; + struct nfs4_label *label = NULL; + struct nfs4_label l = {0, 0, + .context = { .context = NULL, .len = 0, }, }; label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); @@ -5595,7 +5589,8 @@ static int _nfs4_get_security_label(struct inode *inode, void *buf, { struct nfs_server *server = NFS_SERVER(inode); struct nfs_fattr fattr; - struct nfs4_label label = {0, 0, buflen, buf}; + struct nfs4_label label = {0, 0, + .context = { .context = buf, .len = buflen, }, }; u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL }; struct nfs4_getattr_arg arg = { @@ -5621,7 +5616,7 @@ static int _nfs4_get_security_label(struct inode *inode, void *buf, return ret; if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL)) return -ENOENT; - if (buflen < label.len) + if (buflen < label.context.len) return -ERANGE; return 0; } @@ -5713,8 +5708,8 @@ nfs4_set_security_label(struct inode *inode, const void *buf, size_t buflen) ilabel.pi = 0; ilabel.lfs = 0; - ilabel.label = (char *)buf; - ilabel.len = buflen; + ilabel.context.context = (char *)buf; + ilabel.context.len = buflen; olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); if (IS_ERR(olabel)) { diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index cfcabc33e24d..85a527ccd6d7 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c @@ -1141,7 +1141,7 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, } if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) { - len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2); + len += 4 + 4 + 4 + (XDR_QUADLEN(label->context.len) << 2); bmval[2] |= FATTR4_WORD2_SECURITY_LABEL; } @@ -1175,8 +1175,9 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { *p++ = cpu_to_be32(label->lfs); *p++ = cpu_to_be32(label->pi); - *p++ = cpu_to_be32(label->len); - p = xdr_encode_opaque_fixed(p, label->label, label->len); + *p++ = cpu_to_be32(label->context.len); + p = xdr_encode_opaque_fixed(p, label->context.context, + label->context.len); } if (bmval[2] & FATTR4_WORD2_MODE_UMASK) { *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO); @@ -4163,8 +4164,8 @@ static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap, return -EIO; if (len < NFS4_MAXLABELLEN) { if (label) { - memcpy(label->label, p, len); - label->len = len; + memcpy(label->context.context, p, len); + label->context.len = len; label->pi = pi; label->lfs = lfs; status = NFS_ATTR_FATTR_V4_SECURITY_LABEL; @@ -4174,9 +4175,10 @@ static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap, printk(KERN_WARNING "%s: label too long (%u)!\n", __func__, len); } - if (label && label->label) + if (label && label->context.context) dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__, - (char *)label->label, label->len, label->pi, label->lfs); + (char *)label->context.context, label->context.len, + label->pi, label->lfs); return status; } diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h index 22494d170619..1189aad71592 100644 --- a/include/linux/nfs4.h +++ b/include/linux/nfs4.h @@ -15,6 +15,7 @@ #include #include +#include #include enum nfs4_acl_whotype { @@ -43,10 +44,9 @@ struct nfs4_acl { #define NFS4_MAXLABELLEN 2048 struct nfs4_label { - uint32_t lfs; - uint32_t pi; - u32 len; - char *label; + uint32_t lfs; + uint32_t pi; + struct lsm_context context; }; typedef struct { char data[NFS4_VERIFIER_SIZE]; } nfs4_verifier; From patchwork Sun Jun 2 16:50:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971989 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C7CFA6C5 for ; Sun, 2 Jun 2019 16:54:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B24591FF40 for ; Sun, 2 Jun 2019 16:54:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3F2828A00; Sun, 2 Jun 2019 16:54:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F21F91FF40 for ; Sun, 2 Jun 2019 16:54:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727096AbfFBQyM (ORCPT ); Sun, 2 Jun 2019 12:54:12 -0400 Received: from sonic310-27.consmr.mail.gq1.yahoo.com ([98.137.69.153]:33522 "EHLO sonic310-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727085AbfFBQyM (ORCPT ); Sun, 2 Jun 2019 12:54:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494450; bh=BDqvrOe/Zpr49BPyFqMi2sAByPPxYi6emNEKjjpBQB4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=AMbBfeYzphfii8sUpptzPcRGYymxbR4YolKCEo2mOODJZkZkaXLpKYyP1mtfkWALMvZgzcRCuJRdWDkL+lFmufO4Q1j4Hp3SQPxyiSLeO1MNO0XdGu8D4dk1VDZ0pwaEda6/Eh+e1iN2G/6taZ16jH7ff8O50KaI4hpRPgqCQol7HH3xs53pNst49kQn2EYJRoVk4n74w6kinc3xCqZzpMcxdvB6tyaohlToqYx62/DP5Tqq2YUqOgsy6GM4MyvIgYT3pscW+cuu+DvLdtLYb7OFrCor4e4p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CPlJtq26H.zU3BCxTEpSTNVeNK0m9M5KEyPds7g5Fii8IF.8s0p76HAC eEG60HSoRnKUShOYu2XUSxqL30.IClj2nDT_fdlyvufaL5IfEeDej1wCSk090ibH6N9aR7Oym3Ke i2PlbsxKc.gMNO3yWWnbO2a9Yb2hhkxH.Auw39IXjpQXes.VGDsvUnTWLTwfcL3SXLi0Z_t2kgUU Ylnf3IiF1e2miHV4qd_SGz_ShQjZB0I3mvWqxXcQ3uOMaDbxhme9q_X2uQxBugwup4JuPmbdwkyx T0SjsSNlaaja_QMFjEfGkeSQNxSimh2LA6dhjLv8V7K9Iws2VTpHCQDs- Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.gq1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:54:10 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp430.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e9ca3210f73b95a606016904e284b22a; Sun, 02 Jun 2019 16:54:09 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 50/58] LSM: Add the release function to the lsm_context Date: Sun, 2 Jun 2019 09:50:53 -0700 Message-Id: <20190602165101.25079-51-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In order to ensure that the release function for a lsm_context matches the LSM that allocated it an element is added to the lsm_context structure to contain a pointer to it. This function is called in security_release_secctx instead of relying on a value in a hook list. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 6 ------ include/linux/security.h | 1 + security/apparmor/lsm.c | 1 - security/apparmor/secid.c | 11 ++++++----- security/security.c | 5 ++++- security/selinux/hooks.c | 14 ++++++++------ security/smack/smack_lsm.c | 16 ++++++++-------- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 3a779a0f9e15..d1235a3cd8e9 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1326,10 +1326,6 @@ * @cp contains the security context. * @l contains the pointer to the generated security data. * - * @release_secctx: - * Release the security context. - * @secdata contains the security context. - * * Security hooks for Audit * * @audit_rule_init: @@ -1662,7 +1658,6 @@ union security_list_options { int (*secid_to_secctx)(struct lsm_export *l, struct lsm_context *cp); int (*secctx_to_secid)(const struct lsm_context *cp, struct lsm_export *l); - void (*release_secctx)(struct lsm_context *cp); void (*inode_invalidate_secctx)(struct inode *inode); int (*inode_notifysecctx)(struct inode *inode, struct lsm_context *cp); @@ -1939,7 +1934,6 @@ struct security_hook_heads { struct hlist_head ismaclabel; struct hlist_head secid_to_secctx; struct hlist_head secctx_to_secid; - struct hlist_head release_secctx; struct hlist_head inode_invalidate_secctx; struct hlist_head inode_notifysecctx; struct hlist_head inode_setsecctx; diff --git a/include/linux/security.h b/include/linux/security.h index 9a9de2bafa55..94c714310ab7 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -121,6 +121,7 @@ static inline bool lsm_export_equal(struct lsm_export *l, struct lsm_export *m) struct lsm_context { char *context; u32 len; + void (*release)(struct lsm_context *cp); /* frees .context */ }; static inline void lsm_context_init(struct lsm_context *cp) diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 76c409737370..771b0ae24a5f 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -1225,7 +1225,6 @@ static struct security_hook_list apparmor_hooks[] __lsm_ro_after_init = { LSM_HOOK_INIT(secid_to_secctx, apparmor_secid_to_secctx), LSM_HOOK_INIT(secctx_to_secid, apparmor_secctx_to_secid), - LSM_HOOK_INIT(release_secctx, apparmor_release_secctx), }; /* diff --git a/security/apparmor/secid.c b/security/apparmor/secid.c index 9dc17903a936..30fd4ad80948 100644 --- a/security/apparmor/secid.c +++ b/security/apparmor/secid.c @@ -81,6 +81,11 @@ static inline void aa_export_secid(struct lsm_export *l, u32 secid) l->apparmor = secid; } +void apparmor_release_secctx(struct lsm_context *cp) +{ + kfree(cp->context); +} + int apparmor_secid_to_secctx(struct lsm_export *l, struct lsm_context *cp) { /* TODO: cache secctx and ref count so we don't have to recreate */ @@ -105,6 +110,7 @@ int apparmor_secid_to_secctx(struct lsm_export *l, struct lsm_context *cp) return -ENOMEM; cp->len = len; + cp->release = apparmor_release_secctx; return 0; } @@ -122,11 +128,6 @@ int apparmor_secctx_to_secid(const struct lsm_context *cp, struct lsm_export *l) return 0; } -void apparmor_release_secctx(struct lsm_context *cp) -{ - kfree(cp->context); -} - /** * aa_alloc_secid - allocate a new secid for a profile * @label: the label to allocate a secid for diff --git a/security/security.c b/security/security.c index 6588172b3ec8..c8ce190dcdda 100644 --- a/security/security.c +++ b/security/security.c @@ -1987,7 +1987,10 @@ EXPORT_SYMBOL(security_secctx_to_secid); void security_release_secctx(struct lsm_context *cp) { - call_one_void_hook(release_secctx, cp); + if (WARN_ON(cp->release == NULL)) + return; + cp->release(cp); + lsm_context_init(cp); } EXPORT_SYMBOL(security_release_secctx); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 7bf73493d10d..0e347a26c3d8 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -2812,6 +2812,11 @@ static void selinux_inode_free_security(struct inode *inode) inode_free_security(inode); } +static void selinux_release_secctx(struct lsm_context *cp) +{ + kfree(cp->context); +} + static int selinux_dentry_init_security(struct dentry *dentry, int mode, const struct qstr *name, struct lsm_context *cp) @@ -2826,6 +2831,7 @@ static int selinux_dentry_init_security(struct dentry *dentry, int mode, if (rc) return rc; + cp->release = selinux_release_secctx; return security_sid_to_context(&selinux_state, newsid, &cp->context, &cp->len); } @@ -6306,6 +6312,7 @@ static int selinux_secid_to_secctx(struct lsm_export *l, struct lsm_context *cp) u32 secid; selinux_import_secid(l, &secid); + cp->release = selinux_release_secctx; if (l->flags & LSM_EXPORT_LENGTH) return security_sid_to_context(&selinux_state, secid, NULL, &cp->len); @@ -6325,11 +6332,6 @@ static int selinux_secctx_to_secid(const struct lsm_context *cp, return rc; } -static void selinux_release_secctx(struct lsm_context *cp) -{ - kfree(cp->context); -} - static void selinux_inode_invalidate_secctx(struct inode *inode) { struct inode_security_struct *isec = selinux_inode(inode); @@ -6367,6 +6369,7 @@ static int selinux_inode_getsecctx(struct inode *inode, struct lsm_context *cp) if (len < 0) return len; cp->len = len; + cp->release = selinux_release_secctx; return 0; } #ifdef CONFIG_KEYS @@ -6781,7 +6784,6 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = { LSM_HOOK_INIT(ismaclabel, selinux_ismaclabel), LSM_HOOK_INIT(secid_to_secctx, selinux_secid_to_secctx), LSM_HOOK_INIT(secctx_to_secid, selinux_secctx_to_secid), - LSM_HOOK_INIT(release_secctx, selinux_release_secctx), LSM_HOOK_INIT(inode_invalidate_secctx, selinux_inode_invalidate_secctx), LSM_HOOK_INIT(inode_notifysecctx, selinux_inode_notifysecctx), LSM_HOOK_INIT(inode_setsecctx, selinux_inode_setsecctx), diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 1b5b3e421bff..e00346799cdf 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4425,6 +4425,12 @@ static int smack_ismaclabel(const char *name) return (strcmp(name, XATTR_SMACK_SUFFIX) == 0); } +/* + * The smack_release_secctx hook does nothing + */ +static void smack_release_secctx(struct lsm_context *cp) +{ +} /** * smack_secid_to_secctx - return the smack label for a secid @@ -4444,6 +4450,7 @@ static int smack_secid_to_secctx(struct lsm_export *l, struct lsm_context *cp) cp->context = (l->flags & LSM_EXPORT_LENGTH) ? NULL : skp->smk_known; cp->len = strlen(skp->smk_known); + cp->release = smack_release_secctx; return 0; } @@ -4467,13 +4474,6 @@ static int smack_secctx_to_secid(const struct lsm_context *cp, return 0; } -/* - * The smack_release_secctx hook does nothing - */ -static void smack_release_secctx(struct lsm_context *cp) -{ -} - static int smack_inode_notifysecctx(struct inode *inode, struct lsm_context *cp) { return smack_inode_setsecurity(inode, XATTR_SMACK_SUFFIX, cp->context, @@ -4491,6 +4491,7 @@ static int smack_inode_getsecctx(struct inode *inode, struct lsm_context *cp) cp->context = skp->smk_known; cp->len = strlen(skp->smk_known); + cp->release = smack_release_secctx; return 0; } @@ -4713,7 +4714,6 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = { LSM_HOOK_INIT(ismaclabel, smack_ismaclabel), LSM_HOOK_INIT(secid_to_secctx, smack_secid_to_secctx), LSM_HOOK_INIT(secctx_to_secid, smack_secctx_to_secid), - LSM_HOOK_INIT(release_secctx, smack_release_secctx), LSM_HOOK_INIT(inode_notifysecctx, smack_inode_notifysecctx), LSM_HOOK_INIT(inode_setsecctx, smack_inode_setsecctx), LSM_HOOK_INIT(inode_getsecctx, smack_inode_getsecctx), From patchwork Sun Jun 2 16:50:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10971985 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9FB5A92A for ; Sun, 2 Jun 2019 16:54:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DF091FF40 for ; Sun, 2 Jun 2019 16:54:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EEAD2873A; Sun, 2 Jun 2019 16:54:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18D161FF40 for ; Sun, 2 Jun 2019 16:54:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727087AbfFBQyL (ORCPT ); Sun, 2 Jun 2019 12:54:11 -0400 Received: from sonic310-27.consmr.mail.gq1.yahoo.com ([98.137.69.153]:34086 "EHLO sonic310-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726229AbfFBQyL (ORCPT ); Sun, 2 Jun 2019 12:54:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494450; bh=QOEIKGYoz1Vdbj2R6mhpXvN+kMT3nkCZkTlG/jPsC/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=oaequ1lwRc3BlCS+iBkoNGi/7ASEo2Cg8sPMNdtjt2r3sSRmN2v98+Bv78SsFaCo4ge2odqAvB/sdGBxluuOvIPAqL4PPgd2Qh+veVNSmXtpiz9DV/SA+C9rjSqE2RmDnhJ07TH3RhOWdmSs8YGQv4lAm1OM+VqBGJ5ogpS3AbpNE4yTP0eL7PUQf3ydZYoKGNGnWPJ+0u2ITxeIiT1MwpMSfvCxGnCAqGCzrPBTrBu2hURWIOYyrjHSPpgI6uWXEfmD1wylN3NX83XJ/u5ILHiNRKChnyqp/oeutu/pXyutOo+IIH4tY2Tgfw8TKcQP8Ft/lRetChTz2VwffDAnbQ== X-YMail-OSG: Oee7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r3FkmjPzWgyRi9fovEv9v9WYvdc8MiVPY7YbCdUwThV7AEL_ldOlDH 5jrhGuM7OkuugTyS5Epn7mXzJV41Dc5HYNi8bYI7d73TDJI5a_U7uTMlLuhrdaiHUMcCKPlhEMtD Y7nb8FD7K1_ensGfg29l8n1.YsWoF3T4qTURzllETlNrsWwoFiEtW8E0T9rzNVxwhgESe61jcgiz PuZbuB6.VmzBIrwRlixEGHzazP.vkgVTPjXVIs.RT2Wvx_LqP_bejJg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.gq1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:54:10 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp430.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e9ca3210f73b95a606016904e284b22a; Sun, 02 Jun 2019 16:54:10 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 51/58] LSM: Use lsm_context in inode_setsecctx hooks Date: Sun, 2 Jun 2019 09:50:54 -0700 Message-Id: <20190602165101.25079-52-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert SELinux and Smack to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 5 ++--- security/security.c | 6 +++++- security/selinux/hooks.c | 6 ++++-- security/smack/smack_lsm.c | 5 +++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index d1235a3cd8e9..088985d10a69 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1383,8 +1383,7 @@ * operation. * Must be called with inode->i_mutex locked. * @dentry contains the inode we wish to set the security context of. - * @ctx contains the string which we wish to set in the inode. - * @ctxlen contains the length of @ctx. + * @cp contains the string which we wish to set in the inode. * * @inode_getsecctx: * On success, returns 0 and fills out @cp with the security @@ -1661,7 +1660,7 @@ union security_list_options { void (*inode_invalidate_secctx)(struct inode *inode); int (*inode_notifysecctx)(struct inode *inode, struct lsm_context *cp); - int (*inode_setsecctx)(struct dentry *dentry, void *ctx, u32 ctxlen); + int (*inode_setsecctx)(struct dentry *dentry, struct lsm_context *cp); int (*inode_getsecctx)(struct inode *inode, struct lsm_context *cp); #ifdef CONFIG_SECURITY_NETWORK diff --git a/security/security.c b/security/security.c index c8ce190dcdda..9d09c774a1e9 100644 --- a/security/security.c +++ b/security/security.c @@ -2008,7 +2008,11 @@ EXPORT_SYMBOL(security_inode_notifysecctx); int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) { - return call_int_hook(inode_setsecctx, 0, dentry, ctx, ctxlen); + struct lsm_context lc; + + lc.context = ctx; + lc.len = ctxlen; + return call_int_hook(inode_setsecctx, 0, dentry, &lc); } EXPORT_SYMBOL(security_inode_setsecctx); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 0e347a26c3d8..af0d98f4dd37 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6356,9 +6356,11 @@ static int selinux_inode_notifysecctx(struct inode *inode, /* * called with inode->i_mutex locked */ -static int selinux_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) +static int selinux_inode_setsecctx(struct dentry *dentry, + struct lsm_context *cp) { - return __vfs_setxattr_noperm(dentry, XATTR_NAME_SELINUX, ctx, ctxlen, 0); + return __vfs_setxattr_noperm(dentry, XATTR_NAME_SELINUX, cp->context, + cp->len, 0); } static int selinux_inode_getsecctx(struct inode *inode, struct lsm_context *cp) diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index e00346799cdf..4570e8cac1b3 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4480,9 +4480,10 @@ static int smack_inode_notifysecctx(struct inode *inode, struct lsm_context *cp) cp->len, 0); } -static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) +static int smack_inode_setsecctx(struct dentry *dentry, struct lsm_context *cp) { - return __vfs_setxattr_noperm(dentry, XATTR_NAME_SMACK, ctx, ctxlen, 0); + return __vfs_setxattr_noperm(dentry, XATTR_NAME_SMACK, cp->context, + cp->len, 0); } static int smack_inode_getsecctx(struct inode *inode, struct lsm_context *cp) From patchwork Sun Jun 2 16:50:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10972001 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 06D796C5 for ; Sun, 2 Jun 2019 16:54:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9A661FF40 for ; Sun, 2 Jun 2019 16:54:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD4352873A; Sun, 2 Jun 2019 16:54:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 749871FF40 for ; Sun, 2 Jun 2019 16:54:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727100AbfFBQy0 (ORCPT ); Sun, 2 Jun 2019 12:54:26 -0400 Received: from sonic317-38.consmr.mail.ne1.yahoo.com ([66.163.184.49]:44719 "EHLO sonic317-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727097AbfFBQy0 (ORCPT ); Sun, 2 Jun 2019 12:54:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494464; bh=0jVxUPp+/V3kRc2gW7rNVCE5I4hyQouQVqDWX5FgND4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=fCsxCOqPQbS0JgHfLSYk2uvPXrZPY7OaAwxt2Rbn3zR+YnVfHVg27t48plJlgbUsUT689OOI30LAKjaWthBS8hB9l5Bi9pSqqszz0F9dgwkw4l/DQtP/tsR6v2DZasQFtAyT9BQnzY2LeThuOrA7bTxO+m0S1sLxtVVkxmWXK/5CuX3G5rtXLVJC3IVx5+0hFUNFipQwru0ZjKH5r5fcBGP3RDyPz/U1BUS+FCsaEEx00kEhiVHxQo9W5Lt+9VQEWCCkSgJeRJWgd6LBsU5r+TmU+JW7yBzm0WMJLgxfGUC9sfOT3OAralFX29dgN1havuJuiXrDwugj62hOfhXbAw== X-YMail-OSG: QgOQYcAVM1lJKPnFcls6VwdLkU15blZ1NV3ZFaa1T79ksQnTlbSwtFFpAOzO8ay gx3rfpUx1c__cUcR0S.3OestsGtvSBR.7_87roqsO60DllDrIZw0AxKK3D.VtZwpnASQV4SCtDhB Os8vGczfEaalOOBKvTuMCeLJHtXGac_vedqf3JLtHBGVGKNQ9_iO5Sh_YbKHIRKGBYUe.Vuxho7U MRIjjggRVat7J_o.4CsogDC6JUJn9F.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z0b35wA0X5lD5l1xV0E- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:54:24 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp418.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0b8226328c4965373e1d598ce42fc97b; Sun, 02 Jun 2019 16:54:21 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 52/58] LSM: Use lsm_context in security_inode_setsecctx Date: Sun, 2 Jun 2019 09:50:55 -0700 Message-Id: <20190602165101.25079-53-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Casey Schaufler Convert security_inode_setsecctx to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- fs/nfsd/nfs4proc.c | 8 ++++++-- fs/nfsd/vfs.c | 7 ++++++- include/linux/security.h | 5 +++-- security/security.c | 8 ++------ 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 0cfd257ffdaf..5b4ea2a317ed 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -54,12 +54,16 @@ static inline void nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) { + struct lsm_context lc; struct inode *inode = d_inode(resfh->fh_dentry); int status; inode_lock(inode); - status = security_inode_setsecctx(resfh->fh_dentry, - label->data, label->len); + + lsm_context_init(&lc); + lc.context = label->data; + lc.len = label->len; + status = security_inode_setsecctx(resfh->fh_dentry, &lc); inode_unlock(inode); if (status) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 7dc98e14655d..2d6dd4bb7247 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -531,6 +531,7 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct svc_fh *fhp, __be32 error; int host_error; struct dentry *dentry; + struct lsm_context lc; error = fh_verify(rqstp, fhp, 0 /* S_IFREG */, NFSD_MAY_SATTR); if (error) @@ -539,7 +540,11 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct svc_fh *fhp, dentry = fhp->fh_dentry; inode_lock(d_inode(dentry)); - host_error = security_inode_setsecctx(dentry, label->data, label->len); + + lsm_context_init(&lc); + lc.context = label->data; + lc.len = label->len; + host_error = security_inode_setsecctx(dentry, &lc); inode_unlock(d_inode(dentry)); return nfserrno(host_error); } diff --git a/include/linux/security.h b/include/linux/security.h index 94c714310ab7..0be6eadd0110 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -439,7 +439,7 @@ void security_release_secctx(struct lsm_context *cp); void security_inode_invalidate_secctx(struct inode *inode); int security_inode_notifysecctx(struct inode *inode, struct lsm_context *cp); -int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen); +int security_inode_setsecctx(struct dentry *dentry, struct lsm_context *cp); int security_inode_getsecctx(struct inode *inode, struct lsm_context *cp); #else /* CONFIG_SECURITY */ @@ -1237,7 +1237,8 @@ static inline int security_inode_notifysecctx(struct inode *inode, { return -EOPNOTSUPP; } -static inline int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) +static inline int security_inode_setsecctx(struct dentry *dentry, + struct lsm_context *cp) { return -EOPNOTSUPP; } diff --git a/security/security.c b/security/security.c index 9d09c774a1e9..363647cf1ae8 100644 --- a/security/security.c +++ b/security/security.c @@ -2006,13 +2006,9 @@ int security_inode_notifysecctx(struct inode *inode, struct lsm_context *cp) } EXPORT_SYMBOL(security_inode_notifysecctx); -int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) +int security_inode_setsecctx(struct dentry *dentry, struct lsm_context *cp) { - struct lsm_context lc; - - lc.context = ctx; - lc.len = ctxlen; - return call_int_hook(inode_setsecctx, 0, dentry, &lc); + return call_int_hook(inode_setsecctx, 0, dentry, cp); } EXPORT_SYMBOL(security_inode_setsecctx); From patchwork Sun Jun 2 16:50:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10972007 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2B44A92A for ; Sun, 2 Jun 2019 16:54:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1AD8C286E4 for ; Sun, 2 Jun 2019 16:54:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F4552873A; Sun, 2 Jun 2019 16:54:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3FF91FF40 for ; Sun, 2 Jun 2019 16:54:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727109AbfFBQy1 (ORCPT ); Sun, 2 Jun 2019 12:54:27 -0400 Received: from sonic303-27.consmr.mail.ne1.yahoo.com ([66.163.188.153]:45356 "EHLO sonic303-27.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727105AbfFBQy1 (ORCPT ); Sun, 2 Jun 2019 12:54:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494466; bh=s293PbMAjW22h/8ubCAR0YEDBHbqaLOuUY2hFLr6/0s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=DtJQnXUM9fnLeyeQMMl0aIZMAggikq7FHFPU3YhSwj/NY+x8WVSuSX/8A/dNCNUqsGuByaj0doiL+QrT9hN88G1KtnWmYIk51Fv71bqKlfGU+stTj9IdI1y7ScDmVulna5gUPGCUiO3N4ofO24WwesK+BupoS5pkvKe91Y+xwem6HKZ8CEbfUXzvPeqBNDQAlMhXtAh2V+92aRNHxjUc8nN9kxEFG9cOZ+/Pp5fCPTA8LQbXwg07CmosNzyxTtoAKwM9pnKnVp1A78eLh+GHlVCTQOyKuAZ+4tJlxZ94dlxw6AMJIkiNgFdNlzha6KDBcq6doIF6RwIYtjd5GOyUnw== X-YMail-OSG: XfcXFqYVM1nKRc6FqRagebTuxsckWAV2i8gohIXBEVx1flzRqRhRrgozBGHQ0NN wf2nBQxcl_DIQML.5wW6O14W8mOdKJ4bAO24bqwr9FuiIIoKga5mzo3yoE6UmYIqGpa00h84e6Y8 VskKuVy8HqhGngKKhi_h93gq0cexgidzzyqw_5r_BtyAADMK0lADzz7Ixz0WISVwPbN7XI7wNDZP ffKdVpAAGqQE4KsLjUN5tn3eIoDsEmbu1XajlTenei1TUj73_eRYC0oHNSyZ2if0F.9esYW8Z_GA Ydh6Hgl3styPUhN6uZG_hYhY3msLz4tU1Jo42TLMw8nAGjKIdfAVBwc5qn0ve56D6P9.HhozmY1F aqKvn5ko0fpl18KSta2plYWkqTJK6oIXXWfDwqn12b.7FkKjZsx9Uv0c5C5yivF57QW6VYrAOSFy psm1q13rBKr5DWarpa2zYBWdrkMun1VjtAcEZp.8o2hXhSpyxlw5Dm7gUaLZnaqhR3dJds7inwdj lgaBvkqw8dNX.EzXuD7i88W9xk3SDXtDIzuk9vPEKtcpz5.gukUpZc3y4Kc_L31ofoVUeu00LXOu MBvsMxthNFV1XosxBTTg14VTvCpueu.cU5shyMj3sOO.4PnKSQqEK4R7XOXD2WoDUFNVXUuFoH8H FGnk7SgI0WAFyqgAb7wuDtol3Wqq12qogzRsltq7jhtjv90yu1skyQLDB5fb7jU7QRb.tTlGc4Ix XCzrhZPZ37XlfMte5Qc2x.o2mY3ODD7dfM_KP8KkMlNAnyX87lBE0QzRxDu_BUU_tBdUeRFClXWr BEm5okgdyZVU7Cn1LLMQVeMeb2lmYzEPhkyz3YOwRr4S2TkhwwFlnQFAXm3du0Pl9NKBZeeoSzNi elH0Wg.wXDMSFpuTczgZAoOcgjrZPhQewjRVBaPR55DMaj3d4tnaTvXfl7ltrfg_8tshcO3XI_8w ypzCmemJOKmiDRXWOOYoTomcG8Fq7ZnEpJC1rP9DweY4yIrnZF6nT7N0xbTj6qQOdDBsk7KsoTg0 zDUtqBr3RdwOrLaBV7ZCnkLV958ljlYMfwUXczFiuPkY9LfqyoL27Q10XxqhBK8eVslHz1Nu_Ew5 uquYJ7ki0FG1e50_rfKvGmnCoSLIzyqjT3wylJRIlacWl18ncN6iGZO08dAKlnPGRfC8c_9IbOQS XQYhR_qtVRErCLOVYASY5Wd99zuyJ2FQqbStgwemmL5XoMXzeQ2If1HaVwPf.JL_mAYrDDssdr33 FB8TqYzUolSNVuI.mk6W92Xgc_5A3G7.sf22Hdhaked8d4Idhe5FJ Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:54:26 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp418.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0b8226328c4965373e1d598ce42fc97b; Sun, 02 Jun 2019 16:54:22 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 53/58] kernfs: remove lsm_context scaffolding Date: Sun, 2 Jun 2019 09:50:56 -0700 Message-Id: <20190602165101.25079-54-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Change the parameters to kernfs_node_setsecdata from a data/length pair to a lsm_context struct as both the function it calls and the function that calls it want that. Signed-off-by: Casey Schaufler --- fs/kernfs/inode.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c index 4c7da446d210..d6e25cd7bf21 100644 --- a/fs/kernfs/inode.c +++ b/fs/kernfs/inode.c @@ -135,20 +135,15 @@ int kernfs_iop_setattr(struct dentry *dentry, struct iattr *iattr) return error; } -static int kernfs_node_setsecdata(struct kernfs_iattrs *attrs, void **secdata, - u32 *secdata_len) +static int kernfs_node_setsecdata(struct kernfs_iattrs *attrs, + struct lsm_context *cp) { - void *old_secdata; - size_t old_secdata_len; + struct lsm_context old_context; - old_secdata = attrs->ia_context.context; - old_secdata_len = attrs->ia_context.len; + old_context = attrs->ia_context; + attrs->ia_context = *cp; + *cp = old_context; - attrs->ia_context.context = *secdata; - attrs->ia_context.len = *secdata_len; - - *secdata = old_secdata; - *secdata_len = old_secdata_len; return 0; } @@ -363,7 +358,7 @@ static int kernfs_security_xattr_set(const struct xattr_handler *handler, return error; mutex_lock(&kernfs_mutex); - error = kernfs_node_setsecdata(attrs, (void **)&lc.context, &lc.len); + error = kernfs_node_setsecdata(attrs, &lc); mutex_unlock(&kernfs_mutex); if (lc.context) From patchwork Sun Jun 2 16:50:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10972005 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ED85C6C5 for ; Sun, 2 Jun 2019 16:54:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE30C286E4 for ; Sun, 2 Jun 2019 16:54:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D2B822873A; Sun, 2 Jun 2019 16:54:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F5A0289FA for ; Sun, 2 Jun 2019 16:54:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727091AbfFBQy1 (ORCPT ); Sun, 2 Jun 2019 12:54:27 -0400 Received: from sonic310-30.consmr.mail.ne1.yahoo.com ([66.163.186.211]:43423 "EHLO sonic310-30.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727101AbfFBQy1 (ORCPT ); Sun, 2 Jun 2019 12:54:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494465; bh=zgFSe6tWYXYAPxCMjdvNLFgshVy6juLl1RtnFRkSwpk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=h8HS9bMzJLqgeKZaahYTm8GSvYLPDMMwVK/MAufm92g4IimYCTDmnjy+5E3dtNz5S6C7ibi3yWNWqP9Ay/QzXKb7xJH5nkCW63V+siKrXjgsCLOP+doG8U/Bl4AWnZN9SsgwFhyR25KADSxC0W0y2cQqnGqq1CskKNWq27C8BD0gH/EV2SBE5yIMP14c5kSWlaT7zG4lId/DxhNsxn3YM6Nru3PSjnxHnZdSd6qflVHdvqqQPmq0MaGDtNJ0YU5ejMNbMSOZ/XRGwYpJyCPqMpvWi4EA4BiZXv3Yu06nw7suOTmIM46NF8RIcBicd9izOmNkO4O35S76hIrHiZn+Mg== X-YMail-OSG: Mb1i93AVM1nu2kjuuf5vBSb3CasYpakc5K.q2fNlVL1kgzheVoZUcEnkhupFx_h y0JOb.7urSFKUhbo8e0jRuKefB7zob1SmSwsR6BRX5tzRwCxE7NH_i3IBKekWQqwvxEFeD_ql02p xkDO6CnHFumoqtbJDNiGb5c59aFFw6ipxchh4FNe.Y3syOYxQuMpcus5jZkyG0pd50n00MhdOUce TLF7OMj9GDlBYCKSaXH6r.KP6QrQn6PMZXV5gSN.HbdA10vDRWc2FiQW9ZJB6KGbocrnEfeGNmZA Jap6gaBKnd7CGBS7v1FTKqwgZ4C9DtsDw8N14YmJd9N1FfRyc9p9CLWJZJ0SKLUWL83A1ksN75tU INl.ZfwcPExUhnTwIk_kH1muRk5_q1QtfCnl6g0nwdGi.Bq2NDGn9yOmFOa7T.UOZiHN6M9rRFGi pRCrjargD7T3HsP9tR8AN9ryL_QxdYk4UqpjEGkjpMKqtI0LPaOjYV1dpfdUt3lk6NHJuywW0ywB JLufdWmd.Gcpuchv95a11HR09J4LVJDFUeaWSPqxf1vXdrcHd5U7qmRzhCriX3lYtiOeK6PrdI8C KCP9GubYZ3n1q5IkMOSv5gHHogsHj7a3.IkLB4O6NjFEwRTEAcJk7T7agmcNUfsr6EW_Y3Ii.Xrd a3oRajeolg2J3flJfNuHODGZLH072hL.gzHbRrSgu_8RnQ6oPAacwaHFLdOmYIeK92Lh7z5qSAs_ J958Z2gKSI43qqnUXHv04sdLrZTxlWO8.mBZYszzttu_FEx76c_sjhxWXY4cTESA_AAcA2xcaw5u _tN9qmAnE7syWEWl6U2P6TNvQEY9qadcHaY_8F1GBW_AMhYU_YjuUJS_x_MtthgR_qql_9Ka.PwW t_50j8.GCt00FYewEntWxM5_eON7QBe.L_yyM2ECUztnv_rk1reny2gr9nQGkGlDV1gPJzINbsJU aV_zw71C12ND_qZzl_B3.UmF0hgBvibJUmYPJNz7KOI2uWzR9HHCKPWsVfJ1NHeeGcPxTXxAFmbj z12PRZLxkFcDSyLlJMho3XQLG_FjUuB9D8lX5LfIk8ebvz_2cwI80GgRD5gKNr7fnIIsp4sxkxJQ uI6DRUXCudIZsVG00G3hcN9XDYDM71Uqe_PJwWx5LPUE3piF_7DUwOgplMuOwqvHbOwgOJ.x8WvY YWIMGYa8.KDPE79bQNr79WY33YsuCNBwgiSUR3kz4bl3SxmYYDy5X09O8xyBKA1L.pLllhdESa78 qfaxdc.H..HIm0vdut92GmmF2_0LNoQ5IzOPK0K2eol2bAY80E57M Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:54:25 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp418.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0b8226328c4965373e1d598ce42fc97b; Sun, 02 Jun 2019 16:54:23 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 54/58] LSM: Remove unused macro Date: Sun, 2 Jun 2019 09:50:57 -0700 Message-Id: <20190602165101.25079-55-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The call_one_void_hook macro is unused since the change to how releasing a secctx was made. Remove it. Signed-off-by: Casey Schaufler --- security/security.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/security/security.c b/security/security.c index 363647cf1ae8..ae43735575d6 100644 --- a/security/security.c +++ b/security/security.c @@ -698,16 +698,6 @@ int lsm_superblock_alloc(struct super_block *sb) P->hook.FUNC(__VA_ARGS__); \ } while (0) -#define call_one_void_hook(FUNC, ...) \ - do { \ - struct security_hook_list *P; \ - \ - hlist_for_each_entry(P, &security_hook_heads.FUNC, list) { \ - P->hook.FUNC(__VA_ARGS__); \ - break; \ - } \ - } while (0) - #define call_int_hook(FUNC, IRC, ...) ({ \ int RC = IRC; \ do { \ From patchwork Sun Jun 2 16:50:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10972011 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1A11C92A for ; Sun, 2 Jun 2019 16:54:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B95E1FF40 for ; Sun, 2 Jun 2019 16:54:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F377D28A00; Sun, 2 Jun 2019 16:54:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A00A41FF40 for ; Sun, 2 Jun 2019 16:54:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727097AbfFBQy2 (ORCPT ); Sun, 2 Jun 2019 12:54:28 -0400 Received: from sonic303-27.consmr.mail.ne1.yahoo.com ([66.163.188.153]:42514 "EHLO sonic303-27.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727107AbfFBQy1 (ORCPT ); Sun, 2 Jun 2019 12:54:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494466; bh=cP6y4hrQLvKO7rVafzTnUGAgt8Nk7i9nw+ffKlms2R0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=Uo/GwIndgAFwKamLNXPpQ93CcF4yRqfOXnxFRiMxhOoskKPM7IXL9lVAVOKLyWoLw1ap9ELvqWkqbcWmKJOa0KAj3KuLw5ElnxoreguVzxy5nZXYL7ncnnw0DNT1Xj8JyhVzwSIOe+Qjwp6Tk+OTGBI3/evNDNF9zEeB5gDx7f9JpFjBTsoCHX1vLO1YdgkA/gpmzkURC1RLbm9Oltkvb6RPx2ym+Jbf2iUvN69GhCYPWm+tE0ixdxBXwanoMFYes+yzw9hV1i0UW9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JyEISSfF2aAEPnelB24VLYHseLVwONzTfvGArc0j9QbhK4L25NmUDzmaZvIc6lt1X6wsbVH U5Vs0FaE9cqzdMEP0EVcCqkdpMA467j69pPTV7mMjBvtud8YoTUeBe_S57BbosSF7NJxXA._iy_v NQvDD0bj2Z8B2mJZV3VoCQRzWOYZYmJknDGUi9Laxns2sK0M.4.7eCcLwjQzYmvNFdYRVLHMkb3W IYfVtug7F7ao8ykrzhe1FA0SkzeVxLUg2GNDBcDUUBEONdzs0.UeoRSIEZMJz4eTfw12fa6oGuJT kIpxZKqI73j9h2uPzGg9IpJTIl0jc7uTOh6w2HGYITXUk8AQVfNcb50j1mlc- Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.ne1.yahoo.com with HTTP; Sun, 2 Jun 2019 16:54:26 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp418.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0b8226328c4965373e1d598ce42fc97b; Sun, 02 Jun 2019 16:54:24 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 55/58] LSM: Special handling for secctx lsm hooks Date: Sun, 2 Jun 2019 09:50:58 -0700 Message-Id: <20190602165101.25079-56-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Create a special set of LSM hooks for the translation to human readable security data. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 10 ++++++++++ security/security.c | 32 ++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 088985d10a69..d90d953c8ef4 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -2032,6 +2032,16 @@ struct security_hook_list { char *lsm; } __randomize_layout; +/* + * The set of hooks that may be selected for a specific module. + */ +struct lsm_one_hooks { + char *lsm; + union security_list_options secid_to_secctx; + union security_list_options secctx_to_secid; + union security_list_options socket_getpeersec_stream; +}; + /* * Security blob size or offset data. */ diff --git a/security/security.c b/security/security.c index ae43735575d6..b05265ec24f0 100644 --- a/security/security.c +++ b/security/security.c @@ -420,6 +420,9 @@ static int lsm_append(char *new, char **result) return 0; } +/* Base list of once-only hooks */ +struct lsm_one_hooks lsm_base_one; + /** * security_add_hooks - Add a modules hooks to the hook lists. * @hooks: the hooks to add @@ -436,6 +439,25 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count, for (i = 0; i < count; i++) { hooks[i].lsm = lsm; hlist_add_tail_rcu(&hooks[i].list, hooks[i].head); + + /* + * Check for the special hooks that are restricted to + * a single module to create the base set. Use the hooks + * from that module for the set, which may not be complete. + */ + if (lsm_base_one.lsm && strcmp(lsm_base_one.lsm, hooks[i].lsm)) + continue; + if (hooks[i].head == &security_hook_heads.secid_to_secctx) + lsm_base_one.secid_to_secctx = hooks[i].hook; + else if (hooks[i].head == &security_hook_heads.secctx_to_secid) + lsm_base_one.secctx_to_secid = hooks[i].hook; + else if (hooks[i].head == + &security_hook_heads.socket_getpeersec_stream) + lsm_base_one.socket_getpeersec_stream = hooks[i].hook; + else + continue; + if (lsm_base_one.lsm == NULL) + lsm_base_one.lsm = kstrdup(hooks[i].lsm, GFP_KERNEL); } if (lsm_append(lsm, &lsm_names) < 0) panic("%s - Cannot get early memory.\n", __func__); @@ -714,14 +736,8 @@ int lsm_superblock_alloc(struct super_block *sb) #define call_one_int_hook(FUNC, IRC, ...) ({ \ int RC = IRC; \ - do { \ - struct security_hook_list *P; \ - \ - hlist_for_each_entry(P, &security_hook_heads.FUNC, list) { \ - RC = P->hook.FUNC(__VA_ARGS__); \ - break; \ - } \ - } while (0); \ + if (lsm_base_one.FUNC.FUNC) \ + RC = lsm_base_one.FUNC.FUNC(__VA_ARGS__); \ RC; \ }) From patchwork Sun Jun 2 16:50:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10972017 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CED756C5 for ; Sun, 2 Jun 2019 16:54:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE05C2873A for ; Sun, 2 Jun 2019 16:54:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B133B289FA; Sun, 2 Jun 2019 16:54:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 628DD1FF40 for ; Sun, 2 Jun 2019 16:54:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727121AbfFBQyp (ORCPT ); Sun, 2 Jun 2019 12:54:45 -0400 Received: from sonic302-8.consmr.mail.bf2.yahoo.com ([74.6.135.47]:39473 "EHLO sonic302-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727118AbfFBQyo (ORCPT ); Sun, 2 Jun 2019 12:54:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494483; bh=nBnBMo6nnWk5nN0YxdI8fLfbN2dvJh7eXD4R2+pTog8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=Yqh2EJdBY95QgBtZ8J245JijgiSYlswEnvRWw+Y83cshnhUHFniAyaD6DJ1WihNERDxyOqLt0lW0GlNMAiMXOsB61+rMt0lmwLFny89G5G0a5orXc792IPbOgrXUWBfcGfQyREvyspl4PSIr3cM6HOouarJuGgnugh4xqeKqNBLqzJyeNB1ZENOE1R+noeS1R4Ub7KYP46eo2xsW4QsX2sAEsV3dy4U5StrFW5ud31yXdr7zt0Fkk1qC+2x8zOWDMZ9VUhkhfUb4grBOoBO+3sFPopZe/u2mRzCuEfpwcli6gllCc0C0lAniIn1L73CVxmYB4RpqXCUJaGMXRFA6PA== X-YMail-OSG: 7MoqQh4VM1lySqFqzTdsraUhdqEw8uAZ.g3..UeaWp37EOMmqZ6m0C.Kl0E9Lzo Iio6Uj.rN6iJMxo2EV.7nesdJhxCX4aA.c6_hft1QAufeYjrYOik_LCkoGg9mRPkdJxFs8rAkqkx .4THs1tDG4tXqgHHhUUPrz1QWYVTTpUua6wp1Whny6OtZe5q4SzNYis3ts5Qu8IhtDYJ68tWdynT vnSTsRA8Tq1hrLsjA8pZaBME1e4Q9JdmGfX.TUicTsKYF9HRgZSKeqeKs.hGCE2WaYKSHJ3lJ2hT TSDJDq2P2PTKhn9maWXBrUtIrnOcUN1o_dsZ53l_jzFGGuE3K3.z4ErkbAuoCa.b0tjphN1snqKM RKL8.X89J0JObJJoiSVIgx3IKMQQv.vX5eHp8qvwjGlL2UBSQ3MG.7bRcEyn16ujbw47cQRR3a6k dhIu2XYJ8T3r7Cjaeuje1p_CnU_fk5bGFSHcsAHNxJjmQBe1Kbcdx6hWiZXzAmd0kjRhhF_7hpfw LjnkfuGpmWtLXNVMujGQCvxBucHILZYS7A4ef4kxALMyFA0xmrET2.KsLGiw5G78iuLpjWkXG1xc n2qNqdnueGyADQd8ezXw587hKWvRd2IKlU7R7eYg12pe_6t6ESNg4TigxsW_kzFpNFS6DV9kaHoz azJy9buK3bh.v9k8.5D9mVEu8IX2QutKZXiWJKlHvMGNTIenOKwzeR38eY1YP84yBbj5EwYYtjGc g_Juv4atn9tqE7ElaoHvfNIfVFw4b_8oBXxvq5jqX09ctx9hAWlc.MApitSFBpsgJURBCUpP3N5S xbGJiIGwPhHiKbIi9meAGUj2UD7DYa2etcxHz_x9ioDDosikztQSN8wF10vLyNfpcTopQWo3izHi GsOynrj0ubO1zyct3R5rj5Bmpsac_.0XTh8vBVOtk6uJMhjXzajO7B9mWmn0_2PL0H4oBke0h_Tk p5ZindJPm1XkCPr2WYq1wa3kx9Jv5VZeOIQ2rJmjhfO_IDe0fVbTUseDh7qVKB65LybaoxKqgakB Oy_V0z3GiCRWn_YY6Y1LTuuPkcHhRqtrG6BayIZYWr7g.XA01lsbJ5ifhLj8QkjKqEA2TGBrKQlS 7Uuur6PWGrC2XRX7.F0wfq_6TszfJaY052X1UmffsDfcInl5Yn4Yr4tqUNUn21T5.slQx75lgMSR .0wSlpTMLwO7WkdWh_Zj7J_0BABpYKEzkmbNC1eyF_2bWu1XkSbCXL_Ymu4y_ReWdKgC2Hhekf7L B2pg_oQxugfkeGW1Lx8O5cJtb_Es7yue8pATj_QXwKfHXiQwPpU8zy06v Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:54:43 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp411.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 4f202846722f9a871dab498da8fe7ef4; Sun, 02 Jun 2019 16:54:38 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 56/58] SELinux: Use blob offset in current_sid Date: Sun, 2 Jun 2019 09:50:59 -0700 Message-Id: <20190602165101.25079-57-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace the use of current_security() with a call to current_cred() so that the blob offset can be correctly applied. Signed-off-by: Casey Schaufler --- security/selinux/include/objsec.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/security/selinux/include/objsec.h b/security/selinux/include/objsec.h index 59a3b1cd5ba9..c9a88b7a96a7 100644 --- a/security/selinux/include/objsec.h +++ b/security/selinux/include/objsec.h @@ -31,6 +31,8 @@ #include "flask.h" #include "avc.h" +extern struct lsm_blob_sizes selinux_blob_sizes; + struct task_security_struct { u32 osid; /* SID prior to last execve */ u32 sid; /* current SID */ @@ -45,7 +47,9 @@ struct task_security_struct { */ static inline u32 current_sid(void) { - const struct task_security_struct *tsec = current_security(); + const struct task_security_struct *tsec; + + tsec = current_cred()->security + selinux_blob_sizes.lbs_cred; return tsec->sid; } @@ -174,7 +178,6 @@ struct bpf_security_struct { u32 sid; /*SID of bpf obj creater*/ }; -extern struct lsm_blob_sizes selinux_blob_sizes; static inline struct task_security_struct *selinux_cred(const struct cred *cred) { return cred->security + selinux_blob_sizes.lbs_cred; From patchwork Sun Jun 2 16:51:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10972023 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C53214DB for ; Sun, 2 Jun 2019 16:54:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F17D81FF40 for ; Sun, 2 Jun 2019 16:54:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E430A286E4; Sun, 2 Jun 2019 16:54:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE9202873A for ; Sun, 2 Jun 2019 16:54:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727107AbfFBQyp (ORCPT ); Sun, 2 Jun 2019 12:54:45 -0400 Received: from sonic302-8.consmr.mail.bf2.yahoo.com ([74.6.135.47]:36694 "EHLO sonic302-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727113AbfFBQyp (ORCPT ); Sun, 2 Jun 2019 12:54:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494483; bh=5GP2CrxJNDp2BFUDQ+U49VHnhWLXKi0Sb6zMHU3zI00=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=oSUjUGUa9qc/285CNQC4qy6J7sGmdTyhX6ktJZjKn9eP5O4RJKex2acqkrYPKtJvAtIj3sJQaAJNoJC3map6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kkHv8_wObUJPaNvisGHj7.fa2F.FUh r6RHbXI8AWBygQ.HJnNTS58CAiw5jW4ITSGQnAcG0UQpB7jYKxuah1XNSJ9eATUvvCCztvnJEh78 .vC_vPeUgjr5V7Q0HPvofvnDLUN84xkkhpvGKu3D_LZovMZWqfGAvX6Y4v6o.YhIB1b1dY.opIlZ bBDJ.Q74K4fOs1CrDRHAS7a1oD3fNLb6PBAXggs80kETZHB.kmHNMgx4Dlp6t.5HSuBeRzUyiQkL bPaRv5c_Bb6UyRywcSCVRLIjkCVowNU2daY8jpy.8hsfauQdf_k2qcMLXUe1NK3SlcJ.A0o7Dlqt nsalNdmg4s9_MCSYNjyKND5wr_6Ppi9VCIYKuwP2gBJ2qqmmpyKU6t8N1NKBk.2ipQA0ubqU7ZYG Lz2pUKrsT2BbZHMX5dYEDrxS7ERbUV2AmYFI2uR8Y7Sx2BPTEBhNFyLbsepTLVJ3fHM9FWBAHXf. 3q7TBMpNmDVa84Qn3drcO_Wi1feMa3nsj2.z.PsYuk2ijEKO.NrL9AY.b2Q-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:54:43 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp411.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 4f202846722f9a871dab498da8fe7ef4; Sun, 02 Jun 2019 16:54:40 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 57/58] LSM: Specify which LSM to display Date: Sun, 2 Jun 2019 09:51:00 -0700 Message-Id: <20190602165101.25079-58-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Create a new entry "display" in /proc/.../attr for controlling which LSM security information is displayed for a process. The name of an active LSM that supplies hooks for human readable data may be written to "display" to set the value. The name of the LSM currently in use can be read from "display". Signed-off-by: Casey Schaufler --- fs/proc/base.c | 1 + security/security.c | 110 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 109 insertions(+), 2 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index ddef482f1334..7bf70e041315 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2618,6 +2618,7 @@ static const struct pid_entry attr_dir_stuff[] = { ATTR(NULL, "fscreate", 0666), ATTR(NULL, "keycreate", 0666), ATTR(NULL, "sockcreate", 0666), + ATTR(NULL, "display", 0666), #ifdef CONFIG_SECURITY_SMACK DIR("smack", 0555, proc_smack_attr_dir_inode_ops, proc_smack_attr_dir_ops), diff --git a/security/security.c b/security/security.c index b05265ec24f0..4af99077572d 100644 --- a/security/security.c +++ b/security/security.c @@ -46,7 +46,9 @@ static struct kmem_cache *lsm_file_cache; static struct kmem_cache *lsm_inode_cache; char *lsm_names; -static struct lsm_blob_sizes blob_sizes __lsm_ro_after_init; +static struct lsm_blob_sizes blob_sizes __lsm_ro_after_init = { + .lbs_task = sizeof(struct lsm_one_hooks), +}; /* Boot-time LSM user choice */ static __initdata const char *chosen_lsm_order; @@ -577,6 +579,7 @@ static int lsm_task_alloc(struct task_struct *task) task->security = kzalloc(blob_sizes.lbs_task, GFP_KERNEL); if (task->security == NULL) return -ENOMEM; + return 0; } @@ -736,7 +739,10 @@ int lsm_superblock_alloc(struct super_block *sb) #define call_one_int_hook(FUNC, IRC, ...) ({ \ int RC = IRC; \ - if (lsm_base_one.FUNC.FUNC) \ + struct lsm_one_hooks *LOH = current->security; \ + if (LOH->FUNC.FUNC) \ + RC = LOH->FUNC.FUNC(__VA_ARGS__); \ + else if (LOH->lsm == NULL && lsm_base_one.FUNC.FUNC) \ RC = lsm_base_one.FUNC.FUNC(__VA_ARGS__); \ RC; \ }) @@ -1569,13 +1575,22 @@ int security_file_open(struct file *file) int security_task_alloc(struct task_struct *task, unsigned long clone_flags) { + struct lsm_one_hooks *odisplay = current->security; + struct lsm_one_hooks *ndisplay; int rc = lsm_task_alloc(task); if (rc) return rc; + rc = call_int_hook(task_alloc, 0, task, clone_flags); if (unlikely(rc)) security_task_free(task); + else if (odisplay) { + ndisplay = task->security; + if (ndisplay) + *ndisplay = *odisplay; + } + return rc; } @@ -1945,10 +1960,28 @@ int security_getprocattr(struct task_struct *p, const char *lsm, char *name, char **value) { struct security_hook_list *hp; + struct lsm_one_hooks *loh = current->security; + char *s; + + if (!strcmp(name, "display")) { + if (loh->lsm) + s = loh->lsm; + else if (lsm_base_one.lsm) + s = lsm_base_one.lsm; + else + return -EINVAL; + + *value = kstrdup(s, GFP_KERNEL); + if (*value) + return strlen(s); + return -ENOMEM; + } hlist_for_each_entry(hp, &security_hook_heads.getprocattr, list) { if (lsm != NULL && strcmp(lsm, hp->lsm)) continue; + if (lsm == NULL && loh->lsm && strcmp(loh->lsm, hp->lsm)) + continue; return hp->hook.getprocattr(p, name, value); } return -EINVAL; @@ -1958,10 +1991,83 @@ int security_setprocattr(const char *lsm, const char *name, void *value, size_t size) { struct security_hook_list *hp; + struct lsm_one_hooks *loh = current->security; + bool found = false; + char *s; + + /* + * End the passed name at a newline. + */ + s = strnchr(value, size, '\n'); + if (s) + *s = '\0'; + + if (!strcmp(name, "display")) { + union security_list_options secid_to_secctx; + union security_list_options secctx_to_secid; + union security_list_options socket_getpeersec_stream; + + if (size == 0 || size >= 100) + return -EINVAL; + + secid_to_secctx.secid_to_secctx = NULL; + hlist_for_each_entry(hp, &security_hook_heads.secid_to_secctx, + list) { + if (size >= strlen(hp->lsm) && + !strncmp(value, hp->lsm, size)) { + secid_to_secctx = hp->hook; + found = true; + break; + } + } + secctx_to_secid.secctx_to_secid = NULL; + hlist_for_each_entry(hp, &security_hook_heads.secctx_to_secid, + list) { + if (size >= strlen(hp->lsm) && + !strncmp(value, hp->lsm, size)) { + secctx_to_secid = hp->hook; + found = true; + break; + } + } + socket_getpeersec_stream.socket_getpeersec_stream = NULL; + hlist_for_each_entry(hp, + &security_hook_heads.socket_getpeersec_stream, + list) { + if (size >= strlen(hp->lsm) && + !strncmp(value, hp->lsm, size)) { + socket_getpeersec_stream = hp->hook; + found = true; + break; + } + } + if (!found) + return -EINVAL; + + /* + * The named lsm is active and supplies one or more + * of the relevant hooks. Switch to it. + */ + s = kmemdup(value, size + 1, GFP_KERNEL); + if (s == NULL) + return -ENOMEM; + s[size] = '\0'; + + if (loh->lsm) + kfree(loh->lsm); + loh->lsm = s; + loh->secid_to_secctx = secid_to_secctx; + loh->secctx_to_secid = secctx_to_secid; + loh->socket_getpeersec_stream = socket_getpeersec_stream; + + return size; + } hlist_for_each_entry(hp, &security_hook_heads.setprocattr, list) { if (lsm != NULL && strcmp(lsm, hp->lsm)) continue; + if (lsm == NULL && loh->lsm && strcmp(loh->lsm, hp->lsm)) + continue; return hp->hook.setprocattr(name, value, size); } return -EINVAL; From patchwork Sun Jun 2 16:51:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10972025 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BA7856C5 for ; Sun, 2 Jun 2019 16:54:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A93491FF40 for ; Sun, 2 Jun 2019 16:54:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D9FE289FA; Sun, 2 Jun 2019 16:54:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55FA11FF40 for ; Sun, 2 Jun 2019 16:54:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727122AbfFBQyt (ORCPT ); Sun, 2 Jun 2019 12:54:49 -0400 Received: from sonic303-8.consmr.mail.bf2.yahoo.com ([74.6.131.47]:41144 "EHLO sonic303-8.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727118AbfFBQys (ORCPT ); Sun, 2 Jun 2019 12:54:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559494487; bh=NriQJ/Ly+k4Qx0CdGV3MY+BheCtZdoxEEIBOuIRJP8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=n18yMz2c2KD/+Br+6EJfZY4fvQvzHNnzr+zT/HwEknds9CjcI0CpnbUFB83AvWlJWdzFDS/1Id5tvLLTQ3KiBcBTYST0MnXXDA096Pwaqz5IrVB0iMrSSkH28rWZBeO5i2tZ8fR5l7E6M03Xv3QakNMn+A1TiCZ1fuu9yE9bURo8zX5nkF7utwssPwDHvep8Oo/h2U+ZrQuFmJqHjgupdTDWtiFdB2Ex2axoI5SQWFG0NKNtYsyJ4bkK9TYiZ3p38WFB1EoJpksvZ7jFjPxwcby62G1FUPG24tPr/TEd/EKR+Z91k8fvLhkF4VcXDMqnxi2Mx1r16QP0ls9g5CA6rw== X-YMail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rq2tEfmlBOu96PnUGbsjdmDDiN8NTIkXukGYq4AXqhRlBplrqFc0pCWbeisrUtFuKB1KQnn70zh 1o3nboOB7p2SEleEHP5Re3znOHEXwjC50UyG482LUaBi0HBdO_JTDxZMsLZKbDU223uF8rC1wiHV w1J3FYPnNmAj7dG7EWIwz2DEHhUu1bG23SZ6eMxzY2N9Qpqcg.i8CT_gcd5Pvs8dQw1OS9Y1shJg o1BfezTb4hVZB7eDSEjLqJWiRyrUvLcgvRSRQLdNbm0AcSXdDnTF1I3A- Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.bf2.yahoo.com with HTTP; Sun, 2 Jun 2019 16:54:47 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.net) ([73.223.4.185]) by smtp411.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 4f202846722f9a871dab498da8fe7ef4; Sun, 02 Jun 2019 16:54:43 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 58/58] AppArmor: Remove the exclusive flag Date: Sun, 2 Jun 2019 09:51:01 -0700 Message-Id: <20190602165101.25079-59-casey@schaufler-ca.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602165101.25079-1-casey@schaufler-ca.com> References: <20190602165101.25079-1-casey@schaufler-ca.com> MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP With the inclusion of the "display" process attribute mechanism AppArmor no longer needs to be treated as an "exclusive" security module. Remove the flag that indicates it is exclusive. Signed-off-by: Casey Schaufler --- security/apparmor/lsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 771b0ae24a5f..a8b11a7f29fa 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -1705,7 +1705,7 @@ static int __init apparmor_init(void) DEFINE_LSM(apparmor) = { .name = "apparmor", - .flags = LSM_FLAG_LEGACY_MAJOR | LSM_FLAG_EXCLUSIVE, + .flags = LSM_FLAG_LEGACY_MAJOR, .enabled = &apparmor_enabled, .blobs = &apparmor_blob_sizes, .init = apparmor_init,