efi_loader: pkcs7_parse_message() returns error pointer
Since pkcs7_parse_message() returns an error pointer, we must not check for NULL. We have to explicitly set msg to NULL in the error case, otherwise the call to pkcs7_free_message() on the goto err path will assume it's a valid object.
lib/efi_loader/efi_image_loader.c +2 -1
@@ -538,8 +538,9 @@ static bool efi_image_authenticate(void *efi, size_t efi_size) } msg =pkcs7_parse_message ((void *)wincert +sizeof (*wincert), wincert->dwLength -sizeof (*wincert)); -if (!msg) { +if (IS_ERR (msg)) {debug ("Parsing image's signature failed\n" ); + msg =NULL ; goto err; }
Quoted 4 lines · Patrick Wildt
Since
pkcs7_parse_message()returns an error pointer, we must not check for NULL. We have to explicitly set msg to NULL in the error case, otherwise the call topkcs7_free_message()on the goto err path will assume it's a valid object.
@Takahiro
I think we should start documenting the library functions properly. The description in lib/crypto/pkcs7_parser.c does not conform to
https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#function-documentation
Especially we should describe how errors are returned.
Best regards
Heinrich
Quoted 19 lines
Signed-off-by Patrick Wildt <[email protected]>lib/efi_loader/efi_image_loader.c +2
-1@@ -538,8 +538,9 @@ static bool efi_image_authenticate(void *efi, size_t efi_size) } msg =pkcs7_parse_message ((void *)wincert +sizeof (*wincert), wincert->dwLength -sizeof (*wincert)); -if (!msg) { +if (IS_ERR (msg)) {debug ("Parsing image's signature failed\n" ); + msg =NULL ; goto err; }
Heinrich Schuchardt
Reviewed-byQuoted 12 lines · Patrick Wildt
Since
pkcs7_parse_message()returns an error pointer, we must not check for NULL. We have to explicitly set msg to NULL in the error case, otherwise the call topkcs7_free_message()on the goto err path will assume it's a valid object.Signed-off-by Patrick Wildt <[email protected]>lib/efi_loader/efi_image_loader.c +0
-0
lib/efi_loader/efi_image_loader.c static bool efi_image_authenticate(void *efi, size_t efi_size) · line 541
Quoted 5 lines
lib/efi_loader/efi_image_loader.c +1
-1@@ -538,8 +538,9 @@ static bool efi_image_authenticate(void *efi, size_t efi_size) } msg =pkcs7_parse_message ((void *)wincert +sizeof (*wincert), wincert->dwLength -sizeof (*wincert)); -if (!msg) { +if (IS_ERR (msg)) {
Compiling with sandbox_defconfig results in:
lib/efi_loader/efi_image_loader.c: In function ?efi_image_authenticate?:lib/efi_loader/efi_image_loader.c:541:7: warning: implicit declaration of function ?IS_ERR? [-Wimplicit-function-declaration]
541 | if (IS_ERR(msg)) {
| ^~~~~~I will add the missing #include <linux/err.h> when merging.
Quoted 6 lines
lib/efi_loader/efi_image_loader.c +1
-0debug ("Parsing image's signature failed\n" ); + msg =NULL ; goto err; }
Heinrich,
Quoted 8 lines · Heinrich Schuchardt
Quoted 4 lines · Patrick Wildt
Since
pkcs7_parse_message()returns an error pointer, we must not check for NULL. We have to explicitly set msg to NULL in the error case, otherwise the call topkcs7_free_message()on the goto err path will assume it's a valid object.@Takahiro
I think we should start documenting the library functions properly. The
Generally I agree, but
Quoted 3 lines
description in
lib/crypto/pkcs7_parser.cdoes not conform to
https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#function-documentation
Especially we should describe how errors are returned.
Remember that this file, as well as others under lib/crypto, was imported from linux kernel source.
I made a minimum set of changes to align it with U-Boot code. So I'm rather reluctant to modify the file.
Thanks,
-Takahiro Akashi
Quoted 24 lines
Best regards
Heinrich
Quoted 19 lines
Signed-off-by Patrick Wildt <[email protected]>lib/efi_loader/efi_image_loader.c +2
-1@@ -538,8 +538,9 @@ static bool efi_image_authenticate(void *efi, size_t efi_size) } msg =pkcs7_parse_message ((void *)wincert +sizeof (*wincert), wincert->dwLength -sizeof (*wincert)); -if (!msg) { +if (IS_ERR (msg)) {debug ("Parsing image's signature failed\n" ); + msg =NULL ; goto err; }