summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikulas Patocka <mpatocka@redhat.com>2021-05-10 14:49:05 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-05-26 11:27:32 +0200
commit6353b35c47118474d86945e79edc4685f7bc8631 (patch)
tree420c4ac642cb3c1dece209492bd6d6697722ed24
parent3e01c5c20452a385e70888cfb465e0359ffa54ad (diff)
downloadlinux-stable-6353b35c47118474d86945e79edc4685f7bc8631.tar.gz
linux-stable-6353b35c47118474d86945e79edc4685f7bc8631.tar.bz2
linux-stable-6353b35c47118474d86945e79edc4685f7bc8631.zip
dm snapshot: fix crash with transient storage and zero chunk size
commit c699a0db2d62e3bbb7f0bf35c87edbc8d23e3062 upstream. The following commands will crash the kernel: modprobe brd rd_size=1048576 dmsetup create o --table "0 `blockdev --getsize /dev/ram0` snapshot-origin /dev/ram0" dmsetup create s --table "0 `blockdev --getsize /dev/ram0` snapshot /dev/ram0 /dev/ram1 N 0" The reason is that when we test for zero chunk size, we jump to the label bad_read_metadata without setting the "r" variable. The function snapshot_ctr destroys all the structures and then exits with "r == 0". The kernel then crashes because it falsely believes that snapshot_ctr succeeded. In order to fix the bug, we set the variable "r" to -EINVAL. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Cc: stable@vger.kernel.org Signed-off-by: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/md/dm-snap.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index 510b0cf430a8..2a1a7025b4b9 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -1265,6 +1265,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
if (!s->store->chunk_size) {
ti->error = "Chunk size not set";
+ r = -EINVAL;
goto bad_read_metadata;
}