提交 c340b1d6 编写于 作者: T Timo Warns 提交者: Linus Torvalds

fs/partitions/ldm.c: fix oops caused by corrupted partition table

The kernel automatically evaluates partition tables of storage devices.
The code for evaluating LDM partitions (in fs/partitions/ldm.c) contains
a bug that causes a kernel oops on certain corrupted LDM partitions.
A kernel subsystem seems to crash, because, after the oops, the kernel no
longer recognizes newly connected storage devices.

The patch validates the value of vblk_size.

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: NTimo Warns <warns@pre-sense.de>
Cc: Eugene Teo <eugeneteo@kernel.sg>
Cc: Harvey Harrison <harvey.harrison@gmail.com>
Cc: Richard Russon <rich@flatcap.org>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 c344180c
...@@ -1299,6 +1299,11 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags) ...@@ -1299,6 +1299,11 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
BUG_ON (!data || !frags); BUG_ON (!data || !frags);
if (size < 2 * VBLK_SIZE_HEAD) {
ldm_error("Value of size is to small.");
return false;
}
group = get_unaligned_be32(data + 0x08); group = get_unaligned_be32(data + 0x08);
rec = get_unaligned_be16(data + 0x0C); rec = get_unaligned_be16(data + 0x0C);
num = get_unaligned_be16(data + 0x0E); num = get_unaligned_be16(data + 0x0E);
...@@ -1306,6 +1311,10 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags) ...@@ -1306,6 +1311,10 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
ldm_error ("A VBLK claims to have %d parts.", num); ldm_error ("A VBLK claims to have %d parts.", num);
return false; return false;
} }
if (rec >= num) {
ldm_error("REC value (%d) exceeds NUM value (%d)", rec, num);
return false;
}
list_for_each (item, frags) { list_for_each (item, frags) {
f = list_entry (item, struct frag, list); f = list_entry (item, struct frag, list);
...@@ -1334,10 +1343,9 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags) ...@@ -1334,10 +1343,9 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
f->map |= (1 << rec); f->map |= (1 << rec);
if (num > 0) {
data += VBLK_SIZE_HEAD; data += VBLK_SIZE_HEAD;
size -= VBLK_SIZE_HEAD; size -= VBLK_SIZE_HEAD;
}
memcpy (f->data+rec*(size-VBLK_SIZE_HEAD)+VBLK_SIZE_HEAD, data, size); memcpy (f->data+rec*(size-VBLK_SIZE_HEAD)+VBLK_SIZE_HEAD, data, size);
return true; return true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册