[PATCH] x86/boot/compressed: Fix signedness of rdfs8()

redacherkaoui posted 1 patch 1 month, 1 week ago
arch/x86/boot/compressed/cmdline.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
[PATCH] x86/boot/compressed: Fix signedness of rdfs8()
Posted by redacherkaoui 1 month, 1 week ago
rdfs8() reads a raw byte from the decompressor command line buffer but
returns it as 'char'. On toolchains where 'char' is signed, values in
the range 0x80..0xff become negative when promoted, which can lead to
incorrect comparisons while parsing.

Return u8 from rdfs8() to preserve the correct byte value.

Signed-off-by: redacherkaoui <redacherkaoui67@gmail.com>
---
 arch/x86/boot/compressed/cmdline.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/x86/boot/compressed/cmdline.c b/arch/x86/boot/compressed/cmdline.c
index e162d7f59cc5..d48ba959dbc5 100644
--- a/arch/x86/boot/compressed/cmdline.c
+++ b/arch/x86/boot/compressed/cmdline.c
@@ -8,13 +8,16 @@ static inline void set_fs(unsigned long seg)
 {
 	fs = seg << 4;  /* shift it back */
 }
+
 typedef unsigned long addr_t;
-static inline char rdfs8(addr_t addr)
+static inline u8 rdfs8(addr_t addr)
 {
-	return *((char *)(fs + addr));
+	return *(u8 *)(fs + addr);
 }
+
 #include "../cmdline.c"
-unsigned long get_cmd_line_ptr(void)
+
+static unsigned long get_cmd_line_ptr(void)
 {
 	unsigned long cmd_line_ptr = boot_params_ptr->hdr.cmd_line_ptr;
 
@@ -22,10 +25,12 @@ unsigned long get_cmd_line_ptr(void)
 
 	return cmd_line_ptr;
 }
+
 int cmdline_find_option(const char *option, char *buffer, int bufsize)
 {
 	return __cmdline_find_option(get_cmd_line_ptr(), option, buffer, bufsize);
 }
