]> www.infradead.org Git - users/hch/misc.git/commitdiff
lsm,nfs: fix memory leak of lsm_context
authorStephen Smalley <stephen.smalley.work@gmail.com>
Thu, 20 Feb 2025 19:29:36 +0000 (14:29 -0500)
committerAnna Schumaker <anna.schumaker@oracle.com>
Tue, 25 Feb 2025 20:07:24 +0000 (15:07 -0500)
commit b530104f50e8 ("lsm: lsm_context in security_dentry_init_security")
did not preserve the lsm id for subsequent release calls, which results
in a memory leak. Fix it by saving the lsm id in the nfs4_label and
providing it on the subsequent release call.

Fixes: b530104f50e8 ("lsm: lsm_context in security_dentry_init_security")
Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Acked-by: Paul Moore <paul@paul-moore.com>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
fs/nfs/nfs4proc.c
include/linux/nfs4.h

index c25ecdb76d304a8d2d061401c8add775429dce0c..6e95db6c17e928b70e749a712302f76ebbb412c1 100644 (file)
@@ -133,6 +133,7 @@ nfs4_label_init_security(struct inode *dir, struct dentry *dentry,
        if (err)
                return NULL;
 
+       label->lsmid = shim.id;
        label->label = shim.context;
        label->len = shim.len;
        return label;
@@ -145,7 +146,7 @@ nfs4_label_release_security(struct nfs4_label *label)
        if (label) {
                shim.context = label->label;
                shim.len = label->len;
-               shim.id = LSM_ID_UNDEF;
+               shim.id = label->lsmid;
                security_release_secctx(&shim);
        }
 }
@@ -6272,7 +6273,7 @@ static int _nfs4_get_security_label(struct inode *inode, void *buf,
                                        size_t buflen)
 {
        struct nfs_server *server = NFS_SERVER(inode);
-       struct nfs4_label label = {0, 0, buflen, buf};
+       struct nfs4_label label = {0, 0, 0, buflen, buf};
 
        u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL };
        struct nfs_fattr fattr = {
@@ -6377,7 +6378,7 @@ static int nfs4_do_set_security_label(struct inode *inode,
 static int
 nfs4_set_security_label(struct inode *inode, const void *buf, size_t buflen)
 {
-       struct nfs4_label ilabel = {0, 0, buflen, (char *)buf };
+       struct nfs4_label ilabel = {0, 0, 0, buflen, (char *)buf };
        struct nfs_fattr *fattr;
        int status;
 
index 71fbebfa43c7e2bd27708814c7300c506ce64c1b..9ac83ca8832660d59b15605f39232b54de8db8e6 100644 (file)
@@ -47,6 +47,7 @@ struct nfs4_acl {
 struct nfs4_label {
        uint32_t        lfs;
        uint32_t        pi;
+       u32             lsmid;
        u32             len;
        char    *label;
 };