Skip to content

Commit 9084ed7

Browse files
stephensmalleyAnna Schumaker
authored andcommitted
lsm,nfs: fix memory leak of lsm_context
commit b530104 ("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: b530104 ("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>
1 parent 1f7a4f9 commit 9084ed7

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

fs/nfs/nfs4proc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ nfs4_label_init_security(struct inode *dir, struct dentry *dentry,
133133
if (err)
134134
return NULL;
135135

136+
label->lsmid = shim.id;
136137
label->label = shim.context;
137138
label->len = shim.len;
138139
return label;
@@ -145,7 +146,7 @@ nfs4_label_release_security(struct nfs4_label *label)
145146
if (label) {
146147
shim.context = label->label;
147148
shim.len = label->len;
148-
shim.id = LSM_ID_UNDEF;
149+
shim.id = label->lsmid;
149150
security_release_secctx(&shim);
150151
}
151152
}
@@ -6272,7 +6273,7 @@ static int _nfs4_get_security_label(struct inode *inode, void *buf,
62726273
size_t buflen)
62736274
{
62746275
struct nfs_server *server = NFS_SERVER(inode);
6275-
struct nfs4_label label = {0, 0, buflen, buf};
6276+
struct nfs4_label label = {0, 0, 0, buflen, buf};
62766277

62776278
u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL };
62786279
struct nfs_fattr fattr = {
@@ -6377,7 +6378,7 @@ static int nfs4_do_set_security_label(struct inode *inode,
63776378
static int
63786379
nfs4_set_security_label(struct inode *inode, const void *buf, size_t buflen)
63796380
{
6380-
struct nfs4_label ilabel = {0, 0, buflen, (char *)buf };
6381+
struct nfs4_label ilabel = {0, 0, 0, buflen, (char *)buf };
63816382
struct nfs_fattr *fattr;
63826383
int status;
63836384

include/linux/nfs4.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct nfs4_acl {
4747
struct nfs4_label {
4848
uint32_t lfs;
4949
uint32_t pi;
50+
u32 lsmid;
5051
u32 len;
5152
char *label;
5253
};

0 commit comments

Comments
 (0)