diff mbox series

[next] cifsd: fix kfree of uninitialized pointer oid

Message ID 20210610164603.554691-1-colin.king@canonical.com
State New
Headers show
Series [next] cifsd: fix kfree of uninitialized pointer oid | expand

Commit Message

Colin King June 10, 2021, 4:46 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Currently function ksmbd_neg_token_init_mech_type can kfree an
uninitialized pointer oid when the call to asn1_oid_decode fails
when vlen is out of range. All the other failure cases in
function asn1_oid_decode set *oid to NULL on an error, so fix the
issue by ensuring the vlen out of range error also nullifies the
pointer.

Fixes: 8bae4419ce63 ("cifsd: add goto fail in neg_token_init_mech_type()")
Addresses-Coverity: ("Uninitialized pointer read")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 fs/cifsd/asn1.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Namjae Jeon June 11, 2021, 12:40 a.m. UTC | #1
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently function ksmbd_neg_token_init_mech_type can kfree an uninitialized pointer oid when the call
> to asn1_oid_decode fails when vlen is out of range. All the other failure cases in function
> asn1_oid_decode set *oid to NULL on an error, so fix the issue by ensuring the vlen out of range error
> also nullifies the pointer.
> 
> Fixes: 8bae4419ce63 ("cifsd: add goto fail in neg_token_init_mech_type()")
> Addresses-Coverity: ("Uninitialized pointer read")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
I will apply, Thanks for your patch!
diff mbox series

Patch

diff --git a/fs/cifsd/asn1.c b/fs/cifsd/asn1.c
index 2c63a3e5618b..b014f4638610 100644
--- a/fs/cifsd/asn1.c
+++ b/fs/cifsd/asn1.c
@@ -66,7 +66,7 @@  static bool asn1_oid_decode(const unsigned char *value, size_t vlen,
 
 	vlen += 1;
 	if (vlen < 2 || vlen > UINT_MAX / sizeof(unsigned long))
-		return false;
+		goto fail_nullify;
 
 	*oid = kmalloc(vlen * sizeof(unsigned long), GFP_KERNEL);
 	if (!*oid)
@@ -102,6 +102,7 @@  static bool asn1_oid_decode(const unsigned char *value, size_t vlen,
 
 fail:
 	kfree(*oid);
+fail_nullify:
 	*oid = NULL;
 	return false;
 }