+
 int cmdline_find_option_bool(const char *option)
 {
 	return __cmdline_find_option_bool(get_cmd_line_ptr(), option);
-- 
2.43.0
Re: [PATCH] x86/boot/compressed: Fix signedness of rdfs8()
Posted by kernel test robot 1 month, 1 week ago
Hi redacherkaoui,

kernel test robot noticed the following build errors:

[auto build test ERROR on tip/x86/core]
[also build test ERROR on tip/master linus/master v6.19 next-20260218]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/redacherkaoui/x86-boot-compressed-Fix-signedness-of-rdfs8/20260218-230616
base:   tip/x86/core
patch link:    https://lore.kernel.org/r/20260218150008.28179-1-redacherkaoui67%40gmail.com
patch subject: [PATCH] x86/boot/compressed: Fix signedness of rdfs8()
config: x86_64-randconfig-002-20260219 (https://download.01.org/0day-ci/archive/20260219/202602190815.lFBVk5IE-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
rustc: rustc 1.88.0 (6b00bc388 2025-06-23)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260219/202602190815.lFBVk5IE-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602190815.lFBVk5IE-lkp@intel.com/

All errors (new ones prefixed by >>):

>> ld.lld: error: undefined hidden symbol: get_cmd_line_ptr
   >>> referenced by ident_map_64.c
   >>>               arch/x86/boot/compressed/ident_map_64.o:(initialize_identity_maps)
   >>> referenced by kaslr.c
   >>>               arch/x86/boot/compressed/kaslr.o:(choose_random_location)
   >>> referenced by kaslr.c
   >>>               arch/x86/boot/compressed/kaslr.o:(choose_random_location)

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] x86/boot/compressed: Fix signedness of rdfs8()
Posted by H. Peter Anvin 1 month, 1 week ago
On February 18, 2026 7:00:08 AM PST, redacherkaoui <redacherkaoui67@gmail.com> wrote:
>rdfs8() reads a raw byte from the decompressor command line buffer but
>returns it as 'char'. On toolchains where 'char' is signed, values in
>the range 0x80..0xff become negative when promoted, which can lead to
>incorrect comparisons while parsing.
>
>Return u8 from rdfs8() to preserve the correct byte value.
>
>Signed-off-by: redacherkaoui <redacherkaoui67@gmail.com>
>---
> arch/x86/boot/compressed/cmdline.c | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
>diff --git a/arch/x86/boot/compressed/cmdline.c b/arch/x86/boot/compressed/cmdline.c
>index e162d7f59cc5..d48ba959dbc5 100644
>--- a/arch/x86/boot/compressed/cmdline.c
>+++ b/arch/x86/boot/compressed/cmdline.c
>@@ -8,13 +8,16 @@ static inline void set_fs(unsigned long seg)
> {
> 	fs = seg << 4;  /* shift it back */
> }
>+
> typedef unsigned long addr_t;
>-static inline char rdfs8(addr_t addr)
>+static inline u8 rdfs8(addr_t addr)
> {
>-	return *((char *)(fs + addr));
>+	return *(u8 *)(fs + addr);
> }
>+
> #include "../cmdline.c"
>-unsigned long get_cmd_line_ptr(void)
>+
>+static unsigned long get_cmd_line_ptr(void)
> {
> 	unsigned long cmd_line_ptr = boot_params_ptr->hdr.cmd_line_ptr;
> 
>@@ -22,10 +25,12 @@ unsigned long get_cmd_line_ptr(void)
> 
> 	return cmd_line_ptr;
> }
>+
> int cmdline_find_option(const char *option, char *buffer, int bufsize)
> {
> 	return __cmdline_find_option(get_cmd_line_ptr(), option, buffer, bufsize);
> }
>+
> int cmdline_find_option_bool(const char *option)
> {
> 	return __cmdline_find_option_bool(get_cmd_line_ptr(), option);

What toolchains are that *for x86*?!

This code is about to change substantially, but it wouldn't hurt to make it "unsigned char" or to include the appropriate header. 
Re: [PATCH] x86/boot/compressed: Fix signedness of rdfs8()
Posted by kernel test robot 1 month, 1 week ago
Hi redacherkaoui,

kernel test robot noticed the following build errors:

[auto build test ERROR on tip/x86/core]
[also build test ERROR on tip/master tip/auto-latest linus/master v6.16-rc1 next-20260218]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/redacherkaoui/x86-boot-compressed-Fix-signedness-of-rdfs8/20260218-230616
base:   tip/x86/core
patch link:    https://lore.kernel.org/r/20260218150008.28179-1-redacherkaoui67%40gmail.com
patch subject: [PATCH] x86/boot/compressed: Fix signedness of rdfs8()
config: x86_64-rhel-9.4-ltp (https://download.01.org/0day-ci/archive/20260219/202602190002.InnoyJmU-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260219/202602190002.InnoyJmU-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602190002.InnoyJmU-lkp@intel.com/

All errors (new ones prefixed by >>):

   ld: arch/x86/boot/compressed/kaslr.o: in function `choose_random_location':
>> kaslr.c:(.text+0xb9f): undefined reference to `get_cmd_line_ptr'
>> ld: kaslr.c:(.text+0xbd1): undefined reference to `get_cmd_line_ptr'
   ld: arch/x86/boot/compressed/ident_map_64.o: in function `initialize_identity_maps':
>> ident_map_64.c:(.text+0xb2a): undefined reference to `get_cmd_line_ptr'
   ld: arch/x86/boot/compressed/vmlinux: hidden symbol `get_cmd_line_ptr' isn't defined
   ld: final link failed: bad value

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] x86/boot/compressed: Fix signedness of rdfs8()
Posted by kernel test robot 1 month, 1 week ago
Hi redacherkaoui,

kernel test robot noticed the following build errors:

[auto build test ERROR on tip/x86/core]
[also build test ERROR on tip/master tip/auto-latest linus/master v6.19 next-20260218]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/redacherkaoui/x86-boot-compressed-Fix-signedness-of-rdfs8/20260218-230616
base:   tip/x86/core
patch link:    https://lore.kernel.org/r/20260218150008.28179-1-redacherkaoui67%40gmail.com
patch subject: [PATCH] x86/boot/compressed: Fix signedness of rdfs8()
config: x86_64-kexec (https://download.01.org/0day-ci/archive/20260218/202602182354.HCHrfAu7-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260218/202602182354.HCHrfAu7-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602182354.HCHrfAu7-lkp@intel.com/

All errors (new ones prefixed by >>):

>> ld.lld: error: undefined hidden symbol: get_cmd_line_ptr
   >>> referenced by ident_map_64.c
   >>>               arch/x86/boot/compressed/ident_map_64.o:(initialize_identity_maps)

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] x86/boot/compressed: Fix signedness of rdfs8()
Posted by kernel test robot 1 month, 1 week ago
Hi redacherkaoui,

kernel test robot noticed the following build errors:

[auto build test ERROR on tip/x86/core]
[also build test ERROR on tip/master tip/auto-latest linus/master v6.19 next-20260218]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/redacherkaoui/x86-boot-compressed-Fix-signedness-of-rdfs8/20260218-230616
base:   tip/x86/core
patch link:    https://lore.kernel.org/r/20260218150008.28179-1-redacherkaoui67%40gmail.com
patch subject: [PATCH] x86/boot/compressed: Fix signedness of rdfs8()
config: i386-randconfig-011-20260219 (https://download.01.org/0day-ci/archive/20260219/202602190559.5x6DqOz3-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260219/202602190559.5x6DqOz3-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602190559.5x6DqOz3-lkp@intel.com/

All errors (new ones prefixed by >>):

   ld: arch/x86/boot/compressed/kaslr.o: in function `choose_random_location':
>> kaslr.c:(.text+0xb95): undefined reference to `get_cmd_line_ptr'
>> ld: kaslr.c:(.text+0xbce): undefined reference to `get_cmd_line_ptr'
   ld: arch/x86/boot/compressed/vmlinux: hidden symbol `get_cmd_line_ptr' isn't defined
   ld: final link failed: bad value

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki