Message ID | 1519934986-9612-1-git-send-email-andreas.dilger@intel.com |
---|---|
State | Accepted, archived |
Headers | show |
Series | filefrag: avoid temporary buffer overflow | expand |
On Mar 1, 2018, at 1:09 PM, Andreas Dilger <adilger@dilger.ca> wrote: > If an unknown flag is present in a FIEMAP extent, it is printed as a > hex value into a temporary buffer before adding it to the flags. If > that unknown flag is over 0xffff then it will overflow the temporary > buffer. Correction, any unknown flag over 0xfff would overflow the old buffer size. > Reported-by: Sarah Liu <wei3.liu@intel.com> > Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-10335 > Signed-off-by: Andreas Dilger <andreas.dilger@intel.com> > --- > misc/filefrag.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/misc/filefrag.c b/misc/filefrag.c > index 9c57ab9..dc00393 100644 > --- a/misc/filefrag.c > +++ b/misc/filefrag.c > @@ -179,7 +179,7 @@ static void print_extent_info(struct fiemap_extent *fm_extent, int cur_ex, > print_flag(&fe_flags, FIEMAP_EXTENT_SHARED, flags, "shared,"); > /* print any unknown flags as hex values */ > for (mask = 1; fe_flags != 0 && mask != 0; mask <<= 1) { > - char hex[6]; > + char hex[sizeof(mask) * 2 + 4]; /* 2 chars/byte + 0x, + NUL */ > > if ((fe_flags & mask) == 0) > continue; > -- > 1.8.0 > Cheers, Andreas
On Thu, Mar 01, 2018 at 01:09:46PM -0700, Andreas Dilger wrote: > From: Andreas Dilger <adilger@dilger.ca> > > If an unknown flag is present in a FIEMAP extent, it is printed as a > hex value into a temporary buffer before adding it to the flags. If > that unknown flag is over 0xffff then it will overflow the temporary > buffer. > > Reported-by: Sarah Liu <wei3.liu@intel.com> > Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-10335 > Signed-off-by: Andreas Dilger <andreas.dilger@intel.com> Looks ok, Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> --D > --- > misc/filefrag.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/misc/filefrag.c b/misc/filefrag.c > index 9c57ab9..dc00393 100644 > --- a/misc/filefrag.c > +++ b/misc/filefrag.c > @@ -179,7 +179,7 @@ static void print_extent_info(struct fiemap_extent *fm_extent, int cur_ex, > print_flag(&fe_flags, FIEMAP_EXTENT_SHARED, flags, "shared,"); > /* print any unknown flags as hex values */ > for (mask = 1; fe_flags != 0 && mask != 0; mask <<= 1) { > - char hex[6]; > + char hex[sizeof(mask) * 2 + 4]; /* 2 chars/byte + 0x, + NUL */ > > if ((fe_flags & mask) == 0) > continue; > -- > 1.8.0 >
On Fri, Mar 02, 2018 at 09:48:28AM -0800, Darrick J. Wong wrote: > On Thu, Mar 01, 2018 at 01:09:46PM -0700, Andreas Dilger wrote: > > From: Andreas Dilger <adilger@dilger.ca> > > > > If an unknown flag is present in a FIEMAP extent, it is printed as a > > hex value into a temporary buffer before adding it to the flags. If > > that unknown flag is over 0xffff then it will overflow the temporary > > buffer. > > > > Reported-by: Sarah Liu <wei3.liu@intel.com> > > Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-10335 > > Signed-off-by: Andreas Dilger <andreas.dilger@intel.com> > > Looks ok, > Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Thanks, applied with the 0xfff fixup in the commit description. - Ted
diff --git a/misc/filefrag.c b/misc/filefrag.c index 9c57ab9..dc00393 100644 --- a/misc/filefrag.c +++ b/misc/filefrag.c @@ -179,7 +179,7 @@ static void print_extent_info(struct fiemap_extent *fm_extent, int cur_ex, print_flag(&fe_flags, FIEMAP_EXTENT_SHARED, flags, "shared,"); /* print any unknown flags as hex values */ for (mask = 1; fe_flags != 0 && mask != 0; mask <<= 1) { - char hex[6]; + char hex[sizeof(mask) * 2 + 4]; /* 2 chars/byte + 0x, + NUL */ if ((fe_flags & mask) == 0) continue;