diff options
author | Joe Thornber <ejt@redhat.com> | 2021-12-10 16:44:13 +0300 |
---|---|---|
committer | Mike Snitzer <snitzer@redhat.com> | 2022-01-04 21:56:03 +0300 |
commit | 85bca3c05b6cca31625437eedf2060e846c4bbad (patch) | |
tree | 14d1f97999ed6e45c2c4fe71aab6fa2f421bd395 | |
parent | c671ffa55d8b0dd3ed0a329e15dfe9c58f7483cd (diff) |
dm btree: add a defensive bounds check to insert_at()
Corrupt metadata could trigger an out of bounds write.
Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
-rw-r--r-- | drivers/md/persistent-data/dm-btree.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/drivers/md/persistent-data/dm-btree.c b/drivers/md/persistent-data/dm-btree.c index 0703ca7a7d9a..5ce64e93aae7 100644 --- a/drivers/md/persistent-data/dm-btree.c +++ b/drivers/md/persistent-data/dm-btree.c @@ -81,14 +81,16 @@ void inc_children(struct dm_transaction_manager *tm, struct btree_node *n, } static int insert_at(size_t value_size, struct btree_node *node, unsigned index, - uint64_t key, void *value) - __dm_written_to_disk(value) + uint64_t key, void *value) + __dm_written_to_disk(value) { uint32_t nr_entries = le32_to_cpu(node->header.nr_entries); + uint32_t max_entries = le32_to_cpu(node->header.max_entries); __le64 key_le = cpu_to_le64(key); if (index > nr_entries || - index >= le32_to_cpu(node->header.max_entries)) { + index >= max_entries || + nr_entries >= max_entries) { DMERR("too many entries in btree node for insert"); __dm_unbless_for_disk(value); return -ENOMEM; |