From a41abea65d673d7c006dbde2ca832abdedd0bb2b Mon Sep 17 00:00:00 2001 From: Martin Roth Date: Mon, 23 Oct 2023 17:10:29 -0600 Subject: device/dram/ddr3.c: Check SPD byte before using as a divisor The Medium Time Base (MTB) value is calculated by dividing one SPD byte by another. Return an error if the divisor is zero before using the value for division. Found-by: Coverity Scan #1469303 Signed-off-by: Martin Roth Change-Id: Ic0a70291c42b5c2d21d65de92487b2dd88609983 Reviewed-on: https://review.coreboot.org/c/coreboot/+/78613 Reviewed-by: Patrick Rudolph Tested-by: build bot (Jenkins) Reviewed-by: Felix Singer --- src/device/dram/ddr3.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/device') diff --git a/src/device/dram/ddr3.c b/src/device/dram/ddr3.c index 9e11ab57cc06..1fa3f4c3b2ba 100644 --- a/src/device/dram/ddr3.c +++ b/src/device/dram/ddr3.c @@ -422,6 +422,8 @@ int spd_xmp_decode_ddr3(struct dimm_attr_ddr3_st *dimm, spd_raw_data spd, /* Medium Timebase = * Medium Timebase (MTB) Dividend / * Medium Timebase (MTB) Divisor */ + if (spd[181] == 0) // Avoid dividing by zero. + return SPD_STATUS_INVALID; mtb = (((u32)spd[180]) << 8) / spd[181]; dimm->dimms_per_channel = ((spd[178] >> 2) & 0x3) + 1; @@ -437,6 +439,8 @@ int spd_xmp_decode_ddr3(struct dimm_attr_ddr3_st *dimm, spd_raw_data spd, /* Medium Timebase = * Medium Timebase (MTB) Dividend / * Medium Timebase (MTB) Divisor */ + if (spd[183] == 0) // Avoid dividing by zero. + return SPD_STATUS_INVALID; mtb = (((u32)spd[182]) << 8) / spd[183]; dimm->dimms_per_channel = ((spd[178] >> 4) & 0x3) + 1; -- cgit v1.2.3