Skip to contentSkip to conversation

reiserfs: UBSAN: array-index-out-of-bounds in direntry_create_vi

PATCH In review Bragatheswaran Manickavel 1 participant 2 messages Oct 26, 2023 – Nov 4, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 reiserfs: UBSAN: array-index-out-of-bounds in direntry_create_vi

deh defined as an array of type __u16[], and issue is triggered when it's trying to access an element at index 1, which is out of bounds because the array has only one element at index 0.

---
 fs/reiserfs/item_ops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/reiserfs/item_ops.c +1 -1
index 3a5a752d96c7..ccf547c5e8e1 100644
@@ -484,7 +484,7 @@ static int direntry_create_vi(struct virtual_node *vn,
 				  vn->vn_mode);
 		dir_u->entry_sizes[i] =
 		    (j ? deh_location(&deh[j - 1]) : ih_item_len(vi->vi_ih)) -
-		    deh_location(&deh[j]) + DEH_SIZE;
+		    deh_location(&deh[j - 1]) + DEH_SIZE;
 	}
 
 	size += (dir_u->entry_count * sizeof(short));
Signature · 1 line
2.34.1
#1 lore raw
Quoted 17 lines · Bragatheswaran Manickavel

deh defined as an array of type __u16[], and issue is triggered when it's trying to access an element at index 1, which is out of bounds because the array has only one element at index 0.

---
  fs/reiserfs/item_ops.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/reiserfs/item_ops.c +0 -0
index 3a5a752d96c7..ccf547c5e8e1 100644

fs/reiserfs/item_ops.c static int direntry_create_vi(struct virtual_node *vn, · line 490

Quoted 8 lines
fs/reiserfs/item_ops.c +1 -1
@@ -484,7 +484,7 @@ static int direntry_create_vi(struct virtual_node *vn,
  				  vn->vn_mode);
  		dir_u->entry_sizes[i] =
  		    (j ? deh_location(&deh[j - 1]) : ih_item_len(vi->vi_ih)) -
-		    deh_location(&deh[j]) + DEH_SIZE;
+		    deh_location(&deh[j - 1]) + DEH_SIZE;
  	}
 
  	size += (dir_u->entry_count * sizeof(short));

Could someone help in reviewing the changes. I see reiserfs was marked with obsolete but still wanted to know whether this patch is correct and can be taken (if possible)

Thanks,
Bragathe