btrfs: Fix wild pointer reference in btrfs_set_buffer_lockdep_class
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.
Signed-off-by Ye Bin <[email protected]>
--- fs/btrfs/disk-io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/disk-io.c +2 -2
@@ -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
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->keyswill 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'.