1From ceebf5998b71e11c81133680560b498977d3d3cd Mon Sep 17 00:00:00 2001 2From: Chrostoper Ertl <chertl@microsoft.com> 3Date: Thu, 28 Nov 2019 17:06:39 +0000 4Subject: [PATCH] lanp: Fix buffer overflows in get_lan_param_select 5MIME-Version: 1.0 6Content-Type: text/plain; charset=UTF-8 7Content-Transfer-Encoding: 8bit 8 9Partial fix for CVE-2020-5208, see 10https://github.com/ipmitool/ipmitool/security/advisories/GHSA-g659-9qxw-p7cp 11 12The `get_lan_param_select` function is missing a validation check on the 13response’s `data_len`, which it then returns to caller functions, where 14stack buffer overflow can occur. 15 16[Retrieve from: 17https://github.com/ipmitool/ipmitool/commit/d45572d71e70840e0d4c50bf48218492b79c1a10] 18Signed-off-by: Heiko Thiery <heiko.thiery@gmail.com> 19--- 20 lib/ipmi_lanp.c | 14 +++++++------- 21 1 file changed, 7 insertions(+), 7 deletions(-) 22 23diff --git a/lib/ipmi_lanp.c b/lib/ipmi_lanp.c 24index 65d881b..022c7f1 100644 25--- a/lib/ipmi_lanp.c 26+++ b/lib/ipmi_lanp.c 27@@ -1809,7 +1809,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert, 28 if (p == NULL) { 29 return (-1); 30 } 31- memcpy(data, p->data, p->data_len); 32+ memcpy(data, p->data, __min(p->data_len, sizeof(data))); 33 /* set new ipaddr */ 34 memcpy(data+3, temp, 4); 35 printf("Setting LAN Alert %d IP Address to %d.%d.%d.%d\n", alert, 36@@ -1824,7 +1824,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert, 37 if (p == NULL) { 38 return (-1); 39 } 40- memcpy(data, p->data, p->data_len); 41+ memcpy(data, p->data, __min(p->data_len, sizeof(data))); 42 /* set new macaddr */ 43 memcpy(data+7, temp, 6); 44 printf("Setting LAN Alert %d MAC Address to " 45@@ -1838,7 +1838,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert, 46 if (p == NULL) { 47 return (-1); 48 } 49- memcpy(data, p->data, p->data_len); 50+ memcpy(data, p->data, __min(p->data_len, sizeof(data))); 51 52 if (strncasecmp(argv[1], "def", 3) == 0 || 53 strncasecmp(argv[1], "default", 7) == 0) { 54@@ -1864,7 +1864,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert, 55 if (p == NULL) { 56 return (-1); 57 } 58- memcpy(data, p->data, p->data_len); 59+ memcpy(data, p->data, __min(p->data_len, sizeof(data))); 60 61 if (strncasecmp(argv[1], "on", 2) == 0 || 62 strncasecmp(argv[1], "yes", 3) == 0) { 63@@ -1889,7 +1889,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert, 64 if (p == NULL) { 65 return (-1); 66 } 67- memcpy(data, p->data, p->data_len); 68+ memcpy(data, p->data, __min(p->data_len, sizeof(data))); 69 70 if (strncasecmp(argv[1], "pet", 3) == 0) { 71 printf("Setting LAN Alert %d destination to PET Trap\n", alert); 72@@ -1917,7 +1917,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert, 73 if (p == NULL) { 74 return (-1); 75 } 76- memcpy(data, p->data, p->data_len); 77+ memcpy(data, p->data, __min(p->data_len, sizeof(data))); 78 79 if (str2uchar(argv[1], &data[2]) != 0) { 80 lprintf(LOG_ERR, "Invalid time: %s", argv[1]); 81@@ -1933,7 +1933,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert, 82 if (p == NULL) { 83 return (-1); 84 } 85- memcpy(data, p->data, p->data_len); 86+ memcpy(data, p->data, __min(p->data_len, sizeof(data))); 87 88 if (str2uchar(argv[1], &data[3]) != 0) { 89 lprintf(LOG_ERR, "Invalid retry: %s", argv[1]); 90-- 912.20.1 92 93