appendedsig: Fix grub-mkimage with an unaligned appended signature size
PATCH 1/1 appendedsig: Fix grub-mkimage with an unaligned appended signature size
The grub-mkimage does not add zero padding when creating core.elf with an appended signature size that is not aligned to a multiple of 4 bytes. Firmware is unable to read the magic string "~Module signature appended~" from core.elf.
To fix this, round an appended signature size + appended signature ELF note size up to the nearest multiple of a 4-byte alignment and truncate it to the appended signature size.
Example:
grub-mkimage -O powerpc-ieee1275 -o core.elf -d grub-core -p /grub2 -x \
kernel.der --appended-signature-size 490 ...
--- util/grub-mkimagexx.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
util/grub-mkimagexx.c +7 -1
@@ -248,7 +248,13 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_descif (appsig_size) { phnum++; - footer_size +=ALIGN_UP (sizeof (struct grub_appended_signature_note ),4 ); +/* +* Rounds a appended signature size + appended signature note size up to +* the nearest multiple of a 4-byte alignment. +*/ + footer_size +=ALIGN_UP (sizeof (struct grub_appended_signature_note ) + appsig_size,4 ); +/* Truncating to appended signature size. */ + footer_size -= appsig_size; }if (image_target->id !=IMAGE_LOONGSON_ELF )
Signature · 7 lines
2.50.1 (Apple Git-155) _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 24 lines · Sudhakar Kuppusamy
The grub-mkimage does not add zero padding when creating core.elf with an appended signature size that is not aligned to a multiple of 4 bytes. Firmware is unable to read the magic string "~Module signature appended~" from core.elf.
To fix this, round an appended signature size + appended signature ELF note size up to the nearest multiple of a 4-byte alignment and truncate it to the appended signature size.
Example:
grub-mkimage -O powerpc-ieee1275 -o core.elf -d grub-core -p /grub2 -x \
kernel.der --appended-signature-size 490 ...Signed-off-by Sudhakar Kuppusamy <[email protected]>--- util/grub-mkimagexx.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)util/grub-mkimagexx.c +0
-0@@ -248,7 +248,13 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_descif (appsig_size)
util/grub-mkimagexx.c SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc · line 257
Quoted 10 lines
util/grub-mkimagexx.c +7
-1{ phnum++; - footer_size +=ALIGN_UP (sizeof (struct grub_appended_signature_note ),4 ); +/* +* Rounds a appended signature size + appended signature note size up to +* the nearest multiple of a 4-byte alignment. +*/ + footer_size +=ALIGN_UP (sizeof (struct grub_appended_signature_note ) + appsig_size,4 ); +/* Truncating to appended signature size. */ + footer_size -= appsig_size;
Should not this be
footer_size += ALIGN_UP (sizeof (struct grub_appended_signature_note), 4); appsig_size += ALIGN_UP (appsig_size, 4);
?
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 42 lines · Daniel Kiper
Quoted 24 lines · Sudhakar Kuppusamy
The grub-mkimage does not add zero padding when creating core.elf with an appended signature size that is not aligned to a multiple of 4 bytes. Firmware is unable to read the magic string "~Module signature appended~" from core.elf.
To fix this, round an appended signature size + appended signature ELF note size up to the nearest multiple of a 4-byte alignment and truncate it to the appended signature size.
Example:
grub-mkimage -O powerpc-ieee1275 -o core.elf -d grub-core -p /grub2 -x \
kernel.der --appended-signature-size 490 ...Signed-off-by Sudhakar Kuppusamy <[email protected]>---
util/grub-mkimagexx.c| 8 +++++++-1 file changed, 7 insertions(+), 1 deletion(-)util/grub-mkimagexx.c +0
-0@@ -248,7 +248,13 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_descif (appsig_size)util/grub-mkimagexx.c SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc · line 257
Quoted 10 lines
util/grub-mkimagexx.c +7
-1{ phnum++; - footer_size +=ALIGN_UP (sizeof (struct grub_appended_signature_note ),4 ); +/* +* Rounds a appended signature size + appended signature note size up to +* the nearest multiple of a 4-byte alignment. +*/ + footer_size +=ALIGN_UP (sizeof (struct grub_appended_signature_note ) + appsig_size,4 ); +/* Truncating to appended signature size. */ + footer_size -= appsig_size;Should not this be
Quoted 4 lines
footer_size+=ALIGN_UP(sizeof (structgrub_appended_signature_note), 4);appsig_size+=ALIGN_UP(appsig_size, 4);?
Thank you Daniel for the review.
Did you meant footer_size += ALIGN_UP (appsig_size, 4); if yes, then it should be like
footer_size += ALIGN_UP (sizeof (struct grub_appended_signature_note), 4); footer_size += ALIGN_UP (appsig_size, 4);footer_size -= appsig_size;
Thanks,
Sudhakar
Quoted 2 lines
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 44 lines · Sudhakar Kuppusamy
Quoted 39 lines · Daniel Kiper
Quoted 24 lines · Sudhakar Kuppusamy
The grub-mkimage does not add zero padding when creating core.elf with an appended signature size that is not aligned to a multiple of 4 bytes. Firmware is unable to read the magic string "~Module signature appended~" from core.elf.
To fix this, round an appended signature size + appended signature ELF note size up to the nearest multiple of a 4-byte alignment and truncate it to the appended signature size.
Example:
grub-mkimage -O powerpc-ieee1275 -o core.elf -d grub-core -p /grub2 -x \
kernel.der --appended-signature-size 490 ...Signed-off-by Sudhakar Kuppusamy <[email protected]>---
util/grub-mkimagexx.c| 8 +++++++-1 file changed, 7 insertions(+), 1 deletion(-)util/grub-mkimagexx.c +0
-0@@ -248,7 +248,13 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_descif (appsig_size)util/grub-mkimagexx.c SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc · line 257
Quoted 10 lines
util/grub-mkimagexx.c +7
-1{ phnum++; - footer_size +=ALIGN_UP (sizeof (struct grub_appended_signature_note ),4 ); +/* +* Rounds a appended signature size + appended signature note size up to +* the nearest multiple of a 4-byte alignment. +*/ + footer_size +=ALIGN_UP (sizeof (struct grub_appended_signature_note ) + appsig_size,4 ); +/* Truncating to appended signature size. */ + footer_size -= appsig_size;Should not this be
Quoted 4 lines
footer_size+=ALIGN_UP(sizeof (structgrub_appended_signature_note), 4);appsig_size+=ALIGN_UP(appsig_size, 4);?
Quoted 7 lines
Thank you Daniel for the review.
Did you meant
footer_size+=ALIGN_UP(appsig_size, 4); if yes, then it should be like
footer_size+=ALIGN_UP(sizeof (structgrub_appended_signature_note), 4);footer_size+=ALIGN_UP(appsig_size, 4);footer_size-=appsig_size;
This subtraction makes me very suspicious. Something is off or not sufficiently explained. E.g. the commit message does not say anything which part of ELF file has to be aligned.
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 53 lines · Daniel Kiper
Quoted 48 lines · Sudhakar Kuppusamy
Quoted 39 lines · Daniel Kiper
Quoted 24 lines · Sudhakar Kuppusamy
The grub-mkimage does not add zero padding when creating core.elf with an appended signature size that is not aligned to a multiple of 4 bytes. Firmware is unable to read the magic string "~Module signature appended~" from core.elf.
To fix this, round an appended signature size + appended signature ELF note size up to the nearest multiple of a 4-byte alignment and truncate it to the appended signature size.
Example:
grub-mkimage -O powerpc-ieee1275 -o core.elf -d grub-core -p /grub2 -x \
kernel.der --appended-signature-size 490 ...Signed-off-by Sudhakar Kuppusamy <[email protected]>---
util/grub-mkimagexx.c| 8 +++++++-1 file changed, 7 insertions(+), 1 deletion(-)util/grub-mkimagexx.c +0
-0@@ -248,7 +248,13 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_descif (appsig_size)util/grub-mkimagexx.c SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc · line 257
Quoted 10 lines
util/grub-mkimagexx.c +7
-1{ phnum++; - footer_size +=ALIGN_UP (sizeof (struct grub_appended_signature_note ),4 ); +/* +* Rounds a appended signature size + appended signature note size up to +* the nearest multiple of a 4-byte alignment. +*/ + footer_size +=ALIGN_UP (sizeof (struct grub_appended_signature_note ) + appsig_size,4 ); +/* Truncating to appended signature size. */ + footer_size -= appsig_size;Should not this be
Quoted 4 lines
footer_size+=ALIGN_UP(sizeof (structgrub_appended_signature_note), 4);appsig_size+=ALIGN_UP(appsig_size, 4);?
Thank you Daniel for the review.
Did you meant
footer_size+=ALIGN_UP(appsig_size, 4); if yes, then it should be like
Quoted 7 lines
Quoted 3 lines
footer_size+=ALIGN_UP(sizeof (structgrub_appended_signature_note), 4);footer_size+=ALIGN_UP(appsig_size, 4);footer_size-=appsig_size;This subtraction makes me very suspicious. Something is off or not sufficiently explained. E.g. the commit message does not say anything which part of ELF file has to be aligned.
Sorry Daniel. I will correct the commit message and add the proper comments for subtraction.
We should manually truncate the core Image with appsig_size after creating the core image before signing it if we do not subtract the appsig_size with footer_size.
Example:
grub-mkimage -O powerpc-ieee1275 -o ./core.elf -d grub-core -p /grub2 -x \
kernel.der --appended-signature-size 490 ...
truncate -s -490 ./core.elf
sign-file SHA256 ./grub.key ./grub.pem ./core.elf ./core.elf.signed
If subtract the appsig_size from the footer_size, then it reduce one step for GRUB image signing.
Example:
grub-mkimage -O powerpc-ieee1275 -o ./core.elf -d grub-core -p /grub2 -x \
kernel.der --appended-signature-size 490 ...
sign-file SHA256 ./grub.key ./grub.pem ./core.elf ./core.elf.signed
Thanks,
Sudhakar
Quoted 2 lines
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 72 lines · Sudhakar Kuppusamy
Quoted 50 lines · Daniel Kiper
Quoted 48 lines · Sudhakar Kuppusamy
Quoted 39 lines · Daniel Kiper
Quoted 24 lines · Sudhakar Kuppusamy
The grub-mkimage does not add zero padding when creating core.elf with an appended signature size that is not aligned to a multiple of 4 bytes. Firmware is unable to read the magic string "~Module signature appended~" from core.elf.
To fix this, round an appended signature size + appended signature ELF note size up to the nearest multiple of a 4-byte alignment and truncate it to the appended signature size.
Example:
grub-mkimage -O powerpc-ieee1275 -o core.elf -d grub-core -p /grub2 -x \
kernel.der --appended-signature-size 490 ...Signed-off-by Sudhakar Kuppusamy <[email protected]>---
util/grub-mkimagexx.c| 8 +++++++-1 file changed, 7 insertions(+), 1 deletion(-)util/grub-mkimagexx.c +0
-0@@ -248,7 +248,13 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_descif (appsig_size)util/grub-mkimagexx.c SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc · line 257
Quoted 10 lines
util/grub-mkimagexx.c +7
-1{ phnum++; - footer_size +=ALIGN_UP (sizeof (struct grub_appended_signature_note ),4 ); +/* +* Rounds a appended signature size + appended signature note size up to +* the nearest multiple of a 4-byte alignment. +*/ + footer_size +=ALIGN_UP (sizeof (struct grub_appended_signature_note ) + appsig_size,4 ); +/* Truncating to appended signature size. */ + footer_size -= appsig_size;Should not this be
Quoted 4 lines
footer_size+=ALIGN_UP(sizeof (structgrub_appended_signature_note), 4);appsig_size+=ALIGN_UP(appsig_size, 4);?
Thank you Daniel for the review.
Did you meant
footer_size+=ALIGN_UP(appsig_size, 4); if yes, then it should be likeQuoted 7 lines
Quoted 3 lines
footer_size+=ALIGN_UP(sizeof (structgrub_appended_signature_note), 4);footer_size+=ALIGN_UP(appsig_size, 4);footer_size-=appsig_size;This subtraction makes me very suspicious. Something is off or not sufficiently explained. E.g. the commit message does not say anything which part of ELF file has to be aligned.
Sorry Daniel. I will correct the commit message and add the proper comments for subtraction.
We should manually truncate the core Image with
appsig_sizeafter creating the core image before signing it if we do not subtract theappsig_sizewithfooter_size.Example:
grub-mkimage -O powerpc-ieee1275 -o ./core.elf -d grub-core -p /grub2 -x \
kernel.der --appended-signature-size 490 ...truncate -s -490 ./core.elf
sign-file SHA256 ./grub.key ./grub.pem ./core.elf ./core.elf.signed
Quoted 8 lines
If subtract the
appsig_sizefrom thefooter_size, then it reduce one step for GRUB image signing.Example:
grub-mkimage -O powerpc-ieee1275 -o ./core.elf -d grub-core -p /grub2 -x \
kernel.der --appended-signature-size 490 ...sign-file SHA256 ./grub.key ./grub.pem ./core.elf ./core.elf.signed
I think you are looking for this:
footer_size += ALIGN_UP (sizeof (struct grub_appended_signature_note), 4); footer_size += ALIGN_UP_OVERHEAD (appsig_size, 4);
Though still commit message begs for better explanation of the issue.
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel