mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 18:47:22 +00:00
fru, sdr: Fix id_string buffer overflows
Final part of the fixes for CVE-2020-5208, see https://github.com/ipmitool/ipmitool/security/advisories/GHSA-g659-9qxw-p7cp 9 variants of stack buffer overflow when parsing `id_string` field of SDR records returned from `CMD_GET_SDR` command. SDR record structs have an `id_code` field, and an `id_string` `char` array. The length of `id_string` is calculated as `(id_code & 0x1f) + 1`, which can be larger than expected 16 characters (if `id_code = 0xff`, then length will be `(0xff & 0x1f) + 1 = 32`). In numerous places, this can cause stack buffer overflow when copying into fixed buffer of size `17` bytes from this calculated length.
This commit is contained in:
parent
d45572d71e
commit
7ccea283dd
@ -3078,7 +3078,7 @@ ipmi_fru_print(struct ipmi_intf * intf, struct sdr_record_fru_locator * fru)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
memset(desc, 0, sizeof(desc));
|
memset(desc, 0, sizeof(desc));
|
||||||
memcpy(desc, fru->id_string, fru->id_code & 0x01f);
|
memcpy(desc, fru->id_string, __min(fru->id_code & 0x01f, sizeof(desc)));
|
||||||
desc[fru->id_code & 0x01f] = 0;
|
desc[fru->id_code & 0x01f] = 0;
|
||||||
printf("FRU Device Description : %s (ID %d)\n", desc, fru->device_id);
|
printf("FRU Device Description : %s (ID %d)\n", desc, fru->device_id);
|
||||||
|
|
||||||
|
@ -2254,7 +2254,7 @@ ipmi_sdr_print_sensor_eventonly(struct ipmi_intf *intf,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
memset(desc, 0, sizeof (desc));
|
memset(desc, 0, sizeof (desc));
|
||||||
snprintf(desc, (sensor->id_code & 0x1f) + 1, "%s", sensor->id_string);
|
snprintf(desc, sizeof(desc), "%.*s", (sensor->id_code & 0x1f) + 1, sensor->id_string);
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
printf("Sensor ID : %s (0x%x)\n",
|
printf("Sensor ID : %s (0x%x)\n",
|
||||||
@ -2303,7 +2303,7 @@ ipmi_sdr_print_sensor_mc_locator(struct sdr_record_mc_locator *mc)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
memset(desc, 0, sizeof (desc));
|
memset(desc, 0, sizeof (desc));
|
||||||
snprintf(desc, (mc->id_code & 0x1f) + 1, "%s", mc->id_string);
|
snprintf(desc, sizeof(desc), "%.*s", (mc->id_code & 0x1f) + 1, mc->id_string);
|
||||||
|
|
||||||
if (verbose == 0) {
|
if (verbose == 0) {
|
||||||
if (csv_output)
|
if (csv_output)
|
||||||
@ -2394,7 +2394,7 @@ ipmi_sdr_print_sensor_generic_locator(struct sdr_record_generic_locator *dev)
|
|||||||
char desc[17];
|
char desc[17];
|
||||||
|
|
||||||
memset(desc, 0, sizeof (desc));
|
memset(desc, 0, sizeof (desc));
|
||||||
snprintf(desc, (dev->id_code & 0x1f) + 1, "%s", dev->id_string);
|
snprintf(desc, sizeof(desc), "%.*s", (dev->id_code & 0x1f) + 1, dev->id_string);
|
||||||
|
|
||||||
if (!verbose) {
|
if (!verbose) {
|
||||||
if (csv_output)
|
if (csv_output)
|
||||||
@ -2449,7 +2449,7 @@ ipmi_sdr_print_sensor_fru_locator(struct sdr_record_fru_locator *fru)
|
|||||||
char desc[17];
|
char desc[17];
|
||||||
|
|
||||||
memset(desc, 0, sizeof (desc));
|
memset(desc, 0, sizeof (desc));
|
||||||
snprintf(desc, (fru->id_code & 0x1f) + 1, "%s", fru->id_string);
|
snprintf(desc, sizeof(desc), "%.*s", (fru->id_code & 0x1f) + 1, fru->id_string);
|
||||||
|
|
||||||
if (!verbose) {
|
if (!verbose) {
|
||||||
if (csv_output)
|
if (csv_output)
|
||||||
@ -2634,35 +2634,43 @@ ipmi_sdr_print_name_from_rawentry(uint16_t id,
|
|||||||
|
|
||||||
int rc =0;
|
int rc =0;
|
||||||
char desc[17];
|
char desc[17];
|
||||||
|
const char *id_string;
|
||||||
|
uint8_t id_code;
|
||||||
memset(desc, ' ', sizeof (desc));
|
memset(desc, ' ', sizeof (desc));
|
||||||
|
|
||||||
switch ( type) {
|
switch ( type) {
|
||||||
case SDR_RECORD_TYPE_FULL_SENSOR:
|
case SDR_RECORD_TYPE_FULL_SENSOR:
|
||||||
record.full = (struct sdr_record_full_sensor *) raw;
|
record.full = (struct sdr_record_full_sensor *) raw;
|
||||||
snprintf(desc, (record.full->id_code & 0x1f) +1, "%s",
|
id_code = record.full->id_code;
|
||||||
(const char *)record.full->id_string);
|
id_string = record.full->id_string;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDR_RECORD_TYPE_COMPACT_SENSOR:
|
case SDR_RECORD_TYPE_COMPACT_SENSOR:
|
||||||
record.compact = (struct sdr_record_compact_sensor *) raw ;
|
record.compact = (struct sdr_record_compact_sensor *) raw ;
|
||||||
snprintf(desc, (record.compact->id_code & 0x1f) +1, "%s",
|
id_code = record.compact->id_code;
|
||||||
(const char *)record.compact->id_string);
|
id_string = record.compact->id_string;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDR_RECORD_TYPE_EVENTONLY_SENSOR:
|
case SDR_RECORD_TYPE_EVENTONLY_SENSOR:
|
||||||
record.eventonly = (struct sdr_record_eventonly_sensor *) raw ;
|
record.eventonly = (struct sdr_record_eventonly_sensor *) raw ;
|
||||||
snprintf(desc, (record.eventonly->id_code & 0x1f) +1, "%s",
|
id_code = record.eventonly->id_code;
|
||||||
(const char *)record.eventonly->id_string);
|
id_string = record.eventonly->id_string;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDR_RECORD_TYPE_MC_DEVICE_LOCATOR:
|
case SDR_RECORD_TYPE_MC_DEVICE_LOCATOR:
|
||||||
record.mcloc = (struct sdr_record_mc_locator *) raw ;
|
record.mcloc = (struct sdr_record_mc_locator *) raw ;
|
||||||
snprintf(desc, (record.mcloc->id_code & 0x1f) +1, "%s",
|
id_code = record.mcloc->id_code;
|
||||||
(const char *)record.mcloc->id_string);
|
id_string = record.mcloc->id_string;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
rc = -1;
|
rc = -1;
|
||||||
break;
|
}
|
||||||
}
|
if (!rc) {
|
||||||
|
snprintf(desc, sizeof(desc), "%.*s", (id_code & 0x1f) + 1, id_string);
|
||||||
|
}
|
||||||
|
|
||||||
lprintf(LOG_INFO, "ID: 0x%04x , NAME: %-16s", id, desc);
|
lprintf(LOG_INFO, "ID: 0x%04x , NAME: %-16s", id, desc);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user