All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] f2fs: Fix gcc9 error -Werror=maybe-uninitialized
@ 2019-05-17  9:00 Michael Chang
  2019-05-17 12:26 ` Daniel Kiper
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Chang @ 2019-05-17  9:00 UTC (permalink / raw)
  To: grub-devel

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.

Reported-by: Neil MacLeod <neil@nmacleod.com>
Signed-off-by: Michael Chang <mchang@suse.com>
---
 grub-core/fs/f2fs.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/grub-core/fs/f2fs.c b/grub-core/fs/f2fs.c
index 644653dbe..bb28b291b 100644
--- a/grub-core/fs/f2fs.c
+++ b/grub-core/fs/f2fs.c
@@ -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



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] f2fs: Fix gcc9 error -Werror=maybe-uninitialized
  2019-05-17  9:00 [PATCH] f2fs: Fix gcc9 error -Werror=maybe-uninitialized Michael Chang
@ 2019-05-17 12:26 ` Daniel Kiper
  2019-05-17 16:16   ` Neil MacLeod
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Kiper @ 2019-05-17 12:26 UTC (permalink / raw)
  To: Michael Chang, neil; +Cc: grub-devel

CC-ing neil@nmacleod.com

Michael, thank you for posting the patch.

Neil, does it solve your problem?

Daniel

On Fri, May 17, 2019 at 05:00:19PM +0800, Michael Chang wrote:
> 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.
>
> Reported-by: Neil MacLeod <neil@nmacleod.com>
> Signed-off-by: Michael Chang <mchang@suse.com>
> ---
>  grub-core/fs/f2fs.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/grub-core/fs/f2fs.c b/grub-core/fs/f2fs.c
> index 644653dbe..bb28b291b 100644
> --- a/grub-core/fs/f2fs.c
> +++ b/grub-core/fs/f2fs.c
> @@ -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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] f2fs: Fix gcc9 error -Werror=maybe-uninitialized
  2019-05-17 12:26 ` Daniel Kiper
@ 2019-05-17 16:16   ` Neil MacLeod
  2019-05-20 11:49     ` Daniel Kiper
  0 siblings, 1 reply; 9+ messages in thread
From: Neil MacLeod @ 2019-05-17 16:16 UTC (permalink / raw)
  To: Daniel Kiper; +Cc: Michael Chang, The development of GNU GRUB

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

On Fri, 17 May 2019 at 13:26, Daniel Kiper <dkiper@net-space.pl> wrote:
>
> CC-ing neil@nmacleod.com
>
> Michael, thank you for posting the patch.
>
> Neil, does it solve your problem?
>
> Daniel
>
> On Fri, May 17, 2019 at 05:00:19PM +0800, Michael Chang wrote:
> > 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.
> >
> > Reported-by: Neil MacLeod <neil@nmacleod.com>
> > Signed-off-by: Michael Chang <mchang@suse.com>
> > ---
> >  grub-core/fs/f2fs.c | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/grub-core/fs/f2fs.c b/grub-core/fs/f2fs.c
> > index 644653dbe..bb28b291b 100644
> > --- a/grub-core/fs/f2fs.c
> > +++ b/grub-core/fs/f2fs.c
> > @@ -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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] f2fs: Fix gcc9 error -Werror=maybe-uninitialized
  2019-05-17 16:16   ` Neil MacLeod
@ 2019-05-20 11:49     ` Daniel Kiper
  2019-05-22 16:35       ` Neil MacLeod
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Kiper @ 2019-05-20 11:49 UTC (permalink / raw)
  To: Neil MacLeod; +Cc: The development of GNU GRUB, Michael Chang

On Fri, May 17, 2019 at 05:16:34PM +0100, Neil MacLeod wrote:
> 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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] f2fs: Fix gcc9 error -Werror=maybe-uninitialized
  2019-05-20 11:49     ` Daniel Kiper
@ 2019-05-22 16:35       ` Neil MacLeod
  2019-05-23  7:40         ` Michael Chang
  0 siblings, 1 reply; 9+ messages in thread
From: Neil MacLeod @ 2019-05-22 16:35 UTC (permalink / raw)
  To: Daniel Kiper
  Cc: The development of GNU GRUB, Michael Chang, John Paul Adrian Glaubitz

> Thanks! I allowed myself to add your Tested-by. I hope this is not a problem for you

