From patchwork Fri May 31 23:10: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: 10970933 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 4A2CB912 for ; Fri, 31 May 2019 23:17:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 386BA28A14 for ; Fri, 31 May 2019 23:17:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CC0E28D92; Fri, 31 May 2019 23:17:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEA3D28A14 for ; Fri, 31 May 2019 23:17:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726728AbfEaXRI (ORCPT ); Fri, 31 May 2019 19:17:08 -0400 Received: from sonic303-9.consmr.mail.bf2.yahoo.com ([74.6.131.48]:36982 "EHLO sonic303-9.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726787AbfEaXRI (ORCPT ); Fri, 31 May 2019 19:17:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1559344627; bh=zNmMomX7FtNuYn5Qpm3pclNFmgRY9BLATnDH4/IPw8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From: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Ut8YmS2L5zYn2BnGnSAAXhHq6Xx zeYUF4Qb93n4bSjUnjaqqCde9gtCdd9_tAN445z_FzmSTT8TWwUWGHcQCSekKDkXTen5KH4BJQ5N vZ1xHRvXTzMmER6BKfbevlmHD89j9NJqS8eHmtKoDYsZ9sjrv1AlFlMLIsDUNm9rNTREgpnUP9Er YRRFScUbgyVTe0YgEYbOndOQakxYJiIEVx8RkHzrySOZy7o6TK7K41atyopAY2Ba3TfAiEAkdnqS D.lpb8fzF8hqQ5CWi5cNNzC0hqS5.JV67rL5e6DG4aitXGW.Ln95Er5VAs.BgmdPfYQd0zl4R0N1 hgQiuApO9BntzgzeEdXnrIx9516BHP.u.ujB.pRRiGHF9OQxuVLZ01wIunzRAv3LM3woNVMlHweQ EnWKsIOeXfFwAHmAi356v4yf8ss_I8E7psj9wLcOLtGYZZssm9TXoWa2jtvb02lTGwvEVl2VvlVY 4n_BisU6zOLis8_vT5hY2FllyzZOzS0tGDC6dlDdmOwHEjhZ1N6kGwq8QcPK9.iWT4irHCcYF77h URDyWK4MuhtAFD6Sx8ayYEZkYptpDky1y2Yi63GXK8fNb_T2Q1_YTgqU- Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.bf2.yahoo.com with HTTP; Fri, 31 May 2019 23:17:07 +0000 Received: from c-73-223-4-185.hsd1.ca.comcast.net (EHLO localhost.localdomain) ([73.223.4.185]) by smtp407.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID ecbeeaf97d7184c0d421bbd47d8c0363; Fri, 31 May 2019 23:17:04 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov Subject: [PATCH 39/58] LSM: Use lsm_context in inode_getsecctx hooks Date: Fri, 31 May 2019 16:10:01 -0700 Message-Id: <20190531231020.628-40-casey@schaufler-ca.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190531231020.628-1-casey@schaufler-ca.com> References: <20190531231020.628-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 | 11 +++++++++-- security/selinux/hooks.c | 6 +++--- security/smack/smack_lsm.c | 6 +++--- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index c983d573a005..20e59e0b775f 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1394,11 +1394,10 @@ * @ctxlen contains the length of @ctx. * * @inode_getsecctx: - * On success, returns 0 and fills out @ctx and @ctxlen with the security + * On success, returns 0 and fills out @cp with the security * context for the given @inode. * @inode we wish to get the security context of. - * @ctx is a pointer in which to place the allocated security context. - * @ctxlen points to the place to put the length of @ctx. + * @cp is a pointer in which to place the allocated security context. * * Security hooks for using the eBPF maps and programs functionalities through * eBPF syscalls. @@ -1671,7 +1670,7 @@ union security_list_options { void (*inode_invalidate_secctx)(struct inode *inode); int (*inode_notifysecctx)(struct inode *inode, void *ctx, u32 ctxlen); int (*inode_setsecctx)(struct dentry *dentry, void *ctx, u32 ctxlen); - int (*inode_getsecctx)(struct inode *inode, void **ctx, u32 *ctxlen); + int (*inode_getsecctx)(struct inode *inode, struct lsm_context *cp); #ifdef CONFIG_SECURITY_NETWORK int (*unix_stream_connect)(struct sock *sock, struct sock *other, diff --git a/security/security.c b/security/security.c index 84f27428b62d..0c23ffdd92c9 100644 --- a/security/security.c +++ b/security/security.c @@ -1992,7 +1992,7 @@ int security_secctx_to_secid(const char *secdata, u32 seclen, { struct lsm_context lc; - lc.context = secdata; + lc.context = (char *)secdata; lc.len = seclen; lsm_export_init(l); return call_one_int_hook(secctx_to_secid, 0, &lc, l); @@ -2025,7 +2025,14 @@ EXPORT_SYMBOL(security_inode_setsecctx); int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) { - return call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, ctx, ctxlen); + struct lsm_context lc = { .context = NULL, .len = 0, }; + int rc; + + rc = call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, &lc); + + *ctx = (void *)lc.context; + *ctxlen = lc.len; + return rc; } EXPORT_SYMBOL(security_inode_getsecctx); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index a2257ccaee5c..e881f42d3ff8 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6355,14 +6355,14 @@ static int selinux_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) return __vfs_setxattr_noperm(dentry, XATTR_NAME_SELINUX, ctx, ctxlen, 0); } -static int selinux_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) +static int selinux_inode_getsecctx(struct inode *inode, struct lsm_context *cp) { int len = 0; len = selinux_inode_getsecurity(inode, XATTR_SELINUX_SUFFIX, - ctx, true); + (void **)&cp->context, true); if (len < 0) return len; - *ctxlen = len; + cp->len = len; return 0; } #ifdef CONFIG_KEYS diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 78c01ef707eb..46eead699e1d 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4484,12 +4484,12 @@ static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) return __vfs_setxattr_noperm(dentry, XATTR_NAME_SMACK, ctx, ctxlen, 0); } -static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) +static int smack_inode_getsecctx(struct inode *inode, struct lsm_context *cp) { struct smack_known *skp = smk_of_inode(inode); - *ctx = skp->smk_known; - *ctxlen = strlen(skp->smk_known); + cp->context = skp->smk_known; + cp->len = strlen(skp->smk_known); return 0; }