Clean up unused values
cover Clean up unused values
Coverity listed three unused value bugs in the GRUB. These patches help clean up and remove these uneccessary bits of code.
The Coverity bugs being addressed are:
CID 428875
CID 428876
CID 428877
Alec Brown (3):
fs/jfs.c: Clean up redundant code osdep/unix/getroot.c: Clean up redundant code loader/i386/multiboot_mbi.c: Clean up redundant code
grub-core/fs/jfs.c | 1 - grub-core/loader/i386/multiboot_mbi.c | 2 +- grub-core/osdep/unix/getroot.c | 1 - 3 files changed, 1 insertion(+), 3 deletions(-)
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 1/3 fs/jfs.c: Clean up redundant code
In grub-core/fs/jfs.c, coverity spotted redundant code where the pointer diro was being set to 0 and then being overwritten later without being used. Since this is unnecessary, we can remove the code that sets diro to 0.
--- grub-core/fs/jfs.c | 1 - 1 file changed, 1 deletion(-)
grub-core/fs/jfs.c +0 -1
@@ -716,7 +716,6 @@ grub_jfs_find_file (struct grub_jfs_data *data, const char *path,grub_uint32_t dirino =grub_le_to_cpu32 (data->currinode.inode);grub_jfs_closedir (diro); - diro =0 ;if (grub_jfs_read_inode (data, ino, &data->currinode))break ;
Signature · 7 lines
2.27.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 2/3 osdep/unix/getroot.c: Clean up redundant code
In reply to Alec BrownIn grub-core/osdep/unix/getroot.c, coverity spotted redundant code where the double pointer os_dev was being set to 0 and then being overwritten later without being used. Since this is unnecessary, we can remove the code that sets os_dev to 0.
--- grub-core/osdep/unix/getroot.c | 1 - 1 file changed, 1 deletion(-)
grub-core/osdep/unix/getroot.c +0 -1
@@ -540,7 +540,6 @@ grub_guess_root_devices (const char *dir_in)for (cur = os_dev; *cur; cur++)free (*cur);free (os_dev); - os_dev =0 ; }if (stat (dir, &st) <0 )
Signature · 7 lines
2.27.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 2/3] osdep/unix/getroot.c: Clean up redundant code
Dear Alec, and grub-devel,
I haven't checked the specific code in question, but do we really want to be removing such null-assignments? (Thinking about multiple patches exactly like this).
In correct code, they are of course redundant by definition, however their intended purpose is that if the code happens to be incorrect, they turn use-after-free bugs into zero page accesses.
Since static analysis of a language like C is inherently conservative, it is entirely possible that it is detecting the redundant assignment, but not the use after free it would have prevented.
With UEFI looking to gain more memory protections, including un-mapped zero-page (alongside NX), it might even be a good idea to add more such assignments instead of removing them.
Best regards,
Mate Kukri
Quoted 29 lines · Alec Brown
In
grub-core/osdep/unix/getroot.c, coverity spotted redundant code where the double pointeros_devwas being set to 0 and then being overwritten later without being used. Since this is unnecessary, we can remove the code that setsos_devto 0.Fixes CID 428875Signed-off-by Alec Brown <[email protected]>--- grub-core/osdep/unix/getroot.c | 1 - 1 file changed, 1 deletion(-)grub-core/osdep/unix/getroot.c +0
-2@@ -540,7 +540,6 @@ grub_guess_root_devices (const char *dir_in)for (cur = os_dev; *cur; cur++)free (*cur);free (os_dev); - os_dev =0 ; }if (stat (dir, &st) <0 ) --2.27.0
Quoted 4 lines
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 2/3] osdep/unix/getroot.c: Clean up redundant code
Mate,
Next time please respond to all people/addresses in the original email...
Quoted 6 lines · Mate Kukri
Dear Alec, and grub-devel,
I haven't checked the specific code in question, but do we really want to be removing such null-assignments? (Thinking about multiple patches exactly like this).
Quoted 7 lines
In correct code, they are of course redundant by definition, however their intended purpose is that if the code happens to be incorrect, they turn use-after-free bugs into zero page accesses.
Since static analysis of a language like C is inherently conservative, it is entirely possible that it is detecting the redundant assignment, but not the use after free it would have prevented.
We know the Coverity makes mistakes. So, we carefully check its reports. These ones are not exceptions. Here the Coverity is correct and it is safe to remove redundant code. I expect somebody was changing the code at some point and forgot to drop surplus assignments.
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 2/3] osdep/unix/getroot.c: Clean up redundant code
Quoted 16 lines · Daniel Kiper
Mate,
Next time please respond to all people/addresses in the original email...
Quoted 10 lines · Mate Kukri
Dear Alec, and grub-devel,
I haven't checked the specific code in question, but do we really want to be removing such null-assignments? (Thinking about multiple patches exactly like this).
In correct code, they are of course redundant by definition, however their intended purpose is that if the code happens to be incorrect, they turn use-after-free bugs into zero page accesses.
Quoted 9 lines
Quoted 3 lines
Since static analysis of a language like C is inherently conservative, it is entirely possible that it is detecting the redundant assignment, but not the use after free it would have prevented.
We know the Coverity makes mistakes. So, we carefully check its reports. These ones are not exceptions. Here the Coverity is correct and it is safe to remove redundant code. I expect somebody was changing the code at some point and forgot to drop surplus assignments.
Nope. It was to keep an invariant and ensure we don't double-free
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 3/3 loader/i386/multiboot_mbi.c: Clean up redundant code
In reply to Alec BrownIn grub-core/loader/i386/multiboot_mbi.c, coverity spotted redundant code where the variable err was being set to GRUB_ERR_NONE and then being overwritten later without being used. Since this is unnecessary, we can remove the code that sets err to GRUB_ERR_NONE.
--- grub-core/loader/i386/multiboot_mbi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/loader/i386/multiboot_mbi.c +1 -1
@@ -86,7 +86,7 @@ load_kernel (grub_file_t file, const char *filename,return GRUB_ERR_NONE ; }if (err ==GRUB_ERR_UNKNOWN_OS && (header->flags &MULTIBOOT_AOUT_KLUDGE )) - grub_errno = err =GRUB_ERR_NONE ; + grub_errno =GRUB_ERR_NONE ; }if (header->flags &MULTIBOOT_AOUT_KLUDGE ) {
Signature · 7 lines
2.27.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 8 lines · Alec Brown
Coverity listed three unused value bugs in the GRUB. These patches help clean up and remove these uneccessary bits of code.
The Coverity bugs being addressed are:
CID 428875
CID 428876
CID 428877
Quoted 4 lines
Alec Brown (3):
fs/jfs.c: Clean up redundant codeosdep/unix/getroot.c: Clean up redundant codeloader/i386/multiboot_mbi.c: Clean up redundant code
For all patches Reviewed-by: Daniel Kiper <[email protected]>...
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
I oppose to all 3 patches. These assignments are not redundant but keep an important invariant: the variable in question can be passed to free(). For this it needs to either be NULL or point to a valid allocated memory. In this code this ensures that we never double free even after code changes
Quoted 21 lines · Alec Brown
Coverity listed three unused value bugs in the GRUB. These patches help clean
up and remove these uneccessary bits of code.The Coverity bugs being addressed are:
CID 428875
CID 428876
CID 428877Alec Brown (3):
fs/jfs.c: Clean up redundant codeosdep/unix/getroot.c: Clean up redundant codeloader/i386/multiboot_mbi.c: Clean up redundant codegrub-core/fs/jfs.c | 1 - grub-core/loader/i386/multiboot_mbi.c | 2 +- grub-core/osdep/unix/getroot.c | 1 - 3 files changed, 1 insertion(+), 3 deletions(-)
Quoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
If I may add a small point, apart from the invariant being kept, initializing on definition also makes bug behavior more deterministic. Hunting for a bug that only manifests on certain uninitialized values in memory is hard.
Quoted 31 lines · Vladimir 'phcoder' Serbinenko
I oppose to all 3 patches. These assignments are not redundant but keep an important invariant: the variable in question can be passed to
free(). For this it needs to either be NULL or point to a valid allocated memory. In this code this ensures that we never double free even after code changesQuoted 21 lines · Alec Brown
Coverity listed three unused value bugs in the GRUB. These patches help clean up and remove these uneccessary bits of code.
The Coverity bugs being addressed are:
CID 428875
CID 428876
CID 428877Alec Brown (3):
fs/jfs.c: Clean up redundant codeosdep/unix/getroot.c: Clean up redundant codeloader/i386/multiboot_mbi.c: Clean up redundant codegrub-core/fs/jfs.c | 1 - grub-core/loader/i386/multiboot_mbi.c | 2 +- grub-core/osdep/unix/getroot.c | 1 - 3 files changed, 1 insertion(+), 3 deletions(-)Quoted 4 lines
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 4 lines
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel