Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: asymmetric_keys - fix uninitialized pointers with free attribute

Uninitialized pointers with `__free` attribute can cause undefined
behavior as the memory assigned randomly to the pointer is freed
automatically when the pointer goes out of scope.

crypto/asymmetric_keys doesn't have any bugs related to this as of now,
but, it is better to initialize and assign pointers with `__free`
attribute in one statement to ensure proper scope-based cleanup

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/all/aPiG_F5EBQUjZqsl@stanley.mountain/
Signed-off-by: Ally Heev <allyheev@gmail.com>
Reviewed-by: Ignat Korchagin <ignat@cloudflare.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Ally Heev and committed by
Herbert Xu
79492d5a a26c23e0

+2 -2
+1 -1
crypto/asymmetric_keys/x509_cert_parser.c
··· 60 60 */ 61 61 struct x509_certificate *x509_cert_parse(const void *data, size_t datalen) 62 62 { 63 - struct x509_certificate *cert __free(x509_free_certificate); 63 + struct x509_certificate *cert __free(x509_free_certificate) = NULL; 64 64 struct x509_parse_context *ctx __free(kfree) = NULL; 65 65 struct asymmetric_key_id *kid; 66 66 long ret;
+1 -1
crypto/asymmetric_keys/x509_public_key.c
··· 148 148 */ 149 149 static int x509_key_preparse(struct key_preparsed_payload *prep) 150 150 { 151 - struct x509_certificate *cert __free(x509_free_certificate); 151 + struct x509_certificate *cert __free(x509_free_certificate) = NULL; 152 152 struct asymmetric_key_ids *kids __free(kfree) = NULL; 153 153 char *p, *desc __free(kfree) = NULL; 154 154 const char *q;