@@ -62,7 +62,7 @@ use crate::spec::ImageReference;
6262use  crate :: store:: Storage ; 
6363use  crate :: task:: Task ; 
6464use  crate :: utils:: sigpolicy_from_opt; 
65- use  bootc_kernel_cmdline:: utf8:: Cmdline ; 
65+ use  bootc_kernel_cmdline:: { bytes ,   utf8} ; 
6666use  bootc_mount:: Filesystem ; 
6767
6868/// The toplevel boot directory 
@@ -83,6 +83,10 @@ const SELINUXFS: &str = "/sys/fs/selinux";
8383/// The mount path for uefi 
8484const  EFIVARFS :  & str  = "/sys/firmware/efi/efivars" ; 
8585pub ( crate )  const  ARCH_USES_EFI :  bool  = cfg ! ( any( target_arch = "x86_64" ,  target_arch = "aarch64" ) ) ; 
86+ /// This is used by dracut. 
87+ pub  const  INITRD_ARG_PREFIX :  & [ u8 ]  = b"rd." ; 
88+ /// The kernel argument for configuring the rootfs flags. 
89+ pub  const  ROOTFLAGS :  & [ u8 ]  = b"rootflags" ; 
8690
8791const  DEFAULT_REPO_CONFIG :  & [ ( & str ,  & str ) ]  = & [ 
8892    // Default to avoiding grub2-mkconfig etc. 
@@ -1653,18 +1657,26 @@ struct RootMountInfo {
16531657
16541658/// Discover how to mount the root filesystem, using existing kernel arguments and information 
16551659/// about the root mount. 
1656- fn  find_root_args_to_inherit ( cmdline :  & Cmdline ,  root_info :  & Filesystem )  -> Result < RootMountInfo >  { 
1660+ fn  find_root_args_to_inherit ( 
1661+     cmdline :  & bytes:: Cmdline , 
1662+     root_info :  & Filesystem , 
1663+ )  -> Result < RootMountInfo >  { 
16571664    // If we have a root= karg, then use that 
1658-     let  ( mount_spec,  kargs)  = if  let  Some ( root)  = cmdline. value_of ( "root" )  { 
1659-         let  rootflags = cmdline. find ( bootc_kernel_cmdline:: ROOTFLAGS ) ; 
1660-         let  inherit_kargs = cmdline. find_all_starting_with ( bootc_kernel_cmdline:: INITRD_ARG_PREFIX ) ; 
1665+     let  root = cmdline
1666+         . find ( "root" ) 
1667+         . map ( utf8:: Parameter :: try_from) 
1668+         . transpose ( ) ?
1669+         . and_then ( |p| p. value ( ) . map ( |p| p. to_string ( ) ) ) ; 
1670+     let  ( mount_spec,  kargs)  = if  let  Some ( root)  = root { 
1671+         let  rootflags = cmdline. find ( ROOTFLAGS ) ; 
1672+         let  inherit_kargs = cmdline. find_all_starting_with ( INITRD_ARG_PREFIX ) ; 
16611673        ( 
1662-             root. to_owned ( ) , 
1674+             root, 
16631675            rootflags
16641676                . into_iter ( ) 
16651677                . chain ( inherit_kargs) 
1666-                 . map ( |p| p . to_string ( ) ) 
1667-                 . collect ( ) , 
1678+                 . map ( |p| utf8 :: Parameter :: try_from ( p ) . map ( |p| p . to_string ( ) ) ) 
1679+                 . collect :: < Result < Vec < _ > ,   _ > > ( ) ? , 
16681680        ) 
16691681    }  else  { 
16701682        let  uuid = root_info
@@ -1832,7 +1844,7 @@ pub(crate) async fn install_to_filesystem(
18321844        } 
18331845    }  else  if  targeting_host_root { 
18341846        // In the to-existing-root case, look at /proc/cmdline 
1835-         let  cmdline = Cmdline :: from_proc ( ) ?; 
1847+         let  cmdline = bytes :: Cmdline :: from_proc ( ) ?; 
18361848        find_root_args_to_inherit ( & cmdline,  & inspect) ?
18371849    }  else  { 
18381850        // Otherwise, gather metadata from the provided root and use its provided UUID as a 
@@ -2085,18 +2097,42 @@ mod tests {
20852097            uuid :  Some ( "965eb3c7-5a3f-470d-aaa2-1bcf04334bc6" . into ( ) ) , 
20862098            children :  None , 
20872099        } ; 
2088-         let  kargs = Cmdline :: from ( "" ) ; 
2100+         let  kargs = bytes :: Cmdline :: from ( "" ) ; 
20892101        let  r = find_root_args_to_inherit ( & kargs,  & inspect) . unwrap ( ) ; 
20902102        assert_eq ! ( r. mount_spec,  "UUID=965eb3c7-5a3f-470d-aaa2-1bcf04334bc6" ) ; 
20912103
2092-         let  kargs =
2093-             Cmdline :: from ( "root=/dev/mapper/root rw someother=karg rd.lvm.lv=root systemd.debug=1" ) ; 
2104+         let  kargs = bytes:: Cmdline :: from ( 
2105+             "root=/dev/mapper/root rw someother=karg rd.lvm.lv=root systemd.debug=1" , 
2106+         ) ; 
20942107
20952108        // In this case we take the root= from the kernel cmdline 
20962109        let  r = find_root_args_to_inherit ( & kargs,  & inspect) . unwrap ( ) ; 
20972110        assert_eq ! ( r. mount_spec,  "/dev/mapper/root" ) ; 
20982111        assert_eq ! ( r. kargs. len( ) ,  1 ) ; 
20992112        assert_eq ! ( r. kargs[ 0 ] ,  "rd.lvm.lv=root" ) ; 
2113+ 
2114+         // non-UTF8 data in non-essential parts of the cmdline should be ignored 
2115+         let  kargs = bytes:: Cmdline :: from ( 
2116+             b"root=/dev/mapper/root rw non-utf8=\xff  rd.lvm.lv=root systemd.debug=1" , 
2117+         ) ; 
2118+         let  r = find_root_args_to_inherit ( & kargs,  & inspect) . unwrap ( ) ; 
2119+         assert_eq ! ( r. mount_spec,  "/dev/mapper/root" ) ; 
2120+         assert_eq ! ( r. kargs. len( ) ,  1 ) ; 
2121+         assert_eq ! ( r. kargs[ 0 ] ,  "rd.lvm.lv=root" ) ; 
2122+ 
2123+         // non-UTF8 data in `root` should fail 
2124+         let  kargs = bytes:: Cmdline :: from ( 
2125+             b"root=/dev/mapper/ro\xff ot rw non-utf8=\xff  rd.lvm.lv=root systemd.debug=1" , 
2126+         ) ; 
2127+         let  r = find_root_args_to_inherit ( & kargs,  & inspect) ; 
2128+         assert ! ( r. is_err( ) ) ; 
2129+ 
2130+         // non-UTF8 data in `rd.` should fail 
2131+         let  kargs = bytes:: Cmdline :: from ( 
2132+             b"root=/dev/mapper/root rw non-utf8=\xff  rd.lvm.lv=ro\xff ot systemd.debug=1" , 
2133+         ) ; 
2134+         let  r = find_root_args_to_inherit ( & kargs,  & inspect) ; 
2135+         assert ! ( r. is_err( ) ) ; 
21002136    } 
21012137
21022138    // As this is a unit test we don't try to test mountpoints, just verify 
0 commit comments