f2fs: Fix gcc9 error -Werror=maybe-uninitialized
PATCH 1/1 f2fs: Fix gcc9 error -Werror=maybe-uninitialized
The function grub_get_node_path could return uninitialized offset with level == 0 if the block is greater than direct_index + 2*direct_blks + 2*indirect_blks + dindirect_blks. The uninitialized offset is then used by function grub_f2fs_get_block because level == 0 is valid and meaningful return to be processed.
The fix is to set level = -1 as return value by grub_get_node_path to signify an error that the input block cannot be handled. Any caller should therefore check level is negative or not before processing the output.
--- grub-core/fs/f2fs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
grub-core/fs/f2fs.c +6 -1
@@ -702,7 +702,7 @@ grub_get_node_path (struct grub_f2fs_inode *inode, grub_uint32_t block,grub_uint32_t dindirect_blks = indirect_blks *NIDS_PER_BLOCK ;grub_uint32_t direct_index =DEF_ADDRS_PER_INODE ;int n =0 ; -int level =0 ; +int level =-1 ;if (inode->i_inline &F2FS_INLINE_XATTR ) direct_index -=F2FS_INLINE_XATTR_ADDRS ;
@@ -712,6 +712,7 @@ grub_get_node_path (struct grub_f2fs_inode *inode, grub_uint32_t block,if (block < direct_index) { offset[n] = block; + level =0 ; goto got; }
@@ -860,6 +861,10 @@ grub_f2fs_get_block (grub_fshelp_node_t node, grub_disk_addr_t block_ofs)int level, i; level =grub_get_node_path (inode, block_ofs, offset, noffset); + +if (level <0 ) +return -1 ; +if (level ==0 )return grub_le_to_cpu32 (inode->i_addr[offset[0 ]]);
Signature · 1 line
2.16.4
CC-ing [email protected]
Michael, thank you for posting the patch.
Neil, does it solve your problem?
Daniel
Quoted 51 lines · Michael Chang
The function
grub_get_node_pathcould return uninitialized offset with level == 0 if the block is greater thandirect_index+ 2*direct_blks + 2*indirect_blks +dindirect_blks. The uninitialized offset is then used by functiongrub_f2fs_get_blockbecause level == 0 is valid and meaningful return to be processed.The fix is to set level = -1 as return value by
grub_get_node_pathto signify an error that the input block cannot be handled. Any caller should therefore check level is negative or not before processing the output.Reported-by Neil MacLeod <[email protected]>Signed-off-by Michael Chang <[email protected]>--- grub-core/fs/f2fs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)grub-core/fs/f2fs.c +6
-2@@ -702,7 +702,7 @@ grub_get_node_path (struct grub_f2fs_inode *inode, grub_uint32_t block,grub_uint32_t dindirect_blks = indirect_blks *NIDS_PER_BLOCK ;grub_uint32_t direct_index =DEF_ADDRS_PER_INODE ;int n =0 ; -int level =0 ; +int level =-1 ;if (inode->i_inline &F2FS_INLINE_XATTR ) direct_index -=F2FS_INLINE_XATTR_ADDRS ;@@ -712,6 +712,7 @@ grub_get_node_path (struct grub_f2fs_inode *inode, grub_uint32_t block,if (block < direct_index) { offset[n] = block; + level =0 ; goto got; }@@ -860,6 +861,10 @@ grub_f2fs_get_block (grub_fshelp_node_t node, grub_disk_addr_t block_ofs)int level, i; level =grub_get_node_path (inode, block_ofs, offset, noffset); + +if (level <0 ) +return -1 ; +if (level ==0 )return grub_le_to_cpu32 (inode->i_addr[offset[0 ]]); --2.16.4
Hi Daniel & Michael
I've tested the new patch (in place of my attempt) and grub is building successfully so it looks good here!
Many thanks!
Neil
Quoted 61 lines · Daniel Kiper
CC-ing [email protected]
Michael, thank you for posting the patch.
Neil, does it solve your problem?
Daniel
Quoted 51 lines · Michael Chang
The function
grub_get_node_pathcould return uninitialized offset with level == 0 if the block is greater thandirect_index+ 2*direct_blks + 2*indirect_blks +dindirect_blks. The uninitialized offset is then used by functiongrub_f2fs_get_blockbecause level == 0 is valid and meaningful return to be processed.The fix is to set level = -1 as return value by
grub_get_node_pathto signify an error that the input block cannot be handled. Any caller should therefore check level is negative or not before processing the output.Reported-by Neil MacLeod <[email protected]>Signed-off-by Michael Chang <[email protected]>--- grub-core/fs/f2fs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)grub-core/fs/f2fs.c +6
-2@@ -702,7 +702,7 @@ grub_get_node_path (struct grub_f2fs_inode *inode, grub_uint32_t block,grub_uint32_t dindirect_blks = indirect_blks *NIDS_PER_BLOCK ;grub_uint32_t direct_index =DEF_ADDRS_PER_INODE ;int n =0 ; -int level =0 ; +int level =-1 ;if (inode->i_inline &F2FS_INLINE_XATTR ) direct_index -=F2FS_INLINE_XATTR_ADDRS ;@@ -712,6 +712,7 @@ grub_get_node_path (struct grub_f2fs_inode *inode, grub_uint32_t block,if (block < direct_index) { offset[n] = block; + level =0 ; goto got; }@@ -860,6 +861,10 @@ grub_f2fs_get_block (grub_fshelp_node_t node, grub_disk_addr_t block_ofs)int level, i; level =grub_get_node_path (inode, block_ofs, offset, noffset); + +if (level <0 ) +return -1 ; +if (level ==0 )return grub_le_to_cpu32 (inode->i_addr[offset[0 ]]); --2.16.4
Quoted 4 lines · Neil MacLeod
Hi Daniel & Michael
I've tested the new patch (in place of my attempt) and grub is building successfully so it looks good here!
Thanks! I allowed myself to add your Tested-by. I hope this is not a problem for you.
Michael, thank you for posting the patch.
This and other fixes posted earlier are now in the tree.
Daniel
Quoted 1 line
Thanks! I allowed myself to add your Tested-by. I hope this is not a problem for you
Not at all!
Quoted 1 line
This and other fixes posted earlier are now in the tree.
Latest grub HEAD (53e70d30cf0d18e6c28bab0ab8d223a90d3e1b46) continues to fail when building f2fs.c with gcc-9.1 due to a packed member issue
- Adrian (John? - sorry!) proposed a fix[1] and Michael confirmed it is correct, but that fix doesn't yet appear to be in the master tree, any ideas?
Thanks
Neil
1. http://lists.gnu.org/archive/html/grub-devel/2019-05/msg00096.html
Quoted 15 lines · Daniel Kiper
Quoted 4 lines · Neil MacLeod
Hi Daniel & Michael
I've tested the new patch (in place of my attempt) and grub is building successfully so it looks good here!
Thanks! I allowed myself to add your Tested-by. I hope this is not a problem for you.
Michael, thank you for posting the patch.
This and other fixes posted earlier are now in the tree.
Daniel
Quoted 12 lines · Neil MacLeod
Quoted 1 line
Thanks! I allowed myself to add your Tested-by. I hope this is not a problem for you
Not at all!
Quoted 1 line
This and other fixes posted earlier are now in the tree.
Latest grub HEAD (
53e70d30cf0d18e6c28bab0ab8d223a90d3e1b46) continues to fail when buildingf2fs.cwith gcc-9.1 due to a packed member issue
- Adrian (John? - sorry!) proposed a fix[1] and Michael confirmed it is correct, but that fix doesn't yet appear to be in the master tree, any ideas?
Quoted 4 lines
Thanks
Neil1. http://lists.gnu.org/archive/html/grub-devel/2019-05/msg00096.html
Yes, we need the patch from John to solve reported gcc-9 build issue entirely. From the latest update he will do soon. :)
http://lists.gnu.org/archive/html/grub-devel/2019-05/msg00099.html
Thanks,
Michael
Quoted 17 lines · Daniel Kiper
Quoted 15 lines · Neil MacLeod
Quoted 4 lines
Hi Daniel & Michael
I've tested the new patch (in place of my attempt) and grub is building successfully so it looks good here!
Thanks! I allowed myself to add your Tested-by. I hope this is not a problem for you.
Michael, thank you for posting the patch.
This and other fixes posted earlier are now in the tree.
Daniel
Quoted 16 lines · Michael Chang
Quoted 15 lines · Neil MacLeod
Quoted 1 line
Thanks! I allowed myself to add your Tested-by. I hope this is not a problem for you
Not at all!
Quoted 1 line
This and other fixes posted earlier are now in the tree.
Latest grub HEAD (
53e70d30cf0d18e6c28bab0ab8d223a90d3e1b46) continues to fail when buildingf2fs.cwith gcc-9.1 due to a packed member issue
- Adrian (John? - sorry!) proposed a fix[1] and Michael confirmed it is correct, but that fix doesn't yet appear to be in the master tree, any ideas?Thanks
Neil
Quoted 6 lines
Yes, we need the patch from John to solve reported gcc-9 build issue entirely. From the latest update he will do soon. :)
http://lists.gnu.org/archive/html/grub-devel/2019-05/msg00099.html
John, ping? Could you send us the patch soon? IMO this is the last thing which blocks the release.
Daniel
Quoted 4 lines · Daniel Kiper
John, ping? Could you send us the patch soon? IMO this is the last thing which blocks the release.
Just a second, I will send the patch today. Sorry for the delay.
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer - [email protected] `. `' Freie Universitaet Berlin - [email protected] `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Quoted 7 lines · Daniel Kiper
Quoted 4 lines
Yes, we need the patch from John to solve reported gcc-9 build issue entirely. From the latest update he will do soon. :)
http://lists.gnu.org/archive/html/grub-devel/2019-05/msg00099.html
John, ping? Could you send us the patch soon? IMO this is the last thing which blocks the release.
Working on this now. Just need to perform a test build with gcc-9 now.
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer - [email protected] `. `' Freie Universitaet Berlin - [email protected] `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913