<def-group>
  <definition class="compliance" id="grub2_slub_debug_argument" version="2">
    <metadata>
        <title>Enable SLUB/SLAB allocator poisoning</title>
        
    <affected family="unix">
    <platform>Ubuntu 22.04</platform>
    </affected>
        <description>Ensure slub_debug is configured in the kernel line in /etc/default/grub.</description>
    </metadata>
    <criteria operator="OR">
    <criteria operator="AND">
      
      
      
          <criterion test_ref="test_grub2_slub_debug_argument_grub_cfg"
          comment="Check if slub_debug is present in the boot parameters in the /boot/grub/grub.cfg for all kernels" />
          
      <criteria operator="OR">
          <criteria operator="OR">
            <criterion test_ref="test_grub2_slub_debug_argument"
            comment="check for slub_debug in /etc/default/grub via GRUB_CMDLINE_LINUX" />
            <criterion test_ref="test_grub2_slub_debug_argument_configdir"
            comment="check for slub_debug in /etc/default/grub.d/*cfg via GRUB_CMDLINE_LINUX" />
          </criteria>
          <criteria operator="AND">
            <criteria operator="OR">
              <criterion test_ref="test_grub2_slub_debug_argument_default"
              comment="check for slub_debug in /etc/default/grub via GRUB_CMDLINE_LINUX_DEFAULT" />
              <criterion test_ref="test_grub2_slub_debug_argument_default_configdir"
              comment="check for slub_debug in /etc/default/grub.d/*cfg via GRUB_CMDLINE_LINUX_DEFAULT" />
            </criteria>
            <extend_definition definition_ref="bootloader_disable_recovery_set_to_true"
            comment="Check GRUB_DISABLE_RECOVERY=true in /etc/default/grub" />
          </criteria>
        </criteria>
    </criteria>
    
    </criteria>
  </definition>


  <ind:textfilecontent54_test id="test_grub2_slub_debug_argument"
  comment="check for slub_debug in /etc/default/grub via GRUB_CMDLINE_LINUX"
  check="all" check_existence="all_exist" version="1">
    <ind:object object_ref="object_grub2_slub_debug_argument" />
    <ind:state state_ref="state_grub2_slub_debug_argument" />
  </ind:textfilecontent54_test>

  <ind:textfilecontent54_object id="object_grub2_slub_debug_argument" version="1">
    <ind:filepath>/etc/default/grub</ind:filepath>
    <ind:pattern operation="pattern match">^\s*GRUB_CMDLINE_LINUX="(.*)"$</ind:pattern>
    <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
  </ind:textfilecontent54_object>

  <ind:textfilecontent54_test id="test_grub2_slub_debug_argument_default"
  comment="check for slub_debug in /etc/default/grub via GRUB_CMDLINE_LINUX_DEFAULT"
  check="all" check_existence="all_exist" version="1">
    <ind:object object_ref="object_grub2_slub_debug_argument_default" />
    <ind:state state_ref="state_grub2_slub_debug_argument" />
  </ind:textfilecontent54_test>

  <ind:textfilecontent54_object id="object_grub2_slub_debug_argument_default"
  version="1">
    <ind:filepath>/etc/default/grub</ind:filepath>
    <ind:pattern operation="pattern match">^\s*GRUB_CMDLINE_LINUX_DEFAULT="(.*)"$</ind:pattern>
    <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
  </ind:textfilecontent54_object>

<ind:textfilecontent54_test id="test_grub2_slub_debug_argument_configdir"
  comment="check for slub_debug in /etc/default/grub.d/*cfg via GRUB_CMDLINE_LINUX"
  check="at least one" check_existence="all_exist" version="1">
    <ind:object object_ref="object_grub2_slub_debug_argument_configdir" />
    <ind:state state_ref="state_grub2_slub_debug_argument" />
  </ind:textfilecontent54_test>

  <ind:textfilecontent54_test id="test_grub2_slub_debug_argument_default_configdir"
  comment="check for slub_debug in /etc/default/grub via GRUB_CMDLINE_LINUX_DEFAULT"
  check="all" check_existence="all_exist" version="1">
    <ind:object object_ref="object_grub2_slub_debug_argument_default_configdir" />
    <ind:state state_ref="state_grub2_slub_debug_argument" />
  </ind:textfilecontent54_test>

  <ind:textfilecontent54_object id="object_grub2_slub_debug_argument_configdir" version="1">
    <ind:filepath operation="pattern match">/etc/default/grub.d/[^/]+\.cfg</ind:filepath>
    <ind:pattern operation="pattern match">^\s*GRUB_CMDLINE_LINUX="(.*)"$</ind:pattern>
    <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
  </ind:textfilecontent54_object>

  <ind:textfilecontent54_object id="object_grub2_slub_debug_argument_default_configdir"
  version="1">
    <ind:filepath>/etc/default/grub.d/*.cfg</ind:filepath>
    <ind:pattern operation="pattern match">^\s*GRUB_CMDLINE_LINUX_DEFAULT="(.*)"$</ind:pattern>
    <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
  </ind:textfilecontent54_object>


  <ind:textfilecontent54_test id="test_grub2_slub_debug_argument_grub_cfg"
  comment="check kernel command line parameters for slub_debug in /boot/grub/grub.cfg for all kernels"
  check="all" check_existence="all_exist" version="1">
    <ind:object object_ref="object_grub2_slub_debug_argument_grub_cfg" />
    <ind:state state_ref="state_grub2_slub_debug_argument" />
  </ind:textfilecontent54_test>

  <ind:textfilecontent54_object id="object_grub2_slub_debug_argument_grub_cfg"
  version="1">
    <ind:filepath>/boot/grub/grub.cfg</ind:filepath>
    
      <ind:pattern operation="pattern match">^.*/vmlinuz.*(root=.*)$</ind:pattern>
    
    <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
  </ind:textfilecontent54_object>





  <ind:textfilecontent54_state id="state_grub2_slub_debug_argument"
  version="1">
    <ind:subexpression datatype="string" operation="pattern match" var_ref="local_var_regex_slub_debug_var_slub_debug_options" />
  </ind:textfilecontent54_state>

  <local_variable id="local_var_regex_slub_debug_var_slub_debug_options"
  comment="Regex that matches slub_debug with value var_slub_debug_options"
  datatype="string" version="1">
    <concat>
      <literal_component>^(?:.*\s)?slub_debug=</literal_component>
      
      <variable_component var_ref="var_slub_debug_options" />
      
      <literal_component>(?:\s.*)?$</literal_component>
    </concat>
  </local_variable>

  <external_variable comment="Variable defining the value the argument should have" datatype="string" id="var_slub_debug_options" version="1" />




</def-group>