s390/boot: Fix couple of early boot edge cases
Vasily Gorbik
maintainercover s390/boot: Fix couple of early boot edge cases
Fix three independent minor early-boot issues involving the physical memory search range, full command lines with IPL parameters, and unbounded facility ranges.
Vasily Gorbik (3):
s390/boot: Fix physical memory search range s390/boot: Avoid IPL parameter append past command line s390/boot: Bound command line facility ranges
arch/s390/boot/alternative.c | 5 +++-- arch/s390/boot/ipl_parm.c | 23 ++++++++++++----------- arch/s390/boot/physmem_info.c | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-)
Signature · 1 line
2.53.0
Vasily Gorbik
maintainerPATCH 1/3 s390/boot: Fix physical memory search range
search_mem_end() calculates the number of 1MB blocks with a signed int literal. CONFIG_MAX_PHYSMEM_BITS values of 51 and above either overflow the signed int or shift beyond its width. This produces an invalid search range when the binary-search memory detection fallback is used.
Use an unsigned long literal so the full supported physical address range is represented.
--- arch/s390/boot/physmem_info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/boot/physmem_info.c +1 -1
@@ -141,7 +141,7 @@ static int tprot(unsigned long addr)static unsigned long search_mem_end (void ) { -unsigned long range =1 << (MAX_PHYSMEM_BITS -20 );/* in 1MB blocks */ +unsigned long range =1UL << (MAX_PHYSMEM_BITS -20 );/* in 1MB blocks */ unsigned long offset =0 ;unsigned long pivot;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 1/3] s390/boot: Fix physical memory search range
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines
search_mem_end()calculates the number of 1MB blocks with a signed int literal.CONFIG_MAX_PHYSMEM_BITSvalues of 51 and above either overflow the signed int or shift beyond its width. This produces an invalid search range when the binary-search memory detection fallback is used.Use an unsigned long literal so the full supported physical address range is represented.
Fixes 4d14c2666b6b ("s390/mem_detect: replace tprot loop with binary search")Signed-off-by Vasily Gorbik <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH 1/3] s390/boot: Fix physical memory search range
In reply to Vasily GorbikQuoted 5 lines · Vasily Gorbik
search_mem_end()calculates the number of 1MB blocks with a signed int literal.CONFIG_MAX_PHYSMEM_BITSvalues of 51 and above either overflow the signed int or shift beyond its width. This produces an invalid search range when the binary-search memory detection fallback is used.
Quoted 8 lines
Use an unsigned long literal so the full supported physical address range is represented.
Fixes 4d14c2666b6b ("s390/mem_detect: replace tprot loop with binary search")Signed-off-by Vasily Gorbik <[email protected]>--- arch/s390/boot/physmem_info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Vasily Gorbik
maintainerPATCH 2/3 s390/boot: Avoid IPL parameter append past command line
In reply to Vasily GorbikA command line may occupy all but the terminating byte of COMMAND_LINE_SIZE. In that case append_ipl_block_parm() passes a zero size to the IPL parameter conversion helpers and points the destination one byte past early_command_line. The helpers subtract one from the unsigned size and write the converted parameter outside the command line buffer.
Convert the IPL parameter in the command line parsing buffer first. A parameter beginning with '=' can then replace the existing command line regardless of its length, while other parameters are appended only when space remains.
--- arch/s390/boot/ipl_parm.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
arch/s390/boot/ipl_parm.c +11 -10
@@ -23,6 +23,7 @@ struct parmarea parmarea __section(".parmarea") = { };char __bootdata (early_command_line )[COMMAND_LINE_SIZE ]; +static char command_line_buf[COMMAND_LINE_SIZE ];unsigned int __bootdata_preserved (zlib_dfltcc_support ) =ZLIB_DFLTCC_FULL ;struct ipl_parameter_block __bootdata_preserved (ipl_block );
@@ -135,31 +136,32 @@ static size_t ipl_block_get_ascii_scpdata(char *dest, size_t size,static void append_ipl_block_parm (void ) { -char *parm, *delim; +char *delim;size_t len, rc =0 ; len =strlen (early_command_line); - - delim = early_command_line + len;/* '\0' character position */ - parm = early_command_line + len +1 ;/* append right after '\0' */ + delim = early_command_line + len;/* '\0' character position */ switch (ipl_block.pb0_hdr.pbt) {case IPL_PBT_CCW : rc =ipl_block_get_ascii_vmparm ( - parm,COMMAND_LINE_SIZE - len -1 , &ipl_block); + command_line_buf,sizeof (command_line_buf), &ipl_block);break ;case IPL_PBT_FCP :case IPL_PBT_NVME :case IPL_PBT_ECKD : rc =ipl_block_get_ascii_scpdata ( - parm,COMMAND_LINE_SIZE - len -1 , &ipl_block); + command_line_buf,sizeof (command_line_buf), &ipl_block);break ; }if (rc) { -if (*parm =='=' ) -memmove (early_command_line, parm +1 , rc); -else +if (command_line_buf[0 ] =='=' ) { +memmove (early_command_line, command_line_buf +1 , rc); + }else if (len <COMMAND_LINE_SIZE -2 ) { *delim =' ' ;/* replace '\0' with space */ +sized_strscpy (delim +1 , command_line_buf, +COMMAND_LINE_SIZE - len -1 ); + } } }
@@ -245,7 +247,6 @@ static void modify_fac_list(char *str)check_cleared_facilities (); } -static char command_line_buf[COMMAND_LINE_SIZE ];void parse_boot_command_line (void ) {char *param, *val;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 2/3] s390/boot: Avoid IPL parameter append past command line
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
A command line may occupy all but the terminating byte of
COMMAND_LINE_SIZE. In that caseappend_ipl_block_parm()passes a zero size to the IPL parameter conversion helpers and points the destination one byte pastearly_command_line. The helpers subtract one from the unsigned size and write the converted parameter outside the command line buffer.
Quoted 7 lines
Convert the IPL parameter in the command line parsing buffer first. A parameter beginning with '=' can then replace the existing command line regardless of its length, while other parameters are appended only when space remains.
Fixes 5ecb2da660ab ("s390: support command lines longer than 896 bytes")Signed-off-by Vasily Gorbik <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH 2/3] s390/boot: Avoid IPL parameter append past command line
In reply to Vasily Gorbikarch/s390/boot/ipl_parm.c static size_t ipl_block_get_ascii_scpdata(char *dest, size_t size, · line 140
Quoted 5 lines · Vasily Gorbik
static void
append_ipl_block_parm(void)
{arch/s390/boot/ipl_parm.c +1
-1-char *parm, *delim; +char *delim;size_t len, rc =0 ;
Reverse x-mas tree?
Quoted 5 lines
arch/s390/boot/ipl_parm.c +1
-1switch (ipl_block.pb0_hdr.pbt) {case IPL_PBT_CCW : rc =ipl_block_get_ascii_vmparm ( - parm,COMMAND_LINE_SIZE - len -1 , &ipl_block); + command_line_buf,sizeof (command_line_buf), &ipl_block);
...
arch/s390/boot/ipl_parm.c static size_t ipl_block_get_ascii_scpdata(char *dest, size_t size, · line 154
Quoted 3 lines
arch/s390/boot/ipl_parm.c +1
-1rc =ipl_block_get_ascii_scpdata ( - parm,COMMAND_LINE_SIZE - len -1 , &ipl_block); + command_line_buf,sizeof (command_line_buf), &ipl_block);
Both could be long single line statements. :)
arch/s390/boot/ipl_parm.c static size_t ipl_block_get_ascii_scpdata(char *dest, size_t size, · line 159
Quoted 6 lines
arch/s390/boot/ipl_parm.c +2
-3if (rc) { -if (*parm =='=' ) -memmove (early_command_line, parm +1 , rc); -else +if (command_line_buf[0 ] =='=' ) { +memmove (early_command_line, command_line_buf +1 , rc);
Would it be possible to use something different than "rc" as name for the variable? It is actually a length. Maybe something like "append", or "extra"? That would make the code easier to read.
arch/s390/boot/ipl_parm.c static size_t ipl_block_get_ascii_scpdata(char *dest, size_t size, · line 163
Quoted 4 lines
arch/s390/boot/ipl_parm.c +3
-0+ }else if (len <COMMAND_LINE_SIZE -2 ) { *delim =' ' ;/* replace '\0' with space */ +sized_strscpy (delim +1 , command_line_buf, +COMMAND_LINE_SIZE - len -1 );
One line?
Anyway, feel free to ignore the style comments. Code looks good.
Vasily Gorbik
maintainerPATCH 3/3 s390/boot: Bound command line facility ranges
In reply to Vasily GorbikThe facilities and debug-alternative command line parsers iterate over inclusive numeric ranges. If a range ends at ULONG_MAX, incrementing the current value wraps to zero and the loop never terminates. Large finite out-of-range values also cause unnecessary early boot iterations even though the bitmap helpers ignore them.
Stop each loop at the size of the bitmap it modifies. This preserves all meaningful range values while guaranteeing termination.
--- arch/s390/boot/alternative.c | 5 +++-- arch/s390/boot/ipl_parm.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
arch/s390/boot/alternative.c +3 -2
@@ -45,11 +45,12 @@ static void alt_debug_modify(int type, unsigned int nr, bool clear)static char *alt_debug_parse (int type,char *str) { -unsigned long val, endval; +unsigned long val, endval, limit;char *endp;bool clear;int i; + limit = type ==ALT_TYPE_FACILITY ?MAX_FACILITY_BIT :MAX_MFEATURE_BIT ;if (*str ==':' ) { str++; }else {
@@ -73,7 +74,7 @@ static char *alt_debug_parse(int type, char *str)if (str == endp)break ; str = endp; -while (val <= endval) { +while (val <= endval && val < limit) {alt_debug_modify (type, val, clear); val++; }
arch/s390/boot/ipl_parm.c +1 -1
@@ -233,7 +233,7 @@ static void modify_fac_list(char *str)if (str == endp)break ; str = endp; -while (val <= endval) { +while (val <= endval && val <MAX_FACILITY_BIT ) {modify_facility (val, clear); val++; }
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 3/3] s390/boot: Bound command line facility ranges
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
The facilities and debug-alternative command line parsers iterate over inclusive numeric ranges. If a range ends at
ULONG_MAX, incrementing the current value wraps to zero and the loop never terminates. Large finite out-of-range values also cause unnecessary early boot iterations even though the bitmap helpers ignore them.
Quoted 6 lines
Stop each loop at the size of the bitmap it modifies. This preserves all meaningful range values while guaranteeing termination.
Fixes b5e804598d59 ("s390: allow overriding facilities via command line")Fixes 15c33a5bc9b8 ("s390/alternatives: Add debug functionality")Signed-off-by Vasily Gorbik <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH 3/3] s390/boot: Bound command line facility ranges
In reply to Vasily GorbikQuoted 11 lines · Vasily Gorbik
The facilities and debug-alternative command line parsers iterate over inclusive numeric ranges. If a range ends at
ULONG_MAX, incrementing the current value wraps to zero and the loop never terminates. Large finite out-of-range values also cause unnecessary early boot iterations even though the bitmap helpers ignore them.Stop each loop at the size of the bitmap it modifies. This preserves all meaningful range values while guaranteeing termination.
Fixes b5e804598d59 ("s390: allow overriding facilities via command line")Fixes 15c33a5bc9b8 ("s390/alternatives: Add debug functionality")
This is quite esoteric. Not sure if this justifies Fixes tags.
Quoted 5 lines
Signed-off-by Vasily Gorbik <[email protected]>--- arch/s390/boot/alternative.c | 5 +++-- arch/s390/boot/ipl_parm.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
Vasily Gorbik
maintainerQuoted 9 lines · Vasily Gorbik
Fix three independent minor early-boot issues involving the physical memory search range, full command lines with IPL parameters, and unbounded facility ranges.
Vasily Gorbik (3):
s390/boot: Fix physical memory search range s390/boot: Avoid IPL parameter append past command line s390/boot: Bound command line facility ranges
Quoted 4 lines
arch/s390/boot/alternative.c | 5 +++-- arch/s390/boot/ipl_parm.c | 23 ++++++++++++----------- arch/s390/boot/physmem_info.c | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-)
Adopted Heiko's proposed style changes, dropped Fixes for patch 3 and applied