Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3501852iog; Mon, 27 Jun 2022 18:11:09 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uI5PhMsbv1rcxIeGcT3ukTYbsSBSJZsO1FDeDv9PYHL0C/gBQyjgIJofgrmS6/EEG/DlTc X-Received: by 2002:a17:906:7a54:b0:722:ecd7:10c4 with SMTP id i20-20020a1709067a5400b00722ecd710c4mr14912234ejo.693.1656378668822; Mon, 27 Jun 2022 18:11:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656378668; cv=none; d=google.com; s=arc-20160816; b=WVkkg1h+s3E1WbowfDcTtKn7FmnUkBX6AyOAn4nQkRmlYdP7Is528njhVZIkrcXKX8 /6kEM4TC4E+TO80UHrsNqt+coRX9dngneVmqpG6H223hWrdsJF3mLyd/aRr4hkhf+LhP pHpgIAuXEqEbhUpHG9o9HSReP2vA84xmtztUwYzVyVJFU0VzkcDWSsZdWyKAWyPDoWhF JxE5Pv/kgYq2e5naVMvXHi/UUknNV5QyDiMwmIiGQCt8qfunG7P+9eaMxTt+3i2PZOUp qv5kFn1VPOu97Xgs877O4pp1/2vkKeEu/IOLQG+R10Ycub9WPiGu+jNG4F3iCxSNj0nt TrTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FN94LEWzwUDDYtALZrFGtv3Fq1k9e81NgNZU/g6SJyc=; b=JEyUM5rD5cL82uuSOi+76gLzuqlpEasyqQBtLLp1d5GjxnQLWqbtcPgmV+OIJ2cRfv Z0bV339kJC5L40rPCkihD0E7bAIvRQe3W91fGPSDqpCqXnog/Bp4+xrQLiGZncSkde9A C2y+TmEw3ROquxjAUJ8n6YzsjRMY+Zq8VWHbKLiBvzmHIdeeILYZgXeXy0RC7TE6E9ta C74FK9a20WHkrD0YE4Af/hKCMvzUGQ+KtTQYx0ZZMIVplJln6fch97xJFClxpxWc+uy8 6XNXAfzMdxoQutjAexbJoDmNVqEdiFKguIapYk/+ul/8VNX3Jh/3u0UC38Ql3qB/WRP9 Ggng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=MANiyw22; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f19-20020a056402161300b0043582813da8si13702159edv.500.2022.06.27.18.10.44; Mon, 27 Jun 2022 18:11:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=MANiyw22; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242864AbiF1BIF (ORCPT + 99 others); Mon, 27 Jun 2022 21:08:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242899AbiF1BHW (ORCPT ); Mon, 27 Jun 2022 21:07:22 -0400 Received: from sonic302-26.consmr.mail.ne1.yahoo.com (sonic302-26.consmr.mail.ne1.yahoo.com [66.163.186.152]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85FEF205EB for ; Mon, 27 Jun 2022 18:07:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1656378440; bh=FN94LEWzwUDDYtALZrFGtv3Fq1k9e81NgNZU/g6SJyc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=MANiyw22EhfLWbwhyqCW4KjrClAoFR8epQ/SBuw94qw/oQf6cVgxRhBC1NwswLY5Vz3qsLgY/yXu/tqE0DCetJMu2JdEuE/LWEhi30HHcFrxdlef0w48CoY2Da81ze/KHJp8OhAq/mb4wbdueUi3eIcpxUB3p+M7I7o8rYXnjsHJivvYpWw/4JlsZt/sRJHECz66NE54hzHubw1CIF0cXhgyXpXqB+gHK+bdKgMBGt/vNLgOWDMqW+Ec9VInCInZyOmgnYcljBNmSC6pXDMChPahg6WPAuzmK0aU2JyWGk5yPe8bAkuaPHxBm1b9Wl2xAA9xEigSUWZ6nMky9xp/Pg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1656378440; bh=PYmmTdTxxHW7kUJqiEbzlTal8wzsRZE9Hh+8i/+6owp=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=J8fZ7WJCb9Je4gkOv0PZMV4s4iIZLTQb49M7ir5EFhWYdtYQbSxdbNofOqFyc57CPTzQTuGfmZmU2McCpIvVea5IKqyZ2ItCIuF6n01j9yhoXtz4X41cNbosyryui1iPqjTsVTHTZiDQSDKN3LNMI+TFlMpNtOGSem2QRjlG2UZBj0ABpRnpiy45r5VLkRxxI1igJgeNvEsZPTzKYekx6nh9SYQNu475jViBx5ZSzyLrEDcxKR7s8euOqF2ws6l7gzOmvlaipPph16jx8TaaDkaB7F7x5JWllTSB9pp7m1InZIBc/6c6/rAfUqg59SfbsCsQuOhpUY3IKjpcsqycsA== X-YMail-OSG: 4qknKVYVM1lxC1E1LYGsrZ3EESCczJB2g4cY1QZQ0kOTanuzq4onJeFYSUgCBF3 dtmeZntkAWW_JPWYDE3oGeqyg27g2l99ffTr51lsYRNJ44JCctaMyxTdoTtKxYNR7EyjOnkoEHU6 vEqnZGKv7cn11HqDCapAcK82W1atxCV0uWAfr7cAcvNpYPZietC7lpJo6pCEZsR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: Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.ne1.yahoo.com with HTTP; Tue, 28 Jun 2022 01:07:20 +0000 Received: by hermes--production-ne1-7459d5c5c9-fdkvw (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 2b15a6d5cfb14c238c7aa5ef58eb279b; Tue, 28 Jun 2022 01:07:16 +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, linux-audit@redhat.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, stephen.smalley.work@gmail.com, linux-kernel@vger.kernel.org, Chuck Lever , linux-nfs@vger.kernel.org Subject: [PATCH v37 17/33] LSM: Use lsmcontext in security_inode_getsecctx Date: Mon, 27 Jun 2022 17:55:55 -0700 Message-Id: <20220628005611.13106-18-casey@schaufler-ca.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220628005611.13106-1-casey@schaufler-ca.com> References: <20220628005611.13106-1-casey@schaufler-ca.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Change the security_inode_getsecctx() interface to fill a lsmcontext structure instead of data and length pointers. This provides the information about which LSM created the context so that security_release_secctx() can use the correct hook. Acked-by: Stephen Smalley Acked-by: Paul Moore Acked-by: Chuck Lever Reviewed-by: Kees Cook Reviewed-by: John Johansen Signed-off-by: Casey Schaufler Cc: linux-nfs@vger.kernel.org --- fs/nfsd/nfs4xdr.c | 23 +++++++++-------------- include/linux/security.h | 5 +++-- security/security.c | 13 +++++++++++-- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 512ad208d62a..3e42738df71a 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -2713,11 +2713,11 @@ nfsd4_encode_layout_types(struct xdr_stream *xdr, u32 layout_types) #ifdef CONFIG_NFSD_V4_SECURITY_LABEL static inline __be32 nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp, - void *context, int len) + struct lsmcontext *context) { __be32 *p; - p = xdr_reserve_space(xdr, len + 4 + 4 + 4); + p = xdr_reserve_space(xdr, context->len + 4 + 4 + 4); if (!p) return nfserr_resource; @@ -2727,13 +2727,13 @@ nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp, */ *p++ = cpu_to_be32(0); /* lfs */ *p++ = cpu_to_be32(0); /* pi */ - p = xdr_encode_opaque(p, context, len); + p = xdr_encode_opaque(p, context->context, context->len); return 0; } #else static inline __be32 nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp, - void *context, int len) + struct lsmcontext *context) { return 0; } #endif @@ -2830,9 +2830,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, int err; struct nfs4_acl *acl = NULL; #ifdef CONFIG_NFSD_V4_SECURITY_LABEL - struct lsmcontext scaff; /* scaffolding */ - void *context = NULL; - int contextlen; + struct lsmcontext context = { }; #endif bool contextsupport = false; struct nfsd4_compoundres *resp = rqstp->rq_resp; @@ -2893,7 +2891,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) { if (exp->ex_flags & NFSEXP_SECURITY_LABEL) err = security_inode_getsecctx(d_inode(dentry), - &context, &contextlen); + &context); else err = -EOPNOTSUPP; contextsupport = (err == 0); @@ -3320,8 +3318,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, #ifdef CONFIG_NFSD_V4_SECURITY_LABEL if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) { - status = nfsd4_encode_security_label(xdr, rqstp, context, - contextlen); + status = nfsd4_encode_security_label(xdr, rqstp, &context); if (status) goto out; } @@ -3342,10 +3339,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, out: #ifdef CONFIG_NFSD_V4_SECURITY_LABEL - if (context) { - lsmcontext_init(&scaff, context, contextlen, 0); /*scaffolding*/ - security_release_secctx(&scaff); - } + if (context.context) + security_release_secctx(&context); #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ kfree(acl); if (tempfh) { diff --git a/include/linux/security.h b/include/linux/security.h index 5afd0148a1a5..ca2ed1909608 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -624,7 +624,7 @@ void security_release_secctx(struct lsmcontext *cp); void security_inode_invalidate_secctx(struct inode *inode); int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen); 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 lsmcontext *cp); int security_locked_down(enum lockdown_reason what); #else /* CONFIG_SECURITY */ @@ -1500,7 +1500,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 lsmcontext *cp) { return -EOPNOTSUPP; } diff --git a/security/security.c b/security/security.c index b52c7c55a092..72df3d0cd233 100644 --- a/security/security.c +++ b/security/security.c @@ -2428,9 +2428,18 @@ 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 lsmcontext *cp) { - return call_int_hook(inode_getsecctx, -EOPNOTSUPP, inode, ctx, ctxlen); + struct security_hook_list *hp; + + memset(cp, 0, sizeof(*cp)); + + hlist_for_each_entry(hp, &security_hook_heads.inode_getsecctx, list) { + cp->slot = hp->lsmid->slot; + return hp->hook.inode_getsecctx(inode, (void **)&cp->context, + &cp->len); + } + return -EOPNOTSUPP; } EXPORT_SYMBOL(security_inode_getsecctx); -- 2.36.1