1From 879f57c3b1ff17b1ca0dbdc8aac9c7a814e876fc Mon Sep 17 00:00:00 2001
2From: Chrostoper Ertl <chertl@microsoft.com>
3Date: Thu, 28 Nov 2019 16:44:18 +0000
4Subject: [PATCH] fru: Fix buffer overflow in ipmi_spd_print_fru
5
6Partial fix for CVE-2020-5208, see
7https://github.com/ipmitool/ipmitool/security/advisories/GHSA-g659-9qxw-p7cp
8
9The `ipmi_spd_print_fru` function has a similar issue as the one fixed
10by the previous commit in `read_fru_area_section`. An initial request is
11made to get the `fru.size`, which is used as the size for the allocation
12of `spd_data`. Inside a loop, further requests are performed to get the
13copy sizes which are not checked before being used as the size for a
14copy into the buffer.
15
16[Retrieve from:
17https://github.com/ipmitool/ipmitool/commit/840fb1cbb4fb365cb9797300e3374d4faefcdb10]
18Signed-off-by: Heiko Thiery <heiko.thiery@gmail.com>
19---
20 lib/dimm_spd.c | 9 ++++++++-
21 1 file changed, 8 insertions(+), 1 deletion(-)
22
23diff --git a/lib/dimm_spd.c b/lib/dimm_spd.c
24index 41e30db..68f3b4f 100644
25--- a/lib/dimm_spd.c
26+++ b/lib/dimm_spd.c
27@@ -1621,7 +1621,7 @@ ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id)
28 	struct ipmi_rq req;
29 	struct fru_info fru;
30 	uint8_t *spd_data, msg_data[4];
31-	int len, offset;
32+	uint32_t len, offset;
33
34 	msg_data[0] = id;
35
36@@ -1697,6 +1697,13 @@ ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id)
37 		}
38
39 		len = rsp->data[0];
40+		if(rsp->data_len < 1
41+		   || len > rsp->data_len - 1
42+		   || len > fru.size - offset)
43+		{
44+			printf(" Not enough buffer size");
45+			return -1;
46+		}
47 		memcpy(&spd_data[offset], rsp->data + 1, len);
48 		offset += len;
49 	} while (offset < fru.size);
50--
512.20.1
52
53