Skip to contentSkip to conversation

btrfs: Fix wild pointer reference in btrfs_set_buffer_lockdep_class

PATCH In review Ye Bin 2 participants 2 messages Sep 29, 2020 Btrfs file system

lore
Share & tools
lore

Ye Bin

author
#0 lore raw

PATCH 1/1 btrfs: Fix wild pointer reference in btrfs_set_buffer_lockdep_class

'ks' is pointer type, but not initialized, so ks->keys will reference wild pointer.

---
 fs/btrfs/disk-io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/disk-io.c +2 -2
index 177da507dc2a..7068d006d43f 100644
@@ -189,12 +189,12 @@ void __init btrfs_init_lockdep(void)
 void btrfs_set_buffer_lockdep_class(u64 objectid, struct extent_buffer *eb,
 				    int level)
 {
-	struct btrfs_lockdep_keyset *ks;
+	struct btrfs_lockdep_keyset *ks = btrfs_lockdep_keysets;
 
 	BUG_ON(level >= ARRAY_SIZE(ks->keys));
 
 	/* find the matching keyset, id 0 is the default entry */
-	for (ks = btrfs_lockdep_keysets; ks->id; ks++)
+	for (; ks->id; ks++)
 		if (ks->id == objectid)
 			break;
 
Signature · 1 line
2.25.4
#1 lore raw

fs/btrfs/disk-io.c void __init btrfs_init_lockdep(void) · line 194

Quoted 7 lines · Ye Bin

'ks' is pointer type, but not initialized, so ks->keys will reference wild pointer.

fs/btrfs/disk-io.c +1 -1
-	struct btrfs_lockdep_keyset *ks;
+	struct btrfs_lockdep_keyset *ks = btrfs_lockdep_keysets;
 
 	BUG_ON(level >= ARRAY_SIZE(ks->keys));

ARRAY_SIZE does not dereference the pointer, it uses only the type information, in this case 'struct btrfs_lockdep_keyset::keys'.