acpi_table: Fix coverity defect in acpi_write_spcr
PATCH 1/1 acpi_table: Fix coverity defect in acpi_write_spcr
Fix "Integer handling issues (SIGN_EXTENSION)" in newly added code:
Cast serial_info.reg_offset to u64 to prevent an integer overflow when shifted too many bits to the left. Currently this never happens as the shift is supposed to be less than 4.
--- lib/acpi/acpi_table.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/acpi/acpi_table.c +2 -2
@@ -420,7 +420,7 @@ int acpi_write_dbg2_pci_uart(struct acpi_ctx *ctx, struct udevice *dev,static int acpi_write_spcr (struct acpi_ctx *ctx,const struct acpi_writer *entry) {struct serial_device_info serial_info = {0 }; -ulong serial_address, serial_offset; +u64 serial_address, serial_offset;struct acpi_table_header *header;struct acpi_spcr *spcr;struct udevice *dev;
@@ -473,7 +473,7 @@ static int acpi_write_spcr(struct acpi_ctx *ctx, const struct acpi_writer *entry } serial_width = serial_info.reg_width *8 ; - serial_offset = serial_info.reg_offset << serial_info.reg_shift; + serial_offset = ((u64 )serial_info.reg_offset) << serial_info.reg_shift; serial_address = serial_info.addr + serial_offset;/* Encode register access size */
Signature · 1 line
2.46.2
Quoted 6 lines · Patrick Rudolph
Fix "Integer handling issues (
SIGN_EXTENSION)" in newly added code:
Cast serial_info.reg_offset to u64 to prevent an integer overflow when shifted too many bits to the left. Currently this never happens as the shift is supposed to be less than 4.
Quoted 30 lines
Signed-off-by Patrick Rudolph <[email protected]>--- lib/acpi/acpi_table.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/acpi/acpi_table.c +2
-3@@ -420,7 +420,7 @@ int acpi_write_dbg2_pci_uart(struct acpi_ctx *ctx, struct udevice *dev,static int acpi_write_spcr (struct acpi_ctx *ctx,const struct acpi_writer *entry) {struct serial_device_info serial_info = {0 }; -ulong serial_address, serial_offset; +u64 serial_address, serial_offset;struct acpi_table_header *header;struct acpi_spcr *spcr;struct udevice *dev;@@ -473,7 +473,7 @@ static int acpi_write_spcr(struct acpi_ctx *ctx, const struct acpi_writer *entry } serial_width = serial_info.reg_width *8 ; - serial_offset = serial_info.reg_offset << serial_info.reg_shift; + serial_offset = ((u64 )serial_info.reg_offset) << serial_info.reg_shift; serial_address = serial_info.addr + serial_offset;/* Encode register access size */ --2.46.2
Quoted 6 lines · Patrick Rudolph
Fix "Integer handling issues (
SIGN_EXTENSION)" in newly added code:
Cast serial_info.reg_offset to u64 to prevent an integer overflow when shifted too many bits to the left. Currently this never happens as the shift is supposed to be less than 4.
Applied to u-boot/master, thanks!
Signature · 1 line
Tom
Quoted 8 lines · Tom Rini
Quoted 4 lines · Patrick Rudolph
Fix "Integer handling issues (
SIGN_EXTENSION)" in newly added code:
Cast serial_info.reg_offset to u64 to prevent an integer overflow when shifted too many bits to the left. Currently this never happens as the shift is supposed to be less than 4.Applied to u-boot/master, thanks!
"I'll just bend my rules and apply this before release, it'll be fine" I said to myself. But:
sandbox: + sandbox
+(sandbox) In file included from include/linux/printk.h:4,
+(sandbox) from include/linux/kernel.h:5, +(sandbox) from include/linux/libfdt_env.h:13, +(sandbox) from include/linux/libfdt.h:6, +(sandbox) from include/fdtdec.h:17, +(sandbox) from include/dm/ofnode.h:11, +(sandbox) from include/dm/device.h:13, +(sandbox) from include/dm.h:13, +(sandbox) from lib/acpi/acpi_table.c:10:
+(sandbox) lib/acpi/acpi_table.c: In function ‘acpi_write_spcr’:
+(sandbox) lib/acpi/acpi_table.c:498:15: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 8 has type ‘u64’ {aka ‘long long unsigned int’} [-Werror=format=]
+(sandbox) 498 | debug("UART type %u @ %lx\n", spcr->interface_type, serial_address);
+(sandbox) | ^~~~~~~~~~~~~~~~~~~~~~
+(sandbox) include/log.h:159:21: note: in definition of macro ‘pr_fmt’
+(sandbox) 159 | #define pr_fmt(fmt) fmt
+(sandbox) | ^~~
+(sandbox) include/log.h:260:17: note: in expansion of macro ‘log’
+(sandbox) 260 | log(LOG_CATEGORY, \ +(sandbox) | ^~~ +(sandbox) include/log.h:282:9: note: in expansion of macro ‘debug_cond’ +(sandbox) 282 | debug_cond(_DEBUG, fmt, ##args) +(sandbox) | ^~~~~~~~~~ +(sandbox) lib/acpi/acpi_table.c:498:9: note: in expansion of macro ‘debug’ +(sandbox) | ^~~~~ +(sandbox) lib/acpi/acpi_table.c:498:33: note: format string is defined here +(sandbox) | ~~^ +(sandbox) | | +(sandbox) | long unsigned int +(sandbox) | %llx
+(sandbox) cc1: all warnings being treated as errors
+(sandbox) make[3]: *** [scripts/Makefile.build:256: lib/acpi/acpi_table.o] Error 1 +(sandbox) make[2]: *** [scripts/Makefile.build:398: lib/acpi] Error 2 +(sandbox) make[1]: *** [Makefile:1914: lib] Error 2
+(sandbox) make: *** [Makefile:177: sub-make] Error 2
And most other platforms too. I'm reverting this for now, and if someone is packaging v2025.01-rc1 too, just do that too. Sorry.
Signature · 1 line
Tom
Hi Tom,
Quoted 39 lines · Tom Rini
Quoted 8 lines · Tom Rini
Quoted 4 lines · Patrick Rudolph
Fix "Integer handling issues (
SIGN_EXTENSION)" in newly added code:
Cast serial_info.reg_offset to u64 to prevent an integer overflow when shifted too many bits to the left. Currently this never happens as the shift is supposed to be less than 4.Applied to u-boot/master, thanks!
"I'll just bend my rules and apply this before release, it'll be fine" I said to myself. But:
sandbox: + sandbox(quoted diff) +24
-0+(sandbox) In file included from include/linux/printk.h:4, +(sandbox) from include/linux/kernel.h:5, +(sandbox) from include/linux/libfdt_env.h:13, +(sandbox) from include/linux/libfdt.h:6, +(sandbox) from include/fdtdec.h:17, +(sandbox) from include/dm/ofnode.h:11, +(sandbox) from include/dm/device.h:13, +(sandbox) from include/dm.h:13, +(sandbox) from lib/acpi/acpi_table.c:10: +(sandbox) lib/acpi/acpi_table.c: In function ‘acpi_write_spcr’: +(sandbox) lib/acpi/acpi_table.c:498:15: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 8 has type ‘u64’ {aka ‘long long unsigned int’} [-Werror=format=] +(sandbox) 498 | debug("UART type %u @ %lx\n", spcr->interface_type, serial_address); +(sandbox) | ^~~~~~~~~~~~~~~~~~~~~~ +(sandbox) include/log.h:159:21: note: in definition of macro ‘pr_fmt’ +(sandbox) 159 | #define pr_fmt(fmt) fmt +(sandbox) | ^~~ +(sandbox) include/log.h:260:17: note: in expansion of macro ‘log’ +(sandbox) 260 | log(LOG_CATEGORY, \ +(sandbox) | ^~~ +(sandbox) include/log.h:282:9: note: in expansion of macro ‘debug_cond’ +(sandbox) 282 | debug_cond(_DEBUG, fmt, ##args) +(sandbox) | ^~~~~~~~~~ +(sandbox) lib/acpi/acpi_table.c:498:9: note: in expansion of macro ‘debug’ +(sandbox) | ^~~~~
Review
Quoted 10 lines
(quoted diff) +10
-0+(sandbox) lib/acpi/acpi_table.c:498:33: note: format string is defined here +(sandbox) | ~~^ +(sandbox) | | +(sandbox) | long unsigned int +(sandbox) | %llx +(sandbox) cc1: all warnings being treated as errors +(sandbox) make[3]: *** [scripts/Makefile.build:256: lib/acpi/acpi_table.o] Error 1 +(sandbox) make[2]: *** [scripts/Makefile.build:398: lib/acpi] Error 2 +(sandbox) make[1]: *** [Makefile:1914: lib] Error 2 +(sandbox) make: *** [Makefile:177: sub-make] Error 2
Appologies, I only build tested it on a single board. Will send an updated version.
Quoted 5 lines
And most other platforms too. I'm reverting this for now, and if someone is packaging v2025.01-rc1 too, just do that too. Sorry.
--
Tom