blob: b5ce9e92ececfee6f4eba39ec7a3822254fe2257 [file] [log] [blame]
Andrew Geissler82c905d2020-04-13 13:39:40 -05001From e6aa6076f65e71544bd6450d20d943d7baaccb9f Mon Sep 17 00:00:00 2001
2From: Chrostoper Ertl <chertl@microsoft.com>
3Date: Thu, 28 Nov 2019 17:06:39 +0000
4Subject: [PATCH 4/5] 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
13responses `data_len`, which it then returns to caller functions, where
14stack buffer overflow can occur.
15
16Upstream-Status: Backport[https://github.com/ipmitool/ipmitool/commit/d45572d71e70840e0d4c50bf48218492b79c1a10]
17CVE: CVE-2020-5208
18
19[Make some changes to apply it]
20Signed-off-by: Wenlin Kang <wenlin.kang@windriver.com>
21---
22 lib/ipmi_lanp.c | 14 +++++++-------
23 1 file changed, 7 insertions(+), 7 deletions(-)
24
25diff --git a/lib/ipmi_lanp.c b/lib/ipmi_lanp.c
26index 060e753..dee21ee 100644
27--- a/lib/ipmi_lanp.c
28+++ b/lib/ipmi_lanp.c
29@@ -1917,7 +1917,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
30 if (p == NULL) {
31 return (-1);
32 }
33- memcpy(data, p->data, p->data_len);
34+ memcpy(data, p->data, __min(p->data_len, sizeof(data)));
35 /* set new ipaddr */
36 memcpy(data+3, temp, 4);
37 printf("Setting LAN Alert %d IP Address to %d.%d.%d.%d\n", alert,
38@@ -1932,7 +1932,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
39 if (p == NULL) {
40 return (-1);
41 }
42- memcpy(data, p->data, p->data_len);
43+ memcpy(data, p->data, __min(p->data_len, sizeof(data)));
44 /* set new macaddr */
45 memcpy(data+7, temp, 6);
46 printf("Setting LAN Alert %d MAC Address to "
47@@ -1947,7 +1947,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
48 if (p == NULL) {
49 return (-1);
50 }
51- memcpy(data, p->data, p->data_len);
52+ memcpy(data, p->data, __min(p->data_len, sizeof(data)));
53
54 if (strncasecmp(argv[1], "def", 3) == 0 ||
55 strncasecmp(argv[1], "default", 7) == 0) {
56@@ -1973,7 +1973,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
57 if (p == NULL) {
58 return (-1);
59 }
60- memcpy(data, p->data, p->data_len);
61+ memcpy(data, p->data, __min(p->data_len, sizeof(data)));
62
63 if (strncasecmp(argv[1], "on", 2) == 0 ||
64 strncasecmp(argv[1], "yes", 3) == 0) {
65@@ -1998,7 +1998,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
66 if (p == NULL) {
67 return (-1);
68 }
69- memcpy(data, p->data, p->data_len);
70+ memcpy(data, p->data, __min(p->data_len, sizeof(data)));
71
72 if (strncasecmp(argv[1], "pet", 3) == 0) {
73 printf("Setting LAN Alert %d destination to PET Trap\n", alert);
74@@ -2026,7 +2026,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
75 if (p == NULL) {
76 return (-1);
77 }
78- memcpy(data, p->data, p->data_len);
79+ memcpy(data, p->data, __min(p->data_len, sizeof(data)));
80
81 if (str2uchar(argv[1], &data[2]) != 0) {
82 lprintf(LOG_ERR, "Invalid time: %s", argv[1]);
83@@ -2042,7 +2042,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
84 if (p == NULL) {
85 return (-1);
86 }
87- memcpy(data, p->data, p->data_len);
88+ memcpy(data, p->data, __min(p->data_len, sizeof(data)));
89
90 if (str2uchar(argv[1], &data[3]) != 0) {
91 lprintf(LOG_ERR, "Invalid retry: %s", argv[1]);
92--
931.9.1
94