All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] xfsprogs/db: fix a segfault in the print command
@ 2017-04-07  7:49 Shan Hai
  2017-04-07  7:49 ` [PATCH 1/1] xfsprogs/db: fix a segfault by bailing out the print on a corrupted block Shan Hai
  0 siblings, 1 reply; 5+ messages in thread
From: Shan Hai @ 2017-04-07  7:49 UTC (permalink / raw)
  To: linux-xfs; +Cc: darrick.wong


There is a segfault in the xfs_db as below:

mkfs.xfs -f /dev/sda1
xfs_db -r -c "agf 0" -c "addr rmaproot" -c "p" /dev/sda1
Metadata CRC error detected at xfs_rmapbt block 0x0/0x1000
Segmentation fault (core dumped)

---
 db/print.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Thanks
Shan Hai

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

* [PATCH 1/1] xfsprogs/db: fix a segfault by bailing out the print on a corrupted block
  2017-04-07  7:49 [PATCH 0/1] xfsprogs/db: fix a segfault in the print command Shan Hai
@ 2017-04-07  7:49 ` Shan Hai
  2017-04-07 17:23   ` Darrick J. Wong
  2017-04-07 19:31   ` Eric Sandeen
  0 siblings, 2 replies; 5+ messages in thread
From: Shan Hai @ 2017-04-07  7:49 UTC (permalink / raw)
  To: linux-xfs; +Cc: darrick.wong

The print command of the xfs_db would cause segfault on a corrupted
or CRC error block, fix it by bailing out the print when encountered
a corrupted or CRC error block, below is an example to reproduce the
segfault:

mkfs.xfs -f /dev/sda1
xfs_db -r -c "agf 0" -c "addr rmaproot" -c "p" /dev/sda1
Metadata CRC error detected at xfs_rmapbt block 0x0/0x1000
Segmentation fault (core dumped)

Signed-off-by: Shan Hai <shan.hai@oracle.com>
---
 db/print.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/db/print.c b/db/print.c
