From patchwork Tue Apr 9 21:38: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: 10892661 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 3557817EF for ; Tue, 9 Apr 2019 21:41:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2658D285C6 for ; Tue, 9 Apr 2019 21:41:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A8D22886B; Tue, 9 Apr 2019 21:41:48 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 08B69285C6 for ; Tue, 9 Apr 2019 21:41:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727082AbfDIVlq (ORCPT ); Tue, 9 Apr 2019 17:41:46 -0400 Received: from sonic304-28.consmr.mail.ne1.yahoo.com ([66.163.191.154]:37130 "EHLO sonic304-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727047AbfDIVln (ORCPT ); Tue, 9 Apr 2019 17:41:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846089; bh=TWuw99DnWmB51yX+yr9YkHlREDb2dZVqgCxQsdxAgdM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=uidGi60OaNFol3GSRcQV7qG+YNAjI6hRmO0ASHkpVFquugpiDcZeXMa/ewUBxuxY2mhO1ey9io9QMxfgdBYs1+O37jvYyaPESFOqyfGw0g5WmOH+MQ/hJPNU+y7oelEmpgrcOjgncnpChNHYG5ubDsei9wQttXxr9PmCfJQqODq6by6kjRGDkYe4PDPjMjlAYlbc1O55gk7nDDatCG8KYRwMnFymkrUz3uBAoDahoyfHO/hU2+8UXiju2vDxhJLvfqnttvnDIBw2yCwInt685FONbTY94sRuZqIZD3nZQzf7HTHSfq/sFD5zZ2djV1gN5m+1U+Z7pm2mAQoXZo9v4Q== X-YMail-OSG: M_2GNgUVM1mAELjcCTzqfHOj1sowVOXJsr0daBh8mPMmQIMArpVrTIFrJCYGJee AkZw1e.TVa6oTxuhqGtPvTvIP2..Qi9Ofhp8BZOGpmmXfldwun8cw6z4gGnCQBggyr0Mc_ENAn4P mMbQS2xwaZ9R1WUhppg8NUBTAJ2Ba1smF00AI1IaiAuGJIElVQMGsqdvjZrkCccHuArg.lboR2jr 5h4iw7ns21efjASm553afJK_cJMNif8RzguykmsMSikBSaX.ahW9c2KVtupdlDgA0sI_Bah9Vmpc vgFzZ3ugg4j0XZ1b2Nx8BsvitAkfAbSmIPRfTCQa._TFkyWd_Uxml8rC5Mdv9HgI6GEUpuKa0hsP T4FRjVtYlt.xR1NDJdlEXg5D__tO38jfMtetI0T1Sxl6g9yya.M0e5pPfYGjxi.Dq.6JLbbG7Ue8 rTHt0Zyv8n.jQvApSAefU_qdcERXP78eWXwkYWZPfxawptwr.0QuHdS2_ic0UPd2lvwm8TcJbVcf YWCR1EYIx5CN3..VXQxt8kRYjUqytYBSjQenspPV4ATTl01DGD5jXtRst9lpe.zzAHT7cji63KOy rbX6zV0pEzRGc65rNAa0SpzYPlpRb3pwbBeQZ5YB2.rIsdW1TwH0E64ky4F_UXK_KLjEY7tDPSvI 8widOaHtcadHZcEZG2YPQy08mzg1N1WJQ002_0DAcwVims2.w5mazJI.fMp823A6yqEztkuavqbB cZ9OwDIObdFWLRhofffF4xBo5y.6m3orwkxElkUNGDIO8nyQiSOJa2pQ2pNq1_FQE5XhatJFdeX1 QwHbPUMQBMXp6jkBZGaJnXz.JCD8aq1ELpbt21UkoR5RZ8FGpT_ZK3bCyRoT_8mxjcKowx1ja3ru Qge72aKCyMv3tijxxCsHAY8os_.zpqebM9stCZ5rpcEusTIs46fhTNuYJoUEQ2FRp5DCJNjzFQnd 7mGVlf_kTUZ1YnYElIzqj4c8V29W2cQhqlFOP7X0eo2ifFCrrH1lrqHDmbIVu_kR9VkFmTZnFG8w LfVnyfMZCPLAd81qAgZI8sU5CJD7tCD5f1RDsbkhWbubwg3lHFVc86iG..8SKgpTff04O9ZrMIt3 OHjAoTAy1uGOA3ZVY2v3URQNuwBnS9gUeGYSBSMa3CHkMu34jM_j2q80- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:27 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp423.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 9c4e55bd3d312d6c1e8f7ed93770d720; Tue, 09 Apr 2019 21:39: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 Subject: [PATCH 01/59] LSM: Infrastructure management of the superblock Date: Tue, 9 Apr 2019 14:38:48 -0700 Message-Id: <20190409213946.1667-2-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 a9b8ff578b6b..cdc5730666d6 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -2055,6 +2055,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 Tue Apr 9 21:38: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: 10892813 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 835141515 for ; Tue, 9 Apr 2019 21:59:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74BAE28721 for ; Tue, 9 Apr 2019 21:59:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6912E287B7; Tue, 9 Apr 2019 21:59:05 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 5572F28721 for ; Tue, 9 Apr 2019 21:59:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726640AbfDIV7B (ORCPT ); Tue, 9 Apr 2019 17:59:01 -0400 Received: from sonic301-14.consmr.mail.ne1.yahoo.com ([66.163.184.247]:45799 "EHLO sonic301-14.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726580AbfDIV7B (ORCPT ); Tue, 9 Apr 2019 17:59:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554847133; bh=uYMzsP8oNFL/qA8PyuIX9+E+dFu5phtarBiekUH0zk4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=Nfy1vZEathkRCOGYKWFckI+yGt2U4AvLqC7N6gtsZFPCrmQeaqYhp9O3Z0aXEYkPWlAIwNy9yt8KhJANoVy3IXC2LcoSe2CyQNIk94EGM/BGgR0eANVqPhs9/v9RqFW9XJTbcJ0ctNxPQdorc4NqTJpJMh3q85Bz+BRjHdscYWe7Nka3ZR9YFhrml7ih7bLvImJ8PY+rjfdGynnWtpEjRapHYkuKNoI4gzaqWy/wZ26NdA1Br+UlJcswR2msLkoUVMpWyeqegZ7l8BiilnrnmxuV7B6jwsXAWsnoALX4Pp41xyOb2fqTj+kiFK+Y8OMVyVEWKd4mkTqqhpeYBron7g== X-YMail-OSG: aY2LYYUVM1kraFWA7mhP7RKRjF64KnIGXExFAj5JxquRhtlDl_yNcuO3Quy69Be oBcIaDXu2GebvPLsJP2pJhjIyREnB7erbcAdJHEbMPH0S.Sj0dBIRRnsZg1gbGHjkUe5qZH2V2cY JrZb_A_7EcfqvcpqkDpiE8QcLLJibWakoiKJQKKrvKjF1vCJfo6.GqWYyZjtnTv8pwlvtOZjXT7b NWWKomCA89TB.wKbKXfYS19weHewdxYG53gyq6NP_BUrM1AvSh85l3hfNIHyCfNftx1dGc6goIAO jM7fGKa7.7tESA14R4KiwhrHEZvu6fTKU8jxQadzySfvinn2yf_CkfTuJVPHjQQLpJeC9y9urcj7 Ut.erC.YUbWIRSAdJF4454ngENEK30.2aLm.rgbrGHEKfi0iAznxORP7IU6Wk4BQzNNEAsxtIEAP G5IvnFAbCG4WXhoIM7A1MxO45WiGeCW0bSqKvtsAjHcntMxrl4w533.OFw_4dkYYkorO9nR_pQsM IQgizqKZfEI6E7bdKT4aXl6eEmqbSo1ph2k6kLQnDaTF4lk0cZEVNk3IKvrr7Hbq9CHAsaNUaUcg UrK0G74cC8dvqGuTnsp9aWEqcV__2xyLGWW_FepIG2YZ1.3ohDb7_uKMtgdFeA4B0yRBbtU7pX.d Rija__eI6593MQ8z6u9nGHz5sfQ1juXXpm_HYd1wIA60b67VmWUQvLv9QveDrBj6abfy3U0A3GZT E0J0DvC.gYRQ9ieCjq3ZDkX4VQ1wFk37EWoLnXWGchy4VI0R.YBhEHBwcYjn6bSTdvf6JxwifBa8 fo5bZlbUzOUKpm0fvn77r6NQuYClL4VqMU9rO7fy0_lmfaoQL4vm8oXGSktvq8YVCzM.kOwNOzkC XRScMkxWjsQ3hdc.4z0j7Vz6O8iIVBghuYhRvzmwh3Mq0qALid84U5Jh3FsBFYHt98ijWy849uQm v7o1CU6boRAUafDXgLxniQk1puxf2yJhO3nLginVMJmo6t.9C56XBzfxOY.BjDqUoZYDxiN5hKxu OMVXkVmorMGayaSmgPuFJkeEWD6G3KB9rWZyZrJBhdvND6kTZDOLdO1y4hT5Sxzl4pQ1epiC0hvz UX._3McorD7Z7vwrOVLijAvQ64DzK9ZpHKYz3d5BLLFQygJCAojUXgJYbpg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:58:53 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp423.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 9c4e55bd3d312d6c1e8f7ed93770d720; Tue, 09 Apr 2019 21:39:55 +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 Subject: [PATCH 02/59] LSM: Infrastructure management of the sock security Date: Tue, 9 Apr 2019 14:38:49 -0700 Message-Id: <20190409213946.1667-3-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 cdc5730666d6..1dbed888dab0 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -2055,6 +2055,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 Tue Apr 9 21:38: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: 10892467 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 8FA0D1805 for ; Tue, 9 Apr 2019 21:40:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 833492858B for ; Tue, 9 Apr 2019 21:40:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 773FF285D4; Tue, 9 Apr 2019 21:40:01 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 AFDEE285C6 for ; Tue, 9 Apr 2019 21:40:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726612AbfDIVkA (ORCPT ); Tue, 9 Apr 2019 17:40:00 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:36006 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726558AbfDIVj7 (ORCPT ); Tue, 9 Apr 2019 17:39:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554845997; bh=dF+9lBJ8wYV5xYvHfxtglumJAG1aS1bgW4kXIJ5xz2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=Zr128cxkTVAdG2kloMbct8DCOItGHGE+1CllJ6RrcFjtpBdS3k9yISB89XCA+2IV8loO7hhDzNnbYGPtfLizybv0GZ+JA+LVKAogZxsM2dzyEULUIO8HEoqCkuO9hqASkOd60aHYkSUdHckUsyy4U532oT/VO3TYuYkkLP7vFnbYy/4nRnCgzB4cvTzMd6EEL66USHM6yfpioAkUjUURflLeF5o6r8Ank1ylce/9AkgM7O864chkrgNQBkkh07iOrRF6nz6XZyeFw5OwMwvrSSiWnFiMDMvB8vwD4ADF7Cwnf35bsdemm+Sce6axcQwFQ4r9CqTt4STihjWJEu7Tcw== X-YMail-OSG: oqpfT9oVM1mTRmwgGGXLTAgDaJqn_4welTk8ilwBMD7g5al_u3zRJSEoNZpkIRO 11X5kpehji2zvM4Lb_4CQ4CM.eGiRt9G0Cd303BT47tuDO2CnzIHzjfwuuN9ICR7T9C2s67h8C9c AHWW__CdBO_fFjPOBj.08mBloq__stCOHLj9.g2hPtYB0sf9mmyZOFDoGGhzeK4VAtPoJqIIBuxA ju_N7lVvvdgPSm_4NZQDDVsPg7CEP.zKKWJCqanlLGn69X3JZWw6DeyoZTGGOWNjY0rDojppKCzy AgStZLgPJdPjtKsEOCjPba5CmYE39Kkc7Qr_CHu7SWlY8x2XZXIazmOkaxSH.E3kF8vqZyVzmD1Z .xIFCmcpf8Sov5bUAS6staG.gVA7nQNLHOF5RrwyLkABcQPLcN9YQUgIPilog0nvefQgYy7iRyfw A0KGL8NGcdT1PKxeaZWc2B.6eVHZIkM2ndlRe_x5Yl86b9B7_fKNvWqDP_m.6N1IX4XCoF9ifSYy s8eXgYLl7qUyOKiUKloXaDC1G3.HnI8DI9SOhHGS5tMAPx5jI7huyuFGMzfy_GzmbSBR.emreT45 QuhwMI69yuvuiglitkCzdQbryhAf83m7SehQUF5ucJKcBPUnVNA5ceo4dCh_5LQ4i8xX1LSTVS3o _IbjNFq8VejcE8ohtOr.4j9iRvYohJrfqAipS2A5LXOXTofVxh9O1XPdqOFKA3XjtZXux527.jbb hF614J5MQ2SH2iS9DGiI7JUnU4gKTu__1KqdEMwBPYST0iAvdL_nWfSgv_p4uQGbxh.IxJEnUVhb _FJM9Ou_qg7826IykzxexGtC3rqQI50h_UwtIwzRh81xPnOtDtAijsCE0iBRmVMZ_PTySkTDLFqK 464Dse7g1XtHdL3tVLXRAs1F4fMbXvPHJZ.T8riUWHhMQ45iUm6bfktyyJkTYUJcq6EvMvinbfd4 A7fLKWMcHcXbrtYxQgFulBUWV4d8IDsXvf0YbgTKEKl.igypv5naDJiX_rjChV1L6V1hCe991mGR 6wsXRMveR_eOC9IiNMPlMg1hXzmha5ZDPtzcd7bgYMH8CQ7K3oQ4UyQtx8bksZYBiUeS_b7OdKVX 6f9CI1S7naqsdLY.QAW5lwfEItrMo2tauDW_CIbtUIwfqgV79WxKY6F1d Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:39:57 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp423.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 9c4e55bd3d312d6c1e8f7ed93770d720; Tue, 09 Apr 2019 21:39:55 +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 Subject: [PATCH 03/59] LSM: Infrastructure management of the key security blob Date: Tue, 9 Apr 2019 14:38:50 -0700 Message-Id: <20190409213946.1667-4-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 1dbed888dab0..9e3d593a1ec3 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -2058,6 +2058,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 Tue Apr 9 21:38: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: 10892539 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 256741805 for ; Tue, 9 Apr 2019 21:41:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19C7F285C6 for ; Tue, 9 Apr 2019 21:41:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E16328952; Tue, 9 Apr 2019 21:41:07 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 B6D8E28862 for ; Tue, 9 Apr 2019 21:41:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726950AbfDIVlF (ORCPT ); Tue, 9 Apr 2019 17:41:05 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:34698 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726921AbfDIVlF (ORCPT ); Tue, 9 Apr 2019 17:41:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846063; bh=is2u5Y0DRwzBY1W00Se6/XMCwBAVUpvFG8LStFYaqTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=CE4wAe4du0Ththjc6C38kGggCV774T2tkuQoiQYOlUNxlIsngXVJxZ3TbPMjYNUK6SG71mnH867k8kOnY+ytTiZbhwC8BdfDNCRgW98ZD8DdF0FhHlFveHivLPwAIGiCqJkj9UV3jSoB6wSBmvPZ4lgCQ3hjUt5QGQ2r9ASISiJ0nx1wAKar0E5BhOTQ1stFARGpWdXLzFIFXzXRYc+tOR20P/tapt7ZdAH8ASWQuSGZ7juACUTtqkol1EC9ax6Rt5R34TcAJ0/UrZyCMqp1K3lC8G7fENRs8plBMav6/6GVypViCib12/BTR13PcIDgndEYFVqkLDQPCDbTLTdUbA== X-YMail-OSG: ufOrQ8UVM1kku_9wSsdaAxTssXUA5YN3hBly9MNLkc8G.AqInxIMKtZzvO45810 cHbPHlSYbqWDN0NHYapeGEaevGO7xBt89vg_yvZdtcSyOH15DR3GBMam7dA491eY7V73..PO_cRg ZsUI.M0utdJA65m.Xkcyf4Qf8mOVzV3W5fIXDHc_ED.ikYn4SW7QNPmai47V4_oMkCtMAUN5jPoh pkkPPIZk0Z9UVTgipiYTYXTC36WwYTuUu3DiLi8RGnYK4dY6imXDEVtH6jjt4WfXi2SP9KaI_gBt BSLI5I3n0PoYV3eFhk49x0fJJwVHcduyV9wvjzB5_Zl8CqhHOnyclcVjuLExjL19ZxVARRX3yOnH bXfXv0gkbD2HxRz_fGbaTPCb9C8JbMpsBrUcmBazYFtALqP9FSdI4xtdEWc1PBDq0KL9TdHwEC3z q2gmLhaIo4FaXUwoTZb59uOhp1tQRInEj.D11Ezud1_BE_z8rprLiNGibonMhSFJCDWwdFkvGx8J _MNv2CCVw6jSifdOmCqKNFUx8JS1YT47FVL_7_lPcjSu.QBgOdaRzew_KkYvyGBMXBtUpBeeBrU0 5mrHqaqS9WCTUOYk5IX0bYZuY7r87rvHB_PxHhP.78Lmuq2Q3ZkTu6NQ3OEqRUMOwu0shV76Ijji p8n9VLDZyT4.2f395gZCO3Q5VSJBMRGp0p4HriljoLLT6TzNG4U_Wi7pMSG3TtN3K9Sivyw6PnNZ Em5fi1QTZ1OujnQh4l4QkMaS7iMb0oa8DilERtU.U6fdMDFgCaffuQXQpktTQuZ5rhXxtVqxJZNi HMQBJ5nB2WgrUEInhuP57k6tObqP9Bpxl5_HKubQZ6hI_nXEl80RbmyZTsDNm_sLivutS06Q3WyR DMYJo3t1YpXk7.SiDsQqM.9hqM1r77K5xbTXvIihfpkZ2KePS1I6sq9q8aMeibS5FvBjsEJzLQcU FxHS5FL3U1_ko6O8chDJPtkfC0vB0SWTTcCFaao4ymBsy2ZJ9lesNLaEihg_S_ZBH7lXgrSt_G3C gynWm9oo3qilb7HGCLKbDjyRyRm8NF29MKHQXHj0Ud1dqh1BeoRHFuQJdZy72F93JEY50z3Q.H2A kYB4ecRIF0j4foV.zDwKYeLL50I4k149DlvG4qakghL137qLOq8_u1AsI Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:03 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp423.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 9c4e55bd3d312d6c1e8f7ed93770d720; Tue, 09 Apr 2019 21:39: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 Subject: [PATCH 04/59] LSM: Create an lsm_export data structure. Date: Tue, 9 Apr 2019 14:38:51 -0700 Message-Id: <20190409213946.1667-5-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:38: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: 10892469 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 09B9017EF for ; Tue, 9 Apr 2019 21:40:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFD8E2858B for ; Tue, 9 Apr 2019 21:40:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E04A7285E2; Tue, 9 Apr 2019 21:40:05 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 4B6EF2858B for ; Tue, 9 Apr 2019 21:40:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726627AbfDIVkE (ORCPT ); Tue, 9 Apr 2019 17:40:04 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:33502 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726646AbfDIVkE (ORCPT ); Tue, 9 Apr 2019 17:40:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846003; bh=NZEtztwTT91pajlXg+jbP5POdRvcqe1ikLbatbSvXaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=hfBUBaWI7Fha5o3QozF4JnXZTS/u0y/DmIceWlnkbwr6RQjpEPCfLLoq2OmQqjwvGpp7Ii+gnZLvNY1EcDOw2JSwgz9YjmpYTQha7hno/dq8Gz4mfpsBclIsGgqBZ3jgg0pX+A+AbSlRaKpcgJypj0I5hrcZAFDLZW+YF0I5Hg38ITr8qAM47YEoY4/ODVs3Z4D/KSv8HOEd1xqr8d4SR24lpF0K0v6kp4JjE6Oj+UpjVKePbenynwSH43+seNcmn3o31QwPHzD6j8qMsrsyLs1lJaEP6WyUcnwEjMxNcgZsiVxpCJAAEmmO4AJQnq3tKS/KNTErka7d5AOOctW/gg== X-YMail-OSG: sLORbUcVM1kTxK.uy0rfa.Q7kJhOR2ZlTLAvPSadHG9BHQXdqm1ouySJI16inmy G8gkd.PWSnXTFMYkxRkJWfK6N_1lRGIv.bKrrZXdCI_5NuTd_7G1fH1_1Izt98uEz9WLW7MJAISO 5TsvOaIbJZl3_Axy3QmWk46kRY4is_hJxQDlaW7LjRCWYhnDuyl3oEpCoi8ULYJt6Gz0VjV035B4 iDEDI9wVV2pEZP64Nxyheermzds833Oc6VRF.4xXBAMd.CE6_4uapRysMiMgFt63J6CHwGqXMlgf FfAJfvEmpECi4DKfE08CWqAOt4hi5SKrH.79bGTQHv.RfRgVUzcBJN3KFQJaW.u9owX6NXBg1rAZ g24Hp9WFFo7a5hqssHGAI7Xw.uwz8CHFEF.hrPj4MSiWJYCLAF4aTyWz19E_SV4PnC.d7LcJDf_. SA2Juj6cbNzXKKgL7A.fjC5b513gxGsOSxW06_SzwFAdu9rlzFTUo7g_m244ToHUz6GSjIB0YpeH as.XbqydirltsiMfNUyp3h34vpixsA9IyYZGM0rhhJkUy_Hky8BHhjt0sv0s3mjfjGL_b66BBLfR STHgo9x3dhIDO1wBhwWadzp6Gu2rYESofzeLUygVHH00t.Uttqp6h.7D3FzFgZhI7TebRhawZWyo yPanX6D3p4dYuIU_2vCc0OBNuQ_3IvzcTMW1I_h_7gJItAFSXsrBSmVI_JC31d1iA1N7FgfECiyQ GUbAMokNCvsKd53jLyF7wHlgyi5ryfnbngfeVvmDO76QhUstu.rREq_vpSaR4Ui3u14VtNb1G4sE zStSjp5dVXOuUakAvTXw3xw7ZHL0gAjzesYJMJI0SPipME0qJmUyEux1ymeYnVDsgE0i0k4R8vwN c98D1ViiB1jnTcewfDAVEVMjcBm8o9Z4NOdG7z8gKGfAYuFKjenCh5gQUZhrA8soG8G5_eDNXuiI g9mQGRrC6Qbn5wewyjf5Y6Y5AI2zkQ0Rs2x_8rJMEFtP7D9n_lzT05zkrTxuvHr0BdEY9ofckJGT tCyJB7mXHDPT1TH2g6iDQvhKmH1jSFm1hWUPLNe.B2Han05uUlkgWm.AejDuyJyg.FCG94RxVXE7 WBiPP4FwsG.o4h9hn2W3ukHnJesuuP9qVU07AVdkpZc31mxKLInAyWBWX Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:40:03 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 41cfc07a55038469dc17a23ac993d21e; Tue, 09 Apr 2019 21:40:02 +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 Subject: [PATCH 05/59] LSM: Use lsm_export in the inode_getsecid hooks Date: Tue, 9 Apr 2019 14:38:52 -0700 Message-Id: <20190409213946.1667-6-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 9e3d593a1ec3..baeb83ef487d 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 @@ -1574,7 +1574,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 Tue Apr 9 21:38: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: 10892473 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 582C013B5 for ; Tue, 9 Apr 2019 21:40:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AF4B2858B for ; Tue, 9 Apr 2019 21:40:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3EEE128600; Tue, 9 Apr 2019 21:40:06 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 BD2D9285C6 for ; Tue, 9 Apr 2019 21:40:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726646AbfDIVkF (ORCPT ); Tue, 9 Apr 2019 17:40:05 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:39943 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726654AbfDIVkE (ORCPT ); Tue, 9 Apr 2019 17:40:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846003; bh=+cOk5EbWObSrJ4n/q5EXan1kjg10sH4/KzvjAQgXLT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=iVSnesLvuWtaGSHlX77nm3XEHEDIgsXjVWup+NZxhREUwFCwjqsXEO2g8R6RNzdEasofcK5zO5n7jFNJf5x3q8nQ/I6Ericb/sDULGgEpzb8aYvrpE7wI7x/NNpIzZo7EyBW3ivmT9dNrlrsAvbXlY35Ocg1oW/1NYV+xjHQv5U4sAHR1UyBkEsFLZjl6EBEbNZ7b2e/n2WdVaWCu75+RNtThIHaMhoDPc1hnguBqekX4ZOTRPWVVHR57jWWNDm6hB383VGs3sdbYLu3P7nYT17R10eLp2GPrpvXLNXq+R82Q14b79LGbULoSwq0V8jc/StE8epRl/LDS9r6byAvew== X-YMail-OSG: s9q9MmgVM1li3i8R13VahEeBWs2zE6FEmcw8xGG_Kmr6qnIHeaKKfYsCmY.o_6A P7L6G6FTLUyGjAP26cx7_E5yEHRAmHP661ZpWN9.7ORAnINzsig5.kyj0sE1yLisPzMjZpvPrnRB _ACZfCl8VAVGlAvBf8_LLmoxFB.X0Dd.clUd9l6KBlaPHw3bxPnnR9N6Wk1G5pU3TPzLRs4r5EF0 91bkb0divxqt_TgGbpEt_LQRZY8hWX4UZ_c3foBmguEPTSY9_X.AZJfxUOwrbUGMAinx6Uu_Uk3r j9IcOKRNZq7I.a23hG0mqVEh28BTUksTpnd4xEJwv5DmKroPCPcXh7NLZwB1Vc5UiommlWHrERRO nTL2utNzVndnNf90yM4GWNziONuHzNqwXPrI3HSlTmrASjTwh4aGmchYvdnkQ9JLvhqeS0siHyYo 22uuBeH0P2796XOoIE_6UQgz5Man9TkzknSlueukaQnqIMUUEDBFsd_46WI5WITGW5jURoPVgaVw TKo0c1YNnIXEtnFvufWM1WuKoCe6q7yfYOxyrbkQrp5qtgJ1kVXA8Z0lVNSUayWhOTOn7uIceflr G06mcb90yAt6wqPq0Bp4dptCGF_b0h_dWEUJhf7rgHS3P_m3eYDjjQYebYZlh5GV5sK.ciDenoLt duoqM1M8Ju4eozmoTZEdUnt3tMdysT6P2szU6UF7VAgD8dODyvhxNnhCsZfW7DFqbs8f2FhbK8eb UgA4HXTWwhvrb4rmrby5K_KYlkt.abv2w5Ki9Ek0cHlMpWV9P6l6..mbMfd122MA.lPdje90WRso y3owWMxhCPgyV1sKVSkT_tkx1986vb4c_D0Td5QhoOUzclyDfz.XIIVaR7RX7dU2rMRkOF8yghud aycTg1Y4lEcrEuKCy.OUlgXOTpNegHdPYT68EyisrCqFrIY75peW5HHiTY1od0CfnZUDGpr0S4P0 SZoN2mF4zpMMqZAgsokbZCh_8UWENHJCZFYbKdFumjcaaEeNf89eunSSEJZrpbmu8SCqmUBH7Nc4 cAJwR7hlVZthhxevz.wZMkOsxnmEHR8867JJI97w.4Y.bvG4SL3_.63xfWZkaTdUOEFiMW.ZiZl4 WNcqdLPJlBIBT4Bbv4hVF0mEJaKytE2LVl3O0eUrAa5JDNffmTLalxrAe Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:40:03 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 41cfc07a55038469dc17a23ac993d21e; Tue, 09 Apr 2019 21:40:02 +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 Subject: [PATCH 06/59] LSM: Use lsm_export in the cred_getsecid hooks Date: Tue, 9 Apr 2019 14:38:53 -0700 Message-Id: <20190409213946.1667-7-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 baeb83ef487d..2fe54dff3efa 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). @@ -1604,7 +1605,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 Tue Apr 9 21:38: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: 10892483 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 AAA16186D for ; Tue, 9 Apr 2019 21:40:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A91728833 for ; Tue, 9 Apr 2019 21:40:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E38528857; Tue, 9 Apr 2019 21:40:11 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 F205D2886B for ; Tue, 9 Apr 2019 21:40:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726685AbfDIVkK (ORCPT ); Tue, 9 Apr 2019 17:40:10 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:36139 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726680AbfDIVkJ (ORCPT ); Tue, 9 Apr 2019 17:40:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846008; bh=MmtCEsyght4Z5zl828NTA0CWqne8Yk1YCMTRtKNxpho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=YLt91O1c7WgylMvRKH9RLviTxv2cmvhYAbEq3Hsu3MGd+wuyAkdMQnhz3bqpyVvTHYOAFFzra5cJusBgAdKK1cWNZt2EM5Tg/X0CUjRj2YI28PoYeLvUjmMkE/KoTs/l0E2l8hhXfTMETrBii0xjK2pf5RfkzwfcZD2NllqUCCwFD8ydVgCW5Q0ScRS7Xmc3DhdrvIvJ7ey/oZB8ImgJ7ukeOh47gzd1rbGUPojgNAYvJVolZcA0PzQVIsNOem+JPTrYM+Tc6fLmSqxdORaBOMjBZ955vdpCRCRreQ3nf37BOaQtEof0opus2ZR75mNZdu7910k6oA0jbP35QsxL9w== X-YMail-OSG: k4EfCOwVM1mKBhuVMcr4ulfCv51meTDF864CBMmCq2NhWGVxcnLib5J.AzL8UT9 8OLA23oEibw377w6qeP78lnTXXhEUZ9m6HgZBZowwv8YvRzd10.51pHluWha.3pK1y3eoESoxg55 mTu3e72wpkbX5KlyNJSKrRToUroB7EqQkk1fpePvBujEXlemLnd2pZpxKfxvTdLnuVkT64cE6d43 CvPeEi7wtkuJoCnkM4LzaHmU4GRBA4.Q323386s0cmNpXSaXpbYamVmYnaZMvmnzdV6OzS1gfdBJ OV757sQAAJUOefxRSPHCtaxzQyCKVn2UuBoWk9iCUbea6RFyxERoer_ZD139NQSKzecruaWNBcax CJCAOQhOOi5enhm8IUKwoueQvCJXIQw2THMFekCzCtIo6LjrSvsLSuHajPLh5LHgkbqNRY4me754 NdoBYq_1rcp_xT5CcNi9vx._yxc.oDluwgeMkEnxF8rNzBcvcPF.jHyC250zwxliHbmZ6pbU1hGU 3DwWcgf1hzspLGmk3YHHvOuzwljy3Jlb5ji1F8Nk5KNv3PobJe6NLcu90ZmWkJgM8IgnKGGxGBXK 7xw9PtZmZWPXmwQKM39YJOXo022xRtmWNGkrPN5XmtBnjDggw4sKGPEiFeDi2ik_Ypzemqz55mS6 DpUyUNTlKNXbf5EsKODx7q_31h3PjdY9VM4_n.GgU8k7rxK65diOy774Id0aD1.XYZVe9lQac4nz gGJNBzcgIPzdUVt0jfoQXD9vUmnsI7LIDIU.yWjrH8babVEeESICvCFpl.5YsThTM_mo.XY9ZZbQ dWJS3LwZBdLsNpYe3gE9Pal8VXbIAdOFtGeo.cHvWaRjbEGTJHnX1FcZzJAySxyQdrEzNzkLstss wxFxPew.xO54WMODbmgusCd_t6LuF0PgZowa4p7RzglZKX3zb4hp3GKUZ8YgIy956yR2cbhGd9dz xsVjlK9ooYmEP3bxdJspyeq.XKO2X3J4m_FLUd2DxR395UXY6sy8XYLpEKOHlrAJd8TgdYoKMyHt ULuG8e_HeDO4lMBLWGJOGTs.wdEw0wwMkj.NJM_2HylZQHeGnMnwR.H9fJrW0RA44t0sKHCs7kO8 CJjAZxeBi53QvNfvhP_ma.Q2d5oulc6svUsgzZRHgraFnA2cQdi1RkH7U Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:40:08 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 41cfc07a55038469dc17a23ac993d21e; Tue, 09 Apr 2019 21:40:03 +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 Subject: [PATCH 07/59] LSM: Use lsm_export in the ipc_getsecid and task_getsecid hooks Date: Tue, 9 Apr 2019 14:38:54 -0700 Message-Id: <20190409213946.1667-8-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 2fe54dff3efa..544671f44dfa 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: @@ -1096,7 +1096,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 @@ -1618,7 +1618,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); @@ -1636,7 +1636,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 Tue Apr 9 21:38: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: 10892481 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 6428613B5 for ; Tue, 9 Apr 2019 21:40:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5659128833 for ; Tue, 9 Apr 2019 21:40:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4ABE128862; Tue, 9 Apr 2019 21:40:11 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 C7DFA28833 for ; Tue, 9 Apr 2019 21:40:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726671AbfDIVkK (ORCPT ); Tue, 9 Apr 2019 17:40:10 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:36071 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726666AbfDIVkJ (ORCPT ); Tue, 9 Apr 2019 17:40:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846008; bh=bnhiZa2kx1PJdglKUm2qCM3rIeOnoh8kwEckh5gvzqc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=gB06Fa0QMAcsuml4RI8uu5WCrA1zfrteG020hPMsMSWrB+tBbk5ZQFR4cWRUAHNtIBa13NqMWnufoXa7GSDEPcOEI3Jr5FLndLwzvBiaxLaCh+djA4gqgCkLb26RSFADIUDEyM90gMw0B2nnbXfaDBrR0naIsqOYaIiH6Ew4jnpaHGd+kwLEmlSDXzR93CtSUEe1+Mgb5cpz4Dzk7WJ3ceDjQalv3KVRn8CO/UXkFHST2NNrQCeGbx2RZcncOHN1taoW0O4+uMB1ejO7xS4pUIyyg7AXedq4+GSPTZAvRY4G3FDMRTAnqntB1ivbJ7a32YPr0uHLW2KMCpcths0agg== X-YMail-OSG: YKw6R84VM1k0FCWcTp72.ycJ1EwOudTV2uQxVPEGILym8CbcNRfd8ZlNRmm4enT eWF2xEgiOthU6XdkcgxVNHOQ.wOpUpyrgdPLRoAQ7B18hWAs.JiuSla5FeEFSmwlNLHiSmEI6npu OaE25SXfbsXoqhrp1TIuRA4R4xsjpGUtkN_ZW9CqKP9vkdX2IUCDFVWh94jHheMFkQrZ2IgYOUPo 5W2Evi5RYGyiBQBWJU1RCSYTeS.bj2fOBUtG.av1GHCKcOCyIZc9H0zC2uK5SEKzYAeMQ.pzr_gq wHz5ecuXaGYMQ0G_LSfMKMktr8yAKvACQGiqdkwad0s3NegAAQ07wiW4.oc4yMw850gUEFd8qo_V cDMAyPg6.PwZxSgw2dgSFEGlqym4cXq8UXKVYswEB3HDST6cBlnNtvzA165viHajty5p2JUWMErU A_XimzVHkHvBJZBHILniOt2JnO50tZukdi5U7gbwdm2F1YSSGh9PHmFPypzmar3TNLdC6hqPd33v kY7desXQS2ve7wQBVgDkANip1qUX8SzmfjnFX1HruZ_VCsHEgtbM.jilRKfzBDp2pn.kAaeiVV8Q oJSehycIa5jf26UUJ00BaKt.uwyzCwM6jmEOc_yAKD.gRnlNmCNTbIZd_JpF8WBQNmlvHRyjWJRU .DSPQPg2985nN036jm6ijXcT5B.8PJTFLuJ_yEdA0o.gzkHj0EcgP13mLNzXEAKD7XD7ThwoH1TP 0iF50ZT7ukGgxCGr8xwbpH6Dtsrxwo_MkLRI_zAaD1I.OHZiw8ovtv8fATFqXXIXYau67CeGzvsc govJbvA9eTKr3BZLwgyOq32ODjX8nGhEOW0Js5.ZcLWl9ajRyY1rU3NNVwCnMFki3NjsiFVNGOu7 olQ5ai14DelcRWxjmmKgwf41KSjAe7v7vSf59EjviDa6fDOk.rW.F42OXjAK8IxB2bzKUDFMmjUX kGSMYDtKxBN72I4y0CdIPFHiAQBR8LJW.0mWJ47zPplb9qWKAcoBmijBYFLLtbdgdVHJ.LRhnq.f vqxlQP.Af0Cavd_DFZJPqyJ3y7QvwLvereh.5cWjzmcdJbVTSfL_Ik6YtEjmzHEUId6koUwoCVdP QyudFxMNoAD3pv3XNG1p1wQ7hQXH36k1ie1mShBuXQyEYjTsBxLkO9y60 Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:40:08 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 41cfc07a55038469dc17a23ac993d21e; Tue, 09 Apr 2019 21:40:03 +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 Subject: [PATCH 08/59] LSM: Use lsm_export in the kernel_ask_as hooks Date: Tue, 9 Apr 2019 14:38:55 -0700 Message-Id: <20190409213946.1667-9-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 544671f44dfa..85b8217ce2f2 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: @@ -1606,7 +1606,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..8d4334f68a65 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..da85d607d40a 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 Tue Apr 9 21:38: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: 10892651 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 B4E4F1805 for ; Tue, 9 Apr 2019 21:41:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5F14285C6 for ; Tue, 9 Apr 2019 21:41:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9AA542887B; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 17A4F28857 for ; Tue, 9 Apr 2019 21:41:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727065AbfDIVln (ORCPT ); Tue, 9 Apr 2019 17:41:43 -0400 Received: from sonic304-28.consmr.mail.ne1.yahoo.com ([66.163.191.154]:39556 "EHLO sonic304-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727081AbfDIVln (ORCPT ); Tue, 9 Apr 2019 17:41:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846093; bh=FXPJ6Gfz/Kw1RJDXF2OhaTmACwfJr6C43ZPwo4T1SLA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=Tx4hvfSPIN/elJ/3kye42/xYh1BNpYNmB25tdD99SCnUwhMFdAHr5mBZSLF+CHMcYaVXXXepP1nniOLq/KabyktXIgHFmfvNqBzLwt+dbZlTC9KV9iGPuHqDarZ0NVZ9OIqJBiX3lpXh1pEwqBWaa1L1Ah8vP1H8rebgUE11uWINBLzRQKNe/UQsllm06j/iw519HkAgzjSs4pebGm2rWwzwdzdqNhlSrt6/P88AMgpFEtu3wPnfta8WQPGbYzQ5GYLXzPYDnB4KAGo5pkcRKLVTv45AOdfovwLRIqPpfBq8CSsI/ArBJIPSqspdFUZ+VGv1ZbmFuDeAk+W4M73gug== X-YMail-OSG: _VsKVtoVM1kZKaN3MoQK6Icl.2EQRj3CewU1qPgs_EA7kVmXP9b_4wO8duUE2kd 6L_O7eFOy8KLimBqQf_JbsbpQfkn6KR5HmJLNFBSzgzYGz4kCTAZjYeMy8AfaV7biM.F64IRJdBz hPnmgbL1lAOfXi7jXskhf4vDO6ynqVLg_o1YDY.VIh2557z0tXZbEP7Z4a7SLWL_Am1C9IBYgPAR d3WyG74elQD_4xiBbhFE.36BkDw.o.LQoQ0Ov5mddhUA2C.dwORavs1dOHy_wEa9tfPM40nHP97J W3Y_IJjEyYynxFDC6AsjNjxQC2aCPa76WaEG664gIBcx1t5xK_NyP2ultRK6PG8Dle1KZfwOztIL ewVnHZSFB2kTl_Nd0u0kXG1LuMMIfB4zdmrGbxjd0av9jtvnWRxkPC3x3daFxjDebYUeP7LlulS6 L0H2IAYUnW4drejIGbM74lgHaWwrUQa_bjtV1EywMqqE.sWdfJJRvpRcoKwpjP6XAmuTMhR4eyKj qP76hLgWYFmSU45zOSaQYAdMK3nvOr4gQCeeeY6v9BHS6g9Upix744vc9OK9r113JquIQfntpC3b mgqz5OaC.MX2MVznBmnYF1JJppxJMTHejzUEPyNztexz2frUVOZAIUVY79jk1.2bH5ebNp7gq1RC n7e7nAWvmZ.NeThHuVZqblYQ8YiZ5uuHUJT7d4WW9uzOXgckHTwEtO0u0.px56_4nUbQDXf1jlmW 9BJy8oZ7LQAqse2KLf64elFaHRSY_p3GS3dhtLguEctd1WmsV1GqUg2JP1asEHFyISJCzCYcsaSV wy2wb2rXkXk0MxLu1uHTCAC3jxQDKSPvZ338dLjK_UCIgXXuGzjQaOawh2qG3OSpgqYP4w9gCmmg Qgk2OomeQIY0bVoVTNU3WuyKjNdFNJRnTqOFc9UVlEPrdZLKvDodQa4fbMMU_4cdBgLz51E8kydd fVj6NIcfkTKLbUy57PCyIgByqKEbKk64gglM8bbyG5sAODhmR93momcrW2W_1qZ2nieTNH8Xt4dC ZL8kSz4YffFbgaLhsK3ZHaEnYls6l.zUbn7SS1Iu6DK3unA9hMi0R1ZPMhvwqXOfLx3Eq1uU9L6I PKuMekGPzvqcCS5T7LysquHkhedRax5T_kV3NjUwePcaGMNV6hk29r4boVA-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:33 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 41cfc07a55038469dc17a23ac993d21e; Tue, 09 Apr 2019 21:40:04 +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 Subject: [PATCH 09/59] LSM: Use lsm_export in the getpeersec_dgram hooks Date: Tue, 9 Apr 2019 14:38:56 -0700 Message-Id: <20190409213946.1667-10-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 | 7 ++++--- security/apparmor/lsm.c | 3 ++- security/security.c | 13 ++++++++++--- security/selinux/hooks.c | 6 ++++-- security/smack/smack_lsm.c | 5 +++-- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 85b8217ce2f2..59f38c18426a 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -881,9 +881,9 @@ * the IP_PASSSEC option via getsockopt. It can then retrieve the * security state returned by this hook for a packet via the SCM_SECURITY * ancillary message type. + * @sock is the socket * @skb is the skbuff for the packet being queried - * @secdata is a pointer to a buffer in which to copy the security data - * @seclen is the maximum length for @secdata + * @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, @@ -1710,7 +1710,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 8d4334f68a65..03dfa0cd6739 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 da85d607d40a..5318b9e6820a 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 Tue Apr 9 21:38: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: 10892497 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 9CA94186D for ; Tue, 9 Apr 2019 21:40:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FC8928862 for ; Tue, 9 Apr 2019 21:40:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 845AD28885; Tue, 9 Apr 2019 21:40:38 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 B4D0D28862 for ; Tue, 9 Apr 2019 21:40:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726702AbfDIVkh (ORCPT ); Tue, 9 Apr 2019 17:40:37 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:35967 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726688AbfDIVkh (ORCPT ); Tue, 9 Apr 2019 17:40:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846034; bh=JqmHPCKmgnqzoENFdhELAFCXcZpoQtrMW7bW3NRYmPs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=HlwY0lNhX1FhcFnPElrBurIZ15Zrm4ArjEJP0wdlT6vdAQf8Hnd1Io7idDx8UoqPwckWRmZQCySiwt81+awjQ2YXU6mv1L5HHGDFskYg/402ThG9cLimJj8k9rdE9QCqukBjeljhUjClIjj9OCcFsw8/YQrldRiQhGlgwv4h3hNsZ6rkCbCY44f1qKRMUsMerzs5isiPT46mnKF3nKNaSAD96TqIzQZIfnVQFZVEcM3t6wWsC007LE2nkZzm8BRWfL1DD1uN73m3MFq/5LB0vHgMEocxlfR7Oogjk9SJd1WDbg/4EzUiFsjrV6vsDNfZv04lW8yriPwHdxjWV2sn+Q== X-YMail-OSG: Gg4XAOUVM1nPPTxCYwxtHpzBZGwRUFRJNoFXnhRROCwsMFhZLEQ7mQf_7Asj5kH EhmwWCNCOiKmn2HucVGPOKbXk_RrDZ3i6AZIM2vnrgHP83r9DFrB5pSWuLe5IcdqD_ZgKaUZQfaS BCODeL5ix3HO1mXV5TxaLcSD4Iu1ZvwZaGZhJy6hanKu6HWOO5jlOEVSSZkm5lRxmtPZplhm91Lg t0OfwQOiwEKwjoCoSxa6ODRPvdghGrXwgdgKmslIHDD3.0t_gx4.myXykA7rP8QpqaSb94Qhys3K fhe3t5V97ax6WgBSwD47xaDEZeIPBOUzsXZw7.dtsxqRDUVBWi11WgCv0VuyZTCDHtk4ARtpug04 xIJXQPxEhY7xemPh1L.wue7ipYTUh6xt.VEIe2hkhDvmJiimGROiWyPa74lumhjYWeHTiJ7TMQUe UivwnWHY53viSjmKlIa1m9fNeWnomqk5uUe9zABh29KMJsea3RRvp.L4hZsyjAvARNo2swkPWvKY rSbye_5H2k.ZechIMqz.aLRrvVoKoihsAdGyZxokipDdWf1xU3V2HgUcwuiXMHPdRDDooUP7Cd20 8ROq9T7qf74sEAWDXjMAHHR6ZAZOROWW4XIBBEESXK1jamJYSl.z_idGeARB2bllT6pmv6d6SK3m 4yjYgkM2H1dhsnl17BKv9_VlyHrF.9hbXFM1rMC0dNLElMmXL9ILEHrDXOkNHFHw_ZZRyL40aPjO kAk2wj9bysr8n66K6G8kk3c6Os8V_pEZLgMGCGHkgDihylAslAh8.WS_wv_T.p3B9uZnqkTNcQHD iyEsWc286uunRoT2_ptbaCD07xQR0UPa3HL9sC3W7sYElCVlq0y1O283gwQf5eLMPd5aGc3CbXwo mkeIv42DqY5vJtcabt6vAKc69lqfj9EO8O3xXWvL1VSeji_9z0p9QOlyAgq7FTdnynsJ_Ehq18rc oTXoMNO0zthrqFz5CAmLea6wqngFkgd1XKMEmiMxVt5d2qQksy__3Bh3jgygeLZFWxHvd3vTFWg6 tQUaXwX72uC2dloehYNR.NzQ2FTpo06QjCBrN5uMt31wwt6as2XlLHNtmGkJY3qp4tq5u4q0ZaB6 .H7ODeR4wUfxeOiCTRD.hFaJxIIzhdl2PZMKhTAcMBmuG8lvNjpVnQztSyY4- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:40:34 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp413.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 3d2ea789de6b345569f1c9b3872b02c3; Tue, 09 Apr 2019 21:40: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 Subject: [PATCH 10/59] LSM: Use lsm_export in the audit_rule_match hooks Date: Tue, 9 Apr 2019 14:38:57 -0700 Message-Id: <20190409213946.1667-11-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 59f38c18426a..690ab020508e 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1357,7 +1357,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. * @rule points to the audit rule that will be checked against. @@ -1786,7 +1786,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 03dfa0cd6739..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..d7efc5f23c1e 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 5318b9e6820a..0e048c1456ed 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 Tue Apr 9 21:38: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: 10892537 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 0CDAF17EF for ; Tue, 9 Apr 2019 21:41:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F22C02887B for ; Tue, 9 Apr 2019 21:41:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E440728885; Tue, 9 Apr 2019 21:41:06 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 96503285C6 for ; Tue, 9 Apr 2019 21:41:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726944AbfDIVlF (ORCPT ); Tue, 9 Apr 2019 17:41:05 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:40709 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726757AbfDIVlF (ORCPT ); Tue, 9 Apr 2019 17:41:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846063; bh=fnJcv2J/MrzRf8h1makEn2/UWDvYNR2yTG2TfGic4Xg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=Ypio5f4YH48Oq+GLJiivwqPJo4/Yf6THJmZ/XIV8VS8NpoGZdeI3foe0jla4dOq3crx2I9nzZnEk/NeEhqE9tp+9qQULlMDkWknmLfN2Lxz0L8BRRSq9BdGnnASTc5dTFz/HbqRupXoLhiGau1AJQu50FGjKDHdhgn/gCY/q+n2QPqjoEhiA/giPritniGaL6T3wWDKeHFUpmIrPInJPkrLpsScJMU4tR0zVOlqWvLDxczAcMvjfDX5j0quGT8HJ8mTFsEknBsATU9KEIgGoFSMmDSV9I6C4jOSmXrfp2S4+WGvpItbyURPnjsn95OT1ChX4bZAphpYc3ytnWP6McA== X-YMail-OSG: g5WvnMQVM1m3RHUQczxuuHTERk8A2jN1rpR4IlE_THH0U1emOIzaKatldN47RUx e3ZGFdCLUnYF9fuvo3Gfo9H6YDVluTyFIols2c_RleVJomeSFTFgXIPKsdJ6na8_wXR3hCW66SG0 snvnenOfde_T_hocjYDam0mQNwMmfqi.BCUdZfbouDpYvaFfW3ayQ6Obk.8ibd_.xVz3lG3dtdfs vfu2jQXVRfNFv7tcVVgh9QexE9Oxrz3UesNrFBJig14hDUpqK2aLJ8qLh7qm.0vS.J2qq.3sfzK. KFnpYS6w997H94TZUaETW_k3qWgiJ5hSfM2kWw9yt0tZtraIDqYV0QSrStclf48GYV20dT1I3wJM OM5TpeC9ZmF1Pr1p6fdlzTOqZaYtq6M9MZ5r.wzcjfnp7RyEEIaUKMwS6ouZP0dFdnWWYWYE2ERz BpH_yv1t50W6gr9cu7dS3kbX9.qjN9CaHuqLhoYSOgEd.qyeVt33PVk_yzbLYEkygtl1qNOIZsHE qIoOAS68d_WC13JCFuUX8s_tuzYldlKy5Wsg_qCctT1CXiCuWpu3QqMHIUthClKE4DtNvQ9K_cP2 k2_ESTXXCrizU_63qIlh.XHatUJAhcb0SzBAtK8Nrl82UmruehcjeskGvFg6im.TW8zl9QUIeXGQ tPbXINGQA.ZWHuAIvAvLhJz_2yJnAGvQks28NpyENK8ChXEtmqQOg0Zm9TO22tBepKbtQyObOX4z RaiB5lf1u4xNhFaKZJgBwXE8.PGYFYK8m8FT2SC6VVOXYlWFXftGcD8YczfravDlkS.kRwvmS381 jN5KDh0NojAYe8y7DgwLwP.XCEsOqDOZ.NB9LA7_bMUO7NX3ik.9W0U3s12zPOjiLIdL5WPj2zmo JR9sLu7TIj0aYcc12GwAQqCv4q9J0tTIZ8psj9Hgo7C9I_Ox6JkcMDJs7aNRr8MovOuGauShoJ2G W7KcOMjcUDfafcP7HBgx1qCQk6hmW2tzSBGEnV23hFS4cHd43CD9xqdKRh3MTxlEQRPWW6bU_yEc 50sWWz5ch32PynAzLOxyLDZVbYLNLpq7NQkVUlwYd2RPg06tS.Fy.4Tl.HWU4BLtLlQoaIhUSc9v CfQdafQeQD62hBEcRU7dV8MeoGr_mCgPR20eFfN3DHJMSjbxgkwJpixeQ068- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:03 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp413.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 3d2ea789de6b345569f1c9b3872b02c3; Tue, 09 Apr 2019 21:40: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 Subject: [PATCH 11/59] LSM: Fix logical operation in lsm_export checks Date: Tue, 9 Apr 2019 14:38:58 -0700 Message-Id: <20190409213946.1667-12-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Fix the logic in Smack and SELinux when checking to see if the secid is included. Signed-off-by: Casey Schaufler --- security/selinux/include/objsec.h | 2 +- security/smack/smack_lsm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/security/selinux/include/objsec.h b/security/selinux/include/objsec.h index d7efc5f23c1e..59a3b1cd5ba9 100644 --- a/security/selinux/include/objsec.h +++ b/security/selinux/include/objsec.h @@ -61,7 +61,7 @@ static inline void selinux_export_secid(struct lsm_export *l, u32 secid) static inline void selinux_import_secid(struct lsm_export *l, u32 *secid) { - if (l->flags | LSM_EXPORT_SELINUX) + if (l->flags & LSM_EXPORT_SELINUX) *secid = l->selinux; else *secid = SECSID_NULL; diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 0e048c1456ed..a3776501965d 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -477,7 +477,7 @@ static inline void smack_export_secid(struct lsm_export *l, u32 secid) static inline void smack_import_secid(struct lsm_export *l, u32 *secid) { - if (l->flags | LSM_EXPORT_SMACK) + if (l->flags & LSM_EXPORT_SMACK) *secid = l->smack; else *secid = 0; From patchwork Tue Apr 9 21:38: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: 10892509 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 7A53E13B5 for ; Tue, 9 Apr 2019 21:40:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C4862889C for ; Tue, 9 Apr 2019 21:40:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 570D62897E; Tue, 9 Apr 2019 21:40: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 D31A22887B for ; Tue, 9 Apr 2019 21:40:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726680AbfDIVkh (ORCPT ); Tue, 9 Apr 2019 17:40:37 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:39284 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726697AbfDIVkf (ORCPT ); Tue, 9 Apr 2019 17:40:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846034; bh=seyjgce0pdmEa+cpaRVpjQK9OBPNuMErUFViqdarFKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=GctxdS4ZjDWc4sJ9bqL7yyIMqH8jAaJBAzAns1jxy1jexvWr0m3fcTXaePXwX7OqwUluaqE6NxyPr9MW6vYRrkALhfQVMo1DL7WDcgRJh2RjTUNmeuH8H+1kHOwTy+drurYxHmFRP5MTvQTDpKX1v75AeArhDcw+KhLg10jMQxIKrN4Bx1FrUb9bt89lq1WpjLyjF3cOKq4lZJJkLAKLgt9EI/TnnpGdg3EB5BQWgg/v0R3iH9hS+6ICYicEKCMNeUmRqpMDPZzpo4tf8ZeO9pdTBQpkGI34Z4+tlBclGnVqU3u2nz4WLU+mZrneiMMtemmz3zZ7p3HQPj6u4h4Bag== X-YMail-OSG: l549ItYVM1kxaTdV9HZlkn9F_XyoxLzGYKXJ3LJi3034pz_bIsVNq3TfOZrOkV0 W95.wU5a8Nef43bKq3FLr3ZyIj9VjEnDWZdeud2db9UZVD71AzgjfMbk.Rfdj0bToT0nU0k_k.GJ j9JC3Nxx43imuofvnJpIsk5qffTLgKRH11ET.sO8UiwXa6l4Ji.7mlPmX_2faTsNz8rJrzZcbuL9 zY0gFq0a7k7PHWuFmBalS8oBkMJFddMr5BgwW7CeRzkxb6y0moFC2ER_VHQVE5mS2GuHtfI36S3c o3cfvBcWxuX22Q_ngdIzUxr4FcsUT6DgM1dVzrZsI1Bpj.KtSeJQPq6FT4Yg845SiGlOK5vnpTs8 pBJoypObgCSp.zLIIEBALEz49nXs0DmZDg2ehydW2cAxCKuHpvC9jpIR0oBefCbmex9CR9XnXD5U UYvf8lJzXA3qeB3ISicH0VgRTc4ATh0gNpHySmLPHHJMOrEsCKizUukrncaFv7ixIuYPWqwIFB8y Ezm45zFla8BOx0.FBYX6fq4R2eWuL3A7.3yFC0VHc9RLt85cS5RtM3hQA5clobmah4RM_5HxCRz9 8_wNkfVS2ENHR_K5qLggv5LkXb6mYzSgrXzRznuql56BSxcjcI5B_VlPj6LUbVQX12RJI_XP1Epx 4EOWCxiBN5k2CtOPxmbTARi0TLmJI2.J8vQO8KXDWnd0DfnXL06H8rBdjpWivWcz6WNuZR1APoAC TTfNvBs0fQ5L0t4LxeT69709VnQzdmyNttcT4AU54OW6kzq3PVtvWIfkKB1KzecK6awVQXrYxrvU SbFPzSP5PTozU_P8MwwmC8sp8osyJ7olgHIpVINM45Qxf2PcNzt8yA4ykvnOY7dZ56i3bbLeCucy PIrEXrHCQAbZZ_kznjYmSr99x6vBftCLA04SkCfJonRfLEGvD3j1PLyEbYkuw7.h68DF_IL.Uoav ku9Zs4gaPov3Bvdn4yQzJnxyhfDywY2Ud5lKIpGjF4ElUYrr8nkdnKa93S6uyCrfc0qW9LAXJOwe StDyER5OoKIo0d3ChXkappPR7VIu_XI1qP9upBnkuDG1dVyrcbFm_jAWIljRp79hRQScu1UWQMgv IglfMg0XkAEDqlSYYLv0zH6a7LtLwlXHSNycK9i9b4gCQbsW73rIuAA2t0PE- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:40:34 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp413.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 3d2ea789de6b345569f1c9b3872b02c3; Tue, 09 Apr 2019 21:40: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 Subject: [PATCH 12/59] LSM: Use lsm_export in the secid_to_secctx hooks Date: Tue, 9 Apr 2019 14:38:59 -0700 Message-Id: <20190409213946.1667-13-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 690ab020508e..11ace5c923bd 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1322,7 +1322,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 @@ -1672,7 +1672,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 Tue Apr 9 21:39: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: 10892507 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 57DFE1805 for ; Tue, 9 Apr 2019 21:40:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47C7628862 for ; Tue, 9 Apr 2019 21:40:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C8E82887B; Tue, 9 Apr 2019 21:40:39 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 B405F2886B for ; Tue, 9 Apr 2019 21:40:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726602AbfDIVkh (ORCPT ); Tue, 9 Apr 2019 17:40:37 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:37539 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726690AbfDIVkf (ORCPT ); Tue, 9 Apr 2019 17:40:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846034; bh=HePCWke2c6I7BkpqTHfPNmlfpR/ZgJTIEAfrAn5Ctvo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=RavP5LuLw0V0LS3NgYFJCacnGzNBF9gEPdxMEXXcFZqMIQ8zwv/aWedJ+6tvVvKNHHKQu2/wMTZAoe5XQLQ9XGNwPnZKjAohteH6X9Nq1xQVCxvVwL0uzFGXBpZTlXWw+ijqB5HoBagN4iaSdS9BCutBwEuYphmFsF0Y8UnkZFhqp7o0MRpDdwfgsMsFNh4ruXAfT7BwR8iUyKq84cTcU5YKaunN4IWaqtUo/yxL0yYH0r9LRspAVL4NajsxHoREqamjrSa86ocVSAerbGgA4mEmpzy9Ij1V9LTmuwevEezz8RpQxnj8c3SjhC970Gl2gE4z8I19Ffe9AeHUL5rbsw== X-YMail-OSG: x8_mjywVM1mNb8656Bqzx6HjpolPq6Bas42SzM8kRKqjybiMb0_xOFNTLbIGWhO 7rOCGO0MVDd0b5Q4ppLVgl9__mTA63pe.wGN3e3UrIyBLhtCpV3iR_ChvJ_BuUtnPuIJv.BObD52 rJJPtytkv_Vmls_6bfV0yCQ7TkC75trmDhxoO6AlWGd28e1NGeA4PzlVFa60uZ9fyjFOpz2F5KqF vU_IlG5OWNCBiTfOhYH5OYAxndAtl_pFy44GhN2aS_gOEuIHUx.mELrcQcDOGGcW_8OL0b55mEHC Whc3PazV8_AId8l3bL.zVN5afRtKPKWgkbnUViNUkVMGpCvTWMf55FmOQdoSHxMVQN8FXSiGtK3G S6aXcfdwS_zWALha9P_MKhtSMIEDd41AyraPdvBCkRuc4eaAFPzQ_kM9HaTUNDplaatpseMPGY4e _BeKnTl0Rf502gDavvJ2uhmQVjYo8rwhp3U0xyPJXmQQBfoz2KZd.6HmBerpQ2jfQWZszx2LySWt mWG5iPwGmyUACYgEZnP.MUaDu7mUgFPcWYV7a0jeqanu72b9KsrWNzoN36WxRNgfM1Pn4PHdrZue f0O2HdsB4Wo1rI5S_yeMEoaV4t63qm2JTlw9UEz7Z.Oxa_adfaQmSNu50F0VdzGaiCbkvfyW8W07 l1IhbZ8VTwF3pBW8bEE8EL4RvCR.hsnJn6bIHwLFVLiW6kRp_ioFfoBFSx2M2cYVU4.IYtia5sjE vDZSfzmJLqaz73ci_24jfjtEkL5U.qCOAGPljSvxkzipho53GQ3dHLl5t13P0O8c8kL5TGBpX5pr a_4W3iFPptKMrfA6s53m95UpvjTudjfq5t4OFa2Jt0Fp9FcBJb_nAWwM5IM_Vx2JN7Z1uYUTRIL4 ZYLv_jmv07daBMECjwunYnfmYLJYCaU0yAx8Ug1RwsZj_jRQYg0Dd10nz7DzrAOcjOpwd2PTbMjO zv0E3OPFpMCSIz8Omt6Z_._2HcJ16bH.TwGkuoV1AyEjVOQ22tecc6_ziW0fiVnwFcHFuvQOaA9K pN2LFbenopwCDFh43iVMguXVtIsGrbYqLa625R1OJ3HCqQ2HMSzRkZ6H8yu1_s.10LklHRnPEwXt pmZ5P.gj_NWhj1SYmmXgxlTqDKV1b0RVvpCO8bi5u4T9jaJTSHJE7wGugnWg- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:40:34 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp413.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 3d2ea789de6b345569f1c9b3872b02c3; Tue, 09 Apr 2019 21:40:12 +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 Subject: [PATCH 13/59] LSM: Use lsm_export in the secctx_to_secid hooks Date: Tue, 9 Apr 2019 14:39:00 -0700 Message-Id: <20190409213946.1667-14-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 11ace5c923bd..af0bcdf8fcfe 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1327,8 +1327,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: @@ -1674,7 +1674,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 Tue Apr 9 21:39: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: 10892559 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 DF37D17EF for ; Tue, 9 Apr 2019 21:41:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D266528862 for ; Tue, 9 Apr 2019 21:41:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C709428885; Tue, 9 Apr 2019 21:41:10 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 2F1952887B for ; Tue, 9 Apr 2019 21:41:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726936AbfDIVlJ (ORCPT ); Tue, 9 Apr 2019 17:41:09 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:39646 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726842AbfDIVlF (ORCPT ); Tue, 9 Apr 2019 17:41:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846063; bh=kBs6xavdKLksOJrpeyZAKYy1l7B4qvl4+o1ibk1YtLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=R/3rvCBwmy3yrX5Q2SXyG4GIUoj49IChQBKEDjZqRRkS0E3q5AGNo6tgblLMCfkTNCYVtBJSSokeF1OvpdKQbcNwf8+vFYxihDDNvP+CoHIA50wwD9bP5vcUosVY4MQtkIzVxO1flKE5OOMe+lNvtG7gd8DsiVnlH2Bb9SNUeTbLpqKKUFa1cJTwX3l7mmDCuv3Zm9BXPHLnlqfGn6qWBDP6twE6h/QGyWQgpj6kPLXJqFJAp2GhtYnKlwBrkhz8QUXTNv9szXCqXR4EDSjVgGzGbO6QHnTO3KLe9FpCi5BtpXf6jlZW2fBtUlP56K6hiuD9NRI6VKXgfFriG5bQsw== X-YMail-OSG: qEfr638VM1lrkmfc6O1ZBMP2nBCigaXX9bhu6HoLJ4QWmx2W.e1AULM9CohPrdA 4LZt3W_bU0YPnGjU.KdvpkwXN1hnfrjBqGOK5LYcP3BORIw1TfZmUxJbUbxOXa5jjl_DSHjHsKKk gsUpZeCpKusIlbaPo9XRDunXzeBClgjK8oooy0Nt004xHaSBX_ua_t4Z1cHLzjbob1TvL9kNQwfB Uyp4pK6lelcEX7F06RIBpWls8hhz2QXhohRygjj1AHrzjJZGkMkrYfdcTLy35GmAEl80Iu7kG98a FtnxHHBApUMpVYm4TBHof3yvUaSDFq4CvTuH5GtfNo6mwWsK29YSnHsrr0Ve3WnfREAUBo4cJ8ED uq_0UjnIZYT57FqMI8plwpOVn4ow8URg0q2YC1YGnzPC7q3lYV8C232zR57nOVVtMlGRCLYqVzLi iMS3KbQ4fO7jDWGPl.DnWTZrU0ozeQlyIkDJ7c0dZST8nXnkrSbzvBHMxugyQqz7hz2UWonmaNwI sKCgOeCnLIsqfNkMOTQCZZRk5bQ_2U6rFIBmKwft5kQIV2aJM2dIXZ7Cel6FVxULIVWKIARBLzBZ OYLmscAMYc_JUMpxo4xfl8BbKVz.iW18MJbMtmcUWCJlLd2YCc2XIkXJcQ3A9wEPtgT9x9G9RpYj bf86byUal9zvDPx.Pe4iLEwATBB.tivlwFvvEl14TC8iolqVLuc10magpI6JBDKHFs.NpAkPKlg9 TqvyRU.X3sp2Nq2LP2Du03h2lSylrhl6S4LbQ9.eQftDJ6sDyKC6N.vdphJqf5c674GC4JfJi.K4 Mwqp.fOugd1OCwSmrQzRtZgfBzaOFIdSXisgDpgALFZI2cH44VrLodlXPU9ugdrPdSPH8g_1ZSPW 6ovkF4ZMnTqmqPxL2_UCRvNuS6w43Hdz.iRzkdhCARIWiDA6oSTcmtOchc3wi007rksh69hA7NV2 OVsXVjFupIf7dPPPxjz0TG12iloxsx8UWN5JOKo6F4R00d1NZJaYi2Hwd8XtjaDfShtZd5RHO793 uSBzNg7cCJ1wVyNvu_nvjg2JmNETcwu6w4ze7hWqyqYJlS4knNtqWXiStbTfBgZSjK.Kne0F6Phu WSiadNp4JGWx0nnNIz6KfGrwdLD0aiTCn43keVXuxa_AIMOSZtD_UZ36usVA- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:03 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp413.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 3d2ea789de6b345569f1c9b3872b02c3; Tue, 09 Apr 2019 21:40:12 +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 Subject: [PATCH 14/59] LSM: Use lsm_export in security_audit_rule_match Date: Tue, 9 Apr 2019 14:39:01 -0700 Message-Id: <20190409213946.1667-15-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10892575 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 A9C9613B5 for ; Tue, 9 Apr 2019 21:41:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E154285C6 for ; Tue, 9 Apr 2019 21:41:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9289228952; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 187BB2887B for ; Tue, 9 Apr 2019 21:41:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726930AbfDIVlM (ORCPT ); Tue, 9 Apr 2019 17:41:12 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:39027 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726906AbfDIVlG (ORCPT ); Tue, 9 Apr 2019 17:41:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846063; bh=1W3uUkvFiV/hG0OeWxySGoGDdIhr1Nn/Tz9IT5pFX0c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=SuNmFK6g084lWQL1MHF4HH79/GKL1Sq5elX32q0FBB0eDQ5TyMEQFpi8UGFCXCIfWSM3nNbq6Yr0j+q/HwLuw32CvcWJC3gg+XLSxAuaaqrAoEvqojwpDt+3p4Wueqxqe9HU89b0d6BxzBqFinQtee9BtZj31f7G22MBC8L1r6yp9c7nLt55qzfKDYDbtDfOIkpZzHiJSGqPq8DtseNmSQ+DsQW2tWIbaqHKPf4EYnkMjB7bn0jLmRtFKtrUCEAW75uSRCFe4gWtgsD+J9DwhHUvV05ZIMAjviVm64CUdOwZhSNecsEJFE1r5WmdkrDm8pC6HRawhWAlFF85vabW1Q== X-YMail-OSG: LYqTMFQVM1nxh7.B2VmQnw68Pr0Tl8eSz8QHIzqI.0Lxq0BzwDIU1rigydef4oa jhz6q2G_iUqeaBeDAJt0vh8uzMsIALQ.xziBuS2J0e2xbaJU_050LX5H1ui3VGTSGxQ_ajikWBTq VeVX8F3cGJPUPUtGryO3TqABFDrgVIg5UoNVIWViA1P1NYg3BbgxbfBfAuZYwStC.9zDZ4nxGLGG Joy2uTgVVaERklZVr1xod.EyUcZSds94lxcM7YRUelu02a6cpABZLznCVCkdWsmYEr_s7ZpvkRdS 3720e8m5l7o_9BSELTKrYct3ZwBgy8dpOzjZvTm16uPrfcYoRVVlxw.mtPSxdDaxEJTac43oUsaW WMpwHdZRe4NbsB4HyIMllhXaMvlsvtJKkJotqZ3.7OZUuBCMFSm6rkugo5hyNGIz2nwfqGyzoDSV uvo.08zn0c_EoFl7OOjwNeYJ6zLJthbrsQmI6Y8_E6tkn7EacuwB1MwNR.Jilif.qm_58tM8EtdO ykzUb1HK0x99P0wMBGp4.rxn9yYCLUpfsWKXKdUP_MmgqeHcqxdAf5tPLBfOobbFUy1_AApq5E40 thMoO7Ms850L3NiUGR.s_PYzmxEhWH_2K4dUbFLgRv6qj9r4h2Yx_4_qVVusUgBNBA6493cwjVAC 9HmYtNKltjG1y0qdRKpNM5k0SKZZSZs2rWi4q_g9snKcLZz3WSZHNEJAwZUE6GkDKTPk7tb6JgH8 kOc19AEOc0F.ky6fmU6JGX5TIgnv5C9yM8RHgDOoSRVRr1r.SF.eyUicb334GBbiNaL9JvoH_SVw Pl0UrGHgrxdUEKsSB7ZBwtZkQytfAuIVI1Qu8cqI5WAZK5eiVSFDiwM1Ope6AZCj5mWO3XxGQsCX uv82aQFTUMJpQ3kSQAbw48gUnp9Ys5Hg2RxK.zRq8ar13Ge7DYgYF.Nv3Ki4ssdqxaOw70JYCv3S tTef3dxdz0a0EC0U8iWNBLO.AmA4.mU.0u4V3MKG9Sg_6u4ATGqO18GTEPkz_mOfErJ0du4yFHV6 yZcmqUY060iq6Vx9xZj40TwpA2xXtDaT9v93W1dpZmo7OfHSOx78CrV0YmFSLB8qj8GsW6XM3zMb ijNwv8uEG_WcrsGhJN0fXXZXA_yG1nwb0rkt1pL3oTM5jXDNvrymiiy4Hu3Q- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:03 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp425.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d8fc391abae2ed5c1368bb3c988d9ffd; Tue, 09 Apr 2019 21:40:18 +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 Subject: [PATCH 15/59] LSM: Use lsm_export in security_kernel_act_as Date: Tue, 9 Apr 2019 14:39:02 -0700 Message-Id: <20190409213946.1667-16-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 ddd45bb74887..023f422eefd6 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 Tue Apr 9 21:39:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10892669 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 5EA56186D for ; Tue, 9 Apr 2019 21:41:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51B1228857 for ; Tue, 9 Apr 2019 21:41:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4617328862; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 CB80828892 for ; Tue, 9 Apr 2019 21:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727070AbfDIVls (ORCPT ); Tue, 9 Apr 2019 17:41:48 -0400 Received: from sonic304-28.consmr.mail.ne1.yahoo.com ([66.163.191.154]:42528 "EHLO sonic304-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727084AbfDIVlp (ORCPT ); Tue, 9 Apr 2019 17:41:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846093; bh=wTEQTvklkThW7Dll4nUn/vb0sTDbloo0pZigu96CHzg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=etZPwlRLz48pcVAHb/WMGYP9Ji7XI8t/SBHO/bT7puS4qioQG/ahpPXTWkAw5ZbJFDhRXH/PZ6mK4ckSGGuR7XgNOrvcSR3KyIogHzPNhD31/he0p3x4eku42NEUhH8BfVXfeukB4J9Y1jvxb/0yLVip24Q1B/MFu2KeboHkLWPFIAHzFWnIAfBkO/rnxKcQ4hy2ymt2Xh5DSfk51dfsADC0GT2fQfusmiVLNfXZJA3IUXWg4I/Cf7TREK27MrNZtYdV7btoPnqlybYjidZDqP5ld6xTzh02/avInA3D5yJFU6A4L9dFlbnP28RTjenNn3aDG/5j8ZVrynf5tV5B/Q== X-YMail-OSG: X6ZAkZkVM1lM3.Qk5hX00OPjy2X37_62mrHMGeZMw5m88iaqYVGKM5d0_M_KUUO JFDS5QoBJGn7r2I1glrUOigM7.tOTP9JD.TlpGdXUm76WWRChnRLxNTC1HhEEEY65N5aDBShw8X8 bNXCRiWz.I_oA6jThi3WsdkAU6cemFWEyc0QW3DbrUThbkJ5eKq6nchs_wLU6xJTNSUZ8prj9WpE zoEeizZiGdkUzTayh1NUGuL3GQEogX5AxOtWHNXnbiOfUBj6yggh9zVW_NTcdrX1I9JHBeAX38aN Rl0fNe73sdThOTTxZV0IwsqQeY7GAgBq_5U2QKoT0kxc7uncMMkFAwZ.1OnJi_Agn849i8CS8n3C TFPDPc.0b5CXf9g4mivGJZ6aJmVSP1jZHnSsg_UBYlR3Ii0OxcblU9ASgG4eZBd4McPtJmyMKrHS 7IRdPDXBGyREwUmfjUxlETB2l.YWpLia2SUNUrl7m5WXygk9bGRiN3cu4z.npeWAr0Txn_47DTbg _Hp_RL0cLtq.3RSWE5TDHqlrDIp9IwSeHcIoQZ4m6LLbxgj3joe8qDeE5i1YjFwrgjNjfr4cilkf EU.Jak14axZXrGG0WB6ovBiUOebEVE3coSke6gq0B.AHa_qtcddDET4BP9pljtygKup2xsEzEAN4 .1jUx5O4GawoXhkl5NVfD9iDnQwZ5d7umVcm5KjNVsNqERTpn7b8IO2EAo.gQWM29gmTDKZxnfh0 VctO5ECRYyy5bfuYAAPGSl0Nllf4Srb98w6s0tZHmmQiIAYxCRNs0aNTvzpE2AvP_bMpGhrVVrin EbZnfGIdfkAZFnFvYgEmA2kvajiplHi6hG0K.ARL_I_SQ4mRfef9mS97tYtOznkpsH93Opde2BMu LFcjWFfNdu7lkWwR.V.NDsFUW.h3DTHqGQyB4mZCCcuYktUsW3FkzAX7H_9qmM.Ci4ubJd3XG_op NnUveWioY.j0z6SRT1g3lhRnNlBAZtQeDyJ2DdVqSDo.28PPHKEexFDP.NgNCKBDtoiOYTaASbbO erc.drmScJlga3FpH_g715KUSgiK0vA4QRJ2rTPvjjutIVOVmOO13sl1tmqkB8SfqtWdTB5DCrtZ T7o7kj7imHpiscGNnjsYWMME_tdIeG1udiTHnOfzr3lKK4Nteh_VtbiSFSmQ- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:33 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp425.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d8fc391abae2ed5c1368bb3c988d9ffd; Tue, 09 Apr 2019 21:40:19 +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 Subject: [PATCH 16/59] LSM: Use lsm_export in security_socket_getpeersec_dgram Date: Tue, 9 Apr 2019 14:39:03 -0700 Message-Id: <20190409213946.1667-17-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892511 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 D2C07186D for ; Tue, 9 Apr 2019 21:40:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C621928885 for ; Tue, 9 Apr 2019 21:40:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA8212897E; Tue, 9 Apr 2019 21:40: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 03F4328885 for ; Tue, 9 Apr 2019 21:40:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726712AbfDIVkh (ORCPT ); Tue, 9 Apr 2019 17:40:37 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:45451 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726680AbfDIVkf (ORCPT ); Tue, 9 Apr 2019 17:40:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846034; bh=nhyQ5HEMViXMwzj11P6PbXR0lPC7xmZwGngBq91che4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=RYM/YZTVP2CUe9PdTwmWc0xz16rtXHOTDxjrrrRXaQaCpegPXbefTFWwdZ2OpjoDcVkoyGM7dto7cND78XeZi/N+vaYA6cTL67o/SIwPaqqM/bGzGwEuYXa/q3Q1O9LIoOmiZDokUEppFL0+XN8qjqNLi2SV88Xo9w77sE8K+WEtcnigraVCy04XX652aP+4PyRLaPtOkHe9nrz8mI2yjlTbyYz/FhegGNaWRlCnOYmrOA8ZHO7MzqQAtqTDGTZnw2e+ReJ+7ipA5FR25zmuDirptFy08lnGSYarZ0a0nLXhiZeAOKO7jVQMTEb2DNaXsEyjVtfl5MIG382obcJ4AA== X-YMail-OSG: HpMg8KcVM1l4JpgPyp97MBeZK.a55Kkbz4bZ6L2BoIWqMaTvXo3t1Y9mVvUe7wf 1bPbubdxvZ_RW0zDBZroxj.Ets.k1GGpNy8ZvPHVpwJLoyYHXYBQEpPOi3mKRwJ62CEY._gjx7z. JT7tmy_tpTrPaKkPbXz3TH7e_vx7SkhJ3pbbsKcE2vuNTPJWdZtiS89SlkYzpMGuVqc7U48D1aH5 kQ3tkt18VHAOh3mQVc92UZ7j7ooY_ItTgPCrsCZaKR_JDZ.a8mqBYNxS2nYGGOAAvlbQvEtpyRk6 7hl.EaxnxXPiwj5q6r6D2l5d5gGcGdY_C7DB5D0aHo9TNfn48ylPcPevRkJ5fGMRs2Tp630hyjN. KiV2Qod7UC7gkAfR2T_tUCG.jyjUUShiTkhZE9BozFRMWkM7Ir1JYd2QoV0EFCVit4BxSGqiVUrQ 3Jtjgk7TUcffEvxun.j8ef7W..b7ebPPjDQZ4Xastb.2.Ztm0fiDR35WJE.gOr5XPS2fczud.6IN FqMnOm8o2Q0i12fo2VGBxM214Qe8cZezd35TGpqsM553DUkbM2muHA.0z0bivk72fVWoVtaR3tY5 PTtJdXefA6MOgN7mLd8WUyXAk.wxnauJl8HMj7GpL3Z26RmgjzOGiN_zn5yyFugbAtk4BvXypAyp tHxljElupoV3HiZWJd71QiTdMihK5vY9nLM2hcdpNcz3tNh1nZZJpwOP5WxWsYCOgOu0zXmVnkMf Si_w0Q0g8l5mOpOEAV.JiG6cq4svRwDMX8yCHh40ch64qt1cONnYKUdkQmREAwk0O8Tbc5uqsLy8 dnzOrF_yqCXJu2kKoveN_3zvo8vm8fmEaap517dpNXO0UJSwjWZtGIry_j8NXkdeXMWasCUM7PXU k_Y9bzh1aH6ujk9d2QJs4ggfDIFTDZtBDNE_NnXeA9ToE01BAoeZV04w3iErEhj8m4A2ShPfgXSw IGPMVu8e.je_9UGq9FO.v66RK_acA3HkoZpiSygYvTkpTwyVr_q8VCDOTFWhxHmkFcYaVj1B9WkA 7pWNRU7gW_0xYbuInlX5xHdYKTX6ZDcyoaTqZV2YDm8sw.2kCCOGEE4ekQ0qInUvHdVjKLAJOaxG _6vKe9OzzMXjaXy5zDuCxMlfeBaRDFZczk2K8Zb4atugVepv9bOnB6PhsLzbHJcC.iZ4oJv_e1A- - Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:40:34 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp425.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d8fc391abae2ed5c1368bb3c988d9ffd; Tue, 09 Apr 2019 21:40:19 +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 Subject: [PATCH 17/59] LSM: Use lsm_export in security_secctx_to_secid Date: Tue, 9 Apr 2019 14:39:04 -0700 Message-Id: <20190409213946.1667-18-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892555 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 6477F13B5 for ; Tue, 9 Apr 2019 21:41:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 566E4285C6 for ; Tue, 9 Apr 2019 21:41:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A88328862; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 4081628857 for ; Tue, 9 Apr 2019 21:41:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726926AbfDIVlH (ORCPT ); Tue, 9 Apr 2019 17:41:07 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:45420 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726872AbfDIVlG (ORCPT ); Tue, 9 Apr 2019 17:41:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846063; bh=7li7tkNnxiLkHtu/0oyIewmS2h9OYS5xrTRq2nlRU0I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=Pm7LlBwHb1oY4zRHruFZOGxChC4c/ZC0aCeoSIEn7G815sILWAz0E9fJoFAChD33gf2Vtgk3H/GRqhThy+lXpwglVQAvNduE6Y/K6QyFtT8aECtlx3cNxpRV76RgpA22OUzUJCtsinVQczWcu7Hn11KMKFqeoLkaREFZ3aiRjkt0w7zQH33W3L0VNi9od0L4gvw+UHKYYQYE/fvaozNGsb5RMcl8dhjZVfeVi/OTw0L0CpzbWAIUrbaOGKTiZpt853YLcG8a1V/rp6CBh6b/EndeatPw40CGk0MRqyTkpccQcD+43SRpQpYDC/13g3tHxL2b5hiD6eFsT2E+okxPFw== X-YMail-OSG: ezjdBf8VM1kNDJ.t8uovO6cwmtu1yZB1ZxxHTDqX506NI7yG2MfcvgDioNM78zK fUa62NlA02874OhlqvrZh9TVQXgilO_.nPjL5D_UM_FYE8p8_7lpaG_.V5irIIPmI0RP1FpMeeYP Z9ZonH3KCmjSFxali7UyP.es6IknEgxxbiIQfp3uyspvJv21zB_XV2y8Eiv2ucuwteu8NcZ5UpCq fN6AXpIOwZuISCry6nVTBikhhVwrHEd_zLtIFgg9uDIi3sito2sZO7EcqvSNv3D63duTPjhKznne yCnILy6JToUMhSKsqvb1T3xcbR97rUa7QJAp7fSozPmLMxdS03oMiEq1xqE0rqijk.MCLWL3I3yI 06i3RuZf7QmY0tUHutZogL7FSNZ7WSMjo4usoUCWDDQI1LW5mHPLgI6DofL8UnXLOxYFimvZJUCn 1HBVSh52wKrsLSRrAzN.tn09OdLfEGKbcQ6xlm4gyYBo9lwfCVIOg3NrCgEwyXJ.riyjK81lvda_ vx4zoc9ph2ovaD2rCg572oX84IPhXWYq0i2vs168yBfc_h3VuOo4wypNXu.IrvO_wk6uaDvE1Lkm F4ehLD2B3xUby5eNAOG_Vbro6bpGg9I_ArnabBeRh6ReOPv_fCBSMyWUIuHPMYNJXQ7GD8cb4Qcw ugaK2mZ_QKp.1yiFcYguf0Jm.3chkMa4Pd2rHcufhdDKbafta0kCkYpFTaE.FZA5wuNZXrhtwanV 5qqzKhguCO23CU1gF.HUdUuvLXOOxxk2aoelF2w1R026qRVLYRGSGO8s3n0Bo8DYY5W2Lx0X9jhs pMl4_Mjo1SHqayUQE4VRCjWpDNpxk8__tSDhSXrpBHtNi6k6yPzhhiyWbkZhLKS6m8Gg.mlyKu.a g.jWnYW8Q2Ce553HJ_SUXyxBPJCHrZ8Zqt4Wli4uow0QpIntGY2E6w4gtuEf21u43SVPBAAFjWcF 378uibd22wXkGce5qVgLaXDjafgGJNCBKXc.LteShPQwutLmnMxt4x8nOWmQr3w2QPIjOjseX2ZF r5PzvALdlF9fICSmtaeMQm8JUJ8n1ZAsdrnE_nsMekYOmVYRWRbPa545BoE5M03nFQtVni45xPHV PiUI7xOsOFaItq7kBk5r92OISJYfQohrWdjzewlaMm0zU8XM_KaY48dl.Vg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:03 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp425.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d8fc391abae2ed5c1368bb3c988d9ffd; Tue, 09 Apr 2019 21:40: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 Subject: [PATCH 18/59] LSM: Use lsm_export in security_secid_to_secctx Date: Tue, 9 Apr 2019 14:39:05 -0700 Message-Id: <20190409213946.1667-19-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892643 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 7E2FD13B5 for ; Tue, 9 Apr 2019 21:41:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7156228862 for ; Tue, 9 Apr 2019 21:41:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 65D162887B; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 2444528892 for ; Tue, 9 Apr 2019 21:41:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727127AbfDIVlm (ORCPT ); Tue, 9 Apr 2019 17:41:42 -0400 Received: from sonic304-28.consmr.mail.ne1.yahoo.com ([66.163.191.154]:38676 "EHLO sonic304-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727069AbfDIVlm (ORCPT ); Tue, 9 Apr 2019 17:41:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846093; bh=affcoRY2PaaUmEgcqS6C9HybTLSyjRteSCEEdycSbI0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=oa/jJREb89TjXV79eluJR5dpbltM7D3c8VX5Xa6x0wNQTUaLFD72c6b4h0jnFI2BpwpEOZQlAh6e8BQ92JPYVLP8jVeDaXKn6qYOvyLqdOCpR/l+YN9z9vFr2nOpqcMAUvDsJQA/jsdykXEVBU7szwkpn7pKvjAdF1lssm9x/1DTQfk7nA1Kq/2+C1xyEX3W2+urYE6MkO8SWdL4dUucFkWhhROMrjlGyCn9vvCRbtzdaAND6st4SCwG7bY374Paze5qGMor9gpsfIxSNDh6PZC10OhPjkOK/E/JLKLWbibxh7ATZgcvkMFQrfNABDjS+B/xjYfPBMvZcWErnq2jEA== X-YMail-OSG: 3G9yRZwVM1k70hb1uLdKllt8nUp9CmO7gqzKcBPeyHyp7uQCbuDJtw80aPxC3H8 LAReeD51Z39bHuOp.m5qQRB6In.ScJUqP1U1_WdPqoKdf_mmyvy2nkdYM011TzInpQD3ab6txgGa xouGgm1ZcWqoABVNxerr2RHdbLTcxTBgtF2bwFSyJipGMPFCDRFDS9OkcqOJeUPLplpV9pxo2C6T Dk1Qo2ZuJ8pmnhRlcXEJ2Cb9Ox7i9.PEE2D1RXY4NXtwFWTctPNRY5towJZ0lOOTnlmgEDz66W81 _Z8pXQqc7a2Rwn40wzpxPlskkw.W8MQlxa4_h52lFOMMe3yp475L6hYRs6u53VIQwOnA_fZtwsm0 LcHkrWzbDEpsRDsOP_Lfrq1bbEoM2g4L5r1issw_6Isj.e.1hmOkqijISMthgQz9CRvSs20MVJdf VH3vdop5Wxpq48heH48x9HhTodYWLMAkDSSAFGbzygoeS_x_W_Hu.oH3qAIea2Qak.oSlCfe3wNW Cpm0cTEZ79oiCptGhVtpDmIJBW0rMCDSRGZPAHwU4eE0m1Xm89ePHXF7BCblzFNrqT0Vi371Tdd_ KFZWOs8dSs7ooP8NVBiOftdah56wUm8WwoYoaEtbKcnF7_oCaPBYm1C1xSrhOsfDcIaDsSbmo8fm 3kRmSWTDxe906rAtfikNZkSQPjdWi5NvIl0UA1o4r3rweZ4jsZrSKV2Fb94dZDUPQkzZbJtDhQa5 VAvoMwIFJ59MxWUUO8tOnBhL01f3clZSZownbygonDL5cVmkEyhDvzALyUrKmctgSsYJLbbxcjzg C7UpMfNu9fJSLP06Q5z87_jAtHGY_JaoSbs88UqXNORz9QS3B5cwnOHcoS4FfBENsru5k1jDX_Y6 pizwDEdH7qnV39eizN9ZhqtUjwkuC163fVaUbwsELleGZ5AN4c14IEJ36Gr4IyLuFfRsfoKDOyUu EG4U5cxUI4LxeeH0puwkiwbqySpgKUebUrVOg3FNyWQlf4flMIWasr8bMKTxoAx8wiSYWv0hAHgv WLCfhAINdkgfx5UyoZJEnckBLsK6IGRCGu7nNpYEtnRT6EXMfmWrZxYbvlmC70HWi28vrkSVxkqh GITY2PqVUyFWmTMBkdpabFp5azQK2xWL6.6XY8Ou.6uA7evD3_C7TIG53TV_I Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:33 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp425.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d8fc391abae2ed5c1368bb3c988d9ffd; Tue, 09 Apr 2019 21:40: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 Subject: [PATCH 19/59] LSM: Use lsm_export in security_ipc_getsecid Date: Tue, 9 Apr 2019 14:39:06 -0700 Message-Id: <20190409213946.1667-20-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892585 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 E3DF418B7 for ; Tue, 9 Apr 2019 21:41:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D45E028857 for ; Tue, 9 Apr 2019 21:41:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C909D2887B; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 187D328857 for ; Tue, 9 Apr 2019 21:41:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726906AbfDIVlN (ORCPT ); Tue, 9 Apr 2019 17:41:13 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:33134 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726805AbfDIVlG (ORCPT ); Tue, 9 Apr 2019 17:41:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846063; bh=rnYFo5ZRZDk+OWS44zRZyocobFLx6h6kqTHu/9Enlaw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=h9AyZ8Zppa/814olq0RKxbkCjs0141oz//uxDhXvoF2XqgPQ4ZcLAomSfjFRUqiHAbdjAAEPhanEu10kY888eB5CTzVmn5gYadRY+FnTZ9z7SPRoJC5i/MCQPfm2sqb9+T/Y0L5voE19XswTpucfaz46/zQDuh/39XyCoI/OSfQu0770hhcBzyh9iqaYbPmuoLQw9EEr4db+lZS6AISLvD9PNGOAjAf68Y+Gm5qAZ1oBRXS0kgJnPnSfshTRzYGyZTMjW1ImsVC00xQwkSrmuUSgjZDJWP61t0gX6PACXLf0bGt2dPbXmPdOI0RfresF48HzFKAnq0oF+qjYiU7eRg== X-YMail-OSG: Vi49t8sVM1kgw3wNNQconhNgOCeD9m8hP1HaIQvBT1rBQRcZ1qhMpnYL2WCVm_s eBDI6F20jjRLbgA9F.l6ZqoiU3TW.OpN_fHr5D.K7O2FShxmqTdKy.NfRBwRopNQTjq7PaASa_2I 47Hj1HHMRXiF0aceu_.wGZZn5szoIFdIwX9_C5FeqLwlgxbaHwds7LAGbgSaC2t79aB3RQX07JhU JNzcfitoxnU2wAEt4lkwlaDq79yKIdYLs7h2o2d5zyIXmJZHsmG6PfcLNYbuyBneatKYme4TQiw2 IYmM.v308hhNKXCPQQ1Eg8gFhn9xOug0ex4SsU.0IcZ1IrQEOE6CqavCmMNzc9EtSPI.M7ZOco7N xZt3N4ekBpSmMmkpdhHfoi2bzpXXOT.j6.ralKYUph_xosE9QMEkcJy46ESCulTWlKzznU7q_vRG DMgPXyuNL_HImGY2Wh417JNE.FMWei63H46TrNebGSU4aS5.nmQmPysxkI.F_x_CivTIE2hZ4Omb inmWel3gZ.08BB0kTpG1flWf3iKvl3NQaA4Yl0IlbaH5c3OkEcocdVHYL9KscKeTW1oWIYkjTgaW SHQcXo6g2p9EQ7p1_ifn.nImVuZgxNzE.FkeELgPP2IqU94g8i.4I4yrcY9ZEAJWjBsoitMVFGqc 96fe6L.Svi7GDRN0j5lNP62CN6qwQLjNpo.7rN7wg0XdQ8bGqnbpzni4jU4xgMf0NAjCuIDt_cEH FK.O39DjyySXm9Fym7s6HZ9pp_hVW6pQ6zdb8Y3y46FOmYHL8_h6tfdKwvnhW.c7tgRhfub3YyhW g2a_l4DhXE7Hmq3QWujbqUw8tFNMuNwWdKxEwAjeagDMkRV2OeRYN4tUrTZ26JJCImG3BxQ2Dvqh 1KufrALFQwVDULm.9hqVeiSAnSBqccBjkfoorDVoSsQZPdARx2KV8mGqoKjV8.5IrOhlQxrbzeQS ydHKCq9v2TjvDXq0HkFnf6WM5XnMXOZBPg3pzAQl1eIhodDDDi2OK74SEC8Wi.RgPbuVN7_14fxF YSTKMeqywECzCpKMk35KXlllECtPf.UjWkpyKUBK94.kXJT4FkWflQp91olWCPEe7IMoVzH3FHSO pogNCay77WDUPC_XE66LIRH3tACM9IFGxg0YY70YDNvWxJwdQwnDgaSZgBr2KGw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:03 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp422.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 9d24739551c480912ea4720c6639d78e; Tue, 09 Apr 2019 21:40:27 +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 Subject: [PATCH 20/59] LSM: Use lsm_export in security_task_getsecid Date: Tue, 9 Apr 2019 14:39:07 -0700 Message-Id: <20190409213946.1667-21-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892657 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 E78BE1805 for ; Tue, 9 Apr 2019 21:41:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9C8D285C6 for ; Tue, 9 Apr 2019 21:41:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD9EC28885; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 54B22285C6 for ; Tue, 9 Apr 2019 21:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727138AbfDIVlp (ORCPT ); Tue, 9 Apr 2019 17:41:45 -0400 Received: from sonic304-28.consmr.mail.ne1.yahoo.com ([66.163.191.154]:40297 "EHLO sonic304-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727082AbfDIVlo (ORCPT ); Tue, 9 Apr 2019 17:41:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846093; bh=GPvWJDPXSClM26o50qIJxfLTG9C4Dy1cxsnhyj+//zw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=V/UJdw59gXDfc6Yj/Ci33QbBWL/LMCYf2JTkLk3vGZCOHTxroKs3P+C2weHqXJF/0tvS9nvMkNJUnkOtzj3RvzIQSwrVt0PwMRIYwznH5i0bMMs7FYh51ryoYsfYCy4FCeI3hXyrT6H91vAeerOwgI1g2YrnBsM6Fds8L17Uysi+wsEaNkfF5EUrRDSesHR68Tx5uURypx1Ity6iedJrlurcTPTs0kMf5pxMY1GJu5ZYUs5OQnUi4/AUbvbKtl1CmVhMR0fuMPFjsfX3kyqyu0noIw0bDa8GjFXBBaTsUt5KoX2k4TZFU7/yK5VEJBeXljJfV12lGI5MFCnERG7saQ== X-YMail-OSG: hYawKZQVM1nlGEzBmLuKKy1kG2lfdYeC9aaWgbJuhuagdvsqNbXHiioSO1m7GwF pcp2eeOvRnVIG44V4l6F.yz9l77g1xk03wDhSGnZ2FAgTI7prEQEHuDRok9w7AT3obBZ1hzs_Oh4 VOrdCEzMcQUYi8RP6ozWjMjF5E54bLrWQBVSzKicjybtTXLz_L0px6oHk7B2uFYNV1CHC0FyMp7m d05VDrJNDYzGkiZvrS37O4SEZsWd3dTZp7wVjsfvIuuS8abMFKDQk9xCAd7q4BDAeJmGRtgdGWJs RCo7FMuajDiA9zgHPhw7l8cWB2QWkTMCu4TpZDdlprPOOCHjKzT7VMWWRu5Zt1xf839BxsSiHe1. Far8CaT3_zh.ckitlz3UONi5P.6Ao.xcxqgBvwVPBgskU8KQwmF0NdQVzS9AVPrlj1bQTO3g7j4x gAGwNiocmNkYyvOdABmn3twHT79t_Vl2PbAhdkCcqFVSTqZ_Et0Y.0EaSQaya89NzV8BwzxwIXhF a6vlGfm2SY5MUYYGpmoWHYvoRZ8EVeLwM6C2XY8.I8p7TtvIyvMWGwlI11lV8Iu8fOGMQ1M1c_lF YSKPjPY70ov2YE0DfPxK9AtKNK2W0mJkAh0aDacsZK7CkuCYlW85tLUvep4y.pdFgFNtVEdFGWQC wKM7eT_gLp.UfqBm1doyepjVd_escbK2ztLsHGPUTWEsqhAkfMklWatHF3joVePZDVia0PpV_tJJ _CIIMcoOJYceBhe05oAEvtPRb1_gSo9_M2CM.EQmNY1UG9Rd9KV_RScfOoIUDH1U7i.MTApfJFSl AWVpfOk0wKTx8i2o10qO23IQd_dU7Ay7CHP1F0HZbzUfGiEcp6zOmRmgIJHg6_pvRoAF2TtTnO3g Nz3U.qcofYt5Y8jFM8g84gMPYnp0_0tie6TU9FgmsTG0_WpNha1KDmF8O3lppDn7lqlOWG.h7pMH I3NJotF7bbK92_tPt7AtTCLN4RpHSfTgDjgK1lvO2Hii1aOolHCsQH4WPxzYVyPnCyokH6kzUbzh XlVFYK84LJ5LgA6rxf.cckKmcgdljzj2Vcdj4gPlzLFuW6H8y03zODraqDWlNQ2bdrwTgcIMaVVk IbNzU0rbt9hmRagr253VPboCumyIjAzd8iJdxEO2wj6bqigKAlEaZj_Ixk1_t5A-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:33 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp422.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 9d24739551c480912ea4720c6639d78e; Tue, 09 Apr 2019 21:40:27 +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 Subject: [PATCH 21/59] LSM: Use lsm_export in security_inode_getsecid Date: Tue, 9 Apr 2019 14:39:08 -0700 Message-Id: <20190409213946.1667-22-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892649 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 69BFF17EF for ; Tue, 9 Apr 2019 21:41:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D4672886B for ; Tue, 9 Apr 2019 21:41:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51B212889C; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 EA05A28885 for ; Tue, 9 Apr 2019 21:41:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727081AbfDIVlo (ORCPT ); Tue, 9 Apr 2019 17:41:44 -0400 Received: from sonic304-28.consmr.mail.ne1.yahoo.com ([66.163.191.154]:46062 "EHLO sonic304-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727078AbfDIVln (ORCPT ); Tue, 9 Apr 2019 17:41:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846093; bh=0JVMKDcgnflVCRGzj1eTsOgE9xKpgnePntpCQbXL9EQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=MrkrEw8pm8ttBm05lrJojST2YyevypLstjvJskacrqg6RowijQCix6X522jYQv+CzyDBldvmXR2heJe6FcuY9BApPDd22esSWwFZiYHDVkmaRtC7pfR5LLHdcoE2nJq/B7Y5qXfoCHvdaJyiMqwUEk/eZXf+0iFePoPoZqPJ8w2mRkBgFH6hYOQyFmc8+qDOmS3qQgpzkg34epyHe6Wx+IfBc2z41w6CbxYMh0Oay27Q49JY1Yk1VKWrT5xxd/pgrBTmwYoiaIwevDHhArZ2ouH2ScEVmHZyBcVPJY6/gyPVQlc/20v83D98g1uDdzPF9RvvZTDgJl4Qdjq7pBOATQ== X-YMail-OSG: 2ArPiaAVM1k.fKMUmDZFpyqx4K54WPCcH9ph144_iuUL5WdmRrABbqhxGv.fE5l BFunaQ0XZFErkWVRFmqgBlledbt5i3xSo4Too5L6VNyUkNWdPlwd66glchzewQvB0Pj8tgK5Sdqm 1rNhggqyOoK0yWtjYIsg_nkf1e3KOJI2Vs7V_Vf2nKychseSQKlRbwBnCFkRjt72R_ib2rLSsHTb llasnSR7DZgFmpTlxA7LoH_Vw3QlQzWgZXCK9Yt9OgUzCuEBptc0BTWLLONfVKjSrowjMnFtvevq B_uFhOzRMD3YsAWnIMwAdV4A8aafm_LTwp550GiYyML.A9PGLSGsfEp2wKYUqH3WPpc_rm0Wk7XQ W3TIF.wXCBKQ__l.cf59irf2tezdJYuMcM6szxqzg_9lkupg_43bQfgWyCuz8i_nJQL6NbTNCPUY uv0nbkUbZlt5XUFE58V1HDzRJOdepekR_i1BvWYQw.WK.Mo3jYGwKU_0N_C74JUh2142cibw1pox MPbTFMUCdetXrEU174v1MIX.usO3x.qgOAcI2DvtarcRm1_JnSSPy86gKrjLFbIWx0xBRhLHubaj NvuvwhRtQketC6_fR5R6_lvbu5StSB1vSFuRkzL_k.Ob_lDEVGkPuw2JGfzXwZjTFiqSwE3NACr. RA4JpJ8qraEL.T1byXjq9qNyQ7VfdhhiIqw_hj.tzA6jCJpkmeebOwpN8iIy6bxdn7p_BA5o7mS6 FjfLeGStLId5wniBuQJTmUeJGC1afTU7mij8HwluOQJV1Z0RrLWAbApgXfF3NLypkb6vxXd6VtMx .4y4KP.tRHIOWnvbFxmN62PCFBO0H_sWBZjJKdJN1kf6paZ.T6XBnb0JRdTGXrK5fxnhkF3CQaX7 Yll_llXqYhUhM.Aj0fyRSBS0phom50AqDqDMpyCeM0Iw7hLLp4.eoURV.wmE4i6ruqlhuii03Ifa HrAP9iMD2Mfi0VC_jo71RVw5DuBan4WfOHUQsvOD9.TIxjNcz13gmGzRbFb.vcpyPEmuozx99F.8 4xtGnf.lXZZ_Rn8Ep_oJnDGzm_2eQEQEwXt53uLtX8iqBpt4oEmfT0i6KE7pqLzN3DFjMT44uB0O 9K9D15C8MCvipGRe4CIP3e_ijPmUxQf_oPwZG_TL7ZPS7wKTrLCEOYPEeLZen4g-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:33 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp422.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 9d24739551c480912ea4720c6639d78e; Tue, 09 Apr 2019 21:40:28 +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 Subject: [PATCH 22/59] LSM: Use lsm_export in security_cred_getsecid Date: Tue, 9 Apr 2019 14:39:09 -0700 Message-Id: <20190409213946.1667-23-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892489 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 3ADDD13B5 for ; Tue, 9 Apr 2019 21:40:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E1AB28857 for ; Tue, 9 Apr 2019 21:40:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22AD92887B; Tue, 9 Apr 2019 21:40:36 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 B3CB228857 for ; Tue, 9 Apr 2019 21:40:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726568AbfDIVkf (ORCPT ); Tue, 9 Apr 2019 17:40:35 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:34408 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726702AbfDIVkf (ORCPT ); Tue, 9 Apr 2019 17:40:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846034; bh=j+cuqymh91xxGIirxxPJDUSMb0L9mw21aX8dKstwmqI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=V4W9Oi8kUs5hD1VBcUYyqFig9ESXqmhTZ1SjiL2jicUYlzN+0go8THjkYZU2oIvWxiqSP35ci6cA2NiUtbCEoEBcszwD0WS11TsyNL8agIuM6oGBANF2qut7XqnnIiAUcPesxMunglCf6wXKIAvmNJ3h21CRrJncqzfCE0Gkil55JloWITyjoIbglIZSjAS75kcTgovtlrwVjERc1IaGhMIIKor4fZchN7YOYU9a1FRGWOz4OvKwaYfyT3vJDvk/miIrAFFKRQ4g0lTzFn+x7dZSWqUOGuwzuww3KAsDUCV4EtAvuUYUtSh8vprb0CKu6iYhIRlDp1GM8lMneGFYeQ== X-YMail-OSG: 1E5fiScVM1mxULQMACrePCWHugLs_0sWpb1PqEYRoZfA8qipgpwFtXpGYuxJzoo VcMcr7SC_5d.bUbbRdlfsOB7rGX8vL.eoY06YM3CpPLwoNLP5ToEWVuKl_I0udNK00xWqXKJFukG GAeeOBZctto5jrorP3FUHXFThGvt5AvEbS7_neclC6Lef0w37yoNR5fnB2tP0NhOj241ZtJ5TFGy HJmgpdlngXLbQEt3l8LHt6CjgGZXcI11f9GNJ8ggvT0hVZFAcuTjJ03CUnem2eldP0FJ5j4WKFSj MaIxZx_dhKKT.yyDeICgx6OCcnO_WIsGOWqk10jJ7LrgLxkCmm9wDT7KoAjRakTf46upobE2CWnq Uqw85Eped31ciNaYoavhIuyfYkSdIqPw503j4VlF6btp3VAUI__kgh5kEs_Rsr.Z0kJgop3IL6nT 5AjGdpkodb4b6BmGvGpKnZqcrO_qMECq9GDLy6QGNXFV4cQAkKsKB3.tPfor3p1WImbg829QbGOE Kgmmf2y59RkRPzJJvhbA0ZgtbRKGTqMMaNgLA943DvCM3tGpg19hBjSskxf9tVUqff3HW4A6uDUX 482jXn.WH9BRH3FoqzjOHa8r2Sg92qT2Ce3ItFUeNUZpi7VpHtNUZ_rx8zqODGUtrWY0f8PcYb9F eL4mO_G1EMhoZZU_bcsF50FSn1vwH0TDGeG7xQmp3RZjuLzCqYWPvaU6lDWCbov_tBMXv70atl5. V0x8LEC2IUDo2pdRCpOlGVB8ckcX30orjxskUF_D72182KfdsLRcb73i46SuB.mU8d1CZwFcWr37 S0VVDQ0v3rOOeG.yA13leZbuhGBTyJRcWKUqmbnJJj5qP8eDshwQ29W93v6SZsgthYM9o7lQvTzD uL.hdSDiPHJuR2nvR6xG5vER6xlW7E8ms1JJnZHjp1maM0oDRJY92Z.Lojp23WLg79hj0R8dBFVs CAB8KzJNaJ05rLq7rBCYqMwULQbjFXJxQwFVaOGxdiAA8RCSOjzphXTe70_wueESNGy0_8bnC_76 6D9r_7oz3S9VPzAcP4TrGSk8O2e9IlTFMDiizFBb8aEi8N9SEbQTXNkL_kFd5zsDWfOve9FcIe0u N7gHMWI9zWWRGM8CbIGNOz9own7g3wcmQ4VqHU5bpFb2wJozpVY2qkrRoYLN3lQ-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:40:34 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp422.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 9d24739551c480912ea4720c6639d78e; Tue, 09 Apr 2019 21:40:28 +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 Subject: [PATCH 23/59] Audit: Change audit_sig_sid to audit_sig_lsm Date: Tue, 9 Apr 2019 14:39:10 -0700 Message-Id: <20190409213946.1667-24-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892499 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 D722213B5 for ; Tue, 9 Apr 2019 21:40:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C88E328857 for ; Tue, 9 Apr 2019 21:40:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCFF728885; Tue, 9 Apr 2019 21:40:38 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 3CB4D28857 for ; Tue, 9 Apr 2019 21:40:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726705AbfDIVkh (ORCPT ); Tue, 9 Apr 2019 17:40:37 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:41064 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726706AbfDIVkf (ORCPT ); Tue, 9 Apr 2019 17:40:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846034; bh=V6rKCyElicKZF/0fKwJbU08oHRiI1KUrOSjj+nGJXW4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=Z2xuumYWxQWcbNzKOpBlMBC9/T4m7npE0afRWO8TGZ4vJWTPUMGddGv8J4cypX0eINbKlTyARU2yRF7H41Ox1AWoKucaCHAwInYtlQiSfZLeGyMJ65/aj5YwjQaIn9WXd/bY57AaYA2fon9a7hPJrpY8ypLlRv9WOtN/RH3N8A8GaO+AY0wfPm0yl/UDERTUAoF1YQjsBzjv6dFJzSi6QMKqDPsE9Qfq8FyDrura0evG542WFz//swfkmNdDKlrAIlQAIFcRPCwX6J8ZRwxbEeJhOf24BtIGT+FzX+hE6GpRwNZyYO5LINXc8qBUNtbPSioOcttplZJhhn3FQlnzTw== X-YMail-OSG: XE0GTJUVM1koJ7q1Pq_7mYY8f.p5dVNo9hKjLdozob8svlibl48xDL8jwstBuP. P82xHpxNuTmXofSmtHwidqMcPAC8nubJOkuWyeL8vDWjjSsGs.D64KS7Y342M2ipDtE7t50B5Hog kldCbQg1CpQwt6IO_FuBXZjRZZ0znXYnKLEPQMLjs6lc9FQ47xBBg6NV_j09pcKkRyKzK5jmOSHw CdXPlYgDzhlLoDDbY3kxCPES9VoaptpnmdBgWCaN0Sb7YXsQSg.Lpulw7yXwWcdW.cneEeP6QSix Apf56if5oDCMZUcjoiDcDSzg3foIQmDf3MTrTuelfjrUe2i8kfwTDFV94Yv.oDlrwUGxYU9CnRlU Ct4zYPpwCwy9T6yvGN_qoKJsN6CFvkVBmu3VgjGhnEvxcqn_r7FbVJzD4T5Hon.lYF7RfO6LI0E9 GW085rafmvElDwkRPYaq0h0lj_C3kDbFs_MHNRauCiOedOCpgdK6_NSx0K0IUgTLBLLa0d1eyyoF Z6iiUUJRXiPev.PcuuB.UUeFAG5azL6nW21d0t1PZJ9ceAOcH_tQpkZOVl58sNCeApPSqgjxXlSk rcgEQMTKrRhX6GZozUYQZMVqKzbG4qW6QcwPM3ZzM6DnGOdfBk76UsKKJCOz..P.PdjikEjXCcDO EfPjnHiV5SYvSgSNH6yT909MoKORfYdJvBiPdXMPb7qcXI_hYaymh1PDjoMzeT7Qk.xfoAUZHe8D wdQ31SMhz2FCnTz7Gb.umQE5k54v5mFhwHc58Y1Iv8YsTeYz0L7jWFQI5NM_wg7SWed8kWsripa0 k9Tr96i0.rSf_7uuYv3WSf58W_JVo6Ii2rQb_KsihZNIOzZIw2v6dewSNR74Owjz2ulDtVeOl08D rvB7CmvxcLikyQWwA26mZnz87j_Fh8TO9mNv86MjZSIkdE1p0yCBc0mvMx7IdyWeaKNDQrbbvoEO AkDVWZ3orJb6nGockfkZVJIm5JJ7ZLNkBGUHl62AgQOVZ16QAClU9qUmp0Xr45mCbD4zwVhLmBU3 WXva3cRKvTRaGBsalVZsb5c7k8jHt6peRs6A7iP.CSQQiIUQpN8PgnNnwDVWWas7jPLiLaPqJNOV EDpHp13UqSUYOaGfsiU1nvUQyB_HX3XQQJb7iRIJy4i17ajPXqLQjh6FfJyXUqw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:40:34 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp422.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 9d24739551c480912ea4720c6639d78e; Tue, 09 Apr 2019 21:40:29 +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 Subject: [PATCH 24/59] Audit: Convert target_sid to an lsm_export structure Date: Tue, 9 Apr 2019 14:39:11 -0700 Message-Id: <20190409213946.1667-25-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892519 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 5FEA913B5 for ; Tue, 9 Apr 2019 21:40:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51C6F28857 for ; Tue, 9 Apr 2019 21:40:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 457F728985; Tue, 9 Apr 2019 21:40: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 CD17B28857 for ; Tue, 9 Apr 2019 21:40:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726591AbfDIVkm (ORCPT ); Tue, 9 Apr 2019 17:40:42 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:40326 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726713AbfDIVkk (ORCPT ); Tue, 9 Apr 2019 17:40:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846039; bh=NLJ9WRLN3mqnoEKmIr7GkqEF3TZIbdXheKniGVooL5g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=hpbb02g1734AJK9hnJdRuVQFKl8mzH2EiVbMg6o+YSmGopivzQma/hOHmaqSSbsdTLwgbCLYaZe3bSGDILAgSWNdFugHHKpE3LWC0YEEuqAobLGix6ihRU/ptju/WXK3dXWnLSnYNwFyV5CRakyFpzwRs8kQWnChYaS9oNWICFESzDAe53XXRwBqyJnuOyMHGKC9zn4T6X1PSBSPMNtz3ILqX5aTAn3xheQJ2ytWZV9tpUqyptx+ZUU0yqiY/9hXBxZ4bbg1EUH2F0DkMwBSsMLiib7GJDjGqS78PJEsdmC2TacfqxxGi8KJZ2HwKMare8fxriSNGUkwxLRGZHaJYg== X-YMail-OSG: rxa44sUVM1kyT3Tg4RitZ3uVZKd17iHqtVBpjw5xVTMMIQCU7VAhIwyzczscjxt Evn1TKzzbRyVVYRH.TpqluY9YFb4L.43tIaePBMluYzHvq1UpZ3eGjEXQ0SQpdnmDY9in.n76c0u lRoh96_XP_e_iYTaXMJ0ctw9pCy46QEPSlK4WoQy5RN9a0nSVhEBkyAWzPVOa0.cr583j4mb0p.K pmQAG9ODM.5DP.AzIF69dauHig1OM6N8_16uCxwPudnpgWnge4qcim3iCbDIPwPX6FSh7iayiORC RsDvbOlCY08Sz1rAXrrY57Xaev39fTrw1J7gTQYvuA_j2LgTVNOBTdIp0uFtUe1u7nBzPO7oHGuW b3kNKAvbYyRnBAQjTfp5eQHiojCUFUgHyWxZbh91ngpiXw.re6AodDmLJJPPXopqSWaJPHWUFTsx xAcn4X0_HiHeRaCBoZ7mOZrQjNAWu5AP9zmiOPeKXtaareZdB.jWA4qOuogmiIq0RfFumO5dBjG6 U.fvSjFF7AhzVs1c.HDfijKllSDMRLIJ_bU5zf.AIwDk7ft5_UhouFkjgR3Czmk2lYk1E8ucQHlP O1Rv7FLPa4.Wv7cExLOnfag9C0Z7yvsGajUZk7UjtOYjE8GP9QsPM0aZuwvEmBIKi61oy.GG3Iol QN0X0whRGf0u2OILGRCW.2e_X5CaiXo9Ml3CWwylxqYxbpdhNtLDkwBBSRg.Fpw34G6d83qfT_2D Ci2r3WtS7mZojNjgKuVICEbpeTw5xUog3TPeSRqUqz.WGgw7edVhxwNEyUl6iLY5YHdMj3kzSFxx JdYWreKpCaU_CU7219lwzBqEgmvTzEt0aPunuG5wcEuKeNHhK6QNuHQ10cOwNrKUe3T1.TxBsLNP Z3euQbRpqcixnLt53Dm8ZIdPFhYsVhOLos8jkM_GWoFSjtTSybgNw97Pmzt2KHQTz3g.lMLyeHUD VNrXpGkAhxvq6tM0Lw4C6ChA4Xce.y6Figx5ZRclzkydPLgVIFI9nplxZf3m55HuXs6FldJh2ADT Rz7DTf881t8l5c98Wjd0yJnzJEv518TG5_jwURLLbD9PhDBt0sSsdsXrBJdpOeD2g0r7kZtdEtVI Fzq3Fzob9UXNqaekOj0QX7uhwrloMGOVZOE3GxQ5cRpXdu9zdrRY9wrqhzisilw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:40:39 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp407.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0f9fc43d6127678694d9e39aed29be56; Tue, 09 Apr 2019 21:40: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 Subject: [PATCH 25/59] Audit: Convert osid to an lsm_export structure Date: Tue, 9 Apr 2019 14:39:12 -0700 Message-Id: <20190409213946.1667-26-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892699 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 0D82918B7 for ; Tue, 9 Apr 2019 21:41:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F423C285C6 for ; Tue, 9 Apr 2019 21:41:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E888728885; Tue, 9 Apr 2019 21:41:54 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 4359D28857 for ; Tue, 9 Apr 2019 21:41:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727113AbfDIVlx (ORCPT ); Tue, 9 Apr 2019 17:41:53 -0400 Received: from sonic304-28.consmr.mail.ne1.yahoo.com ([66.163.191.154]:39976 "EHLO sonic304-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726580AbfDIVlx (ORCPT ); Tue, 9 Apr 2019 17:41:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846093; bh=WdnFJNhqMM887DyLRoNCsL62MRkkEDeoMEYJROIA3Sw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=TfIOBLBDBphrdKHXkR+uY5tz9GUBZKZ0VMYUTWNbQPnawMX/ApM9OooxtQYiM/KE6zhdzcIgQfBed2ojQIdqhsGbErZ9UV44KR/tfV7b0YvP4UhKV2ZLFryBfxqfvIBynjVzQS/8ObpunIIAKJH3ZBnauMFd9Wkqhs9lijnml6wd/A0az+sMNw2eafCVyUCwYKBT/V/OyV1tdgVSPCdydF7YZjkPNVyq0kW0aALgPg6HxIqKRPkgxiS+hJNYYarppSA09tKqat5emqDGiTRMVJbukxCYWym+pOEqs05vFUNPl0JnXixbTWVt2QP1aOt11nt+Nyy3ruMNwJy/bP2Vkg== X-YMail-OSG: YlAK7jsVM1nNluacuBvFp4f5Gv7F2b.oBa1niCqvrN2GYmvip_.2u4fij8IfiPF kTL.fabJ57qNQnCdjy3bu65EYERbPpeJ7ZozVETqaOzUVtHoLoYKDXcDWKY6rRiqZGpvihnhtFGz dhrTh7bGDqI0F9IFgaWb55qaU0eEMQ8ufpcakanPft59UnNLHUw6eDb6Ucw.BxA4.CAZoul8uiGd .hLZdwAMLKvjdf4GDoIqBiBBzkF3ECd3EVMQT4kpQNi7IM0Nim5WF_DkCOVq1gGRC.a5if4AlLtK GvRxkGh_EwyB4z4G9IO5n_mY5sJCuaBgFpZkLmFb6mlE6Dfz7B4Q3aXG6PdAAjEwZP7tL75LQPwo BaiAS0JMiab5I2FujFs_We0MuhasAxAFLlRygSTN6YHbhL.rGJyDkkPe9ZqZftvRPTLnOzL3X2ci 5ITrGhKk7LNuRNlkJFM3.YRKUSa0sNeaCgbMB.ZRmftn4GjSNAi32QEioE6pZTNbjcgv9KRV8cNZ A8V6CJ2eaAFc6cmyviYg2HyDY4QtowPmT2iOhsjhBG3Cu7v.u0dz411d4rX_JaBywJM43NwVTLVm MgyJOevRWHhiMrP2f_F84J8YYt6MVe6AE9JZUPvyPOhTj8DNgmxmlhPt49dZXLlj1cIhg.pIXcir gD9Ebx6X0QORAlfv4C8OH5wLvqO1058Emwgiypd1p8YFfMAVtWWswm1QBqIaPX2po.kv9PuugWYr j5MO2agxMuBUcqJMz6Jjiuik6VEz0NcONL2kQCz1vvXVO5BtNfTYJ3uOtJZDoMgXeWPHjM1kvpS9 3u5Z6jys87O0TogjXPOH.dAX9iYhisiKCjz2oP87XLb_AOtNrIFlft2hFoZ4Jo00EWGzQXhgQet9 VHwWA0ramPKGo_uDLHcRu5WQRISj2TBzIYaERbTkOUPg9476FuoqrlLCdprR8YNJZrbBmzXQumeF husgwjK4GCq8Cw5Rpry6FVgC.LyeH10PRp3oZkpd2899K_BbEXjovyVoaDAOLJofPbwbOVQoX.oq Dbw.QYk6te3We8RclOqfk1Rm4r6UwhxAVs2Qwjig9zzniG9GRT9I8xmlcdlHj7CHAI.BDP_HWEpa zzTRzlR3QbqO6H8mXpyJv5jGX5rUO7u3iuRbCp3xsdNIbo.QSQg0Kd2uLuU6HVg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:33 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp407.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0f9fc43d6127678694d9e39aed29be56; Tue, 09 Apr 2019 21:40: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 Subject: [PATCH 26/59] IMA: Clean out lsm_export scaffolding Date: Tue, 9 Apr 2019 14:39:13 -0700 Message-Id: <20190409213946.1667-27-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892681 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 04D4A1805 for ; Tue, 9 Apr 2019 21:41:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC54728857 for ; Tue, 9 Apr 2019 21:41:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E0FB428862; Tue, 9 Apr 2019 21:41:50 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 7DF2C28857 for ; Tue, 9 Apr 2019 21:41:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727110AbfDIVlt (ORCPT ); Tue, 9 Apr 2019 17:41:49 -0400 Received: from sonic304-28.consmr.mail.ne1.yahoo.com ([66.163.191.154]:33550 "EHLO sonic304-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727112AbfDIVlt (ORCPT ); Tue, 9 Apr 2019 17:41:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846093; bh=W6Zq0mDGK6AXoBDD4bxoIumDend/XN6awxL+92CHmPI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=LnF0/pwEHjgCtzikMnh5MX8EhxGi8c8M1DXloZFbbWY27baN74AzHIrwpj6lfE5tETJBAuapmT7n3Lj210XE5gr1mv7xboiXVKdvzamJWYqCeO1d1LKt5yAWM9UmdFpyrIZXUOdVn84ADSHBXptQJ4dYh7Rd4prBRma/OCx5Bl2gc0K+j+1LwRr2zrVyJhfo+cMeHh7C2Zuh51llV8QM1kW3tIVGseOk3tTrGctA5Z79VtUToQwU5s1WBqujfYVtR4GxywMTQXr2wI3pC8Z711L8UyKOyG5iT/CrxpyDeywZuLs3x5J52mMn8RCcyjMiRkURsExyJMvGnThR2aHAtQ== X-YMail-OSG: zh2CAE8VM1m1QUpYWqnFOU_xkH9A909VR61LxSkzPwMZAsdk8nwRgZLK_ZZke7L IXeUxjJAsr6dEtFnCFH71O3Kwq0Sgw3VRLBehXyqRtHS7kFOXH6IY2g_RtbUcB8UQp1014fLOgCZ IaUDJqM0q1rBRx0Qke94PnZaiAPavkmK3n6cgXmmYeE3p9k_rDwWYMlnSJKWKupgEROCP39PBUBg QTVxPHI6dhBIOd_kz04Z_nLwuZdN2LuMGmDhMwCUg2JiXwmmBHRhgNPh4csjnhPpo1nqBrKqnkSX VNwQXdo1TOQAbR7RwHX9uZ6IvMTMv6qx19.rWQjf48.Xn66HHgbsAuO4wDF7xrB7OKHdF.OCOcfT b2iu4PREZN.BIsGCVdV6toeTzhjsbX9cqSLbbFFjHm1gnfCca5w0tvXHv2x0pct4rFYd220JHeuZ nCKkTiD3CctBi5I2a2cA9fLNJgOMcSawOBkgpqrRmZwhJLLgXBzzlG8NnuvetWFlJke8XzOs.8Qx RKhKR93GWB.2R6kby55xCREm1hNDj30k_BRgWmDFseSDLj6wMnToVG5EYM_ejGEQxUOGKMnwpYtY .5l2JCj2K58hBPpE53TPwV1dxebntyHgC7zGueq9uq0VpQU2xTeVbp1Nua4bSPv2MxrFREXx21hM vXqgIEZKgB9SeRDKAN88btMFC08wjl2sA4jRwzvwpP2j1ivHQD6NayGvAtPONqZvRT2Fbve8ugjp ZXwHlJzsstjS6j2ygQYoFRyv36Vn6iwulL9nRP_MWNQy.QCyKn9bOlylB9mBrN8lmHviyxwIL.8Y O7Pp5fCemiYHy9DmoxsVo5qelVdegqvMvXzJhSqX2iN5.JimY.2YNY4c2zHFVbi1suTvq7iP36Lj f30dH9cZ8zuGl65QbKgn.n3CZgkRIDktHjAbOs.bjgK10.Zp5voYPyOnKKtAZrY7M2j11h8UjumP qw3uxgdLcWBL3RCv2x9NnopcbunjPM97zj8yuoijcTNwpfhVHuBKiClonCfIsDN6ndLLTNZp66LI mhm14._eeVyXs5mdMMIb_JdWdFSIwoWYguK8qXvpEkxfZruZJC9ZBq01ZhWq6vIK7lPqyzZ1sSuw 9cgjq27ek5kNi_LR0OP6ukzTi6iL17u4cvM1k7ANyHXxH8pwFlezePBqP_DsQhw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:33 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp407.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0f9fc43d6127678694d9e39aed29be56; Tue, 09 Apr 2019 21:40: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 Subject: [PATCH 27/59] NET: Store LSM access information in the socket blob for UDS Date: Tue, 9 Apr 2019 14:39:14 -0700 Message-Id: <20190409213946.1667-28-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP UNIX domain socket connections don't have sufficient space in the socket buffer (skb) secmark for more than one Linux security module (LSM) to pass data. Expanding the secmark has been ruled out as an option. Store the necessary data in the socket security blob pointed to by the skb socket. Signed-off-by: Casey Schaufler --- include/linux/security.h | 20 +++++++++++++++++++- net/unix/af_unix.c | 14 ++++++++------ security/security.c | 17 ++++++++++++++++- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index e76d7a9dbe50..c413dcc1905a 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -71,6 +71,7 @@ struct ctl_table; struct audit_krule; struct user_namespace; struct timezone; +struct sk_buff; enum lsm_event { LSM_POLICY_CHANGE, @@ -100,6 +101,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 @@ -143,6 +160,8 @@ static inline void lsm_export_to_all(struct lsm_export *data, u32 secid) LSM_EXPORT_APPARMOR; } +extern struct lsm_export *lsm_export_skb(struct sk_buff *skb); + /* These functions are in security/commoncap.c */ extern int cap_capable(const struct cred *cred, struct user_namespace *ns, int cap, unsigned int opts); @@ -174,7 +193,6 @@ extern int cap_task_setnice(struct task_struct *p, int nice); extern int cap_vm_enough_memory(struct mm_struct *mm, long pages); struct msghdr; -struct sk_buff; struct sock; struct sockaddr; struct socket; diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 4d4107927ba2..afe9c9f1adeb 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -143,21 +143,23 @@ 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)); + struct lsm_export *ble = lsm_export_skb(skb); + + *ble = 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); + struct lsm_export *ble = lsm_export_skb(skb); + + scm->le = *ble; } 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, lsm_export_skb(skb)); } + #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 69983ad68233..015c38c882ba 100644 --- a/security/security.c +++ b/security/security.c @@ -46,7 +46,22 @@ 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; + +/* Socket blobs include infrastructure managed data */ +static struct lsm_blob_sizes blob_sizes __lsm_ro_after_init = { + .lbs_sock = sizeof(struct lsm_export), +}; + +/** + * lsm_export_skb - pointer to the lsm_export associated with the skb + * @skb: the socket buffer + * + * Returns a pointer to the LSM managed data. + */ +struct lsm_export *lsm_export_skb(struct sk_buff *skb) +{ + return skb->sk->sk_security; +} /* Boot-time LSM user choice */ static __initdata const char *chosen_lsm_order; From patchwork Tue Apr 9 21:39: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: 10892597 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 BBEFA186D for ; Tue, 9 Apr 2019 21:41:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE8CF285C6 for ; Tue, 9 Apr 2019 21:41:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A29F32889C; Tue, 9 Apr 2019 21:41:16 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 53C6F2887B for ; Tue, 9 Apr 2019 21:41:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726849AbfDIVlP (ORCPT ); Tue, 9 Apr 2019 17:41:15 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:41610 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726808AbfDIVlF (ORCPT ); Tue, 9 Apr 2019 17:41:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846063; bh=DXZobVlHba7NLExIjhRRZRkmastZlDIkiPrs42J8njM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=gIhL8ezGAimS0SOypVTcuu+w0h4akRQA2zkugJAtJEd9VLg4/wnsPXiPs+nqOh9acQOzNTn5WuZ03piWa0Z3ug8yFqwULG8dGORA0BKE7Or1l4gpCjUr2ZkSHW0Jlus83Ppu9PAhdO6K12jV/Sy1PBEgnQOm9j0A13q2JLQQDRDVPamC/38T1k6FWFSnZJgkfjRjp93HvLtcMsGC/SBP0poULHhHwSe0gny6TsdhQwXqDgDCw4LiMvZ5Lgoit56RUzHDSI4GBvKjkYdBSA8EdhWh964fwT7YDWJ0xJC3enGY0B1RY/fPI4rs8tQM/6bqKf9qba5hVrCY7UxeOphYzA== X-YMail-OSG: dLy3Z7wVM1kwrF3sxuZW9Cv_QZy23tBqj7Ev0q8LNyVeuZ2Os2JDUWspMt1v2xB wJYegWM3uTv9Zqlw..a.YSHAWVbkjO4PEb99rVV9CqUXs9Nw9utiz6wXwIBvzj8AqKk7t0VoGekG RVsv6rpzk8S4CFo3eEHXo6DSKg4K1UEwauUxMWXCRIqcoLcL8W6CRnwZqrcDr_Le8HYqNhnoVfQ8 Je30WqX_HNsSFERLKoqmEIRaqMl.TpSnNsGE2tSaaHyuxhidqcPnlMeV51dCqutVT8NOWCC8VzOp 4XuBZ..x7f6Hpd19swc_4zM1qJfsR4HCN9clOKbyznrf.ZWLxkqT4IMHoN8vVUEDdBmGu9OvhAVn uHXykJBh5sb.22GcJYIbAsALDcvA1shyf3WvQffx1ddLEMl34KAhFrNoJcW7Ulst8SvTAuZwQRlW JnklfnWz9sO5ZwVwxwtTR123Nc6d.QAI3kXYgWOLANN3gqULxbNfXrSV3HH_7yMzxTQFiHTFAUU1 hVfQsLpjJ_pYvA_m9jLlbMstHYnEgxydZD5v1JK0i3_Cu4JoQJktJvTyfo4Qt4b44Qs4N1MbqS.3 rl_gWwOqh2KEi4_Nzz5Hh6L4do2IFxzxMLhus.CZ4ktKyY5_IpVX8ukm4avLRJhbNgkZHVDWD1en i3Od8j8IsX7vyt.xyxMiAytGpU8n3MDweB7Hb8qseW6vqHlfHHDE4KGfeXh7YH8maUz1rrcdSJag KqQcdJ9uE4MLwiWueyD71e.rqCd9wtO_Ha1c53WXqqDPtrLANhTa2l53dETU9QRC7V2Hq4miEgjQ uDzBwqpuActE81JqRitp3LW3tpGimr1whtYp6MEk7Yj6p37.Qet1v7Z9tzcrFNEPe3v5ReDV2QHL Y2OfG7Su1m7ZG8HISdmrfjQROOIRtbx6VG5uFyA0z.1KFc4zY_7HWRCP052R23uPfFwDUxML.0Ok lr6UROB4bxol8FWoGDowOvAXW9He8NthtXP5xzhVD2qCQo9O3em2EE3gKMoiXoSDcP2_yHTsG34g zXvpihlHw4SIPmclLc46GMUpGCSAaXoDrRr9ROmWPBIbkpg5j03WzirFvIq9Bt2BaRxcEC_DehP2 iXAFvoWtKZrAwadh_nPKjWiym6hPu3pyambtCfRHuONCbpwmiHK7R4_22acnVcA-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:03 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp407.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0f9fc43d6127678694d9e39aed29be56; Tue, 09 Apr 2019 21:40: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 Subject: [PATCH 28/59] NET: Remove scaffolding on secmarks Date: Tue, 9 Apr 2019 14:39:15 -0700 Message-Id: <20190409213946.1667-29-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892515 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 33D031805 for ; Tue, 9 Apr 2019 21:40:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 287512897E for ; Tue, 9 Apr 2019 21:40:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D2A828985; Tue, 9 Apr 2019 21:40: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 ACFE82897D for ; Tue, 9 Apr 2019 21:40:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726723AbfDIVkm (ORCPT ); Tue, 9 Apr 2019 17:40:42 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:35621 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726591AbfDIVkk (ORCPT ); Tue, 9 Apr 2019 17:40:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846039; bh=n7o8QGFhmUAYfuuVtS2cjj7dSkuQxOxyGbWYP+SBOLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=UNmtIOMCUt0qtBx7R7oZtgeekVL/I+5gscfFEp6ubf5Zf920ytBIFKti5oXWOyvSduAsZS3aabE2fyfExx//U+ZTw9KTUleoJEKqn34011EUOwF291HmA5RxBsWwlxUWwObk0rpiUb88Yqn6tyG1Q4LDm/1OPf96++yoGI6hHhNKUHXydHMCKcFFUPaGRr6eKc979ozC3vRqBhmi1cc66mBFBECcdp9EkbdH0QZXuhnUcsar8ZtID8LQrPLNZYlI1Kv0G6t2+0UshFZex12uqQMRDCf+9233sNhhSGnkp1fF0Q2chPdJfKIQEhhKGY78bZNoPRbyGnfD7i0yTeDVTg== X-YMail-OSG: klhnJrsVM1mFCnkU0Kls9h.5E2Fia8TasWTMc6Gtx8H6I08ZbPL7wW5u1X8s7SX yeG796lowseN0Y36oBjB4Y9oKEtzFRHASOf.rj1P.Ayw4bKauE9HH1EJOP8pVIbQKJ_56kTIwvjb kSDV0sFmq2lNlO_XpWTUd2BG3xhCbd64BdxQIXMMeL8J88cDzU8R6JJ_gSxTWGjF9yFFyvYmRn6Q mJddrTQftmzp.d6ZbH10y.Q_IRXWu2qaGUGUzQJ7yh7QDmRjvgEysZ6MrUMmqwrvsa3tqxXWKgKm pqv_AATCv9Da78rOUymIZ8ES6uGXd.QUmhALimOxt3jiVa7HiIpsTns9zmLXp.PiWSt56eL0F_07 sdUTJTgpDHGjHb8R5_I99.89mbszBHu27k1qLu8tWjcAUZUi0QIQRf2AFGc4tWUc2kFHBfJHbGG2 OB3TyP8VH09VX0CIdvNkV3QZSS.0qMABgq_dnggujYVEYacdZI9WJvUYR_BFWN0rn.FTckD2SDXq t1VDm.cUc5I05_bxSWFF.lwnz4XjLu5Px0JnhbJLWWNaaSmfYb5cMQlQWgOGsbpxfF90dDRXFLP6 AD.oxCorvUVmhSWhw4LINs3fEKw9D.sYkuPKQ62iyqSlmENqqSIuLrXGJwZKMipBRYYWrK03zd8t OlCbAETOYrvzhQ2ZG5Jil_3EdMQrOZWIVYZ0BB7vt1GIIdbUI_kC5hfAX2j_eWqzHR7n2HXjMOzz ddSMJ1UMwjlktepwWnapQ9UwVv_OGPNmFlxM2xuhXP6Or3gUcWrmbr0GYLsbBoJHaGxXuKWuMybm PC1VUyyspg55lD1rf2dhB2gCwZdHrN4.yskDsE4Mxw1fE7owb8rhmRvroQojtli0Q252oz0EepHo NZW5sGIE_SUq6R_CRcfQM7yEscq4IsRBRxhMx6W4Bd2vJDThrorqqHrDYems3CY7Z7o_9M7t8XyD HYE_jMrb04297ehVpoEC3djNV3vlBG7XzJekgi4YwDR6TN0JtF1x.Ze1mLOYpugbz3lAmXJpPwJd VULRFokAj6mMgNEDnWgoeZXXK24zepF5bjAMMefWCscUQh0.DbrQPk80tWx18tq2r429k6a_tP4K MZ7FQYHFjSlwR8HlTZt1cGPOt8WxO9TPtk.ARRhy2VTG1GWd7dK4aN08ywGTKPw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:40:39 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp407.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0f9fc43d6127678694d9e39aed29be56; Tue, 09 Apr 2019 21:40: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 Subject: [PATCH 29/59] NET: Remove scaffolding on new secmarks Date: Tue, 9 Apr 2019 14:39:16 -0700 Message-Id: <20190409213946.1667-30-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892523 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 9C56C186D for ; Tue, 9 Apr 2019 21:40:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DD8428857 for ; Tue, 9 Apr 2019 21:40:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7AA6A2889C; Tue, 9 Apr 2019 21:40: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 1EC2E2897D for ; Tue, 9 Apr 2019 21:40:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726730AbfDIVkp (ORCPT ); Tue, 9 Apr 2019 17:40:45 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:43146 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726713AbfDIVkp (ORCPT ); Tue, 9 Apr 2019 17:40:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846044; bh=KYlupIPcbLYAYHDyLLLdG0LtZrXeMUYE6GpZUguvURc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=lgxS5vGuums+xUhsjlm8yNCpNC1F9tITlLecE3y5g0g0Add9R4VriKQpkIlnvJVGUSNfaqvfOU0Aob1xiwGMpk4gFPZpqJvLILvM/Fe1QKeJ7bYPklOIx2yqiCOD/FbBmBSMXUs8WOPOLlItrZuasbGUxkvVknlNrZyZ4HVG80F3TD7HQOGDRJFAXJ6PrQXeMbb8zsMKVWrDNSSJUSlvaWlJocdlm8uvogsfBsf+1CoL5Ac+GejczMUyPb5LANGx7XjXLtSrr+AQMspj4FYuEkdEIfsyUOVRglnKMDZZEWp2tMBFI0mqHt7OeBcUlZ391oa5056CVnxAIkWj3PCv2g== X-YMail-OSG: MzTA5XYVM1kZloBqQh6x9S08SaNyyYDbP72IafmDf2sFgDZu2mX57kJzS.qUpnb i9tKzd0aIG7EX5oSJmSVtf1f7DtGBLLifp9HdMD2Hsmjf7jxavWgeA_SGAlyXGXQL85wC_eAFP64 F5lq1CmnLhPeUDVUiLIJVXfaL4XiCVHsMWbkPe72rKTTKDcIkt1jB8IOVWsBTTzFjqu4vbWks5X5 nnMpFxoHasS9UC69AUM3Uzk0dYK00N_3sO6GONd1his2nSuwCWVU9jVK3792.OM2ljglBxF6k8pN Minxupm_PLflQ8XkWTf_P7bHxeZIi2WajhlsSNso7kHYIgacmtfBgCXSKx.jMGRF7hmSY4Bf8M8d gpk0I2M521iGUAutPEQTYtSpedrVCMcyoCgYL2rh2lZk.cW3F1g1kTowdVqq6a67cVhQys.Nfsth FvxWB4OhQb3Ynz7_NhyjnoLeB6C1eR1NOQ2kYHPLFz1O1IT3yo3IMdyu7waH3QxWK_4B6qBQdQRK wqPgRm1ka_RBUe1VoVWNEDtwCvFGRpeZ3l1YRIpKvzp7Y4YiL2fh.LRDXjTnrtDNWBIMkYwabk9B ywfTKWXNuRTabaaTAy2p_O.axKJUgHd4kjQNaoVFksJAiQBJE2TIsRReBLvDfzT4Fb9.qQMeLrB8 hH1crusqzwWQFCbOHuRR7p5RDjziQW7L5Lcxam2EJ2Qwpr1b3ae9k7_HibzWRoj_JjLf4sZddyhR Rb.uglc9dWM1tNe0.c1TpUNezu84Y7Gy4nIVZin.6VwTuCmikeBAlcXpFy5n3bUo89TIBzWrp7mM hUXbnw4d.S6Q_Nwsf1tUEN840P_fiLvzYNZmPrEk1AxmjsqJ2qbSAZuYaECM7Qs405eOxLkd_oMk SKlwfG7wyJ3o_krQ48N1xvbZsjw7srhRDFVp5.T3e2YVhyI6NlrAfWIolRiH9REt2YLE4Ul0k1E8 34ZtWWLIFZSADNXmZsHDwH811HIWk.dvJzpLlJmLqEXLCaox6mafwQiMMTgaLs5W7J7Yfr8hhlR6 XT_rDF_m4ZGZlUYRA_a72h7Hh2OFGyATNPse.FJtm1EVpwokAcTa6IhzEAvz.iBAgHeSkbIpo3u9 KZDnzdwDzFQ5hQK0giauHk7Nq1sDE6rHqL6df4Xp09EKTBJiIsixAKcm.D_YLng-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:40:44 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp422.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 4c017142cf03fa35170466cff726262b; Tue, 09 Apr 2019 21:40: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 Subject: [PATCH 30/59] NET: Remove netfilter scaffolding for lsm_export Date: Tue, 9 Apr 2019 14:39:17 -0700 Message-Id: <20190409213946.1667-31-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892573 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 9031D1805 for ; Tue, 9 Apr 2019 21:41:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82FC128857 for ; Tue, 9 Apr 2019 21:41:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 77D5928885; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 431FC285C6 for ; Tue, 9 Apr 2019 21:41:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726925AbfDIVlL (ORCPT ); Tue, 9 Apr 2019 17:41:11 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:33650 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726902AbfDIVlH (ORCPT ); Tue, 9 Apr 2019 17:41:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846063; bh=ru3IBy79wwcnAZalZt5K4emNkCbgFnwqv7TisHF5r3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=qhPh1dvDpfi2t5Mp7GKrRp34tHuQQgGyBQWCji/f0Wq/FZ77P1jfFjw5A5/0sdP3pKMi7IDpjklHSTu0U9GJTvstxJKmtMmluPAyCOMqGtch0UPl96HueffkLCnEeKbkAHozus4I5a0M2noqXMWWWtHYjMCVKQCBr/rPaUbXrlQqeo8js4zIdl+MyULsAPtWbw8HFHx/NIJiMHrw0xxuzZfNiMljsPrF33Hq7XoUcOV2qP5X8K57T0Q1MvLIF02ezAsKmkjQJNVOEIZhFZZT82nKnHy0CSivqWlXMIJWFii6DSsD/4evG8+3A5VuovTH85i9oxELKU6yVySOeNzhig== X-YMail-OSG: ei70h60VM1m32jxkLwyHeCgB_IezSJd5icDssNmtIkvnXUtYYUrGtsai14Bjp0w yFhLwSx4dRy0lFKDWP0.pt1fib0CCvrXN5GfZ1EdRrgKfDKqII7LLBgn38EIBM3rn5y5hXuMDOH4 h25V991fWQn45XrvZjkDbsNb395v5jeQFkARaHJkmhhKtZfLtd8KD6d9aMil4c5sZtHLLPYnHqou F.N1ru7zcpLAEUAt_y0C_x0sNh3obs8GuYL0NI0D4pYD2kR3.iDMlG_y0Zka2b2mFNkgi3AX2Ht8 YsJ4AWlDJwMN5nnIPCUQhYWzDYN8THdnbzF8jJ4erSRq66B3GuXMIZWK_FcW0qBz0hG6deZGXXcD nWI__rtrlJ59Rqj5KHJlgL_Uknf2yw1JW340ODHfhnVQRus7ec9sWMF6UBzggKqAsuQS23AxQrth t.0Ph.ful574Kh2IWJ0oUjNclzItRiEebvtefvJrUz9RfIsOEC4e77xtoOSyb_4jc8nHzZFaaj2r D.XdLphj0LcsNAzzPUcg4tfs9TWUa04hT0JzeA6C7FgvfmY9lobeid9TRYlXht7Pd7iP9Iyzz2nN 1EZ9BDm7Xi84BHbFqy9mNv7f8w3I1R5tUjCH5duzmQJW3hRUXz27Ptx9JxruW7lqOOUsPL5TPgWl RylIINkz5dMbOGyIpxmZj4ljjgRDpWTG4kEvjQ6AB.IP7qlcTPl3BFe11eSxbqGvTdR3ax0.2L8r zsRqoPSEqPOTR70B4qBXs6Pw9kpqP8ImTxaDpC4myRzSRuIvjnwLPcN5S2UqhKpghvoEHZsROLd1 ljVJPBD2NZHWxIBsaywaBTa919ut0H0TqJpyB0_k4xUvYkyVx2hP9MoosWBKai603LQ0BPIBmhQ1 hhO5PuxwWl4uL.59pall7Lrq6q1nRW5IEnh.NyntRkLONr5rioVdPxyRkAgqnjxQ0oqG9Jp0tNBv AcSVh369mrIKKrw1LGw.pTFmFdowzWgCyJTloB7s1uviKEwq99YPGFSusXlr32pSmOkyUb2Si77R FNZvpcy_f1suHWc8BMS7QE5.gehjM1UROneibxKH08o9H_LG6ZgFzdQ2wPpuy62nrTcyOFeaj2Q_ sKut0ubjeoA2PH9iRrYSFYTKTiVnvEoOSjRez1sErVBIg5f8legTXf3GNEeTSGBv6_hOgNQ-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:03 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp422.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 4c017142cf03fa35170466cff726262b; Tue, 09 Apr 2019 21:40:44 +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 Subject: [PATCH 31/59] Netlabel: Replace secids with lsm_export Date: Tue, 9 Apr 2019 14:39:18 -0700 Message-Id: <20190409213946.1667-32-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892663 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 5F3A7186D for ; Tue, 9 Apr 2019 21:41:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52C5F28857 for ; Tue, 9 Apr 2019 21:41:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 472ED2886B; Tue, 9 Apr 2019 21:41:48 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 7740D28857 for ; Tue, 9 Apr 2019 21:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726760AbfDIVlp (ORCPT ); Tue, 9 Apr 2019 17:41:45 -0400 Received: from sonic304-28.consmr.mail.ne1.yahoo.com ([66.163.191.154]:33673 "EHLO sonic304-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727085AbfDIVlo (ORCPT ); Tue, 9 Apr 2019 17:41:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846093; bh=fGxfp/CN22PmumS7bLwAFMtRgSd8WhnZOIiNQimjmvQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=nvxznKSE6eXsaplQwxwglVie6+pYwMy0EKnlVpQ79jVxi1mM0Wf5VfQPPEAnY9KrANDwogExjt30QJGLG/Eb5AJuYux4gXb1OtA+UwrLOVX+GOhhWtSv/RvmcrKM70onPkYg5XWrgWJBmjqNF/MFcn5rwNewfowgwDexKckRCymmk61JXdnUDs/FHIXJHw2hY63Yzy2F7wH7cuaJosfcZy1/0pYI56qqmDQnMrAnqZaeQHlf92HdnnClmfWeru0eYhBFr4PUBh1+6H/ZNzhdB0Gy1BsSn56dONsnewqAGQl+zkmjiHgliO3lREiTelJC4mmW8oD+HHG4qwssMdkZnQ== X-YMail-OSG: OEZq2KgVM1l59GHVuZE1vRJue8wYMJ7lw5V2tnCt2yTEWQZDJt9Anef.kkrjBr8 a5TxZ.oSVtCFABOzs_gipyrm4T_u.myQxQEdtJG4O07QoNeL6BA2YLA3EDBBhVl7aI._Cv0Y2zjU mH3KlDf83buHefR2CMjTzIi.BpS2tXBKwUEn7XDyX..OL_CuGGN2XYC6WJjL4Dr_10NI8NowLWVA kCE.6yy646iQkjuuAO389nnA1dpwG0PJ14ra.P2uwHfTK2pRsfA0BvnyIIMhdKoxM93UNjLKaH4D QIbI.Fba6wLHPZRc2TrQH5IAwShA_NNuvZCGTwMIncOJQexWtek4N9bR.MI1Nvd0GSbguiDNbLyS g2WZg_4Q1yUvJ8Dutd4EJVp_ePQ2KvztYNN9XeYAL8CfOT.7qhn2QrhGQ0M5q1EKk_4meBKycnzl TfehKwzMbkaV3ojOchtw0vDsrto3fPdTw9gVq6BipluvHjJkbY1dLlGhAAhJsrlBmbTtGcQAi7hT L39dl8S9zMAuS2OL4KqXuBBCLpIByPFI7Fbv3sUMmf2z4KuqVXlC132PXXhW88_PWDUjehyt88NF yRjlGhzUqNc6gpYHNUVyL1l.pw0zH0X.lq56ubOEN.1oIBy0bigXEaGXgUCi2pf1MoVBeUBo.2jI UfiLvUAGHHUxKkzkYWSGdTQWklpYmCUtR8mkKlwgDuWB3hds0Jf63yFlmilLBAKcHmZG3R4or17R 76Hrue2n9kO0QARAeIDWfaw_UemwRNbgjFNzn_rrUyNMT4bcdrWhZbh9ljXFOk_27hm3bPY7Q4PR 2YH00IAaD7nVaW9vzPuhKQw_t9NZGo05sSGpGvM87gkqpiJlRGMT1R5jAtZgytc4p.3lPi0pSQtS oLZe5cA09qLD0wt_fCjeDz6qEZES68GMU6nq6ZgTz0j40vwQdXJfvbBuHPWVX8LmZ3YUdqW0w7je 3tFGJBJFuLBNFaUz5dFYHNUYaqPlvXGdzsX.S._rgBmwxzdUEER.Q72.3m4IfgHaO70jDBr7lRqu SAkWVO4cJVNMxCNoeJJhtMWWCRn34v7qVTr7Awrno_hDDiwA8yMxwUtmacefB09LSeYC.vG_w.o1 NNA7WDHgvdDRvJy1DA6qgHOEr.Rprr0PoGdsWNJR.BDe6704VZb1US5oXpwWrLw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:33 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp422.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 4c017142cf03fa35170466cff726262b; Tue, 09 Apr 2019 21:40:44 +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 Subject: [PATCH 32/59] LSM: Remove lsm_export scaffolding functions Date: Tue, 9 Apr 2019 14:39:19 -0700 Message-Id: <20190409213946.1667-33-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 c413dcc1905a..6c44aca19c65 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -117,49 +117,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; -} - extern struct lsm_export *lsm_export_skb(struct sk_buff *skb); /* These functions are in security/commoncap.c */ From patchwork Tue Apr 9 21:39: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: 10892533 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 B4A2A1805 for ; Tue, 9 Apr 2019 21:40:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A51DD28885 for ; Tue, 9 Apr 2019 21:40:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9773228862; Tue, 9 Apr 2019 21:40:48 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 5681D285C6 for ; Tue, 9 Apr 2019 21:40:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726738AbfDIVkr (ORCPT ); Tue, 9 Apr 2019 17:40:47 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:44490 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726732AbfDIVkr (ORCPT ); Tue, 9 Apr 2019 17:40:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846045; bh=cOt9caKD/749IXNAg082OZdZ8wyzsShJ6Dne6L26IXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=LF+BYpqoKJrMqE19IIdBfLGQmwaV5qxDfFGBKSluqeKf2jQtPJKP3JkU3KFYFPHQRYWM0r/MwEJpUyl2frlfH5tzqbcbGEnKZ060NZpHH0vqGsPue48T0EJtmp0Xw1lxkTSlNc08J7GLZGwoTeYjhpEagHiFoHjDZugo/cSkOxF3EMVXYxPloZw+U02AvL4PUjd3GyFpmvn8KI43AxF1OKjqoUuVrTEbsBGCy8jb1SD+xk+nm8oq4L2jvyCLRpxh6IZ0BI0Uf1/gSLTY3YMtX+atM2w7147Q6P7HKIcbvoVcRPB8uhF424ZEm3w+YZljlyaDV9iLuqh93By0E/VLdA== X-YMail-OSG: TY_BuJ0VM1k2_9KaJoa9yxP_t3enDIJBjDjdiGANZqEf3XOIXPmso82VdA7C3I7 WgVGLxJuKqypJ5.JRki9ACB5m8qJMDRneHr7tnUloNPLTcuKLeLLnVbSS5TKBuq5pLv9b6VDtSwm 5mGFroe_5uku4XFSnw9Id2ygShLr465dwYOwJiKN6vUzerXHrNl86CcgXRrGpBCOqgtYcZgdraKy Xs2oeq7UDx56._tI6B15lUh69mBYzX3o4gsQJBIXa.aiGiGqRJJKX2F8rzrnyHR_UFlRe.7a3tom xV3t.BEN6howQ0WGnOApvAIsC6LsUGbd5_c9oQlCZvbm0o0wqOoHNRLDiO992mPDPmbZYq5vFWAs MXV.N7CVeNagaBP917LBdO3p0m9TtitYBTfh9ypNB0KaD7RcVoMB70iRjGDhMdPfMwikPje.ZGm2 mU3EKGL5HOWxo_Br_2w3jDAHiPZpxFqK32tMKMk2GqJzWfshvtDvOAAigejO4vGr55f4.Kc1T84x 55IyQ9nPYm48ZoQDZa6Zx0P_sCPJdBsUhXYi0ChQ5BkvarVaqmUehL.SItq3Xe3p0XT19MP8g_YJ cqridA2ONGQWVyz7GLv1jZDuQLP117tSPsD6vc8fYR.dCVVptUwv8qYrcX9YerMBf6Bxdgz_rpf0 AWphTuLbCV1aydKHlvjeQfGnOcrHHe5ShCQ6IjQFqsrg1PWxa5_ByipmTEJD_pp21bSPqdRLsb.T 368K4KB3DToP_P4Twz68mopUoevJUfLnXqKocAKk5f4V4tvwh9GCSHSfORwmL8DaPpKiD5JJ2Ior 5LvBeEvapEMcgszBJecAX9IHIIhQ7XZUvw.lYZ14sq.j.m.mshLaKuewqgpTzE8bN6rWB0q8G8bG YVGLIPm1AOUszl1pQSFoLa70BeCazR9Z.5lLfXL4a1A72FVNGwSd1FK6JVKkrKAZdkfhu4gVZqDC v1lYOawpm.KH.DEPl3Q4HXJ2KhvbUCmDrUjtyrUHq_kNEwyQDqZU5K.yjScLHI4C3HPpLd.gwOSA Z1lB0ONbMRQh8hYFMiFNWXhtYMBsnoE4BVDqSPDh77avCRQssqI5p5fEKDEcdvaJOaWwcJy_.ctQ cinTFK39CQ9Tce4zZk5JB1bnG.jrZnTt_s2o7R3HR2VaBrsIbEUCVn4Me4be5cQ-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:40:45 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp422.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 4c017142cf03fa35170466cff726262b; Tue, 09 Apr 2019 21:40:45 +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 Subject: [PATCH 33/59] IMA: FIXUP prototype using lsm_export Date: Tue, 9 Apr 2019 14:39:20 -0700 Message-Id: <20190409213946.1667-34-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892689 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 99C071922 for ; Tue, 9 Apr 2019 21:41:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C5E728857 for ; Tue, 9 Apr 2019 21:41:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80F9B28862; Tue, 9 Apr 2019 21:41:52 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 EF0DD28857 for ; Tue, 9 Apr 2019 21:41:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727154AbfDIVlv (ORCPT ); Tue, 9 Apr 2019 17:41:51 -0400 Received: from sonic304-28.consmr.mail.ne1.yahoo.com ([66.163.191.154]:44192 "EHLO sonic304-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726708AbfDIVlp (ORCPT ); Tue, 9 Apr 2019 17:41:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846093; bh=XFEQORQN/Rrt9xNIMHTY8NF01S7CWObpcTiWCO3b0pw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=ALDg2c3CUkbVFhccDZctWNBq9mwPw3XxWgPvdt6/QvaXif9T4QdSw4DdtcEf56RxjTDZ6zC+8qcH5Dfl8SdsxrX2FVX7zSL2wQgH1NDcLm3BqToCMmCs4ud+vsBP7RVlYrYdmpVb1v/r6TPwiwq6Vtk34x3ZpaHAxn3FqSTaMQ6QZ85lI0/rdDTnRvDwFw4givNZ0ftW+KmkWuTjKGSo96KBjIb1OJVZbE1n+MXVr9gD6YUzJVwrHzVDYohy+038IpoYec8VMPzl7tGYGwh0rjlRJsG7SQGw6bNzMtNjV1bHesXZJohHA5OSJ+9FegYqSlGv2wMtBq4aSFUi3W83ig== X-YMail-OSG: XG7Ojq4VM1luQgZ8Dr_1LlJmszDBVkPvTz6OcpWheNH2gXwGg2DvV_DtAibAoGh N6.AfQtUm8ho_g59GdbAyyHyFyT7fWybHygbKJSEtm8rLVo8XoJJ8Bb2KRuVk51RXcNpi0bKPmtN vgeRHPropGAFXL.O.D_t5tPKbRzJcOkr8Pka.EYw7bt3fvKKQ9ZssELiX38cu.OrEwL8JU5vvBpP CuufxCg8seecXve4TqTW4Rg8Xdbnd8wiKt9E1l9aHyVW0ZN1JcLUSbaZqrbquVk3KcdD4YWJNiKB LSNBFO3EKXgPTce7Q2psW2HTiomDCUA7DEBu6oho9.C.8xuVQPxFF4euAK7ko3jP04Abcu.RxSW5 mtiBNHB2c1fi8TFTiGzfPo53MYJRblHQcY1tAWiqFalcyRhedLQclqtjWCGh4IZaGgWQhgiKXRlx DU1mWkKODC0znr_2qBo05WynlGK6lLD6atP1rOBZ7GA8RQ2_6gvGh5nh5KuRIiepmbNicVu6tCyM NgzZFepOay9VkurkTPtTQqMjubh6utQ0Cf0BEScrYYSdQoUGHNzNKs29aM3TPodET5614pWvb_WW rcVgrAG7H8ortwCIHHJRv9o3QRU0VB8lHoIDOlUaclcDe2rZPnfXrSx0Z2ICSCf6coxDGVA_ZCkZ 7ymYb6TtGFI51P1SWqnZVaO8KKrhUYf2JJ9hi6PoO08mEz7925lEVlOfmIjD5cQZtRAyBrT24pBI P7QW9LT5Ssza0OeoOrfm4ahr3bUYBFh9FSut5wJ5ak4tvd67pmCr6ZyS02KeJMJkLc0DPUYgJpQ_ j.hX9zkjDtKFbj9Z9RtPjbSoQtV37vniDHcJVoYAlYiaG38_9J1m0.SV6MS0t7gVw1hv4o1u8YkQ LH6Uyv89.m8UMZ5Z6hiEtfS8_T7A5vz6WaR2LerzFxESv8mlx20WXiwpY3EI5kWq0qHIacPutvQY .MrYjS.PMDQfpeJJ5EdqKrCoGrW_v5W8SeGG67XOE.OvAwVFQOonx1hkggU5fynDEW55VuM_zCYv pZuCR9xKrXOkfVwBBZobIicmIPHQ9xCrO6VPxvy7hLLa1Kt5cTlL2xpN2_n27sYcSNBSg_ehEFSK OlBV50dsDS9oQ4dngvyz8lvgeQCZaHjyx26RwoZrgTLp.UdtqitmqyrlzSkznUw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:33 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp422.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 4c017142cf03fa35170466cff726262b; Tue, 09 Apr 2019 21:40:45 +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 Subject: [PATCH 34/59] Smack: Restore the release_secctx hook Date: Tue, 9 Apr 2019 14:39:21 -0700 Message-Id: <20190409213946.1667-35-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892673 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 D98841805 for ; Tue, 9 Apr 2019 21:41:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD3D328857 for ; Tue, 9 Apr 2019 21:41:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C21542886B; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 75CA328862 for ; Tue, 9 Apr 2019 21:41:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727073AbfDIVls (ORCPT ); Tue, 9 Apr 2019 17:41:48 -0400 Received: from sonic304-28.consmr.mail.ne1.yahoo.com ([66.163.191.154]:36306 "EHLO sonic304-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727080AbfDIVlp (ORCPT ); Tue, 9 Apr 2019 17:41:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846093; bh=VEDYIM3R1NMqedNbn6scDMcxUUfpt0y9Ccbwl5mHx6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=CsQq9sdLMKK2JhzXxKjLJIS9qHAVhGfz7MVGqzmONkFYEL88EQq61y/tPv3dq5yhzxwqaSLp/lsk71G3kxehQ7PfH32KqHUbXEt05f2V+2cnF2VzCP3UxQCbhKlSwrnJ3v5mEbH6fPUjTCIUjFL0W+dlM6a25e9aEKeJe2zQf2kpPx8sSAK4CNTLYFuMREYI0xN2bIlOT1LGFYGd0xyWW0QNvwOHCxH1PsCaTLl6qkiGHhdluY8pzFYx2Amd0mrQjgkdzN+HJM3gnCK2DMeTk2VufbNGd06IWhDdBjs6i99sPrac1+4BAf/EOxrJ0LwN8bEF4VJqZFoENCb6vz+NqQ== X-YMail-OSG: ElnSnMkVM1m6mIEPIVTWjS9OZgBhm1.uQDa9zsyjcVFCZmK10VC_43XGhS3mxtt oL84oLqkL_zDzpTQDjGSd9oT2snnvDRWjiY_zlz84NNBrBzZpcMPoIqu2MkRx3oQx03twIsCZsQ1 9YvhhfqMl2AMk0h1oo5rVnyn0qGf73bTPvrEeWxu9WM5skkQFWEAApcO3JlnLhM0vBFhe5qJsWTi 9mHMSYRqvpYeVbYV0D9geoZiE073uBoF8QYOY1sz9vGEv8kbQ8Hz.rV8MllE82YvCBK7lTp40Wv7 vipuKTQWWwMBbNsKpdWOM3T6twG9yzfnR7_nMAelPR4PowoQHeQFgPKVkB42jUJ3AHlhpe4F8yRG PC_8O.ZayHaHu7i3X9KxUiHUNyKN_x3mQobnmKz8MJKp.wyGw6ncdMz_wl_dBdew2Q2Ko_r.ndwV Fy0aIkkJV6rypLU5zTnWOGh9NFXSI8bAUNbJJ5DKTzgQrLS1z37tmCs5JzOt72fQ3DPkrAs4lr9K Ha6jfv8d8pQZ5916sdmhDRv9kj4xTO3RTWXzSUE3Uv_6.l7yp2ntfSpuHEM5se5LkzOQk4cSc54a h1MQgDucEyk90zyttK6_oFUGC.cT69ZLFQkVkHoBXgnRgm2iNm5qrl0WJv_IKCRnuEKpL6zzzZH_ 4o9VNMqmP9x0i4m83K6B1rk4gPjPJ4Qhvvhk5VSjjggLYFRRKVCziojqwPcbBcGwHJQDPnHLWaOY STKRXRdaIs.apCR2D3oZyx_bMX7wDpX8efm50kFnUCVfoEMsQefPZfXl0JEB8hBqRSDi0DbfUW.U 5xnC5T2G8LEQ0skECC16vpCm2p9u3Byuybj5NjHxDOtPZt.SKNzMmFVyPOd7UbyeedEjHgQLYxpz KQ8YZjzx6kdSCMmWJGha0kIrJtTdACiHuSXtoZP7YnNam0d3.FwfVzHCgBk0BrqPQCmnMHuVZejm jcpJHJcuOOeId.IqNNMKI3PD6bBhbQfWD.yIxnRetGyK37Co22iVc3jcFtS_lpvnptMtFiBHxaJ4 LPYbQ7L7VaoigKV7PALWViH9jxRQHQRUDz7A2YO8RJbCldDyrKjswnK5DZjFknOkVngfA.a15aZz TYSagZEXos.dE52kxNodi470o8tsENFyoN2143RwADNtaNuCpOlgSk6TSbhaxjg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:33 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp408.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 6a737b6f7572f7259a29fc213d8f0ed1; Tue, 09 Apr 2019 21:40: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 Subject: [PATCH 35/59] AppArmor: Remove unnecessary hook stub Date: Tue, 9 Apr 2019 14:39:22 -0700 Message-Id: <20190409213946.1667-36-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892587 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 0B321186D for ; Tue, 9 Apr 2019 21:41:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F13B0285C6 for ; Tue, 9 Apr 2019 21:41:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E571C28892; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 9474C285C6 for ; Tue, 9 Apr 2019 21:41:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726953AbfDIVlN (ORCPT ); Tue, 9 Apr 2019 17:41:13 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:43946 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726923AbfDIVlF (ORCPT ); Tue, 9 Apr 2019 17:41:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846063; bh=qAJ+Rda21nKW+P9EyOWFlXVarN/YAKnXHrX4pZPXalg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=e+VRnSud7rdFVtcRBw8wOjBB7Lxd1XCLZ199+IYioIfETQ76GVB/SkITBwWXvwD8TH37bsqvXBHoDHrAFUMMSkut7QsIuEWOAUoasTEf670vinSlEj8p7ODO60NyDzcNQdri2899Zs4rwUV5YX9A/e/w2bQZ96Xq0iconkxU2FdDtAiCZVZed27rJ3vlqjLXXg9Tfdr+e0S5wvgPkE9c1S+EVoFifNzT8XZg73zkBxQ9GGfHu0VgETvaXGHdOWdqpDgCCJiSSzs0KaEFj4CkULl7lconKpEYp8sS7+b/SRnW6ToLlRIHwBu/d9XfPPdJxI58A53+BipW5MSkyTQeRw== X-YMail-OSG: vw49.RcVM1li4ZVYc7niFNTjtkOqomyet8nQ7RG4aJc0DH81lGhYdAFpLOGjkHG P7T8c8Ml5kbniDV.utSvxFRMKOtqw1IfbynICMp7omKKVldMkLLGqMwY6EzVQR0go0RP81N3zA7V _LHXg9GApWOnYnS7f8fiKUNT8MkX.O5DBRAp5tgLue69DVoDPwQU3.2OqijX5vVsgmgGqyOjE0jd 2PZ2K7e8twvkUV0iO4iV98qR4D54FPgPFkpX9fmd3dNvhWdVSMshQE4E06B4fAXgcsmgHillxxD6 rdp0MLLRqrQ1fGYJAsecVLcNBAHSLGmPwIG0WCi4ubfDXg5sCPC0uRGp_EkAKL48NmdlBvowPIrN 8FHZHtKk78LDLSGaOaUjI_iXNdgUQVfjsCc19m.xh8.Yp0TlNSUxVvSn700MitcCt5e59sGOmey0 uYBuQ7EMy5bU9TykomfNP3.PStNGPtkIBJ1v8oPlCDxFLVpKpl55XzQAi0GzUrvSVHX9VL0ARlFn yVtkV7SzfFbcH82L0bbvAzpCkUC6H3zMIZIBDlYdZp3RNN9Khr7IOzDIZPgsj3m5um9dubFOVO7k cr5xf4ENv49VwjftL0eW5zpoIv8m8kfJW3q2ni5sPBPR8S.Wyj4paSZReePnq1F5uOvJkee6E_GL 0JolN.P5DwTNiRLs58nE20yuqlghp.cPQHoHylCpyfP8n3O.Zyn_Pm7086XayVv2We71.lSQBn7w 9GGU14en9gJzcAztcgo_XWOCpmW0RmxrO0M0lrvmrwXr4ljGkYvqSliu_JxO0XGk5arX0TH6Ftyq nXblfym5j8myVN9rOBc8hdSXk3lK0pYzZa.Le5USCNlzb6omcmnRzlONHYayin2q4p_Qce53fh8u W.bF.nLyx14sgOpAhPBOJ7Y_ileiLw0wRwxY5nytxh7CGUNnS1VioOFb8Po7iyCqbgrYI32sJc1E PJodDBMhqCMv4seCOcxzkJ22veLoHX1SxHHoU8NHez0m4K0gs4h_0nMHuggt_FNY_hZVkAlfPMR3 W0tu8TcnlgYJRPMsLHUkxzFSq3EoMToeE_4l2QfHJwr_tiVu1AM8F82BJD6Sl5ClHS2sCTHv5ird tl6ZPUN5.fnBNvKnKl0C2v3vvWwpus.kb4VLSiDDTNtrEYhX770ncZqWzMpLoIg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:03 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp408.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 6a737b6f7572f7259a29fc213d8f0ed1; Tue, 09 Apr 2019 21:40: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 Subject: [PATCH 36/59] LSM: Limit calls to certain module hooks Date: Tue, 9 Apr 2019 14:39:23 -0700 Message-Id: <20190409213946.1667-37-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 015c38c882ba..7bf16c547010 100644 --- a/security/security.c +++ b/security/security.c @@ -713,6 +713,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 { \ @@ -727,6 +737,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) @@ -1966,7 +1989,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); @@ -1974,13 +1998,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); @@ -2105,7 +2129,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 Tue Apr 9 21:39: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: 10892553 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 334BA186D for ; Tue, 9 Apr 2019 21:41:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2711E285C6 for ; Tue, 9 Apr 2019 21:41:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BC3C2887B; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 B360C285C6 for ; Tue, 9 Apr 2019 21:41:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726763AbfDIVlH (ORCPT ); Tue, 9 Apr 2019 17:41:07 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:44190 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726924AbfDIVlF (ORCPT ); Tue, 9 Apr 2019 17:41:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846063; bh=vbPmsKchcYujFbsoTOZdCYFpnfZ1qp/ZBXWOn5HufTo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=XITBCGUdf4hlzvpYKdlZ9dm22juCfkr4Ly0mCOBQEaB6Y2sS9qHI5XWaMWx0pRxfppxSvPLTTRSIvfrMY0UBE8qI26XPV08xzMdE1PGbqeA2pFjflEBxHJuAzQ2vLMcaSA4Zd3aOrWz6d+kfrBNyfBLPdzF0KsdufZz9yeNeNs9Eu0coSnHrEuH62Ac5IR3rHaA37O9MSPLjRMK5AYJcGAL9IvPzochxUx4ZBLqviZGLmBbIaeGqHMW9qayrGTf44pcaTX1ZVQ4Rso9pUZZeYr9+s39J8P/v8Ib4B2Sh3Ba//YzRGED27VPlG7+xJGN80tSuOmQi9VSXbX3lPY1IGg== X-YMail-OSG: qKFGFvAVM1n3.Ch8BujxaN_OZC1dIGto_I1tskiGCkYkTO2UuOw5YBD9H3OYpBG ZnjmQ0ou824x1UXR6VuW2VVny_Lc2L3gV3FJnnrVPVrfAJGkiuYe1.SHuJCxU8eDFc40eYqWpjFk ulcwwohBqy4_Ux8SqmWSryOuF_pivWoJfsEgNUQOVX5m2EtlLsVtVhGgVqEBQrHztXhANRg5XRDX 1Ba0BJu4fWO8UlLwhzsPIhb460Aa19JaRXQKnb7Ux4ob_n1M10CnTpgRrmar9F9EzowwDpzTSCeL fp295QAOaCFcyBHTTOBfxX2vCZ2oMTQZ8p30hnujEJZBsSNphYJzm7EyEn3TvpaEXaX20f1h8AG9 c75XdcFbgL4mQxbXOIe9_9rR6jVKk97M_kgHqz3zgl88D8UGqEg_nMj1iHIBlt2aPu625pHjhwy_ c0O9b7UGVjMvSfaCuiFoIW4ViL.WVloR2UBq09Mr6JlE.hd.jMVqNOBGx13dELxdp.E8dKoqXlG. mLgp_X1_DJ_qm.rJp2QWMtqVECRy4W1iEMHhCXPAOM6PxoRTFsk7OsRLnddPeOQLTTRPNvMzd8m4 I3kAJmpLMf1pO1ceChGEquJ9k3WXitbriz67IFLyHwAxgBFYU59upG2pFiKgl06rAL3hLqOZMZHm GwEzZcZ0QBYe7IGDo7U_QsPCoTfG7l3MTeHssJnq036Ah40EflcOwFzO0WM1We.k7zATabZJiGqP vQE7XUPMVNiEYjiV612cpJrlkntjOspNQSUw4C0hvI7DKYu6slH5Ge2HcgP6PLKKCXxZ6mpGybAw 7Nc_SQe04sxSf1fnf5amSXjGn9.q.phvjBcnuSlPIbHEqqbT.m1vBBxAbjga_KlDSYa_h4EgOqx0 Rr8LpAp9XDXjZOBUmO6F7nshg1KdaqNVpewWdaM.KJeuQ.v82TcSK_pVYYUS80LkwPJ7nImnzZrc IKU85ubRBTN6rRiXqZ_F0tNcAx898p9FzXB6SoHZhiLUXJgyC85YXvxzX6xpmY4U29y3ksIVM9N7 ote8V6gzLgkVdS9eqEERV.sAtwHXc_YGTRdrCCu7jLV.hoRX3y0Pamu7RG5EDGpl2I.pPEojkJdZ r6AzywkUt4_xeq6vGbubFkCCy5EnDXE.Xyy_ZjhbnqHd3pF8Pz5qmEBX6ukrmzA-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:03 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp408.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 6a737b6f7572f7259a29fc213d8f0ed1; Tue, 09 Apr 2019 21:40: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 Subject: [PATCH 37/59] LSM: Create a data structure for a security context Date: Tue, 9 Apr 2019 14:39:24 -0700 Message-Id: <20190409213946.1667-38-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 6c44aca19c65..8dd21133ede8 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -119,6 +119,17 @@ static inline bool lsm_export_equal(struct lsm_export *l, struct lsm_export *m) extern struct lsm_export *lsm_export_skb(struct sk_buff *skb); +/* 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 Tue Apr 9 21:39: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: 10892645 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 ED0261805 for ; Tue, 9 Apr 2019 21:41:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF6C828857 for ; Tue, 9 Apr 2019 21:41:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D385A2887B; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 C8B7328857 for ; Tue, 9 Apr 2019 21:41:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727069AbfDIVln (ORCPT ); Tue, 9 Apr 2019 17:41:43 -0400 Received: from sonic304-28.consmr.mail.ne1.yahoo.com ([66.163.191.154]:38587 "EHLO sonic304-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727065AbfDIVln (ORCPT ); Tue, 9 Apr 2019 17:41:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846093; bh=7gPoCWetxgh6OIRNGIIxTECY/QFBwCB1nRYgDUU/GGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=sDJXGn3jYJ+M71Ceor3jSGfNlq7P4RnxlpP4LbLeHuAhkYQtNkaiYBIqktvzP2p9toHjUlyRolzudHBiZGICjFO6XeffYLXLSeepUHbzDkzPYSAoNa0b9/jDcwSVo85pi0mthfp6Ui6WKNDU5OZ9VPRusVyPShC0ccDdol+spJiutiYZos+EAoNZcm2RLCBItFC5v71kFaQu0JhBQzUNV41NGde2u8jMl/+ptPdWexER7M2Y6YOxHcwxaa1wknk8USl5EBWXN3zTtCxfYvwQ1sMbun0wCo+cIrmAZKnT0HDAq7hZOuGUWDBkCNKhDrWLnlsguX2wHklJjrXA3sCiTQ== X-YMail-OSG: RB45ODAVM1kXTi49dvPlXb1UQjEejBYGXtcNwD6I8urRvna4UKKM8GYtg4h0xCw w_NwZiN7g_D6L1bxvoym5nO3d40Zp9xkPb9AsQfMQLS1qgbkAwBDa6uDDwgHVZGxDBlQvpoebNbz w4DfiPU0OnYPVqQIDdeSAe6rMQVcCcW7qPP69aTFI_Zg87mMMZFeTEOCOToHvGvOmaTNNtMy30hV TQh6uG47S6KmLEImwcmD9ToAKqzZ1WMv1zefQmSo5FlCK1q1jKxBH99gJCOsRXESK9RItdiCpjLJ BvmTrCKBedy2DhKFhud.GnAZyAyjSrV8hTOhhwu3SKvGjpRphQbJnXzP5RC1sY62BCih_pVLpNzB FiW2hxuI_HRXob2XRqrJsXeclzm8qI7wms82MPsSBZskIjsgY2Dg3E3ZBxEvL.UsfUFROKxvnjY4 ge8VMOabB4XR5GTuJcIQgPGHiqC5NwE0Bhfg3MCNePHpTsskr4cxPwOjQBZeIgAInXs0OirNMIRh ezxnc3Bs.n0I6u9dsmhaArf3jYsBKbBFx.HuzbuMwUAnc5cgPdLfNDe5lcLZ6YEf7nAjBMuJ9Eqj 1UVKGWN7xwFEgoKtuE_qYnwVCskK.f.QIQqgaXwabd_2OXw9..V6n0GpUPiC9SffVWLU0VyfFPH_ 6wWr7z1UVl89jf.uq8ObRrsEOC8vlyMyTexRlI2ReEVC7awgs1Si2Yf3TZMaTeZ.PJvvqFKuR72t bqXe2VVKLdiX4F52c1UQTToVyKXyeSJbxgI74VtK0_.tF_gdJH3HPCyMWB4lMFSNXokPCuMCfPNG HdOLuGJit.d6lD697zsNAlOgAO8N.ouSipO9za2kh2xRZjd0RoiDj9x2IhB5z0DYUEDFzGLKrFrR t3Q6kfV3GWlSyatqleTo050Oysnlm9pbv2srrvwgp_DY7yqH4OUPVW0MyFwxuq9KSifk4r7G0_Gi VEYj99TwQIeFbH8EZap1FOO9W9dXg61VVe3jHUydqvbofPyo6ejqEWdmbPNIZiI7jYS6YkxdRRn3 XMu_wTnjXFqzgn270mA4WqsZRIb1ChiB_jYSIbNAM6P2U9GXWGVHgALmbepEoGxmQRgpJHMDpvSD mGQIsliJMqlCWxmyQjkLjwggHrs6kqxr215NoMxtCv3vIylaVg9nWJcClrYL3cA-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:33 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp408.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 6a737b6f7572f7259a29fc213d8f0ed1; Tue, 09 Apr 2019 21:40: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 Subject: [PATCH 38/59] LSM: Use lsm_context in secid_to_secctx hooks Date: Tue, 9 Apr 2019 14:39:25 -0700 Message-Id: <20190409213946.1667-39-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 af0bcdf8fcfe..566714aa0caf 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1323,9 +1323,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. @@ -1672,8 +1671,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 7bf16c547010..7cf8e268a45c 100644 --- a/security/security.c +++ b/security/security.c @@ -1989,8 +1989,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 Tue Apr 9 21:39: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: 10892561 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 320C113B5 for ; Tue, 9 Apr 2019 21:41:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25C43285C6 for ; Tue, 9 Apr 2019 21:41:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A1792887B; Tue, 9 Apr 2019 21:41:11 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 8B2DF285C6 for ; Tue, 9 Apr 2019 21:41:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726842AbfDIVlJ (ORCPT ); Tue, 9 Apr 2019 17:41:09 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:45137 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726879AbfDIVlF (ORCPT ); Tue, 9 Apr 2019 17:41:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846063; bh=oZw+jxmu0klx8qKKkocY1UUY4fu46NlBbhyji1WzJ7A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=SCMMnaf0nU9kWPEAPiRlwlAOX9KLlZyhJAqN0vcfqNyQW46Kfwcz2cSmRmPa6MrOjtjCQLj9JhfwEkheFdm+WiU7n81BVE//RuT436mrqsN1u8AYFKsVOFQxszQs87msHTkdogKa213nrXAKSVLbcZ9R9bD+OlIW61La+mhqhRDDiC+dU6RWw8jPDx4WRqN2ChxUw+ATRyh2U02VHvxJzepGz/CFz3tGTHIxVmzeyIAqa+wkDDp44hqwjMnQuEb3/p5z/+9+pqtVJ8V5HQ/8ArjbH4gVxjCUpG0XY1BrnKLLZoI1gMq43DKSH3PkmjYpP3kUOp0h/Hw0Rgz+Rhi8fg== X-YMail-OSG: YZOYJXYVM1n8BlfIL4sCah_QT0Xc1XCbP8iFwE_UgBcEvISwHthvaXIWGkKX83x akNQGGA7Qp.keKMFHS7kOQeE7hkG8e7gAQ3ZC_2DVI7Y5gSjHPn54KCDn08KM0JiRjkF3FtEzg.V xtprZ7ParUPsOKHrOaWLnhEmlMeOUYlgP63STUtpShq6aymY4OqeDrDRzZt31YQcOtScaiT5IrZG erz7CzXd9TNqKSA2G4w6CyLs5zI90QL7LBhcu7Gwio1GUliUWtUK8xRcnxKgErzQp6gI_edAx7o4 kRYbNKKg6w38cRuU5Mn2GGl73g4FMB5RkxDENggOkc0_Ii2bz8tBxEnlCfty0EYz266KUllXtYu9 4LhucEX0rQs29n_cs7UPD9OWfOb1ktVebEAONBu8EPjTyFOOFrM5WglesbnZW28S.VQgXbX34XMK JAf58wyFuL7hQEvO4_V_wOGoITQIIaErKdVTAFbaFStcckmMeUeOaxgLYbKT.h_022Dv86GRfDuw gvlUv1B1e25mM3EBtBZVhhyGdem2A1RCyz95OGNYbdoD3cMaGbcVhnca11WbGME6gXtvZwoVcjcw z6HJBX6wmUoCYr_nMc_PLNvwGQksbeRhkBX61Hw.EVP6eOT.ZFAHyAJLvQXHZBDbOuVYEj69.gWe 9zFo06uQYsj_O6urrySx05.p8KiBsBAGOTa5riv.fXtvpyE1akhByrWnbvrPjwvnvuBDfLxFnK9Z LttH5zizls0Hryl32qn01ThVx4HafVwC2BVcdfTfcSED7pd_aOoeDhD_eDaSfcNSf7WwpXDyUrLC b64zozaL6X1KCpoi.f_oiESYnpF_j0cWRUyP7P7ijvDQb.BI_MPj1o9wtKLYEtSpvgxcN5ncwk5a 3uXTEmM08xs.L4vHIvD8WxuFxaK_v6uM8HhfWxewptegqRaCVlxOspjwkOtRi7K6SPRozrTCuikb t_s1g1d357hYo1Sg6OWFvFC.ifkLibrirAMwexK9DBE1RNSzurjsnw5JmgNDQjVhAUte0u9MFeyy 7AwrZoFg7oT7VybTT9ejHARAXQ3hrQEJbwPRUGu8Vo6KPwCJKxuJTz4rXlxePdLPtPXRpKnb6Opb gJPbQS9M5ew4Fo3gKiACiL11W173a3IEV5Q.wybm5aiLJklf84az6QpN05pBrXA-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:03 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp408.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 6a737b6f7572f7259a29fc213d8f0ed1; Tue, 09 Apr 2019 21:40: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 Subject: [PATCH 39/59] LSM: Use lsm_context in secctx_to_secid hooks Date: Tue, 9 Apr 2019 14:39:26 -0700 Message-Id: <20190409213946.1667-40-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 566714aa0caf..8b842fd13fb4 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1327,8 +1327,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. @@ -1672,7 +1672,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 7cf8e268a45c..f3788840019a 100644 --- a/security/security.c +++ b/security/security.c @@ -2005,8 +2005,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 Tue Apr 9 21:39: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: 10892547 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 346B413B5 for ; Tue, 9 Apr 2019 21:41:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2655E28857 for ; Tue, 9 Apr 2019 21:41:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A42A2889C; Tue, 9 Apr 2019 21:41:08 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 A5BEC2887B for ; Tue, 9 Apr 2019 21:41:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726907AbfDIVlG (ORCPT ); Tue, 9 Apr 2019 17:41:06 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:43075 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726926AbfDIVlG (ORCPT ); Tue, 9 Apr 2019 17:41:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846063; bh=ZMFPRX5fTeMRBlSYOW6teWpgOAJGelAiTDnV//rgRYQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=uJwVJeaWW3MBe3/9VFWaJX3tP08C+nu1ywRy2SNVRiNNgebBZwUzkOvBdHn3ecLXgiuRBGpyImLVkSokjTkdG7RNpKVtO9gxAdlbN43Djl9J6mb1FnAoW34kTpUvb2Z5Rn0tmKiRMYCTHwYfOrX50Dk8xAq7zseXqChjyYTBserdDcJBh6sjYtF3pAQhblpLIi8ts5WLz80KQ2BCSS6ze4z12VZx6DIDMMbNP+LaJa/gJYTSYMDQ0QUQ/YrWSezAtI1R58Bvr6gZZ+YkrGsR95Lp1Sb4KTkRwqF9F4+UJDefflcggkb/zE1le4dcO00lPn72Fm9JyPGKxk6a+a8akA== X-YMail-OSG: gtynvHgVM1m9oV6WpVcXHMRafEz3qHBAR8LNcamRS6ErGOIIddi4AIRODxBIs6Y hkY4GOOHD3nreFoc8qwSqSvd1pz4pZZ_ASDPQxexKpGbd5K4cEvx_wmCusxNdI5NJqrlkAS892qJ 6mwyS3UbHP3yaz_OdGr1rwP79ay1BZGMHvWLroUxVyQLIm4lu2.lh_oyagDRYjhP0XDiOMWosjn8 YsDvXXlOcESqUU5FdTLlBAyzOYQsLZuglLbxKU6O43eNrzirAmSv7vd52KlFpmndZpnNrYGPI.ci vFbzP0QF0Vi9IXy6JKb2I1qPBQ3FrDLeNWWEt5BWn8GS7oD.c2BRfK3XjGJl_pY8KlyphFqX4DRJ Vn8okiKgDQSL2z8R3wHbZVi9Q6g42LbMcM.itAE5YIlr_lDQ5UqJH8sHnCvf6OPvVufhT.PWL5Ko F6L_pM3wLDhFIUHyjzb42Jxh3_yO.3ZQzfTa4O36QRWonL5vX6cVhErxwOSK6ck9HQKYgZtaXUAs FCm48oNNva0dwZpHDgiHvL6S_6WB1zDaEkME0IziHjSqNEKwA2ukDY9yeVksXUPrQ1QAU__YA7tk YrSgvmBCEMoorAZjT9DVpIKwdy2h7iyCH_DprwHckHtbXjidBo4R7vx3VJXs8SQ6O1nLVXyPjHmu bcjybbp.He1aLKVMsbkg.Py8p_84B5l5DlV8ERpvSz7ByrfvLBLBOL9FM8U2j8jEEW_bXQ29T5W4 KmkepmUhVvxwmNNntcxvn55kaWswjMXVHHbLZnEdKKssx5Z0eCwYgeh9qbTYPWzQ_pWRq2ulRlCC bGhrIpGrsrOiRekqzrWxfijkrlN_mfdttUTmGKIF293ym7gkBzcNea8pDaQBvSHW8Pri9ow.Tgw5 EuD0lf9YnjicpnMYU8gg5HYOeudV97vof.ruL3xHR0_hUj1KdokVdlorACJ3Z6.xz2z.QQe5yI8o cDcmFe5tsz7OqKod6EooX3.wZjjrNGdGn6OmFTHT1SzGxvsnBrL1wpyjsksWVz.p1cKVoBgW56qt gmXE1KZOKRj5uZmmrAwOoVSfDfQZTh_G6oJ6ITgRuQg8NneLrRellIsjAnW7PM.OswytoeDPXC5g jqefsv_IXzY7TAh5y8UamB0cUQ4BYu4a86BsSjHRJ5y139Wk0vXp7SaVHXrJbUw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:03 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp403.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0d1cdfa4e40e9d37a3e144929c04344d; Tue, 09 Apr 2019 21:41:00 +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 Subject: [PATCH 40/59] LSM: Use lsm_context in inode_getsecctx hooks Date: Tue, 9 Apr 2019 14:39:27 -0700 Message-Id: <20190409213946.1667-41-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 | 9 ++++++++- security/selinux/hooks.c | 6 +++--- security/smack/smack_lsm.c | 6 +++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 8b842fd13fb4..34ed56be82b8 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1401,12 +1401,11 @@ * @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. @@ -1679,7 +1678,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 f3788840019a..4625a9b00d1d 100644 --- a/security/security.c +++ b/security/security.c @@ -2040,7 +2040,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 Tue Apr 9 21:39: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: 10892591 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 A816F1805 for ; Tue, 9 Apr 2019 21:41:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96E1C2887B for ; Tue, 9 Apr 2019 21:41:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B6FC28862; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 2B2C1285C6 for ; Tue, 9 Apr 2019 21:41:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726952AbfDIVlN (ORCPT ); Tue, 9 Apr 2019 17:41:13 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:44781 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726938AbfDIVlG (ORCPT ); Tue, 9 Apr 2019 17:41:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846063; bh=QBEwHL43ut+mDxdXHm9kJRs4xn/suS1Ne3uAL6B3bPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=GbY37i3PO4MyAGEiKuEgI45qH1SiW7Al3Db6bK+5c/3djtC3Hrvp2rnsRU6Jfp3TJHDIEg5Lp0dOBOxNOd9RY/hOTxt6glqttpOs8d8AvIlEL0Nmv49dlvU03A/Exsgm0dF6OaVRyPt0yxoQDUKICa+YOtupMfmUlOzhJHkIaO573ksM7blN2nI+EIb+CUNyPBhjoN+VsfroLbUF4nI+r6xXtp2XXmq5ACCpPiYyMsqGv/B9LbyQTV3O5WcggmuDVrJj3/PJRYhrzP5rd1OqrsOsifsMG7LO634S4dRJQFIpGxsrtOV7tfgfM7LmoDV3akkJANJ0gSOdbE/hVez/PQ== X-YMail-OSG: shsfBnsVM1nxMhRd6FbllN0SfD8XP2A40IYpaTGljnw064e_.vJKump_waCnWrg W7r_l915QwNKd75to3VhOmPbn95EMixcD8a7.r641lKKlTmlJEsEze2lb4YJmFvJEIEpA0PZ3f_W 45_a7c9DhT1drALEC4HgCzqSaf0nvROoH.DRNeRL5kn03aj.KhRz0Oqintl329TNd2_MRq_Rw4E5 cZmLQgZhrHEqYOHI0O5zGPUcJYmZtvKaEDMI1t8hNIFme6KVdPfxEkNzfgaPFCUHycc6dTyFFfWW 3jsfVzt0uynQYd3NARLtKfPhY69xLds.MQQbLVo.sFVoswcX4A3tdQfaygo5uxWnxQBPJ.9i3ppG 9B.7k.0a9q02P64_pEJO715dvB2howBF1zqrC_EPZNZqrKstNeB4I5xIxC.UakMVxqqhRjgebpNX HJ8uEKFnImI8wtSkcsi66zifvLAwygAFwSUO7iIyBZYmzxoLvWBmEcfMIZdIdIL6wI5JQrqtcOuN aDoxBgBcgblop_QkfakTyNGrTU5v1ieSGfPMjhFM8UQqgf6kTmOWp02Y3oHLsAH9Dw0Vjl.r2D3w .Wc6Ek8Xgt8zWLoYza3kHpET4_iKZkx1VWRXc9MTnelpItQ04wU2FQlsZmtV0kO9FhRA9tVgJgqf EwO5dzxCwWx9kxIEJaRpFc0wxx07zANiuwOtOSSdCHRI8aMcnvyjMksY0eeQ_6ZuC74950tQ9v.W VGu_NSPJ9vZ89j3nzwdQoaqZTOwc54kjJkZ3wE5gn799OgKewrkm8X4VwHfmAhrj1yyBQsUs_tAa xwID2XMGPDyUE1.W2sEHz9r2V0yxgC0ANFOmik3N_BMxuqaeNFL.5unYSKMmv2tDJGJIJ1XrBAE3 BrHyArkgzkgYytLQ9sjV4CxQgCjyJ9ahRUr5_ZCJ1afdwRHQpj91aTsJ0ounAJTS_.Pr0IkqtOCm bJ_kuikiyadSFUF9Vl0lFMi9VQ60El8.g2SRtyylOVmNXPtnhHo8QSUzvtWRCsBKxuoLuqeon0et guehdiJWTc5hrJp4tCOiB4UFK_pOmzDJVHvueAD9QP_HA4p.g1Cgqdf4cM5RmfVcbSjOiMAZrwci ds77ypUr4uMkh38W5k4gZhvDWYVfvKH3qHJQWNrJvSdsE509dLmZE8LWk99E53Q-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:03 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp403.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0d1cdfa4e40e9d37a3e144929c04344d; Tue, 09 Apr 2019 21:41:01 +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 Subject: [PATCH 41/59] LSM: Use lsm_context in inode_notifysecctx hooks Date: Tue, 9 Apr 2019 14:39:28 -0700 Message-Id: <20190409213946.1667-42-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 34ed56be82b8..3344d18ba9d0 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1382,8 +1382,7 @@ * 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 @@ -1676,7 +1675,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 4625a9b00d1d..ecaabc820d87 100644 --- a/security/security.c +++ b/security/security.c @@ -2028,7 +2028,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 Tue Apr 9 21:39: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: 10892601 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 6D7281805 for ; Tue, 9 Apr 2019 21:41:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 612CB285C6 for ; Tue, 9 Apr 2019 21:41:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55D972886B; Tue, 9 Apr 2019 21:41:17 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 F322628862 for ; Tue, 9 Apr 2019 21:41:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726826AbfDIVlP (ORCPT ); Tue, 9 Apr 2019 17:41:15 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:37770 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726813AbfDIVlF (ORCPT ); Tue, 9 Apr 2019 17:41:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846063; bh=C4pqK0cCjqPg2OjmA/YdWF8k0OBv4qNwJVjWV8L6d5Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=fZlkZk4nZdTzvhvLXQ/ddDxXTNlOBuLzyfZN3UpIf99kAX5JGgXAkarjhzJPeWX6uOkbEIbWbYaN+tjtGm9uYV3prGnOoUpspuG0xIN6ptx7f9ntRtQJPEHGSQn0AUe694Nl0PAInwa/cNVRCW+e52afMXbqxKFY7+E5BMnxj8KWQ4nXJUCpP+HwW0DWtXR3sFgI34QCA+gis21tU9ACHwlbof7qINt0RcZuGMBjt74qO2rbY2z3K8wUtLLe5GZ+jq+2fiv1Cmt3rhXiwhfg9IId6PTlt5qUw3mvY1Yxx7+xD1bP2DCrMAff8i9YW4K/rQNPwuuCAHKUTnjMMUXurg== X-YMail-OSG: e3veqNAVM1kSoxepAwlHGf3KiVIvBtb6XPteWfgW5fhisQsLWkVXGm9pcgd8RNr B17tL8sXyozBhkedTgbi8izk3NYfp_mpoZiDQph4GuuDEjQSeya5MFMmV57THtXm4aBsRwDXpppA VXhsmwSfxRGU55x0rkJRHvH0lE2NSeIUbhTsFJDAOqqIJgmN9wIqNaCYXXWRsg9esu71kKLH4rRV CT0Grz_2SsAv3swkWFR84j0Deib2BTnUUCJc5K3jOtSfLjU.j6ch0oJLEbiaOJ7qnpGDO6x.iYTu 3ckFys_NvA4.4oPej6jU.ih0fDVW75i0y7440.RQMw.QXJ1TDsgESbKMqhkP2_JR5STwPWCjkY42 apoSKmK6BjUXLTOXzCrjGyTahEtPjb_cVC9YDCQjB7Byx9ZazvAzodTNB8PvM.heC0GR.oEcnSrc TlwGCinuJxxgs1MmSfR2sN1oCreourL9Z76dx2JqhfPLBL_790EmdFIvywZUMqCDsbgtgRmz6v12 rMj6h7ltdGuCLBb3dIOUYeaPRUzw9srK8DA_gp20WTm7Xzm4nQBth2jucP2SK5dJAp0hUeUTRDWg KKudCjYNcCYICVxWL5i9B_G7foAi6EgQrJazvdAc9OKCs3df5koWgME9wc9nrmvQlY1ZPrKOnG9Z HqcNXDsv_yXxeVfdDgwUwkFP6tgkqhw_ggweE.TACdUyTgnI.zXhrCsZi9VBy.c7BVP.wWwgR0G3 Yds28uz2Cgt8MQDYGgzfVPo3lTf7rmDbCd.akPNv9sWUhSRat2yQBuTTTzwKjM4VzHMd_YjCg.m9 r8HfivXgpxfzVTa8a0kqhsTKNeTaIT7cE.BqPeYoj4jetIC6YqBQERQOF.eJiThvPJkP6Me8LLrf AvUT6QEC1F.QQ8._Zgfn85hm5nHUuFLE6lrlTr8k3AYvgWtdfnjmXEPQCTnuNI73UYPQrPQ7IBo5 yXtMyD2ueg1mLoFNfdZZPZxJ3LWKhWRI8_ho3w.tY78VLSrCvObIenwgo38kJfCz9B7XYX65EjVw 2L7LbNSnpgUwB1fUeMI3IuglUkkGfJW5yyHaCQIOVU3vL_8WnS8tlCUPO9OZZc2Dk6ApnVUUr5CH UjLP74x9GVg3V..CUhTo17L.YVTrcQ6wHTqKMvqgaKMKQTslh9qSK480AkIdPcg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:03 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp403.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0d1cdfa4e40e9d37a3e144929c04344d; Tue, 09 Apr 2019 21:41:02 +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 Subject: [PATCH 42/59] LSM: Use lsm_context in dentry_init_security hooks Date: Tue, 9 Apr 2019 14:39:29 -0700 Message-Id: <20190409213946.1667-43-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 3344d18ba9d0..f60ec98596c8 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -166,8 +166,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 @@ -1500,8 +1499,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 ecaabc820d87..5e35adb43d65 100644 --- a/security/security.c +++ b/security/security.c @@ -1032,8 +1032,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 Tue Apr 9 21:39: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: 10892595 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 A24661805 for ; Tue, 9 Apr 2019 21:41:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95DEC28885 for ; Tue, 9 Apr 2019 21:41:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A4C528862; Tue, 9 Apr 2019 21:41:16 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 31EFC28892 for ; Tue, 9 Apr 2019 21:41:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726964AbfDIVlP (ORCPT ); Tue, 9 Apr 2019 17:41:15 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:41101 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726826AbfDIVlF (ORCPT ); Tue, 9 Apr 2019 17:41:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846063; bh=74rPh+sCnMpg6mZ/XiPS4qZefks1l7WGjfPbmrUu5zs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=o7hC9IfNh/8TViwMr01bxXjjpZNQVVGy5SVNytqVc+Gb2LNws/D7z63B0Coj0Ux/JOqtCldj3as+IB3vwjEfF8DSbcFngC+HsaEri8SESfpFTo0cpmuILUEydftLA+l1hJBjsJeybE4uEUxAtZD1miR+Wdpg6q76uasnjdpZFXg72XzD/kA3bOXwElFb81kTOt1FKL8R5TBDMcNbp1gLrQDU55z0i15LQe/UgoNpZpM0kmZgmJmIosv58m72wANSWswAK6LQkSjOfT5tiFtUIkW2IP4t0bllHg89Rv1BvoAv4GqKKUaQS/R1dV8ozCe4OlhWJh7VxvN3JPcYmjf03A== X-YMail-OSG: WzZx2iAVM1kogtTh4MxcEZIQtsvQpkL1Ra1SELSQi6vXJYkXWlbXubI4.VKHl5b _HrqtCdddoMHwH1le7yC8HKVDg2Y6NGRH2uBH3jJJlT351alZekkS3YbpoCpKaVOxOoBujUNCx6z qUVK56pv9m6_NWaZgf4cb27kxwJHGP_cU9a53wRiqY61FDycW3M5PIz.q_EzJF7Mpm4259K4mcsu d_LbxfjlOGwNEQpUZdpka7M8SxuuXv2rS8iwiR385lbt1kvYBdYPhLJFi4uKDKkN69gCQKk5kDUi aoSFyI0TtlO7upSEReyHNsp.blBPVv7q3y3UjY1wG7QquLXDX5zRFwE0ZYIEFbroUh7laVqbCwka 4qYLIBPe4569TdHgqJXosCWIlddDZ8RjCF3WCKWPe1UTik5tJaztlM2CnikMsjqGMuj2yQMGp2hL MUq1dMR_E2Z5jKa4UlWVz.jNwO5BXYbUuCR_wSw9LXapdq9cPdvcqR0O.J.9mi1ipixvD4NpuI49 1WGWddPI9e8FuguVlCAhCPJtJQ6cF47fwLEPYGhsDl_UusK.LffYAGgiHPbNLA1kF0r3UDR0pvEp aA0RGIYh_smwH8tZHfMCaOezwn3fXwe2vHSfIuWYPuVsFDBYe35MMvddLceqZ5wFTCQxTsfU8qko uBv_Tv1Z2i.88MLSbrAaTTvUV2COH4K4eLLHOQ0n1gGkuGOLpR4tLluOgRKJOy6vdZ8i0EYbt_BN OqboAJDWpAOY4gT_J0Qg7t.rIu9DEBvMmIwCT9GbTqvaerg9trj5NOYDL0iPCPwqNz2yxvlwP6n_ 50iqZp.r5pE41jSInNfLo43o4Z3gOdr7URrtIg.5IU2OP4eJRdhBSptWTDK94X9YrkiObPtyiQuA GmXmJGy_5o0bbQRN7VTuHvyNcf7OcxWwqx2BVACmAegKMO3.YdiP_DcfF4YFLs4.j8adYbpJGRDy SHvocpRBzz1yfO6EmwUk8onAewTPP_r3PF763EeKaiTDQcZlpG59tTjjsWVxZk0Mkci5aGoEd5ju yY3ONQR66xPrE42.l3dQuKcBOB3m..GbRbnTZSNaH5vz5biXawjE3bNl9Ln6GivzuU.8aHG.v1BZ pWEDr18dDwZcRm8FUH8ySn3Ip8bw28JjqDPD9XIxrnRSEXkiIQT.5JiHLWqvoBQ-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:03 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp403.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0d1cdfa4e40e9d37a3e144929c04344d; Tue, 09 Apr 2019 21:41:02 +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 Subject: [PATCH 43/59] LSM: Use lsm_context in security_dentry_init_security Date: Tue, 9 Apr 2019 14:39:30 -0700 Message-Id: <20190409213946.1667-44-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 8dd21133ede8..ba9bcdbfaebe 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -304,8 +304,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, @@ -676,8 +676,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 5e35adb43d65..7069ff857f58 100644 --- a/security/security.c +++ b/security/security.c @@ -1029,17 +1029,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 Tue Apr 9 21:39: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: 10892567 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 E297F13B5 for ; Tue, 9 Apr 2019 21:41:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D562328862 for ; Tue, 9 Apr 2019 21:41:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C986D28857; Tue, 9 Apr 2019 21:41:11 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 5F8AE28885 for ; Tue, 9 Apr 2019 21:41:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726850AbfDIVlK (ORCPT ); Tue, 9 Apr 2019 17:41:10 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:44326 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726691AbfDIVlI (ORCPT ); Tue, 9 Apr 2019 17:41:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846066; bh=BkiVgWxV8LugM7dQFM0z6uB/OZ9M/gQ3t5pE0/A8yGY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=qvo2Z/L06RQDn21xTiZ7P4QQNz65Bh9aTIJlWoCG8AG0Ysp3o4LG0VHB+0wi78SlVrRVIhZRRoTEptDGTgiIHBZDbIdJwUGTB/qT46hJgWyL9o/rGjMvafRLaserhvkVZS35KnYFpwxK4rAQWGbefIqw2OnP/AhXoD8LaL66PEU3MUUh9D17vNcMWSXKfRRLtRN+cEAvRZRk9yy0D5E1ZcOjbv5LaMeYvCtapCoijAOucpbRRr/sqvGm93A5wOVNytaj4+nEu5yCB8rkOCKKRoaFSMpYP3uAC4f5adDPj2V7Tq8cT1Fvnx7Uy+vS3i/4toQkE9G8q70dqEYAvFgOjA== X-YMail-OSG: snphV6oVM1kNtcWuNddOPTFmLZVnPiz2SggnMon.KXoEfulHs18qI.Foprb0QHN HjBA4YYOheTMkCUQt__jwqap5HTXQoMXVegEiknTl9lAMjc5CIeTfTTgQUjR2bSqfefWj1OsMhEa Jc2Qb4_MNwsRR51gerBwDA1w5uos5dPJPldvsceI8QBUR0hP6ebVy3MbmeoIi6THVqBSQoqZhRR1 MkSLDkYzQ0MIZrFkAkxOdC9pButW0R8S9FRaFb8Mh4__VLKkh_DzDqfheiSsaP90_aB2uizECykS XXDYFPOVx.3QiMb4y9o24BQvjtodUp3rT7DuEZHzkI.Gk_QhEbwSNyX3qR64q1krO6I54khRVUfr ziPkC2t7GBgz6QRmL_nNnY5mla0rfAVrSbml8WH6BBlPfnGsjvUwRQC3cg.J8l97mXExdJmBAv2F rOhZcTURCg3LeyCnGCtk_1hcIIPP9KTzNQWMP1I69C8K4OBlUSGafsuEEhLxjqZz_TT5EYSt5oqV L6VmSkSx6.RMr2dXEw8IbyrRfAZWlKQrdgW1HhTz_Bow76gtL3OHuUlya3wFVRn9xytTUpjzVq7S L_Gb12uy75dF8FtEod.FkJ9o5.KmSSuAQGkswCIXDYOXmWIFCXW21rDDsB..R7HixwjPT6LMfGq9 7GamF_axtX_2WA7OyGMo992ve7iV.j1JoEtEzET4M_O9wzvOhEmUkdUoLBPtdScPZ.WWPlYqP5au Am6mctjn4Bf8WQakAqIVcFwltkH961Jnc0hnp68S.c.YewZpfBFHI.mQOeyShtqnVoT8XRccM7yF jaiAXiroWOwSrYAhK1nuo6ay2Z9h6A6NvWi0YULHtwvOZuMoCT6H46zaNUA66snoJzwMwvx.kvHW h6E_YSsuzXMK3RCic3_2Qk1Ka.lPrHFR.YW86GaqLi8oqnJvEd2YoG72TVHfitYMzTS5DfByrIkv wFx371qdI6kBmFDaztdbFi7fNsmCUCUxMs0Ku56X7MIYGjHLpkyVwG4eqahuWMWOE3lYY6CQmT_4 3tJ8GVHufSuXydvpqmXr3fbnsXjuNU2fq8P6EBXu2B3lzSTd0fjrtG9jMQBuu0Ctfa.5R0LYt0aW zSaV.grKxsQKjM0US_9jl9xeaFPU.91LShxebCrHmfRvhEz8ZQPixEjwURcp_Pg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:06 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp403.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0d1cdfa4e40e9d37a3e144929c04344d; Tue, 09 Apr 2019 21:41:03 +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 Subject: [PATCH 44/59] LSM: Use lsm_context in security_inode_notifysecctx Date: Tue, 9 Apr 2019 14:39:31 -0700 Message-Id: <20190409213946.1667-45-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 ba9bcdbfaebe..2abbaf72779e 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -439,7 +439,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 */ @@ -1234,7 +1234,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 7069ff857f58..f5e332bfcdbe 100644 --- a/security/security.c +++ b/security/security.c @@ -2026,13 +2026,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 Tue Apr 9 21:39: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: 10892593 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 381F713B5 for ; Tue, 9 Apr 2019 21:41:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BD37285C6 for ; Tue, 9 Apr 2019 21:41:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 20AC22887B; Tue, 9 Apr 2019 21:41:16 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 A6D0E285C6 for ; Tue, 9 Apr 2019 21:41:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726805AbfDIVlO (ORCPT ); Tue, 9 Apr 2019 17:41:14 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:37274 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726849AbfDIVlO (ORCPT ); Tue, 9 Apr 2019 17:41:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846072; bh=zegT0UV/a0mEisN0gB9wl+y3EnZt90kYI1JdG3iO73s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=EdesAauvk2Frv0XUrpbbX3ef001ZitkimtefsApJ80NoYa3teQqhoB8p1WOLwvO5zlkdDQ9ruY9u6dOUQpPe1EUzo1/WI5+pLZRe09ml47FwJkIIlxibIIbPtyAS0b070+lpm29pX2Tn84hg2fRUzenLYUsFOCv3R3+KbtzdX9Azvd3jxJZoaNLY7PL2UY7wALVmXT7CUd1wQBqAVBsbm5N1+50uuTbsXUOPZq4SNSBkKl+iT99b0S0K5nssY+qtAmL6JqiQKnHINii8rkRBOk4nUOTtiFkgCdByG4NA2tI1WtDILDaG/fZPgRR4dMOpbEDpC0zUQMhbifWwFVTwtg== X-YMail-OSG: Mk0DgHkVM1nep.GQenxF8bOlYB17uKcHdPQUY0xEIH0TIcm5jIbfV14gZ0hhw.B 924YoYL6padftpQJ_bPD5uMYMjQe9HVQtYXgbQIuxWhVBNwCTxnLePRm_i5xIks02aN.uNIKy8uM 8SXkbM2wCgPTk7VnpIXVtPaztsphzwhb5vEfMIljsFuf3K3rtrfzcpzf6k1mGY0esTPU9zrTL5T5 V_dzEWoWfvwKMYabL7m84rgFo_80x8J3vhLy612YS9RyWgxvr3HsE4jOPeQf4udvb45BT2klQsAT 246pAfYp1o_U3xO3hskMvADNcCQAmoCwHPcldm3UNJ7odOA04PV8fVJ6TopyLINoEhs_mjAaSWlC c99uB_Qt1wQ5mING_tz3PdFrhjgiRkoB9V7QVanHFaLofVb0H2OWqBJfs4Tic.opc1VODz5GRyUe mIMrOgAQGmqjo15Izxgv1yboyz5v5BBck2pbowcbRlD5LL3ykPHn0MkaSE_ujQSMgYCrC4qFPsAA 48LzyAXk3MYMkN1wsVekEfAhrana4aBRjqEnyq5HYpdXO5olYATvhslfqBwulKHjEklyQk_.jAF0 UL_4gf6LiPNy2xAycwYD1VySIce4QpGJQtCzPvRhMmDm.MilXLZhnbLci.vXb13N3AtkI7gYNlQJ 0MUWQT2EosugJrh_jFU0jRR_G.a1nWRNdhjX4JkXkcm6.qm7W_mmOerANp.P1vMomDGAXmIjWR91 vyDchnugU6xb4P2EiN17LgaG5qvULWdBYw0m.NVufBFDPW7jYcwQhLLoIL2XoPgMT2cQc.Lt0M9V .JpgFM__.eawYFHfWgeunXZuFG7ppBJCgGcm7rG.3YLqRV4goFJ1WP4Mk0ylx8zk8LNDYrXrZwOA kPhdd7xsLHVoP.DwBR4rU.pmfmCo_TI5p1hGu2kaUnTBHkQfunmJKiuRtYzm.z6l2aev3dGWn_Zg 22TxMESN0ra_PPmqIhTPysAATETACaSvofl0.pQZ3wCndkjicGDYSOpGUw5BumrMc0HkgNV6eJAS hdz36ungf_Bwbra3Q_wlUKNK4B98789ED1rnKFd9zi7pfJSgaezJB4Mu8Oa2R7i.CZ5N.SvMh2NB a0wek9U5CZlFi5uhQgECxIxM2AK_ecyM5gNE4r8a4ss4lO4qtwbPtzudY.L7stg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:12 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 909a163ce0f03793fff6be9a79785446; Tue, 09 Apr 2019 21:41: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 Subject: [PATCH 45/59] LSM: Use lsm_context in security_inode_getsecctx Date: Tue, 9 Apr 2019 14:39:32 -0700 Message-Id: <20190409213946.1667-46-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 2abbaf72779e..b9f824952748 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -441,7 +441,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) @@ -1243,7 +1243,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 f5e332bfcdbe..b7e15cbd4021 100644 --- a/security/security.c +++ b/security/security.c @@ -2038,16 +2038,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 Tue Apr 9 21:39: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: 10892711 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 5B55718B7 for ; Tue, 9 Apr 2019 21:41:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E4EF285C6 for ; Tue, 9 Apr 2019 21:41:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 42FC728862; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 BF44D285C6 for ; Tue, 9 Apr 2019 21:41:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727115AbfDIVl6 (ORCPT ); Tue, 9 Apr 2019 17:41:58 -0400 Received: from sonic304-28.consmr.mail.ne1.yahoo.com ([66.163.191.154]:43846 "EHLO sonic304-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727156AbfDIVl6 (ORCPT ); Tue, 9 Apr 2019 17:41:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846102; bh=Bz4Myh+vsbujN22ch93KZc6mzSg5aPOU0wuPwMKBSrE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=qiojpj9WNyp6BZprYbc56V/m7vo9AuZ1T9eEgmJAHar8fRkyxJ0Z3vtI7HtvuTKiubOyYSanROKriVXfcbPQoJVWeSEjemPiEjApBvbwSmuLVHp6IpccXOvPjxRDiw3zFlbo56qrtFNtKbegNgFymKao66JnuOc3JaSLmNLhR/U0KQQVmvTPZchY8aLu3gsJiAnbzDy99xoPASTfgaoWW7KMfihTCtjjx5BMsJm+AIx6Cm3fVybKWtiIQAriyNZg9YxGQlHgRCrQVoFLtwa+7ov4J+AIHewLJ8VGkaJL7+Lk3GyMSMShbHJsPIx5+4Vq8gdaA1eF/ZZqRpx3dQkQRg== X-YMail-OSG: YuhJvy4VM1kOp0WPRE6VdQVnXDwVxdp_W8db11kgOHVofUDvewJztuAweYkJK7a Gm4.rG8fXHTZlvj6A2od94BYEZiloeYkn5YnlQMo8sQCuMd1n04jMm9t._NeNuJBDXPeWpcASSt0 _eZaiZOmdCpfh.ASlkd8p_vfDH6QNH_lyr11Z.6B3_mgK18AVAHlV7G_2o2.qK_RO7PQfERt4r1I x.1rLss1STtVHIO2M_6uIuvnzkZHBSaRnU8IwEfJf2Hwd04bo9T5h0SRmbGuYNhcy94YlOjclsVT GfbK2gc54RFJj020CSex8IfwTEa.geAfWemhWM7i6fz_eZcUZK.RcXgQpdJjKipmf1yud3a5.z0S r1HsNBdVg5E6RzQapM5PSRtbKlxL6pOUTbZdQuQJAEE3B4WFUnzzeICyIm78YzgvHF43ydbPIk6n Wj1VkHEEHA7_1wSEWg0VWNmBR6qRZlq6fAfCx4Vcu6seKPTDF_Tnj9ROnBTFkBZXE4sAWFGe88Dt .SG6WfIZXJIyoSl2FRLXnkN.oQh3OPQVb2HqBF.XT896RlJQC5WMNA1T3bV2ZvO.mJDD30LM0nXG XXZn600wPmOFzkAL3w6IPkN07eau6euYwOSQkF1b8_w3CHh_0ZLxlirXKF3dzrju3P5w_nSCbsWX KQ0nc7zPK.Lz_F4fVlFqwnF8GkIvncwxuRHtGFvGPwWg.slnsz.NB8FjK9AQRGmBIjhijfe0yvnI IwhmUxSDfcIOZ_BEo_Kf6ucyh33ByzZJro7tidHgMhpulRcXYHRpDjdozdkzxr1QBK5xr7NX6wNO MD7CEtT43yUpBDcATj__zsZK_ug3dPgbQEVxNxiiFLPtPioZaH_tMMdiORpQrdXAQdJT664Iwbdf vzDhZ_CDSJ_6vIad2PRP6XGko.GI0nW5qm5F6q6iQOR32PB.WbLHPAorJvNrcIQhpYz8O4jsA1Qw 4.IQ7vyF11hQ2FeJjxNRZR7CG6sWgrCT.A917C4Cz3p93GHlmw2D1mqi7iQMx3GCqq.faoSrbRo. 1D3qNIxce9DX3_sgxR1B1NwgptjgDHYXiPQznhFtvCfB4vLeWoCQX25rBy98qZNlIMe08hWOVTI. ASksDpqAflVptIBcYzJ7AOs5idUTIF8XQitY3thubGP1VksGPvlDeLFawvTBTZA-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:42 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 909a163ce0f03793fff6be9a79785446; Tue, 09 Apr 2019 21:41: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 Subject: [PATCH 46/59] LSM: Use lsm_context in security_secctx_to_secid Date: Tue, 9 Apr 2019 14:39:33 -0700 Message-Id: <20190409213946.1667-47-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 | 8 ++------ 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index b9f824952748..9a842a20b4b7 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -434,8 +434,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); @@ -1219,8 +1218,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 b7e15cbd4021..f51ea4a134ae 100644 --- a/security/security.c +++ b/security/security.c @@ -2002,15 +2002,11 @@ 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 = 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 Tue Apr 9 21:39: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: 10892607 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 EA9A013B5 for ; Tue, 9 Apr 2019 21:41:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD33A285C6 for ; Tue, 9 Apr 2019 21:41:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1A2028862; Tue, 9 Apr 2019 21:41:19 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 3FA582886B for ; Tue, 9 Apr 2019 21:41:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726813AbfDIVlR (ORCPT ); Tue, 9 Apr 2019 17:41:17 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:33459 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726962AbfDIVlQ (ORCPT ); Tue, 9 Apr 2019 17:41:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846074; bh=0HvNAEM5ldRD+uctL0wTIJl/wIYr3ZZyu0EQxH10SGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=RazMJFvAFzgp59t15OZLvw54cOfj/nN0G5I/B4iqGf77kEWOYfTI828S32wzMRSuEPHi4F7MlQzxopDXHuFnnE2d+wxJhGpjQ02QVYQHaHvbZPX5508m7qis4pMfBkQ+B7bNT+rSq1A5ldvJMD1d0FdSTCqILeHSAGjnlJZlXNPr+U7FXALouOanCBmXbe7J2CkGXDukdkKdhzxRQJVHz2VvSCtB5RnCyQPoSkmTWBAnro4Q6V6qqa9SMNyuUYTsjVEKpS1K1xfjXzFYAhesFlpgnacHXdFY5x9dEh0SqT7psXv8BAVgO1TslKMTy9sBS/nd8SDPpUIS/LG7lEdFIQ== X-YMail-OSG: TLBxVA0VM1ky8EeBddCh0AnGIEg_EPU0sHYiQY41DaFZXrHxYyDPzJ6BNPgZZY2 2e7UUGxLUK7dFqDOzUvalL2M.Hslnk3rRmrtlRj_Ed1aUzavIvnZtfR0aROFH3IgAfvKSu1A.yiE GrXnay7Y8QGBOzjvoEU01rTlBYbtximMt2k_4k8RYfRr0pEFXtz0F0c47I2QiasvqcH3yTWsMkGd dHp5NAIAe6K3XuJAl307K8X1u5Hdggaf4uUagHs5HvFYjRMk3zt3DNHmBFC6MPU68L3mOoyhan1D m0Lh65KM_DnlkU35SRhiNLBurfuCjdKoYNXx51duMw.gjl1m7vqH0N5Xs7VK7gDSKjXuD3Og.Jkk tXfQpo8YKKI4YVHQKuPS9VDDQT35AWk7H5K7AJgjvaTqujNvrGPBjBiTINr.KUh.cczWsQpoqx4a wQZGHpM3T14tblZd35N0IMJVoiFXhoyPcsarPnUICuiJ6vn6YSYR6D.GFvR8DrWLgZCV0KHRbFao PJffQFIAf7jBqJtIkjF.pBIg_JQduDIbDtP9RnGrdTOuCI29lBCFdT_eJJ8dzoVKheGcIBh.os_M ry9yMBznGe4cb9CR0qKMZabcZUFyLEXiQePg95BAxDIcEd8nEDQKhrYiPd9w8EoF1DPpQJbMI.C5 h.RFytQLzd8XDoKIPc6QtB58eWYVYFbHhSrI6BoGBCs6N2Vw70m4SuJzfRLQRnNqFXM28t2x2ATR XCbIyuRIdHViooBgjkdRtuSbeZfNvlThdNqJlzlKUqstqa35dZdCFJHD4SpGIDcKtUdoxN9wRA6U 1TnrbR8U3bwVU8L_b7aIT1S5IbYDDlaSv7F5dw6KcYDzXHpI9SxAeBgQQ9SfpQhTvfF85CIESsCL qkT2vtrJoLjkd3zWWQSNFa0H_udjKPqyGwQoAsXp1WrJG3jw.n08LdnMhEA3Anv2bAXWyx1ctZxt 2JTkSF05BvtEkpWnNInCtpmTsEbmgsZ0DNnVSFReCTqmi0tnFoqzmReL_6jeTxbAGlj0LohF6B21 kwDbOLtnPiyX2dATAxe9sdHfyVn_LjiCFavLCzBy769tpd9ibQgaxy.bouBcse.TjRhgRhR.sJiJ Aizg120mpI1DdxwXvIRcB7_g.sBvIpKbj5tnFVMfYivm.Vag2N6TUJt0hoSTezw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:14 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 909a163ce0f03793fff6be9a79785446; Tue, 09 Apr 2019 21:41: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 Subject: [PATCH 47/59] LSM: Use lsm_context in release_secctx hooks Date: Tue, 9 Apr 2019 14:39:34 -0700 Message-Id: <20190409213946.1667-48-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 | 7 +++++-- security/selinux/hooks.c | 4 ++-- security/smack/smack_lsm.c | 4 ++-- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index f60ec98596c8..11bfa0a4f188 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1332,7 +1332,6 @@ * @release_secctx: * Release the security context. * @secdata contains the security context. - * @seclen contains the length of the security context. * * Security hooks for Audit * @@ -1671,7 +1670,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 f51ea4a134ae..149cceb5e366 100644 --- a/security/security.c +++ b/security/security.c @@ -2004,7 +2004,6 @@ EXPORT_SYMBOL(security_secid_to_secctx); int security_secctx_to_secid(struct lsm_context *cp, struct lsm_export *l) { - lsm_export_init(l); return call_one_int_hook(secctx_to_secid, 0, cp, l); } @@ -2012,7 +2011,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 Tue Apr 9 21:39: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: 10892617 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 9570C13B5 for ; Tue, 9 Apr 2019 21:41:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86A40285C6 for ; Tue, 9 Apr 2019 21:41:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B4342886B; Tue, 9 Apr 2019 21:41:25 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 1F80F285C6 for ; Tue, 9 Apr 2019 21:41:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726962AbfDIVlR (ORCPT ); Tue, 9 Apr 2019 17:41:17 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:43504 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726847AbfDIVlQ (ORCPT ); Tue, 9 Apr 2019 17:41:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846074; bh=KrQLTbaoGamBkZEi20GLQ5sT2nJBoRBl7qwjn3e5IEQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=tEB76HwmCG14wc/arEdvAlvWNA96wK+kG87/zXCD+4Nkec7FoWAdZ8bW7q888WOGlnnGWTee76Lpk46Pd2/l8dsy7mAbc0wjzf7t9ycVrFcdunRnQIDjgRD45PJ5OOVCXRdS6FSKmBHtRGD/N3+MzYuUkzQfcwPdhbk8FAxm4+VGJ2Ia9W9GRQc9jhC9PIlK7miJ22Zv23MPr04aImMBpco3WU+TPc+iCqm0E96Fc4GKa+pAonkTySacwptILjm/cFkfbphWnTfUkOGIzihs58+oSomHDn2nL27hDos4aLn7u8lAFgJhEd1Re+8xD6wsiesP6IbMb9j5fm+PkVoK3Q== X-YMail-OSG: g.hLPVUVM1kFu_rHWPdkGFJmXK.ahx0M5E9aBlDq2WNnqTCw_TB1y2HrJzfgA.L BE9ZsGUgfxHYT4b9UcLLl5ibhGD0tjU2Fy9Ang8fGl7ZTaeMG9Lz16tlRPWW8LWfClBouRCoCR0z myVfrzfqFHTa7L3d.uSSqyoD1zYmk3wehjtY9NZ3UaUn6.f3LKNBdOD6Ys2zbCNfyy7fNUE1rKxq M5YC1kLyUAMLRwyVM6g0dW2S2P4REYCEsq77QL4AtI1wLlnYUEdz9fjnoUKoe4GR4TZvutH263jo 5edFqBLY_fJEWM.7SS7FSoVkn.LJuIylkIiRS8hJvcn1nV.JRPPZQ4gA7pbnjmK7x.8EuTgbO80d 1UlzcsHY_MVE6T3KLeg0BF0750Gh8iVuql99IYoJAOrNu1AGnrtWlxTGllqS5YGGhBln3Yt0jge4 AMlyasskGwZ5.Q5M1hWvkxmc1WPeyc0ot6Cu_BMD39IydNGi8AMweO.xRURbnv.czsJPG5RbLu5h GvrcWRGmMVwaGEz0Qmf6kVvPAWyMscGux.M.8EjCjgJ6N_OsVIoVnmu_iZ4XhK.UI678j4N.VxX8 y1Xrdg8h4Oy59jn1PtPLzGPeKVZm2HVp3VFWLTvY6H.SMX_Xtcn2MMIqce4MA0OArNGzO8rBCYZ1 QQo3Ly5pOgKsQtEAXu2jBnK1Gvt62gCIhxX7kiggbKHu9w87zyS7gEDktZ_X.ZYMFH_0F0swEg4i 6ZVIbd5fUjAYy.EsR1OkbDVZJF2gokwNjnb.kZVLYT2CP7KWQ_TDKzTeFPvDcFnZE45MdWwq2qQ3 ebus1xJqOEhlGo9SydKnZi4gLERephEoOYxrROfjsSYCbpVvjqPphVR5iZFwxq7E.r1XRqI6YiN1 Z__epouXzh9xhUdRhkspMxFqJm5Md.m1cXy0dhdII_K2lGkoxJTpNk3INbJOJ6t.J0fCWYGQ8NFg 8BSJTzev_th1FRxJaZV9Tymt3eOPCIhmQUcFzFYvlHL5kZm8P8I9ZgsPKuk4Rl3Q90378lOtNQWa E3pg4yreCjUiNCvu5IAAHOrUZFHz8B9qZdd4N189snrMASK0wZytVW.zeLFb7navAZTFd4JyRszu 83B0AJmDXyBFlw1gfEU_BA6x0sLwu0vbPlcCtoIPvEtekpqPt8kL9q3g- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:14 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 909a163ce0f03793fff6be9a79785446; Tue, 09 Apr 2019 21:41: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 Subject: [PATCH 48/59] LSM: Use lsm_context in security_release_secctx Date: Tue, 9 Apr 2019 14:39:35 -0700 Message-Id: <20190409213946.1667-49-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 9a842a20b4b7..3b1e482f7b7a 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -435,7 +435,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); @@ -1224,7 +1224,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 149cceb5e366..fbfe20891a9f 100644 --- a/security/security.c +++ b/security/security.c @@ -1996,7 +1996,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; } @@ -2009,13 +2009,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 Tue Apr 9 21:39: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: 10892619 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 B25F21805 for ; Tue, 9 Apr 2019 21:41:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A40B8285C6 for ; Tue, 9 Apr 2019 21:41:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97FC428857; Tue, 9 Apr 2019 21:41:25 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 B832128857 for ; Tue, 9 Apr 2019 21:41:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727002AbfDIVlY (ORCPT ); Tue, 9 Apr 2019 17:41:24 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:44082 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726959AbfDIVlQ (ORCPT ); Tue, 9 Apr 2019 17:41:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846074; bh=BMsJGQ6hiFpCi81nT9ABih4oXCjQqCjedI+OyC1staE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=md42TtvJ0ZJ8wisJHrjYmbnZDH6LdAKW9pRaamvTJrdyDyuVTA8JOoT1/a2jIpIk6wmmXzMl29mAkdbv6AXbyuhK/GEl4s26HeVh2x+jz9i6XXS0AbV6hSAHDQImfvzgElULceJXHg8qNbrxCUPos1P2lqKiNMd8D/71E82KE+2NBZ7OMSViUWLjLFLmVokRE4gr0serLJ0T14OU23LOkX001MTWEE/hGDIuGpep7U8SujfkhlbtQlpfxR0h9LnMVFuIjY2/ktft8zlpWP5Pb8sJkm+afZ/kQe6xR5iP1ByqfBMoj+Zsmv46olSa9sucqtjwWcme2ePJEQGLbR2gHQ== X-YMail-OSG: 5le_AhcVM1nkgtwIFr1gUsGuIcW_8FSYsERtekDTbm32lLpDdR3FW1X054I6iC7 NdegXa_Jc9UN29NAyINrWz8PzbABHziK6cSn8lJ7MHI2bqMShkKq9y8eO352vZA2r53yLq5i02Rv lDUzqu6TU4V7A8DEPAJ6U5sKDyWZ449aTK299RMhNnafezhJY4WKx21H99VCSnviYbm4ay555cET jOLSKqCQkOaaQaYxcR5PR.5B0iVcFtCVyDH.NzaBQQmMhM0ZyR1mtB3PS_1wqB.Ylqd6PayGpsUe HafZefrdIBmaO6VbrqpUR_WBfwS_tq4kL5Rulq5OCoZmPKtqMee9sjZ6ajGsynTY5GnC4885dze9 WbHSDxnAi3WBt4UvQheSCGPy4XjsSELIgrM4HY6yzla3V9dz3oJ0Y3SavESbmduJFFv6YU8L_vBM MpszFAasIWcodx.HvLT0XXmOTk655OdbicLJCfVQgUiKmDxRfAEyLnTbYgxGHdhEIY2ZxZwg2RYv o9XNCdq9_o4crVm2R5LyheObhDJfP.mqZ91o9LXM4GoVRkc.onFDH6MVe9759ssJYEL44oM2JguS Vn2QoYW35COqoxoA23xmoX6o6goIka0kuVXXsCtv.wOfX34HffBbOg8cOaqesFiwkB5nfHvPRS4v tvewtastwLKA.MmBlT2ceq8WWOFdrfCVsi9WKws3UgwiUUaW9.PiwmU8L4DRnbufpivsL55Hoxu5 vvIc9SCSkELW4YRwzNaeXYGzDcIUcJfa8tA9yocz.yb2IiZmd1C2hOEXIZOXsyzJIDRRGLabl7Pb YXBZd51Hu8lI4guh2Mwejawf3iRBHzS5pKaa9yoyPrgZPqpvPVskOYWKfCCTfOOEXNt.R7Na1D0F qhO1b3h4J6C2d1vbtdkLwmEDRqC56Z9iGYkWCzr7MidHjy4MN4KExZM3QF27Y36ItBdG1gj9QHOK ap4SoyMwSda2Joo3OwJunLNl4hCVoho_i22fDGcDINbvTSgQZa6Nb3Me.ZNvZ3mTWHDALTTJDfDD CLmK.Ljb95TbrGWe0USUTBn.H9b4oC0PkTmyeXiK.7CMZmH5DjupSUCByqqpLXSg84dAv1JF6cCw UeLlSx0FyC18bpBXIzXsoSkXCu8lsG3z1uTARQqwbWAXiAou363ELF4urpCoK Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:14 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 909a163ce0f03793fff6be9a79785446; Tue, 09 Apr 2019 21:41: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 Subject: [PATCH 49/59] LSM: Use lsm_context in security_secid_to_secctx Date: Tue, 9 Apr 2019 14:39:36 -0700 Message-Id: <20190409213946.1667-50-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 3b1e482f7b7a..0ec12fce69e2 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -84,10 +84,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) { @@ -433,7 +434,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); @@ -1213,7 +1214,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 fbfe20891a9f..7cc2ec984b7d 100644 --- a/security/security.c +++ b/security/security.c @@ -1987,18 +1987,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 Tue Apr 9 21:39: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: 10892633 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 557C217EF for ; Tue, 9 Apr 2019 21:41:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 470D3285C6 for ; Tue, 9 Apr 2019 21:41:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B44528862; Tue, 9 Apr 2019 21:41:35 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 261F0285C6 for ; Tue, 9 Apr 2019 21:41:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726565AbfDIVlX (ORCPT ); Tue, 9 Apr 2019 17:41:23 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:33591 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726744AbfDIVlX (ORCPT ); Tue, 9 Apr 2019 17:41:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846080; bh=obxKrBiGm3LYlnlm6RakpP9K6J8LRUBE6b25/AUVMcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=GHW9REdsKqBQdqwtidxbnIJ7dTXbxC95fHbb7bn7uXkfMMDPai2pKxkzg1iNh9BoU+UECUn+JRaJxik+1hbudRaudogBckbf9nqZyvJ1K2GahcvDFarNjfJR2wqjXBF0cVv5SQu3xmHSIMAcjXx/XM6OCafFIVGNgeqSr87g/EbQag4ThecHdGBBMMFeVqIOCYY3GPcIXOdoKYDuGecWvgmkuRGgjbI8oLKEW03oOX315+YuHtychTlyOm2LVlRPHs4XNga8NSkm5dMpDNe4jP3ffOv8GkByeohW7M99sOH2G/tM+0edNDz++62z0Xz29cZUE2aEiYHtbqHe7/HX5g== X-YMail-OSG: Y2tkzTIVM1ni_sOX1OIM1i3kpz2aQmSLrPq3ZuHH3CtKL0s0mQCY2xY8XG1uKQr v4nDykfpfB9W7d7tzdoCnQPtTkEKPRdsVnXOS357I2t5WCxO4GYZqnMQEMp6MA.TZt7k6UykyOXl WL.MmStVwlwvBLI59PIWJQ3O9bQt7F3n6MSNLqftfZy67JLJ2Nb7SSJyGz0PjgbsFSHetfgoJgeJ ynMdQ6qO7.x2xLy438E6rbTPedI3Z1IK8elLJDjJ3i8tOi0H6GYUoe_I7fsJ5o32i02pwJrwpxBX 21mlsWm8a1t9926LAOFyaBnbVo3UtKvrogDd1vlD2gCtVJHm1zNgNHxzJ.P7jga4HRhnjsc4DjM4 cWO_PHPcjEU7EABpht4HOdUl7Viy5ttr3A_BQdT6Qs9vgXrHwPlsaMaSdUdE8HH5TVL5hpvEuGzV FoMAex2BLxrbMPfXRetIBlqscR.Xek4eQbvdxrd8g7vPu9BgZNTtGXJiJN43poAf73mUD5JrbKgh Mvxn2Vc7kWh13yJ9uccTUD2_bXSlzeNQeiMn2lFMus87cg7b8QjIskCc5gDA.r6MaAd0.wARQ64c jjgpYptBWkY1PgajSxDMZga29lcBcXJZ3qqoguM8ZtVq2_e51uBKJGvX4h9FX6VG1D0sRzUVlLu4 TcKdMnnAkM2eRsgL1GFm.q4cydA4.owV4CbA0S1lrsCclF_WhLNaJcbYogHuU5DXbwW8Iq8yDcvC 2bm0DCIcy39vDU.zA.K.IE2GyW34FswFEeyOSyC0ET_5RPDxPDA8dsuCg1661wGvlDD7VB8HaVDk PgEF92KB4uroAGjJ7nVkzPvcAULNsFvopbg_w6BpAhepCbqZgzfCEdFKWwzHTxonaAcNpnbGdL9l gOacjiRhhZIhO4xobk0ZeUXqBHj6BdWebkLFMkVjEcnuYJKatKXVzD6YCAbDHvFxfHrMBkXZg3b5 bYaMAWXjziG8OEkIaJjM9a1m4fZ1OUQctFfs.rE26toM_YhR3f.Za3408vA.9pw.O.V_pTtRk60t UKDoyVWa453h8LiREzGP4nDNmd3fm71fdpMA93uYBat9Yh_DDlt3uFCYttJUFscL8EnEbCqW3Fw2 CrLYgi7MZomWZmAGmWP.sjIZJH86x0FWKKpuqbG1KkKLf8NcK6Qs1EKGtT7qF1Q-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:20 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp424.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID ef161db9af8fc10234759f56f4c7a0ea; Tue, 09 Apr 2019 21:41:18 +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 Subject: [PATCH 50/59] fs: remove lsm_context scaffolding Date: Tue, 9 Apr 2019 14:39:37 -0700 Message-Id: <20190409213946.1667-51-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892635 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 74F3013B5 for ; Tue, 9 Apr 2019 21:41:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66CD3285C6 for ; Tue, 9 Apr 2019 21:41:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5AFE928862; Tue, 9 Apr 2019 21:41:37 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 B6F56285C6 for ; Tue, 9 Apr 2019 21:41:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727048AbfDIVld (ORCPT ); Tue, 9 Apr 2019 17:41:33 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:44622 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726875AbfDIVlX (ORCPT ); Tue, 9 Apr 2019 17:41:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846080; bh=+g7G/wVBjyt3VCLj1TPz1dLjB4cw24g67qHyiWgofvg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=H9/33EObte0TyETBwf+CNYvi3Q9AQRW3e1nYiWgtr7M9RF3wdQOyBphZUUKijRUOMQ+l/DKBNu/sz8OLqwCvM9GdThL9v8hVm/+/1IgCdk1hPARgTIvTZYpGR7Bwi3cEogKsQfVp1cVmJ+RG4L0o7QuVZpEFKSC1XIastr7v2E89LDjOnFL+7pxW6EVdpR+tR2q525Ds848ww4xGsVHj1R2XEjl4nugCFVPM2gh37lazQLqRtVffK4ekRQ2GZeZ/uvdg6znLjzcVoVLEC2wZZe7JMXUQZCQPv89bXfwNNX0bBgqpS/qO0mAnYCw42NaofOvioaoVFldS16YTgsNkUA== X-YMail-OSG: nJqm5swVM1llEnPb8xnDgu1jf3bL3EkfYsS_E.mOFKNxtnawwEg8Pg7n3Z85VI1 kMB7D1SaS7b5oy8yoZ0HCbT1.2KmzM1dIuOCsSKB3E0BHqaivT4xvCKiA_OEwnVeWOupG69m8jUt St.f5CghM..f296Fm7xcmmr.oPs1ArZO5xJLDXzTFtDayXaQB8Z7NAzaprrjs8zybvHD4LMCMbrq sbutDZm0Y8kHfHbqop_Jo4U0XxnI8OfVhcJzlqY_UMyfhIzf31dnSwhceqJRZ8iNRp6DlcaE5.Hv L4wq7ZMtd47myzrW8Cv1kmuwFtoWCYtzj_zAphpoXHoOk62Ipb.OHGRiwmiDDx9pT5M018pa5Zg7 9aIsbmu0VrfpKwhooXaQrjIDtHFRQawxzF56OgXNBtcTtI84gxj8t0nISnnoYrGUQN6mmzGWxvga L8OM8t_ISVKp6NZ.URsaZA3yY3LOD4jIiXHyQqMI6vUf.af7eWwcRcanKCWQqBgiaOE0isG5PDx6 MdIuFFdRrFW5SXkahO11ApyivIFOeDJE2e3eAF6fjj5m.ctDpL88nPuIZagcomX6AipAkAimwFWg Hg_Ha1AxmMOOW2re_b5FiKDyuFDRg3qcmdmOZglNN35.xo5B2OghDy_7v01gTKzkNRfseb5WpQ7B DEi_N9gXL_a2i_EkNyPl2UG1E50_tIWUfRLU2iU_wsaeLKANLq5wsFMAuY3ylP2C8kgCluP9MoJA pVnvWS..yZhINaOJujtrh10LtLtNOmbnOqoU7w1b7EwhxjnRH.bvfHtYCTsnwoVN.n5HJlzLVywz Y.VHv8J7lmBtjhQQBqMiDeEchGtw6irG3yOkTo_l9hEIMNU47zpB641Edq69_oLDFsv_vp9biDhK .Ta7MKeOW6HdJUVprBLOheur3PB3TPLybjhda2d6dylJXykzbbjPwRas54VqFeS7QZgt24NGeqWW uTaAR5rl0_duubn3r8BlmVycoP4Q534BWrK4RXGlSRvUvAEunEJREjRQhLxwxhtmJCVx_9ERsxNZ 8bEoDWW4ctUahQTTRBzZ7es3GBKwKlBli9RXbxpieSPDNQfgQORdtgVnA5sifOoJfN._FVcCXHBb zXOi_VqhBMQs_MXgGYYuSseLfAk7GiBVf8_ymHyel4CexOSc_KPyuw9dm6cCECQ-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:20 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp424.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID ef161db9af8fc10234759f56f4c7a0ea; Tue, 09 Apr 2019 21:41:18 +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 Subject: [PATCH 51/59] LSM: Add the release function to the lsm_context Date: Tue, 9 Apr 2019 14:39:38 -0700 Message-Id: <20190409213946.1667-52-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 11bfa0a4f188..1d364e211639 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1329,10 +1329,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: @@ -1670,7 +1666,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); @@ -1947,7 +1942,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 0ec12fce69e2..76681aca95cb 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -124,6 +124,7 @@ extern struct lsm_export *lsm_export_skb(struct sk_buff *skb); 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 7cc2ec984b7d..8bb1be7f2b85 100644 --- a/security/security.c +++ b/security/security.c @@ -2002,7 +2002,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 Tue Apr 9 21:39: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: 10892613 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 C456E186D for ; Tue, 9 Apr 2019 21:41:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B29BC28857 for ; Tue, 9 Apr 2019 21:41:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A791A28862; Tue, 9 Apr 2019 21:41:23 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 347D92887B for ; Tue, 9 Apr 2019 21:41:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726570AbfDIVlV (ORCPT ); Tue, 9 Apr 2019 17:41:21 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com ([66.163.184.50]:38822 "EHLO sonic317-39.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726998AbfDIVlV (ORCPT ); Tue, 9 Apr 2019 17:41:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846079; bh=OWoo7vTJwcNQK6ycCy7jbnovWFk2r1PEz4nld5sP+to=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=U7q9nuKPKN4junGR3B0vJnTLIIjpcqG9KvmQ3ns6gQbepA4VDkhrkHieUbFIdpJ2pJXmqHeL/LTRGnHuSGEY4qDk4qKgrvvuVO1d2RhBAV9YSjiMqEwB5/tn7GX5TP7YwF/A7sjx9kjX1yW0fLxmQqjkpq9Uek/VNRKmRaRLXAQzB4QY2PkMzVkYC0iyRPWP8qkOfTGy+XGfcw8ayyuDrJ+2BzqWIQJ3gWqAQR1S98Ga1xc8EyggkDHmdzbFX4VBlcB3tzcgKqKiE50mxbEzvhF46iLyNjwTOmoyzLO3OfhAA16acDJOcurEGqwev3QNIPFkeTFQrS7gd7i5po6QDw== X-YMail-OSG: 3Pvm_1AVM1mCPR9xZsyDJMjvAFwYi6rpHdIq5Gn3wXQkFCCiQXkd_3iZtIUcVNI UA8L9PqB7W7aLe78FD96yLUH1jNEWuoPjlSvQVJgdDx8WlPA6DzgVwtGHZpk4fn2dMU7d_8OaHSp 8yt_c13ctjgJxgFIG9gqSA79gy_hfQXZk6gWQL17tyZVU37A74E65gynUhFlMYdEUMTPZw8K.g8I nCCLZpiX.wsEf3x37yr1EVB8jQv2xIAykAk7Na_dIS_ISOlTVmnw4B5ADvGTfFWZObuVITC63_gq F5JvVWqjX0lLcQVJAHE0dwy_BSGSCUiuvcjjLcz3XgNcTiZ5MybPVsmowqLUngOsYtSU_mJqkU7U jYybV7lqjMUEu4OkA6wE73HAdnNt5Yx7qtfKBunoh.3AnRR3.lUzKxYI..lpaZVDQA1K4.EQuy35 2adyvE29sBBCu9mjuQiN5NDVTEhkQ8OCvqbpi6SORauyghZd0KZDKcVSbPAKhdaApxVf0icSN8vb 3zZLzYrN0ABvjaNWGw9Rwk1Xh0ShSLJV1uBXGShXFLTTdErPNeAmuwpR5CBONbPn8hBdXO3lvgxF 8K_FxFtHKpCTVUefctYQbBQQ5YGoGMOZy.13MI6V.ToFiksCpOyak9CY0_U5Pnr5mwxQbtpiySyC 8PDVMSSxu4bzourfAC2nVuGMA7FHC1TQi9jbT2r5p_xRhw5OE1DZCAEM5Uj4zBOU0kQ_556hw8NS yu2zaw4dTiW.k9.Rvvxn4lC9WayeHWxyFU4z6vFOr3kVlU1zIleDks55DoY4hYRuRjC7RJlR4zSA MLs48G1uEUp3yp2uzFg.Tfb0QU4ix7tvNPg621cMAJLdStvSH38Gam4K4ZxqPQ1w6h_zKsnk96dQ 4irfrlEcKI0bpeKZLMiaYiHonkpnpffXl_N3xQNEIZogw8ctJ47NswMuv8UbGo6VijqpFr5_pZIj DVv5BMtcxziyWtw.QF72OoIhk9XXtEGu5TkSZhsxWJUOPO57cnb9tm5BFTlsqwU4iN5xr6hFxqC0 5nkQFIi13ZFvivXNapuT9X2OK8IoE2Kowj2XIiOf2lCfk_P9p_aMdvFSZ33H9MugZqTP4CJTI3Ww 0Pt4yjxI6SHLaggus4t6wYnXwxh2T_ha8DsVp_G4Lh8eJ_v5UBf.Bc23U3iyKcw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:19 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp424.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID ef161db9af8fc10234759f56f4c7a0ea; Tue, 09 Apr 2019 21:41:19 +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 Subject: [PATCH 52/59] LSM: Use lsm_context in inode_setsecctx hooks Date: Tue, 9 Apr 2019 14:39:39 -0700 Message-Id: <20190409213946.1667-53-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 1d364e211639..014791349bbd 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1390,8 +1390,7 @@ * 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 @@ -1669,7 +1668,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 8bb1be7f2b85..36a7034d1f91 100644 --- a/security/security.c +++ b/security/security.c @@ -2023,7 +2023,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 Tue Apr 9 21:39: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: 10892627 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 BC40713B5 for ; Tue, 9 Apr 2019 21:41:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE97D285C6 for ; Tue, 9 Apr 2019 21:41:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2C7C28862; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 42E7E285C6 for ; Tue, 9 Apr 2019 21:41:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727032AbfDIVla (ORCPT ); Tue, 9 Apr 2019 17:41:30 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:43376 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726787AbfDIVl3 (ORCPT ); Tue, 9 Apr 2019 17:41:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846085; bh=dRfjl1AB3/4wu0T+48nviV38M45041jZ8lVQvnspWfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=cwow+n4FuoiKRlakPcN1oixDYawkXD7Yse38weNGLYxWDgkmCS//yzU7b3BxOTE6isHvjP7HYtNboctfc+NCuzRSBgTv0NBwarEgzU5GjHqKlqplfCtJcO61DtmUiB7x2sRcSt+iPFGIWoacz7/SviWKLWTpk7fJl5pNne0EL+vsCFBgduaUdxEStz1STio2yfECjUW4VfjNML11aCkjSAqx87SYsfTKIIzA18lJeE0YXFgvnFgWOvGXjIgqRkWH5dsyeV0t1TgOHYi+Rf4eRZFryKPCtvdCcElPbsftwqH6Zut11L+W9fakbHIlPHEhwUaG0fSSlCyPymSSEVFVmA== X-YMail-OSG: NY0WupEVM1kbr3uLIz2bYjTrjQbNPJBwRG1IAtr7FnZZbW6K8WYWivp8sU_uoKH lPqu27on82nS5dBI36w.gwYVVzXO361z1aqdBIRAtDUq55cEKHhVNQA0AHfC5qsS3PgLD3agdCc8 HmTOz.X6rQ7FOEgo7wFGG6Hc9DhP9wf7MrPaivkdDEQoBDfbMxPRexnVTrsiLVWpXo22hOfctL91 _922eOXreNyFUwjWhOr.0EJgB17qvrfVKxJn4PYGWqItnugvn370kXxMs84hJtcyew53GTPmqhBw 68cqVfcTODI43HdP.XZZCeVbjF7DJbNrubLqycPDojtXn6jjGLx2f4cO9AWX2b1lbN0jRN4MHgNx .sLKo.zxTR3Il3gVLdfDFlGlGg7WGzl1S2Ty3.jVeqz8G97I1teJiUxrWQTgmAjFiya0FsTaLOwL O9x8.DrSinWpIP3mCMsI_xCpTreWllKMF3I8_j1xuyzf8WMBND3PBauprVvRbfV_sbLSmvIV1mFS hbf_Q6_plbTUw0suAhEUB7JSXmoirCDZ6pr2mYUcdC5XVYp9TNpDDbFrvcRBzGTrB18wFZNqGUIy rif7Homb50PjIQTSTVFuNmIb16A6K3QzQxuhmFv87btIV9cjWAunJiq7m5qB6Qerk.me9lUta0tp Ryn9jOeKhnJyBhRgVOdGNGyBAEyc1laz49c1NCFLdpK3emJ7jgpFW01O2YijqMjGVopdFOtmA7iM RtTByn5n.KwtLkiNFZX5Z5QTNMc2xDHAKA6iuRc_hDUXgD_zdGFRUpJrh.j5Q1uIc4aGCmj20pwF l9pZoNE7D9e3CX4eWu2ESfHBzPQPhquesV0FkpagKyZGp0JS6bLUF.DmGvhTfUUlP8OV8UKw5ktl ikzTJR6AdEV8s.K_9wZkBW08ua914zzcv7AZjvuVwnBdhPGsFuMqIUumHOGOU2bM.V2jTqw2SNKi GSNotIbpW6ixNSWvRZXbAcRAVktXVY7zetRYLPQrpYkpmGqzdiF_5XQtQR9q5dn9JaIOV2MnZoy4 dRt3XlVgX3altJXP2NavSLq6LGyxTQzUCaWCVg9SUt5g_7cN9vPqD9rbOLICLU8FrDf7BtbqoEHw Z64sKVGBua6DpWlv1LsHkOqTde3m3YMZ7Q6bRUiRfO.efCvqY0u4bSH9OlXKkSQ-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:25 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp424.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID ef161db9af8fc10234759f56f4c7a0ea; Tue, 09 Apr 2019 21:41: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 Subject: [PATCH 53/59] LSM: Use lsm_context in security_inode_setsecctx Date: Tue, 9 Apr 2019 14:39:40 -0700 Message-Id: <20190409213946.1667-54-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 76681aca95cb..38bb4a5f52ce 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -441,7 +441,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 */ @@ -1239,7 +1239,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 36a7034d1f91..1b4b74af0cb7 100644 --- a/security/security.c +++ b/security/security.c @@ -2021,13 +2021,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 Tue Apr 9 21:39: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: 10892629 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 41AB01805 for ; Tue, 9 Apr 2019 21:41:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F2A8285C6 for ; Tue, 9 Apr 2019 21:41:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2333628862; Tue, 9 Apr 2019 21:41:32 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 C784A285C6 for ; Tue, 9 Apr 2019 21:41:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726787AbfDIVla (ORCPT ); Tue, 9 Apr 2019 17:41:30 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:41183 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727035AbfDIVl3 (ORCPT ); Tue, 9 Apr 2019 17:41:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846085; bh=s293PbMAjW22h/8ubCAR0YEDBHbqaLOuUY2hFLr6/0s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=DO5u7/67y38MJVqO9ctbWi7C7ly/jeij8fXqy6Yw0aJBGObY1OpDiVW/Vu1fU/+kSVsxN1xHGNrvgLBIDR4EMFYIhKzDHUd4jUszX4iSQWw7ASc9UkaLxgUU3Q+NK3wQv8w++9XBMVqwlz/71OHNczUFHSw/2xKRMMPGQmgFXJtL0lX6fJLErES7fdyAt3J2azZXSLmxlUFHdpXvZJP79bAdR0jYBVTc32bafwjuVOwjHt27PpnlMhyMHmqShZyJG3297eA6dYEE1P3TPOju1zRdm5j1Lmk/vzIGkkIwVXNT9Rr4haUX4Zp8AHfErKtGRIiTqCi4Ih+GUEuNF5AzuQ== X-YMail-OSG: FR6yTNkVM1nQIABLJsbzFlrlo6sEkcot9Bq2PxFlnmr8b0NTOBGmmFP2vmmIHdT ZK3BMkqwx85jnSi5flhtmPn3cu1x71yGtcxvswtIBXEE4HPixtDCfMraCxYNGrSjN7QnzLtzWkgC 2YKEscmPgyuOH3DoHap62O8PE6.ukuNjIRCtwZkxkHELvv1MBjeVTve0ePnX4i_Ul49v2il918Ko tVHjn4cJrBn7Llwrz_zR_ZjWJYLvw0JBOtPhC9qWbBbog3Y09KxBdW89Mv2NYfZNWNH_d8qW82Cp _lASR.2CqyWdUyUSf0FNIJvutrWkoagh6JaUgbaSuN1SDvX73rH6Y.P1EM8p2Vd8ILj72uVo2mtS pAyIe..R_NJ2eh5ZoCZ9u8K14noxG1TKbRpswLwFHAOo80Sb9V9f400kRBj2CfG2SYbppBtacRUA 1hdKUPlZjG8.VkaWwnsTL953ddE5h46qR57NX5vGzzclKi2zrCGFtxR.KHESKrjEOQFhXEXVUufs 1icM.gn8i01F88ZDkgQyHlZ9OCS0.gqS1UKJPY08BTJjol5RJ4rEiae_MK2VtUV2l_WqLUxm7zcF jn3g2nxfteUbsv7RYboLhLgtVOi7leioQIhN4RdIcd57T8qLt5mSx2TMwYzlPZ7jeHyuqUjZ4gYR w5W1.PFtCPo5p3iWzyvMnHD..Fhgy3HB9LSNGhHPqlkpma088fUG3C9lm6TumFvWEGt1WeEB.yGD tYOK36zAQdcCZjhdvpNHTESYbz2t.Pu_geViaP7biIPLVrj8Ytdt4SUQ6PvnFmIXfVv2r503CT0O YPVnKMB_bDsK5XByx2.Sr6ZFjOBiuZ1Zi3.M_nTsFiGEocnVIYI8fWYI9f7SHGbldfBPbFLIUMub gbyYm0ZDkAx7X6VS7Bedw5Bb99YRepKG5qmXOGamZ.nKUWWFE32zhHpJp4ma.pi4MiXi2Cg51YNg QWWgy5BzU.DsslPMI3yNRuSqGS7HF.AtysRhuCREmXg3GwAJbbIWGYg5OOcgzUEXtB51rcgk_nLu 85DX5bGFPrxRmnpnnQ_TE1QbsuIFT01PEn0O0ueES1nHjR7XJQ2O7ZE6zD2ztb6WicloWeIAbGkv cCmYJn7QYR2t6B56OPdSIFq6NiwAhV2OIcndrwpNfuje53lDQLZ4W4hRwtASsww-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:25 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp424.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID ef161db9af8fc10234759f56f4c7a0ea; Tue, 09 Apr 2019 21:41: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 Subject: [PATCH 54/59] kernfs: remove lsm_context scaffolding Date: Tue, 9 Apr 2019 14:39:41 -0700 Message-Id: <20190409213946.1667-55-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892707 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 2D2DD1805 for ; Tue, 9 Apr 2019 21:41:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B1C2285C6 for ; Tue, 9 Apr 2019 21:41:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F61E28862; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 B52DC285C6 for ; Tue, 9 Apr 2019 21:41:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727057AbfDIVl4 (ORCPT ); Tue, 9 Apr 2019 17:41:56 -0400 Received: from sonic304-28.consmr.mail.ne1.yahoo.com ([66.163.191.154]:46290 "EHLO sonic304-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727144AbfDIVlz (ORCPT ); Tue, 9 Apr 2019 17:41:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846104; bh=+7mmd+MXJOKZKn8VAeu6zAtdrRYOBd+PhCBuPJj/JDU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=k4yE/XsFjV7BPXv3xqAAWIUaW94lE+diDQXNSrrV+O3UO5+bqbMXCkCs27mt9k68KMLnysUDOnZQtcMLyOv5S6GSWOPFc6VCsgT0aeNUFz0qsAWm6wCOJUo3vTKI3DWXmzDLIkd6fVSIVALutK9iFW8A74RlSUWqzYuR8bF4cP+pcrLbDH/DF3LLKxa1HXzHK2lZqbxN4qpkO/7kac8PvlZ0WivD4dowc29VmkWLTLNYIqH8+mVsbnV1LKDDN5UbKax2wprDxpfzJ1aqnjEIYyYlWYweFVQCKkwsSDdT0lcNaqgYsh2wruTQJR3Ey+sqf/B79ZkR7BvrJ9Ha+JXomQ== X-YMail-OSG: ZrxelzAVM1ncVbXXEjJtv7DyD78jzz7vpQGLBYc1ngmVMshl6ULuHJdGSQKYZQ. 8i6.PdwBnsu1bcQD6BIU7esr4mFt6emTruAPrCjIPBAy16Pr.lbGAq97V.Wf3qefYmoTpicMs7Vo VGlG7lNRR9uo7WkZblvUOq.fyiGIyxLCYQBVCu97181NVrBIDXlsaiZCEO8dh8k.NcR1Il2qsVGk 4oKJ0McjrBqBUTmcM93m5Kcl5GaM9wJYAoUUC.8NK4D4kmzn7x9T7ONSqQ1pbaQTNy7K_QPnyhKy suYqoM.zWpjKHsB7jfCdQcUShFg_cjOYlb9AvqtN_5_m.pnqz5hmOzNDD3MC42Qa4O6m38iTHHct RZrTt83GnsSXVrfJS6R6Nf.IQyMSzjqsarEVgwGz98l.9Ls_jgDNot7rfhOYguuvQNmFNJe_mO7x S1T528euslecBBwPgVQlXAsvSo02wK4mesDvyzw4vBOjR9nB_jbPs0c1WlwUGO3IA2aamwQWaGKJ sQIVyyGruRYU1t26_nLqEIELoiApePrUV_a1.tfdxUeZaVfZekYbFs9g42xHeDDDo6.TV9ys_e94 1COYnSBBWg.fkMGPi33odMM6MXPSvxh.Ni7VoZYz.0roUziM0M8uxXRtaLkH5AJ2vUvBUv67klSR EpxPyDKyiGOrLzbQTfhvMMTXtcOuPdV.v2Nol8aAtYhQFzqfGAZ979DfVf2ZTRwWUIHifkOoZJ8C Mrjt577RWO1A3kiShQeya2uFR2HQG7XwTTywS209R2qnpUXMDjpyNHzU2yRzl9DMdEDTCXk0Ierl FZJM9Uy58WrnZlYPF_7DpJrr4CIStpZ95YSVUuxi_ufnRFPWXYDGVU9sZZuP6ygiJO3Ql8OmgGmT LFgS2w6TVjsYuRdJx5afyVUh9Ed2dWT6Bwy1JZFrnLxAImlpQ9CTE3QX_C5bmy94pqbziUkWAck0 jkn8yO8ZCgObFiXMNBMZKgFKGC3StOFHeBK.AsaTzKdPySGEX7O9oAvWY5EEyx9CKX2jBi3kUMM4 .4y7yTGZZocn3seDzpRSKzCxDNnVH_biAgDt2XkIBMnu5wkm9qkyRSvVvAG04V6nCZvhM.SBNunw u7nOIGAmWWli.IvqRN1PObYr9N2tJEplsFu9eLKJuvQtBgTGyqsrBTtYRaumAgw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:44 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp416.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 3e563602cfa877b5908e791085320721; Tue, 09 Apr 2019 21:41:27 +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 Subject: [PATCH 55/59] LSM: Remove unused macro Date: Tue, 9 Apr 2019 14:39:42 -0700 Message-Id: <20190409213946.1667-56-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 1b4b74af0cb7..ce50054f58a0 100644 --- a/security/security.c +++ b/security/security.c @@ -713,16 +713,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 Tue Apr 9 21:39: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: 10892705 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 243A818B7 for ; Tue, 9 Apr 2019 21:41:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16751285C6 for ; Tue, 9 Apr 2019 21:41:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A9C328892; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 A7595285C6 for ; Tue, 9 Apr 2019 21:41:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727159AbfDIVlz (ORCPT ); Tue, 9 Apr 2019 17:41:55 -0400 Received: from sonic304-28.consmr.mail.ne1.yahoo.com ([66.163.191.154]:45119 "EHLO sonic304-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727116AbfDIVly (ORCPT ); Tue, 9 Apr 2019 17:41:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846104; bh=l6hRzUHs1qLEfXiPo6JWIN35aWkJvJ1zUm6OHnbsNzM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=kbdlnl+pv+6zUqnIVxnOjJ81uQeaNWrSds9jTGAW1YtIcpoYlVDoleZEJX+4O+suEorDKfRm0UnzJfhydzL0IK7pRaP9BT60VyDuiJKjFCsSvIWRCEsJ85nRaCo+GceMbQZPP51iQPt1cB9evCxKZ2gTynTuDzq2n/O1d/w/gki+1yTSz902OK9UzTKHVjFmEi9K565SSNILk5eRsIaEjByneNs9wov967nEY5BE6JbjYGCzihV/L84LRoW1GLpEM67x94McRu6FGoIU4NmuC5u1r+xnI0hlVObUoHJma9aiCVqc3nMZcMCPkcOj5dAxugNRdRJ/NAzPOOn9N55M3g== X-YMail-OSG: iNBbxMoVM1n0V4dQ4RxuRHlQRJ0gmlrcl5I5kZmo_RZpHuGnFygTPrgxXvVQRjF sbmi_fYRiRx6T3MKmCVAGOMS5bw.tQYaazhayV6By6lGEJ4oS0.SbNPZY9qR8fI434vrOjXHQetd 9GI3cTxmqvZj8JyfQK9zmeBMDldk53ydAcEp8n.IyMul5lBqU3F9dHabUvyOgTqyz0aHFVbRt86X 1Pt0gQ_MEjS0VMinVE1f7f._J3jSD0zzyH4Pv30Zw2k0zotwkwvGJSbtfZQwW4pZ6tTWEMCFUSkn FzsSQge4UVIsFxPubJeUXlPxqvM_KcwuD_1lHV.oq2oi6c_KwxL2TAGeE0bw3rB6faUVdZoRzqDX 55dOSJO4YO5T6E7_1FuNeM0RGRRpYaRFlXwkvesKLrVbu2kq6fqs5YLvhIHFi31jyPqItXu.0yOo CcK66pQHKEyyZX_DdDKcGyxw7Sg6nyJBo0QPa_Kj988aCzUb8MH5XC3GcR_VRYwDmrjIzSwCbulb CxlZ3pAXX0cOXxMlGUtxfUnDwwjP3tVNX3yRaqhmaS9bPuDux7NJUmn.KJy62CrrBJcTCzoJOsVL rJkQMyuFKmZZGFmu.99v_rFK8d_GCxxcCOR8TEjIy3tgLb.PuBw1IkuU.zZNjtyPFxU286EgVd1U XP9NK7ITLamzTJmmYPKHNW5t8ABMxeMlpufiHGEzzz3m_SKrXQNE015q.CojYT.g505j3rgdjE_X 6zb.LTXi9YfAhP5hU1XsdI.9XPyTTga55JO6xMwhMbCke6jWkPFlT5q1qAX0bQDESUtAdy6tipIq gkPAPGd3f7i3Ol4yOHwOOs8mI7UTloVKlxss8CNcuy8FmCwBkk4CIWXTjdH.iDWxs93Q2O5koAJT t3NZFw8q2F.QlzsmJ5cPfUudCfk5k32I8UdQVnEvd1NHwlDa1m0Ps0btD9XG7gsp3eMLuKCXPckL 1Uf_yag5fXzGGGlpfA4lRhYx5iz6Ki4mohm0Jsc8orwdWx7AclFZfJGD4hMUMsJUQ06okiWWX_v2 jYf1IIOHkFSdjEQN.Ifc5UDN3YPwy4CsGUTEtk63G.9xJRrlYKJyXv_Ou0mN6Pz_Bxq6xEOVU_Ie OVUWh4mqJajUdtkNsCeFy6XflfzbYUuMyuAo77oLwvedVrNbXVjop139z5qU.1w-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:44 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp416.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 3e563602cfa877b5908e791085320721; Tue, 09 Apr 2019 21:41:27 +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 Subject: [PATCH 56/59] LSM: Special handling for secctx lsm hooks Date: Tue, 9 Apr 2019 14:39:43 -0700 Message-Id: <20190409213946.1667-57-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 014791349bbd..0653f295897a 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -2040,6 +2040,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 ce50054f58a0..29149db3f78a 100644 --- a/security/security.c +++ b/security/security.c @@ -435,6 +435,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 @@ -451,6 +454,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__); @@ -729,14 +751,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 Tue Apr 9 21:39: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: 10892701 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 954881922 for ; Tue, 9 Apr 2019 21:41:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86FED285C6 for ; Tue, 9 Apr 2019 21:41:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B18B28885; Tue, 9 Apr 2019 21:41:55 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 2CEF6285C6 for ; Tue, 9 Apr 2019 21:41:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726580AbfDIVly (ORCPT ); Tue, 9 Apr 2019 17:41:54 -0400 Received: from sonic304-28.consmr.mail.ne1.yahoo.com ([66.163.191.154]:41911 "EHLO sonic304-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727112AbfDIVly (ORCPT ); Tue, 9 Apr 2019 17:41:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846104; bh=nBnBMo6nnWk5nN0YxdI8fLfbN2dvJh7eXD4R2+pTog8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=XHrYDBlxnhzH74wW/Q0T3qB0ocPk5xwIo1l2f3tQHj7t3u4ZuOmnnlj3SgBqsFR5rs5Xl2YTczu8CY03J8A2q6AuLv2k1sH455hwdIrmEMjZI9NhX1qX6iK3HHQK4gJB7xVpzb2yzaxpOAJQfYa3aLGSTAbcOosNj3xZXVXsEQusGpAvfmvThxpxK8SPbM0kSEHZv/YPe4SEXRmtxqjAWGNYw8O6TmX1+462O/VCKOaY8WDxY/3DjAzW/gFQnjnxkmBdQhab4fzoeET4bj7pMLAgA4g5mSVq8AqlRuuVS9qd26WOb4Mnsg671JRXy4aAbX+tLjTSW6wgJv4wxOqk4A== X-YMail-OSG: nvBwpLYVM1kBxGBrO8awYw070B2d7Yd8j57cSH93cWL8uFH3S.pFQDnIBl40R9w melP9YxcPmWAwTanYY6oEQkIR0ggW1hLxg06EDmiZVTW0s0D7NiUBW8E4eFLkdqsetls8PoIs61w W3mc53F67Bw6BrVpky7FajHHzQ0A4rEcay8jIo13gfqUb9LLVxmIc9LpPgLOZCRs_r8V.5ett84v n8j3JduquNU1d7Jylo48i.LLnt3KRIYCe7xr4UXzdLTyTcNBDlluyRGqC6OFlECIO__E_4rh_tP8 VRYIT3Hap47RvqjOxixRyBytVmxEuJi1JKq9ggWquqDvWagDh_B3XexJWl9ENFEEM2leuwjn7W0z Dq0JvWijACN5m93CABIbGyhiIes6Bs286fS5rVhEmLQdDPUGnCM6FKGIf9yt4hqluHDOScyhqRkE ufIQfC5yUE7Ua0_DtCFzx3Wx.vOOZqWlraSzo6UgQWz9pD8FSVmGtwm1WS9lPr.Qx8_DbpnItYyv cnHg5FHw38MqkH_aVaQXeHijaVO1gTPz4I7858ryGOS7HAqGi4yVuMXZPCNsT0UmZQPdI6KuyNfl d3joAnuWbAyjNDBhlAa0fZ89QfdIwhgC7_SWlBnrXQ_M6VGuqUTKFZ85pM4Wvz9.8ldNVIR48Efe X0DMn6nSfBYRG_bJMgfkIUXkw8kG1KUps0Djk5MVR1bh0q43zYP9PghMFN1qK4MF4qKYe43tLdqq gvOYGk8iAEBDj9LgiZVwmel8EeJCAAXkUz_OcHBT1mLstrnw0p3u_yGYn.H08K_huFPwaziLYQPT sz80qpsxgm.8eZqhossQ3t2Q8BcVopTRl33QSZ2KTX9DKYutpbKpm5bUGzndK30xE_HudgHIITG0 Jq4OGlF.fg8wEGyeli9FaxCSmdPZKY8pohRjFHk9IoIQGIXo_K_9QQqKEsSP8spMn9mmzei_7VUP hLWN5moXIqUKZ8rVHr4yblnlAM6hV_uN0zz1p1VYt2s6EtjpebfU4UTrWF_mkqYAUZWBaHoE0U23 FSupBOAcl1vYdVhBhCkhVkQZ9nI_CF3dQ_NRejyML5bMEICikHfF6yGEFY52F.0aGKvykbGEaHHo EiDdpw0Nc4YeJes3KeQpoiW5XDj93K5ptZRXXwvuEnjYqyIM_V6bHuUJ_22cupA-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:44 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp416.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 3e563602cfa877b5908e791085320721; Tue, 09 Apr 2019 21:41:28 +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 Subject: [PATCH 57/59] SELinux: Use blob offset in current_sid Date: Tue, 9 Apr 2019 14:39:44 -0700 Message-Id: <20190409213946.1667-58-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 Tue Apr 9 21:39: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: 10892671 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 8F6E11A2B for ; Tue, 9 Apr 2019 21:41:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 816FF285C6 for ; Tue, 9 Apr 2019 21:41:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75D0A2886B; Tue, 9 Apr 2019 21:41: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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 F2908285C6 for ; Tue, 9 Apr 2019 21:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727084AbfDIVls (ORCPT ); Tue, 9 Apr 2019 17:41:48 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:44360 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727073AbfDIVlq (ORCPT ); Tue, 9 Apr 2019 17:41:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846099; bh=wkVO2XcNDsJ9+Rl/WTZ53Df7Cu4YQ9uiXt+d9u6c1Uk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=NnB7R/QStkRgUEHNJRY8H7R2ncgOlRj+yzi+TnbwlXpHgMME5igwiiBX+1IjqvfQPAr7BScgpBja9RxUy67s+txSHZ8RhMWceytRdcaGK2D9RF++l4JgZ1UCGlG0BxUGBCRDkRGfX+0HON7zXHLdqbtZu7KtdNPuith7sSKbyfyHK4m7cRw6mcPgm4dOok+KLqF+25NOuwXjga9RCOO4ppiOX/J5vzvo76pEzxhTgsR4bmK79xmGEQglttmfhb5ZcclNH93+zBZY75p0BS9Lv8bJzV2uqU7B3rPWA7iheay3GWO6Fb8M4tLbMseHmzGj/3nrCoi4rv0A5D+gKMfJ9Q== X-YMail-OSG: nFXl_pkVM1m1NkOiXQsnDAztfqZCPNTYlfgChedFi0S0OiNc.1ncBxVZ1rhoqxI Ufmnpxu8nRy3yrYdI9JCCr7.5jcC.7AMwBbTMFl3xifGGY0AG.k9VtJkbfQ09jo8iKIAqC01P6dG gvbkmh5bedTYpHFKW4n2rqTTPGjYruGXGZFi3efIRa3Rs9LH6D6dJdbnlmWM7lvK3U7E9_J_nUAT N4T.XQGguqYGAUhYpqihXKbeif07RNWtXWK0r85YCLk0QdsV23IilFL.3MvAmTyYoGKomK63X1kM WlqDCQqLY09xc9kS9ru.PrXxDf9jJBrkPcmqA8zq5j43ZSWHfW3XQZ5mz8wZVFH_nZuCNBcRaRFO wPEiLGMrOhoXz5E0qitgtXnL3h7m.6RtlGNfVjhDqJ.IPymZa4LwuxXnWY4IZmp8KAunyUZt2.SV n.vanjNsQMIJDsj_UBb6u5UtgUl7Rj5BtMpsUayfx5zMjB1aPBxD2kcgJUHcRGo.NSX_ddDAoYp. CoHEQTD.ZCu7icFH9lFd8SgJdN3iaZaxYXYq4cyG7NnOF1Qv_hcMvvBOc4kddOt7E1KQnRGM_qAv p2z05nm32oQUzkmoao1TwgZNW.Zqtj4xyuVu.0FMiVTj0zjDHMIbyADToXYHi1_iGNsbemFvO6xU zOk7dFNUtcBlhjNoZdqdlAyBxm807VzaOyksVWMcWmh3NxfneX787l9RCFzWrFDbqUOETma0PGhY 2HXdFWRjB38xoNiKQVz37UZT496_4sC0uHi8vLDaXCavMZKD0qbcE_jyr9knQBESFMbML.w3vUEl 1i_94ktSn_ItYKSpEiwXnSvxVW42AYS9agVuJWMfhQHcRoP9iev4UJ54chuwVc6ZbhAlSZ5ryTVH rt7QCZdyxhmjU2Hu02y9qY3Dp7zgc.cPpLLCzdRB1X4J4wNv5Sx9lA.knihGVhObgjrvBe32wlZe ysk9CBUsp8W7.eWOzP4rvvzwScJEfjDqwBdPkKVCTWafO3pBXlRF_.tSCZHKtESM.lgwEMEFdQlc 12PwvOrAqi1caYfNSq3XnQhU1kPIba.ah2RKP8QYdK4sQNdoXOrgotDkIq.VEKnk5tSBE2nTKWBX qbQgvDYEPdqULCQ3Rk_WsHA.Z8NMC041ACGL_wix7MfrWYWkLwGIvRTldzQMTow-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:37 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp416.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 3e563602cfa877b5908e791085320721; Tue, 09 Apr 2019 21:41:28 +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 Subject: [PATCH 58/59] LSM: Specify which LSM to display with /proc/self/attr/display Date: Tue, 9 Apr 2019 14:39:45 -0700 Message-Id: <20190409213946.1667-59-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 | 123 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 121 insertions(+), 3 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 29149db3f78a..6e304aa796f9 100644 --- a/security/security.c +++ b/security/security.c @@ -47,9 +47,13 @@ static struct kmem_cache *lsm_inode_cache; char *lsm_names; -/* Socket blobs include infrastructure managed data */ +/* + * Socket blobs include infrastructure managed data + * Cred blobs include context display instructions + */ static struct lsm_blob_sizes blob_sizes __lsm_ro_after_init = { .lbs_sock = sizeof(struct lsm_export), + .lbs_cred = sizeof(struct lsm_one_hooks), }; /** @@ -751,7 +755,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_cred()->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; \ }) @@ -1617,6 +1624,7 @@ int security_cred_alloc_blank(struct cred *cred, gfp_t gfp) void security_cred_free(struct cred *cred) { + struct lsm_one_hooks *loh; /* * There is a failure case in prepare_creds() that * may result in a call here with ->security being NULL. @@ -1626,26 +1634,44 @@ void security_cred_free(struct cred *cred) call_void_hook(cred_free, cred); + loh = cred->security; + kfree(loh->lsm); kfree(cred->security); cred->security = NULL; } +static int copy_loh(struct lsm_one_hooks *new, struct lsm_one_hooks *old, + gfp_t gfp) +{ + *new = *old; + if (old->lsm) { + new->lsm = kstrdup(old->lsm, gfp); + if (unlikely(new->lsm == NULL)) + return -ENOMEM; + } + return 0; +} + int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp) { int rc = lsm_cred_alloc(new, gfp); - if (rc) + if (unlikely(rc)) return rc; rc = call_int_hook(cred_prepare, 0, new, old, gfp); if (unlikely(rc)) security_cred_free(new); + else + rc = copy_loh(new->security, old->security, gfp); + return rc; } void security_transfer_creds(struct cred *new, const struct cred *old) { call_void_hook(cred_transfer, new, old); + WARN_ON(copy_loh(new->security, old->security, GFP_KERNEL)); } void security_cred_getsecid(const struct cred *c, struct lsm_export *l) @@ -1960,10 +1986,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_cred()->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; @@ -1973,10 +2017,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_cred()->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 Tue Apr 9 21:39: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: 10892667 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 0D1741805 for ; Tue, 9 Apr 2019 21:41:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00BCE28862 for ; Tue, 9 Apr 2019 21:41:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8D382887B; Tue, 9 Apr 2019 21:41:48 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 7061428862 for ; Tue, 9 Apr 2019 21:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727047AbfDIVlr (ORCPT ); Tue, 9 Apr 2019 17:41:47 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:43492 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727070AbfDIVlr (ORCPT ); Tue, 9 Apr 2019 17:41:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1554846099; bh=NriQJ/Ly+k4Qx0CdGV3MY+BheCtZdoxEEIBOuIRJP8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=kyzgyvU3PrFzJIw0Eag2wrjxFPdnjBJAb66fNwl7ltDWr3TMtK7EuSDB2IOZN4pJa0u0qUFJsQsKL7W7X4gtf5AkM9k5pI+wz9lH2PWJSbLZCFQIgAfbT+2ZXGzWuQcU3FEXVsHW/L/oQlwf+9nR1spa8v8O70wNihIkWqok0jFvIkErEp7OYm6iojjY/hfYsmOXmklMb0s5x+17kJkuz7hjXfJGy/gY80BRTXfLADScB6droPcohchBQVCKp0RiZHXcS0dctlAecb8Q1jnlEf9kpO4A0mlmvOJbIIhmhvLS+9nrutGxHMcTOGB38KSHjZKC9e31UCjmJKgco9UzHQ== X-YMail-OSG: lYIZs5kVM1k0mFsK9L_LeHMJO9RurH_FGcFPQ6Ioi26wqD59pk72Au5rS.ILoB8 pHhnXzV6or61lB0bzLP8Zym7vHAFvo5nfKLXYOo.WUgfmHT_3w6Av_Nuq0AiAifJBZyw_VRuuhno 6U0We9Hoa8PqkEjwRSqUZweNQDxvXFGS0GHB4aBWAoe3FSWY1o7P4qds4a5pSfQ3FC.mU10EhlJL HodQalFss7ap11OLrzEUSCvkGPcR7eubuJzMwVIM92PPL8mJ0nAnKMOWlcoIHTZXBXTS8oG4CvhR 1Kk_xcrI.ervJLWhmc1F1IJRH8ZOcvJxbWardmcCUgsXCk.HbaYi1suomfZfJo.GFCZ6OQNdMOQx 2Df3LwWvlMAGZc3t2fMyY.283lzjFo24VCaLy7Z8sBKXPe9NjllzZBz5AxOluoI9z0X0CSME6dX5 WdUoq06OU.25JVhgXHn_jpPjOah8GostaqhJPSzQnNe4bDVMYfto2M414.vegIC2qMa1C62ZHV6G 7MDs3Nk_xVXNOaOhXgQWJJ8nP6M0R2QOzCPa9G8DDO50xFQoBJyhjZQmbe9NSz4sJtR.Gcz6lI8y Oo_2lv6MsikyoIWOp1wu12pNCTLrAA84dQUiLK5GDAidpoDuv512qZl5U0_.k0BE4KDIeU_.K02q fHs_RyFAqFjRFr2lW7ru4.eu1uM3VAjKASFkNm_7r6v2igZvNDusEHtqeJ1GQTem5IRgr0o8gHLS q.dp_n_nbK4twyXerdJR1jqoBGgIblLmNS.Rp5yZzH0qs1EtjGJ8zFZ9tQ1wLd.qfGUDEJjqt6C4 MOftAmGPLOZzFbRZYfiIbDYQ6.q3TvPERiaYVvNmuTTRcUCFSz_fVZBCEmRAtOnB09664fSK9VyL yKZILDs1ZmFQjHJcyIE91O49tJqJuRIMaRXDvc2XrgDF4Nh6SaxU5cs2t5SpK998RXQYvXpUlrgq qQMJEB.MmlXUXIEJ2I1DN9UmA5PsBh4HoQ9EmSYpgYCVI8ND4dJwV5RkFeaZiTKDo_IisRiOjPzA FLYdzRoWQSr51_rU39x5FdgtxwgDRvEhryCOnNJ2pmB3eHk3fZO0MczH4tFgHF3ZQXGrnVHl5l.M 0qIbSMjc9sjgvzr7UPwTRomTL7sm9lyZJIB1XbBjVEOeQBSG8pEwFUMZ62gh02w-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Apr 2019 21:41:39 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp416.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 3e563602cfa877b5908e791085320721; Tue, 09 Apr 2019 21:41:29 +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 Subject: [PATCH 59/59] AppArmor: Remove the exclusive flag Date: Tue, 9 Apr 2019 14:39:46 -0700 Message-Id: <20190409213946.1667-60-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190409213946.1667-1-casey@schaufler-ca.com> References: <20190409213946.1667-1-casey@schaufler-ca.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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,