From: Paul Moore <paul@paul-moore.com>
To: Stephen Smalley <stephen.smalley.work@gmail.com>
Cc: Casey Schaufler <casey@schaufler-ca.com>,
linux-security-module@vger.kernel.org, jmorris@namei.org,
serge@hallyn.com, keescook@chromium.org,
john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp,
linux-kernel@vger.kernel.org, selinux@vger.kernel.org,
mic@digikod.net, ceph-devel@vger.kernel.org,
linux-nfs@vger.kernel.org
Subject: Re: [PATCH v3 4/5] LSM: lsm_context in security_dentry_init_security
Date: Thu, 20 Feb 2025 12:53:54 -0500 [thread overview]
Message-ID: <CAHC9VhQUUOqh3j9mK5eaVOc6H7JXsjH8vajgrDOoOGOBTszWQw@mail.gmail.com> (raw)
In-Reply-To: <CAHC9VhSSpLx=ku7ZJ7qVxHHyOZZPQWs_hoxVRZpTfhOJ=T2X9w@mail.gmail.com>
On Thu, Feb 20, 2025 at 12:40 PM Paul Moore <paul@paul-moore.com> wrote:
> On Thu, Feb 20, 2025 at 11:43 AM Stephen Smalley
> <stephen.smalley.work@gmail.com> wrote:
> > On Wed, Oct 23, 2024 at 5:23 PM Casey Schaufler <casey@schaufler-ca.com> wrote:
> > >
> > > Replace the (secctx,seclen) pointer pair with a single lsm_context
> > > pointer to allow return of the LSM identifier along with the context
> > > and context length. This allows security_release_secctx() to know how
> > > to release the context. Callers have been modified to use or save the
> > > returned data from the new structure.
> > >
> > > Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
> > > Cc: ceph-devel@vger.kernel.org
> > > Cc: linux-nfs@vger.kernel.org
> > > ---
> > > fs/ceph/super.h | 3 +--
> > > fs/ceph/xattr.c | 16 ++++++----------
> > > fs/fuse/dir.c | 35 ++++++++++++++++++-----------------
> > > fs/nfs/nfs4proc.c | 20 ++++++++++++--------
> > > include/linux/lsm_hook_defs.h | 2 +-
> > > include/linux/security.h | 26 +++-----------------------
> > > security/security.c | 9 ++++-----
> > > security/selinux/hooks.c | 9 +++++----
> > > 8 files changed, 50 insertions(+), 70 deletions(-)
> > >
> >
> > > diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
> > > index 76776d716744..0b116ef3a752 100644
> > > --- a/fs/nfs/nfs4proc.c
> > > +++ b/fs/nfs/nfs4proc.c
> > > @@ -114,6 +114,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 shim;
> > > int err;
> > >
> > > if (label == NULL)
> > > @@ -128,21 +129,24 @@ nfs4_label_init_security(struct inode *dir, struct dentry *dentry,
> > > label->label = NULL;
> > >
> > > err = security_dentry_init_security(dentry, sattr->ia_mode,
> > > - &dentry->d_name, NULL,
> > > - (void **)&label->label, &label->len);
> > > - if (err == 0)
> > > - return label;
> > > + &dentry->d_name, NULL, &shim);
> > > + if (err)
> > > + return NULL;
> > >
> > > - return NULL;
> > > + label->label = shim.context;
> > > + label->len = shim.len;
> > > + return label;
> > > }
> > > static inline void
> > > nfs4_label_release_security(struct nfs4_label *label)
> > > {
> > > - struct lsm_context scaff; /* scaffolding */
> > > + struct lsm_context shim;
> > >
> > > if (label) {
> > > - lsmcontext_init(&scaff, label->label, label->len, 0);
> > > - security_release_secctx(&scaff);
> > > + shim.context = label->label;
> > > + shim.len = label->len;
> > > + shim.id = LSM_ID_UNDEF;
> >
> > Is there a patch that follows this one to fix this? Otherwise, setting
> > this to UNDEF causes SELinux to NOT free the context, which produces a
> > memory leak for every NFS inode security context. Reported by kmemleak
> > when running the selinux-testsuite NFS tests.
>
> I don't recall seeing anything related to this, but patches are
> definitely welcome.
Looking at this quickly, this is an interesting problem as I don't
believe we have enough context in nfs4_label_release_security() to
correctly set the shim.id value. If there is a positive, it is that
lsm_context is really still just a string wrapped up with some
metadata, e.g. length/ID, so we kfree()'ing shim.context is going to
be okay-ish, at least for the foreseeable future.
I can think of two ways to fix this, but I'd love to hear other ideas too.
1. Handle the LSM_ID_UNDEF case directly in security_release_secctx()
and skip any individual LSM processing.
2. Define a new LSM_ID_ANY value and update all of the LSMs to also
process the ANY case as well as their own.
I'm not finding either option very exciting, but option #2 looks
particularly ugly, so I think I'd prefer to see someone draft a patch
for option #1 assuming nothing better is presented.
--
paul-moore.com
next prev parent reply other threads:[~2025-02-20 17:54 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20241023212158.18718-1-casey.ref@schaufler-ca.com>
2024-10-23 21:21 ` [PATCH v3 0/5] LSM: Replace secctx/len pairs with lsm_context Casey Schaufler
2024-10-23 21:21 ` [PATCH v3 1/5] LSM: Ensure the correct LSM context releaser Casey Schaufler
2024-10-31 22:53 ` Paul Moore
2024-12-06 20:05 ` Kees Bakker
2024-12-06 20:57 ` Casey Schaufler
2024-10-23 21:21 ` [PATCH v3 2/5] LSM: Replace context+len with lsm_context Casey Schaufler
2024-10-24 16:10 ` Pablo Neira Ayuso
2024-10-24 17:57 ` Casey Schaufler
2024-10-31 22:53 ` Paul Moore
2024-10-31 23:15 ` Pablo Neira Ayuso
2024-10-31 23:23 ` Pablo Neira Ayuso
2024-10-31 23:58 ` Casey Schaufler
2024-11-01 7:25 ` Pablo Neira Ayuso
2024-11-01 16:14 ` Casey Schaufler
2024-11-01 16:35 ` Paul Moore
2024-11-01 16:42 ` Paul Moore
2024-11-01 16:59 ` Casey Schaufler
2024-11-01 17:54 ` Paul Moore
2024-10-23 21:21 ` [PATCH v3 3/5] LSM: Use lsm_context in security_inode_getsecctx Casey Schaufler
2024-10-31 22:53 ` Paul Moore
2024-10-23 21:21 ` [PATCH v3 4/5] LSM: lsm_context in security_dentry_init_security Casey Schaufler
2024-10-31 22:53 ` Paul Moore
2025-02-20 16:43 ` Stephen Smalley
2025-02-20 17:40 ` Paul Moore
2025-02-20 17:52 ` Casey Schaufler
2025-02-20 17:53 ` Paul Moore [this message]
2025-02-20 18:02 ` Stephen Smalley
2025-02-20 18:15 ` Casey Schaufler
2025-02-20 18:16 ` Stephen Smalley
2025-02-20 19:33 ` Casey Schaufler
2025-02-20 19:37 ` Stephen Smalley
2025-02-20 20:31 ` Casey Schaufler
2025-02-20 20:33 ` Stephen Smalley
2025-02-20 21:08 ` Casey Schaufler
2025-02-21 3:16 ` Paul Moore
2024-10-23 21:21 ` [PATCH v3 5/5] LSM: secctx provider check on release Casey Schaufler
2024-10-31 22:53 ` Paul Moore
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAHC9VhQUUOqh3j9mK5eaVOc6H7JXsjH8vajgrDOoOGOBTszWQw@mail.gmail.com \
--to=paul@paul-moore.com \
--cc=casey@schaufler-ca.com \
--cc=ceph-devel@vger.kernel.org \
--cc=jmorris@namei.org \
--cc=john.johansen@canonical.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mic@digikod.net \
--cc=penguin-kernel@i-love.sakura.ne.jp \
--cc=selinux@vger.kernel.org \
--cc=serge@hallyn.com \
--cc=stephen.smalley.work@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).