Skip to contentSkip to conversation

xfs_metadump: ignore attr leaf with 0 entries

PATCH In review Eric Sandeen 2 participants 3 messages Feb 2, 2017 – Feb 16, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_metadump: ignore attr leaf with 0 entries

Another in the ongoing saga of attribute leaves with zero entries; in this case, if we try to metadump an inode with a zero-entries attribute leaf, the zeroing code will go off the rails and segfault at:

                memset(&entries[nentries], 0,
                       first_name - (char *)&entries[nentries]);

because first_name is null, and we try to memset a large (negative) number.

---

db/metadump.c +2 -1
index 38519f1..66952f6 100644
@@ -1654,7 +1654,8 @@ process_attr_block(
 	xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &hdr, leaf);
 
 	nentries = hdr.count;
-	if (nentries * sizeof(xfs_attr_leaf_entry_t) +
+	if (nentries == 0 ||
+	    nentries * sizeof(xfs_attr_leaf_entry_t) +
 			xfs_attr3_leaf_hdr_size(leaf) >
 				XFS_ATTR3_RMT_BUF_SPACE(mp, bs)) {
 		if (show_warnings)
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Eric Sandeen

Another in the ongoing saga of attribute leaves with zero entries; in this case, if we try to metadump an inode with a zero-entries attribute leaf, the zeroing code will go off the rails and segfault at:

                memset(&entries[nentries], 0,
                       first_name - (char *)&entries[nentries]);

because first_name is null, and we try to memset a large (negative) number.

So what /does/ get metadumped in the !nentries case? Is it the block header and whatever else happens to be on disk? I guess that's useful for diagnostic purposes, since we don't know what's really "stale" when the block is obviously bad. (I was eyeing zero_stale_data but then convinced myself it was fine to just exit.)

--D

Quoted 23 lines

---

db/metadump.c +2 -2
index 38519f1..66952f6 100644
@@ -1654,7 +1654,8 @@ process_attr_block(
 	xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &hdr, leaf);
 
 	nentries = hdr.count;
-	if (nentries * sizeof(xfs_attr_leaf_entry_t) +
+	if (nentries == 0 ||
+	    nentries * sizeof(xfs_attr_leaf_entry_t) +
 			xfs_attr3_leaf_hdr_size(leaf) >
 				XFS_ATTR3_RMT_BUF_SPACE(mp, bs)) {
 		if (show_warnings)
 
--

To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 6 lines · Darrick J. Wong
Quoted 5 lines · Eric Sandeen

Another in the ongoing saga of attribute leaves with zero entries; in this case, if we try to metadump an inode with a zero-entries attribute leaf, the zeroing code will go off the rails and segfault at:

Quoted 7 lines
Quoted 5 lines
                memset(&entries[nentries], 0,
                       first_name - (char *)&entries[nentries]);

because first_name is null, and we try to memset a large (negative) number.

So what /does/ get metadumped in the !nentries case?

Um, nothing, because it segfaults?

Oh you mean AFTER the patch. :P

Quoted 5 lines

Is it the block
header and whatever else happens to be on disk? I guess that's useful for diagnostic purposes, since we don't know what's really "stale" when the block is obviously bad. (I was eyeing zero_stale_data but then convinced myself it was fine to just exit.)

Hm, probably worth finding out what reall does happen for this block, but i'll go ahead & commit this for now just to avoid the segfault.

Quoted 1 line

thanks,
-Eric

Quoted 25 lines

--D

Quoted 23 lines

---

db/metadump.c +2 -2
index 38519f1..66952f6 100644
@@ -1654,7 +1654,8 @@ process_attr_block(
 	xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &hdr, leaf);
 
 	nentries = hdr.count;
-	if (nentries * sizeof(xfs_attr_leaf_entry_t) +
+	if (nentries == 0 ||
+	    nentries * sizeof(xfs_attr_leaf_entry_t) +
 			xfs_attr3_leaf_hdr_size(leaf) >
 				XFS_ATTR3_RMT_BUF_SPACE(mp, bs)) {
 		if (show_warnings)
 
--

To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html