Skip to contentSkip to conversation

xfs_check: fix test for too-high level in v2 dir node

PATCH In review Eric Sandeen 3 participants 5 messages Sep 12, 2013 – Sep 23, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_check: fix test for too-high level in v2 dir node

The test as it stands allows level == XFS_DA_NODE_MAXDEPTH (5), but a max depth of 5 equates to level values of 0 through 4.

Level 5 would be a depth of 6.

---

db/check.c +1 -1
index cbe55ba..d9e3e3f 100644
@@ -3138,7 +3138,7 @@ process_leaf_node_dir_v2_int(
 	case XFS_DA_NODE_MAGIC:
 		node = iocur_top->data;
 		xfs_da3_node_hdr_from_disk(&nodehdr, node);
-		if (nodehdr.level < 1 || nodehdr.level > XFS_DA_NODE_MAXDEPTH) {
+		if (nodehdr.level < 1 || nodehdr.level >= XFS_DA_NODE_MAXDEPTH) {
 			if (!sflag || v)
 				dbprintf(_("bad node block level %d for dir ino "
 					 "%lld block %d\n"),

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#1 lore raw
Quoted 14 lines · Eric Sandeen

The test as it stands allows level == XFS_DA_NODE_MAXDEPTH (5), but a max depth of 5 equates to level values of 0 through 4.

Level 5 would be a depth of 6.

---

db/check.c +0 -0
index cbe55ba..d9e3e3f 100644

db/check.c process_leaf_node_dir_v2_int( · line 3144

Quoted 8 lines
db/check.c +1 -1
@@ -3138,7 +3138,7 @@ process_leaf_node_dir_v2_int(
  	case XFS_DA_NODE_MAGIC:
  		node = iocur_top->data;
  		xfs_da3_node_hdr_from_disk(&nodehdr, node);
-		if (nodehdr.level<  1 || nodehdr.level>  XFS_DA_NODE_MAXDEPTH) {
+		if (nodehdr.level<  1 || nodehdr.level>= XFS_DA_NODE_MAXDEPTH) {
  			if (!sflag || v)
  				dbprintf(_("bad node block level %d for dir ino "
  					 "%lld block %d\n"),

I think the current code is correct.

0 is a leaf. levels 1-XFS_DA_NODE_MAXDEPTH are nodes. Subtract 1 when used as an index.

--Mark.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#2 lore raw
Quoted 27 lines · Mark Tinguely
Quoted 14 lines · Eric Sandeen

The test as it stands allows level == XFS_DA_NODE_MAXDEPTH (5), but a max depth of 5 equates to level values of 0 through 4.

Level 5 would be a depth of 6.

---

db/check.c +0 -0
index cbe55ba..d9e3e3f 100644

db/check.c process_leaf_node_dir_v2_int( · line 3144

Quoted 8 lines
db/check.c +1 -1
@@ -3138,7 +3138,7 @@ process_leaf_node_dir_v2_int(
      case XFS_DA_NODE_MAGIC:
          node = iocur_top->data;
          xfs_da3_node_hdr_from_disk(&nodehdr, node);
-        if (nodehdr.level<  1 || nodehdr.level>  XFS_DA_NODE_MAXDEPTH) {
+        if (nodehdr.level<  1 || nodehdr.level>= XFS_DA_NODE_MAXDEPTH) {
              if (!sflag || v)
                  dbprintf(_("bad node block level %d for dir ino "
                       "%lld block %d\n"),

I think the current code is correct.

Quoted 2 lines

0 is a leaf. levels 1-XFS_DA_NODE_MAXDEPTH are nodes. Subtract 1 when used as an index.

        case XFS_DA_NODE_MAGIC:
                node = iocur_top->data;
                xfs_da3_node_hdr_from_disk(&nodehdr, node);
			to->level = be16_to_cpu(from->hdr.__level);
                if (nodehdr.level < 1 || nodehdr.level > XFS_DA_NODE_MAXDEPTH) {

so nodehdr.level comes directly off the disk.

Hm, ok, let's look at the verifier, xfs_da3_node_verify:

xfs_da3_node_hdr_from_disk /* sets to->level = be16_to_cpu(from->hdr.__level) */

...

        if (ichdr.level == 0)
                return false;
        if (ichdr.level > XFS_DA_NODE_MAXDEPTH)
                return false;

ok, so 1 through XFS_DA_NODE_MAXDEPTH is valid for a generic node. *shrug* ok fine, I agree. It's only xfs_check anyway. ;)

Feel free to drop this patch then.

But now I'm trying to reconcile it w/ the code in repair,

 			i = da_cursor->active = nodehdr.level;
			if (i < 1 || i >= XFS_DA_NODE_MAXDEPTH) {

which considers nodehdr.level == XFS_DA_NODE_MAXDEPTH to be problematic, because i (== nodehdr.level) is used directly as an index into a level[XFS_DA_NODE_MAXDEPTH]-sized array.

So confused. :/ (Maybe the cursor array needs to be 1 bigger?)

-Eric

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw
Quoted 9 lines · Eric Sandeen
Quoted 8 lines · Mark Tinguely
Quoted 7 lines · Eric Sandeen

The test as it stands allows level == XFS_DA_NODE_MAXDEPTH (5), but a max depth of 5 equates to level values of 0 through 4.

Level 5 would be a depth of 6.

---

...

Quoted 5 lines
Quoted 1 line

I think the current code is correct.

So confused. :/ (Maybe the cursor array needs to be 1 bigger?)

-Eric

Well, I am frequently noted as being permanently confused!

I was referring to the kernel use of XFS_DA_NODE_MAXDEPTH. All the comparison indicate that having a value of 1 to XFS_DA_NODE_MAXDEPTH as being okay.

When it accesses the xfs_da_state_blk_t blk[XFS_DA_NODE_MAXDEPTH], it decrements the index first there is no blk[] entry for a leaf that is why it does not need another entry.

I need to study this more.

--Mark.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#4 lore raw
In reply to Eric Sandeen
Quoted 60 lines · Eric Sandeen
Quoted 27 lines · Mark Tinguely
Quoted 14 lines · Eric Sandeen

The test as it stands allows level == XFS_DA_NODE_MAXDEPTH (5), but a max depth of 5 equates to level values of 0 through 4.

Level 5 would be a depth of 6.

---

db/check.c +0 -0
index cbe55ba..d9e3e3f 100644

db/check.c process_leaf_node_dir_v2_int( · line 3144

Quoted 8 lines
db/check.c +1 -1
@@ -3138,7 +3138,7 @@ process_leaf_node_dir_v2_int(
       case XFS_DA_NODE_MAGIC:
           node = iocur_top->data;
           xfs_da3_node_hdr_from_disk(&nodehdr, node);
-        if (nodehdr.level <  1 || nodehdr.level >  XFS_DA_NODE_MAXDEPTH) {
+        if (nodehdr.level <  1 || nodehdr.level >= XFS_DA_NODE_MAXDEPTH) {
               if (!sflag || v)
                   dbprintf(_("bad node block level %d for dir ino "
                        "%lld block %d\n"),

I think the current code is correct.

Quoted 2 lines

0 is a leaf. levels 1-XFS_DA_NODE_MAXDEPTH are nodes. Subtract 1 when used as an index.

         case XFS_DA_NODE_MAGIC:
                 node = iocur_top->data;
                 xfs_da3_node_hdr_from_disk(&nodehdr, node);
			to->level = be16_to_cpu(from->hdr.__level);
                 if (nodehdr.level < 1 || nodehdr.level > XFS_DA_NODE_MAXDEPTH) {

so nodehdr.level comes directly off the disk.

Hm, ok, let's look at the verifier, xfs_da3_node_verify:

xfs_da3_node_hdr_from_disk /* sets to->level = be16_to_cpu(from->hdr.__level) */

...

         if (ichdr.level == 0)
                 return false;
         if (ichdr.level > XFS_DA_NODE_MAXDEPTH)
                 return false;

ok, so 1 through XFS_DA_NODE_MAXDEPTH is valid for a generic node. *shrug* ok fine, I agree. It's only xfs_check anyway. ;)

Feel free to drop this patch then.

But now I'm trying to reconcile it w/ the code in repair,

  			i = da_cursor->active = nodehdr.level;
			if (i < 1 || i >= XFS_DA_NODE_MAXDEPTH) {
Quoted 7 lines

which considers nodehdr.level == XFS_DA_NODE_MAXDEPTH to be problematic, because i (== nodehdr.level) is used directly as an index into a level[XFS_DA_NODE_MAXDEPTH]-sized array.

So confused. :/ (Maybe the cursor array needs to be 1 bigger?)

-Eric

Strange, the kernel attribute asserts use XFS_DA_NODE_MAXDEPTH-1 as the maximum good value.

Looks like the repair code uses the cursor level[0], so we cannot index with (i - 1). I agree that the array in the da_bt_cursor should be one greater.

--Mark.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs