From patchwork Thu Feb 28 22:17: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: 10833811 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 99A27188E for ; Thu, 28 Feb 2019 22:19:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 879F12F245 for ; Thu, 28 Feb 2019 22:19:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A7F82F2CB; Thu, 28 Feb 2019 22:19: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B4D42F245 for ; Thu, 28 Feb 2019 22:19:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728223AbfB1WTs (ORCPT ); Thu, 28 Feb 2019 17:19:48 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:39756 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726189AbfB1WTr (ORCPT ); Thu, 28 Feb 2019 17:19:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392385; bh=osd3P5kfm1TLEBkFX4Ie2FyfoA2vXLSCMcBXhwlXlkQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=LT/gKsuoOythHMOOvSPOwkmp1XxsZAightPNkTXBl9AsY2ekLn00HDxNQiuur9cLJCxCV3gdAZaur+TwJZurCKlHiCW53XzDQaBYSFV65tjumpkCgiCNZJgIqne3uLY8kuJcKk7p1qGf/usVyrXhe6oqtNV/qNBGozSqkTLwTMN5VOldxviS+yshCu2HuW+/NSLJGGKOI8E54Fm26QH5/OkSoj2PW2KnJyLNstz/FyyUVA+kJCNGXXAFtraDolJJE8NRWkQMEiytg0f71eN+YwWK7r/ZSQvtjQw8OucuFeLpuyu4OyGB7I6hzUmLFRiWfofDGut/62myj/s5ZBkKvA== X-YMail-OSG: jrJQEMYVM1mIx412ILWe1sAz6QmXW6IuxrKkDsbu68RPGIKt5MHT5ntGuRVNRJM P1EqOqhXq_fM.hPm7A.3Xu5..eceT3xBAyJagytOn4mzWXtVdLQt2gJj7dsBYfi2vWddZhDmXMk8 40KyteA95rG_fRAqXXZqbcw6KsEEYPbjW3vJ_zAWnBx8tvZC7FTs2s96IDRsfNhaI9TbAS3FJYPS cjw2nev_WpBNIMVi6FRTeqj4oRJCIqLLRUg89oPBgxJWb1dH6ATU8GjrTT6mFwr6NCQP322lDcBw YnJv4iz664O9dueRnur6mxLop5GEZ7huh.1VzJbmxip9jp2AJ7cdOAVQIhusU712yztikOtZw_Wv 7edXF_iqNJZy6VNgswy0LN3rReRSe.FiFofAftjk43flO0S52IZXzk7jsMZh2sUUPCOrFqXJ9aSc ZrCaNW25MirfI_ptvncAAH3qwYzqrcglpGiYg0gPFilip6KApwfUbFFhYENaKVRi22E4W3HM4V6T iKupfiXPFRS.pzOSgULIb7DAPf5XBN.CxCqdAmeK4CtnLGLEYf6ZNe_oXPrjRO.6tgb837eM03aS sn97pTTWhqOzG_67VCspbjWkCJPaoIADA4DU0mpWN4b5rP.UbmgNcO6aTvckkCTDzChLiUmzEIK3 yBxEKy0Odt33Q4kFV6hRKLc6gGjaGVK8DqIUwVtisgkwikWr3Ni1z.IP2MV23oDH90K3NQP4mllt PC6uq0lfHxwdlKSr305CYECjjpK3zxcZYi4.wf2CXc6WVaZjQgkO95Tvr7.K.Gywb7fuIapGsZ0K jc5QIqXEd8s7DA3w3yMTu95CHs_B_xxB_QUS1ePOeqZDgVzpTD6PnGwwPFx6DzY.PUypTlQ.u.nP 6tYmoSasvM7zZnEXfi6dqSZLA.gj.qgmqQteeQOJ4ql53tk8eMnl4WG4XE83YJF6quPXEvEbWW1K gakC9lUtpeile3er1iX0Lr2YJVWeInkAP68bCS0PFcz7C8tg43FD2afVVraY98Kc8OpRkzn1S.bj h5ABf7T3Lq2gvGNF4qqUVkCMPwGoy7zz_9.2U0dkaBqTRRTr4Q3vq0y3GvNNIl.SjpI3LOhwvlFb dJEayICLIZDbQ79fDAjIx8yfGHB6o0j7FFNi3ag-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:45 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp403.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID eca90f2e660dab57d5d3726b0a8f0373; Thu, 28 Feb 2019 22:19:43 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 01/97] LSM: Infrastructure management of the superblock Date: Thu, 28 Feb 2019 14:17:57 -0800 Message-Id: <20190228221933.2551-2-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Casey Schaufler Move management of the 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 | 55 +++++++++++-------------------- 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, 83 insertions(+), 69 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 22fc786d723a..97510e9b9288 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -2036,6 +2036,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 b6bff646d373..fd8d7ae967c0 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); } @@ -296,12 +297,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 @@ -599,6 +601,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. * @@ -762,12 +785,21 @@ void security_bprm_committed_creds(struct linux_binprm *bprm) 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 5d92167dbe05..f36cf93695ad 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -333,7 +333,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 @@ -364,11 +364,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); @@ -377,18 +373,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; }; @@ -492,7 +480,7 @@ static int may_context_mount_inode_relabel(u32 sid, 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); return sbsec->behavior == SECURITY_FS_USE_XATTR || sbsec->behavior == SECURITY_FS_USE_TRANS || @@ -511,7 +499,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; @@ -624,7 +612,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; @@ -857,8 +845,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; @@ -890,8 +878,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); @@ -1057,7 +1046,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)) @@ -1349,7 +1338,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 @@ -1739,7 +1728,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)) { @@ -1770,7 +1760,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; @@ -1919,7 +1909,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); } @@ -2550,11 +2540,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; @@ -2625,7 +2610,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; @@ -2779,7 +2764,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; @@ -3016,7 +3001,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; @@ -6538,6 +6523,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 = { @@ -6563,7 +6549,6 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = { LSM_HOOK_INIT(bprm_committed_creds, selinux_bprm_committed_creds), 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 d6e7b4856d93..4190c5e9e66c 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c @@ -51,6 +51,7 @@ #include #include #include +#include #include #include "flask.h" @@ -2732,7 +2733,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 9c7c95a5c497..e943e0fd3ea1 100644 --- a/security/smack/smack.h +++ b/security/smack/smack.h @@ -384,6 +384,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 79d6d2a6a0bc..18892df4ecaf 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -539,12 +539,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; @@ -553,22 +548,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; }; @@ -694,7 +677,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; @@ -793,7 +776,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; @@ -830,7 +813,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; @@ -1081,7 +1064,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; @@ -1323,7 +1306,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) @@ -1593,7 +1576,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; @@ -3201,7 +3184,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. @@ -4491,6 +4474,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 = { @@ -4499,7 +4483,6 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = { LSM_HOOK_INIT(syslog, smack_syslog), 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 Thu Feb 28 22:17: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: 10833817 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 CC0E0188E for ; Thu, 28 Feb 2019 22:19:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B98E02F26E for ; Thu, 28 Feb 2019 22:19:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ADBC22F2CB; Thu, 28 Feb 2019 22:19:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 868622F26E for ; Thu, 28 Feb 2019 22:19:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728107AbfB1WTs (ORCPT ); Thu, 28 Feb 2019 17:19:48 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:43090 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729286AbfB1WTs (ORCPT ); Thu, 28 Feb 2019 17:19:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392386; bh=odTfUI1xLr3S/hgQZqJoiHbxRGBGyf7g6J7Jp0I/lrs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=UiElE0fI85q7CsiVTbkbbiB6cDucaAJHXQEniQWYwIwGtDhHY/C+Jr9IfpNNhej02lLBMXk7LuToWMBcFAZdz5xgBXups0+lNwJZ4k05h1xQaX3HJJ2qgKePJyOFiX4j6KoDuN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Ff.MkI.EsritaLOqgBHM7ToCGdeEIWr09y tdp1V7BreEExuiWJst_og6xR858tsS5ZVL0oLXQTgyJAZ5N4WHC54EyJWKjKW0OQRpH3QZw3diMc nMYvf45q.WKrUt5bJCjuACKTi1buOw79XoF.q5Cot4OHUHHSiz5W.X1tiHveXjWuu5Z_b42WbEdo ZaCcHcHJajPoNCh2aGQg6a6qsz5nA56VDJJycgBA.aQZiz9LXNiMnlNMW8zkfJCFHKVFU.4dFwKX ZGZA.QQQ2fub.yi6LbqkmyNmorsEGZHA_ Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:46 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp403.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID eca90f2e660dab57d5d3726b0a8f0373; Thu, 28 Feb 2019 22:19:43 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 02/97] LSM: Infrastructure management of the sock security Date: Thu, 28 Feb 2019 14:17:58 -0800 Message-Id: <20190228221933.2551-3-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move management of the sock->sk_security blob out of the individual security modules and into the security infrastructure. Instead of allocating the blobs from within the modules the modules tell the infrastructure how much space is required, and the space is allocated there. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 1 + security/apparmor/include/net.h | 6 ++- security/apparmor/lsm.c | 38 ++++----------- security/security.c | 36 +++++++++++++- security/selinux/hooks.c | 78 +++++++++++++++---------------- security/selinux/include/objsec.h | 5 ++ security/selinux/netlabel.c | 23 ++++----- security/smack/smack.h | 5 ++ security/smack/smack_lsm.c | 64 ++++++++++++------------- security/smack/smack_netfilter.c | 8 ++-- 10 files changed, 144 insertions(+), 120 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 97510e9b9288..22145f2a6464 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -2036,6 +2036,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 bb5a02d2439f..b77571ddbed3 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 fd8d7ae967c0..43bed5fd6da3 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); } @@ -302,6 +304,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); @@ -601,6 +604,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 @@ -2034,12 +2059,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 f36cf93695ad..6133bf4b737d 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -4215,7 +4215,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,}; @@ -4272,7 +4272,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 */ @@ -4288,8 +4288,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; @@ -4304,7 +4304,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; @@ -4436,7 +4436,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); @@ -4607,9 +4607,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; @@ -4641,8 +4641,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,}; @@ -4684,7 +4684,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,}; @@ -4717,7 +4717,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; @@ -4785,13 +4785,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 || @@ -4851,34 +4853,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; @@ -4892,7 +4887,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; } @@ -4902,7 +4897,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) @@ -4917,7 +4912,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; @@ -5065,8 +5060,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. @@ -5083,7 +5078,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; @@ -5104,7 +5099,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; @@ -5121,7 +5116,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)) @@ -5205,7 +5200,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 @@ -5246,7 +5241,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; @@ -5387,7 +5382,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; @@ -5426,7 +5421,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; @@ -5518,7 +5513,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 @@ -5547,7 +5542,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; } @@ -6523,6 +6518,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 e943e0fd3ea1..010236b198d9 100644 --- a/security/smack/smack.h +++ b/security/smack/smack.h @@ -384,6 +384,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 18892df4ecaf..b09b19e6466f 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -1352,7 +1352,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; @@ -1734,7 +1734,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 @@ -2144,11 +2144,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. @@ -2162,11 +2158,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 @@ -2175,7 +2170,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) { @@ -2188,9 +2182,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 @@ -2308,7 +2301,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; /* @@ -2353,7 +2346,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(); @@ -2429,7 +2422,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; @@ -2516,7 +2509,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; @@ -2610,7 +2603,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; @@ -2658,7 +2651,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; } @@ -2683,8 +2676,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; @@ -2738,7 +2731,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) { @@ -3480,9 +3473,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 @@ -3528,8 +3521,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; @@ -3566,7 +3559,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; @@ -3731,7 +3724,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; @@ -3848,7 +3841,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; @@ -3898,7 +3891,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: @@ -3911,7 +3904,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) { @@ -3949,7 +3942,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() */ @@ -3969,7 +3962,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; @@ -4068,7 +4061,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) { @@ -4474,6 +4467,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), }; @@ -4580,7 +4574,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 Thu Feb 28 22:17: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: 10833809 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 1932017EF for ; Thu, 28 Feb 2019 22:19:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 085862F291 for ; Thu, 28 Feb 2019 22:19:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0CE92F2CB; Thu, 28 Feb 2019 22:19:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CDC82F291 for ; Thu, 28 Feb 2019 22:19:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726189AbfB1WTs (ORCPT ); Thu, 28 Feb 2019 17:19:48 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:41164 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728107AbfB1WTr (ORCPT ); Thu, 28 Feb 2019 17:19:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392385; bh=R9Cl382zwabtlYbHrBE+YOkLeuWWJbLiCPDXQYnLx3k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=AFPXz+bpMLIFOoeCr/HDa5j3Vx+DIGTRRWm9InPmP4rsAzxItIFZJ3pzo6l8O/ArYm+T+dwV6n+uxV2+PjHlnY5FnwUa1QveEs9+cRkpIqKLxKukKaHEtfg3+DtblYQsTp4rfFW2xmG6L3kd3nS0JgkAAvx1zfqyQ56OgC9wDlzpAymtjffFjIk2xeJugnj3vPgrXsFzG2vZbGUl2UoGyFTPBHOoBC94ZcglGN8t43GLPZgGViJJN12tTbDuBH4dI6l37EPZIKmbwQRfH4nbmnj86vRuGBJMkepKO4OWEvZ/Q5vWd9l/izD8M7DRMZdr9M7wsB+xfUud+MypGAvVjg== X-YMail-OSG: 1t_zGY4VM1my8L6VYQNI7W9ZbSfRItYgRKQQvHmvfrj2e9Z4odIk5b_4AOspuOS zXlaCBti_UlBxnR3Tmwa_X89vb_OCRbzhYIdXJRF0RWlUnBL3AZryUPsvjpcLLttIS6Ciy12RTgk TkIv1x02AZtpEVFKFz2fBxZegP8d3oaOtmahyLickGEmqsjoUtCt8Ecm.vJXDzzNCNR5sgXXEYl8 SfvjgHiiMjiWWEZYS2s4rS8yNHqqKG6JGMA1t9LepHJfFiqbeHRSf1Y5Eoccj57D6S_WUU5i8y.X lzcAVcu5R.swF5IVGIhKvCFTmkhN.5NDJMORYfT7eICii1UoliQmyIalYpJWBM4A4aiItWhOkHDV aHBgDOKx69XF4.jKmyEGshDj8ANqX0dm7uNH1ghNdqVO0i8xYVdd6vQOw4SvgrOqoUXGNuwxDXmW YIRm9u8nm7iyvTVQH3RQTXHCezJQa0zQrsLFRI1hfiMNpcSouwAQegmwCg5Wxj.e_h61sa8Bbljn gH_VR13viMmYD4B0Qc3kHHeIgB9t8waeUZ6DKPTbuFY8PKxGTJVoGoA6cRre8nxHSrznKnmz07fO m9nqwOwPYBp6Ny6hXTe6MJ_i4J_8XAAfXlGnhkN2RCGInIQ6095LH5gODPYMMChkiLvxruuUx.2x rnGxo6wchggSyKhmVQ9cGOWW7e9yc4Kf4MUuQr9vRjOrEaePciAXDHw4toD7BmpLfc5WPFCRYrZj mgkhfF9GlEaxRp8oxNm10SW4WmIdZqkV5Xaq8o22QKI4KGngywmaHeKjr2YtFq.16USADnEt1Bov zSM5SKGtP7hJcOX0ytWQGxZgKmyYOMBDAvuHk_ysayNYZjSVIsF9goQunls2tFNsNSodXxk8kuVi .SR2D2wgUbSet_I6JqGM67mgkCnxO6iUVgMZpwVWVQ1wAXgT3U5rM9sTvu8P8MaShew8q1tD6K8T 7J73WIhBLqvD5xw8wwjMeoS163xCyhAyixjeRn7NpqHCfRMUzEskfuRBwu6s6ow3OML_0v5WHcto n4R_tvciFF5O23BEM735vsTFncZm4.O8BBtPIeAhErnZRa7D2dPwq2RyBiNNbCXAN6CaBRk7DwTn Fe8Gg5d4o8OUmFrSnucOyII5.0NhvgLe5ZvPCK_4- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:45 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp403.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID eca90f2e660dab57d5d3726b0a8f0373; Thu, 28 Feb 2019 22:19:44 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 03/97] LSM: Infrastructure management of the key security blob Date: Thu, 28 Feb 2019 14:17:59 -0800 Message-Id: <20190228221933.2551-4-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Casey Schaufler Move management of the key->security blob out of the individual security modules and into the security infrastructure. Instead of allocating the blobs from within the modules the modules tell the infrastructure how much space is required, and the space is allocated there. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 1 + security/security.c | 40 ++++++++++++++++++++++++++++++- security/selinux/hooks.c | 23 +++++------------- security/selinux/include/objsec.h | 7 ++++++ security/smack/smack.h | 7 ++++++ security/smack/smack_lsm.c | 33 ++++++++++++------------- 6 files changed, 75 insertions(+), 36 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 22145f2a6464..f19751dc53be 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -2039,6 +2039,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 43bed5fd6da3..750b1b63edbb 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); @@ -303,6 +306,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); @@ -569,6 +575,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 @@ -2325,12 +2354,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 6133bf4b737d..54b8a42ed3a3 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6243,11 +6243,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) @@ -6255,18 +6251,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) @@ -6284,7 +6271,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); @@ -6292,7 +6279,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; @@ -6517,6 +6504,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), @@ -6729,7 +6719,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 010236b198d9..f623d059421d 100644 --- a/security/smack/smack.h +++ b/security/smack/smack.h @@ -395,6 +395,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 b09b19e6466f..d748c709f31a 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4093,23 +4093,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 @@ -4122,6 +4112,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)); @@ -4141,7 +4133,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 @@ -4161,8 +4155,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; } @@ -4177,11 +4171,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; } @@ -4466,6 +4461,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), @@ -4584,7 +4582,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 Thu Feb 28 22:18: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: 10833803 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 8979318B7 for ; Thu, 28 Feb 2019 22:19:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C9962F245 for ; Thu, 28 Feb 2019 22:19:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 701EA2F278; Thu, 28 Feb 2019 22:19: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DE8A2F245 for ; Thu, 28 Feb 2019 22:19:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729181AbfB1WTr (ORCPT ); Thu, 28 Feb 2019 17:19:47 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:44476 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729293AbfB1WTr (ORCPT ); Thu, 28 Feb 2019 17:19:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392386; bh=kdtislM8E8h74/k7iD5aHOq6AYv+fS3/ejHJ7LD5ioI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=lh+QsAyxCQq105gQQotAtOAEFGdBw6aK1Dxq/xpp9X2G65T5M0YEBcpCoA89vDMlhZ0zEQdqDj8lkfViTBU0MUac1AeC6/OhrLW62JcaYKSIlrHjxlZRHlqvqDnURRh5oiFWQi/73qjf5KL9jw/eInalDCb9iFRWhIVWLGTqOhNsH/ZOqDCK5TfmoGdzJ7tOZLY7FiZXh/mcHuVPU6sggo/ULC64yX4HljIkyvnuebqGpAFQG8hKUGHo0G24cWvE6hdAuwkN8sDMU77QYGWo5MSi4kngSQ21zjXcItvj4WxL9mVTUZpwCpGACQRw1SgVDb6WyhLJYOS8NH7uc81NXA== X-YMail-OSG: zAfK7zwVM1np_7128qPpP6wQGyulkb5n_7K6Kc6rZfk8pEAjW9hKS_Ubka5Eqou Fei1Ga9RyW5djwhjm4azyTFO3hS2v.Hm9g.261N7GsGYCyCEUhhlIiX948VqHTnXiAwROMNBUzqv S30duzrAio93qWv.FbzpO60rSxyQUb0m_i4GnySW3ztqbUwRaNtOGLCg89g.PVUYp8_WwNGoZz9C zTM9j0E6UtmGGHVKXr.RywehFDkWk8i5RaTnUTQZaBPSBIstO0RZbbnNleVnOvrKRw_Uz82rXyiE M3kFsrSI6pWMzyHRpS0PTNw0VV_ufaeIlNe30GwNzJ2JD7qhttKh6BB5lENFGXeZ3gGIysMHlT9q Q584eq2X0NW8M6.mgwbg0As7Jr5mRZCMTo065hV.GFxXH_kAp8GB.410yXqYt7WqrQ2T_8EMiDT. LjNXRN7BdJpQYIrXxXaFMxzknnyZl5UE6KMzNAQ27JOg0c_3DIa4XG7sFH_QH6GJnX0q1.ZV7kY0 hNxOgZz1AZhHWcXxE_UnCLrCLFmpx75dzZ3CeHSUNL1Hagr_pyWg1mDQwkp.lxadJDGKqlA0cw15 FOKo3kL_aQ3aX8WB.SGzTmwmSvLNP2EfIhsDGryr8d5SGBCWihPy_WJ_Et7lUKo0idF35rwUCmlS MSGvuVW6ougtnbreUPtfBj83.G_96A06LFn4PRb60uGbV2zsvWifci1vGs8nonkZ4QMEQE43pvB3 qE.hw9gdqzVQI0YwrEZAArXqoKVUtvnCnM9SNds5XEez6Cds6B82gRsT8UG0WIn9TXOCcXc.polz ibxi8vK7QpES8XnrI37rvKrL2SbqPmhhxRrfW0v971NO6BqYxkKq1Dl3fqHa5gRSHLeAav9xopie oIN6avkljfrruwoHhaRKqhQdlCSM8hMm5m2ArEjaWXbfWjkO5ZllGupa1jg16htJAQdyTMFCrno7 IENywvAzeUpmS_JnzP0EKNTrw8QdVYSiukOmPKd7Z2CKroBQvr27QK7ik_EaB_LFpeHBF9Bqs8oh rbHFl6uB4Si6mTChF8CY6RLUW.UeIMyUXj822E717zonNEg0UPcbswlp_1gqZU_1os9K9693P1ul lVU1SG41nzLnV8e43z3FcbTSoybv448XPiHUJxg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:46 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp403.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID eca90f2e660dab57d5d3726b0a8f0373; Thu, 28 Feb 2019 22:19:45 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 04/97] SCAFFOLD: Move sock_graft out of sock.h Date: Thu, 28 Feb 2019 14:18:00 -0800 Message-Id: <20190228221933.2551-5-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move sock_graft out of sock.h so that sock.h doesn't need security.h. This makes Casey's life easier as lots less recompiles after a change to security.h. DO NOT TAKE THIS PATCH! Signed-off-by: Casey Schaufler --- include/net/sock.h | 14 ++------------ net/socket.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index 2b229f7be8eb..2beeda35e39f 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -51,7 +51,7 @@ #include #include /* struct sk_buff */ #include -#include +//CBS #include #include #include #include @@ -1800,17 +1800,7 @@ static inline void sock_orphan(struct sock *sk) write_unlock_bh(&sk->sk_callback_lock); } -static inline void sock_graft(struct sock *sk, struct socket *parent) -{ - WARN_ON(parent->sk); - write_lock_bh(&sk->sk_callback_lock); - rcu_assign_pointer(sk->sk_wq, parent->wq); - parent->sk = sk; - sk_set_socket(sk, parent); - sk->sk_uid = SOCK_INODE(parent)->i_uid; - security_sock_graft(sk, parent); - write_unlock_bh(&sk->sk_callback_lock); -} +void sock_graft(struct sock *sk, struct socket *parent); kuid_t sock_i_uid(struct sock *sk); unsigned long sock_i_ino(struct sock *sk); diff --git a/net/socket.c b/net/socket.c index e89884e2197b..d5da935302a7 100644 --- a/net/socket.c +++ b/net/socket.c @@ -3425,3 +3425,20 @@ u32 kernel_sock_ip_overhead(struct sock *sk) } } EXPORT_SYMBOL(kernel_sock_ip_overhead); + +//CBS - HACK TO SPEED COMPILES + +void sock_graft(struct sock *sk, struct socket *parent) +{ + WARN_ON(parent->sk); + write_lock_bh(&sk->sk_callback_lock); + rcu_assign_pointer(sk->sk_wq, parent->wq); + parent->sk = sk; + sk_set_socket(sk, parent); + sk->sk_uid = SOCK_INODE(parent)->i_uid; + security_sock_graft(sk, parent); + write_unlock_bh(&sk->sk_callback_lock); +} +EXPORT_SYMBOL(sock_graft); + +//CBS - HACK TO SPEED COMPILES From patchwork Thu Feb 28 22:18: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: 10833829 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 A522C18EC for ; Thu, 28 Feb 2019 22:19:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 980382F26E for ; Thu, 28 Feb 2019 22:19:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CD782F34F; Thu, 28 Feb 2019 22:19: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C94E92F26E for ; Thu, 28 Feb 2019 22:19:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729433AbfB1WTw (ORCPT ); Thu, 28 Feb 2019 17:19:52 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:36383 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729473AbfB1WTv (ORCPT ); Thu, 28 Feb 2019 17:19:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392390; bh=4mpagIDXm11/iyGeFHwFTRusBEV7u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WSJOwWk.rHMJx.srX 3NgkyPcAUDWwEJnfjz9kM.lXpNldtxl1vsWtzg3SQR3D1d5YMcqt_0wv5_0TIpfnDvoW.kw7gRJY 7ZDOXvvSlB8nJmujVlIVaUe5ZjvLTAnM.KWnGuoNXLlJQ6ANt_TE5jRGylbSKh4Co0XtSd4KdDoR _8A_6P8zqY5h15qAHyd2GDiqfp5lC7a21NXeJoV_Qp28FRyfOTH6FDfaQmKPVwbzdhBhPLGT9ATt T6tvRH7eqYkxIpgqHSpzs5b2qzBojHNpC4h6Nwj6lxrd0Yazq5XNZ9Zna3FLAE.RYNxGeg8MUzK2 _ZiU4g2T.Z1YdUbHkbgCg_BxHJsAL_Nr7El2qWPzt9rEXg5EL7EaI02_Cj7ec8vnhvmZ7072Og2V fLQLbGQ1lIWgaq5uPj_a0eKBdA7IZgIMfQ6phJf3ABfbmMQpwdTKwhrpq4QUPyVAbecDp5BAicrA ZiIzNspl1.fzEIkb.SCkaTvVmecpA9fmRQ4oAAZKq Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:50 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp403.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID eca90f2e660dab57d5d3726b0a8f0373; Thu, 28 Feb 2019 22:19:45 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 05/97] LSM: Create an lsm_export data structure. Date: Thu, 28 Feb 2019 14:18:01 -0800 Message-Id: <20190228221933.2551-6-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When more than one security module is exporting data to audit and networking sub-systems a single 32 bit integer is no longer sufficient to represent the data. Add a structure to be used instead. Signed-off-by: Casey Schaufler --- include/linux/security.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/security.h b/include/linux/security.h index 13537a49ae97..a79fe8ef9d84 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -73,6 +73,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 Thu Feb 28 22:18: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: 10833849 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 DCDDE18B7 for ; Thu, 28 Feb 2019 22:20:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D263E2F323 for ; Thu, 28 Feb 2019 22:20:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C24992F3CE; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A1952F323 for ; Thu, 28 Feb 2019 22:20:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729445AbfB1WTz (ORCPT ); Thu, 28 Feb 2019 17:19:55 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:35099 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729381AbfB1WTv (ORCPT ); Thu, 28 Feb 2019 17:19:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392390; bh=5lhOOJP5rEU4b0w++kZXsVwOzmrbGCMHIx8THL87gxY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=MN2dlyTMuVOTrXlqcpdTdiZfCRj1vxaZpwprVphz8i327YdyoOoJfjphpDC30WTc55eAPIboBvUShg1XFekHkrBi3R22Z3xycsAY7yKidx097/vxJhFBODq8u8SIvzO9Wv9gCJ+PZTVREr0W6/Rgd3Q7SKlvFKlICpVxw4cN0Vn3LapGuCMlzvN6W1sX7pPTIUx/k8ViWvyhKzCBm3Oj3QiZHj5xH34ZAj0spBZVnvUoMiKODljiXf0rGDPdNityAHe3PfosRc/Y+iFKw6FnTJu18NXIUrWXIpaHl8Ct1Q8ShNtvXspBXz2n3dlq3EHBwLoonkCn9kTcrzqPwxa41A== X-YMail-OSG: snNSUFAVM1n0GaFoKJmV_iV.CmK.BvyoHgJabzUVPY_sZixARIL9cGb0UMmKalT CbjMvrFQZSjfhJ36rPSpapw7CDFWWQior9gTDBVf8sbsUos9YFpEhynRPkeL4QIwllAAeiqJeHkU TCZN2JJhUnR1yt5Ni9nsFy74Kq.UVxxFSaVKQcT8kRWdXCqIXwKsbEe.w9XT9fH0mYBgJ6MSyb62 v_vQI7Me1Ur3aD44cOqzb4e6hpXAnDGfqASDgT2czFLLhDX0aEzI2q8qYApcR.Ap7hJY1HsxMkoU kMpHoDxOq8.Kr8c56HaJtai509xgcDaJMEJaFPIzU8UwJvasWSeZUhEKbOcDsc7nxX5NQUfVvKAH pH4OnJg3hqwuZIpcUlNQ4_Gd3czphevxROcRaOEydoGKQIGNtFHXhLnr_a.gIEGFKBE5HokyCBrE 3AXUNUH_gHpNg8jlXkLwK7djszIbjcYkmccajWQXAi7.nkQpEH3Ej6TwYs4Eo34ZXOrepICL1vVz 9lbcto9AMDh3k0NZZtJdNaWGD23lSXzYVYuqUHSCKziACEu39qm3ZgSyVowHa8kNgz5jf04jeYB9 Zud.t9ZpsASXXm8zTtc1vlJtmRDet_5KBYOWBVnM00kw6XAJXYIVkI8OEH2MssQ4axSURmxCXNmF vGwUbgqFR_hwnF3R0nWUJOwMX8NB6bW4Pm7Ftp54zR52Nw5jLH4v9NH7XbE.d_fjC78S7xujm_bB MrmXvhIL.GVd08_xElyJB2T.BSCi.VR4p1Q6pucITXNGUuTQ1WqN0XrP9Tv27C0pky2CsXpeH.pn Vf7NYiuizJHH_3WRivnMZk6DrWmKspaI5yzJl7hG9wVJMYoK2NiY_Qt.rDTRfPQDUY52IvpiTxiz 9gfo.juiNIk3fn.svdXRzFzakne8MImm88VFcB3sPR7hPjsAFn6QbgLNscGwuOttl.ZwPC4VsBI3 t1j43alFzPi.WeaWEu.2Eru7dIX2q.kL_x6c2ZAA9vmJjvyDRVeDf6wFFrtRkl8dBAkBmpB7U32V Iv3MZ7IDskqRFwsixePVMJQdEhIE5ujnPdibS7KmpFSl42VvElM2BWbQAsY_c9epreAaNvEtHspw PK57vg7Dyuy9eCnRqAEXfPbLXTbPkX7VO0TGgXbLF Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:50 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp403.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID eca90f2e660dab57d5d3726b0a8f0373; Thu, 28 Feb 2019 22:19:46 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 06/97] LSM: Use lsm_export in the inode_getsecid hooks Date: Thu, 28 Feb 2019 14:18:02 -0800 Message-Id: <20190228221933.2551-7-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the inode_getsecid hooks to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when security_inode_getsecid() is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 4 ++-- include/linux/security.h | 5 +++++ security/security.c | 35 ++++++++++++++++++++++++++++++++++- security/selinux/hooks.c | 21 ++++++++++++++++----- security/smack/smack_lsm.c | 13 +++++++++++-- 5 files changed, 68 insertions(+), 10 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index f19751dc53be..ff97f57a87bb 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -409,7 +409,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 @@ -1556,7 +1556,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 a79fe8ef9d84..785d21c81dea 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -85,6 +85,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 750b1b63edbb..5bee7e0b0bf3 100644 --- a/security/security.c +++ b/security/security.c @@ -708,6 +708,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) @@ -1375,7 +1405,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 54b8a42ed3a3..cbf7bf3fa4af 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -211,6 +211,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 */ @@ -3212,15 +3221,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; @@ -3232,8 +3242,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 d748c709f31a..a9277a942ca2 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -464,6 +464,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! @@ -1394,11 +1403,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 Thu Feb 28 22:18: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: 10833835 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 3B9EB188E for ; Thu, 28 Feb 2019 22:20:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D3092F2DD for ; Thu, 28 Feb 2019 22:20:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 214202F323; Thu, 28 Feb 2019 22:20:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95F542F245 for ; Thu, 28 Feb 2019 22:19:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729374AbfB1WTw (ORCPT ); Thu, 28 Feb 2019 17:19:52 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:36291 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729454AbfB1WTw (ORCPT ); Thu, 28 Feb 2019 17:19:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392390;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8PQDCoG7icsZOzxtfp0ouAnaP.En_rvJRIFESft sjmdwCuLBHdASNysn2eh3aUsJW8M8jChxTSvfpZy.gEAaGjGd2FBcu6RuoMyDnoQUcdFlvjV.kKY AObuXRiXDM_OKkCcKuoKo3KR2tKPfn8Dob.80VVZmCPUMzNNNg1dYn40hTEVXdpro6DY2Uz129WG 6m.7yJIIs8A6_AtsB98aM1KbsJrH4IWllzB41oNW2iq0UpdNSFB5J8Fwx5csNQMBdTa8YCpnCYpe 1._TIsD4Rd3QLLYrnrRvo.MkL3jQCO1SjomWRfAzFmNXEzfseuV33CzC5tuoogz4SBngld7eVK0W XtwPzQsRMR_4CB10CuST7RIlb8INFBcB0lDS6bUZIfX.7NV5ZI0KxUPMiIbg8UagmiVmwHoU53eR uRJwQu90eIx4YkweIgQk_hHGwJrl8.YJ9mOwHK6d5qTH_tqI3EyHQD0G0aWwMbpOOH1rTNUZkQb8 rhOVPAT3qaqnjJa.KuNYvXOl8HoYe7lnxtjR1j8DU_9Az5wMfB7I- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:50 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp403.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID eca90f2e660dab57d5d3726b0a8f0373; Thu, 28 Feb 2019 22:19:46 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 07/97] SCAFFOLD: Move security.h out of route.h Date: Thu, 28 Feb 2019 14:18:03 -0800 Message-Id: <20190228221933.2551-8-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move staic inlines out of route.h so that route.h doesn't need security.h. This makes Casey's life easier as lots less recompiles after a change to security.h. DO NOT TAKE THIS PATCH! Signed-off-by: Casey Schaufler --- include/net/route.h | 55 ++++++---------------------------------- net/ipv4/route.c | 61 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 48 deletions(-) diff --git a/include/net/route.h b/include/net/route.h index 9883dc82f723..de599f20ea5b 100644 --- a/include/net/route.h +++ b/include/net/route.h @@ -35,7 +35,7 @@ #include #include #include -#include +//CBS #include /* IPv4 datagram length is stored into 16bit field (tot_len) */ #define IP_MAX_MTU 0xFFFFU @@ -146,20 +146,11 @@ static inline struct rtable *ip_route_output(struct net *net, __be32 daddr, return ip_route_output_key(net, &fl4); } -static inline struct rtable *ip_route_output_ports(struct net *net, struct flowi4 *fl4, +struct rtable *ip_route_output_ports(struct net *net, struct flowi4 *fl4, struct sock *sk, __be32 daddr, __be32 saddr, __be16 dport, __be16 sport, - __u8 proto, __u8 tos, int oif) -{ - flowi4_init_output(fl4, oif, sk ? sk->sk_mark : 0, tos, - RT_SCOPE_UNIVERSE, proto, - sk ? inet_sk_flowi_flags(sk) : 0, - daddr, saddr, dport, sport, sock_net_uid(net, sk)); - if (sk) - security_sk_classify_flow(sk, flowi4_to_flowi(fl4)); - return ip_route_output_flow(net, fl4, sk); -} + __u8 proto, __u8 tos, int oif); static inline struct rtable *ip_route_output_gre(struct net *net, struct flowi4 *fl4, __be32 daddr, __be32 saddr, @@ -286,47 +277,15 @@ static inline void ip_route_connect_init(struct flowi4 *fl4, __be32 dst, __be32 sk->sk_uid); } -static inline struct rtable *ip_route_connect(struct flowi4 *fl4, +struct rtable *ip_route_connect(struct flowi4 *fl4, __be32 dst, __be32 src, u32 tos, int oif, u8 protocol, __be16 sport, __be16 dport, - struct sock *sk) -{ - struct net *net = sock_net(sk); - struct rtable *rt; - - ip_route_connect_init(fl4, dst, src, tos, oif, protocol, - sport, dport, sk); - - if (!dst || !src) { - rt = __ip_route_output_key(net, fl4); - if (IS_ERR(rt)) - return rt; - ip_rt_put(rt); - flowi4_update_output(fl4, oif, tos, fl4->daddr, fl4->saddr); - } - security_sk_classify_flow(sk, flowi4_to_flowi(fl4)); - return ip_route_output_flow(net, fl4, sk); -} - -static inline struct rtable *ip_route_newports(struct flowi4 *fl4, struct rtable *rt, + struct sock *sk); +struct rtable *ip_route_newports(struct flowi4 *fl4, struct rtable *rt, __be16 orig_sport, __be16 orig_dport, __be16 sport, __be16 dport, - struct sock *sk) -{ - if (sport != orig_sport || dport != orig_dport) { - fl4->fl4_dport = dport; - fl4->fl4_sport = sport; - ip_rt_put(rt); - flowi4_update_output(fl4, sk->sk_bound_dev_if, - RT_CONN_FLAGS(sk), fl4->daddr, - fl4->saddr); - security_sk_classify_flow(sk, flowi4_to_flowi(fl4)); - return ip_route_output_flow(sock_net(sk), fl4, sk); - } - return rt; -} - + struct sock *sk); static inline int inet_iif(const struct sk_buff *skb) { struct rtable *rt = skb_rtable(skb); diff --git a/net/ipv4/route.c b/net/ipv4/route.c index ce92f73cf104..1160f4ba5073 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -199,6 +199,67 @@ EXPORT_SYMBOL(ip_tos2prio); static DEFINE_PER_CPU(struct rt_cache_stat, rt_cache_stat); #define RT_CACHE_STAT_INC(field) raw_cpu_inc(rt_cache_stat.field) +/*CBS*/ +struct rtable *ip_route_output_ports(struct net *net, struct flowi4 *fl4, + struct sock *sk, + __be32 daddr, __be32 saddr, + __be16 dport, __be16 sport, + __u8 proto, __u8 tos, int oif) +{ + flowi4_init_output(fl4, oif, sk ? sk->sk_mark : 0, tos, + RT_SCOPE_UNIVERSE, proto, + sk ? inet_sk_flowi_flags(sk) : 0, + daddr, saddr, dport, sport, sock_net_uid(net, sk)); + if (sk) + security_sk_classify_flow(sk, flowi4_to_flowi(fl4)); + return ip_route_output_flow(net, fl4, sk); +} +EXPORT_SYMBOL(ip_route_output_ports); + +struct rtable *ip_route_connect(struct flowi4 *fl4, + __be32 dst, __be32 src, u32 tos, + int oif, u8 protocol, + __be16 sport, __be16 dport, + struct sock *sk) +{ + struct net *net = sock_net(sk); + struct rtable *rt; + + ip_route_connect_init(fl4, dst, src, tos, oif, protocol, + sport, dport, sk); + + if (!dst || !src) { + rt = __ip_route_output_key(net, fl4); + if (IS_ERR(rt)) + return rt; + ip_rt_put(rt); + flowi4_update_output(fl4, oif, tos, fl4->daddr, fl4->saddr); + } + security_sk_classify_flow(sk, flowi4_to_flowi(fl4)); + return ip_route_output_flow(net, fl4, sk); +} +EXPORT_SYMBOL(ip_route_connect); + +struct rtable *ip_route_newports(struct flowi4 *fl4, struct rtable *rt, + __be16 orig_sport, __be16 orig_dport, + __be16 sport, __be16 dport, + struct sock *sk) +{ + if (sport != orig_sport || dport != orig_dport) { + fl4->fl4_dport = dport; + fl4->fl4_sport = sport; + ip_rt_put(rt); + flowi4_update_output(fl4, sk->sk_bound_dev_if, + RT_CONN_FLAGS(sk), fl4->daddr, + fl4->saddr); + security_sk_classify_flow(sk, flowi4_to_flowi(fl4)); + return ip_route_output_flow(sock_net(sk), fl4, sk); + } + return rt; +} +EXPORT_SYMBOL(ip_route_newports); +/*CBS*/ + #ifdef CONFIG_PROC_FS static void *rt_cache_seq_start(struct seq_file *seq, loff_t *pos) { From patchwork Thu Feb 28 22:18: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: 10833819 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 41DA817EF for ; Thu, 28 Feb 2019 22:19:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32C9A2F2CB for ; Thu, 28 Feb 2019 22:19:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 272252F359; Thu, 28 Feb 2019 22:19:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E97B2F2DD for ; Thu, 28 Feb 2019 22:19:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729505AbfB1WTw (ORCPT ); Thu, 28 Feb 2019 17:19:52 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:36895 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729444AbfB1WTv (ORCPT ); Thu, 28 Feb 2019 17:19:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392390; bh=i1PttAKZCuhgesoh/f1kuby1GmIoq4buaBK1bUoKrs4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=GoMHch8nX66t3QO6G1oGqGrcF/0A3Ubd1CmAq++KISSwv1Iq0CjrJOGvTr6tOCc1LkFVtQtR2gBWd5sYFwTIPs22Uhj1ZPA/nezXrCKGxkJTpaH41FwKEpREwjKtTLCN9zVQns51qVX6qfvOvkMtYc0Ml/IiXl8GGjrcELSKH93r8ddjKSUB69t2pTwPwdMhhtPDUjr5WR2V3PdGn10b62iE8i6BlB6DQFTLtOiLvGdU3S74ODvQj8Nmp/yCMiqTa/WgZpOBHPAP/QeK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v_mh94KSYhz8L8fGZhSgRUOirEKGQHCdyajJgN29IOko0KFNdjYmwQFuI2ztO.zov0eCv5iYG WUO05aBzNsh8CBu7mY7oQDKJQnUvpLPed6oGcPqJZogmG4QtjKIIpTuqnuJae_eYCPPcJthg5fQn DhD9EZjy61giSY4IpzM3K42Jh6pOqY8K0ZfjWask- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:50 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp403.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID eca90f2e660dab57d5d3726b0a8f0373; Thu, 28 Feb 2019 22:19:47 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 08/97] LSM: Use lsm_export in the cred_getsecid hooks Date: Thu, 28 Feb 2019 14:18:04 -0800 Message-Id: <20190228221933.2551-9-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the cred_getsecid hooks to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when security_cred_getsecid() is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 5 +++-- security/security.c | 6 ++++-- security/selinux/hooks.c | 4 ++-- security/smack/smack_lsm.c | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index ff97f57a87bb..2e8516447bfd 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -556,7 +556,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). @@ -1586,7 +1587,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 5bee7e0b0bf3..9c10d9aae83f 100644 --- a/security/security.c +++ b/security/security.c @@ -1624,8 +1624,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 cbf7bf3fa4af..d9179b75acb7 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3660,9 +3660,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 a9277a942ca2..e3639d6f1b62 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -1893,13 +1893,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 Thu Feb 28 22:18: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: 10833839 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 A965718B7 for ; Thu, 28 Feb 2019 22:20:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B3A72F2CB for ; Thu, 28 Feb 2019 22:20:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CB842F34F; Thu, 28 Feb 2019 22:20:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D85172F2A4 for ; Thu, 28 Feb 2019 22:19:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729454AbfB1WTy (ORCPT ); Thu, 28 Feb 2019 17:19:54 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:37532 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729362AbfB1WTw (ORCPT ); Thu, 28 Feb 2019 17:19:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392390; bh=wDH2jWq/5InVuEensvl7qeoLag9X/nJnC3tKz8KwL2Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=lGOx6UNZVB8VI8tQqNqzxlzJguwCeEzU8kWDlYRMdjB7AkTSy/OFv58Y85p+2i9MuJ8r2cKgrnZo3eBz+WvdQClZIHB6kts+YbBLIrWGS85I867WXftzYcVFDG4TOqQgBQ+wqKbIrW6iJBl1lKGwI1IvqFIB24t0mVzyekrWgsvjB1NiCCK+5Gk/M/PO34Btl434lHsNWBD2AZmeQD9tLhBvN6PLRuxLZpP6djmUYeFMygLTSu0jU8aw/CuiFX0myEro/p5+heGUMW5E9dZqi1LBlSGp4nZFoMu4F7TFBoK/mo4XSXgSXH9bUspC///O0SMt5zjqjJVxNBGy0/EwxQ== X-YMail-OSG: mE.q.MQVM1ntIQf_vIxqd92ca3bzczhxbS4aBBs8Vfj5kS0QHj09EJojU6e28rF Ebu77oeH0gdpGWzULUIIPVlyAxNCbSFA7MMh9UK2iS2ZkGD6rp7OoCkAdyCunlNJs5g46Edgm2UD 7Q516koT8wMTGa0n2TZ8C3aItYpsra_zN8ixjUK2Y4WK1JlEYmS1pwtEexA64OGCddSCx11rS5JD I63mvVRfwargfYCyU1o.YzKwR81uDDK4xmzOhAcvUFRCViTrNd88TcEXhito6XnGB7EySPDI0yzM sYVn9w17YMDbZp4JNbcrHSGhLrQf8jVUykK6WSaA.8pB4LD4YD1SfbQv3k8d5ufYRYih8c9EyERX jMMqOQP3rOBpgcMLZoPlc6XvdrYZBUlYws3B5RYRXTD04eVrgPhW65KuyYidUjvI4VX9qI.XoWsA T8fnauPSVxd37CAxQEa50KEEVzU4JdPReYnkg6QGRNm7I.wrd.9ynTjw542bcrMCwF3AsCuONxPQ Pb5OEwgdSIvQiayvJwh2r.jVgDpi2k9Z.MZG4GQH7GrEsLY..53jI525eQWTG23U2rL03biLLqzU .7CtaAcSLA9uyHtLsgMLpfrn2QvXUsujSqXsCRvaHQ5OVQcaw5MLiU7diJ7FfmIg7nBsxftdP.iE cP2UGrKruUAQxpm9VZ3vhzcHt4KzuJfWuWUuqiGSjSTnM9LKJ0tVLV4VlDfsreoaTgr.VWyuzLeO A.OrZJnU8yqH.D1AUyhzix7ZUu0WOb._kAcXIkqWRxeSnEgnOsTyAjvtagF42WEntz41uwKaV4Xg D7g_U6nXC7If.8U5rAo0ccm82xriKV0E4HQUDSar7Ms5bD.jHe6xLkgbBTt5FYZsObn0c3usoAuo QuQSKG0dOXbZLClnhfPBNAj9sxxI45o65lJq27ViZupenMcsc5numCZx6d33SWOWDYucaLtWiTgr .P4laoyaXb1uw5t7nWwM6Z85iZuviO2O0bzx7_Cgsny3r7dPY6e40jcIkdMwfod5ytgAMhO2wH3S ZNE_NklpAb7L3kb.hxbr.R_C0TdiVfCLPPQeqCPxtbxqWn44CySAtKWRnOaF9YCWpswWjVXJOGSi AXwt_1i0.lXmA.87DHWk6DVtbX6sXSRigkd8Jklbfu.E- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:50 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp403.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID eca90f2e660dab57d5d3726b0a8f0373; Thu, 28 Feb 2019 22:19:48 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 09/97] LSM: Use lsm_export in the ipc_getsecid and task_getsecid hooks Date: Thu, 28 Feb 2019 14:18:05 -0800 Message-Id: <20190228221933.2551-10-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the cred_getsecid and task_getsecid hooks to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when security_ipc_getsecid() and security_task_getsecid() are updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 8 ++++---- security/apparmor/lsm.c | 12 ++++++++++-- security/security.c | 12 ++++++++---- security/selinux/hooks.c | 10 ++++++---- security/smack/smack_lsm.c | 8 ++++---- 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 2e8516447bfd..f798a947bf8d 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -622,7 +622,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: @@ -1080,7 +1080,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 @@ -1600,7 +1600,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); @@ -1618,7 +1618,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 b77571ddbed3..377fa4ed1518 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 9c10d9aae83f..f6ee25ebfa3c 100644 --- a/security/security.c +++ b/security/security.c @@ -1708,8 +1708,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); @@ -1791,8 +1793,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 d9179b75acb7..104b2315d36d 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3807,9 +3807,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) @@ -5987,10 +5987,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 e3639d6f1b62..d5ff34a5803b 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -2000,11 +2000,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); } /** @@ -3144,12 +3144,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 Thu Feb 28 22:18: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: 10833831 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 014EA17EF for ; Thu, 28 Feb 2019 22:19:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E54422F26E for ; Thu, 28 Feb 2019 22:19:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7F0F2F2CB; Thu, 28 Feb 2019 22:19: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7016D2F2A4 for ; Thu, 28 Feb 2019 22:19:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729286AbfB1WTw (ORCPT ); Thu, 28 Feb 2019 17:19:52 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:43362 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729353AbfB1WTv (ORCPT ); Thu, 28 Feb 2019 17:19:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392390; bh=JCuVFGARXGdMuwyrW5Udrkka/zma4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_4VTLIUkVzAkdF4MXeK3J3l8COWnXfvZNUuDf.S_QzXrsm_lSx8JhoTxS4yU.Cd.H9ATeiOZND SsNO.dgBbEJUTa7duWO0lL6_9638fFjP_bETHLEptCMS5RewbehdttBOrntDM_mjgrqrzkonHsE2 ynKrBv7PgHcV26.ms3UkaJ5xQnAo5YNw2iyFMQvqA3XRvX.wWbP3xLcFFJKJABKi._VGq0Iew_rC bHRe23NK6Ff8msNrtIrAtAASHaPfzndcPaB7jT0DQ49L4f9U8BnNIjOsH52G5fd_zDgR_Nw0Z9DH iGkZg0ic9GhVXKk_UIkWzFGRdjHFw2DKhCfeHTv5FcqqsZk7jtqhojWftjpmlsBASDHl2ej8fnVC Mlaib3apuQP4GSdE2Dx4MIVZpxo4ElusEotsV_NZT23096qIuO8E4cfu3smzivXXq0HX6lGXDS73 jD8snhq9G7afzhtSbUo2zakFyVwCchkwYKJCd1Fim3Xrw Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:50 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0da9962b364e649f4905df2b440bd211; Thu, 28 Feb 2019 22:19:49 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 10/97] LSM: Use lsm_export in the sk_getsecid hooks Date: Thu, 28 Feb 2019 14:18:06 -0800 Message-Id: <20190228221933.2551-11-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the cred_getsecid hooks to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when security_sk_classify_flow() is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 4 ++-- security/security.c | 5 ++++- security/selinux/hooks.c | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index f798a947bf8d..44597189fea4 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -877,7 +877,7 @@ * @sk_clone_security: * Clone/copy security structure. * @sk_getsecid: - * Retrieve the LSM-specific secid for the sock to enable caching + * Retrieve the LSM exported data for the sock to enable caching * of network authorizations. * @sock_graft: * Sets the socket's isec sid to the sock's sid. @@ -1696,7 +1696,7 @@ union security_list_options { 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); - void (*sk_getsecid)(struct sock *sk, u32 *secid); + void (*sk_getsecid)(struct sock *sk, struct lsm_export *l); void (*sock_graft)(struct sock *sk, struct socket *parent); int (*inet_conn_request)(struct sock *sk, struct sk_buff *skb, struct request_sock *req); diff --git a/security/security.c b/security/security.c index f6ee25ebfa3c..909b6b8d1a50 100644 --- a/security/security.c +++ b/security/security.c @@ -2152,7 +2152,10 @@ EXPORT_SYMBOL(security_sk_clone); void security_sk_classify_flow(struct sock *sk, struct flowi *fl) { - call_void_hook(sk_getsecid, sk, &fl->flowi_secid); + struct lsm_export data = { .flags = LSM_EXPORT_NONE }; + + call_void_hook(sk_getsecid, sk, &data); + lsm_export_secid(&data, &fl->flowi_secid); } EXPORT_SYMBOL(security_sk_classify_flow); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 104b2315d36d..6f61a894f7c5 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -4893,14 +4893,14 @@ static void selinux_sk_clone_security(const struct sock *sk, struct sock *newsk) selinux_netlbl_sk_security_reset(newsksec); } -static void selinux_sk_getsecid(struct sock *sk, u32 *secid) +static void selinux_sk_getsecid(struct sock *sk, struct lsm_export *l) { if (!sk) - *secid = SECINITSID_ANY_SOCKET; + selinux_export_secid(l, SECINITSID_ANY_SOCKET); else { struct sk_security_struct *sksec = selinux_sock(sk); - *secid = sksec->sid; + selinux_export_secid(l, sksec->sid); } } From patchwork Thu Feb 28 22:18: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: 10833833 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 7845A188E for ; Thu, 28 Feb 2019 22:19:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 680522F245 for ; Thu, 28 Feb 2019 22:19:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59F242F2CB; Thu, 28 Feb 2019 22:19: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 088EE2F323 for ; Thu, 28 Feb 2019 22:19:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729011AbfB1WTx (ORCPT ); Thu, 28 Feb 2019 17:19:53 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:36120 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729478AbfB1WTw (ORCPT ); Thu, 28 Feb 2019 17:19:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392390; bh=lNuLNszdoMS/3Ss674xKLoLguAXJvpX6T97bTKUBjpM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=oOBgNcpHle9qLwexmRgNZvGZ16jhl5fLR5GLNfVoCXpV16eTrHBymxBPTrdwGAtMnLl3VQlHD8TIftLBNox70oSnNEzB2ysdLUWuc0+zS959a/+4tB2SqGyaPnRy5Yq/8EtVs5Oqz0mzqIMNRReZnWVE5xk55ZB2n9599jsg0FYT+lRwTnkcuLdTez4zH6oh9WCPyRzhd6SQ4v3ocIRVwcyow3mTEI2gnJQDjZMf6VbH00dJ3RzWIKjITcbps3w6Fwb5MX0zVV1Sv908lY95DGyH7qpkxY1cWUBNl1fHhn8yt8m8p+gSLQth6VRAeX4mjXfTq87z2l9nruni6ofjsA== X-YMail-OSG: bcDa_tUVM1lfcM40j8tbI1NNe2PWyWMymjUqCspMK0SbOBnYJkVUJR2Mee6qKGs A9tvekxtMhN0UuDq6lQAvj0rmtAZOWtYkM3ANGnhqcH.f4NOJitIemIGXwzhan8vBFsMt.njdy5b ZaBW8MuDX2Z5xT.dVmfZNxC9IXHRJ1tE.oJ3hEqOuScMPFAyXAWOzAaaO.EkAyagLi3tV7XqgBw3 yfYOjWyIFHtpdhE0Vf6bBG1aCW924sub3_rkQx_Uxq71RxGEHuqcW1sICx7oMdqRopF8C_ImsNn7 kFgjkQARhGh65oxkeml5IPlgERq64F7A.CFvr.OjSPeIHPY3iRh4T0sgEh.02apeZyYN6fVZndQh s.SW11Mm2.GN5qdWl_DLBgnZADmemXnpeV1DHSKIo579GpMQsfDBP3mzj.y2kiUJuuHdgmnxREc3 evM1JGXjJ8i4.zxt7O3TuNKiT.3nxpMFKRbhpBDvAAJtyQLL5EnfSbkEZkla23PXYkJ3_JqATsAW cEsTUBmYSbP.K8SGOgl2Nwfz4bfipLPBeS7yFljYF2Qs8qALfTf3JoqquPnni0.3EL1CMoc95kAU UcO22z2zHFLMs.OZBDPOTN0sOghdHgKlWnuO0TOOkorI2MansrzuJvTobaySsoh7mbFVmtIXY9CQ VZEOzvlk7g9gxuD0VzIXNdEgVPSu2Muk42Sfb5iztq4PWlAprUXqHk37_wXoLDf8Ja.3iF1Le87e hagQhc.goI1D37hP8yTk9AMq4N7I8qpbevWHCtoi7wbnd9HeyK9Oc_zPiNS_kowHBe2SgqPLr8yt 8B80YQTo1uzlXTb6TV1gzBwUEvVfT11b3O9YuS7t_zxJdtO.bYRh3XAlYMpkswOTBUHRpRqiwiwc x6IbnNClJEHSFTXt00jSK2uzJI_xwPh_h4nPPm9Ta5VLuZyoZmp4KfjeZQeVaAJgAp3EbXovgptX QpsGc3qznSRUrIwnUgt36sdliGeqwT3HZEyKA_n9_nDn3tSj0ytlqRbx9xTxi28vkag3.YeHgToi ThSpAuytQaq1tZJMYdmq3Cx3BKvrDFaicp1wqBU4dgB3beF8gXDBcfNLSrQf.rtB6aZ6.WWOg1RT Oqc3HZOgtDf4Ge7zjb7eWDEt99BCTN_uBEHEKZzZVVs7Q3g-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:50 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0da9962b364e649f4905df2b440bd211; Thu, 28 Feb 2019 22:19:50 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 11/97] LSM: Use lsm_export in the kernel_ask_as hooks Date: Thu, 28 Feb 2019 14:18:07 -0800 Message-Id: <20190228221933.2551-12-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the kernel_ask_as hooks to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when security_kernel_ask_as() is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 4 ++-- security/security.c | 15 ++++++++++++++- security/selinux/hooks.c | 17 ++++++++++++++--- security/smack/smack_lsm.c | 12 +++++++++++- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 44597189fea4..796eb441be95 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -562,7 +562,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: @@ -1588,7 +1588,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 909b6b8d1a50..1a29fe08a5d9 100644 --- a/security/security.c +++ b/security/security.c @@ -738,6 +738,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) @@ -1633,7 +1642,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 6f61a894f7c5..efcd905bdabf 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -220,6 +220,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 */ @@ -3669,19 +3677,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 d5ff34a5803b..0e1f6ef25eb2 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -473,6 +473,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! @@ -1910,10 +1918,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 Thu Feb 28 22:18: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: 10833863 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 94DC349E6 for ; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 877CE2F245 for ; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B07A2F2CB; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=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 0E4052F2CB for ; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729576AbfB1WT7 (ORCPT ); Thu, 28 Feb 2019 17:19:59 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:42221 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729553AbfB1WT4 (ORCPT ); Thu, 28 Feb 2019 17:19:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392395; bh=8NmaL5a1XnUMjYedgHA6bQKVWhgyUWwPBtryWzYLXS8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=sdLS9Wf4EOYfAEz79ycBbP//2N33dIPnHNxdmGQNTga6066nRQHD2zFGEDltC77x9mDCd+RE96lh87NyIHKMX+tQRYMgkY+AjMPsMuFUN//7qpBdcmka9sWIsGz/nAiy6DQRFql0jVIJrjVvWzZW445acsdiD4985NGjZO31HfNfxfcUL8Get9sfqq+/jDcXoiIwhsG7KjGLrELZbEnjER0MaUgm9i0bxTglapMVcqtzH7mLxLbLvHwE/mHBTz9hqc8SENa0fmkJiol0bs3GUdZ4R0RHpvkPtJMrUFr9KfB019F+t/oe379gFWi3/4XrxRjDfOGUE1GMKFUmC9Vo6g== X-YMail-OSG: bSuJGTQVM1kxty_9ViagayuWi8jpUfvCNSS1kVJefqrP06gbMoYMZg5leC2.56z 9dM86QmVtfNfYnjc_l.IkyYNUQCXSR.8MWqCIQM3Ypyuh9o9Il35f4QRDk1.paJZEGT7rcAut_V6 XdaMZUUR4nuKXr5p1YC1_Sa44PFh_7a0wPry4x_0ewvCtCxp96pidH6xR1Sxpeuxuv4JENFNBr_E EQ0puaiO073g7hMGxzbQRLalXkX30xaEQlh9OXGA3ESvwEhUZvwJDbwj56JkiEBk9kovWoMAy7Y3 sWMeXmMy5c7ReIrPW9GTB1W8AqtCycDnMZF8Omv2MN2dzyxLHB3G.3YqFFLcmzC5rw.S0xgJfruk lSQnKtA.CLVTZ.CvjFznR7hnCyaWDQXh6dzL6P0.kVZ6f7Mw9UgV91IVeX6e26YPaqf90IMR7Hxy 5Yj4EcPZmATaP1t7QWg155vZ4Na8aGbfUUXw7rLeZiSjpSMWFjEJtVpvvRZ2shTwpwg_AUTRIFCq YKYAqKKMpK4szJdMK6gbdkUyO.wa4W_8E.f8lNw5eVpck1cCTFeDr8QNRlqPwW.SA.pfL6YiPYjI u9J3C1wPwtCtElTkms4Bqc646_RcAEbdHJQIyR_bN8jYot8YJ4m7RCn22g58soha54JHAcHoySjs mAlS2y5bIgvFSc.flEiUwhSEKYkMqFoogAQwZnlRBW.Syl9gEeBehkgP9yMp4GPH9fQWkjwSyANg z2ZBCPNo8FWoy.LgvFBq9HYZ9xy.tz3Xt0Jr.rXdro6Dr1gThPnKfpsK05iboo8FIHw7bG4klBTu CRJG844UxCnKbul3wu0Co9RXFCp8il5EA5scbw0JpOZKuIz6J8TvK_pyyXbm658SxhU0pcaC4UlV D1jHlJ4xDcmypDQu7gVxHXxR6jaSuMCnU0B.RyC5BTyCURW9OaeqipoM4vAnq5A9KJuRuTUCBvM9 38nKEI5x62.u8MUi0f8wUePo4qZtHFQsxyes4ZrLJiKI.GJyslHI3CmOPn6SjUfEKtEv1.iE_wEm hClNlzOJ_s9NXqTKvvtz7chXQWYV3G9dubauqpfzu2hYk0cO2ox0EUTMjeWeuu1dH.zPIRu2mGlE 8JdCshbPycdWRtwCW.5y8_v3.j0MKjyyN_.Op9OGBMgiQMw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:55 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0da9962b364e649f4905df2b440bd211; Thu, 28 Feb 2019 22:19:50 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 12/97] LSM: Use lsm_export in the getpeersec_dgram hooks Date: Thu, 28 Feb 2019 14:18:08 -0800 Message-Id: <20190228221933.2551-13-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the getpeersec_dgram hooks to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when security_getpeersec_dgram() is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 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 796eb441be95..d4f260812c20 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -865,9 +865,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, @@ -1692,7 +1692,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 377fa4ed1518..0f8e671df5fe 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 1a29fe08a5d9..bbb206b01e8e 100644 --- a/security/security.c +++ b/security/security.c @@ -2131,10 +2131,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 efcd905bdabf..1004aa4fc5db 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -4845,7 +4845,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; @@ -4867,7 +4869,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 0e1f6ef25eb2..0bed974b833b 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -3887,7 +3887,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; @@ -3938,7 +3939,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 Thu Feb 28 22:18: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: 10833875 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 E7A2118B7 for ; Thu, 28 Feb 2019 22:20:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D814C2F245 for ; Thu, 28 Feb 2019 22:20:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC16D2F2A4; Thu, 28 Feb 2019 22:20:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE9322F2CB for ; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729805AbfB1WUC (ORCPT ); Thu, 28 Feb 2019 17:20:02 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:39088 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729602AbfB1WT4 (ORCPT ); Thu, 28 Feb 2019 17:19:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392395; bh=PhfowEp+3DGeterhV4KUylGtSjWL9Xf3fqYgDtVzLGY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=KxRl7PqP2LIQ1qjrDYvBQM/0SpgUqPCLfHpIjdASJnKXRfcMssfmiDtXTFXhzWM+TQE22Db91PGqJKoYDbVIWe8vhO5vwSScTEn/mu16KQ9L9p4dzgEIF+X81zSIv0Pqbbq0amR5nN1GT/q6jAYUj9XZxoj74GV4VvWmv+ixbER7lXJtattlrefV++IU4x6Wo5GSw6/GUzucR3/hcrookAkd6HdpHtM4Lt+9ivJTj4l+e5DYGUtOxbmd8YYGLBooC+L+HEyaCtfkA1htEpSQ+u1VqMV1MBuSslN2VOKzFO0wa9szQrGI42F8Zx2N9FVXUjXyYZYiO1+qY8XvXqgVEA== X-YMail-OSG: lPvaEDMVM1mJNMp_0EksKrmn2gUBZzk1XTI2Dn9g4rvqVjUI05toklDwLTgHYvD 7Cxh.ZBdTkmxxYYCKRf081GD2kvv3c8aSVcze2hA8R10iBRxaLFiHvjiVeewPinF4SlqBwQ0cfKD j2WMjC6ihC1rTIM2oCELbUCaGXpv9bqUj3pIv2PPmGEjRc1J8aAx8SNBHAJYxFQdoS8o470u8lc3 l6jhDNxCZ5S.ybOgnYnD7VrKMtjsnBe2KQhJtMtY1om6mlg4Vs3Yz20YKIkf8DQtNn6xoKIRXk5c sbPCQQF_G3nM8JPYyoruSvXveu8KxP51qKyVlL4JmUGWHhk6lA.wRRMrIitYHSyXEC_Y0iN0Fow_ DgFhGX8A_b5WtSaM.K5dMnUZh4r31i0Uh6zfF1W0qgYoVQjHtbS_eHYksU7ltnK8MiKZh4kVUULu 5nX40.xD6Los_ARUPjWLpc5YGMVVTQBfwCHsWI0Z9rwl42EPI69S8Yl00SeJYepPxCXEXNM1Xc4X PbCtQ2uScfVGaxsFoTgsKJgIzXEn78oPew1qPEOA0XKQbJFCXd0Cmi_457A8h3dXAItHKuqLklo3 VN8rgPIarDTDGvaKTPKDe6W5h5ePaph4QLRt0lZ_cnOtUatmqH6Jb6pT3d74ntGUkXZAj2lkNUm7 rM6uVsRIQ0oqxXthrRQFCQRKXSa7LSg2Lfrci.YKVC9DVEnOxdb1MipQpOxCt.5ZYwl.HI9aLzwf 1PxI_DYskXPyovnhQlZD5b4A_7ILB7WVoObYDstT_eMy7AxpxgUcmK0WIZE7B6ruxJ5JjHdcoY_w j4.WMzO0W5AOvj2RTskmZPSALTy.Bc7SXJxafOniADn9Bw9dOyQNFDP94tUCqXbv7AA3L516V53A fTxx4PcD0L7Ycn3ELKJFNiMmxNK0ieECTWJScucGmypEACzVPhpnGX7.4G2CrdohU9PJnOXfAS.B ScZtG_G2QqOtyPEsId3roz0hNH1DUrfTmLqIYYE3DOP1HQie_G1KmbnVbg5AFNCppQSiMnSVpWbT yONySWduNcvGyFz4lgn42Wx38AoiJkfVh7d1LgsCPpd9DINU6tQC_e6SmhT.EL28DTY_TJCTyWPL UxmyssfY2mnVKbOs5i6OzJHxujKnZWOtV2xjFS8KtT3tBkg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:55 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0da9962b364e649f4905df2b440bd211; Thu, 28 Feb 2019 22:19:51 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 13/97] LSM: Use lsm_export in the audit_rule_match hooks Date: Thu, 28 Feb 2019 14:18:09 -0800 Message-Id: <20190228221933.2551-14-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Casey Schaufler Convert 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 | 6 +++--- 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 | 6 +++--- security/selinux/include/objsec.h | 17 +++++++++++++++++ security/selinux/ss/services.c | 7 +++++-- security/smack/smack_lsm.c | 8 +++++--- 11 files changed, 58 insertions(+), 35 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index d4f260812c20..932af86333b4 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1341,7 +1341,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. @@ -1768,8 +1768,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, - struct audit_context *actx); + int (*audit_rule_match)(struct lsm_export *l, u32 field, u32 op, + void *lsmrule, struct audit_context *actx); void (*audit_rule_free)(void *lsmrule); #endif /* CONFIG_AUDIT */ diff --git a/security/apparmor/audit.c b/security/apparmor/audit.c index eeaddfe0c0fb..9a726892a068 100644 --- a/security/apparmor/audit.c +++ b/security/apparmor/audit.c @@ -225,14 +225,14 @@ 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 audit_context *actx) { 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 b8c8b1066b0a..5e4632bacd32 100644 --- a/security/apparmor/include/audit.h +++ b/security/apparmor/include/audit.h @@ -192,7 +192,7 @@ 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, struct audit_context *actx); #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 bbb206b01e8e..51491fda1bc2 100644 --- a/security/security.c +++ b/security/security.c @@ -2467,8 +2467,13 @@ void security_audit_rule_free(void *lsmrule) int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule, struct audit_context *actx) { - 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, actx); + lsm_export_secid(&data, &secid); + return rc; } #endif /* CONFIG_AUDIT */ diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 1004aa4fc5db..1cde918e4140 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -211,23 +211,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 36e1d44c0209..7daa44d188f7 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 @@ -48,8 +48,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, - struct audit_context *actx); +int selinux_audit_rule_match(struct lsm_export *l, u32 field, u32 op, + void *rule, struct audit_context *actx); /** * 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 4190c5e9e66c..fcd11105fafa 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c @@ -3376,14 +3376,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, - struct audit_context *actx) +int selinux_audit_rule_match(struct lsm_export *l, u32 field, u32 op, + void *vrule, struct audit_context *actx) { 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"); @@ -3397,6 +3398,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 0bed974b833b..d26a5e77a92c 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4283,7 +4283,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 @@ -4292,11 +4292,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, - struct audit_context *actx) +static int smack_audit_rule_match(struct lsm_export *l, u32 field, u32 op, + void *vrule, struct audit_context *actx) { struct smack_known *skp; char *rule = vrule; + u32 secid; if (unlikely(!rule)) { WARN_ONCE(1, "Smack: missing rule\n"); @@ -4306,6 +4307,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 Thu Feb 28 22:18: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: 10833869 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 DC9D14B54 for ; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8D4A2A62A for ; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDA4F2F245; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=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 7224D2F3A8 for ; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729626AbfB1WT7 (ORCPT ); Thu, 28 Feb 2019 17:19:59 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:45945 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727920AbfB1WT4 (ORCPT ); Thu, 28 Feb 2019 17:19:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392395; bh=vscZ9YAV9EYGaY9d6eksjc998gZocceOZ6hh36Ogb+U=; h=From:To:Cc:Subject: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1ZsCOZvHkiAaKTtVn1SK7UURxKXqxF3mV.mPisXOWCDfIk VUQsQ4h6bwPQek3A.9Rt4TOXSUCrqixRMQDH_92X8F8E9FBV9cjDKXytE719Awp98MJ4m_Gek7oc MM4BORzYnH3NHidyde.EOCXRz7w1bhvzPS1s2FMPTlEdngxNLVzSjelZ7sbGHvNwHm09cRjtyqZC 6LEDFIun52sDU2T_xIAfwBuCpcaUpOtNO7B.CL7Tzlk3oINRN7Pgxf6PauYYbMaZziVDAjrgnWIl ZoyG0UzMk1i07eV4rfGN3AqOU4QBDkSlU2EEiNC1mrKWOMaizLwQEnnKYk2KuG4GHANSfylYa5N8 olcwN3z36_hwOaWNxcFXASUjt87dzOT6XbdsXOsISDk6Om78qbWVP0kb_v0KWzgIzo2eVCqAs98v _IsvnKX7JfrC5YD9RVJdkofEnjJHswz_yIu3wSvuXFAFCFg-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:55 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0da9962b364e649f4905df2b440bd211; Thu, 28 Feb 2019 22:19:51 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 14/97] LSM: Fix logical operation in lsm_export checks Date: Thu, 28 Feb 2019 14:18:10 -0800 Message-Id: <20190228221933.2551-15-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix the 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 d26a5e77a92c..a1a9fdd3f1c7 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -475,7 +475,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 Thu Feb 28 22:18: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: 10833847 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 C6447188E for ; Thu, 28 Feb 2019 22:20:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B49702F2CB for ; Thu, 28 Feb 2019 22:20:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A7FBD2F3CC; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20C4B2F35C for ; Thu, 28 Feb 2019 22:20:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729528AbfB1WT5 (ORCPT ); Thu, 28 Feb 2019 17:19:57 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:46278 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729591AbfB1WT5 (ORCPT ); Thu, 28 Feb 2019 17:19:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392395; bh=n/0YPWUlTL4zn8PHiK5mlki3U/dbIxLef3XO52Tozg4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=qJTDmDS+QCCQbjDp1ZzTlJk8pIG/bUOY0mgQBfpKBG1olLn5UUyaFb069upIsXqncvJkUWVZoO+52fVl8Duudtr5Qj5g3l2i+L8JW+m7PXl9AFuZ3H+5Ic7Ep6AW/sjosW2Jrrj8IFtp2Tjfodz/wuVbsG3FscGg5a3eZ8BxVIygUC3/ScqGm2Zl4msOhQi37l0//hHmmWujG5Oi83kcotlAQZKf2oPPuKgH8t+A3dMX0s1JNTtX2zW7uiB6QrpNd1FlUXvYkaFTKH1zy6C+Dq0TtVakrysn1u6z2SXgROs1/2iCvxlxQJi0ucYt+42rJ0ZAYt+qrDUiSHMPxtY/Kw== X-YMail-OSG: CLA082wVM1m23PAtjkYRntjIj0dbI16QpbvyrvW5rKHnYK5hmD166iqnqCM6KC8 u4_vHzOQ_9b9P0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odtvyOFBs4goOeheIRe_xgA- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:55 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0da9962b364e649f4905df2b440bd211; Thu, 28 Feb 2019 22:19:52 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 15/97] LSM: Use lsm_export in the secid_to_secctx hooks Date: Thu, 28 Feb 2019 14:18:11 -0800 Message-Id: <20190228221933.2551-16-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the secid_to_secctx hooks to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when security_secid_to_secctx() is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 5 +++-- security/apparmor/include/secid.h | 2 +- security/apparmor/secid.c | 6 ++---- security/security.c | 5 ++++- security/selinux/hooks.c | 6 +++++- security/smack/smack_lsm.c | 9 +++++++-- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 932af86333b4..50629fb10cd5 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1306,7 +1306,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 @@ -1654,7 +1654,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 51491fda1bc2..6e05d3127760 100644 --- a/security/security.c +++ b/security/security.c @@ -1988,7 +1988,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 1cde918e4140..eae3c42c07fd 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6194,8 +6194,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 a1a9fdd3f1c7..83a2b1153790 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4348,9 +4348,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 Thu Feb 28 22:18: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: 10833853 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 40F331908 for ; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E8402F3CC for ; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2030D2F323; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DDAB2F2A4 for ; Thu, 28 Feb 2019 22:20:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729381AbfB1WT5 (ORCPT ); Thu, 28 Feb 2019 17:19:57 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:46186 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729528AbfB1WT5 (ORCPT ); Thu, 28 Feb 2019 17:19:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392395; bh=PYI3vyL47ujLwObxHa1iTlJBA3/bkZVAya4yPQPA0G0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=M22my2fBZIz+CcZJfQxh3Dgrd9bIIQDfm/aLjsr/9IBdo1LfqtNYCm//sv7SnIt7LDAkJbBmpFPYtNWS+5jxG7XA+W+S7YuMGp2UkVd9wMFYD55tAHMIWx67jQx6mXOc29pxZPH0zkfzfqPhe0RYGqlftJoy1JiFJGamwdeHupiJQAz7owzD+mnox6sjow6t2e4VSTDgZhQBqtgGhb3v+4m3kLlrEw2o4Lvrl90c2HmMNTeXpiu/i9BVxh3za4sY2CyhUqwLoDQYHd3OQEPSI9/aQaR5s46XlVBMIrlt7QK2bYRkVmkGonXDAEMOIniU0wl5JnIRvXGOMBpOHyDMVg==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_TfdlG ZwvOsUGbkBoQ8Ngw60aamcCB4uDyCQObyqORRT1v226EWhrqauQaVVTf4OdMHyTRqcMnkIitIXt8 vSVHcKWfTluOozMI9iGsMb1R3aAwQSBsreaFuQBXzWz1pgsk- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:55 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0da9962b364e649f4905df2b440bd211; Thu, 28 Feb 2019 22:19:52 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 16/97] LSM: Use lsm_export in the secctx_to_secid hooks Date: Thu, 28 Feb 2019 14:18:12 -0800 Message-Id: <20190228221933.2551-17-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the secctx_to_secid hooks to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when security_secctx_to_secid() is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 7 ++++--- security/apparmor/include/secid.h | 3 ++- security/apparmor/secid.c | 9 +++++---- security/security.c | 8 ++++++-- security/selinux/hooks.c | 12 +++++++++--- security/smack/smack_lsm.c | 7 ++++--- 6 files changed, 30 insertions(+), 16 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 50629fb10cd5..97ef535dafd0 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1311,8 +1311,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: @@ -1656,7 +1656,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 6e05d3127760..f3c29dd51c7a 100644 --- a/security/security.c +++ b/security/security.c @@ -1998,8 +1998,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 eae3c42c07fd..744fa6141ae1 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6204,10 +6204,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 83a2b1153790..1ee9c94c0e16 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4371,14 +4371,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 Thu Feb 28 22:18: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: 10833857 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 5421E18EC for ; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 472B92F34F for ; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B9862A62A; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=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 7CA7E2F245 for ; Thu, 28 Feb 2019 22:20:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726506AbfB1WT6 (ORCPT ); Thu, 28 Feb 2019 17:19:58 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:41373 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729583AbfB1WT5 (ORCPT ); Thu, 28 Feb 2019 17:19:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048;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nYgYwuuEeXO4dGUTa_lD_8w.rczuInx__ux7U_scPOTnIYb_3pkOXE ynr6RsnZmlSGaw3UD1XIX7QZrDVq.zE6L71YsUEVYCNn7tZEI25dawKtcbh.x_2LVFqLph1Xdn.O IS__GXvTbXNKEzeWbZWU_nB6nVG.tdbJCzLHRNaJUrgIVV.cU8O2T98fpOQaGYfoPMK8eMjvmNBK D.b_lUdTnwxjGGQlMTyJLdbK6OxLLJmlbhic.9uzqyYaAb2dDLAMYkFDQuoCYIp_Tt3uvjNwP4qd GBlnHADIWP02x_9GrT_wvdlxpiBsJQ2d7zt9ONWDVp2ax3hmkDgBgQ_AKskXRl1YKsasoL_.fxai UNM3NvW6qq9tAC8IyCDN5oUO2HiUKbeDAHbEYDWQSrHIgqWQ65S93j4xMRlcptBFbGL54k6iTxsK ZE0wMDMuTlOStTFgVacukp5BzBnEc_ex5Db5p8ZLYD70Y56tawi3c9_Jp3mi2OSXadxIkvahrioY nZR0ZMiWnFWUmhj4zZHlAvINuRwALEFkPYefHENLKDr4Xb8k- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:55 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0da9962b364e649f4905df2b440bd211; Thu, 28 Feb 2019 22:19:53 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 17/97] LSM: Use lsm_export in security_audit_rule_match Date: Thu, 28 Feb 2019 14:18:13 -0800 Message-Id: <20190228221933.2551-18-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_audit_rule_match to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/security.h | 48 ++++++++++++++++++++++++--- kernel/auditfilter.c | 4 ++- kernel/auditsc.c | 13 +++++--- security/integrity/ima/ima_policy.c | 7 ++-- security/security.c | 51 ++--------------------------- 5 files changed, 64 insertions(+), 59 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 785d21c81dea..73017c9e937a 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -90,6 +90,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); @@ -1696,8 +1735,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, - struct audit_context *actx); +int security_audit_rule_match(struct lsm_export *l, u32 field, u32 op, + void *lsmrule, struct audit_context *actx); void security_audit_rule_free(void *lsmrule); #else @@ -1713,8 +1752,9 @@ 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, struct audit_context *actx) +static inline int security_audit_rule_match(struct lsm_export *l, u32 field, + u32 op, void *lsmrule, + struct audit_context *actx) { return 0; } diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c index bf309f2592c4..c784dfa9fa23 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, NULL); } break; diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 6593a5207fb0..5988f4fce7de 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, ctx); @@ -646,12 +648,14 @@ 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, f->type, f->op, + &le, f->type, f->op, f->lsm_rule, ctx); } else if (ctx) { list_for_each_entry(n, &ctx->names_list, list) { - if (security_audit_rule_match(n->osid, f->type, + lsm_export_to_all(&le, n->osid); + if (security_audit_rule_match(&le, f->type, f->op, f->lsm_rule, ctx)) { ++result; @@ -662,7 +666,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, ctx)) ++result; diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 8bc8a1c8cb3f..72eb0efb22ad 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, @@ -346,7 +348,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 f3c29dd51c7a..43afcdf1e424 100644 --- a/security/security.c +++ b/security/security.c @@ -708,45 +708,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) @@ -2471,16 +2432,10 @@ 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, - struct audit_context *actx) +int security_audit_rule_match(struct lsm_export *l, u32 field, u32 op, + void *lsmrule, struct audit_context *actx) { - int rc; - struct lsm_export data = { .flags = LSM_EXPORT_NONE }; - - rc = call_int_hook(audit_rule_match, 0, &data, field, op, lsmrule, - actx); - lsm_export_secid(&data, &secid); - return rc; + return call_int_hook(audit_rule_match, 0, l, field, op, lsmrule, actx); } #endif /* CONFIG_AUDIT */ From patchwork Thu Feb 28 22:18: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: 10833865 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 ABFB2188E for ; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9725A2F2CB for ; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9353F2F3DB; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=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 2E9C12F3CE for ; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726968AbfB1WUA (ORCPT ); Thu, 28 Feb 2019 17:20:00 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:34791 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729615AbfB1WT4 (ORCPT ); Thu, 28 Feb 2019 17:19:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392395; bh=gSgSkfLKahMvLxEzg0eajjverS+j2pMpt07bcZcjOeA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=DgMO7t3eBYmBxF4sZbKiA6dqDNpg5/a/hdGIIZmnulWKZ3P7Y3VBpPSe1i8KzP23aYjW7yPLYMe8Mi/CuGnE97j+Gh992sD+L1cpYQWf+229KP+qymChOl0ZMznFbC8mwqaV5FwpiUs0kLHTE2Y8sOXJEbOAabkK5GViSWiZRL7YuFwbhZuOzHwlLO3bKvc+SDSUsh8mseahBv420g32HeWJ+cO3P15YTxetH9x23Jd77Cdt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HhFjRUAGPDig1eZS5wL4mEbVPDGSNfCanwTFLIITtAEkJqgaP.ejS6HyuwFrJD4lSVZLcLcfZSb 9Kn3bN_7qgS2Qtp5jA9.0lc3k6jV7MEo.fAM0Ty9hf4iU6.uh_YwKZHtY.8RLW2QLN_Z64w5LuLb SA_40Jv_m2c9BXnkdcsWcNlKz_S8oE5OuVRLmkKYzaBaftqk- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:55 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0da9962b364e649f4905df2b440bd211; Thu, 28 Feb 2019 22:19:54 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 18/97] LSM: Use lsm_export in security_kernel_act_as Date: Thu, 28 Feb 2019 14:18:14 -0800 Message-Id: <20190228221933.2551-19-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Casey Schaufler Convert security_kernel_act_as to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/cred.h | 3 ++- include/linux/security.h | 5 +++-- kernel/cred.c | 10 ++++++---- security/security.c | 8 ++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/linux/cred.h b/include/linux/cred.h index 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 73017c9e937a..08fb928cc86b 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -373,7 +373,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); @@ -945,7 +945,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 43afcdf1e424..1607f19f2824 100644 --- a/security/security.c +++ b/security/security.c @@ -1601,13 +1601,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 Thu Feb 28 22:18: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: 10833855 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 59A314939 for ; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46E6D2F245 for ; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A19E2F3D6; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C20762F3A8 for ; Thu, 28 Feb 2019 22:20:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729478AbfB1WT7 (ORCPT ); Thu, 28 Feb 2019 17:19:59 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:44040 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729576AbfB1WT4 (ORCPT ); Thu, 28 Feb 2019 17:19:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392395; bh=yBnhoz8U+buCNblcgn/U8UJglf8q679q3pCQpXPRINI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=KKmzWYhzjb3PY3h93nwMrB3tm/P7yUb/H1BSSudp/KyagtrRLLeCU44Jys0E03zRP24Lnmns1r7zZW52QIV6beY158PBQ3+XVNCFBSLwvCOrVigY8I1pjwxXqLKc0zqUp90aaGFhaILh3on/j+I9yFX1egzISBq/vHXcdouwvx5t+MVnM5GBmNtnuWcUQL/EKHbV2C69/7364GVicHaDzo8DuIpSOFMHAMnahLyi8JmrRXzSDH+UN+uqu7bdovcDz0QQ1SQekyjARViP021dOuOGqH5q0CxsAJkT+l5qIMkrYCSQrA58Z/B47StdFultFbDzKZmmspywYVtZTmWKMQ== X-YMail-OSG: aKU1ytcVM1l5Wgj2n1Ijvh057WMu4_22Mr.5pfe1lg7nKACal1R6RXc4CNGzHPr kn3l99TEY4mYgvpWwQOOahd0edNX7W6M79ybDrcVQ7Q3_oOTqOeymuQN20g956l44IV4ySXHV7dc 597Bo7QWTdpNQ8aizAUs8mvMtXWS6nEySwa48AVWCrfkZXIszQlVo4aPwFEbAD0bYZ_wwcEL6smE PkVDkUYKLUIHZiorMvcjUOsCqMC.sYn5g76zQflOetuRTxF93p.GmVVbxtEj3gNq6pjBK61fcc6p oFD4u6PK8N_hATzTk84m1B0ycdEMuw73u_OxaNWQ4KxN3TqrD26kg_X1gIohWabFmSfWDsW.q8Mj sIRmA.hoGlFM8it8gTXK4xf45_cWdY9Y3_s0NWq2JJ0GtR7DJittVnw3cgXOJh_HyBFIbQYr5zbv LhXMHLeot4351JK2TFvE6c.1Eox8vW9bhyJGUI46jmRmXwwrTz90R7iO2uwcHkSmvJ9K6XrbA8L4 gDSMcPzm6Xfq1AaJ_DVjyhoEBbOtnmzt2yBRePId3F3gxP0mjUVJG1Pp3y8Pu8mr2YLuRZQ7RVCi PMCEhMPXocWuyVMOJ8hlsUvNrE7Rig.1bz0LMcJXUowpupZwxspIzZcjthYUexNksOU.1QJGBjaa nDAyQ8mAbPalv4Zi4LYCdsGy5ADf8fIY7K40Fq8acYMVQAB9SHq.CehW9gq.IwVW2Qb4es9sdis1 HBBn7NGtHhuTCKYinAXgYRsH1JOpF6RJWOBwE9DGimZR76cOQ3R2FbBQz4h4hlzwhhe4AnKZqJoO tiskV1SzQFGv1lb.KBxpzauMEMSFuoDYWANDDlMslLVm71hHblyGCY72xUovMpEFZ_P2ABTHtpA2 pUx0.XWr8y9m2F2yZWhAYyvbCcazJGbSbH_fqg0kTiT9.gdUZsBuPJN8uZ.pmDnxVmvQoNnThGtp 6E4e4QPBwKpvzXvga2.joeDYy24J2_q37USpSWp7yV7_y5mZyX9kvGkyZgqETfxor19623cL4B_P I4FnqfhVS_YbUgMD1yg24BSfMqoIOxoyDh3yhdyuD1pqCMcX5z7Ou0fEGLmERI68Rrw1hYMGM9D_ lv4iAzJXbv44vn0LYctOaa6WHbzlAJtg2IrOtcDBy.z3Bby4- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:19:55 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp427.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0da9962b364e649f4905df2b440bd211; Thu, 28 Feb 2019 22:19:54 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 19/97] LSM: Use lsm_export in security_socket_getpeersec_dgram Date: Thu, 28 Feb 2019 14:18:15 -0800 Message-Id: <20190228221933.2551-20-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_socket_getpeersec_dgram to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when the related data is updated. In particular, the le entry in scm_cookie includes the secid data. The secid will go away. Signed-off-by: Casey Schaufler --- include/linux/security.h | 7 +++++-- include/net/scm.h | 4 +++- net/ipv4/ip_sockglue.c | 4 +++- security/security.c | 13 ++++--------- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 08fb928cc86b..5837cc2a5dad 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -1254,7 +1254,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); @@ -1392,7 +1393,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 1607f19f2824..b86ac7b8a946 100644 --- a/security/security.c +++ b/security/security.c @@ -2096,16 +2096,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 Thu Feb 28 22:18: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: 10833925 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 BA70E188E for ; Thu, 28 Feb 2019 22:20:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE0C72F3FF for ; Thu, 28 Feb 2019 22:20:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC4232F36F; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 094C32F34E for ; Thu, 28 Feb 2019 22:20:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729725AbfB1WUE (ORCPT ); Thu, 28 Feb 2019 17:20:04 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:32906 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729755AbfB1WUC (ORCPT ); Thu, 28 Feb 2019 17:20:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392401; bh=V43EQp2nHtiYphRJr4hBUbs8PYsKCo+3aftn1oHIhLc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=I438bRHyrrzwoMIViRYnOH5so0ZibZHyEGQWfvEcwZ1NCX04AMijSQHaFDkbI5kNCgmbZY4mmxDutPR0gksQNgel2azw1J3RjGjQhbqK/0K0NnnjeNQneKE5aXq+mMcOUNKP85IFeVrUKG+sijRBUCai7XVF0YYhSNs4BqGP0PuhuY8JgkNr2/kb2nAv+68xRBUHOPUqshO6G/d5v1YUaH9fYkePLk6ZeuTQlXZIb3zN3cxl30pqYQ+ZnRmXSg9yORiIf/H2JDq7Ea0k8ilRNBkyt6092Pp6qk8chB7vRaUOk9bXGu+MTrW8HAUeVshbUUaXcmeyEl1rU6hBjU6/0Q== X-YMail-OSG: nhFpK9YVM1kw98nB8oam2JZBfqVWREbYarf22L1ANDkWisNrG9QepDO1CNS1Z2I wzotwMKqD20_flwBB9gatN6hbx8Xm9ibeVfrZ2RcxH8WotAeqK9YUPZ3rHeompcWsSATUd0pxLOy fybj8hPlZdp10J7lcW3Dk08TKyscuM7Q_7Ctt60yTCM9nfyaOWf_TQNs5NfTlxZynfujP88.3IQx UYn5bqQyA.GjKXWvmmCxVtV4zC_EzYTrfOehFV3QlKH9PsNYfwC3znIkXIZ95BC.NTT5Dj38cBqv mxEWdTVr6RXGJ3aKuwXo2gNfdVvSHBE97pdVsT065pflQMNJWY.WFgCDjqgdGew5uuC1guO.wTbX yBDP.zJjxI3TTdcAJQ9uN6VxoBelz2PSYnTjMyKC7BKEMU9WRDa7l8Boqm4I8d9L1RfTOS8oRayw jvdzoIgzA7euY1AaMNomp_ugTjFS4T9KBPE6Enpr1ioLaf9908_HJ96FbyTvbN7lACQMLvOPR35x UB4MRM31g5L6ZISnP7NE3mx9Mpz4kL2_Yq5giECv6erpJl4M8oIj3dBqPymSeHIPQcgNQXJFfyiA TLVFAi.gw8oF8IT0ZR898cHw_0sea.Y58gWtQvAi7agBpOL6u9nidZhlSvfxwplO6CxBP4X9rttj Vd_9VVBcU__r_3Xej9nU7StUO_tj52pGnT2M2bJu2qlqK39TfFydCZXfsYVHYVKgBhYZViewvBip rMAh3KwPgnJxn1xGZwouKORWLFdJmqshFKe9HruEhAPBgDmpP2xzOz5DNN9PA__Lgwoto.AfBWg8 SvfZ3hALL5aaqlSMKh8pYdWdD4j0G7uHyVoCfOpiITJBJMGZ99C58RNEq4FIMeCOoN8gqqGRpsXZ OcFVHs0SN5H6sTaus0GCYHZIauCzAqMNVvJ7uIOl6Z2m.klTD2MSZlChd.u0QfDsruWoYt1_19kk lVMll.WKFKtt1SgT6xyURDn598K1gu0abgQMGhHarPDWpgUd1JCOY3r1MZQH6ecyriOTGVSyxuZa G.8_sJs0o1bT9F7PgjEEQbOFpnXSmjJr19OxPO9kt0ZpInsA6UvZmtw0x_Eouuu.coV1WRT8EcEY DP2vG..p255jkZCIFHCbOk0wgqLwWbQoRPfywGQkFfgxIAO.Tu8dZHvfWAHrZUxR._Ta.WUOkH9X m32v6wMVxOqstmj.Ja2BsH72T9A-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:01 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp406.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 5c7d685bea94a92cc9d12c4cc22f1f0e; Thu, 28 Feb 2019 22:19:55 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 20/97] LSM: Use lsm_export in security_secctx_to_secid Date: Thu, 28 Feb 2019 14:18:16 -0800 Message-Id: <20190228221933.2551-21-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_secctx_to_secid to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/security.h | 5 +++-- kernel/cred.c | 4 +--- net/netfilter/nft_meta.c | 4 +++- net/netfilter/xt_SECMARK.c | 5 +++-- net/netlabel/netlabel_unlabeled.c | 8 ++++++-- security/security.c | 10 +++------- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 5837cc2a5dad..330fc7ac8d7d 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -432,7 +432,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); @@ -1204,7 +1205,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 6df486c5ebd3..a03de2ab833a 100644 --- a/net/netfilter/nft_meta.c +++ b/net/netfilter/nft_meta.c @@ -564,13 +564,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 b86ac7b8a946..da3ccb19dcae 100644 --- a/security/security.c +++ b/security/security.c @@ -1953,14 +1953,10 @@ 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; + return call_int_hook(secctx_to_secid, 0, secdata, seclen, l); } EXPORT_SYMBOL(security_secctx_to_secid); From patchwork Thu Feb 28 22:18: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: 10833887 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 7959118EC for ; Thu, 28 Feb 2019 22:20:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAAA62F2CB for ; Thu, 28 Feb 2019 22:20:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BEC1F2F391; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 442D42F2CB for ; Thu, 28 Feb 2019 22:20:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729817AbfB1WUD (ORCPT ); Thu, 28 Feb 2019 17:20:03 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:33906 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729764AbfB1WUD (ORCPT ); Thu, 28 Feb 2019 17:20:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s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RHPBLHC5igTkqpwTp.GukflyplS7hzSNaxiyszWc_VauRT5 5Y8qrKTk6u2gPjociaOiHfbh53V29Oi45hx3fRcOc3SNrdz7XO6P3jb9qYXLJb4y3oHz.q4KwYHj Vl5z4X6lsDqtqzzeTBun.ReBTJWOtLqMHKSRvyntE0WwUnxcjiH09zC20yEmjFnfwlqQ9Oq7Dzy2 MEPIHlpnPdQUZ9vp9oruaNsoT6CdpCbfCkvE.EEdEEWoSKKRH9jVThJNwyX_b3..9en6RCrwjynx k4DRLdIXubHLHZyXm_z9fUavShtcUTA8JNgNY9Ygps9GkJoToMDAyu.gUdWt3mTqDc_pV9HdF31x _tNNd1H1zXQl4y04cCYtQQeTfXTlIEUnCjxf6f5gyuFrjBnpjMx5JFCtWAukPWFZP3AMOZ6ACzKL 3UVOzDDEtUSuhR0cBaESaAyFYt01E1uFS2z4AZULS377QADiaC9hxe7pnV3tM7MYe4FJU2H7ZNIj slPoohpG343aibxB5pw969iXh1r3edo7I1SCta30G0VU_rZ4- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:01 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp406.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 5c7d685bea94a92cc9d12c4cc22f1f0e; Thu, 28 Feb 2019 22:19:56 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 21/97] LSM: Use lsm_export in security_secid_to_secctx Date: Thu, 28 Feb 2019 14:18:17 -0800 Message-Id: <20190228221933.2551-22-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_secid_to_secctx to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/security.h | 9 +++++++-- include/net/scm.h | 4 +--- kernel/audit.c | 15 +++++++++++---- kernel/auditsc.c | 8 ++++++-- net/ipv4/ip_sockglue.c | 5 ++--- net/netfilter/nf_conntrack_netlink.c | 8 ++++++-- net/netfilter/nf_conntrack_standalone.c | 2 ++ net/netfilter/nfnetlink_queue.c | 6 +++++- net/netlabel/netlabel_unlabeled.c | 18 ++++++++++++++---- net/unix/af_unix.c | 9 ++++++--- security/security.c | 8 ++------ 11 files changed, 62 insertions(+), 30 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 330fc7ac8d7d..d0adf4032baf 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -112,6 +112,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); @@ -431,7 +435,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); @@ -1198,7 +1202,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 632d36059556..aeed1368a166 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -1418,7 +1418,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; } @@ -2167,8 +2170,10 @@ void audit_log_name(struct audit_context *context, struct audit_names *n, if (n->osid != 0) { char *ctx = NULL; u32 len; - if (security_secid_to_secctx( - n->osid, &ctx, &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 (call_panic) *call_panic = 2; @@ -2207,12 +2212,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 5988f4fce7de..0d4e006a7ae1 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -943,6 +943,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) @@ -952,7 +953,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 { @@ -1168,7 +1170,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 { 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 1213beb5a714..d19092fc6580 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 b6177fd73304..51dc1e390d84 100644 --- a/net/netfilter/nf_conntrack_standalone.c +++ b/net/netfilter/nf_conntrack_standalone.c @@ -171,7 +171,9 @@ static void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct) int ret; u32 len; char *secctx; + struct lsm_export le; + lsm_export_to_all(&le, ct->secmark); ret = security_secid_to_secctx(ct->secmark, &secctx, &len); if (ret) return; diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index 0dcc3592d053..537effb6e5be 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) + if (skb->secmark) { + lsm_export_to_all(&le, skb->secmark); security_secid_to_secctx(skb->secmark, 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/unix/af_unix.c b/net/unix/af_unix.c index 74d1eed7cbd4..e2327428aecb 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -141,17 +141,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 da3ccb19dcae..0026edf0a424 100644 --- a/security/security.c +++ b/security/security.c @@ -1943,13 +1943,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 Thu Feb 28 22:18: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: 10833919 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 94B5717EF for ; Thu, 28 Feb 2019 22:20:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 782872F3CC for ; Thu, 28 Feb 2019 22:20:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75F7C2F4E9; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAE032F323 for ; Thu, 28 Feb 2019 22:20:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729679AbfB1WUH (ORCPT ); Thu, 28 Feb 2019 17:20:07 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:45191 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729666AbfB1WUB (ORCPT ); Thu, 28 Feb 2019 17:20:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392401; bh=6Cf6FrfCTZkdNEsoOhKYWIoy1Gi5G8OXKahME1H4mJQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=mMITaC96ncYoa1Ds1eQt4zaRmo1m9LMx5qXhVd0Z+FzKyfe7FgxglCHLGlax971Fn2zx2UGxP+c9HArrUg+at/FNDh3R5fUEIYo7U3tH0LjWXv0NDwdfZlELPDdOL3W5ZxyohoLs79sAs+6QtIWJaMszwuNJV8m0WwG2QVzD96VsFLLKcM0vNznXkkYvQXAyqF/EZIKLQEWkQIrv5qoO3yPG+yAtY8HuK/4sh2XzGJTHviFYpdHKOO+FT6o2TVpm6ouc4NecQ7DCkC0bInElRtqlPOvSMcZpiIUIz7By8+D8bv0lWTUmDz0aD5VrSEUdIbzdwkEpCXQS4d0XxR1acA== X-YMail-OSG: k1EOSPcVM1m9sWgStLP9_VoUTiEfa2N5a9EZR9CdqBnSOmN3G39P_X7dhm6XNzU 4poAG7OOXdGIAfyK9vPVloKVOQZ6hc_nlIAs.vuMV9F.Q9Yy3N6of02NDH0q59s02AnigW4jdIre bYhCsUdc5O4JTZOjZPoBXX1UBlaIC6t2weovGGZAQhLO31M1LUEAGyx0xk1eRA8dUF6mCmKlefvr 6InTu7OjoHWJn2jDkV10RdHkhjZmQmveBoxpw8POZvrnQ2tmlDAC1ojEl77WGPJxgAMfGSbwnHuF DE0eQyFLYLZq9Js32V5udSDuyKtLZXUMCUzxiPROZXnZwlSFQZk59HZNX8n7r6KRVEiHGeZdeLnH gyUiAc.XmDqQD1ZvnfgK5mSME9HZoocCz5d8qvUvJtNem3_LJXlrJYn2pInbRXG34w05F.XHx2NW l_YC.dmG2RLmmUCQQZkr81tT6Ws0AH0igS4BKkggxlR1YmsMlwvfZRBQyEJrNJ0dPMNU1oueqrA. 1t2Qg9AgT3QioRXJ57KloZZtMHOrHz4HLELYT2fG0rTxjpurjvzIebsfTMWkxJSCXPS1h2tSdzNx IWQmVxuQIlfLN6Jh3WzkCos1bgeVPXiGkKGiK9uadZFTcXG4hZKct7.zObpHXRJtKl0nOUaa5mZd mSrn0MBgFMMHT_VonwbUhow0CEKxcPOB9paGR59j6dY5lQc7UHT4aYpAT.d7y.dXjZ47WrPvsABv 0pEg9q8HPDSDvzJ3oR8MRDq7s5qILB.NQRIdF0Q038_pkKu_oY9EfYisRodgOFSC6x.x03V6t9gu CsY8jpF0gkR4RnEdDfPlzqN..g_ouGRToaXUOQG2FB4uaRXjZE9S7XdR6BOaE3PXr77vmXOWIVhG XHTvBzLuOJ566PRiU4wIip5ydfFmbvXCArqLx2VkqypQDj1FRnHRvp49fLH_zdJdj86ZbNVi3xrg hIfv1cgcIrTUv2GUBkArECjQ7TEcEiNfL3jUnnfYsOGr0DoZmoRLpGRJ2gLWjHZ2a1mfVEiIsVA0 ..sCFMLENPjv14qwdG54nxOdyhr13ErroTkYxAPzNHH4PxgOn3Mz3D2W3BTn9HLTMM5NPuCZBqa. IczPULvbKvtWNaYKgBg3_AjJsZNxfzvQmgqb.GcAmZTba.QOg Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:01 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp406.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 5c7d685bea94a92cc9d12c4cc22f1f0e; Thu, 28 Feb 2019 22:19:57 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 22/97] LSM: Use lsm_export in security_ipc_getsecid Date: Thu, 28 Feb 2019 14:18:18 -0800 Message-Id: <20190228221933.2551-23-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_ipc_getsecid to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/security.h | 7 ++++--- kernel/auditsc.c | 4 +++- security/security.c | 8 +++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index d0adf4032baf..48ad03f6631e 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -406,7 +406,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); @@ -1080,9 +1080,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 0d4e006a7ae1..6a991e4b1492 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2166,11 +2166,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 0026edf0a424..8e4cdc88acce 100644 --- a/security/security.c +++ b/security/security.c @@ -1761,12 +1761,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 Thu Feb 28 22:18: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: 10833903 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 ECE2A4B54 for ; Thu, 28 Feb 2019 22:20:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D14572F3CC for ; Thu, 28 Feb 2019 22:20:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5DD32F53D; Thu, 28 Feb 2019 22:20:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F3CD2A62A for ; Thu, 28 Feb 2019 22:20:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729988AbfB1WUG (ORCPT ); Thu, 28 Feb 2019 17:20:06 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:34230 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729553AbfB1WUB (ORCPT ); Thu, 28 Feb 2019 17:20:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392400; bh=e2Zr2FG9sfFjX/bU49iDB+XEpXaQ7bM5zLunLaV8ZcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=fw5e5JVVG8lQVbnyFxtfimZ5JEqsGLlwz3O0hMgggJzrhsndKCBUzQfu/WxDYG2hDlPHTs+4LB+k4cE7mkvk/kYrL1THIeyriCpnOfuHtxwcwcXbsU1xiMzcjct1udhryXqHlFszqEZr0M1qcaBjaqPodHwdjva+TabdiN4fEXq/XTIHC+5BFTLrO4GUWm5EMjAFtnHF7aPLi8EkJBHEd5JFh3lVgbX0f9hHWOI/cKb5MwLkZiG4QnOPh2gvNO/VQPOwVoXvLDd6deaBVKgXBgfu0Wkc3XAeTUhYKA2G4R707jgxONyo5f3okh/jQr7F4SF+znz14i1T0n85+9G8jw== X-YMail-OSG: ODgGva0VM1n.s4TqBLXoLQ74N5ChuYwTK_BSjwWkjqHmXW_vUb79wqOEgEaLycy OhcFHZKUD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M9n651EFnkTm8iFMLSbzzduXYqPFeOyy_B81_0- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:00 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp406.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 5c7d685bea94a92cc9d12c4cc22f1f0e; Thu, 28 Feb 2019 22:19:57 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 23/97] LSM: Use lsm_export in security_task_getsecid Date: Thu, 28 Feb 2019 14:18:19 -0800 Message-Id: <20190228221933.2551-24-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_task_getsecid to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- 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 +++----- 9 files changed, 43 insertions(+), 27 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 48ad03f6631e..d6c56bbebc84 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -389,7 +389,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); @@ -1007,9 +1007,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 aeed1368a166..32753b1e686a 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -2214,11 +2214,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 c784dfa9fa23..223e5e949247 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, NULL); } diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 6a991e4b1492..8f0748395ae7 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, @@ -2262,12 +2260,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); } @@ -2284,6 +2284,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 || @@ -2294,7 +2295,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()) @@ -2307,7 +2309,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; } @@ -2328,7 +2331,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 a2baa85ea2f5..d0580a1f157e 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 4ffac4f5c647..e78658b26a74 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); @@ -469,6 +475,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) && @@ -490,7 +497,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 8e4cdc88acce..a0767f8d7822 100644 --- a/security/security.c +++ b/security/security.c @@ -1676,12 +1676,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 Thu Feb 28 22:18: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: 10833917 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 9C8AA18B7 for ; Thu, 28 Feb 2019 22:20:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E4D02F36F for ; Thu, 28 Feb 2019 22:20:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CAF12F57F; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB34E2F36F for ; Thu, 28 Feb 2019 22:20:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729764AbfB1WUE (ORCPT ); Thu, 28 Feb 2019 17:20:04 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:42294 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729725AbfB1WUC (ORCPT ); Thu, 28 Feb 2019 17:20:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392401; bh=tPfjNLF8Rut7laLw6/UejSwyv6D6+KBG0Il9a0Y2lyo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=J2EFwnGNKSYoAJhrWn7E3u6QkYbc9wnMJxFWp+yT6eO5xyzfFEbsOLx8Ksefy7VIgNTswcn8cdYHJmOzoCYmi40gexTcr+PJ74pQQ7zb+kY8EUXoQ4bQUfa1/vAAqzwcqt6eWMKHyGRq/b3RfIPo4yVidKT7SVXfjb8FBDS1MQC7tM7lbCrThyeyjTzTRMLhJUdXXNy/P3oTTH8RXUvl9h1BvE0qA5GMA50YJ6qo1GMHBvf+7Rwgngvr80bKCJZumiK3EyxcwD++sYJZnHa5r8Nmib/CbdZQK7ipvR/sFGLD2VNScHb9NR8nfFzPHZab/JwDlVFzknvm8yHwm/wP5Q== X-YMail-OSG: 9q_dgJEVM1nxVvFXGAorNjH9fW4G4G7xUN1Qs.Y57MApq3Nxlgx5N9QZk.cVBOB g7Py4LQgPw_D6Dr9xLJTFuBBvtOGj9kz6IO6sQYLA3ma3_Jx3huowqfLheoJXaF.Uig.XccCxRS4 LFBbxSyvT6EU.j24rfNBc7Lhcm3BBN7JRt741QE97DAxyAOVbaEDtRElWY0IUeMYT_fLYjb7BiKo fHhYq9pRP8lrKjMN7T8NomO8qx4ineIKpWm4GFKTEcfuPBV92qVePWyNGeyV1eK_5qvm6rxBsHeu afWq_pMegIm_fCtKXZfKw7wuWpQ_JLxnUtgeOzuH.ioJckDgmZOSXKp9eI69vET4BIn5GEiMFAfu x2Bqw60fgGhiVxgcs6wXBAMwQdwKhWsfXovVXSnKdi2KhABU8uVRttIBTO18Z9WgsH4HPyWgeLzl 7B1wX7Eb9_bFlky.98wlV1SF1BczVsRiUatdweM6F1g_1cauYk2xgC2Wc4llFjVJ5hNV.GgP8N9V 0RPwJUwuTip0ltyUSY.lJSzU71oKDa.sNH3xMozr9geRdZ85w0yqOCCOvhMUPrKTysVwDtuNHneq Dttr894M0WZHCBiNAAqE9NsJZWahhdkMbaRvfqyhUYcI7nhxLdH5030LWdJDvpkdacQ6Up8TO0fW fMcGAFvzdh1W78rQ6QtQfWG82prFQGXGLRIQPK0Hq3HZbzcWverC7aKtmNQaJYzDyTuqVGEGYT_f spdUZ3yN1Y6z0RheN8MK887RkDfb_efTcozoYsLmvbvxH2UhSezcuJsQHZQnH5zXXHVItvykubyE bHJyqdKyfK43FfBHiwB5Z19NBaZoC5qThWurma1LT2kZJuNCOVN09_Woc77fZ6vuVtHywIJu3wlL hbRoZx1edGYhbVrKF7tSIO1JPuRX1XAh7.Ivru0eeL.Mt7HWtysCL6fsElQaMeRX45RkVL8GhEQ0 .pk7wGdiXIZ7IPsI0AkX7wWTsnSynx.nKLa.rfDda9MIuuAXxixs.0nWzguXBXTfKYimKeEFDR7F fmxZ7uKRQQvwaPOpNACAnc4kni.KYQEBTpPJttPQyKcJDVyNlUJAnHtxMC.aQg1w0DwzwXEfeZ5k vOazRISVw0It0cEhg4IzTUo0SfFwB._Awf.R0Vp8.bIAFEOU- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:01 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp406.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 5c7d685bea94a92cc9d12c4cc22f1f0e; Thu, 28 Feb 2019 22:19:58 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 24/97] LSM: FIXUP - security_secctx_to_secid Date: Thu, 28 Feb 2019 14:18:20 -0800 Message-Id: <20190228221933.2551-25-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Initialize l in security_secctx_to_secid Signed-off-by: Casey Schaufler --- security/security.c | 1 + 1 file changed, 1 insertion(+) diff --git a/security/security.c b/security/security.c index a0767f8d7822..66f8ee392af5 100644 --- a/security/security.c +++ b/security/security.c @@ -1948,6 +1948,7 @@ EXPORT_SYMBOL(security_secid_to_secctx); 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); } EXPORT_SYMBOL(security_secctx_to_secid); From patchwork Thu Feb 28 22:18: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: 10834079 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 E48C7139A for ; Thu, 28 Feb 2019 22:20:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8B3A2FC94 for ; Thu, 28 Feb 2019 22:20:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6FB92FC9C; Thu, 28 Feb 2019 22:20:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=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 925612FC98 for ; Thu, 28 Feb 2019 22:20:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729931AbfB1WUk (ORCPT ); Thu, 28 Feb 2019 17:20:40 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:33029 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729663AbfB1WUB (ORCPT ); Thu, 28 Feb 2019 17:20:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392400; bh=UQjfh0v16AxJWcccZZiZEJMDUSepDFazKRU1XVl6thk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=mh8RaDtEIK6adxBCjINF6fsh0f6WDhdJs288T6f3JsUkmUSNUJUTyRAK6QfuZuWyord+0IJnm/msv3lbkjo+KsM7iia2lvo6e5z84G94IXT1Jn96I7ZKjYWtlda7lTj04eZ+XbSetDthwiDNONepa7++Fie3CNxiXTKD+WEDw3XGiwSK3RJljDvxFKwnB/WuhrPkThRqNu/TSw355gAzp170NQCXCqSuMXhsjEHAroiHneG+lN7jDHOxi0/HlsGwmxZwqiS4jGdpVT6A6NNd37/9vfBiw6EXFDgUJak30ktY4FhT2RRVRVqJFYHz1KRJC+mS7TVx//qd+U624Sq4yQ== X-YMail-OSG: LlSbQ_EVM1nhKYIZOdbAZdv7qN5DoxDdlD5BDkoQ6b6kJ9Pqmlvk3n59k0vGb4c l0Tlf17Ppw6ZBQga70oljqEw6x9tv6WDwfwGrq6xWUUM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JxqSC6lIyyCA2Rs- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:00 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp406.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 5c7d685bea94a92cc9d12c4cc22f1f0e; Thu, 28 Feb 2019 22:19:58 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 25/97] LSM: FIXUP - security_secid_to_secctx Date: Thu, 28 Feb 2019 14:18:21 -0800 Message-Id: <20190228221933.2551-26-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix in netlabel for security_secid_to_secctx Signed-off-by: Casey Schaufler --- net/netlabel/netlabel_user.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/netlabel/netlabel_user.c b/net/netlabel/netlabel_user.c index 4676f5bb16ae..0266879efef1 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,8 +113,10 @@ struct audit_buffer *netlbl_audit_start_common(int type, from_kuid(&init_user_ns, audit_info->loginuid), audit_info->sessionid); + if (audit_info->secid != 0) + lsm_export_to_all(&le, audit_info->secid); if (audit_info->secid != 0 && - security_secid_to_secctx(audit_info->secid, + security_secid_to_secctx(&le, &secctx, &secctx_len) == 0) { audit_log_format(audit_buf, " subj=%s", secctx); From patchwork Thu Feb 28 22:18: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: 10833891 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 7D7D01908 for ; Thu, 28 Feb 2019 22:20:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C1962F726 for ; Thu, 28 Feb 2019 22:20:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 609302F3D6; Thu, 28 Feb 2019 22:20:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=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 738CF2F35C for ; Thu, 28 Feb 2019 22:20:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729755AbfB1WUE (ORCPT ); Thu, 28 Feb 2019 17:20:04 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:40416 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729783AbfB1WUC (ORCPT ); Thu, 28 Feb 2019 17:20:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392401; bh=oolrFMQ2hX0yuhkjwNb5bUccD/Sys8wBNq/oV2egimo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=pU9d6haW4+gGFJaNbvlhnG6fuK7phdzftUWJhdVL4bL4Zho+1bCgW7lIcxZbRsGZOyviz+1Fia14Jj9KA+BFnMCs1RuQ/52nsWjVkMKTSQxUtIENWKvuyadrqRpIaifNUI1xwd/4PAua8qckivHbbj5ARTeSozfD6dtYt7Y7yhalZPOHIsiAk499R7NIEN97QcnHKNN4PVdFjOipvU7S6djlziZMhJPVAfl04hA8IHyf1SHVwfmf93MoDQj5XPAYiX0SIfjQtjo2/MRLqSjzh3wCyJS9fM0lDO5iCDtU0BNwPqvh8v9cW6moE7tbEZxoOb3m4D5rk7mD2UsPtfVE2g== X-YMail-OSG: Qm2M75sVM1n.xr5RdEsQ60luOJuYDUXdkpAjYHfjB4vQJijRJiaUvy9nqOzYoyp C1w7JCfso0jliIkeOT8cLoACeg6qKZE33gjgDzbj0Xb_YnlDE0ZM4ptd6K2l2ntlVJrim1EE1dGr VXMZhEyBYaHd_XwSDWLN9vNspngppLVrkhHn7puYNeno__0AW9YdFB1IAmV4Zjm1fZ6b9FeAd5A2 hp0evIQWYSsEwjMWHeRzkil_jcvTXOQ9WF.Oohwydv8j2Gfq5b71L8pDotyZZsZZjlM42g6kECc5 iuvHCL2hFa.AQEyJXXWwQlbY6g3vlvVDmX7OFbnT6bWldkt5V8eCLsDHV54dOlJDAqVK3auWVP1H _8153jNfaAeHI4svlkYeZFeq7zXro2WL8ye6qe84crNsG0ga98mVsqBnMPQ3j6Wsf_Kinf0O3ftV aIx469Pwq6O_cPocxu388GyAE4Xdr.DINFgkNVJSsPql90dKyE4SgtTkLUEQ8VTQ1UB92N3cgtI6 IhRGkGXV3.34BVN06gm26bWVMt7NMQAgKxqJEd6khz2Io0qQGLMEyb2YdXAz6O8wlGAxyngifNnj nZz6ugieanD7yjYsQdvNflkpVh5.eeiiVTQLVvymKsADuzhuisWWgraKClPGZa_Nw_g5dceBiBWk sCYFuq5yqShKfqevkRjoQLQbwtSt9RaWSFgjgfm0_ZkOIfMEepMjxlPpK17A77qMeJDxNVzgCiPH R1_GESvF2ruR9ilxpZ.NojSo2Z8Iw0tJE5OKdTNjWzpQwawfsmgI7YLJLR60kIuqUu1D4DSlk4xj D2LNdlkG_dSVRM1wl7F63dNULS5oL7Qa68uQzJaRQs3Q5.UGwiwTmR_lP6B6dSTxBdnNX36Y49pG Pc5XTYdH2epMdB5EB5U.2SFBivPhtzT4Y4pt4PxsP6fx_gvk1B0Y09zbqlbfzL_anrvgRtQUzquM g7PxjWsJJITwpvAPb1t7.eiN6n5eTdUC7pbXU.Q0N33naiASeb6qZlSunO_PobMXdnDZmw45qxIS SWbSquU501xbg53AsX8RZXKbPM9RVt10T.oy7TpOcVuE0CHX8Z9USvMRAZJniucsiA7sVFEebvA7 u4aOo_GU85JftV_qJYpB5v_b1gWSjsUf7htGJspHh3taAD.I- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:01 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp406.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 5c7d685bea94a92cc9d12c4cc22f1f0e; Thu, 28 Feb 2019 22:19:59 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 26/97] LSM: Use lsm_export in security_inode_getsecid Date: Thu, 28 Feb 2019 14:18:22 -0800 Message-Id: <20190228221933.2551-27-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_inode_getsecid to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/security.h | 7 ++++--- kernel/audit.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 d6c56bbebc84..07fd36f6616d 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -351,7 +351,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); @@ -836,9 +836,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/audit.c b/kernel/audit.c index 32753b1e686a..4b1fe327145d 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -2104,13 +2104,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) { + 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); audit_copy_fcaps(name, dentry); } diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 72eb0efb22ad..6f05e96e5db0 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 66f8ee392af5..c2cf82b063ca 100644 --- a/security/security.c +++ b/security/security.c @@ -1373,12 +1373,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 Thu Feb 28 22:18: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: 10833877 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 54F3D17EF for ; Thu, 28 Feb 2019 22:20:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4345C2F34F for ; Thu, 28 Feb 2019 22:20:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3819D2F35C; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F20612F2A4 for ; Thu, 28 Feb 2019 22:20:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729513AbfB1WUD (ORCPT ); Thu, 28 Feb 2019 17:20:03 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:33157 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729776AbfB1WUC (ORCPT ); Thu, 28 Feb 2019 17:20:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392401; bh=FzVvjR+NFksvu4dNddqr2/PVXMCrtqnd2aRCMpeNGXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=JUAMnVGZMy+yL+kuf3fNwhI2taDO7JFPEx5V6n1gJjZNqwxIz6SLBKVnyZE3k3ms9BPPRQpaUc1qKzqYz1kWorOVUah2fKf6bRj4J4+MSTwzhKP2PFdZ6wTXJcRS9vE0XigJP+80/eFnP9ANklMTqss4BhWFDhPV9T8CyQKxuFNOIOMUJG7R78Egc793+YkLzFdSRLl/EkGXly8Nr7bdMKFTDabu1gs16FHKOP6mx8oO2fF3m+97+aCU65NoEJWCFeUFbhl0zPTwPmItlnl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h_gzLkPgLL.MzwKCK.I_S3pAAxvx0Y9U_vhCaiftg4ma8Cr1TkKGu wqP3cJQLWGZLqhxb8kxTQTeMFp_CuQJvSjMqCYKq8jGf5VnV00q6kO2IX4cOaE71d7zxXV40qU2J nGnukyZ8jUNUDJTTtDlDb2BmzfF1RtpTnaDPITcPflLK8EJ.T Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:01 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp406.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 5c7d685bea94a92cc9d12c4cc22f1f0e; Thu, 28 Feb 2019 22:19:59 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 27/97] LSM: Use lsm_export in security_cred_getsecid Date: Thu, 28 Feb 2019 14:18:23 -0800 Message-Id: <20190228221933.2551-28-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_cred_getsecid to use the lsm_export structure instead of a u32 secid. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/security.h | 2 +- security/integrity/ima/ima_main.c | 3 ++- security/security.c | 8 +++----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 07fd36f6616d..87085ff519bf 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -376,7 +376,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 e78658b26a74..7efc806eb5ab 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 c2cf82b063ca..06461712c881 100644 --- a/security/security.c +++ b/security/security.c @@ -1590,12 +1590,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 Thu Feb 28 22:18: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: 10834077 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 9636B1515 for ; Thu, 28 Feb 2019 22:20:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A35F2F359 for ; Thu, 28 Feb 2019 22:20:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88AB52F3D1; Thu, 28 Feb 2019 22:20:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=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 3B0BE2F391 for ; Thu, 28 Feb 2019 22:20:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729833AbfB1WUl (ORCPT ); Thu, 28 Feb 2019 17:20:41 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:45649 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729671AbfB1WUB (ORCPT ); Thu, 28 Feb 2019 17:20:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392401; bh=CO4B9SsgBMm8T7hrH5GKIgw3RD7XFjAFy3qVi26z7EQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=YnRPj/38PS34ReKF3eeFN95CJdywR54+AayfbtpvpEdwISBS20g/tOa7R7bLBgHQITKyl7RhM4idiWx4MoB5V1h0GEZrUGcVoV6yYwd5pO+DgOxHYOUH3mKUdrsLlDKwLErCJEKduHaub4WM3tNLKIdYgFrV5MDmm88qapAdxxcRGlzOYNCx05GdFtkmOggrAXwT0Z35hWQRRwzjrWSHFIu4iyuXPthCMJcLhSJAxdyAH1eHUtPDqnAFRc4iCH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mJDvEOEYMbA53JOKZWly2BwL.yFnpdRXVExERICP5hGGkpaWwwH46a.d83VrLGdoqqc bnU5euDtadLlv2vt1c16R_y6hvkCDcA6hAoB5QaOlOtp991UC91P5meH7wHyQygNIqKsJ4HQ5iy_ 3xBnmryHBgpJ7G6V0sbZ4be.wEOrZJNTCF_q06R02GgMLRXmr Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:01 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp406.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 5c7d685bea94a92cc9d12c4cc22f1f0e; Thu, 28 Feb 2019 22:20:00 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 28/97] LSM: REVERT Use lsm_export in the sk_getsecid hooks Date: Thu, 28 Feb 2019 14:18:24 -0800 Message-Id: <20190228221933.2551-29-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP REVERT sk_getsecid use of lsm_export Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 2 +- security/security.c | 5 +---- security/selinux/hooks.c | 6 +++--- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 97ef535dafd0..cbfc2a9b5f27 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1699,7 +1699,7 @@ union security_list_options { 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); - void (*sk_getsecid)(struct sock *sk, struct lsm_export *l); + void (*sk_getsecid)(struct sock *sk, u32 *secid); void (*sock_graft)(struct sock *sk, struct socket *parent); int (*inet_conn_request)(struct sock *sk, struct sk_buff *skb, struct request_sock *req); diff --git a/security/security.c b/security/security.c index 06461712c881..e52b500adb27 100644 --- a/security/security.c +++ b/security/security.c @@ -2116,10 +2116,7 @@ EXPORT_SYMBOL(security_sk_clone); void security_sk_classify_flow(struct sock *sk, struct flowi *fl) { - struct lsm_export data = { .flags = LSM_EXPORT_NONE }; - - call_void_hook(sk_getsecid, sk, &data); - lsm_export_secid(&data, &fl->flowi_secid); + call_void_hook(sk_getsecid, sk, &fl->flowi_secid); } EXPORT_SYMBOL(security_sk_classify_flow); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 744fa6141ae1..9879dd828e1c 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -4889,14 +4889,14 @@ static void selinux_sk_clone_security(const struct sock *sk, struct sock *newsk) selinux_netlbl_sk_security_reset(newsksec); } -static void selinux_sk_getsecid(struct sock *sk, struct lsm_export *l) +static void selinux_sk_getsecid(struct sock *sk, u32 *secid) { if (!sk) - selinux_export_secid(l, SECINITSID_ANY_SOCKET); + *secid = SECINITSID_ANY_SOCKET; else { struct sk_security_struct *sksec = selinux_sock(sk); - selinux_export_secid(l, sksec->sid); + *secid = sksec->sid; } } From patchwork Thu Feb 28 22:18: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: 10833929 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 3F2774B79 for ; Thu, 28 Feb 2019 22:20:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FEB32F2DE for ; Thu, 28 Feb 2019 22:20:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E0132F584; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94EF92F2DE for ; Thu, 28 Feb 2019 22:20:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729826AbfB1WUM (ORCPT ); Thu, 28 Feb 2019 17:20:12 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:43158 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729783AbfB1WUG (ORCPT ); Thu, 28 Feb 2019 17:20:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392405; bh=t41F8yAeWdEONiYDCZmM0kjDJ4tBt5I/NGfNVjC2m+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=kTkod6nuazArdhQmAAMF3Ygv188kQlqpctiV3dJgIrLfFc5KBu3IhrQ+jzKHq2Na1bCBopkKOrGbTM2g25tPh3dNcGHb6IeC192pcauFt4PV6op2bmVKDSt4UPOUfopvL6oCtVRkMklskERw48UFBOqbMP25/KLtHyA3oCkoBA7o2up4RdJSQAxVaw3O9HIQSQfpALi5rFWVFQDlnhy7tnMV0G+V/JJ0J3oMI/kwPabDx/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6DJFbvUg0Mx3 z36FeRnibwApt5DSP3a8zAhIolg36XnjUAtCldRYtZZ0T1RNj2dC_jrdBF0TrdYxeKhI0Xr1fjNZ 1lch8XviCugexx3UmOCq17xL18di6Yfbr4r1qdIWuJlXAuvEfv_st9rcJM.cj3r__wEEcm5N6zey wABEo9unbre.Hg0o0s2Ar.BCVBFEo6b8iH7rOGDGPu2Uwy4L3 Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:05 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp406.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 5c7d685bea94a92cc9d12c4cc22f1f0e; Thu, 28 Feb 2019 22:20:00 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 29/97] Audit: Change audit_sig_sid to audit_sig_lsm Date: Thu, 28 Feb 2019 14:18:25 -0800 Message-Id: <20190228221933.2551-30-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Remove lsm_export scaffolding around audit_sig_sid by changing the u32 secid into an lsm_export structure named audit_sig_lsm. Signed-off-by: Casey Schaufler --- include/linux/security.h | 7 +++++++ kernel/audit.c | 18 ++++++++---------- kernel/audit.h | 2 +- kernel/auditsc.c | 3 +-- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 87085ff519bf..ae79b24f076d 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -90,6 +90,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 4b1fe327145d..f89fc60b34d3 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] @@ -1417,23 +1417,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 91421679a168..06c732e0f301 100644 --- a/kernel/audit.h +++ b/kernel/audit.h @@ -330,7 +330,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 8f0748395ae7..c57c2e346c6d 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2295,8 +2295,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 Thu Feb 28 22:18: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: 10833941 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 7191A4B54 for ; Thu, 28 Feb 2019 22:20:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 567362F2CB for ; Thu, 28 Feb 2019 22:20:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 545ED2F57A; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D81C2F404 for ; Thu, 28 Feb 2019 22:20:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729849AbfB1WUM (ORCPT ); Thu, 28 Feb 2019 17:20:12 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:44237 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729920AbfB1WUG (ORCPT ); Thu, 28 Feb 2019 17:20:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392406; bh=RkkT8VCXXloma0Fq/QmxeKgnWLosnAsoKiC6R1t6xs0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=rJoexait/gFkMkP6lsEGLJWa6eeNVahGo3xUcEfA6c9cTqiyqdwuxbmndrfGDyDwjt2GMYPd2r7mD2kkEIg28auhIBGvIBZY6fNJgPIwF3R4QbN4OkH7ZefcuK9nqJaYVKpLqQv0YElQW6MXooHX4K4iGTKZYXLpepRjJOQDjNya4RLgbn1lqlQG4rRAh94RA7Jo6p9aM93hY3SfWYsFw3AOlzPKX+grMqWRtB/oZ1qpbXjWR8D9ZG7cGyOSGiF/aIh2wONUrbUnFVtFMhPuxahlcbRivj33ufIFpTBcurB2AQZU+kjLGqLRKRN7JBjl+qyWmYc0KMlOScQ5lvi5gg== X-YMail-OSG: jEm.EwcVM1nxwz7G39ySxyN_SP5CWoVCLNzNh7fbTZrdG7LbgIbUTh5ZYqab6zG _.jLw1SMXYYnVoT984yuD3XwYWfqCWp5D1.SNXK90ZUsvqQMoxVyeiydpgsI2FvmMbq7_IKiNGDH CS6veEx.nfpQTFiFtEYowM.q45vbwXfcItgVkSBWlePMZ4ck3wP0Y1lXMbeVLL1QResHTCC6a.na GkJA0l4_I0.3u88KNMGt0uH4MpdGetIZb.CuVfrdUIfgYqbqRK0LKrniMV.u_4J4rlMcPkIOdxSy _hS3aNY9z9DinXhTEOf1mNl8_Vz9AuhadWKrPYTMuPcUj9_UQN_dCvvqespRQq6eJwle4QckY.Ic 6aDFE0VGTi_VmLfguLy_izKekJGgFPV1dYXiBz.kkf0sAj4Hx5M6_wv7Uk8U1Ei1fny1qw6Or0_y ks5OEiPRVlFBPDAC4F2hV.KtwCohTuMIhR19USe6vpY2PNf3_SIafYaSXYUQZmJnWfuSxspplQbD QcS1.F8zNXH1pk4VJy239Nm90lw_l86It1PkF1AHqyxqUBK8PetbmM5m38CnqcjIOtgkMOv7_TfR 41M2xhFx7_NKFzTk1ozOyZVENBTJAVciyGrXOJh4h_abjCiz4zaeicgUt4y4jZL8P12Qy3ViDGVf lUKElSWBZcZBLuiCi18GFT2_QdT9ypDL.J4XQeSxvZx.kpnxIoGk6.9JZovbSP9fmljt06adbBoC jgBW7AtboDANT8qXeTnOtfVdreYXeHL77NAHKYxsUFen.0iH3Cbv1OKN5D6JyEOEPFK32kqOl.rN mg0mBf5wj27_hgGHnyTbxJI8SDuEhx3kaSpM902y5KlELy8S78iyLPQ5y953.bPjffdhAWB3ET.J dux0BwmCq8bTjRndeUHEy8z_kTxbzGPlAWGFeRdEElFO7sIfOs.au2CnEH9.tHXTmTnVK50HHfhr KVvsAWW643_OzsYPneDxXCvwa__NZbaxs2q6nWxEFwDTDOOqRRQ_gpseQcImuZjLuJzmrQMHqKMQ s2yT_7bkHAvWg.bt3ft_xCfG4yBzL_g1XjW6VLiFIw1QbuRp6fuhew8c0D37ozz5.B6_7iP7dGuV YZciNRm3lXQg4WeTmiThDBIq8IntpvhD4Ez2yDXFfBtBrF3g- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:06 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp409.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e8fded081226753664bb344863181a7a; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 30/97] Audit: Convert target_sid to an lsm_export structure Date: Thu, 28 Feb 2019 14:18:26 -0800 Message-Id: <20190228221933.2551-31-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert target_sid to be an lsm_export structure instead of a u32 secid. Clean out the associated scaffolding. Change the name to target_lsm to be descriptive. Signed-off-by: Casey Schaufler --- kernel/audit.h | 3 ++- kernel/auditsc.c | 30 ++++++++++++------------------ 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/kernel/audit.h b/kernel/audit.h index 06c732e0f301..63883a773aa2 100644 --- a/kernel/audit.h +++ b/kernel/audit.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -146,7 +147,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 c57c2e346c6d..2ee74d18c90c 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; }; @@ -934,14 +934,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) @@ -950,9 +950,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 { @@ -1401,7 +1400,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; } @@ -1410,7 +1409,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) { @@ -1587,7 +1586,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; @@ -2260,14 +2259,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); } @@ -2284,7 +2281,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 || @@ -2308,8 +2304,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; } @@ -2330,8 +2325,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 Thu Feb 28 22:18: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: 10833927 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 C708B1575 for ; Thu, 28 Feb 2019 22:20:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF4792A62A for ; Thu, 28 Feb 2019 22:20:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD9CC2F3A8; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF8272F3FF for ; Thu, 28 Feb 2019 22:20:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727648AbfB1WUM (ORCPT ); Thu, 28 Feb 2019 17:20:12 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:43928 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729826AbfB1WUG (ORCPT ); Thu, 28 Feb 2019 17:20:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392405; bh=NuwxabuwXKPQuPkTBG+ktKnf+vpaEZcwOMco3zy0Pd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=hKBAstceQ1z1Q13DGDzgcTSr8enZjFe2KPUsm/Hr0Pvs6/j/Qal4nmS6iwB0Z/+fxzN5Pn/rNT+PPMnXentJiSSMYvFrnPryGQZaJz+MotzjTY7bvTE6/tzOfVFKV9IWWWNMuru1hAI9OWO+plV+A+HxoRr0kRY5Vegk3RBqqg+tpPsRKyUQQF7y8aL9u1y4f7KzMmx5gUhUpV1b2S6yLcqldYoCuyjtR7WgAnT5ypnnx3btv8yCXKR5+WrtLbHgy8KadzWJQ+DM3S3s1xLb+jwFdK3nflHdvcujAg0FR0dZSbTaj+0eGQqrg1y2FiaP35pvYRXyEVO0s/lmsAkHjA== X-YMail-OSG: lhaSxwEVM1kjaXcjn3aTuaZQDVD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FuY4H57egEDeU1hJhcuBnSWdzt j5mNY5mV2SM7eHxtOxAVZCscYE2K8mwrZuLH5GuTQY2950Pih Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:05 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp409.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e8fded081226753664bb344863181a7a; Thu, 28 Feb 2019 22:20:02 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 31/97] Audit: Convert osid to an lsm_export structure Date: Thu, 28 Feb 2019 14:18:27 -0800 Message-Id: <20190228221933.2551-32-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert osid to be an lsm_export structure instead of a u32 secid. Clean out the associated scaffolding. Change the name to olsm to be descriptive. Signed-off-by: Casey Schaufler --- kernel/audit.c | 17 +++++------------ kernel/audit.h | 4 ++-- kernel/auditsc.c | 23 ++++++++--------------- 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/kernel/audit.c b/kernel/audit.c index f89fc60b34d3..8f76f164d2af 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -2102,16 +2102,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) { - 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); audit_copy_fcaps(name, dentry); } @@ -2168,14 +2165,12 @@ 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 { @@ -2212,12 +2207,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 63883a773aa2..7bcabad8104c 100644 --- a/kernel/audit.h +++ b/kernel/audit.h @@ -90,7 +90,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 */ @@ -164,7 +164,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 2ee74d18c90c..090f9f2cb571 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -646,14 +646,12 @@ 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, f->type, f->op, + &name->olsm, f->type, f->op, f->lsm_rule, ctx); } 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, f->type, + if (security_audit_rule_match(&n->olsm, f->type, f->op, f->lsm_rule, ctx)) { ++result; @@ -664,8 +662,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, ctx)) ++result; @@ -1158,19 +1155,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); @@ -2163,13 +2158,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 Thu Feb 28 22:18: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: 10833897 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 A1124188E for ; Thu, 28 Feb 2019 22:20:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E2142F35C for ; Thu, 28 Feb 2019 22:20:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 802A72F649; Thu, 28 Feb 2019 22:20:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B700C2F3CE for ; Thu, 28 Feb 2019 22:20:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729767AbfB1WUI (ORCPT ); Thu, 28 Feb 2019 17:20:08 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:42917 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729915AbfB1WUH (ORCPT ); Thu, 28 Feb 2019 17:20:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392406; bh=rTF09SnAjSsZdv1RDo3fHsuRZG2IUT0yBUCiFtcq8Ts=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=Rhp57v+xFZgBVQ8XJ0sikrLmgPlZU6Cs4aKY/aWQSdZmzg6+ipD89NZ0pHIcS05RFT+bPxaiDrRabI5tu41f47SgTsYnC8VEDu4MUlPgzxsNSuY83udAvCL4VuQRFAFyeNWGaeqdiojWGYfsYlW/XHrKGRRVxSOit06SX2qKfBw74rGT/zkRhJEwmTABuDzFIccpRrlUDLGrNfDrdHoIt4ewiXB4YVFb++rvvrs27kEaKmLUi1C3UiCmNET0qYpY5gg4IcJrujRJgrYtaAZHVzO3/sVq/mS3skL5ssNGYKC+VAraMLbLdZGLQWQCWwOKVPDbzwjGyNZnanMBXORvcA== X-YMail-OSG: e2d.LFwVM1nuYBrWVpRYyXAVBSfaiJr9YbASGiJBgRvZw8CVgSTerUeGoq4LKbV holMZA8GNOH6HSjDrgptWC79jLed_oKB3EmJMhMR65LEOUnRRfBJOBoAhOcE4Grh1Q_b4tbUY_9W NhDSIzVaaANiYRLkkgQsQebSOcsTcxje2rSSHAUpULQ2Ijm.KG.ZDf4BROS9EAJUzSzpVTSqU8M0 WU3oHA9Orjy6DMC9Ua07o6we_UVeS_u1KN_VVz2xlecD_NXdMwJc09Nt1dd_0UEvZJw9e9ZiY3AQ kkgo2r_yEJWr.bZXdtjbP9R6xHfH_pbZOkR_vBlx3bSpo.yw659JeTEZTlaWUnvAFK4Za5OWeuCe TjlkAhDXjfx9aKb.TnVxTOQvDiPIfbKIYvZc7q1uFYHkdECRESmRpIGmo_WI4QxZtQHtAcltLzJa RER884OzKlW8nmsBufh_86Gcb7zZxkppGNLjvTJDp06cG4fnk6QECTiJPN.IZ_xghsV4AUMOtztu r9o5a013nEKMSDVIce7slp2Rgw08kRbOIKNKlBfYXx4CwaVpfkDkQKdwInj2uf9xwbm5_vxPFhBT HQjwOHqyXUfmIqms3oI60KK3dvV__4SGRd0_ActKtFsxBz0bPmR3EkroNBiGNNtTswm6U7ak.fS2 Q.uy4b2Hx.OmuFYyJkxV6chO6LyRwyemTdnYFjBMNgQvGD.2LiOCd4_kWIMkbyAtWywcH Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:06 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp409.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e8fded081226753664bb344863181a7a; Thu, 28 Feb 2019 22:20:03 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 32/97] IMA: Clean out lsm_export scaffolding Date: Thu, 28 Feb 2019 14:18:28 -0800 Message-Id: <20190228221933.2551-33-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Clean out the scaffolding used in the lsm_export transition. This requires changing some of the IMA internal interfaces from u32 to struct lsm_export pointers. Signed-off-by: Casey Schaufler --- security/integrity/ima/ima.h | 10 ++++++---- security/integrity/ima/ima_api.c | 9 +++++---- security/integrity/ima/ima_appraise.c | 4 +--- security/integrity/ima/ima_main.c | 25 ++++++++----------------- security/integrity/ima/ima_policy.c | 14 +++++++------- 5 files changed, 27 insertions(+), 35 deletions(-) diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index cc12f3449a72..2edaf4c41300 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -191,8 +191,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, @@ -212,8 +213,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 d0580a1f157e..b2203ff2bef5 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 7efc806eb5ab..c3186ae42371 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); } @@ -475,7 +468,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) { @@ -499,8 +491,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 6f05e96e5db0..b5d12db3cfb3 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; @@ -346,8 +346,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, @@ -396,7 +395,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 @@ -408,8 +407,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); @@ -420,7 +420,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 Thu Feb 28 22:18: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: 10834071 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 9BEAD1805 for ; Thu, 28 Feb 2019 22:20:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DAD22F3D6 for ; Thu, 28 Feb 2019 22:20:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C3962FC90; Thu, 28 Feb 2019 22:20:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11AC02F53D for ; Thu, 28 Feb 2019 22:20:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729881AbfB1WUk (ORCPT ); Thu, 28 Feb 2019 17:20:40 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:43712 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729976AbfB1WUH (ORCPT ); Thu, 28 Feb 2019 17:20:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392406; bh=ATJToVBjnuDBIC7U6KtklpNvDxWpsaxtFTNEcUSwbgU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=qsg0rstvFZf4l5V8P7aoXr0OzKbRefXTT7AJxuHhswaTcBxosIeqGB6KD7cj1iqxDTr3Yh65IX5kf0/o68no+7OB6SzXI0beDh769bCTIpUQP+J6E3ABgOyP0fSS0mrIRAHI2zKCdFDr/ovMYi9dGGmW4w0nDDVUSFBcLJCqPzLah5LrkqNwztBrbpS7psvb04C+tQ5/xng1vgJFJ1My7UvRmD0sisWby3OPBP4QPS1Xatd/KCFswFRUPHZOMvHCQ6CI50WbFEkQOzcj2U0UlcRncMV4ZVrywzx1oFqCuHJuQxrxhBWjttG3u2sPOLU6AQzjlRnXb32WJouh2UoqQw== X-YMail-OSG: IzJelawVM1mkjcIIccWL1dEtfwi6vTTXkzyezLVL4_yBtpnxGtTa9VHWt.xjlex wdx1p8MDJOBDfMVZsIwk04HpUsCm5klyzaGQKkdMfPNApxrQLD_DB1TjLAkc6DQ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ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:06 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp409.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e8fded081226753664bb344863181a7a; Thu, 28 Feb 2019 22:20:03 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 33/97] NET: Store LSM access information in the socket blob for UDS Date: Thu, 28 Feb 2019 14:18:29 -0800 Message-Id: <20190228221933.2551-34-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org 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 ae79b24f076d..6659ffa8cacc 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -68,6 +68,7 @@ struct ctl_table; struct audit_krule; struct user_namespace; struct timezone; +struct sk_buff; enum lsm_event { LSM_POLICY_CHANGE, @@ -97,6 +98,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 @@ -140,6 +157,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); @@ -171,7 +190,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 e2327428aecb..df183ff69d61 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -141,21 +141,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 e52b500adb27..2f9411b93f70 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 Thu Feb 28 22:18: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: 10833935 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 673564B77 for ; Thu, 28 Feb 2019 22:20:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A9882F584 for ; Thu, 28 Feb 2019 22:20:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5901B2F2A4; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F6E92F2CB for ; Thu, 28 Feb 2019 22:20:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729910AbfB1WUL (ORCPT ); Thu, 28 Feb 2019 17:20:11 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:40059 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729875AbfB1WUG (ORCPT ); Thu, 28 Feb 2019 17:20:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392406; bh=Jz4wQbfcze3bBK+GjSLzGZEmDjIBtwBHzwn7qN6Q6k8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=hSIqaYh6PbqlXOxe2Fzo6xGDw66Hi84ejjfgRC7MI+eSsNVbPQWZmU3rkiRMIaDPrpxwCKr2WwDIZjh2k/CGxw4P8iIO+FAEYdW7w4crqZYq3qg6pNF+GUOUj1oEG9w5LVWCa9HqOZRTq7C94untjG4GRrUhnohcrDk659eQg75kHOanfR7eJwvpqcWDYHn5PUg5C/5FbBR7jclxRwN847IylxWD6FAA6r3K72kTwyEeOAhag98+JMjEIZ59hXWJ4HsNJTNOVHl9NBFf7qvaWjcwXhwfNJ5j0VeTW5WPBTt6kVaxAaX7eBfAUYqGwXhcKD77YsEuH2pxXGnlBkAYkg== X-YMail-OSG: qrBHQY8VM1lH65mADLgUEFbPFjPuuHiuYyLmaBpYGUBgXf0SBvZeIy41S7ZfgmG lC6fsCEcaNqboDkytPbgiSVKTCkxwHsimnL4cxxnNSK.IuF_SVfzavnQ5YGxw5T4TN1j9ai6i1ML 4zH8VpTIJ8CCnlNJ9TF8UM2m_c.K_eg8D1sG6UiYAaDvPKzYVWMKgecnvSzeCZ8U2BbPVwlRxg2V dj8kd2qzI4K_GaHwF45JmVGN10X4fETwUDOA17XGOgUm4FhjpJ7awGNmRwXCptK9ZCjgXsi.zr0U HhKvcx7nfi71WAjY.4rp.9J.fqqnCSjzYxItfY0sshin0EvIehmGx19qO.ZuCFcgkm2TuhYUuVvi 9T8bSlBn2EOYIl..AiGoKJ3UPiFiK_hKuk9LuhDW65Ixr4y.gBeBRkr_9_Xmpdxj6BKPJDgUSAdG wYV9IGHYaR0hm8UMtL3IUdspaZ9ZBQP3SP3BPxqQSqk.hlnk_iy1AGFIomF_I_WLMxnUEQd_cnc_ dmLuxo89t.Kimf0ED4aZBeHdBLNLvBT4WSiLM3JSfpAq0yFOPUIdcbmcyQ8b5Ayx2M1hV2luvilu 0mlBXUrRcXfmXbjk2Qk3ZMFYc.MWIdhEfvcIBsmknlyU.nvp73248s2KRYLHR3q4uQ21bATNmcVw 0KYYf1FeXwifiMUJGQBP_0E0TyQu_UYPJ9LbG8KU0iKhze4iEecC1ixW4FYNzco..ZCq6wO25ldT wOX8T5eWPusmj4dfdLFDtCg2i2m.nJILt.h_6uaUqyTvb2a0zQFNQWnzPmJeZooPZcDW242lTsFr yMfu9tC7KUpEekg_._nfjR1_FoofgmIvYz06vHKNYILwg_XQYEnp10.K43u0yuwYU6rFY24DEnke Tl5LZNbl9t1R5FmNjnanp.9BrJ.pVszT9jCtBExHXZHVg9qdpmjcMIpqhugAJ5KGBF68B5RrzrDK MFbSje9NmS09iks0eeoVN3gWC2eGCtWDmdYsx0CUVv9sW1YCjhA7IT0wwncbDx1lj_mSrIF9HQJp VtWq_My.5T6vudvnnB1ShsqDNJYtYCnI0Qp7DifbDN7pTdQIWEFJikmviZpp7nBBIIEvA60DKd7Z W8bVl5zkSJtvVyc0QgwkWRhsfOKo.IVope2mwrz4sL4sIuVIq Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:06 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp409.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e8fded081226753664bb344863181a7a; Thu, 28 Feb 2019 22:20:04 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 34/97] NET: Remove scaffolding on secmarks Date: Thu, 28 Feb 2019 14:18:30 -0800 Message-Id: <20190228221933.2551-35-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace the lsm_export scaffolding in xt_SECMARK.c This raises an issue, in that Smack users have been using SECMARK_MODE_SEL, which is suppoed to be exclusively for SELinux. This is worked around in the code, but not fully addressed. Signed-off-by: Casey Schaufler --- net/netfilter/xt_SECMARK.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/netfilter/xt_SECMARK.c b/net/netfilter/xt_SECMARK.c index 2def8d8898e6..9a2a97c200a2 100644 --- a/net/netfilter/xt_SECMARK.c +++ b/net/netfilter/xt_SECMARK.c @@ -55,6 +55,7 @@ static int checkentry_lsm(struct xt_secmark_target_info *info) info->secctx[SECMARK_SECCTX_MAX - 1] = '\0'; info->secid = 0; + lsm_export_init(&le); err = security_secctx_to_secid(info->secctx, strlen(info->secctx), &le); if (err) { if (err == -EINVAL) @@ -63,7 +64,12 @@ static int checkentry_lsm(struct xt_secmark_target_info *info) return err; } - lsm_export_secid(&le, &info->secid); + /* Smack is cheating, using SECMARK_MODE_SEL */ + if (le.selinux) + info->secid = le.selinux; + else + info->secid = le.smack; + if (!info->secid) { pr_info_ratelimited("unable to map security context \'%s\'\n", info->secctx); From patchwork Thu Feb 28 22:18: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: 10833895 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 760001575 for ; Thu, 28 Feb 2019 22:20:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6323E2F35C for ; Thu, 28 Feb 2019 22:20:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 542E62F649; Thu, 28 Feb 2019 22:20:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38A2F2F3D1 for ; Thu, 28 Feb 2019 22:20:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729915AbfB1WUJ (ORCPT ); Thu, 28 Feb 2019 17:20:09 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:35157 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729872AbfB1WUH (ORCPT ); Thu, 28 Feb 2019 17:20:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392406; bh=XvxKnEkF2sbi5gT9OtymXDF9xExofaDsGkL7ia0bjZs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=ulr1SYjPuhynVx4q5Td+Du1DN038UtWX4WMeHc+AGMsGcTLldUkJNhYSk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cMUSviVessEJUrFCoW_onWHy4ysXu_cu8KNf67jRwcOmKodgO7GKz5gIiVY9 xxf6xj5k7LTUQc6yaMxZN9FnWpZnguctPXjwbObfT0lqXgZdilHBFjizUjkD5V2Dc.EETG.grN2Q Fd0nTh5uHlAuNE_CoxlsOeFzDhHLxdHGUgeNBGqYihVDj1D73yUe6JwXfzWCPe4LgoXk7TQOD_tk EmdqHFjzR57enfSXXfgQWkt24iBf0Zyf.K0S7yrVV4EtBAI1xXC8VTiai_n8qJKneYX5swxZ1HAw LjjciG3CuFPTGqosPCAWgOUNOVoSG6Qf3xrwXcxVzN_VBm54P6S0b6x2RpNVMAIsFj1XC5YT9cag Zg9sBI6iQuQMbICp.0G.0SiMCRUo9fSxY6IfZuyt9fpld2vKX Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:06 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp409.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e8fded081226753664bb344863181a7a; Thu, 28 Feb 2019 22:20:04 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 35/97] NET: Remove scaffolding on new secmarks Date: Thu, 28 Feb 2019 14:18:31 -0800 Message-Id: <20190228221933.2551-36-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace the lsm_export scaffolding in nft_meta. Signed-off-by: Casey Schaufler --- net/netfilter/nft_meta.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c index a03de2ab833a..9f5040140fe0 100644 --- a/net/netfilter/nft_meta.c +++ b/net/netfilter/nft_meta.c @@ -568,11 +568,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 Thu Feb 28 22:18: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: 10833911 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 7AEF94B61 for ; Thu, 28 Feb 2019 22:20:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 664EC2F5FE for ; Thu, 28 Feb 2019 22:20:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4345B2F897; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B25112F3A8 for ; Thu, 28 Feb 2019 22:20:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727110AbfB1WUM (ORCPT ); Thu, 28 Feb 2019 17:20:12 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:41154 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729849AbfB1WUG (ORCPT ); Thu, 28 Feb 2019 17:20:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392406; bh=TqFt4zRbObQqWQnSyYrS5KX3V7rGzJAbZlzxUBMPhvA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=Oh8/9Oc59baoezBg7S5fD9pK31vyr4Bi9muOMNVgbzF5cGH7OT8ZH401QpqC8sbqSfia1LjAMwGnxJ+GJgBaiqwT+uuZVF9KdljznKykwXP9GX62Lh+J/gPL+so64ui4seeh9w0hotBw/pBrTHlaA8ZCJ7ab+BCj+dN+FKUAITPG6bJYf4uypebxp4I7xyNCI7hW6vMZ0jjMUcCmpmmejKcHs4Ol8J1on8SBx/qowrB+WvMZVYs7Mxrc1OLVE89/Gf8hl3BHfN66XdXaWpwYDuI20RQ7pjQRNeFGMS9DbtasQh6Y+wwGgYcnRIK1hn51ycOElGw4opYXffdscO3hpQ== X-YMail-OSG: LA_AOVYVM1lRl9SN1gg7iOKUP02Dclb5QmF36ebI.73RjsWkMsa5n4EnBEkY3YA HTb_QgP3HcewhvU6NRWtvaK9DRybRridJSPzB.AK6KPE7Xn0PHebt8h3ZByVmt1GTElDl2Ka5JUc AbeQY9.CBQzRhFhcm0gWFJrxfx.xefBF37rz0wS8t3i.pLNhLwYyxE2bZHznTev70h_Lz1kIFqs6 HcYMJyFnMM8QA7LXeAIGJUwbGWmZsHOrB.Ybo6HxUpxFgslfls4Dvx38FwG2LgChmE3RaQ5xR_gS ybJHAwpmPlDiSpE0yn99Rz.uefNX.czqPSfWcKrnlVJWJGUwZXyfNpFqd9zyhpFwTPJmTKfSQKZD xsQHPix1h0IXGUc5p7S2IgphpR0kSYRHsR8BtpccSHYQWzpTVWbeb8E1DJjejtJn4vbE.r3r9LQE bjsbehKkeXXe9XiD6jMn4.U.y.uh5FzCh2L_JskZiq0TwIuLeZaspZXIBg_vgX_1UwtwgDBy.A1S XeK1ciUIus8T1C0VG2itGsMZygdUIqq.j7pwyzgze9lrHbzUgmLk9mr69RF9DpxTLJTh6dOQIEqn cfeXPDGSJbM3SW5H8UwHuQ6UcGYEuwQkSJjixQ2i6ro_zulYOFR0k4KydrRRGuXeyPyQV1Z9RQWM l_mlsLIx69ewifcO4jEdIxqfmpzCwmR_BJ6iaQElVOoQ_bFFnYqLYw3kldVFrFLp0V926kzk7Rqo rnvOGVwHCHR6ScsTClpIbRCQ0yJq8Iave7SpQ05FdvxaHLP93nkVFgtyKlG3jbyh_3UF9DOSGmBJ Uux4cMZPH0MufmISy1PPjfqzZaA_jmPbpTAZsm6KCgMtCHh5QiFq5mAzgqpBPZCXoSpWXxmeo.Wn rldt02pZOFTFUXFbJAtxheSYW2JJ3CDgsuu14TzMTaLBMe_t.jVA5G9Qmp6..Qg1OBA9vKj2uiLG FCTrgGK5JhBp4xS9THn6clry82wdrUoNdyhfZRuw5TyKv3Inv4vCazWYqNXp9WbDN_grPuacXue3 Hpm5yAa8u2OoPcoBi6tPfSbYc7COB9OPeCRrznbRh71vGS6BZ9uPL5iENPUChdld0YtD8o17Z_0Y ZLpXDozwBhxYUjSC_KSZUX27WHNLPvqIiDEeLKVm3NGAraYY- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:06 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp409.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e8fded081226753664bb344863181a7a; Thu, 28 Feb 2019 22:20:05 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 36/97] NET: Remove netfilter scaffolding for lsm_export Date: Thu, 28 Feb 2019 14:18:32 -0800 Message-Id: <20190228221933.2551-37-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Remove scaffolding functions from the netfilter code. Replace with direct access to lsm_export fields so as to be explicit about how the secmarks are being handled. Signed-off-by: Casey Schaufler --- net/netfilter/nf_conntrack_netlink.c | 12 ++++++++++-- net/netfilter/nf_conntrack_standalone.c | 9 +++++++-- net/netfilter/nfnetlink_queue.c | 8 ++++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c index d19092fc6580..65741838985f 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 51dc1e390d84..b47ca79b8e14 100644 --- a/net/netfilter/nf_conntrack_standalone.c +++ b/net/netfilter/nf_conntrack_standalone.c @@ -173,8 +173,13 @@ 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); - ret = security_secid_to_secctx(ct->secmark, &secctx, &len); + /* 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 537effb6e5be..a0670137477b 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c @@ -317,8 +317,12 @@ 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); - security_secid_to_secctx(skb->secmark, secdata, &seclen); + /* 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); } read_unlock_bh(&skb->sk->sk_callback_lock); From patchwork Thu Feb 28 22:18: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: 10833939 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 5493D49E6 for ; Thu, 28 Feb 2019 22:20:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4381B2F434 for ; Thu, 28 Feb 2019 22:20:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41BE42A62A; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A33DF2F3DB for ; Thu, 28 Feb 2019 22:20:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729872AbfB1WUK (ORCPT ); Thu, 28 Feb 2019 17:20:10 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:35295 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729903AbfB1WUG (ORCPT ); Thu, 28 Feb 2019 17:20:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392406; bh=umiA6rgN79wKL8zMFCT2r8i1pODDWRGGU2FW9J8lllI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=UayzkvpyUhfuciipnvfPrKtYkIB7D4axLePMaG3R0eU0B7nE3YfhprNiOlnQ8iV2GQe9K1GnZs+CZML4zFdLDVOVMAPZv4X5jHSQbO/FPN+0cA3NkE3peh8PXEY/U9hK4dITcqIH8ev8G19QChQ8lcFPKn+6tAXj57cV2QLAAW42DIVztAzVLaOzMroSXtvAA7ysZZiKWNrp6NI2VxoHUye/ktn8Q1YPKNxB+Pv+eUpA9ql08uxLVqcC+AsbZRDo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q5 7UUE33a6Od0gXKwznVs3Y.oJKVVR5voV08n7m53Zqt9F2vD3DA2fb9ecA3I5.9BN88.Mf5eY.4rX dp1L2FV2eoXfqWnFfvzSuzAbug.RJK6EcDcXUkXY4xVTf9CwYIvQXHKiTWGaRvqFSM.AGzbiJnid 6hLXMuFfkg2uEjCBH3aXSvaxhPmrdNQXI5JCjQMC_M.66CLYkCvDwS3KM Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:06 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp409.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e8fded081226753664bb344863181a7a; Thu, 28 Feb 2019 22:20:05 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 37/97] Netlabel: Replace secids with lsm_export Date: Thu, 28 Feb 2019 14:18:33 -0800 Message-Id: <20190228221933.2551-38-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert to lsm_export structures instead of u32 secids. Clean out the associated scaffolding. This requires changes to several internal interfaces, but no change in behavior. Change the LOC tag type to pass an lsm_export instead of a single u32. As this tag is only used locally there is no change to externally exposed interfaces. Signed-off-by: Casey Schaufler --- include/net/netlabel.h | 10 ++--- net/ipv4/cipso_ipv4.c | 13 ++++--- net/netlabel/netlabel_kapi.c | 5 +-- net/netlabel/netlabel_unlabeled.c | 65 ++++++++++++------------------- net/netlabel/netlabel_unlabeled.h | 2 +- net/netlabel/netlabel_user.c | 7 +--- net/netlabel/netlabel_user.h | 5 +-- security/selinux/netlabel.c | 2 +- security/selinux/ss/services.c | 9 +++-- security/smack/smack_lsm.c | 5 ++- security/smack/smackfs.c | 12 ++++-- 11 files changed, 63 insertions(+), 72 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 777fa3b7fb13..bd6b47fbc1a4 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 @@ -1480,7 +1483,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; } @@ -1500,7 +1503,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 ea7c67050792..01b8006c7c55 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..934667e8969c 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 = &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 = &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 0266879efef1..eae91a11accc 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,10 +112,8 @@ struct audit_buffer *netlbl_audit_start_common(int type, from_kuid(&init_user_ns, audit_info->loginuid), audit_info->sessionid); - if (audit_info->secid != 0) - lsm_export_to_all(&le, audit_info->secid); - if (audit_info->secid != 0 && - security_secid_to_secctx(&le, + 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); 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 fcd11105fafa..d3e730b2ed3b 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c @@ -3577,8 +3577,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); @@ -3651,7 +3652,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 1ee9c94c0e16..37b0ef6ca767 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -3670,11 +3670,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 Thu Feb 28 22:18: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: 10833947 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 E12B44B5F for ; Thu, 28 Feb 2019 22:20:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8B002F2CB for ; Thu, 28 Feb 2019 22:20:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C68EA2F2DE; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 650462F434 for ; Thu, 28 Feb 2019 22:20:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731315AbfB1WUR (ORCPT ); Thu, 28 Feb 2019 17:20:17 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:44017 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729999AbfB1WUL (ORCPT ); Thu, 28 Feb 2019 17:20:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392410; bh=cklG7OKdERKwHoDLgL4wvFaGiWKJoB9sH4j2U4c+Pwg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=gVh72C719/qOHhBSpF0nJSOOZlFoPp4h9oFPEQdIUmimazERte8byBM9ErWHIsL824ZbrFt81VXxNuOeeFqkt6GeZLOXZoYjXXcJByH0hUKmkZrGl91gv1Co/MmBYi3y7DJQzP+egknqc9+nmOrZdco/wcNDo3zDkkNeNd51NKN67pvLieSdT3fNCXBcDxH9GvDzg8EYC6dl5d4bHSa+jqX9hL5YpNbw4YzGtWEBBrt+AdZwgg8Uti35G23OLYbEljYHIStPpQSgOYVcxNpXCGUQ/IFe/Cv0abWg3eidAyDGDJgr/GOqE6Ucd6gV0z7EHICKaHHF0LinEqwzd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vuyqfMYV4gcQRr_pBYFjYMOnzZHqVFGQ5i.y.KLJWa6uRRKtU2zHge9Nwn0gj3AWEQnIhGw vQX5wRx6WORps_wOqG5oJUjWi_bFmRfoviXE0NZXrFveQFHll Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:10 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp409.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e8fded081226753664bb344863181a7a; Thu, 28 Feb 2019 22:20:06 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 38/97] LSM: Remove lsm_export scaffolding functions Date: Thu, 28 Feb 2019 14:18:34 -0800 Message-Id: <20190228221933.2551-39-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The scaffolding functions lsm_export_secid and lsm_export_to_all are no longer required. Remove them. Signed-off-by: Casey Schaufler --- include/linux/security.h | 43 ---------------------------------------- 1 file changed, 43 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 6659ffa8cacc..b8c67da7409e 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -114,49 +114,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 Thu Feb 28 22:18: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: 10833949 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 BE7DD4BF1 for ; Thu, 28 Feb 2019 22:20:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ADD742F291 for ; Thu, 28 Feb 2019 22:20:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC16A2F3CE; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29CBD2F291 for ; Thu, 28 Feb 2019 22:20:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729903AbfB1WUO (ORCPT ); Thu, 28 Feb 2019 17:20:14 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:35814 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730046AbfB1WUL (ORCPT ); Thu, 28 Feb 2019 17:20:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392410; bh=gXaiM7XH8RUd8pmwKjPkAxsoZLt7mPjTPZXaSl2vT8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=KQ47U1Fccexl+NIp8q0tXuJkSG2NgsSYxzPvyd5B9tR4KmMSOXiimuFKtQlqweXy6T45Ex7xqpMlfl4IJOBscoctKiG01GAoZklyKw3au//vqZeGyfB9a39d2YemjaClgslbaXS71d+4ajqvSIUoa66l3unz9AuKXpCerZTxBVGk8Sz8bqMDtEtVbbz8221XnFhFHW/zTlFuITKuoULGIgCyX0uGE13+GqHHH1eLRIbwRW0BW1gYQGvY9pvQbeKrytSaMitnMe+LSqPScXuJuGrIew3bNeQ9CLesprpX5j0nRMUtxl2wePl/+Og4ZaZ0hOSSMGj1vCNTQLIWTPbbdg== X-YMail-OSG: 3wNmhGgVM1mpZlZo1NDV_.JyeANPNiV.hRCbyff1oUl_HTj6Sn.sHiPGd0oIT7z V3qyfULsL3tsesjY3m_2ZVDfgZk79t8Nios6mYtqscOhhkJVv38CzPhuaEkYkvU5efe5zK7yq0PP 1_BNWvMKJ9bo_O1TYflSQcqhmdpnR9m3T3Bms5yFuclfN.oSdeKpIQjR8Lb6X1.oN_3f0_CElK9b x2TMFBDh07iLjY9yYMbEQlG9RV4zOxyq8N9h20TRZ3405suOBd8UIzM4CVANd44UQUjztWcgFlqj xx0Wmkg4pigQSeGsWsDdLGxyBBtL_aEXFS7PPDEwvnBf6ZrP1aYtccBK3kbdLy8oAiKjSXQT5eGD mDFffaNGb6pURsy897i1hoUTD8RTXjXHB1zz4v4W_mw_pGfZfZT5eaDXsR_rTsh0cdAwElFBUufZ qphToZedHDFfkI8AQcCI.MNJZ.tCs8XGnuAqv7r99c0L4c.tHvxnHdUnoI2eMFVBZY7W.THAJlUK 0OHSvNk2rkyAmu.JqoENN7LTdL5isTYMuLA_0v3HdSpDCMSmCW9dXOLwv8GHQkhv77cXi89pYzho V3SHzvPzZZDECC4qYWvmHJpIRIYXz3Usqe3DT6Q5uXS2VHNhfzfjYZL3ZhgIM_bIktsU8yB.w4HO YPcpinDz1W5UnszfZgQ45zQ7WAcoMOhAmHE8qSczSjHlFC_U_ijVPddyz9I7hvqxYH1yKCZNIcmL hHhaR9PxbluxVXwi7fAI9UDJO9_e5KY6TCp10zUvA5wviXafBHAaYC7WXFok7MbGjM0DrM.qobyE tH.j6A81gX5QEFBzlFwEFh9Orqe2QFC8u2EnnNk.6wE2ScxlOminsJVA8Tu2NvhcTIfcvlQZovjp ozxUQLAGHS5mDVf8756m9Dcs.GV9ha2Pw7s_vcIm_TJHthk0aXwd7HFLLFMuX_41p9sFuC13fjFR l6TKA.ApBZGQCyXDuFmDt7iegBXnZccGlm4F1VNH8R6Tgpf6IBlbl48Ke0XdZ4mhpY7RIDxuqmgE 4p6uBOBIZQaUteQ5w5zqLPjND.fh7zUTYztxa.gJkKky7r2BVkd0GafeB5VMVr3V32VcC8hKhEd_ 2Qbsu_XGLjQbVc1gy6tQhmFU0jWqA9___3Y.pMt43kfqhoBs- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:10 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp409.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e8fded081226753664bb344863181a7a; Thu, 28 Feb 2019 22:20:06 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 39/97] IMA: FIXUP prototype using lsm_export Date: Thu, 28 Feb 2019 14:18:35 -0800 Message-Id: <20190228221933.2551-40-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix the prototype on a function stub Signed-off-by: Casey Schaufler --- security/integrity/ima/ima.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index 2edaf4c41300..c46e856b077b 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -308,8 +308,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, struct audit_context *actx) { return -EINVAL; From patchwork Thu Feb 28 22:18: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: 10833921 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 7AF374B6B for ; Thu, 28 Feb 2019 22:20:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6585D2F3F7 for ; Thu, 28 Feb 2019 22:20:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61BE72F3A8; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E9472F4D5 for ; Thu, 28 Feb 2019 22:20:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729875AbfB1WUN (ORCPT ); Thu, 28 Feb 2019 17:20:13 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:36591 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730004AbfB1WUM (ORCPT ); Thu, 28 Feb 2019 17:20:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392410; bh=9aC2ZQuekvXACUyP08KCqpIfMBnwka+hADHn9g2gxyI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=qAruiHweg0chtcklrAUbyyjsB2M02uLIrxX06Cboba6gfPZqCZHbDfrzS7KTjZ3ii1eV10JbJl/gkvK2InTQRtTm2zxd8thADjxHjHEfSo0Ff0I7JZSbjIr1L28RlxsWfuN29HCJDTpGX1mRR2MwRUUHcf59lRJx2kEJD0A17nQ2hynrOg2x8tKe3SWOawZiLZ5GunDf18ivh/68fe9eY2z4Jr5JTbkLbc2jMze1DTE/HYfsPNh43PfGWJKZe6zo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VvF3WVncvkNlQL9bjGojEHjM7WC2BQEy.1nXJEh16XwcEE9BRjCf8Vefgfr56y4 rnuUaQ0DDz96VTL0f6TL8ycF7TUHXIplint2dBjbYjdPsD1IF2.YUOpXUDFO.FOwncU3_BeplbOr 5Pi.LGBuqt3yk8_I9HvBjPR7oKL2KzLTPIEyWpuyX5T0SWfJb Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:10 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp430.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e588ca5e0935b1286f019b02cb065c6f; Thu, 28 Feb 2019 22:20:08 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 40/97] Smack: Restore the release_secctx hook Date: Thu, 28 Feb 2019 14:18:36 -0800 Message-Id: <20190228221933.2551-41-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The secid_to_secctx() hook has to be balanced with a release_secctx hook for stacking. This hook does nothing. Signed-off-by: Casey Schaufler --- security/smack/smack_lsm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 37b0ef6ca767..2695bd373752 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4385,10 +4385,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) { @@ -4625,6 +4626,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 Thu Feb 28 22:18: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: 10833999 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 D73A71575 for ; Thu, 28 Feb 2019 22:20:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC90F2F34F for ; Thu, 28 Feb 2019 22:20:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CABAB2FC88; Thu, 28 Feb 2019 22:20:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=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 7B7F22F606 for ; Thu, 28 Feb 2019 22:20:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730046AbfB1WUZ (ORCPT ); Thu, 28 Feb 2019 17:20:25 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:42593 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730134AbfB1WUM (ORCPT ); Thu, 28 Feb 2019 17:20:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392411; bh=Jp6S20INV/cmAGY4JKdDGeb42w/4k/VHg81J41LNPYw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=LXxrxrYPKGmqqZK9iC3o0gumnvZFhZKvW6CeepeGEqgpUsIpvfhFO3phofWX3C6WCBK9S8970hDszZKhKyaRoJdPE2s2p3z+GwYTUQ59oW8QfpCP/aLpCCbnZNv84ni+GyZJHCmnrdlmzmulRDcAKfZWzaNWLZqhbJIKDiAKJ01nDeW2abKg4uzJJXap7fvS3+MmyGtfpG4AQP8UdfBulXCRnjAkCVey9Po2R4FWFUrLKCbvKzVUmYzP+Lhu0q5UL7ny0pgD2hZ6D13Vbzk06PX3nLVMKPKRqiqVyD8ZrnpPV1X/AKfF855zbLejZi9g7Z3Lcf7lKnavOBtg02pgrg== X-YMail-OSG: rXd8kR0VM1nD3.EZWopDqJS3LG7xgg5OingQRzb5H4V6mb6MqfFrxgVw5vKJlNb cYmbFtrlESToxCRgogXiitMtHeshnG7KUA6FJIDDjzKaccrqxUhiwuJQG3LAecgu3qcdpCrCaZoN GQ52CfG4PdISl4WL2ChHv_ihpVljSW1oH_Sdp70Ecw9gGqvh4J2bdX2OiWOSnjMLXSkCME8xf3oJ 0dYY7jRoVgeo6rBMFTkSw9g0a8f2ArtUiGYooZLD7SzUWH0Mhrg_TK0yHnO64zhs.Xx__k4IEuwM T.zuZturp6zYD813DfC9eS3xrjMTWAJt2UG62GU5VIY2HjurYRlVhRTJ2cTnJul1xqQwqozx3syO H.XUDb2ZIzg0IJOoNO87a2bjcPpcbT_MijJPy47VCSK4txivYciygnpgq5yJoZs6JbHZOqiULT_c K0tFkx24SMa7lZgqbnnBYdAyEr2qZYB4G8dd7GMRZXadUtHHkYQXybqV4y0gkOILGa06GL5WYewt hF7NDAuidJU5uCxz5badyMsGAvknM3IfUpSiPc3qQGFrMPhGIcEZ.JlF74f3nfGjEsSkFifs2TDK fHbywTV5GRcSu8DrLH3aup0L7QgAT_q7_paN3tftXZXsL5jT3rGJ08naiEJZzH69TZuZlimMebho IuLv_zti5zHtgAxna1l3xAlD3lA_yHZZoOVcZ.caVy.spb5aCWpRRSGx0Xr35px_QFsYRriJCEPc vzWurFtdvjt2coDS9DEfd.ywhObg6c7T5mmRSatWAmTIRGcWedc8Qb97cewt5L91j8__rqz66DqG tDmFoUrKtQSu8utRtP9jgPZAs6wpEMaycRdRxNtK0SipC4x._mXzYwaoP.KKZdyplccOSKFk6hKI juzcdIkEdEzvlJsvNTnpXGC3i.7t3bMMM2oaJRUzfL.BYqpMIul7Ha_OFPpyu3h28n7HSFR7hAxW wsPaqAqMljSO6CnlyqsQ5D_bietD0a6_af_eaO8FC2zxBCRlYLxYaXD.JSnVUSCJQ39s07OIcWgH UKdeaFibZG1Bb7cyBua2ed54QqVg.hF0x8pKGmVvgjKnhZI8a0guaSebNj0deQlJVIiBV.vk.6yP 1HdU0k7D6i7ZYBew9uSHDlfZFZKR0HI_mC0y8yaZvBKYmCk4- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:11 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp430.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e588ca5e0935b1286f019b02cb065c6f; Thu, 28 Feb 2019 22:20:08 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 41/97] AppArmor: Remove unnecessary hook stub Date: Thu, 28 Feb 2019 14:18:37 -0800 Message-Id: <20190228221933.2551-42-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Remove the getpeersec_dgram hook stub. It's unnecessary and disrupts stacking. Signed-off-by: Casey Schaufler --- security/apparmor/lsm.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 0f8e671df5fe..8c854f95d814 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 Thu Feb 28 22:18: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: 10833951 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 1763718EC for ; Thu, 28 Feb 2019 22:20:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08D2A2F291 for ; Thu, 28 Feb 2019 22:20:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 073A82F3CE; Thu, 28 Feb 2019 22:20:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=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 A0CC42F3DB for ; Thu, 28 Feb 2019 22:20:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731338AbfB1WUR (ORCPT ); Thu, 28 Feb 2019 17:20:17 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:32842 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730110AbfB1WUL (ORCPT ); Thu, 28 Feb 2019 17:20:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392411; bh=/7s9kJFAdPQiOafDPACLYw/xGNZ7CEoUzzV9C7ARcK4=; h=From:To:Cc:Subject:Date:In-Reply-To:References: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EocRG4DAFrBn4B5 _mKaSuDfyZWx_us8grfZAYyKH2qzDiL_H.0glyXuUJMcB.yBvea853oMrw_CtXHtDClIaC6Kmrw. ZPp_d4cOMZlCT9YGAyHEEjh98crL2WRfMzTqqs2DS_seTznEqH1BgdJv1jft90qHbjC49CD1UYK4 TraMWLtQJZqwZXHfeSKCy5p7QV3aKExIqscFgqUe2KPff2nevNhZRRRFwcMAA7percm6UOkFhSiH MKhKCPtdecv_G_n_YCa2fXmF5oeXg9W.YcM0SLo0WPeXDezJtUJKe8i1qaIaEeac6cjsXNbExAu2 E9FKByN8szySEIUZnbbxf_YVlT9KNMMWjqRzfdxRgH07900PXrFfR.El.faz8Dry2KQ8Emb_eAGD KQd1NbqVZiaqzkFDuPZYpTf7NMH8soap4q6OGhUsPh3hsH85A Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:11 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp430.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e588ca5e0935b1286f019b02cb065c6f; Thu, 28 Feb 2019 22:20:09 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 42/97] LSM: Limit calls to certain module hooks Date: Thu, 28 Feb 2019 14:18:38 -0800 Message-Id: <20190228221933.2551-43-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP LSM hooks dealing with security context strings should only be called for one security module. Add call macros that invoke a single module hook and us in for those cases. Signed-off-by: Casey Schaufler --- security/security.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/security/security.c b/security/security.c index 2f9411b93f70..c81010db34bf 100644 --- a/security/security.c +++ b/security/security.c @@ -709,6 +709,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 { \ @@ -723,6 +733,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) @@ -1952,7 +1975,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); @@ -1960,13 +1984,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); @@ -2091,7 +2115,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 Thu Feb 28 22:18: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: 10833909 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 72A6E18EC for ; Thu, 28 Feb 2019 22:20:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B4A92F53D for ; Thu, 28 Feb 2019 22:20:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 533012F72B; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0904E2F4E9 for ; Thu, 28 Feb 2019 22:20:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730060AbfB1WUO (ORCPT ); Thu, 28 Feb 2019 17:20:14 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:33577 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729903AbfB1WUL (ORCPT ); Thu, 28 Feb 2019 17:20:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392410; bh=nZAPHZHw/8l7c+D0feT3O0gNki/K3iOuAAczB3TsBvE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=pmTXVN2rQOIFR+gUlErfX2cNfiLSHpxFQiq/APczeeWyrjePt5NhaYPTOs4zgd7VcA/4FTSP9KnPEN8YaDoWsnTxO+9LajuVSZDIruMDvQIHpOjvkK3t7RuYi2N1WdP7qqUhxGE0Lq021vt3FvwkrHSNTBu+iybFUg6lqhsjfwYoEjvtgcy+MdfHxQgxuYLvB2rv9mc7P8s4T30pWT5TexHOxUigZ5xHESjYwN10J2K6VwjPStFT1SqeAHSR2N4H5XA24pTKn4SWlcIotoYXG/JkKW43Jk9JjYwnbwGBnvx0gCZ0Jzt+OnxmOBqBukeWuPu9tTlJaXXVOqWiFkWyxg== X-YMail-OSG: jE6ar7cVM1k.8rM6GPwz4h3JU3QFzeealJNPP9AnW6gFSnAyPiA0lC4BUXnxaO0 YLbG49EYTo0h2yPO6Y_d3E5QnbVLOoZG_LvFnmk2lH89CDc9tJPSHEqEUwveqGby1g81IrZ9vuPu SKmwFhu90xpJUApZt3SE0.a8KR7eQMWgXWvDJZ4DMmXhlMSflpqJtcnYH8fjRZEIX0ad71ktylGD KaghRLl5ti..C7Da8GJ71Jm61gIooK17vj4zcEDc6FU2wXbxBkCaznXGYVAEchu3y57zen0qeaDW KM_q4Wi8Pd_Xkyud__2xgsmphNEUOEu7M6rgkr8Jqx5G0aCJnYITBjeKzF1lVkAex6usacrafmfJ lFJFf3YdQcyOVMkEPXMd_FnOC4swwm1UjvNtgCfWXCn46oSnemfMFy3ATrz4q2xYVAzYPY32cLdP yyYvxNycygSGqEtjserQya.9VrO1E3qRYyMdb57xsgu1fipi1ENnr59oOlHkK7cWx_7xyXFhhRs. 7Ekn8cDr6_1TQc_c1rCOqtDBWdwupIFFxNpzmfZ8tRjy1WjHfb196Y5_xU3rkho0BczonRSBZQX5 bivUDDuKs9L_bZjXVxPj8D0tyhWh7TSf0HKGJag5iwOziTT8JitlBCIheZlUwsUV1sRGC9b_mO1M wRMIAQVrQup_SwEz8GFEZdAxltwXhxKZhMm.yvIoMLV1LA6iYz3SlcugErTTuOSbixrsEgdd.dBG FvmfTwr_lIui6aIW8N_3810L3ImfVfFOSHg1DBkK9H47ti2fIufabPYj1Pg5JYu9Vr4iJIdAQt59 tNybYwJWjDtjjDcjWSPeU4WBhsuosk0OAb6rTySFN6O_zhCJkHRKR8jaYmJIdAIJ9pXCgH7SYH_r HlzgKKVwbg9h9Eo8rx8EcOM4o1PO4sTUSIbMfuOvk8jq42eu4xuYORkREaqWaqSD72ISoe0EdkQo LenKPYQ47iS4GrUeo5HnwDp5a3QbyKNTjQrfilBxIv3GCJm3B1vZuhh5H_3blCBKYrQn7uP0gUp4 RvrW8MxZXUhlvumYr4xhUj_BPnmGZbiR9ni4qhaXdJ3XrF_kpIkPu2DDoWsmwUNrJiY1RLPJje1R pPUwFyDk_0q08BNifBa6Qo0QErx8cGjQr6CxKz8BOy8XS6Scv Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:10 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp430.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e588ca5e0935b1286f019b02cb065c6f; Thu, 28 Feb 2019 22:20:10 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 43/97] LSM: Create a data structure for a security context Date: Thu, 28 Feb 2019 14:18:39 -0800 Message-Id: <20190228221933.2551-44-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A "security context" is the text representation of the information used by LSMs. This provides a structure so that the use can be made consistant. Signed-off-by: Casey Schaufler --- include/linux/security.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/security.h b/include/linux/security.h index b8c67da7409e..b60152334d9f 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -116,6 +116,17 @@ static inline bool lsm_export_equal(struct lsm_export *l, struct lsm_export *m) 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 Thu Feb 28 22:18: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: 10833907 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 569B04B5F for ; Thu, 28 Feb 2019 22:20:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 445982F3A8 for ; Thu, 28 Feb 2019 22:20:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3045C2A62A; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C1C22F564 for ; Thu, 28 Feb 2019 22:20:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729920AbfB1WUO (ORCPT ); Thu, 28 Feb 2019 17:20:14 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:42349 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730126AbfB1WUM (ORCPT ); Thu, 28 Feb 2019 17:20:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392411; bh=jPKwi0Xu4DayYN/NA2jFvINUoFK9sSYkBTVu8ePKagU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=arY0dk9e2RzdapoV2uQhGcvlEN2h9TH0B9/S2iBBIommPNWh/JbTjFj58OjsZUGzH+XZYMhUsb0bcZ7Rj5/BlEv6B37R1sSHHwEg4v2VhpzxDoiGCGIgZ0gPoi/wz+0zfjNSL9CcaAag7ywysxPZMbpRtznCACIddBG+3m131JB9zp015oc1Tdndg4g2ZcjkS8F9dbDIYD+qgePmd1I/VJtLvXszLXjMw20ImlgiDxlLnO7a4NgALB+8iEcvSPY3C4QAxyBv3Lli+MWZ24xhRr3opWjgIPlqV2Al88f9YkX0roMLyghxpQspS85bqn8pXBbfYV0DgpoufIqrVekp3A== X-YMail-OSG: Zp7qou4VM1klA2D62xK6a9J_Ks5CEoKMv._rWCPTG0qW0MVIF_JBR7uEm63_hki 8uMtd1SoX5P1FN0rJo4vgcUQ26M1ttWTcaV5viSQKaWkXlHbeUDfJygn0HTcMgC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ic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:11 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp430.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e588ca5e0935b1286f019b02cb065c6f; Thu, 28 Feb 2019 22:20:10 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 44/97] LSM: Use lsm_context in secid_to_secctx hooks Date: Thu, 28 Feb 2019 14:18:40 -0800 Message-Id: <20190228221933.2551-45-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert SELinux, Smack and AppArmor to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 6 ++---- security/apparmor/include/secid.h | 2 +- security/apparmor/secid.c | 11 +++++------ security/security.c | 12 ++++++++++-- security/selinux/hooks.c | 5 ++--- security/smack/smack_lsm.c | 8 +++----- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index cbfc2a9b5f27..97b258488e4d 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1307,9 +1307,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. @@ -1654,8 +1653,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 c81010db34bf..9b25f0113b4f 100644 --- a/security/security.c +++ b/security/security.c @@ -1975,8 +1975,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 9879dd828e1c..4d679697cdad 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6194,14 +6194,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 2695bd373752..015a2342aad5 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4349,8 +4349,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; @@ -4358,9 +4357,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 Thu Feb 28 22:18: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: 10833993 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 262071575 for ; Thu, 28 Feb 2019 22:20:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B4712A62A for ; Thu, 28 Feb 2019 22:20:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F7662F46F; Thu, 28 Feb 2019 22:20:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=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 9987F2F3DE for ; Thu, 28 Feb 2019 22:20:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731428AbfB1WUY (ORCPT ); Thu, 28 Feb 2019 17:20:24 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:37780 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730126AbfB1WUR (ORCPT ); Thu, 28 Feb 2019 17:20:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392416; bh=Ib2k94uXrs+IQbG/SjQ0KV92IRokbm9buCzGxBhJCLE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=gERfJ57nwg51g43G0BWJkyqzFzvurmA0jhRrW7MfECou0z7ffor71qvXn5Mta8UWXiW1F2PIbQzuHZqRgLrJUn/TKxuktmW8imzvx3CcglTJmQoQ93RkPcO5ruGrjNxhNOgDJJzQPaoJWgN1kjvrRqT3TY3khtmmD9+CHVXZ2fhMwQKZxsoCHDzo38lWfeXiAOmEW3qH7mdvNmKYrZASbhwfCbD9+kiIAOjJGV4lBrDBC9Oxj+l3ibEP7CXOLDtwqgD7l0b44jrNnV9UAAbMJr63n2tl1g1vVx3z8bGpuFdWHeVjpU2KqLOgQrxJM9pEFnJwYXvZNgszkN6/Q/VGLA== X-YMail-OSG: Zh90ZbYVM1kRgqGgNsl1PsglPulEXG2sP4kjnzLSNpmZwlSbOt7OLpsnn2r.VBQ htjZvrBTAKqvPkkcC1Xb0njJA0ioE5C82Oaa27rjdLOeXbyX0TYRb3XxkMnCXfsQToODPsVuMHo3 aIu7EakBWcnhatZdOoyeDW2VccvGfkWBjnutpueDSC.gpBTT0HD1se7extXa8gE7KeR87G7Qm4lx Eqnp3NzNnGM46jmogQTRvqcImjAeotvB2NDHR3OCjA8YkJeUJgx2NWv_qXtTCmHnovyRS37J7SjZ 29wOPw23wftNwBi814W60VVeR8poo0VyvjA1.hx5fcoWs5gF3aXcoL6p1UFvWpIbgUQyRj3UNvQz le7ABmgVoXCWQ24liWsVtwLft89eQDwRWoxZ.1X7meGzBThjffYuthqLKmXH5glZ7ueBknK6C.gu Yh44kRnyCd0pDLDw79ZXgsql_uB4uSN.5gUXr1QLcwvWsA1wJG3gbxL7oXM5uSBAdpB4yc.bITzw eA6Z98T6BgH_9yTfcBGbC9NEgQTVh4kryp_hwHQAsrttoB2lEBJyUdc0Au.RMYq66sXJffRRWBkK tpPB0zqtmPmCgWWc.dCoDGP8ZdBVfPHm4gfCeLbS3ViiKGq1HcJjzDznmiFVuEBuYxHlP9VWDrcL IDmGl4ikVyoHIfDk79crUCYDwwv9rcFjWdjgkBJfzYN.L4Y7XqIafzccR3W13wgxmjhckF0PXG3s iNL3uUgMJy7fglZ.jiE_sYZAOIKsfNoLrd8cjmGuub5DgVq7iqueWNj98Au8OpaboiHuGPqkT6Yd NIHh9N8NyMWV4nffVMLiz_KkIinOjpLGO7_Fw1cc7orIDH.t3lYbeBLTvVJoQYrr1KoOpn4kG3V_ OT0y190vjYsxiLKqGme5p7y2UdaznVRdyzlZNLn_AXj4tali1OjtfcdWoQzIP6Ya9WoP_1rk4_d3 QyZJaH.spRfRhOtrwLGYm4twJ0wl6JSa1LAn1pzWwwNt24DrUsPj4satIJIpvhJ6mIvsDPrxllXe 8yQ7UYoeY3lAj4vxdqrVMSflNDfJ1IFg5WdJUjXcqECE56l4fh7XJSsodAASyuopABY_XIy4maHn vzoOQ_Tih_OcOpvBUT3zK4HRAjauPw3BLcHfa5pnvfG4cfE4- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:16 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp430.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e588ca5e0935b1286f019b02cb065c6f; Thu, 28 Feb 2019 22:20:11 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 45/97] LSM: Use lsm_context in secctx_to_secid hooks Date: Thu, 28 Feb 2019 14:18:41 -0800 Message-Id: <20190228221933.2551-46-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert SELinux, Smack and AppArmor to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 4 ++-- security/apparmor/include/secid.h | 2 +- security/apparmor/secid.c | 7 +++---- security/security.c | 6 +++++- security/selinux/hooks.c | 4 ++-- security/smack/smack_lsm.c | 4 ++-- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 97b258488e4d..bb748b0a045b 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1311,8 +1311,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. @@ -1654,7 +1654,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 9b25f0113b4f..fa94f012a7ab 100644 --- a/security/security.c +++ b/security/security.c @@ -1991,8 +1991,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 4d679697cdad..00b47c01960b 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6203,13 +6203,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 015a2342aad5..a5108215ed49 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4370,10 +4370,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 Thu Feb 28 22:18: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: 10833973 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 0F0A81908 for ; Thu, 28 Feb 2019 22:20:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0049A2F2CB for ; Thu, 28 Feb 2019 22:20:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F2D532F2DE; Thu, 28 Feb 2019 22:20:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80F682F34F for ; Thu, 28 Feb 2019 22:20:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730698AbfB1WUU (ORCPT ); Thu, 28 Feb 2019 17:20:20 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:43238 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730892AbfB1WUR (ORCPT ); Thu, 28 Feb 2019 17:20:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392416; bh=+ZC0413d4ELtG59P/A2XiAmWA5XGQXEoI8H0mOHofco=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=Ar1orKcz+MhWk0rQC03esnY7yzxZ9phGzAFjqmsw9eaEDlnUU+07HG1xagPms4DV/mY2MkOsyx2wTcJ7RnVNjCchBhPlH9IiHjjD6gPk0bd/KQnPASomuiHgoJl/pnd/N/FC7nDTIzbTY4yZl89suyMLuPq3ctwz/NPpIyTGq+m0U+9xZk8yhm5d+tEmqjYzdzPn8I39HhjA96oJd59E5CAVPDofTUEiR02W/9dNCU46G2BgRJ1wOQmxY8XIPoFdtMmKu3+eifQD1chB2/wxRRRqDSstlUQ/rGIxNC19iU9YwvBvEDnBmDyVP2NkNz4mtt+suLjFDW6/xrKI6AWANA== X-YMail-OSG: 4aL33zMVM1npadfWcZrzBWDc59NRQwuOlMO3ujCCiQlpkPJNQ41dwbwO96s4a_X uPv8S7Wn1odvBK0jbYECs8_rkrdFnffW7dZeswHRMHDZeZn7q45etMj5o5gp5TQUjLfH8xLEpzTn 7BVH0phxcmHfqz3kwi8M5Ssu0xKBAb9dKnltRLEkE3zbAQcQp6td6oiTzapa.9BXbascBWP48fff J7fOr8BuOPoVMWYXnncx9EccXjIhWY5d0aMzuCZ4plBpFRQlH1UDKyUKGnhWmJNGgjE6_NiEaJCl HWiQvRA5UygX3eR9IHxUbrxoQVoAIWIy8U7NTj1_7fBvoiWcBlW5M1_fN1YWrONUfs9xG.W8Nood OH.ek3.qBId4XRqwCrEoDKpAaWpAoHEHvxTgdV3h7sAr8nUIUC3ECp8CBsaHmPj89z.Rq3IudHE7 3ovuvd.4tTkvjkEmJMKjbrmGHo.lDinqo6wNoulBHtvN81xTqLoQ6avZy0vZLRnndGo74XbtZjZ7 GpJWqjP_ZqdYQEzpiTTJ58zgoIRd6tOcLmgZwZfhjo5Yv1RbZnrjCDLPRuiGcEsZvJTBz51nofxo MEhMuBley80Wg.BP_ijlGd1zStoY510mLlyMlBmIkHK8m3lkUBRazIo8VUTfcIcvgrI8RgL.bojq gi9MHAt.FHA60o0RaMboNBIPUb12dMyEU4w8DzX6cIjeAkTJrbbuzNMG.exv_vxYbm7GuVYF9SMJ a34emVXr6.3RKGBvk2CaoIFDOjrqoriQVJOQB2DLhYrIuHySd7KOrfnJ.1kZ6ql9VoKUqOc9Clz2 eotKMriJnOsEwPKBMLU4ykZLRDNXZg1qQqWZM.Ftu6dq1MfH9sQClfJu0JCHE.a1stfbWOnpqomQ MdRu58e0E9U2ul27HYaADX5UPb7__Y3yW6nEia29MHplUdUSbzKBDGEQoy4quo9F5161W5Zy2xvP mxqVd9cgP47jMxTCaIMjYlCJ.vgl1dIkYU__V.yhkAvfGkhrjuX2D_eUwf8I.iECJ5bDK.0HR_5H xMfGh0fmIEmfUVL5reFc5Z5BOC3htiJDoLj6EIu0GxWwZLX7DwzeUwN6Grnhch43w1hZ6THFFOVN HfAVZ2iyh9eyT2sw47hFQ1UJDHLTs1iGKVv9GmwS6XeofWi22 Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:16 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp430.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e588ca5e0935b1286f019b02cb065c6f; Thu, 28 Feb 2019 22:20:11 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 46/97] LSM: Use lsm_context in inode_getsecctx hooks Date: Thu, 28 Feb 2019 14:18:42 -0800 Message-Id: <20190228221933.2551-47-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert SELinux and Smack to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 7 +++---- security/security.c | 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 bb748b0a045b..713378bdd69a 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1386,12 +1386,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. @@ -1661,7 +1660,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 fa94f012a7ab..b2aa50a583c7 100644 --- a/security/security.c +++ b/security/security.c @@ -2026,7 +2026,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 00b47c01960b..a67b8a3e6b9c 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6245,14 +6245,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 a5108215ed49..b3d4410696a6 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4399,12 +4399,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 Thu Feb 28 22:18: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: 10833961 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 6B04F17EF for ; Thu, 28 Feb 2019 22:20:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CCB22F2CB for ; Thu, 28 Feb 2019 22:20:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50F882F2DE; Thu, 28 Feb 2019 22:20:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF34E2F34F for ; Thu, 28 Feb 2019 22:20:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731126AbfB1WUS (ORCPT ); Thu, 28 Feb 2019 17:20:18 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:43549 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730698AbfB1WUR (ORCPT ); Thu, 28 Feb 2019 17:20:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392416; bh=T4Rd37OVukqoSjsrnRppCQbrWAJC3f47UE1BP1dcfAI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=Fyqao/xdUhPOhnfOSes3Ljjoged0Oe4dW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BtgOgrqqoq3usq B40lSoYml8N0.zeDdNkoJPYPCWGMeVeaSPYZX9nDAdhe8N9LxV4yVyjF0ClecBCq9UXcCY5W6zNp WsEBcRj3LgZ9Shvtzkys90wZeCM4GH7UBb1em29l7HYeKSLdHLdS78L3__ExBUrg2pqwdQGOxNYG q3s1Oq_TqMOvfrIQOITTkSkRm9zqEN2PG44ohC4WhocIJw8ou23cMoFwdDxb.CUA5ZXLSa9mqAU_ .pXVSEIJvBG2PQ_A9Ui0rz4Q2lXBcp7uyTbXCsbro5OI4kNmJzpscq9G850loeTaZMg4_OFSVATy cRczxgdxuw2byc39srN2aTVrTCW8caQyQHneqM9iLbvfrhQVjG3SoJmEKFTDBed02aYI5_mv7L4x s55YFxIbGs.JHHifTcDvg5JPX7gKSuoCUgvcwS6.UHffID7Y- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:16 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp430.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e588ca5e0935b1286f019b02cb065c6f; Thu, 28 Feb 2019 22:20:12 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 47/97] LSM: Use lsm_context in inode_notifysecctx hooks Date: Thu, 28 Feb 2019 14:18:43 -0800 Message-Id: <20190228221933.2551-48-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert SELinux and Smack to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 5 ++--- security/security.c | 6 +++++- security/selinux/hooks.c | 6 ++++-- security/smack/smack_lsm.c | 5 +++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 713378bdd69a..a7a68be7e507 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1367,8 +1367,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 @@ -1658,7 +1657,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 b2aa50a583c7..a0c4ae7da840 100644 --- a/security/security.c +++ b/security/security.c @@ -2014,7 +2014,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 a67b8a3e6b9c..33e58efe59ce 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6232,9 +6232,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) { - return selinux_inode_setsecurity(inode, XATTR_SELINUX_SUFFIX, ctx, ctxlen, 0); + return selinux_inode_setsecurity(inode, XATTR_SELINUX_SUFFIX, + cp->context, cp->len, 0); } /* diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index b3d4410696a6..26cf42ddba0e 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4389,9 +4389,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 Thu Feb 28 22:18: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: 10833995 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 AA16C18B7 for ; Thu, 28 Feb 2019 22:20:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E7762F587 for ; Thu, 28 Feb 2019 22:20:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9AEB82F53D; Thu, 28 Feb 2019 22:20:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=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 3F6352F3DE for ; Thu, 28 Feb 2019 22:20:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730126AbfB1WUY (ORCPT ); Thu, 28 Feb 2019 17:20:24 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:41300 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730046AbfB1WUR (ORCPT ); Thu, 28 Feb 2019 17:20:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392415; bh=rVz/jD/0lGdOCPoY1Eyzu/ubGMwNwJfIW2d1l8+RcpQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=KjoWFm1NsSFT8tKxPqJo/WOt7zwT5kmqTS1MSz4GQQD1luiGJpTe444VkrVjrx7/F6H8VtkAb+WUpC8838QjpipZSthuSQToaIf+6+oQXtH8w5V56yzlAtsHbkRoWF1V3Cgf9AOtveD6381EzmMZnAznBabOnquaUGlWR25ix4pk555vLbyb/IRO+jaaI4O5+t+szN9OrPfDmt0U59iNB3ABCLV7Ckm1j1+rBG9f/zsTxLQtxrs1Def+OVTGIdN0Wi0V33OV5eI1H8tPqCs2WRsl4B1Cznwp9zd6uH+uNrjctPllPfJ0dlex9hYal7szoztZpImUiun+uvPGcrKNcQ== X-YMail-OSG: CFg3pgsVM1lOrGh2l1rorJqHZFZm32HAnszLaf92rYoQoi4MwuTBVkKE4NFnBvT KHD7NAEZa8Q58NA_4zx6ks8CVJ248N0tSIaUaQBrD7Mb6ITCGu3Y8xc6cv9jK55tMAUF24aZaV.N 9y8jbHQhcxtDhmacftfU5QJFG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 28 Feb 2019 22:20:15 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp430.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e588ca5e0935b1286f019b02cb065c6f; Thu, 28 Feb 2019 22:20:12 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 48/97] LSM: Use lsm_context in dentry_init_security hooks Date: Thu, 28 Feb 2019 14:18:44 -0800 Message-Id: <20190228221933.2551-49-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Casey Schaufler Convert SELinux to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 7 +++---- security/security.c | 10 ++++++++-- security/selinux/hooks.c | 8 ++++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index a7a68be7e507..29e52aedd6ac 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -150,8 +150,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 @@ -1482,8 +1481,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 a0c4ae7da840..bacfb690392e 100644 --- a/security/security.c +++ b/security/security.c @@ -1018,8 +1018,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 33e58efe59ce..8b8eb5115d6d 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -2715,8 +2715,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; @@ -2728,8 +2728,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 Thu Feb 28 22:18: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: 10833971 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 D594A18B7 for ; Thu, 28 Feb 2019 22:20:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C76482F2CB for ; Thu, 28 Feb 2019 22:20:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB1632F2DD; Thu, 28 Feb 2019 22:20:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F6C62F2A4 for ; Thu, 28 Feb 2019 22:20:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730730AbfB1WUU (ORCPT ); Thu, 28 Feb 2019 17:20:20 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:46844 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730732AbfB1WUR (ORCPT ); Thu, 28 Feb 2019 17:20:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392416; bh=XVFOpLqVAefZlOLGmccNrc4yiTQy07t3uJyxjT5+V8g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=AfiPWjvJcwoMo+tKY8zO+4h4lDXJESBuP5Hp5oZ+TQ5OW9jhLoO4Qbu3Dbx8JqKJS1+Ne5u8H+Zhnb5RtPFuXUrrZOvSqsG/LpmIz5NCUBa8l+QPjXZAXbB0PV8qhZV+EC019GYk0mDBH5O6N1y6Cga7w3zRthkLA5BNbcGcShyCMPJHbP3xv7dR4777aVgNpDNQ87bN2ebM8m/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r3AuGPmIUFtdi.ZQKMaYRpD5Ex6DJUgAQ2Ilz1Jdgnt ITPmEfdPiZGhRSqqlE9GSY.m2QmsGZFuKvF9nvvNt.MF7ctlBJBf84dj4ORblA9mDOELXrpfywHO 7cGAA6NDbjEbw7vENXnIOfEaozW_T4lF03mR_6ScNVwhqai.u9a.SNa6RgTNPhGClqvwYFhGzjmD 2xPpHDixekk_9VmsZBxM739Lvtyuf0734rgS4XtI9bql_rcU- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:16 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp430.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID e588ca5e0935b1286f019b02cb065c6f; Thu, 28 Feb 2019 22:20:13 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 49/97] LSM: Use lsm_context in security_dentry_init_security Date: Thu, 28 Feb 2019 14:18:45 -0800 Message-Id: <20190228221933.2551-50-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Casey Schaufler Convert security_dentry_init_security to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- fs/nfs/nfs4proc.c | 5 ++++- include/linux/security.h | 7 +++---- security/security.c | 14 ++++---------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 557a5d636183..f56963c995b0 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 b60152334d9f..7940a92e8b5c 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -299,8 +299,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, @@ -660,8 +660,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 bacfb690392e..a821e0558370 100644 --- a/security/security.c +++ b/security/security.c @@ -1015,17 +1015,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 Thu Feb 28 22:18: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: 10833969 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 842B318EC for ; Thu, 28 Feb 2019 22:20:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7730E2F2CB for ; Thu, 28 Feb 2019 22:20:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B0972F2DE; Thu, 28 Feb 2019 22:20:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F21BD2F2CB for ; Thu, 28 Feb 2019 22:20:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730066AbfB1WUR (ORCPT ); Thu, 28 Feb 2019 17:20:17 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:46101 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730215AbfB1WUQ (ORCPT ); Thu, 28 Feb 2019 17:20:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392416; bh=+EktEinDsp7sVGtCHwNA5KY/taBeP90CMVznou1rZ5M=; h=From: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LLiegn7T40SqJs1D1oC9BavOsSnl2pt6KIecMGGHdvE66c4 IlsjYCAo7ykvNARPwjsx9WG_hg4G_7xa7iFcl2SalaRITcl0xICWepPT2E.2G80O_sJv7IYM1n3w CkuVFAyQblylKrS1YQdpxvKn6G785SvBjqpBqtKLFe5H1Dzm9TFym7UuVWHA4SggO4nTJs8KKulM n1Egxu195Y7ziNhR4lWtEfg6tFWt6jpyBBjGReNE7XLlCtt_Ay2MTHkMYZdCmXkcIeXGeh0Rn2Lj esq5VMhE3.et3XjDqkGKVDbdQo.DOvhMDB87taB7VpwfWQJhNk0ci95ePMKRfXjHKSMTFX.xfTBp zMEGtoEWbPEHX2sLTW7b.5pbRT6RlcFwFzsNPnG_v2M.gynkt1aI2heKwKP.YxKfmWkvp1Gp63hT TErI5N6n8bItnz80N0MGnojGQonBS4bB.8kCPumi6GTpq0Zo- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:16 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp423.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 51882fbcdd41d0138ebd23ca73a62b12; Thu, 28 Feb 2019 22:20:15 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 50/97] LSM: Use lsm_context in security_inode_notifysecctx Date: Thu, 28 Feb 2019 14:18:46 -0800 Message-Id: <20190228221933.2551-51-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_inode_notifysecctx to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- fs/kernfs/inode.c | 6 ++++-- fs/nfs/inode.c | 6 ++++-- include/linux/security.h | 5 +++-- security/security.c | 8 ++------ 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c index 80cebcd94c90..7c5b0d5140c4 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 094775ea0781..f6c339d4e6fb 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -339,14 +339,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 7940a92e8b5c..4194f6b8b97f 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -434,7 +434,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 */ @@ -1218,7 +1218,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 a821e0558370..464dee357986 100644 --- a/security/security.c +++ b/security/security.c @@ -2012,13 +2012,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 Thu Feb 28 22:18:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10833959 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 3AD1018B7 for ; Thu, 28 Feb 2019 22:20:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 285F52F3CE for ; Thu, 28 Feb 2019 22:20:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C97F2F3A8; Thu, 28 Feb 2019 22:20:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2DD52F291 for ; Thu, 28 Feb 2019 22:20:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730215AbfB1WUR (ORCPT ); Thu, 28 Feb 2019 17:20:17 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:41876 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731103AbfB1WUR (ORCPT ); Thu, 28 Feb 2019 17:20:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392416; bh=BTDyZ53PLC2ypuQCEfAYhH3SfAb0aSVsiutkzqz2gyY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=FpxZhZEfVhzRp+2ZjLw0vr+/st206ymqbLIhsAfN2crC2OdNNQgN9eqrX5KnsindLFVHlkvczsg0/smIM9yUMFcq2a6JX/yAkAPSligNB/6vKYeVjevMcFS81lJ/6NyD6AXovU9E65jm+nZcBS2QO6VG3m8TrbOQVTyPlnu8X3V76GkN+Tz1qAqXiqaIe5Ua7DXdDQxm35T/nqm/q4p0Rx2VxcT9yviEffoI31qZ9P/L5kdzSmk4HhKSm+krlPNwZjNhDiL3obCjJC11rVPyFwnx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OY.nwXoMCr8ynpQwiyFTq74t._.1z4TpCGiGlXkhSTgva2_s8BZOcaVS KAuxqb71rnFEFb7HryPOCRGt2yn5zn0VriMZe6u7U8DVn7i53KeMZfJ3mcODh6qlIx1JeJiooIfC WxjLSzLdn2zvqU0REqJ.A8xJRVcgZfaoUbeL9NcbX66eTDZY- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:16 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp423.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 51882fbcdd41d0138ebd23ca73a62b12; Thu, 28 Feb 2019 22:20:15 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 51/97] LSM: Use lsm_context in security_inode_getsecctx Date: Thu, 28 Feb 2019 14:18:47 -0800 Message-Id: <20190228221933.2551-52-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Casey Schaufler Convert security_inode_getsecctx to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- fs/kernfs/inode.c | 11 +++++------ fs/nfsd/nfs4xdr.c | 14 ++++++-------- include/linux/security.h | 5 +++-- security/security.c | 11 ++--------- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c index 7c5b0d5140c4..1da14b56888e 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 4194f6b8b97f..2d948f1104cb 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -436,7 +436,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) @@ -1227,7 +1227,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 464dee357986..fd1ce1116969 100644 --- a/security/security.c +++ b/security/security.c @@ -2024,16 +2024,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 Thu Feb 28 22:18: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: 10833963 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 1DE441575 for ; Thu, 28 Feb 2019 22:20:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1011B2F34F for ; Thu, 28 Feb 2019 22:20:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 049392F3CE; Thu, 28 Feb 2019 22:20:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B16C2F359 for ; Thu, 28 Feb 2019 22:20:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729820AbfB1WUS (ORCPT ); Thu, 28 Feb 2019 17:20:18 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:34399 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730845AbfB1WUR (ORCPT ); Thu, 28 Feb 2019 17:20:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392416; bh=xFoB7UEDemun7LHgUdKvmFQJzUPr56+9v/fv1ouPu8c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=mzv9etOiUsrbZrWu4al8RMIQSll4TpeLZ8EBItqThnYXNISY2fShUd3Fn1IWSNmdRUyKaNLYUcDuMi8ZPPRoUogIlgXsC1TZX3IBO7Ta7idmY7+nqaU1Zz0QNNceAvYnC7sngDaEvHUHpYK8TZdpIvoTSI7mpjYDIfBbp12EZY9Zpb5i+rCjBJJhVF1PKY4EOBHuoi8eUIaR/gpdSgDZLg8L1S9mdAbCUHJorTic4iCBJ7zfW2WjORmhWMWfTFObtG3+W0Wu7vktV4WInc3n5XHoSmRWdgaBlpGRblj0YEEzXnONzNwxXJMmupFU/ejtK7HHiM7PRszG3+5QTYp5Fg== X-YMail-OSG: qE23XL4VM1kj3JngZ_avCor430cG0LqL2qNiac2tDrwZPFDm7BeyQdcfRK2Ow25 oc_eNcb45PNPXHZ6WG6SYdcJ8JQIDKF2RrzSIwkow6RD6OEVJ7zdh6bNifhvWqgce4FArGlM96jN OQNKuPkOytTOv9BTkshDrCDpV0GS_nkRv1AxPKlNmCM7KUmAFzkrR0CDvyaXcc2jJfvlCcKpfGIx ZH5.3Kah6bcDcWvughJhaZLA7SN0cNm8o7lwDm4iMwBI5Z3uYL4.7lIewM9xfBRkX4oZ6lMTTry4 zBrCeteLcUho9b15zOr5KlWIz0zm7PguaroKesqgbw6zMTqOCzYb9nJA33MKTz65DQjyTH0Y9Jlj HSfBfigZHADWU4O_ZCz_Z2x834nT0bpA8fezaJ9K1ajntCw.nRVsR05JGU_H8oir3gjjOyKHUp2I ECvI4TGvWw3nKjTzhv_9eZFofgysUDMQHECRPl8nye9hudR9k5eiN4PF0yqOkX5yKw_YTML37V9e 6Fs.zpJQgE1ih4a5Ie9ABbRlXNtXSscuQXzuAS64Z.6.xswtfdPQNOlMXMVf4LGoW3lCDfj0DA9z KtiChnlKlQPi4xM2iOnWB9wd6w_tDYA78J9MEdIkcRnrCSfIKZBM1h2mYvL3vOc3gOiOet9xOLgj dRChCg64JsJgUIjATdAbhJs_ZeS1N9O3YCl0aBVpIV7LMuNv6ZlTtQaGy75Wh6dh.5g5m6cGnxZM AJM0_wWVmFDwP40zQzgZUfzstEWeSX6PAIKZiTwKUOBdg9HWXzA_6KQGQtwW4wBql32o9jrTd3JR 6BrkUYIzW74xzttC7QoA7Q0Jd7EOtaWBJRYmfrDHRqYeY0MMdjrx8aEA5zpxnGecC.TKf7A7dSCL rrSsdwvtZV7sfyFsTiWRKadB7GK5gwxTXwsNWUZYvhL3_dHJ6l9rBF2LrGFu.xphBrqjkh3BBuMX Vmgi4G_IsTQi9TJNS0WsdHr1QKO3zQPzf1qKBykroFDgf5gY8mznd8K5wIywIH6lZPS6CI1Aj_3f yHvs2p3XgepPk_USARlEpWYtj0QoxNVbn7htnm1iWiJroEkjS.CgwO3j_mCQN3T8CMoZReFMNXNc VuyZPn7C4TB7sTbCPfF7mzaq40QGvfl_c2V4Y8tCSCWsQ6UHl Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:16 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp423.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 51882fbcdd41d0138ebd23ca73a62b12; Thu, 28 Feb 2019 22:20:15 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 52/97] LSM: Use lsm_context in security_secctx_to_secid Date: Thu, 28 Feb 2019 14:18:48 -0800 Message-Id: <20190228221933.2551-53-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_secctx_to_secid to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/security.h | 6 ++---- kernel/cred.c | 5 ++++- net/netfilter/nft_meta.c | 5 ++++- net/netfilter/xt_SECMARK.c | 5 ++++- net/netlabel/netlabel_unlabeled.c | 16 ++++++++-------- security/security.c | 8 ++------ 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 2d948f1104cb..23b776bc16bf 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -429,8 +429,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); @@ -1203,8 +1202,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 9f5040140fe0..ad1aa430f733 100644 --- a/net/netfilter/nft_meta.c +++ b/net/netfilter/nft_meta.c @@ -565,11 +565,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 934667e8969c..314528bca31c 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 fd1ce1116969..dadb1cb72920 100644 --- a/security/security.c +++ b/security/security.c @@ -1988,15 +1988,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 Thu Feb 28 22:18: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: 10834051 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 C3C8118B7 for ; Thu, 28 Feb 2019 22:20:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B68CF2F2A4 for ; Thu, 28 Feb 2019 22:20:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B4DE32F53D; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F3772F3FF for ; Thu, 28 Feb 2019 22:20:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731525AbfB1WUg (ORCPT ); Thu, 28 Feb 2019 17:20:36 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:37681 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731609AbfB1WUW (ORCPT ); Thu, 28 Feb 2019 17:20:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392421; bh=TKbttd+wVwKI8Sg8S2yZETLloJ+fHFodAjCzqzLtkW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=jmGhbX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7QWGDGGAkn72cT9NoASuN0w3r8kzPTQ r_KpgZTr2R3IlGF95ifzC_W2bolnysxR_Sl.3iNdzUZfrKv9n0sErtW.fIz4CLCE1KFlErinwvY. QJi4p7iWs1SRIFnZh8OsvHoK59Ds_wlNsm4RBEgm5D9fMBZUSf2QiFl7XeuRTj8EA5j1z1hUavfB FWhEZhDjQdwgHntaeIMoV_cdbf5bP0saU6Qz1K6wyHHFdSo2EZtG3P2yVdQd2Ay_G0JXKSXD3iAp DQAGOrE0zdizvGU.BLFKkvwYPSJgNyXSAWLjOW8lt6wRSxfXg7YC7U0bLSSbKTl.b6mErW.OXe9R zVWcJdzmB1dgCKsI0A7ut6laqDLpYVulM_fwVezblj.TWjhJkgDrehFenPLwgbMqo78lW.XDUkON QzfZkVywFZmjnkgyrw28x6QGSje7YwRFayampRuasrzxZHx4- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:21 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp423.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 51882fbcdd41d0138ebd23ca73a62b12; Thu, 28 Feb 2019 22:20:16 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 53/97] LSM: Use lsm_context in release_secctx hooks Date: Thu, 28 Feb 2019 14:18:49 -0800 Message-Id: <20190228221933.2551-54-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert SELinux, Smack and AppAror to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 3 +-- security/apparmor/include/secid.h | 2 +- security/apparmor/secid.c | 4 ++-- security/security.c | 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 29e52aedd6ac..2f07be4b9800 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1316,7 +1316,6 @@ * @release_secctx: * Release the security context. * @secdata contains the security context. - * @seclen contains the length of the security context. * * Security hooks for Audit * @@ -1653,7 +1652,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 dadb1cb72920..4dfe053ced5b 100644 --- a/security/security.c +++ b/security/security.c @@ -1990,7 +1990,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); } @@ -1998,7 +1997,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 8b8eb5115d6d..ea9603b63f77 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6215,9 +6215,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 26cf42ddba0e..332ac71e8a41 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4383,9 +4383,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 Thu Feb 28 22:18: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: 10834047 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 78A661575 for ; Thu, 28 Feb 2019 22:20:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6545B2F34F for ; Thu, 28 Feb 2019 22:20:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59CEA2FC94; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04AFC2F34F for ; Thu, 28 Feb 2019 22:20:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731828AbfB1WUe (ORCPT ); Thu, 28 Feb 2019 17:20:34 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:41558 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731543AbfB1WUX (ORCPT ); Thu, 28 Feb 2019 17:20:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392421; bh=I2SWh5K68INYnyIQSA+tYZwWK64ln9fVNSN4i97zJx0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=UI7ZFhVQ/K5imvGr2wTGjGWCZefwq8acl4nROIlF3fluYdgMexCe8nC+D/+zDnyvRacXq0nI/Am+nprBC12oxyC+53jKYsJ4ws/xLMAf9Jh4ugFsuHnVepz2IVK3A50C+1b8SmD8DPzqEqeVwNnTZqN9+Dje8lDovTM2j60y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K 07tT_tEoVRGTTlpTabp4EycaaAdc3VqSHLeJeOID5HB.UkLLT.h9p2ZmF8VL4AR1wQaLrGwQeJW4 kzDZpRG2bJBRdqgHNSuwXFOFVKf_SaDbMHOoEgejzXXR546SM59WVHZygw_uT9LRf0V2pI5EEf4W kV1CXJjejQAmCpW175KIqJafx4aMH7_6ff_TB_vXBpl.bVrZB1y9KVgtOig.yTkNRj1Dq6ZmDvA1 QF7BRY3bvYHE5pwvKVEhh42nDDp8vZwJTXE.EYw1b Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:21 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp423.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 51882fbcdd41d0138ebd23ca73a62b12; Thu, 28 Feb 2019 22:20:17 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 54/97] LSM: Use lsm_context in security_release_secctx Date: Thu, 28 Feb 2019 14:18:50 -0800 Message-Id: <20190228221933.2551-55-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_release_secctx to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- 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 | 36 +++++++++++-------------- kernel/auditsc.c | 18 ++++++------- 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 | 12 ++++----- security/security.c | 10 +++---- 15 files changed, 99 insertions(+), 105 deletions(-) diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 4ca0b5c18192..a2f8543b88f1 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); } kfree(kn->iattr); diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c index 1da14b56888e..62b152c24f59 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 f56963c995b0..fe95c055c27b 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 23b776bc16bf..b5c03e326e32 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -430,7 +430,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); @@ -1208,7 +1208,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 8f76f164d2af..55b9431489fc 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -1184,8 +1184,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) @@ -1416,27 +1415,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: { @@ -2166,16 +2164,15 @@ 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); } } @@ -2204,24 +2201,23 @@ void audit_log_name(struct audit_context *context, struct audit_names *n, 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 090f9f2cb571..797a9f1847cb 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -935,9 +935,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); @@ -948,12 +947,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="); @@ -1162,14 +1161,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) { 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 65741838985f..03c3488a37d8 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 b47ca79b8e14..e1a8eaa3a62d 100644 --- a/net/netfilter/nf_conntrack_standalone.c +++ b/net/netfilter/nf_conntrack_standalone.c @@ -169,9 +169,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); @@ -179,13 +178,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 314528bca31c..19cdcf58683d 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 = &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 eae91a11accc..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,11 +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 4dfe053ced5b..4f0c7d2cd1dd 100644 --- a/security/security.c +++ b/security/security.c @@ -1982,7 +1982,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; } @@ -1995,13 +1995,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 Thu Feb 28 22:18: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: 10834049 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 9D463188E for ; Thu, 28 Feb 2019 22:20:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DF902F606 for ; Thu, 28 Feb 2019 22:20:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8243E2F34F; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94C452F3A8 for ; Thu, 28 Feb 2019 22:20:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732266AbfB1WUg (ORCPT ); Thu, 28 Feb 2019 17:20:36 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:36922 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731521AbfB1WUX (ORCPT ); Thu, 28 Feb 2019 17:20:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392421; bh=Z3r1HTDy1+P+o1sE/iyAOYjrezPUZ2YchMc8TzthhyQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=tyObs72yqGv6SnEfuRTkRuITWXxfaraNEeLDDvB4jMSN7ChUyQUdtpl7C4ZZCFu/JG0v5gAYthjUnwxTvWpZxbGV91QpK3i56NTOy52dZzGIqk9y97Kx9w3QQYOE9+wsEGCIh/wLGTGMW481Shx983o5rLVYcD785GcPST0Y3BpAD0cT5UepSDfWpSnKoHgQCJ1sVQag7A3PYHcKDpnVYq2nnlEH3eSD3rJEYV9KqBzFOG8q3bJL3WqklHYp2OC+rCVAnnNhgiw77QrxsNtMHqTcFhDtj5Ln98CO5aR0u4Q3tIqVp6ZAcZGcqx6S+t1PXkLW7xZA3gMBv3MyC4JjdA== X-YMail-OSG: mpZWuHIVM1nO_JSORObInWOiBXpGHv9saYabFGH6rQoqVxl36aymu_Q8skCbP8_ 0A0AQE5V1M7u7Jc9rU6rlCyUfn2XojaCTWx2mwWBqsdZgP9GOEz.h.HzPzvlwu2mADXX.tCVSc1S D4s0IMrMA3MzJYkrc80Pv2SbDu9rhyr5LnmwY1eKHllwjfww_PYIYErbK6qkzYZNKIi_MEAhuu6s Cy7GVHb3ypu2y0q5Rz91cL.G_nstl8cLEOBWcfRiY3efDaE79XiBWis_nUuQZRcYLzw3RsWD92Yz D.fFouWl5P.uYj2ERaXCFPLvDqPKi07xYS7IWsokuivNjv64SqlGH2gah9vNXR8_dCd05UhG3dJh 5eL9wNlQrikYjRwbtTc.Kmt.kyaQ.Qn.COL4hqA_9CwBxcCeblJPnNl0y_dIAnvJp8wntqgRdlOC 3jOqXOk1DvVg1irH34iCnrilCG2KnUlmv5DNpzbhY.8I6zip5F3RFhg_Sn330KUPnePmpYLwKfMS D1Vr6CPgpoJXXhQym_.LkoFL_mN00MXKHz1U1XraokRIiVe97NrLlzaaPCSvuTWDNY3Ng.buuFQC cS4FA_GiirZm9VeR2MF5RRI.mdQORc6RJlGwoTMZ2C0FwZrA.MlB6ZUz2wWwBYB_XOzEbBcMTCOx gRceiwVzFDRysmnLHzu6Eo6d6lLs1S43OOlRbzvpN0HSyf1222UbM5AmjYOsIeur0kK_K3VKW3xg 3w3bXbdj.csYeLzqTsZyeAzpzdrYQufmkBm584HvgQV380BkXTVOvVXZk3zTiLCqJMvF13TRHHMx Gm8fJTS4ThLpXbWRDqr1K8ogPn9Ma1YZ.cz2yAucZWivl92XKT70QBE9.NuhLAvDf7nRckHo2fMZ A4haEL6B0FjrEj5ScfBh9BSXJxyEB49RRTbdXWvWv_1h1Q2Ako8S1htuVhDXlUEhbrM3HpfuIVxV Lg6SXJ1d8AojH2syZM4jM13pFsDP9S3tVpLgeSBMd69hazfG.4IKvCmA1.1VUIN8OYsbg6GyDM1n O4jrn9Uvp3kzVy1Nk1AIs1Ur1no8ETQE6y8XDuCV7k7iXhvC5MWPnfFCQV3AlCjhX40vnvBhVDWg CbXK3mbb0Nq87CkEOVdvgfa9Cc4GuL5_6_qh3QRa.vnwce.4- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:21 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp423.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 51882fbcdd41d0138ebd23ca73a62b12; Thu, 28 Feb 2019 22:20:17 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 55/97] LSM: Use lsm_context in security_secid_to_secctx Date: Thu, 28 Feb 2019 14:18:51 -0800 Message-Id: <20190228221933.2551-56-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert security_secid_to_secctx to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Add a flag for lsm_export to indicate that the caller of security_secid_to_secctx() is only interested in the length of the context. Signed-off-by: Casey Schaufler --- include/linux/security.h | 13 +++++++------ include/net/scm.h | 2 +- kernel/audit.c | 7 +++---- kernel/auditsc.c | 8 ++++---- net/ipv4/ip_sockglue.c | 2 +- net/netfilter/nf_conntrack_netlink.c | 9 +++++---- net/netfilter/nf_conntrack_standalone.c | 2 +- net/netfilter/nfnetlink_queue.c | 2 +- net/netlabel/netlabel_unlabeled.c | 10 ++++------ 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 +- 14 files changed, 35 insertions(+), 44 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index b5c03e326e32..46cc16a67212 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -81,10 +81,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) { @@ -428,7 +429,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); @@ -1197,7 +1198,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 55b9431489fc..87e5f6fffb7b 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -1416,8 +1416,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; } @@ -2166,7 +2165,7 @@ 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; @@ -2209,7 +2208,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 797a9f1847cb..8e48053d4a74 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -935,7 +935,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; @@ -947,7 +947,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 { @@ -1161,8 +1161,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 { 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 03c3488a37d8..72aeba0de49c 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; @@ -622,18 +622,19 @@ static inline int ctnetlink_secctx_size(const struct nf_conn *ct) #ifdef CONFIG_NF_CONNTRACK_SECMARK int len, 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 e1a8eaa3a62d..8574a5611823 100644 --- a/net/netfilter/nf_conntrack_standalone.c +++ b/net/netfilter/nf_conntrack_standalone.c @@ -178,7 +178,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 19cdcf58683d..f01c97eb6285 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); } @@ -566,8 +565,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 +1135,7 @@ static int netlbl_unlabel_staticlist_gen(u32 cmd, lep = &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 4f0c7d2cd1dd..2b2520ba9554 100644 --- a/security/security.c +++ b/security/security.c @@ -1973,18 +1973,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 ea9603b63f77..07213ae8929f 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6199,6 +6199,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 332ac71e8a41..1861587b3620 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4357,7 +4357,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 Thu Feb 28 22:18: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: 10834063 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 5B62918B7 for ; Thu, 28 Feb 2019 22:20:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4ECC92FC95 for ; Thu, 28 Feb 2019 22:20:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 419852F3CE; Thu, 28 Feb 2019 22:20:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 806402FC95 for ; Thu, 28 Feb 2019 22:20:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730287AbfB1WUi (ORCPT ); Thu, 28 Feb 2019 17:20:38 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:37252 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731381AbfB1WUW (ORCPT ); Thu, 28 Feb 2019 17:20:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed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k5VrU9YuH3J.B3J3jlYvoP0SpEtG1mRuuIf9_bcL1soJOdrkcVwYbSPoPBK_7T9VZDAT0etMk1xa 79AK74TeBolhQ7yCMoO8fekyjZNA6U3u8z4EgP.hnbP.1rNaP0SpN2LdW69RjupXXGRhLt_nJg3S yULiamtiwPakvxeqnAGE5Q5sHWSbuixtnnp29fnQA4SNh6daBJNp2sI9ePXpMCzTi_.78LUZ0qd3 d1coZwkX52zTk6kWFh4CmSLbYqyjSRpqEbZes0MyZuK3ksxm1UQbIEpPL2Ew4uoRrlzcG73o8I_U aXPo8MxSCRT0zd7Iwk3nioIO2kSdi4QHg11ZITamyxLzj49gNwjDNx7rc8aXose_H3GY4NdtvBq3 QjMCtSGlPeD6Bzg9blzmzF3CIjxzcLqe2hH4gPGpBuNSt8Ej2FXdjiLtyatoSvJbfi.8ikEIPMx3 WVNLUhkRnlRuJvUdiodjRe4lSCfZGxdYPiC.XVeNFjpylnqK0PBmsEvsA8Vu2gvkelt_lYPKMHf9 i.Opy2DUmeRro6I2CEqJmCwKX5RKvCRTh0y7zw6G7vPa31W0- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:20 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp423.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 51882fbcdd41d0138ebd23ca73a62b12; Thu, 28 Feb 2019 22:20:18 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 56/97] fs: remove lsm_context scaffolding Date: Thu, 28 Feb 2019 14:18:52 -0800 Message-Id: <20190228221933.2551-57-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Casey Schaufler 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 | 4 ++-- 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, 44 insertions(+), 56 deletions(-) diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index a2f8543b88f1..a99ceae97e0f 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); } kfree(kn->iattr); diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c index 62b152c24f59..6db050b7c6ab 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 3d83b114bb08..f9187731e2b5 100644 --- a/fs/kernfs/kernfs-internal.h +++ b/fs/kernfs/kernfs-internal.h @@ -15,13 +15,13 @@ #include #include #include +#include #include 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 f6c339d4e6fb..1679011f7854 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -339,22 +339,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); } } @@ -374,12 +371,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 b1e577302518..67ec16c1b6e1 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h @@ -306,20 +306,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 fe95c055c27b..cc4d7d631feb 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) { @@ -3557,7 +3549,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); @@ -5596,7 +5590,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 = { @@ -5622,7 +5617,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; } @@ -5714,8 +5709,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 2fc8f6fa25e4..e3a237490e09 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c @@ -1140,7 +1140,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; } @@ -1174,8 +1174,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); @@ -4280,8 +4281,8 @@ static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap, goto out_overflow; 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; @@ -4291,9 +4292,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; out_overflow: diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h index 1b06f0b28453..d34865c57324 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 Thu Feb 28 22:18: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: 10834061 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 BF80F17EF for ; Thu, 28 Feb 2019 22:20:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE7DC2F3CC for ; Thu, 28 Feb 2019 22:20:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A30962FC88; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB8F02F35C for ; Thu, 28 Feb 2019 22:20:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731398AbfB1WUi (ORCPT ); Thu, 28 Feb 2019 17:20:38 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:45761 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730287AbfB1WUW (ORCPT ); Thu, 28 Feb 2019 17:20:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392421; bh=fNWGz4uuvEkQLif1Z2lsOSS1NmbXmk0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TrRcAg18 GohBv8qVYA3iF6pi.RK61zD8Erx3peHL9nQFVR0yTgQejxmgKW5BGc_rOWO3QCQwOF1gWBS7lhRy DT6Sb0kvo_0qkAhCl2YRGNtkLtRmLlqPTPbLDuloXoD8SHKWTRHLLnCo.H8wB9GH18ZPsBOJpk1f UU4NkCU2652OEIkbhDqt_.t7WNf3mImB.xv_PXDgU1brMfTisXzbSpamo_05hI1WEtkimeUJUWVZ un.oIHrAhGVR.5_fZwPChbKoD56dW3rloChynbCCwiNP2FT4azTRYtCe2zmazk4WAiYo93vNITzH Y1ZhEYRRAXYoBlMk77.i6wconXwticS9zDtKDhEj7jm0R4IljHi0XkYYp1_yLnRQd3ZsbWxZRbUl cZJbZihSxFC1se9d.JvbmIW0kaVRRQpsOR36d3HEwcYNV5lTF_TKkM7fvg.fF_nWo5WaTPwcdjj7 blJ5m5HUBeHb_3GOF_QuIvA1rzYZoSXefC.aK_7ROLAxFf0oc Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:21 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp423.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 51882fbcdd41d0138ebd23ca73a62b12; Thu, 28 Feb 2019 22:20:19 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 57/97] LSM: Add the release function to the lsm_context Date: Thu, 28 Feb 2019 14:18:53 -0800 Message-Id: <20190228221933.2551-58-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In order to ensure that the release function for a lsm_context matches the LSM that allocated it an element is added to the lsm_context structure to contain a pointer to it. This function is called in security_release_secctx instead of relying on a value in a hook list. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 6 ------ include/linux/security.h | 1 + security/apparmor/lsm.c | 1 - security/apparmor/secid.c | 11 ++++++----- security/security.c | 5 ++++- security/selinux/hooks.c | 14 ++++++++------ security/smack/smack_lsm.c | 16 ++++++++-------- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 2f07be4b9800..349d7c28147a 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1313,10 +1313,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: @@ -1652,7 +1648,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); @@ -1927,7 +1922,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 46cc16a67212..749acb6a28a6 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -121,6 +121,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 8c854f95d814..732b4de175bf 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 2b2520ba9554..a49095112416 100644 --- a/security/security.c +++ b/security/security.c @@ -1988,7 +1988,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 07213ae8929f..8ecdf975c53d 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -2714,6 +2714,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) @@ -2728,6 +2733,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); } @@ -6199,6 +6205,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); @@ -6218,11 +6225,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); @@ -6258,6 +6260,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 @@ -6669,7 +6672,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 1861587b3620..4fcd8271ca24 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4340,6 +4340,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 @@ -4359,6 +4365,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; } @@ -4382,13 +4389,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, @@ -4406,6 +4406,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; } @@ -4625,7 +4626,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 Thu Feb 28 22:18: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: 10834057 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 3180B1575 for ; Thu, 28 Feb 2019 22:20:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 271BC2F3D6 for ; Thu, 28 Feb 2019 22:20:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 256752FC8D; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDBC92F3D6 for ; Thu, 28 Feb 2019 22:20:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731609AbfB1WUh (ORCPT ); Thu, 28 Feb 2019 17:20:37 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:39450 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731398AbfB1WUW (ORCPT ); Thu, 28 Feb 2019 17:20:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392420; bh=LnmnhsasaI77ks/RQLogGGlvRpQnpCWHTy6G0cAXoWY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=GMtobKzW9Mf8YY++IBeQqfdUA/bhT26mERqH0fHwpJ4e/judRLfA6r1qaSSgmXy4ZWArf4/ps0j93FJFJhVfClaDkHx7HEkVis6Q00x86QYufQIZIlMldKQSVOjahFSkgLRpY21rakcVUj9RS4Cx2zxZkj5QxDx091zGH/1ZoB1w04V6isD4YIHBnAsmGTQamsmlFYwBh14k8NIQGS7XebPVpGHtZq1IOrDY3sNPrOFfMNKvpd6RLXNofbxrEK21nK+pEO2K5WYv44De/T2+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scSuapdcXOxoxGuPZFcJAizqTNXvD7.S4XjWVQNCQahBP1NvspzVHN8j90bSR7O g12mgRb3iTgn4lBTqpzeIYWNGlev8dqarvJ1aNH4sOuoY82TAe5sxFFQmTK5o_uUi_LcX05vNEXw .6XJSYUKQCU89I3SUJIa8bL0HQnyPa0PLN1na8SLh8FI.2wE- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:20 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp423.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 51882fbcdd41d0138ebd23ca73a62b12; Thu, 28 Feb 2019 22:20:19 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 58/97] LSM: Use lsm_context in inode_setsecctx hooks Date: Thu, 28 Feb 2019 14:18:54 -0800 Message-Id: <20190228221933.2551-59-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert SELinux and Smack to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 5 ++--- security/security.c | 6 +++++- security/selinux/hooks.c | 6 ++++-- security/smack/smack_lsm.c | 5 +++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 349d7c28147a..84035aea5a2e 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1375,8 +1375,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 @@ -1651,7 +1650,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 a49095112416..42c5467ccedc 100644 --- a/security/security.c +++ b/security/security.c @@ -2009,7 +2009,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 8ecdf975c53d..f58c96e2b6c1 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6247,9 +6247,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 4fcd8271ca24..d3ec5f49ef44 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4395,9 +4395,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 Thu Feb 28 22:18: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: 10833983 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 2113F18B7 for ; Thu, 28 Feb 2019 22:20:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1177D2F359 for ; Thu, 28 Feb 2019 22:20:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F74E2F3CE; Thu, 28 Feb 2019 22:20:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93BD92F3FF for ; Thu, 28 Feb 2019 22:20:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731796AbfB1WUW (ORCPT ); Thu, 28 Feb 2019 17:20:22 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:34778 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731443AbfB1WUV (ORCPT ); Thu, 28 Feb 2019 17:20:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392420; bh=fYhale5NrsEnocMiGoPfT1RN69Aoyq8H4hNdPv6qQ04=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=B8PqHWsG0Ctp6m0qG+bApIJ2Erbo+faFqZJN3Zp0kiGkvfXpKZYCIaEjzfv3U3kWOT0u7gSFXMgJYE4L05n1UXggZNAOBpuTPUOpGTG8ukPtHF3bqE8RTrirJgxUoC4Mb/43SsI5fKn99W8L439eyM1QwAglgvU5TBZIMMQoOwKNBz6y/rCGZY02GVqC+5EfBD66wIxbBV/HS+994MecbmXumi+rr3Yra2qqHa5pKmoM8XNcSdN5clayV+6SRI9m1lCKOdg5VfQgLHs+4TzRwGf/tHgOhpULpAWUuBzeKLOQp6NMSbJxIiqlcxHoeK439nuVNF4Z3gdJ2mX9kifO6Q== X-YMail-OSG: jNX_CiYVM1nL5RE55G6rWl5hzu7zlg8J44Q6RAux.gc37PpO3VgiLtiCSMf_AGi KdJ34t2TYapsVNJ36OwkpkzUCmm8HMOAjvfrxsYgYEr_WmQKOVjJy0cd0Nl8rCAS03zVO2_XWgnB R36WZjtpL_y..TTCs1hBzfkHdCf5pfkcpXd0seCl3M.sWMOK4r_QhRy.wJ2x.LGif6GUXy9i_Co4 WmKqi9nca0_C2pjR4mSyTmGYtF6OL3ub3fuxOa2grzng2mJ.EJu.kb_sIoI.vYIJYBWkk7925ga1 hdKIMnbwpvX1B2KU3EH38fFeGCyCGwmD.O5lka__LWJNbYQ6Ynfm6MITuBglUhuL2P1s6pFDlYjo 4EG2AyBw9nwY.GAtb4QFTVTAtQe9U1.5G_nRnESiInMlQMfs42g5NX2EdXT.A35l7QJVFKV.oPfz _ni2rs2e4oqXI6OThSxFrbX4v1.2YHHD1ngMjlP9AJ53kNBZAbn4cduiEq8UTrH9MMWatDqNuH39 mgo0wLmpWhDLjoBYYXRLNMK.hs9NPrrR5sx6gx_m_yuOmeDJm4zJiq7Hq2fbK5Xp39QLESpWf8wR rygP_yHfWBJTtIqsVi37rsSnUzfvxzohLEBOTyoGUTI6x7KdA4yq1myUiKmM6zDPugbqaNjYW2lq uH3OBg6iX04hFF2Y05ZoksPhKgXXZ2dSm2T5izAW2_reKSW.IPTnLjJwCX2Xq2eL2ofNfkux2SfS fHrlsSd5pie7esj4cKh7lXa2wLK32yMOvuZi24_.xBy29J1Uz.z5z8WlMcZ3z3JXOVZ1FQPl6AI2 M_FSqh.iI8gHESRbHqRnW_yPywW3Y0ol_.JQYGgmUt5dmYOv50s.thHbO5GCw3QQvm9QrUDdkZia rDco5gIWvWNZFd_X4zvrXyHuMpJ4vjexuHZA1RFTZ2AiBdEKLUySkvhCn9NTojApYdD4xQ4jwqSm ONCZcNHP8Ra4ImxDmW.C9xcraG1NqysW3Qdkg.Rcv6K1DNzLiT6PBpjir21z7tC2IYqOC3WzqH2x y0DSdlDn7rEJtdDqC4usD_0K11d0Eq_bMTsMpTLQykRVB0BoKAlFvssYlsFTjgnm1AjX3KW7.Cr5 .q0M.5EQz9LrHV9lmVAVyjTUdAb9mIUcRg9MjhBHurXsLNz2d Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:20 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp423.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 51882fbcdd41d0138ebd23ca73a62b12; Thu, 28 Feb 2019 22:20:20 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 59/97] LSM: Use lsm_context in security_inode_setsecctx Date: Thu, 28 Feb 2019 14:18:55 -0800 Message-Id: <20190228221933.2551-60-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Casey Schaufler Convert security_inode_setsecctx to use the lsm_context structure instead of a context/secid pair. There is some scaffolding involved that will be removed when the related data is updated. Signed-off-by: Casey Schaufler --- fs/nfsd/nfs4proc.c | 8 ++++++-- fs/nfsd/vfs.c | 7 ++++++- include/linux/security.h | 5 +++-- security/security.c | 8 ++------ 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 0cfd257ffdaf..5b4ea2a317ed 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -54,12 +54,16 @@ static inline void nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) { + struct lsm_context lc; struct inode *inode = d_inode(resfh->fh_dentry); int status; inode_lock(inode); - status = security_inode_setsecctx(resfh->fh_dentry, - label->data, label->len); + + lsm_context_init(&lc); + lc.context = label->data; + lc.len = label->len; + status = security_inode_setsecctx(resfh->fh_dentry, &lc); inode_unlock(inode); if (status) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 9824e32b2f23..d9e408c3d0a2 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 749acb6a28a6..cb5e685f60eb 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -436,7 +436,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 */ @@ -1223,7 +1223,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 42c5467ccedc..b45136a8fd81 100644 --- a/security/security.c +++ b/security/security.c @@ -2007,13 +2007,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 Thu Feb 28 22:18: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: 10834021 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 7FC301575 for ; Thu, 28 Feb 2019 22:20:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6FEE12F359 for ; Thu, 28 Feb 2019 22:20:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6DE2E2F53D; Thu, 28 Feb 2019 22:20:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CDD62F3CC for ; Thu, 28 Feb 2019 22:20:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731443AbfB1WU2 (ORCPT ); Thu, 28 Feb 2019 17:20:28 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:39329 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731928AbfB1WU1 (ORCPT ); Thu, 28 Feb 2019 17:20:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392426; bh=1XElOFnX0SWyB3Pfzpq0lWLsE8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dCNV ZIrwZGHQEhRAiRxrheKFF2.Jl8xWlMhO12BP7j9Jg7MFssa6tx.gUBisUffnGTNoEKLm82q7qtZG W_soBSrkeq6gaoyokchL9686fvg6Xz.W1gqHG0fcaF3Av9cQ7dfBlPLVW86_g3ntruA2M5aelHQM e4QP8_UvQpVN4navimpwWTpyeH.wtAkCM_4Ysz61j9311LyYuNXgGZb54bx620d6pomjQxDfrJay 8Hf2gW042qkFprzY1r8FHVQCLku5SAc66.uXoFr0Xpg7ZPaOaK_oV0LoHrlY68Qm0gJpMkZ946Dk rWuVxhFYfdt6vUhW9L9IF7fzkvuRLJYMYEonEe4Ese4rlXK3zt5zGFtbv2FooMW.LBTpV7V0hPNd x5NYFei_zhnN0thMK.9AZ1Jh2qex.KQNuV0EqiV28FWl6w.g5Er97BxH219bU7z1QCqAGVDZVhlC j9iIzgl6N9c7VZmd4MzuZaIvhfk6NHYjZY3at5iOm8PR.ti0- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:26 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp421.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d90148b291d74b44c78573c559ceeae0; Thu, 28 Feb 2019 22:20:21 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 60/97] kernfs: remove lsm_context scaffolding Date: Thu, 28 Feb 2019 14:18:56 -0800 Message-Id: <20190228221933.2551-61-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Change the parameters to kernfs_node_setsecdata from a data/length pair to a lsm_context struct as both the function it calls and the function that calls it want that. Signed-off-by: Casey Schaufler --- fs/kernfs/inode.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c index 6db050b7c6ab..3d47fd74cc8c 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 Thu Feb 28 22:18: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: 10834025 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 6FF471575 for ; Thu, 28 Feb 2019 22:20:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61E152FC8A for ; Thu, 28 Feb 2019 22:20:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6039F2FC8D; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FB8C2FC90 for ; Thu, 28 Feb 2019 22:20:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731894AbfB1WUb (ORCPT ); Thu, 28 Feb 2019 17:20:31 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:41817 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732148AbfB1WU1 (ORCPT ); Thu, 28 Feb 2019 17:20:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392426; bh=6keeEmCLQfJG32h3AdVJECQl7pkaNKOlaO2Xnn12UQo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=ndtkm+7g7uXxgLe/AGeJuKhtF6jbXFUBV0GL3jIR8reVXXRBhK2J8a3xNqsGZ35gpRVSeKz+HrQ95izPt+mjr6VjsqxZdWWWswZMnjtz0zoULseLvtaer328Lk+eeR+lAcOXYOyR1pyBXQS5KTp+PH3LVzbK+0QF+i5EtGH/OVL+jGHhBYBR/u5XJ3pR+DJuOG9XDUwgguJ0whpOHWvqHepHtGTdgTtoqsQUPwILqAAbNoy6/jzTGrED/R4Xxdac6xxZiUHtvSpxjOzuUpstre3rmOgcNmzshcmDD4POrJZMJoFu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Kd.FcVOGt8rYtOU UUpiE6xmdmBgJCadyPDhqFulZ58R6o._nn8z8M7bdkzGTL8C.l6E.Zn5F4cvSFNhgKjck0d.TnLE DfWKKIZvSH7kaPlsX1A.f7v30I1qQv2BwM10Cw27XMMRLpHY- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:26 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp421.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d90148b291d74b44c78573c559ceeae0; Thu, 28 Feb 2019 22:20:22 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 61/97] LSM: Remove unused macro Date: Thu, 28 Feb 2019 14:18:57 -0800 Message-Id: <20190228221933.2551-62-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The call_one_void_hook macro is unused since the change to how releasing a secctx was made. Remove it. Signed-off-by: Casey Schaufler --- security/security.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/security/security.c b/security/security.c index b45136a8fd81..257b7ff4b434 100644 --- a/security/security.c +++ b/security/security.c @@ -709,16 +709,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 Thu Feb 28 22:18: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: 10834011 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 0A4D4188E for ; Thu, 28 Feb 2019 22:20:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF2A12FC8A for ; Thu, 28 Feb 2019 22:20:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3B932FC95; Thu, 28 Feb 2019 22:20:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7928F2FC8A for ; Thu, 28 Feb 2019 22:20:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731928AbfB1WU2 (ORCPT ); Thu, 28 Feb 2019 17:20:28 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:36439 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729839AbfB1WU1 (ORCPT ); Thu, 28 Feb 2019 17:20:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392426; bh=emZL0pcrMIen8v9nduBVX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Ie.V6Q3 TcJvaEM_._BlsjSiceOz7DnJ84FQunbiaiTZju_8jIs2EIykHlTLgdJ8tbC9YsLzSzmMdozJmVUV K4R7GRtsOvg04dm8I_fSjMuXPA.HzyIX9ih6PhdmR6eM0PRYOgDsTsu1MroF7RcqkYYILgJ8jMVR kUXsnwYwofYPsSdMEL75QrXksb.hgoia0RVksNdljMdEWSX.ALX2OULhmPRpDoDFXtLi7Dj8AvuZ zg89X3.lrYTT9BZ7uwl1jlsHZEk4wQNkUDUJ6GQ5ofFVtyyQgj.JjoBQrW_RGOqcUh2cGvXSeRdS ZRwRZ4tM8zX21sr7Xk1DDclicG.iu3uv.YARu8fN7GkSBiLaVxqCVwuSXBbGSbNNBPI5rAVPi6pw dG78UJqb3aiMML3XWnWjOh5rRlBB41Dyf4gCgfwfa7VTQWrE2rqJBmK2Owj4iem_n8pGsCTcoYTJ SolQ4z5JjyB2.WR.ERvJeMnxgkjgfS_pxsPUkPVBHfjd1U9o- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:26 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp421.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d90148b291d74b44c78573c559ceeae0; Thu, 28 Feb 2019 22:20:22 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 62/97] LSM: Special handling for secctx lsm hooks Date: Thu, 28 Feb 2019 14:18:58 -0800 Message-Id: <20190228221933.2551-63-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Create a special set of LSM hooks for the translation to human readable security data. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 10 ++++++++++ security/security.c | 32 ++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 84035aea5a2e..fc2a44e04d8e 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -2020,6 +2020,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 257b7ff4b434..217fa9d98699 100644 --- a/security/security.c +++ b/security/security.c @@ -431,6 +431,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 @@ -447,6 +450,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__); @@ -725,14 +747,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 Thu Feb 28 22:18: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: 10834023 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 11E0C188E for ; Thu, 28 Feb 2019 22:20:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0324E2FC88 for ; Thu, 28 Feb 2019 22:20:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 018A72F53D; Thu, 28 Feb 2019 22:20:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA3322FC88 for ; Thu, 28 Feb 2019 22:20:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727675AbfB1WUa (ORCPT ); Thu, 28 Feb 2019 17:20:30 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:33420 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731894AbfB1WU1 (ORCPT ); Thu, 28 Feb 2019 17:20:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392426; bh=QK9560GfKQyWtmcg3Y6lnKMpYD6MKgEAgcdInD1a9Ak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=GELUpyIomE4pB5EPW95vvS+oN7rUfuX2a2xKewver3BfrJV6MJbBTyca3NR4x1E7n2FkioJr69DGI07cwtLkr+RKiXQQxnineaDW1H5F/PsDZ1ntV7k/f/5KNZS96K7JTXt6hrIwb+0u5WJ3darmSc/zvhe+xPODuc+c0ovNVOOGSSepY39bqWpsEKeuy0Q4pdE0mDICptELK40Hp+ZMw11tbaiIZKgghW76D3zv1RXQNQMsobggCZZjKgFwY+Na6FFty/EsoKEpr24o7Ymxigqnr4bzXrBKGlGuz5jJyrmV9w7ctYNVpdIdD3ywicI/TvLqTnKi9jdkQLdEErSq0Q== X-YMail-OSG: 6gKhbYgVM1mmrPWBCA6062HAsRKfehk83tx2skYssZg8lVo1NX0G6GyQyvCthqz nqcZBPkCs7NhKpQx0aGTPopwKzJ_HFHdUeg2TjLcumnlHyR_1DtJsYa_y1U9X0FrRL6d5zh9q6Ps PVkOEf7bGhoC9lYWaSEH1.Xl5lxnfG9jv9OGOG7XXxGEvl92bSzEPMUInQrCnVwXb9SZQAlJ.14F AOmemee8j2ZepFbOEJCBOAqsxtwrbvRLU10a9Dz6BrfvnN6uFPPxRrecKluWXK7m_Z26GkkSgS6Q I8kcxjwZTU3yzYASi0aLwPWp8d1iVPb6D6mRyBwqRXH__EmCE8cavBciM_IFjyuiHeBKhMeScqXk 8137TH8UqLtlJdnt3vUQbjP_G2Cf95PBWidc0pfWX9n8ykHNZoJfF.9j7qy4mRFSizjbxJLG4Fql SlHC_Ns6mCjwfXJgYTPqVogxHhyvg5xeCOtoAelWjdVEQSfXJenw7Y5Jgzl0kO3dDSfHQ5Nm7Uti eSEO8AEyMQi0wEC5oHIJ.Z03wr8tmTqWS9I3Bfpshe3Fke5psSPXoO5co0LBarsmIlKilxWzSCPf QkvJsBYIc3PA6LSpQS5YhG4dlOCaw5UWQQ1OizM4hQ.AF_Io9ifjcHz9PcwwZV2Scr7zasOQ11j6 m0aS94CcULdZlbIvCNQrmtYD4X9o9Cj4yLsgHunHh39hweu.nu8q700mV9KC7O3lmwvju_2UcGHT NNn1cQLZcX.5iJ4X3GtnK8hX.gSZAk18ZUZvfbei4vxeBJypS7VBE7iz_s041B3Bkji16WFiVJXn pf03RInsX4rvpLKIL3cnWJuYFzoCgR1UKZTpRbj4pXVrGEyJNA84ob_7LV5_PtL1fWDSTsDKEza. 3E9qxYVcgjrNI2kZdeG56oECssHj_9zus8TdwBOHaQI3cLL49YMuZWmjbluq34KYaQaAg4Mma_hg e8z6eOcmd7WKSrYsQVAGT3hgwuPPJMjIXZSTbpWvTQbN6mx7bqBLS2QOeGDT_U.GpU5o.mnYBlnW dh9JwnurkGWP5uEMGE2pqnfB8Qy.B9U39LXGCkw8LbzzqjpV5y_G4CZ12NhkfA19BWNpEa7Whcow c8.lGkASTeyzF8eFNzS6deawihLERsJkdYSlJRbDxXeUhFq6g Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:26 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp421.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d90148b291d74b44c78573c559ceeae0; Thu, 28 Feb 2019 22:20:23 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 63/97] SELinux: Use blob offset in current_sid Date: Thu, 28 Feb 2019 14:18:59 -0800 Message-Id: <20190228221933.2551-64-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace the use of current_security() with a call to current_cred() so that the blob offset can be correctly applied. Signed-off-by: Casey Schaufler --- security/selinux/include/objsec.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/security/selinux/include/objsec.h b/security/selinux/include/objsec.h index 59a3b1cd5ba9..c9a88b7a96a7 100644 --- a/security/selinux/include/objsec.h +++ b/security/selinux/include/objsec.h @@ -31,6 +31,8 @@ #include "flask.h" #include "avc.h" +extern struct lsm_blob_sizes selinux_blob_sizes; + struct task_security_struct { u32 osid; /* SID prior to last execve */ u32 sid; /* current SID */ @@ -45,7 +47,9 @@ struct task_security_struct { */ static inline u32 current_sid(void) { - const struct task_security_struct *tsec = current_security(); + const struct task_security_struct *tsec; + + tsec = current_cred()->security + selinux_blob_sizes.lbs_cred; return tsec->sid; } @@ -174,7 +178,6 @@ struct bpf_security_struct { u32 sid; /*SID of bpf obj creater*/ }; -extern struct lsm_blob_sizes selinux_blob_sizes; static inline struct task_security_struct *selinux_cred(const struct cred *cred) { return cred->security + selinux_blob_sizes.lbs_cred; From patchwork Thu Feb 28 22:19: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: 10834015 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 A807518B7 for ; Thu, 28 Feb 2019 22:20:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A7162FC8C for ; Thu, 28 Feb 2019 22:20:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98B902FC90; Thu, 28 Feb 2019 22:20:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=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 963B32F587 for ; Thu, 28 Feb 2019 22:20:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730146AbfB1WU1 (ORCPT ); Thu, 28 Feb 2019 17:20:27 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:37575 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731833AbfB1WU1 (ORCPT ); Thu, 28 Feb 2019 17:20:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392425; bh=lPuf/l+w96dL9OLn/Q22XVCX10YN/72ynTjEzrbMVJA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=f4NNmsTij6rpVuqNTUBKrJIA+A/9pf5UmZZHyD2LA5m94wOtYvXdLNHRuKUWxy92Ndy+Era6lRzySMAhQzU2Eg7q9B6L2E8s7WslKUsBnz/ut0LRsnTLDxP4vXe5qBIN0xqS/pHIgQRLAFr9dgEVme7Ieu0NZtJZm4kFuttTI2rctAJ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FTMA7ugiQ t6_Tf5wuoYV.bIUiPa9E.7jr4RWz2tL404pBj9TuivtZ0xPo6IPXn2TA2raukWa394OmJ.QAvWtZ 5aP0KNmPL1hagBqEC5cJJCRkyhL6skeYDd6goe3XbnYUZkisAX25bEy4UMopQy8.3LOmEPnfEWOO s4U4sZWoQc6FboYLeym4LYJP8QihL_Cdz8f4FxUaoI59gOEUm3LEPOMv29dw496f7CSra.6nsHYU etV6rHUvuORS8I7mmSoR7au76kTgaBj2tmxtIAgxQh5aqwC4- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:25 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp421.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d90148b291d74b44c78573c559ceeae0; Thu, 28 Feb 2019 22:20:24 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 64/97] LSM: Specify which LSM to display with /proc/self/attr/display Date: Thu, 28 Feb 2019 14:19:00 -0800 Message-Id: <20190228221933.2551-65-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Create a new entry "display" in /proc/.../attr for controlling which LSM security information is displayed for a process. The name of an active LSM that supplies hooks for human readable data may be written to "display" to set the value. The name of the LSM currently in use can be read from "display". Signed-off-by: Casey Schaufler --- fs/proc/base.c | 1 + security/security.c | 123 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 121 insertions(+), 3 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index c9d775fd24ef..632ec6b6d3d5 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2637,6 +2637,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 217fa9d98699..1259b3f50066 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), }; /** @@ -747,7 +751,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; \ }) @@ -1603,6 +1610,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. @@ -1612,26 +1620,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) @@ -1946,10 +1972,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; @@ -1959,10 +2003,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 Thu Feb 28 22:19: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: 10834007 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 634501575 for ; Thu, 28 Feb 2019 22:20:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54F912F3A8 for ; Thu, 28 Feb 2019 22:20:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5383D2FC8E; Thu, 28 Feb 2019 22:20:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE9992F3A8 for ; Thu, 28 Feb 2019 22:20:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729839AbfB1WU2 (ORCPT ); Thu, 28 Feb 2019 17:20:28 -0500 Received: from sonic302-28.consmr.mail.gq1.yahoo.com ([98.137.68.154]:33012 "EHLO sonic302-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731967AbfB1WU1 (ORCPT ); Thu, 28 Feb 2019 17:20:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392426; bh=YwEKmfUdJeYIoOk75VzJuE2RgnnRiZETVFc3PB8XYeY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=k/M4XxRn/WFSZASPaxAAVqm427D0iWRHdSrEqKDfqFIXi/KOd6otrHjyHqutnFEVX57tSVatW7w1jR4XU9Gc/2kSc/Cb2BcZsge7+Lt7VL+rdDSZE4iHgRtWtwlGZx9wtcwN9Z9/1+3JrctqfYxDfj7VB9Za2nWquaH34N88AI8poSeypMUy9Cp1SXYGhx8aM8YK3JuKVvNms87P0j0lfi4CywEfiOYFha2g7r7I+UB+WKyMQJhmZorLOrMukBx9d3g0E0Gby6d3wbLm+ePboUIUQ7fvnHGX3oPXHuQNwAOA32tPlFZoMua6SG4hHmFy/OLKPIAP2ci3O62kurnYTA== X-YMail-OSG: 1USqhioVM1mdIXFbWhoHEyAuTaR2SBTn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ZoPwc9q9VEtG9rq_9tE0PL1x sqVPXNTv5..CSvMPOyBbuFk7FOGkkuAQuqfwMvbAPBVht6xE- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:26 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp421.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d90148b291d74b44c78573c559ceeae0; Thu, 28 Feb 2019 22:20:24 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 65/97] AppArmor: Remove the exclusive flag Date: Thu, 28 Feb 2019 14:19:01 -0800 Message-Id: <20190228221933.2551-66-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP With the inclusion of the "display" process attribute mechanism AppArmor no longer needs to be treated as an "exclusive" security module. Remove the flag that indicates it is exclusive. Signed-off-by: Casey Schaufler --- security/apparmor/lsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 732b4de175bf..d72d5b36dc87 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -1703,7 +1703,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, From patchwork Thu Feb 28 22:19: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: 10834003 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 CF82017EF for ; Thu, 28 Feb 2019 22:20:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF9692F431 for ; Thu, 28 Feb 2019 22:20:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD77A2FC8C; Thu, 28 Feb 2019 22:20:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EB4F2F431 for ; Thu, 28 Feb 2019 22:20:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732165AbfB1WU1 (ORCPT ); Thu, 28 Feb 2019 17:20:27 -0500 Received: from sonic315-15.consmr.mail.gq1.yahoo.com ([98.137.65.39]:45789 "EHLO sonic315-15.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731915AbfB1WU1 (ORCPT ); Thu, 28 Feb 2019 17:20:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392426; bh=d2yi6kashfnbxR/7bzB8UE4jUy5Q3Uozsr8ymRFgpzg=; h=From:To:Cc:Subject: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YSVqsdYO4IKcEoJO0N.Ebnzor7dgo1zKTSYfwKsSadSK95hqJQHj fQeZF0.s4vXZ5VTMAs.Un_pYNUW0TlGFBtX8x52SNW8XAbQqqWHiGcgbvYz1t22QZ4AdRgwq6hln ARS9FcVyowDzITQgVW5Rz6wvL2a4G3YrYodCagGLjCtDaqi24UoZ.7isbil41GXTlq_CzW7BuXoU 82qdtPsuYLHwc5IVbln7qZWm.8.0tfaXp0xIZBZ2L6pbmMsv1BEsZBQm.d3E4G9FXbc838A1aBDK LQT789kzjsRB0FSgUIlupGg_SpMt3xWYRXeHbyT8xVGmbbbeyfzA1QcVY5ga5S4WGlC7R1YUcNKi UKQdVSub8qoGJWuhuahlt9h1Z7DU5V2FcizmUQFP56xN8or9r0hypPIBMzaIpAFtkBiK69BOHDjn wG01e.xfZncJ7Kg6L0EvT9.AY._Kr9tY_7KXO4MKskg62Nj7n Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:26 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp421.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d90148b291d74b44c78573c559ceeae0; Thu, 28 Feb 2019 22:20:25 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 66/97] LSM: Add secmark_relabel_packet to the set of one call hooks Date: Thu, 28 Feb 2019 14:19:02 -0800 Message-Id: <20190228221933.2551-67-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The secmark_relabel_packet hooks are dependent on the results of secctx_to_secid hooks. Add secmark_relabel_packet to the set of one call hooks, as the secid use will always match the LSM providing the secid. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 1 + security/security.c | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index fc2a44e04d8e..e76e5cd05180 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -2028,6 +2028,7 @@ struct lsm_one_hooks { union security_list_options secid_to_secctx; union security_list_options secctx_to_secid; union security_list_options socket_getpeersec_stream; + union security_list_options secmark_relabel_packet; }; /* diff --git a/security/security.c b/security/security.c index 1259b3f50066..024601db215e 100644 --- a/security/security.c +++ b/security/security.c @@ -469,6 +469,9 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count, else if (hooks[i].head == &security_hook_heads.socket_getpeersec_stream) lsm_base_one.socket_getpeersec_stream = hooks[i].hook; + else if (hooks[i].head == + &security_hook_heads.secmark_relabel_packet) + lsm_base_one.secmark_relabel_packet = hooks[i].hook; else continue; if (lsm_base_one.lsm == NULL) @@ -2018,6 +2021,7 @@ int security_setprocattr(const char *lsm, const char *name, void *value, union security_list_options secid_to_secctx; union security_list_options secctx_to_secid; union security_list_options socket_getpeersec_stream; + union security_list_options secmark_relabel_packet; if (size == 0 || size >= 100) return -EINVAL; @@ -2053,6 +2057,17 @@ int security_setprocattr(const char *lsm, const char *name, void *value, break; } } + secmark_relabel_packet.secmark_relabel_packet = NULL; + hlist_for_each_entry(hp, + &security_hook_heads.secmark_relabel_packet, + list) { + if (size >= strlen(hp->lsm) && + !strncmp(value, hp->lsm, size)) { + secmark_relabel_packet = hp->hook; + found = true; + break; + } + } if (!found) return -EINVAL; @@ -2071,6 +2086,7 @@ int security_setprocattr(const char *lsm, const char *name, void *value, loh->secid_to_secctx = secid_to_secctx; loh->secctx_to_secid = secctx_to_secid; loh->socket_getpeersec_stream = socket_getpeersec_stream; + loh->secmark_relabel_packet = secmark_relabel_packet; return size; } @@ -2317,7 +2333,7 @@ EXPORT_SYMBOL(security_inet_conn_established); int security_secmark_relabel_packet(u32 secid) { - return call_int_hook(secmark_relabel_packet, 0, secid); + return call_one_int_hook(secmark_relabel_packet, 0, secid); } EXPORT_SYMBOL(security_secmark_relabel_packet); From patchwork Thu Feb 28 22:19: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: 10834041 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 BFF0F188E for ; Thu, 28 Feb 2019 22:20:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B57072F359 for ; Thu, 28 Feb 2019 22:20:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B36D02FC8A; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F5552F359 for ; Thu, 28 Feb 2019 22:20:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732199AbfB1WUe (ORCPT ); Thu, 28 Feb 2019 17:20:34 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:36261 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731828AbfB1WU0 (ORCPT ); Thu, 28 Feb 2019 17:20:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392425; bh=g3SbYyqnAYykVzKNW9ckS4SnvlWfIuT7xfaM+EUnDjU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=tIb+WifNJ8pN6TvXk7uyDNBgLlziA4kZSzqsmP7UReYtGs8GDvKU4u8nlKtrtFvO+nh3evwUSRIxbW8tJppx+taSBmOYtWbVrgtCcOMH+VbQNIfOs4ZZ1LNaMBa27xYm0+rPdXGGE5VLLZQLziIJdlEOWjRYzQVN2cvoyrtwaSBqGrBaIodJDvKRCA+Tw5eWCocvLXM3ESR/5MMWoJvwje2s8y6w0hiB339jUAH2qZRw1/1/mtloUqraS8eQKzRDT/x/ckAGnTGmzgINVBmJEbBjJZsM+JLP2S55ksDSPiWaWDdgx7rIwoaRrhluekYmTAiTalS6++NRQNs6NumrYA== X-YMail-OSG: 0LlS0lAVM1m0qm0p9Mn3teGTc1PMHHwiPOckm_jm_Iqk9OeMGA4B2IzXY.ilQYQ wOv78D8UyIjsi5nbvCvIh9q.PP3KGqgn5e3teS13gi.Cii4bsW29vtrhvR6Tf6lX5IzirOPnHM7n usecXs18tvqPfQ.bPBtbNC3FxRtj6BDaavtGhu7FSHRBzoQJ.uM3ma8mNLbnoCH4y6jtyOBVy7vT WW9oMKDBnzD6kHFUesSqSZL_mY_eaGeoDd3GqxriUMbT33vCoRBoEGwkYHjNtElUWdArVVIZk7k6 AnfrOooVI0.G2ngRdUE42OROVtWFdbzcqNsU.W.nMuHZuhbxoZDNF_ZqnvPx6srjL2pY0ACGm6qS nddGl9iJ2OLJ2Y6NVAcCxoRcB7Sv0xISx7qEfOOA98tOwaWMG7UqICtRddrUYdgDoJNN5DHrav.J 258YFbzXnCjCxcD4j3W832byQV1CDKmQ5Q7WDW.4CYnJTL7hvd1WnO55oVvd7Dp52TZG_TKN0sZN ew996yoskEEdGS9ntEWXqxI4VJFynnCKd_S5pCJmCG2PZ_C7usRq95l8sraWYvv46s5d7YeJRYbz Q9Z3NY.i7UfIIf1H.iJfxx2y_8MjhYNud6vFjfZU5cK2_hRpUXhMPRZBaPOV8m7nD.F.gbh14n1N yYcBbvZwnDV7O5S6X.CVb9oNQaI6w_IIBm_pBzKmJXffr6fnP3N3txCFBMspY8UIAOObT8Vqv1b2 mI9_MxxdWiUCwC4syP..q7pRazxcsONR2VbWI6izX0bT73RiFdVqxz7TpL3RSFNDMdHGx270N5xR d2W2oa1LnjQdShPfyfcA7Y0t4i7INMvhzQL_pAgzu7CYi6d6dp3A2ETblDlb.415M9DLYAXotkc1 KHYw3KdjJljGVKoPp2_WWzj98vEgRI9Dn7T0bRaZbRUbLHXQ1d2VdstTwMgxLSKSAbGbCQ7fONtR YYjEvo1RGADjaosFY8tl9fHtXbzKZbqOM6AeW6_J779djtSmkfitgMCjr4QYr1znNMXdtt5CzyAs O9PJT_eZv71vBzN.UN8k_bXmZ9TasetniPE0aSGOJq8rbdGOreg7zAwDprtR5Z69dZvJqic7BZvF uQ_mEDNfYLUudLBp6JZgMH.4UTgzKu7UwbBzGLO.JFgtNvkBB Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:25 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp421.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d90148b291d74b44c78573c559ceeae0; Thu, 28 Feb 2019 22:20:25 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 67/97] LSM: Make getting the secmark right cleaner with lsm_export_one_secid Date: Thu, 28 Feb 2019 14:19:03 -0800 Message-Id: <20190228221933.2551-68-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Getting the u32 secmark from the result of security_secctx_to_secid() requires knowledge about which LSM interpreted the context. Add a function lsm_export_one_secid() that finds the active secid in a lsm_export structure. Use it in secmark processing. Signed-off-by: Casey Schaufler --- include/linux/security.h | 16 ++++++++++++++++ net/netfilter/nft_meta.c | 7 +------ net/netfilter/xt_SECMARK.c | 7 +------ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index cb5e685f60eb..cb392c6b620f 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -115,6 +115,22 @@ static inline bool lsm_export_equal(struct lsm_export *l, struct lsm_export *m) return true; } +/* + * After calling security_secctx_to_secid() one, and only one + * of the LSM fields will be set in the lsm_export. Return + * whichever one was set. Used to supply secmarks. + */ +static inline u32 lsm_export_one_secid(struct lsm_export *l) +{ + if (l->flags & LSM_EXPORT_SELINUX) + return l->selinux; + if (l->flags & LSM_EXPORT_SMACK) + return l->smack; + if (l->flags & LSM_EXPORT_APPARMOR) + return l->apparmor; + return 0; +} + extern struct lsm_export *lsm_export_skb(struct sk_buff *skb); /* Text representation of LSM specific security information - a "context" */ diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c index ad1aa430f733..1a2b3efc79ee 100644 --- a/net/netfilter/nft_meta.c +++ b/net/netfilter/nft_meta.c @@ -576,12 +576,7 @@ static int nft_secmark_compute_secid(struct nft_secmark *priv) if (err) return err; - /* Use the "best" secid */ - if (le.selinux) - tmp_secid = le.selinux; - else - tmp_secid = le.smack; - + tmp_secid = lsm_export_one_secid(&le); if (!tmp_secid) return -ENOENT; diff --git a/net/netfilter/xt_SECMARK.c b/net/netfilter/xt_SECMARK.c index a06e50535194..b20753957e8d 100644 --- a/net/netfilter/xt_SECMARK.c +++ b/net/netfilter/xt_SECMARK.c @@ -67,12 +67,7 @@ static int checkentry_lsm(struct xt_secmark_target_info *info) return err; } - /* Smack is cheating, using SECMARK_MODE_SEL */ - if (le.selinux) - info->secid = le.selinux; - else - info->secid = le.smack; - + info->secid = lsm_export_one_secid(&le); if (!info->secid) { pr_info_ratelimited("unable to map security context \'%s\'\n", info->secctx); From patchwork Thu Feb 28 22:19: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: 10834035 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 6F3DE1575 for ; Thu, 28 Feb 2019 22:20:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D1532F34F for ; Thu, 28 Feb 2019 22:20:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A6D92FC8A; Thu, 28 Feb 2019 22:20:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E53C32FC8D for ; Thu, 28 Feb 2019 22:20:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731837AbfB1WUd (ORCPT ); Thu, 28 Feb 2019 17:20:33 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:44006 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732256AbfB1WUc (ORCPT ); Thu, 28 Feb 2019 17:20:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392430; bh=f8K6YGqPGEJWPQrpWKi0AaWdcZaQR+kZDh+aYC77/lU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=PAG1H4wKoMG8Osa1g+zxlqUsFqNXI084BCXfD5A47sBae6z5o3WDHdIUIUHWzWaw/nvnnJ8CBrEBshW3z6qTSoHDFgtL4wHegauzYBl6uaUy61EvETNuAAGNe1OcIfhKPDCIgXAeTFjU2cgHc5onJf0vxkP3aFNLi4sGRUUBUHRZP6ppxLlDEVW5TlHO0FUZcfiTlWHOne9l3qVj1gg2VS++avUGnCKBDn1JQsEiGPNtjg03OxMZLwcB3btUAOMDWMtpKOZjDNETHGTrwGZM37VBR6UPxTlcRCUPF5hK4nj/h6zzmnSdIwMiPlUvB022KeRCbWsIa77x9hFFJ2jNzA== X-YMail-OSG: NIHGviAVM1k8Ja7rtJtis2va7pFFTLxvIC9H0QuqFnBC8d25AFW72CElcjX..it 272W5Xr.IkFiRb__eWl0IQUXQSqiASAXa4L3lYRmeHSVjrrRBpT3xnu4b7BwpOTDBBPxVspomASg _C4tyiMGefYhQXJkmdZF1MLBGaveLAzwd3kA8psCmUGHeth6RWerwB9C92rvvkWmTaS0Nv9enRm0 CmNixM7opJ7aSrAigXNWM5Fb.nWlneQaH626e6PRi4NNYAF_CMmj6G7_Ze2qd2gadQjen8xmt7Ln eOjyyS4TH2xjgtyeA4VrmMoX8SKMsEYj2r1YJ3vipuZMPvyu.dvkeDlyIZLONgOK3wk_yphgTY9J zcYrmsicLCR5g6pV1YQfd0jzKerskdP68by9IXq6oauVTXfhrZOAR2r71jrRPN5jGA2Pak4pogNz jyKOb3yhn4qH8G_huIi9CshevhicZ6sn88IiL9nQxXERGrg.AMXXEGS17OXeTwDTeiQ9IGqixbGW QjogGB_CMNFJ45VqFT02Kua3WuBCAOqzEygGCdiJl4PKGtfGIMavzoBPclPgpGZa3.JFjZ1HohLY p6TLbkgLbHDX33QC2zVnP0Co6O9_2_Hwh3In2pHZC5VPP5WIJpjbCShIsxt.fknP5krRRJFw2Dja iLoXjH53Miu4HZbWZZKfd8bT0Ny9tu1sszVBx7dR0_YAFP9860elg0VzK1rVmtv9r1tbJoPP4OHL 5WJu0QsPxxARhlZhRf3El6e9JIu06xXJTv5WY265a9qOhtOQOXWJCwu6Me8FtPyGJzmpSKxG36qz eJ.Gkd86ZyI67J.IVd_6jZFjFHG_fppakYgOn2vBhxul6Bo.tcYwqg9XNfoJ7p.UgGRGLOoa3w6s L.xcNGHMfiNTYgKnT0TY9G2htgOiHugDvsaTCwLhF7bBbcFBAa7mh41bJIWQVOV_lwGI9hhveeV2 huP_.R2IDo3JXBwbrM8WWgCI1FX8rvkh08rkVTGvI._NhvpG0Om1uYsOuJr0L9nOW8D96lOt.8q7 Ot4dnCqc80M3LBA.a3C8qQ6XfkyXgDPAZ6uThUJB_H03cUC9aF09IL0G6Q16mguohP1qyqh3JKWQ 43IQT9RDtEEE4lSVcjCUDmTV0OPFug0NXl7yKXCnbKjrLvM7ZC9xQmwB4uw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:30 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp421.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d90148b291d74b44c78573c559ceeae0; Thu, 28 Feb 2019 22:20:26 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 68/97] netfilter: Fix memory leak introduced with lsm_context Date: Thu, 28 Feb 2019 14:19:04 -0800 Message-Id: <20190228221933.2551-69-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix a memory leak introduced by the scaffolding around the introduction of lsm_context structures. Signed-off-by: Casey Schaufler --- net/netfilter/nfnetlink_queue.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index 4a3d4b52caef..7a095b9d0a10 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c @@ -305,14 +305,13 @@ static int nfqnl_put_sk_uidgid(struct sk_buff *skb, struct sock *sk) return -1; } -static u32 nfqnl_get_sk_secctx(struct sk_buff *skb, char **secdata) +static void nfqnl_get_sk_secctx(struct sk_buff *skb, struct lsm_context *cp) { #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; + return; read_lock_bh(&skb->sk->sk_callback_lock); @@ -322,14 +321,10 @@ 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); - *secdata = lc.context; + security_secid_to_secctx(&le, cp); } read_unlock_bh(&skb->sk->sk_callback_lock); - return lc.len; -#else - return 0; #endif } @@ -406,7 +401,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; - struct lsm_context lc = { .context = NULL, }; + struct lsm_context lc; size = nlmsg_total_size(sizeof(struct nfgenmsg)) + nla_total_size(sizeof(struct nfqnl_msg_packet_hdr)) @@ -472,7 +467,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, } if ((queue->flags & NFQA_CFG_F_SECCTX) && entskb->sk) { - lc.len = nfqnl_get_sk_secctx(entskb, &lc.context); + nfqnl_get_sk_secctx(entskb, &lc); if (lc.len) size += nla_total_size(lc.len); } @@ -635,8 +630,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, } nlh->nlmsg_len = skb->len; - if (lc.context) - security_release_secctx(&lc); + security_release_secctx(&lc); return skb; nla_put_failure: From patchwork Thu Feb 28 22:19: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: 10834045 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 4FFD118B7 for ; Thu, 28 Feb 2019 22:20:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 444F62F2CB for ; Thu, 28 Feb 2019 22:20:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38F422F35C; Thu, 28 Feb 2019 22:20: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DED52FC98 for ; Thu, 28 Feb 2019 22:20:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731967AbfB1WUe (ORCPT ); Thu, 28 Feb 2019 17:20:34 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:46564 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732266AbfB1WUc (ORCPT ); Thu, 28 Feb 2019 17:20:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392430; bh=EAfxIxB1ZvUzLgH0PH4QuaL8hGRSOCB+7KrFozqHypw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=aiy9EhC64PVjnA/yvwvLHORvgNxP8Ad+yPy3mJ8fxbr/JdvWH+Dy9mxB2FgXhg2XGzN0olduGsSkiiJbj41FGhBM3SMeV650DZ1qDk1PQHx5dP5FeL2Aub9wkdgycCaUuWz5DG5G5xxH+rBwHrXeAonmhC8O/bqkQ2D+MjCeq4xLfgdNRXSdOyycjM4ch1KCozXiiXgI5dZ5GY9Ot/r+YMsEC0is86amFOu9qxi9Po+glxfMqVFhrlwxHWW/b+44eHjNiUTuNExmdyUuMsIP0ilJbIzbCTSk4KhCgW2kKweYOHyH38finWejjrD190TfZXiHseB5abLIIHzzNOcCHg== X-YMail-OSG: sFe2TPUVM1m8vic1V9bjXZ.sBSCRF.Besdk7AQqWp53nfPhzvCkkUJLuS7HbbYh vDeWwm1kvrvuK98zEUJ.97khEYez2Pc_ZYZzwMMS1jC.aXczy.dn5R9.vZ9edTlksC2DUSkIKx6b yo7U3LYPx5y2VeycTgUj8FAuRloY9Gfad3wKji3wxUgm9j_mDZWoH6dwLp6aEQYh7arL7RUu2HE. nvrq.AW6X.ZjD.jSsOFkLTIXrXgQfYqe9YrMIGFmvuraOSelQ0lHlyMWvvmJVXtjOo36RdXS_DXe jn0w7W21LJA79Eajzwhrp9u6_Hlm5k5j3bvpjyxDrhWzSA.PVtg5ffdNE5TRc454rZ3b3KQWVfYy uASE8JslFsLsml6AoKGalLFx5YzS8IxaCLAQgXHqhY.3DGPdkjzvSjwmWy77ttc24aCXI5mMGMNP 4S6JcjWiFVjk.TKK8QZDNZm1sTIDIrWDOKjD4SnBC4jdVrjflf1AuSP3BivA.OPPkXXnnD9AUAnS mJnUYD_34moqsWs_iUkCTzy1h7BUQZq25USgqJYpkk.Hfe5CphM99j39FShuoCKTvgOlzjpP_7gs aOExTqsV_.487SptbNQhTi0J9ZE_Pq44CEzFnivz_kOWR2u.IfcWxl2ZpvQydGTsLfiU0XYYUl61 MHbmcOlMzs.QwVwaSiXKQws1BCwDX3VPry6GQVX.TrAW4W275GyrBzBinMZJ2._RGGlA28evb_7l Mt5AhJC1MqrVnDK0pgcMdX0MgZq7hZ5uAvB04JKt0PUupeLfO6Wv1olZJibXWiwx.R0q3OFQittR ._v5ZGR553181rizHKwTCtqV9huPjmSTyDlMTZ7OEm.N_US0RtMsgyUwnV3m9B0KGVw0SlKw7C2L RpXnVCseN42WT4qgCXa1bn0BbYL4hcgT274S2EM.esnEKnVeQACvlZTS61eV75uGGiSTxWRPRqWT 5XpRo.OpaK7ivH2cIUAGwxzKSQ8brFiqvCCMjLQafvw3QQHT4g0oJfKcEEIvbjivLAsub0zUmH7s bvrKBLqRfMWQ5Ftf4d7yFMpqgujOCMoYHFgVytNnhsF6Wpwwqx.167jU88bB_OWl__MsZ5bVgY93 fG1M.nU40F3_9PYJ.2LJZHy10Pyjer3GQvqjFIhsYiG1EtTk- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:30 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp421.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d90148b291d74b44c78573c559ceeae0; Thu, 28 Feb 2019 22:20:26 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 69/97] Smack: Consolidate secmark conversions Date: Thu, 28 Feb 2019 14:19:05 -0800 Message-Id: <20190228221933.2551-70-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a helper function smack_from_skb() that does all the checks required and maps a valid secmark to a smack_known structure. Replace the direct use of the secmark in surrounding code. Signed-off-by: Casey Schaufler --- security/smack/smack_lsm.c | 39 ++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index d3ec5f49ef44..7b8ad16c09e0 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -3734,6 +3734,20 @@ static int smk_skb_to_addr_ipv6(struct sk_buff *skb, struct sockaddr_in6 *sip) } #endif /* CONFIG_IPV6 */ +/** + * smack_from_skb - Smack data from the secmark in an skb + * @skb: packet + * + * Returns smack_known of the secmark or NULL if that won't work. + */ +static struct smack_known *smack_from_skb(struct sk_buff *skb) +{ + if (skb == NULL || skb->secmark == 0) + return NULL; + + return smack_from_secid(skb->secmark); +} + /** * smack_socket_sock_rcv_skb - Smack packet delivery access check * @sk: socket @@ -3768,10 +3782,9 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) * If there is no secmark fall back to CIPSO. * The secmark is assumed to reflect policy better. */ - if (skb && skb->secmark != 0) { - skp = smack_from_secid(skb->secmark); + skp = smack_from_skb(skb); + if (skp) goto access_check; - } #endif /* CONFIG_SECURITY_SMACK_NETFILTER */ /* * Translate what netlabel gave us. @@ -3814,9 +3827,8 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) proto != IPPROTO_TCP && proto != IPPROTO_DCCP) break; #ifdef SMACK_IPV6_SECMARK_LABELING - if (skb && skb->secmark != 0) - skp = smack_from_secid(skb->secmark); - else + skp = smack_from_skb(skb); + if (skp == NULL) skp = smack_ipv6host_label(&sadd); if (skp == NULL) skp = smack_net_ambient; @@ -3917,9 +3929,11 @@ static int smack_socket_getpeersec_dgram(struct socket *sock, break; case PF_INET: #ifdef CONFIG_SECURITY_SMACK_NETFILTER - s = skb->secmark; - if (s != 0) + skp = smack_from_skb(skb); + if (skp) { + s = skp->smk_secid; break; + } #endif /* * Translate what netlabel gave us. @@ -3936,7 +3950,9 @@ static int smack_socket_getpeersec_dgram(struct socket *sock, break; case PF_INET6: #ifdef SMACK_IPV6_SECMARK_LABELING - s = skb->secmark; + skp = smack_from_skb(skb); + if (skp) + s = skp->smk_secid; #endif break; } @@ -4014,10 +4030,9 @@ static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb, * If there is no secmark fall back to CIPSO. * The secmark is assumed to reflect policy better. */ - if (skb && skb->secmark != 0) { - skp = smack_from_secid(skb->secmark); + skp = smack_from_skb(skb); + if (skp) goto access_check; - } #endif /* CONFIG_SECURITY_SMACK_NETFILTER */ netlbl_secattr_init(&secattr); From patchwork Thu Feb 28 22:19: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: 10834039 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 0E391188E for ; Thu, 28 Feb 2019 22:20:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0068C2A62A for ; Thu, 28 Feb 2019 22:20:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8C152FC94; Thu, 28 Feb 2019 22:20:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91FE92A62A for ; Thu, 28 Feb 2019 22:20:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732195AbfB1WUd (ORCPT ); Thu, 28 Feb 2019 17:20:33 -0500 Received: from sonic309-27.consmr.mail.gq1.yahoo.com ([98.137.65.153]:43330 "EHLO sonic309-27.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732199AbfB1WUc (ORCPT ); Thu, 28 Feb 2019 17:20:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1551392430; bh=KFOiqmYPHUmlyvGrhA826bf8EqEN7bZYPDEB3JWKNcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=KI6gA2Z02+q0XLsgNxalO73ZEAKfU+H0kLPBe84KFQ/tcfiz7gevQFybth4U04ecq+hR37LQFBVhphCMZQok6Dj3iMZs5d1gcWh2fLDSEdR8+3TJFrtUI+tlpu+VQ2bXyzDlQ3B1gckqPwsQofIB7TySFm+DKuSd/TiLX1Xco93TF/WzDEoAkOtpz92nKDEYzvtHZ6p/y4GpG10htvS/ReOsmLo4aTNapV0dm6qI4uKjFPoALahQKShwbta6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QsM5RP71LPaP 5N4eFeFRY7QvgpFfJ46jF.kVzV316cgmCiwfSpRjfbOfX5m6WidNNuItBDhY8NNejARY3HjSQFKT tLbp.ateQ7wLFgY94tLgTW9sg8rH8CNjZPfKzkROaRK2jJg7HyHlpI03.diVyv_UO2CovGJdzkVX ug0W1z9l9QvJf73HCO.8JRw91sgPZkjcWnkKGWOIjb93.13dKUiKsHMATLFg- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.gq1.yahoo.com with HTTP; Thu, 28 Feb 2019 22:20:30 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([67.169.65.224]) by smtp404.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 4ed72522ccf44343c47df9c8f8a3f798; Thu, 28 Feb 2019 22:20:28 +0000 (UTC) From: Casey Schaufler To: jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com Subject: [PATCH 70/97] netfilter: Remove unnecessary NULL check in lsm_context Date: Thu, 28 Feb 2019 14:19:06 -0800 Message-Id: <20190228221933.2551-71-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190228221933.2551-1-casey@schaufler-ca.com> References: <20190228221933.2551-1-casey@schaufler-ca.com> Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is a redundant NULL check when releasing a security context. Remove it. Signed-off-by: Casey Schaufler --- net/netfilter/nfnetlink_queue.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index 7a095b9d0a10..83bb44d70582 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c @@ -638,8 +638,7 @@ 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 (lc.context) - security_release_secctx(&lc); + security_release_secctx(&lc); return NULL; }