John Zhao has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/32924
Change subject: soc/intel/common: Add negative sign check for variable bios_size ......................................................................
soc/intel/common: Add negative sign check for variable bios_size
Clang Static Analyzer found that the rounding operation of alignment=1UL<<(log2_ceil(bios_size)) is garbage or undefined if varialbe bios_size is negative. Add sanity check for bios_size to prevent rounding error.
Signed-off-by: John Zhao john.zhao@intel.com Change-Id: Ifc3f3da52d129ef5d6063a46b045603a236be759 --- M src/soc/intel/common/block/fast_spi/fast_spi.c 1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/24/32924/1
diff --git a/src/soc/intel/common/block/fast_spi/fast_spi.c b/src/soc/intel/common/block/fast_spi/fast_spi.c index 455b13c..560c75c 100644 --- a/src/soc/intel/common/block/fast_spi/fast_spi.c +++ b/src/soc/intel/common/block/fast_spi/fast_spi.c @@ -236,7 +236,7 @@ /* Only the IFD BIOS region is memory mapped (at top of 4G) */ fast_spi_get_bios_region(&bios_size);
- if (!bios_size) + if (!bios_size || (bios_size < 0)) return;
/* LOCAL APIC default address is 0xFEE0000, bios_size over 16MB will
Martin Roth has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32924 )
Change subject: soc/intel/common: Add negative sign check for variable bios_size ......................................................................
Patch Set 1:
(2 comments)
Should another variable type be used?
size_t should be unsigned, so I'm not sure why clang is complaining.
https://review.coreboot.org/#/c/32924/1//COMMIT_MSG Commit Message:
https://review.coreboot.org/#/c/32924/1//COMMIT_MSG@11 PS1, Line 11: varialbe variable
https://review.coreboot.org/#/c/32924/1/src/soc/intel/common/block/fast_spi/... File src/soc/intel/common/block/fast_spi/fast_spi.c:
https://review.coreboot.org/#/c/32924/1/src/soc/intel/common/block/fast_spi/... PS1, Line 239: (!bios_size || (bios_size < 0)) Make it one check? if (bios_size <= 0)
John Zhao has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32924 )
Change subject: soc/intel/common: Add negative sign check for variable bios_size ......................................................................
Set Ready For Review
John Zhao has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32924 )
Change subject: soc/intel/common: Add negative sign check for variable bios_size ......................................................................
Patch Set 2:
(3 comments)
https://review.coreboot.org/#/c/32924/1//COMMIT_MSG Commit Message:
https://review.coreboot.org/#/c/32924/1//COMMIT_MSG@11 PS1, Line 11: varialbe
variable
corrected.
https://review.coreboot.org/#/c/32924/1//COMMIT_MSG@14 PS1, Line 14: Signed-off-by: John Zhao john.zhao@intel.com
By default the Signed-off-by line is below the Change-Id line.
done.
https://review.coreboot.org/#/c/32924/1/src/soc/intel/common/block/fast_spi/... File src/soc/intel/common/block/fast_spi/fast_spi.c:
https://review.coreboot.org/#/c/32924/1/src/soc/intel/common/block/fast_spi/... PS1, Line 239: (!bios_size || (bios_size < 0))
Make it one check? […]
done.
Lance Zhao has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32924 )
Change subject: soc/intel/common: Add negative sign check for variable bios_size ......................................................................
Patch Set 2: Code-Review+2
Arthur Heymans has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32924 )
Change subject: soc/intel/common: Add negative sign check for variable bios_size ......................................................................
Patch Set 2: Code-Review-1
(1 comment)
https://review.coreboot.org/#/c/32924/2//COMMIT_MSG Commit Message:
https://review.coreboot.org/#/c/32924/2//COMMIT_MSG@9 PS2, Line 9: Clang Static Analyzer version 8.0.0 found that the rounding operation : of alignment=1UL<<(log2_ceil(bios_size)) is garbage or undefined if : variable bios_size is negative bios_size cannot be negative since it's type is unsigned. Clang static analyzer must be at fault here.
Martin Roth has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32924 )
Change subject: soc/intel/common: Add negative sign check for variable bios_size ......................................................................
Patch Set 2:
(1 comment)
https://review.coreboot.org/#/c/32924/2/src/soc/intel/common/block/fast_spi/... File src/soc/intel/common/block/fast_spi/fast_spi.c:
https://review.coreboot.org/#/c/32924/2/src/soc/intel/common/block/fast_spi/... PS2, Line 249: It's actually not bios_size that's causing the issue, but log2_ceil itself. If bios_size is 0, log2_ceil returns -1. I think that's where the error comes from, not from bios_size being <0 which as stated doesn't make sense. We've already checked to make sure that bios size isn't 0 above, but then we set bios_size again with MIN() I think that's what's confusing the compiler. Let's just move the if (!bios_size) below the MIN() - I bet that will take care of it.
/* LOCAL APIC default address is 0xFEE0000, bios_size over 16MB will * cause memory type conflict when setting memory type to write * protection, so limit the cached bios region to be no more than 16MB. * */ bios_size = MIN(bios_size, 16 * MiB);
if (!bios_size) return;
/* Round to power of two */ alignment = 1UL << (log2_ceil(bios_size));
Hello Patrick Rudolph, Arthur Heymans, Balaji Manigandan, Lance Zhao, build bot (Jenkins), Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/32924
to look at the new patch set (#3).
Change subject: soc/intel/common: Check variable bios_size after MIN operation ......................................................................
soc/intel/common: Check variable bios_size after MIN operation
Clang Static Analyzer version 8.0.0 found that the rounding operation of alignment=1UL<<(log2_ceil(bios_size)) is garbage or undefined if variable bios_size is zero. Move sanity check for bios_size after MIN operation to prevent rounding error.
TEST=Built and boot up to kernel.
Change-Id: Ifc3f3da52d129ef5d6063a46b045603a236be759 Signed-off-by: John Zhao john.zhao@intel.com --- M src/soc/intel/common/block/fast_spi/fast_spi.c 1 file changed, 2 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/24/32924/3
John Zhao has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32924 )
Change subject: soc/intel/common: Check variable bios_size after MIN operation ......................................................................
Patch Set 3:
(1 comment)
https://review.coreboot.org/#/c/32924/2/src/soc/intel/common/block/fast_spi/... File src/soc/intel/common/block/fast_spi/fast_spi.c:
https://review.coreboot.org/#/c/32924/2/src/soc/intel/common/block/fast_spi/... PS2, Line 249:
It's actually not bios_size that's causing the issue, but log2_ceil itself. […]
done.
Hello Patrick Rudolph, Arthur Heymans, Balaji Manigandan, Lance Zhao, build bot (Jenkins), Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/32924
to look at the new patch set (#4).
Change subject: soc/intel/common: Check bios_size and window_size after MIN operation ......................................................................
soc/intel/common: Check bios_size and window_size after MIN operation
Clang Static Analyzer version 8.0.0 detects that log2_ceil(bios_size) and log2_ceil(window_size) are garbage or undefined if the value of bios_size and window_size is zero. Check bios_size and window_size after MIN operation to prevent error.
TEST=Built and boot up to kernel.
Change-Id: Ifc3f3da52d129ef5d6063a46b045603a236be759 Signed-off-by: John Zhao john.zhao@intel.com --- M src/soc/intel/common/block/fast_spi/fast_spi.c M src/soc/intel/common/block/lpc/lpc_lib.c 2 files changed, 5 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/24/32924/4
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32924 )
Change subject: soc/intel/common: Check bios_size and window_size after MIN operation ......................................................................
Patch Set 4:
(1 comment)
https://review.coreboot.org/#/c/32924/4/src/soc/intel/common/block/lpc/lpc_l... File src/soc/intel/common/block/lpc/lpc_lib.c:
https://review.coreboot.org/#/c/32924/4/src/soc/intel/common/block/lpc/lpc_l... PS4, Line 85: trailing whitespace
Hello Patrick Rudolph, Arthur Heymans, Balaji Manigandan, Lance Zhao, build bot (Jenkins), Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/32924
to look at the new patch set (#5).
Change subject: soc/intel/common: Check bios_size and window_size after MIN operation ......................................................................
soc/intel/common: Check bios_size and window_size after MIN operation
Clang Static Analyzer version 8.0.0 detects that log2_ceil(bios_size) and log2_ceil(window_size) are garbage or undefined if the value of bios_size and window_size is zero. Check bios_size and window_size after MIN operation to prevent error.
TEST=Built and boot up to kernel.
Change-Id: Ifc3f3da52d129ef5d6063a46b045603a236be759 Signed-off-by: John Zhao john.zhao@intel.com --- M src/soc/intel/common/block/fast_spi/fast_spi.c M src/soc/intel/common/block/lpc/lpc_lib.c 2 files changed, 5 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/24/32924/5
Duncan Laurie has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32924 )
Change subject: soc/intel/common: Check bios_size and window_size after MIN operation ......................................................................
Patch Set 5: Code-Review+2
Patrick Georgi has submitted this change and it was merged. ( https://review.coreboot.org/c/coreboot/+/32924 )
Change subject: soc/intel/common: Check bios_size and window_size after MIN operation ......................................................................
soc/intel/common: Check bios_size and window_size after MIN operation
Clang Static Analyzer version 8.0.0 detects that log2_ceil(bios_size) and log2_ceil(window_size) are garbage or undefined if the value of bios_size and window_size is zero. Check bios_size and window_size after MIN operation to prevent error.
TEST=Built and boot up to kernel.
Change-Id: Ifc3f3da52d129ef5d6063a46b045603a236be759 Signed-off-by: John Zhao john.zhao@intel.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/32924 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Duncan Laurie dlaurie@chromium.org --- M src/soc/intel/common/block/fast_spi/fast_spi.c M src/soc/intel/common/block/lpc/lpc_lib.c 2 files changed, 5 insertions(+), 3 deletions(-)
Approvals: build bot (Jenkins): Verified Duncan Laurie: Looks good to me, approved
diff --git a/src/soc/intel/common/block/fast_spi/fast_spi.c b/src/soc/intel/common/block/fast_spi/fast_spi.c index 455b13c..58e7db7 100644 --- a/src/soc/intel/common/block/fast_spi/fast_spi.c +++ b/src/soc/intel/common/block/fast_spi/fast_spi.c @@ -236,14 +236,13 @@ /* Only the IFD BIOS region is memory mapped (at top of 4G) */ fast_spi_get_bios_region(&bios_size);
- if (!bios_size) - return; - /* LOCAL APIC default address is 0xFEE0000, bios_size over 16MB will * cause memory type conflict when setting memory type to write * protection, so limit the cached bios region to be no more than 16MB. * */ bios_size = MIN(bios_size, 16 * MiB); + if (!bios_size) + return;
/* Round to power of two */ alignment = 1UL << (log2_ceil(bios_size)); diff --git a/src/soc/intel/common/block/lpc/lpc_lib.c b/src/soc/intel/common/block/lpc/lpc_lib.c index b383637..c67c435 100644 --- a/src/soc/intel/common/block/lpc/lpc_lib.c +++ b/src/soc/intel/common/block/lpc/lpc_lib.c @@ -80,6 +80,9 @@ /* Each IO range register can only open a 256-byte window. */ window_size = MIN(size, LPC_LGIR_MAX_WINDOW_SIZE);
+ if (!window_size) + return; + /* Window size must be a power of two for the AMASK to work. */ alignment = 1UL << (log2_ceil(window_size)); window_size = ALIGN_UP(window_size, alignment);