1*4882a593SmuzhiyunFrom a8cc95de74ccc3ad090e8062ac335c844f13c9f4 Mon Sep 17 00:00:00 2001
2*4882a593SmuzhiyunFrom: Daniel Axtens <dja@axtens.net>
3*4882a593SmuzhiyunDate: Thu, 21 Jan 2021 17:59:14 +1100
4*4882a593SmuzhiyunSubject: [PATCH] disk/lvm: Don't go beyond the end of the data we read from
5*4882a593Smuzhiyun disk
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunWe unconditionally trusted offset_xl from the LVM label header, even if
8*4882a593Smuzhiyunit told us that the PV header/disk locations were way off past the end
9*4882a593Smuzhiyunof the data we read from disk.
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunRequire that the offset be sane, fixing an OOB read and crash.
12*4882a593Smuzhiyun
13*4882a593SmuzhiyunFixes: CID 314367, CID 314371
14*4882a593Smuzhiyun
15*4882a593SmuzhiyunSigned-off-by: Daniel Axtens <dja@axtens.net>
16*4882a593SmuzhiyunReviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
17*4882a593SmuzhiyunSigned-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
18*4882a593Smuzhiyun---
19*4882a593Smuzhiyun grub-core/disk/lvm.c | 14 ++++++++++++++
20*4882a593Smuzhiyun 1 file changed, 14 insertions(+)
21*4882a593Smuzhiyun
22*4882a593Smuzhiyundiff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c
23*4882a593Smuzhiyunindex 139fafd..8136122 100644
24*4882a593Smuzhiyun--- a/grub-core/disk/lvm.c
25*4882a593Smuzhiyun+++ b/grub-core/disk/lvm.c
26*4882a593Smuzhiyun@@ -141,6 +141,20 @@ grub_lvm_detect (grub_disk_t disk,
27*4882a593Smuzhiyun       goto fail;
28*4882a593Smuzhiyun     }
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun+  /*
31*4882a593Smuzhiyun+   * We read a grub_lvm_pv_header and then 2 grub_lvm_disk_locns that
32*4882a593Smuzhiyun+   * immediately follow the PV header. Make sure we have space for both.
33*4882a593Smuzhiyun+   */
34*4882a593Smuzhiyun+  if (grub_le_to_cpu32 (lh->offset_xl) >=
35*4882a593Smuzhiyun+      GRUB_LVM_LABEL_SIZE - sizeof (struct grub_lvm_pv_header) -
36*4882a593Smuzhiyun+      2 * sizeof (struct grub_lvm_disk_locn))
37*4882a593Smuzhiyun+    {
38*4882a593Smuzhiyun+#ifdef GRUB_UTIL
39*4882a593Smuzhiyun+      grub_util_info ("LVM PV header/disk locations are beyond the end of the block");
40*4882a593Smuzhiyun+#endif
41*4882a593Smuzhiyun+      goto fail;
42*4882a593Smuzhiyun+    }
43*4882a593Smuzhiyun+
44*4882a593Smuzhiyun   pvh = (struct grub_lvm_pv_header *) (buf + grub_le_to_cpu32(lh->offset_xl));
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun   for (i = 0, j = 0; i < GRUB_LVM_ID_LEN; i++)
47*4882a593Smuzhiyun--
48*4882a593Smuzhiyun2.14.2
49*4882a593Smuzhiyun
50