diff options
author | Mikulas Patocka <mpatocka@redhat.com> | 2019-08-23 09:54:09 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-08-29 08:30:25 +0200 |
commit | ace23a4553833ef8d0d5d8cc98296fadb72020ef (patch) | |
tree | 1ad6be75fae881fcba8caf37db0c082b0721e3f1 | |
parent | 23c9e199076aeda42e2657635daea30f22f6663b (diff) | |
download | linux-stable-ace23a4553833ef8d0d5d8cc98296fadb72020ef.tar.gz linux-stable-ace23a4553833ef8d0d5d8cc98296fadb72020ef.tar.bz2 linux-stable-ace23a4553833ef8d0d5d8cc98296fadb72020ef.zip |
dm table: fix invalid memory accesses with too high sector number
commit 1cfd5d3399e87167b7f9157ef99daa0e959f395d upstream.
If the sector number is too high, dm_table_find_target() should return a
pointer to a zeroed dm_target structure (the caller should test it with
dm_target_is_valid).
However, for some table sizes, the code in dm_table_find_target() that
performs btree lookup will access out of bound memory structures.
Fix this bug by testing the sector number at the beginning of
dm_table_find_target(). Also, add an "inline" keyword to the function
dm_table_get_size() because this is a hot path.
Fixes: 512875bd9661 ("dm: table detect io beyond device")
Cc: stable@vger.kernel.org
Reported-by: Zhang Tao <kontais@zoho.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/md/dm-table.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index ec8b27e20de3..c840c587083b 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1334,7 +1334,7 @@ void dm_table_event(struct dm_table *t) } EXPORT_SYMBOL(dm_table_event); -sector_t dm_table_get_size(struct dm_table *t) +inline sector_t dm_table_get_size(struct dm_table *t) { return t->num_targets ? (t->highs[t->num_targets - 1] + 1) : 0; } @@ -1359,6 +1359,9 @@ struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector) unsigned int l, n = 0, k = 0; sector_t *node; + if (unlikely(sector >= dm_table_get_size(t))) + return &t->targets[t->num_targets]; + for (l = 0; l < t->depth; l++) { n = get_child(n, k); node = get_node(t, l, n); |