Skip to content
Snippets Groups Projects
  • Nick Kralevich's avatar
    Add compile time check for expanded attribute neverallow failure · 94c88932
    Nick Kralevich authored
    The SELinux policy language supports an expandattribute statement.
    Similar to the C "inline" declaration, this expands the permissions
    associated with types, instead of using the attribute directly. Please
    see
    https://android.googlesource.com/platform/external/selinux/+/1089665e31a647a5f0ba2eabe8ac6232b384bed9
    for more detail on this language option.
    
    Expansion of attributes causes consistency problems with CTS. If a
    neverallow rule exists which refers to an expanded attribute, the CTS
    neverallow test will fail, because the policy does not have the
    attribute embedded in it. Examples:
    
      * b/119783042 (fixed in 536d3413)
      * b/67296580 (fixed in 6f7e8609)
      * b/63809360 (fixed in 89f215e6)
      etc...
    
    Instead of waiting for the CTS test to fail, modify the Android.mk file
    so that we do checks similar to CTS. This allows us to fail at compile
    time instead of waiting for a CTS bug. For example, for b/119783042,
    instead of the compile succeeding, it will now fail with the following
    error message:
    
      [ 70% 190/268] build out/target/product/crosshatch/obj/ETC/sepolicy_neverallows_intermediates/sepolicy_neverallows
      FAILED: out/target/product/crosshatch/obj/ETC/sepolicy_neverallows_intermediates/sepolicy_neverallows
      /bin/bash -c "(ASAN_OPTIONS=detect_leaks=0 out/host/linux-x86/bin/checkpolicy -M -c
      30 -o out/target/product/crosshatch/obj/ETC/sepolicy_neverallows_intermediates/sepolicy_neverallows.tmp
      out/target/product/crosshatch/obj/ETC/sepolicy_neverallows_intermediates/policy.conf ) &&
      (out/host/linux-x86/bin/sepolicy-analyze
      out/target/product/crosshatch/obj/ETC/sepolicy_neverallows_intermediates/sepolicy_neverallows.tmp
      neverallow -w -f out/target/product/crosshatch/obj/ETC/sepolicy_neverallows_intermediates/policy_2.conf
      || 	  ( echo \"\" 1>&2; echo \"sepolicy-analyze failed. This is most likely due to the use\" 1>&2;
      echo \"of an expanded attribute in a neverallow assertion. Please fix\" 1>&2;
      echo \"the policy.\" 1>&2; exit 1 ) ) &&
      (touch out/target/product/crosshatch/obj/ETC/sepolicy_neverallows_intermediates/sepolicy_neverallows.tmp )
      && (mv out/target/product/crosshatch/obj/ETC/sepolicy_neverallows_intermediates/sepolicy_neverallows.tmp
      out/target/product/crosshatch/obj/ETC/sepolicy_neverallows_intermediates/sepolicy_neverallows )"
      libsepol.report_failure: neverallow violated by allow vold hal_bootctl_default:binder { call };
      libsepol.check_assertions: 1 neverallow failures occurred
    
      sepolicy-analyze failed. This is most likely due to the use
      of an expanded attribute in a neverallow assertion. Please fix
      the policy.
      15:44:27 ninja failed with: exit status 1
    
    Test: Revert 536d3413 and verify compile
          fails as above.
    Test: Compile succeeds
    Bug: 119783042
    
    Change-Id: I5df405b337bb744b838dadf53a2234d8ed94bf39
    94c88932