index e31372f..08bb39a 100644
--- a/db/print.c
+++ b/db/print.c
@@ -69,11 +69,19 @@ print_f(
 	char	**argv)
 {
 	pfunc_t	pf;
+	int err;
 
 	if (cur_typ == NULL) {
 		dbprintf(_("no current type\n"));
 		return 0;
 	}
+
+	err = iocur_top->bp->b_error;
+	if ((err == -EFSCORRUPTED) || (err == -EFSBADCRC)) {
+		dbprintf(_("data corrupted or CRC error\n"));
+		return 0;
+	}
+
 	pf = cur_typ->pfunc;
 	if (pf == NULL) {
 		dbprintf(_("no print function for type %s\n"), cur_typ->name);
-- 
2.7.4


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

* Re: [PATCH 1/1] xfsprogs/db: fix a segfault by bailing out the print on a corrupted block
  2017-04-07  7:49 ` [PATCH 1/1] xfsprogs/db: fix a segfault by bailing out the print on a corrupted block Shan Hai
@ 2017-04-07 17:23   ` Darrick J. Wong
  2017-04-07 19:31   ` Eric Sandeen
  1 sibling, 0 replies; 5+ messages in thread
From: Darrick J. Wong @ 2017-04-07 17:23 UTC (permalink / raw)
  To: Shan Hai; +Cc: linux-xfs

On Fri, Apr 07, 2017 at 03:49:04PM +0800, Shan Hai wrote:
> The print command of the xfs_db would cause segfault on a corrupted
> or CRC error block, fix it by bailing out the print when encountered
> a corrupted or CRC error block, below is an example to reproduce the
> segfault:
> 
> mkfs.xfs -f /dev/sda1
> xfs_db -r -c "agf 0" -c "addr rmaproot" -c "p" /dev/sda1
> Metadata CRC error detected at xfs_rmapbt block 0x0/0x1000
> Segmentation fault (core dumped)
> 
> Signed-off-by: Shan Hai <shan.hai@oracle.com>
> ---
>  db/print.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/db/print.c b/db/print.c
> index e31372f..08bb39a 100644
> --- a/db/print.c
> +++ b/db/print.c
> @@ -69,11 +69,19 @@ print_f(
>  	char	**argv)
>  {
>  	pfunc_t	pf;
> +	int err;
>  
>  	if (cur_typ == NULL) {
>  		dbprintf(_("no current type\n"));
>  		return 0;
>  	}
> +
> +	err = iocur_top->bp->b_error;
> +	if ((err == -EFSCORRUPTED) || (err == -EFSBADCRC)) {

The double parentheses aren't needed for integer comparison.

Also, no need to send a cover letter if you're only sending one patch.

--D

> +		dbprintf(_("data corrupted or CRC error\n"));
> +		return 0;
> +	}
> +
>  	pf = cur_typ->pfunc;
>  	if (pf == NULL) {
>  		dbprintf(_("no print function for type %s\n"), cur_typ->name);
> -- 
> 2.7.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 1/1] xfsprogs/db: fix a segfault by bailing out the print on a corrupted block
  2017-04-07  7:49 ` [PATCH 1/1] xfsprogs/db: fix a segfault by bailing out the print on a corrupted block Shan Hai
  2017-04-07 17:23   ` Darrick J. Wong
@ 2017-04-07 19:31   ` Eric Sandeen
  2017-04-07 23:35     ` Darrick J. Wong
  1 sibling, 1 reply; 5+ messages in thread
From: Eric Sandeen @ 2017-04-07 19:31 UTC (permalink / raw)
  To: Shan Hai, linux-xfs; +Cc: darrick.wong

On 4/7/17 2:49 AM, Shan Hai wrote:
> The print command of the xfs_db would cause segfault on a corrupted
> or CRC error block, fix it by bailing out the print when encountered
> a corrupted or CRC error block, below is an example to reproduce the
> segfault:
> 
> mkfs.xfs -f /dev/sda1
> xfs_db -r -c "agf 0" -c "addr rmaproot" -c "p" /dev/sda1
> Metadata CRC error detected at xfs_rmapbt block 0x0/0x1000
> Segmentation fault (core dumped)

Simply refusing to print any structure with corruption would
defeat the purpose of xfs_db, I think - it is difficult to
analyze a corrupted structure if you cannot examine it.

Today:

# xfs_db -x fsfile2
xfs_db> inode 128
xfs_db> write -c core.magic 0x4949
Allowing write of corrupted data and bad CRC
core.magic = 0x4949
xfs_db> quit

# xfs_db -x fsfile2
xfs_db> inode 128
Metadata corruption detected at xfs_inode block 0x80/0x2000
Metadata CRC error detected for ino 128
xfs_db> p core.magic
core.magic = 0x4949
xfs_db> 

i.e. we can read the structure and print the values even
if it is corrupted.

but with your change on the same damaged inode:

xfs_db> p core.magic
data corrupted or CRC error
xfs_db> 

That's not useful.

I think you need to find the root cause of the segfault, and handle
it if possible, instead of refusing to print any corrupted structures.

-Eric

> Signed-off-by: Shan Hai <shan.hai@oracle.com>
> ---
>  db/print.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/db/print.c b/db/print.c
> index e31372f..08bb39a 100644
> --- a/db/print.c
> +++ b/db/print.c
> @@ -69,11 +69,19 @@ print_f(
>  	char	**argv)
>  {
>  	pfunc_t	pf;
> +	int err;
>  
>  	if (cur_typ == NULL) {
>  		dbprintf(_("no current type\n"));
>  		return 0;
>  	}
> +
> +	err = iocur_top->bp->b_error;
> +	if ((err == -EFSCORRUPTED) || (err == -EFSBADCRC)) {
> +		dbprintf(_("data corrupted or CRC error\n"));
> +		return 0;
> +	}
> +
>  	pf = cur_typ->pfunc;
>  	if (pf == NULL) {
>  		dbprintf(_("no print function for type %s\n"), cur_typ->name);
> 

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

* Re: [PATCH 1/1] xfsprogs/db: fix a segfault by bailing out the print on a corrupted block
  2017-04-07 19:31   ` Eric Sandeen
@ 2017-04-07 23:35     ` Darrick J. Wong
  0 siblings, 0 replies; 5+ messages in thread
From: Darrick J. Wong @ 2017-04-07 23:35 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: Shan Hai, linux-xfs

On Fri, Apr 07, 2017 at 02:31:44PM -0500, Eric Sandeen wrote:
> On 4/7/17 2:49 AM, Shan Hai wrote:
> > The print command of the xfs_db would cause segfault on a corrupted
> > or CRC error block, fix it by bailing out the print when encountered
> > a corrupted or CRC error block, below is an example to reproduce the
> > segfault:
> > 
> > mkfs.xfs -f /dev/sda1
> > xfs_db -r -c "agf 0" -c "addr rmaproot" -c "p" /dev/sda1
> > Metadata CRC error detected at xfs_rmapbt block 0x0/0x1000
> > Segmentation fault (core dumped)
> 
> Simply refusing to print any structure with corruption would
> defeat the purpose of xfs_db, I think - it is difficult to
> analyze a corrupted structure if you cannot examine it.
> 
> Today:
> 
> # xfs_db -x fsfile2
> xfs_db> inode 128
> xfs_db> write -c core.magic 0x4949
> Allowing write of corrupted data and bad CRC
> core.magic = 0x4949
> xfs_db> quit
> 
> # xfs_db -x fsfile2
> xfs_db> inode 128
> Metadata corruption detected at xfs_inode block 0x80/0x2000
> Metadata CRC error detected for ino 128
> xfs_db> p core.magic
> core.magic = 0x4949
> xfs_db> 
> 
> i.e. we can read the structure and print the values even
> if it is corrupted.
> 
> but with your change on the same damaged inode:
> 
> xfs_db> p core.magic
> data corrupted or CRC error
> xfs_db> 
> 
> That's not useful.
> 
> I think you need to find the root cause of the segfault, and handle
> it if possible, instead of refusing to print any corrupted structures.

For corrupted btree blocks, the reason for the segfault is that we call
block_to_bt to find the btree geometry based on the magic number.  If
the block's magic number doesn't match any of the known btree magics, it
returns NULL and btblock_*_offset blow up on the NULL pointer.

The iocursor already knows the supposed type of the thing we're looking
at, so if we don't get a match on the magic number we could try using
the iocursor type to look up the supposed btree geometry, and use that
to print the btblock fields.

Of course once we do that we run into the next problem, which is that
when numrecs is too large, we happily print arrays right off the end of
the buffer and crash.

Eh, having worked all that out I might as well pretty the patches and
send them.

--D

> 
> -Eric
> 
> > Signed-off-by: Shan Hai <shan.hai@oracle.com>
> > ---
> >  db/print.c | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> > 
> > diff --git a/db/print.c b/db/print.c
> > index e31372f..08bb39a 100644
> > --- a/db/print.c
> > +++ b/db/print.c
> > @@ -69,11 +69,19 @@ print_f(
> >  	char	**argv)
> >  {
> >  	pfunc_t	pf;
> > +	int err;
> >  
> >  	if (cur_typ == NULL) {
> >  		dbprintf(_("no current type\n"));
> >  		return 0;
> >  	}
> > +
> > +	err = iocur_top->bp->b_error;
> > +	if ((err == -EFSCORRUPTED) || (err == -EFSBADCRC)) {
> > +		dbprintf(_("data corrupted or CRC error\n"));
> > +		return 0;
> > +	}
> > +
> >  	pf = cur_typ->pfunc;
> >  	if (pf == NULL) {
> >  		dbprintf(_("no print function for type %s\n"), cur_typ->name);
> > 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2017-04-07 23:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-07  7:49 [PATCH 0/1] xfsprogs/db: fix a segfault in the print command Shan Hai
2017-04-07  7:49 ` [PATCH 1/1] xfsprogs/db: fix a segfault by bailing out the print on a corrupted block Shan Hai
2017-04-07 17:23   ` Darrick J. Wong
2017-04-07 19:31   ` Eric Sandeen
2017-04-07 23:35     ` Darrick J. Wong

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.