Skip to content

Commit

Permalink
dm btree: add a defensive bounds check to insert_at()
Browse files Browse the repository at this point in the history
[ Upstream commit 85bca3c ]

Corrupt metadata could trigger an out of bounds write.

Signed-off-by: Joe Thornber <[email protected]>
Signed-off-by: Mike Snitzer <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
jthornber authored and gregkh committed Jan 27, 2022
1 parent 3c3417b commit b5aee20
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions drivers/md/persistent-data/dm-btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b5aee20

Please sign in to comment.