net: sunrpc: fix slab-out-of-bounds read in cache_seq_start_rcu
Subsystems (4)
PATCH 1/1 net: sunrpc: fix slab-out-of-bounds read in cache_seq_start_rcu
Syzbot reported slab-out-of-bounds read in cache_seq_start_rcu().
The issue happens in function __cache_seq_start() when is invoked hlist_for_each_entry_rcu() and the hash value is greater than the hash_size.
This fix verifies that the hash index is within the hash_size value before dereferencing the hash table: if the hash index is out of bounds return NULL, otherwise access the value.
--- net/sunrpc/cache.c | 3 +++ 1 file changed, 3 insertions(+)
net/sunrpc/cache.c +3 -0
@@ -1348,6 +1348,9 @@ static void *__cache_seq_start(struct seq_file *m, loff_t *pos) hash = n >>32 ; entry = n & ((1LL <<32 ) -1 ); +if (hash >= cd->hash_size) +return NULL ; +hlist_for_each_entry_rcu (ch, &cd->hash_table[hash], cache_list)if (!entry--)return ch;
Signature · 1 line
2.47.3
Chuck Lever
maintainerQuoted 33 lines · Alessandro Zanni
Syzbot reported slab-out-of-bounds read in
cache_seq_start_rcu().The issue happens in function
__cache_seq_start()when is invokedhlist_for_each_entry_rcu()and the hash value is greater than thehash_size.This fix verifies that the hash index is within the
hash_sizevalue before dereferencing the hash table: if the hash index is out of bounds return NULL, otherwise access the value.Fixes ae74136b4bb6 ("SUNRPC: Allow cache lookups to use RCU protectionrather than the r/w spinlock")
Reported-by [email protected]Signed-off-by Alessandro Zanni <[email protected]>--- net/sunrpc/cache.c | 3 +++ 1 file changed, 3 insertions(+)net/sunrpc/cache.c +3
-0@@ -1348,6 +1348,9 @@ static void *__cache_seq_start(struct seq_file *m, loff_t *pos) hash = n >>32 ; entry = n & ((1LL <<32 ) -1 ); +if (hash >= cd->hash_size) +return NULL ; +hlist_for_each_entry_rcu (ch, &cd->hash_table[hash], cache_list)if (!entry--)
Quoted 3 lines
return ch;
Signature · 1 line
2.47.3
Thank you for the patch! We have this fixed in the nfsd-testing tree already:
Signature · 1 line
Chuck Lever