Skip to content

Commit 3cfcfc1

Browse files
AlexiousLuchucklever
authored andcommitted
SUNRPC: fix some memleaks in gssx_dec_option_array
The creds and oa->data need to be freed in the error-handling paths after their allocation. So this patch add these deallocations in the corresponding paths. Fixes: 1d65833 ("SUNRPC: Add RPC based upcall mechanism for RPCGSS auth") Signed-off-by: Zhipeng Lu <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent e67b652 commit 3cfcfc1

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

net/sunrpc/auth_gss/gss_rpc_xdr.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ static int gssx_dec_option_array(struct xdr_stream *xdr,
250250

251251
creds = kzalloc(sizeof(struct svc_cred), GFP_KERNEL);
252252
if (!creds) {
253-
kfree(oa->data);
254-
return -ENOMEM;
253+
err = -ENOMEM;
254+
goto free_oa;
255255
}
256256

257257
oa->data[0].option.data = CREDS_VALUE;
@@ -265,29 +265,40 @@ static int gssx_dec_option_array(struct xdr_stream *xdr,
265265

266266
/* option buffer */
267267
p = xdr_inline_decode(xdr, 4);
268-
if (unlikely(p == NULL))
269-
return -ENOSPC;
268+
if (unlikely(p == NULL)) {
269+
err = -ENOSPC;
270+
goto free_creds;
271+
}
270272

271273
length = be32_to_cpup(p);
272274
p = xdr_inline_decode(xdr, length);
273-
if (unlikely(p == NULL))
274-
return -ENOSPC;
275+
if (unlikely(p == NULL)) {
276+
err = -ENOSPC;
277+
goto free_creds;
278+
}
275279

276280
if (length == sizeof(CREDS_VALUE) &&
277281
memcmp(p, CREDS_VALUE, sizeof(CREDS_VALUE)) == 0) {
278282
/* We have creds here. parse them */
279283
err = gssx_dec_linux_creds(xdr, creds);
280284
if (err)
281-
return err;
285+
goto free_creds;
282286
oa->data[0].value.len = 1; /* presence */
283287
} else {
284288
/* consume uninteresting buffer */
285289
err = gssx_dec_buffer(xdr, &dummy);
286290
if (err)
287-
return err;
291+
goto free_creds;
288292
}
289293
}
290294
return 0;
295+
296+
free_creds:
297+
kfree(creds);
298+
free_oa:
299+
kfree(oa->data);
300+
oa->data = NULL;
301+
return err;
291302
}
292303

293304
static int gssx_dec_status(struct xdr_stream *xdr,

0 commit comments

Comments
 (0)