Not at all!

> 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

On Mon, 20 May 2019 at 12:49, Daniel Kiper <dkiper@net-space.pl> wrote:
>
> On Fri, May 17, 2019 at 05:16:34PM +0100, Neil MacLeod wrote:
> > 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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] f2fs: Fix gcc9 error -Werror=maybe-uninitialized
  2019-05-22 16:35       ` Neil MacLeod
@ 2019-05-23  7:40         ` Michael Chang
  2019-05-27 10:02           ` Daniel Kiper
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Chang @ 2019-05-23  7:40 UTC (permalink / raw)
  To: Neil MacLeod
  Cc: Daniel Kiper, The development of GNU GRUB, John Paul Adrian Glaubitz

On Wed, May 22, 2019 at 05:35:34PM +0100, Neil MacLeod wrote:
> > Thanks! I allowed myself to add your Tested-by. I hope this is not a problem for you
> 
> Not at all!
> 
> > 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

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

> 
> On Mon, 20 May 2019 at 12:49, Daniel Kiper <dkiper@net-space.pl> wrote:
> >
> > On Fri, May 17, 2019 at 05:16:34PM +0100, Neil MacLeod wrote:
> > > 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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] f2fs: Fix gcc9 error -Werror=maybe-uninitialized
  2019-05-23  7:40         ` Michael Chang
@ 2019-05-27 10:02           ` Daniel Kiper
  2019-05-27 10:07             ` John Paul Adrian Glaubitz
  2019-05-29  6:10             ` John Paul Adrian Glaubitz
  0 siblings, 2 replies; 9+ messages in thread
From: Daniel Kiper @ 2019-05-27 10:02 UTC (permalink / raw)
  To: Neil MacLeod, The development of GNU GRUB, John Paul Adrian Glaubitz

On Thu, May 23, 2019 at 03:40:28PM +0800, Michael Chang wrote:
> On Wed, May 22, 2019 at 05:35:34PM +0100, Neil MacLeod wrote:
> > > Thanks! I allowed myself to add your Tested-by. I hope this is not a problem for you
> >
> > Not at all!
> >
> > > 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
>
> 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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] f2fs: Fix gcc9 error -Werror=maybe-uninitialized
  2019-05-27 10:02           ` Daniel Kiper
@ 2019-05-27 10:07             ` John Paul Adrian Glaubitz
  2019-05-29  6:10             ` John Paul Adrian Glaubitz
  1 sibling, 0 replies; 9+ messages in thread
From: John Paul Adrian Glaubitz @ 2019-05-27 10:07 UTC (permalink / raw)
  To: Daniel Kiper, Neil MacLeod, The development of GNU GRUB

On 5/27/19 12:02 PM, Daniel Kiper wrote:
>> 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.

Just a second, I will send the patch today. Sorry for the delay.

Adrian

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - glaubitz@debian.org
`. `'   Freie Universitaet Berlin - glaubitz@physik.fu-berlin.de
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] f2fs: Fix gcc9 error -Werror=maybe-uninitialized
  2019-05-27 10:02           ` Daniel Kiper
  2019-05-27 10:07             ` John Paul Adrian Glaubitz
@ 2019-05-29  6:10             ` John Paul Adrian Glaubitz
  1 sibling, 0 replies; 9+ messages in thread
From: John Paul Adrian Glaubitz @ 2019-05-29  6:10 UTC (permalink / raw)
  To: Daniel Kiper, Neil MacLeod, The development of GNU GRUB

On 5/27/19 12:02 PM, Daniel Kiper wrote:
>> 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

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - glaubitz@debian.org
`. `'   Freie Universitaet Berlin - glaubitz@physik.fu-berlin.de
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-05-29  6:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-17  9:00 [PATCH] f2fs: Fix gcc9 error -Werror=maybe-uninitialized Michael Chang
2019-05-17 12:26 ` Daniel Kiper
2019-05-17 16:16   ` Neil MacLeod
2019-05-20 11:49     ` Daniel Kiper
2019-05-22 16:35       ` Neil MacLeod
2019-05-23  7:40         ` Michael Chang
2019-05-27 10:02           ` Daniel Kiper
2019-05-27 10:07             ` John Paul Adrian Glaubitz
2019-05-29  6:10             ` John Paul Adrian Glaubitz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.