Commit graph

184 commits

Author SHA1 Message Date
Jeff Vander Stoep
87ae5f7dbd assert plat neverallows on nonplat seapp_contexts
With the plat/nonplat policy split, nonplat_seapp_contexts should still
be checked against the plat_seapp_contexts_neverallows during build
time to ensure no violations occur.

Test: stock aosp_marlin builds.
Test: name=foo.bar seinfo=default fails (as expected) in nonplat policy
Test: name=foo.bar seinfo="" fails (as expected) in nonplat policy
Bug: 36002816
Change-Id: I95b2c695b23e2bdf420575d631e85391e93fc869
2017-03-07 20:45:07 +00:00
Alex Klyubin
052b0bbb26 Move split sepolicy to correct locations
This moves the CIL files comprising the split sepolicy to the
directories/partitions based on whether the file is part of
platform/system or non-platform/vendor. In particular:
* plat_sepolicy.cil is moved to /system/etc/selinux,
* nonplat_sepolicy.cil is moved to /vendor/etc/selinux, and
* mapping_sepolicy.cil is moved to /vendor/etc/selinux.

Test: Device boots, no additional denials. The test is performed both
      for a device without the CIL files and with the three CIL files.
Bug: 31363362

Change-Id: Ia760d7eb32c80ba72f6409da75d99eb5aae71cd9
2017-03-03 09:44:55 -08:00
Alex Klyubin
8f7173b016 Test CIL policy when building it
Prior to this commit, there was a bug in generated CIL where it
wouldn't compile using secilc. The reason was that the build script
was stripping out all lines containing "neverallow" from CIL files,
accidentally removing lines which were not neverallow statements,
such as lmx lines referencing app_neverallows.te.

The commit fixes the build script's CIL neverallow filter to filter
out only neverallow* statements, as originally intended. Moreover, to
catch non-compiling CIL policy earlier in the future, this commit runs
secilc on the policy at build time. In particular, it tests that
platform policy compiles on its own and that nonplatform + platform +
mappig policy compiles as well.

Test: CIL policy builds and compiles on-device using secilc
Bug: 31363362
Change-Id: I769aeb3d8c913a5599f1a2195c69460ece7f6465
2017-02-25 15:08:31 -08:00
Alex Klyubin
5596172d23 Device-agnostic policy for vendor image
Default HAL implementations are built from the platform tree and get
placed into the vendor image. The SELinux rules needed for these HAL
implementations to operate thus need to reside on the vendor
partition.

Up to now, the only place to define such rules in the source tree was
the system/sepolicy/public directory. These rules are placed into the
vendor partition. Unfortunately, they are also placed into the
system/root partition, which thus unnecessarily grants these rules to
all HAL implementations of the specified service, default/in-process
shims or not.

This commit adds a new directory, system/sepolicy/vendor, whose
rules are concatenated with the device-specific rules at build time.
These rules are thus placed into the vendor partition and are not
placed into the system/root partition.

Test: No change to SELinux policy.
Test: Rules placed into vendor directory end up in nonplat* artefacts,
      but not in plat* artefacts.
Bug: 34715716
Change-Id: Iab14aa7a3311ed6d53afff673e5d112428941f1c
2017-01-30 18:48:17 -08:00
Sandeep Patil
a86316e852 property_context: split into platform and non-platform components.
Bug: 33746484
Test: Successfully boot with original service and property contexts.
      Successfully boot with split serivce and property contexts.

Change-Id: I87f95292b5860283efb2081b2223e607a52fed04
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-01-29 21:09:11 +00:00
Alex Klyubin
e4665d7f85 Fix bugs in *_file_contexts targets
This fixes the following issues introduced in commit
d225b6979d:
* plat_file_contexts was empty because the target was referencing
  system/sepolicy/private/file_contexts via a misspelled variable
  name.
* plat_file_contexts wasn't marked as dirty and thus wasn't rebuilt
  when system/sepolicy/private/file_contexts changed. This is because
  the file_contexts dependency was referenced via a misspelled
  variable name.
* plat_file_contexts wasn't sorted (as opposed to other similar
  targets, such as nonplat_file_contexts and file_contexts.bin). This
  may lead to unnecessary non-determinism.
* nonplat_file_contexts wasn't marked dirty and thus wasn't rebuilt
  when device-specific file_contexts file(s) changed. This is because
  the file_contexts files were referenced via a misspelled variable
  name.

Test: "make plat_file_contexts" produces a non-empty file containing
      mappings from system/sepolicy/private/file_contexts
Test: "make plat_file_contexts" updates output when
      system/sepolicy/private/file_contexts changes
Test: "make plat_file_contexts" produces output which is sorted
      accroding to rules in fc_sort
Test: "make nonplat_file_contexts" updates output when
      device/lge/bullhead/sepolicy/file_contexts changes (tested on
      aosp_bullhead-eng)
Bug: 31363362
Change-Id: I540555651103f02c96cf958bb93618f600e47a75
2017-01-20 04:34:11 +00:00
Jorim Jaggi
aa03ef2621 Revert "property_context: split into platform and non-platform components."
This reverts commit 262edc382a.

Fixes: 34370523
Change-Id: I077d064d4031d40bc48cb39eba310e6c16b9627d
2017-01-18 15:47:11 +00:00
Sandeep Patil
262edc382a property_context: split into platform and non-platform components.
Bug: 33746484
Test: Successfully boot with original service and property contexts.
      Successfully boot with split serivce and property contexts.

Change-Id: I7881af8922834dc69b37dae3b06d921e05206564
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-01-18 00:41:47 +00:00
Sandeep Patil
a058b569e4 service_context: split into platform and non-platform components.
Bug: 33746484
Test: Successfully boot with original service and property contexts.
      Successfully boot with split serivce and property contexts.

Change-Id: Ide67d37d85273c60b9e387e72fbeb87be6da306a
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-01-18 00:33:09 +00:00
Dan Cashman
9c03807223 Split seapp_contexts into plat and nonplat components.
Bug: 33746381
Test: Device boots with no extra denials.
Change-Id: I2f0da92367851142e0d7df4afec8861ceaed9d3e
2017-01-09 10:10:59 -08:00
dcashman
d225b6979d Split file_contexts for on-device compilation.
Simulate platform and non-platform split by compiling two different
file_contexts files and loading them together on-device.  Leave the existing
file_contexts.bin in place until we're ready to build images based on the new
files.

Bug: 31363362
Test: Builds and boots without additional denials.
Change-Id: I7248f876e2230cee3b3cbf386422063da1e3dde0

Bring back file_contexts.bin.

Change-Id: Ifec2c363579151080fdec48e8bc46bbbc8c97674
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-01-05 11:22:45 -08:00
Richard Uhler
c5c3abc6bc Remove option for non-pic dex preopt.
Test: make checkbuild, aosp_bullhead-userdebug boots.
Bug: 33192586

Change-Id: I386df8b6c04fb162f79a4409801ce3e882026ea8
2016-12-28 08:49:55 +00:00
Steven Moreland
52b759777b Remove ENABLE_TREBLE from sepolicy.
Enabling/disabling sepolicy based on ENABLE_TREBLE is not granular
enough (ref: b/32978887 #4).

Bug: 32978887
Test: compiles, doesn't cause any additional denials on device. Nothing
depends on these things I'm removing.
Change-Id: I10acbde16e5e2093f2c9205ed79cd20caed7f44d
2016-12-21 12:29:02 -08:00
Daniel Cashman
65d01349a0 Revert "Move sepolicy and recovery from on-device tree and add dependency."
This reverts commit cf5c6ecb93.

Change-Id: Ie86a6ac20ab5a1611efc0e167c0430eb9df9482e
2016-12-17 00:53:26 +00:00
Dan Cashman
cf5c6ecb93 Move sepolicy and recovery from on-device tree and add dependency.
Prevent sepolicy and sepolicy.recover from showing up in the root
filesystem when they will not be created as part of it.  Also make
sure both are added as dependencies to version_policy to ensure the
neverallow checks are run.

Bug: 31363362
Test: Builds and boots, including recovery, without additional
  denials.  Neverallow violations still caught at build time.

Change-Id: I39e3cbc150551c9316952523927d057538cd00a7
2016-12-16 14:29:59 -08:00
Dan Cashman
1c04027795 Switch recovery to versioned policy and split into components.
And do some clean up:
Replace LOCAL_TARGET_ARCH with global arch specifier that won't get
clobbered, clean up sepolicy.recovery's eng specification, ensure that
build macros are applied across all policy generation, not just
plat_policy, and make sure that all private variables are cleared and
alphabetized at the end.

Bug: 31363362
Bug: 31369363
Test: Boot into recovery and observe no selinux denials.
Change-Id: Ibc15b097f6d19acf01f6b22bee0e083b15f4ef75
2016-12-16 10:19:17 -08:00
dcashman
90b3b94897 Split mac_permissions.xml into plat and non-plat components.
Bug: 31363362
Test: Bullhead and Sailfish both build and boot w/out new denials.
Change-Id: If6a451ddaab8c9b78a618c49b116a7ed766d0710
2016-12-15 10:20:35 -08:00
dcashman
1faa644c81 Split policy for on-device compilation.
Simulate platform and non-platform split by sending the split files to the
device to be compiled by init.

Bug: 31363362
Test: Policy builds on-device and boots.  sediff shows no difference.
Change-Id: I9627d1c66ca37786d97a049666278a4992ad7579
2016-12-13 10:06:12 -08:00
dcashman
0779155805 Restore checkfc and neverallow checks.
Bug: 33388095
Test: Builds and boots.
Change-Id: Ief9064a16fc733bed54eb76f509ff5aaf5db4baf
2016-12-07 11:27:47 -08:00
dcashman
2e00e6373f sepolicy: add version_policy tool and version non-platform policy.
In order to support platform changes without simultaneous updates from
non-platform components, the platform and non-platform policies must be
split.  In order to provide a guarantee that policy written for
non-platform objects continues to provide the same access, all types
exposed to non-platform policy are versioned by converting them and the
policy using them into attributes.

This change performs that split, the subsequent versioning and also
generates a mapping file to glue the different policy components
together.

Test: Device boots and runs.
Bug: 31369363
Change-Id: Ibfd3eb077bd9b8e2ff3b2e6a0ca87e44d78b1317
2016-12-06 08:56:02 -08:00
Jorge Lucangeli Obes
2899434716 Add WITH_DEXPREOPT_PIC to 'with_dexpreopt' SELinux macro.
|WITH_DEXPREOPT_PIC = false| will still cause code to be loaded from
/data.

Bug: 32970029
Test: On HiKey and Marlin:
Test: Add |WITH_DEXPREOPT_PIC = false|, see SELinux denial.
Test: Apply this CL, no SELinux denials.
Change-Id: I0a1d39eeb4d7f75d84c1908b879d9ea1ccffba74
2016-11-21 11:57:08 -05:00
Jorge Lucangeli Obes
84db84e6cd Use with_dexpreopt macro for zygote execute permissions.
When WITH_DEXPREOPT is set, the zygote does not need to execute
dalvikcache_data_file objects.

Bug: 32970029
Test: Add policy line inside macro, build with and without WITH_DEXPREOPT.
Test: HiKey builds, boots, no zygote denials.
Change-Id: I4dace93e8044267232f0f26cfe427fc250d351fb
2016-11-18 14:22:37 -05:00
Jeff Vander Stoep
d733d161cf Add macros for treble and non-treble only policy
Test: builds
Change-Id: Idd1d90a89a9ecbb2738d6b483af0e8479e87aa15
2016-10-19 15:05:05 -07:00
dcashman
cc39f63773 Split general policy into public and private components.
Divide policy into public and private components.  This is the first
step in splitting the policy creation for platform and non-platform
policies.  The policy in the public directory will be exported for use
in non-platform policy creation.  Backwards compatibility with it will
be achieved by converting the exported policy into attribute-based
policy when included as part of the non-platform policy and a mapping
file will be maintained to be included with the platform policy that
maps exported attributes of previous versions to the current platform
version.

Eventually we would like to create a clear interface between the
platform and non-platform device components so that the exported policy,
and the need for attributes is minimal.  For now, almost all types and
avrules are left in public.

Test: Tested by building policy and running on device.

Change-Id: Idef796c9ec169259787c3f9d8f423edf4ce27f8c
2016-10-06 13:09:06 -07:00
Douglas Leung
5807d1d2b9 Fix ioctl defines for Mips.
This patch allows mips to boot in enforcing mode.

Change-Id: Ia4676db06adc3ccb20d5f231406cf4ab67317496
2016-08-29 14:43:07 -07:00
William Roberts
7d9487c996 Merge \"service_contexts: strip blank lines and comments\"
am: afad0c35ec

Change-Id: Id4a4937cc3b7c2ddd6d363144e6fafc90be60498
2016-07-18 22:56:49 +00:00
William Roberts
a584f2f6cd Merge \"property_contexts: strip blank lines and comments\"
am: ee69a2e775

Change-Id: If61f5720180243ec1b5aa9e16d66c95c37f49b88
2016-07-15 21:24:34 +00:00
William Roberts
c9fce3fa59 service_contexts: strip blank lines and comments
Strip whitespace and comments from service_context files
to reduce size. On an aosp_x86_64 build it saves 36 bytes.

However, on builds with more synclines and comments, further
space savings can be realized.

Change-Id: I3cb4effad1d1b404bf53605a3793e3070cb95651
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2016-07-01 15:01:13 +00:00
William Roberts
371918c1fe property_contexts: strip blank lines and comments
Strip whitespace and comments from property_context files
to reduce size. On an aosp_x86_64 build it saves 851 bytes.

However, on builds with more synclines and comments, further
space savings can be realized.

Change-Id: I43caf1deaab53d4753c835918898c8982f477ef0
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2016-07-01 15:01:01 +00:00
Shinichiro Hamaji
2f7b0514fa Merge "Add keys to prerequisites of mac_permissions.xml" am: d1eb0ede9c
am: a8f65aa156

* commit 'a8f65aa156331487153456ed111b7feb1434355e':
  Add keys to prerequisites of mac_permissions.xml

Change-Id: I9b6f11e61f31ec6c11ec35283eff4936b66497f9
2016-05-17 04:09:02 +00:00
Shinichiro Hamaji
ef0c14d3a2 Add keys to prerequisites of mac_permissions.xml
Bug: 27954979
Change-Id: Ia0403e2dc2726523a41742e23beff29b47274392
2016-05-13 16:04:58 +09:00
Nick Kralevich
3116b83f83 suppress unnecessary makefile output am: 6ef10bd48b
am: 1274aa15d4

* commit '1274aa15d415ea317c48b321445583bf25999b6a':
  suppress unnecessary makefile output
2016-03-02 01:47:59 +00:00
Nick Kralevich
6ef10bd48b suppress unnecessary makefile output
checkpolicy spits out a bunch of unnecessary lines during normal
operation, which bloat the logs and hide other more important
warnings. Suppress the normal output.

SELinux compile time errors are printed to stderr, and are
uneffected by this change.

Change-Id: I07f2cbe8afcd14abf1c025355a169b5214ed5c6e
2016-02-29 16:59:33 -08:00
Nick Kralevich
6710e5c377 Don\'t allow permissive SELinux domains on user builds. am: bca98efa57
am: 0551e9e8d4

* commit '0551e9e8d4764578d7304d695ba20040a6e0ea0b':
  Don't allow permissive SELinux domains on user builds.
2016-02-27 04:39:39 +00:00
Nick Kralevich
bca98efa57 Don't allow permissive SELinux domains on user builds.
It's a CTS requirement that all SELinux domains be in
enforcing mode. Add the same assertion to the build system
when targeting user builds.

In particular, this avoids a situation where device integrity
checking is enabled on user builds, but permissive denials
are being generated, causing the device to unexpectedly reboot
into safe mode.

A developer wanting to put an SELinux domain into permissive
mode for userdebug/eng purposes can write the following
in their policy:

  userdebug_or_eng(`
    permissive foo;
  ')

Bug: 26902605
Bug: 27313768
Change-Id: Ic0971d9e96a28f2a98f9d56a547661d24fb81a21
2016-02-26 20:06:52 -08:00
Jeffrey Vander Stoep
7a29402717 Merge changes from topic \'fc_sort-2\' am: 87a73f199a
am: af77ab6b13

* commit 'af77ab6b136b0c4d44e912bbd2b98f958f7ceb45':
  fc_sort: initial commit
  checkfc: do not die on 0 length fc's
2016-01-15 19:41:30 +00:00
William Roberts
49693f1b4d fc_sort: initial commit
Ordering matters in fc files; the last match wins. In builds where
many BOARD_SEPOLICY_DIRS are set, the order of that list becomes
increasingly important in order to maintain a cohesive built
file_contexts.

To correct this, we sort the device specific file_contexts entries
with the upstream fc_sort tool.

Change-Id: I3775eae11bfa5905cad0d02a0bf26c76ac03437c
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2016-01-14 17:39:07 -08:00
Jeffrey Vander Stoep
b9053767ab Merge "Revert "fc_sort: initial commit"" am: 5de7574a59
am: 62871e5874

* commit '62871e5874e6b1663c732c7f2a2b2d6b36604534':
  Revert "fc_sort: initial commit"
2016-01-15 01:12:54 +00:00
Jeffrey Vander Stoep
b1fb7e4037 Revert "fc_sort: initial commit"
Breaks builds with no device specific policy.

Bug: 26568553
This reverts commit 29d146887e.

Change-Id: If9254d4ad3f104a96325beedebc05dd22664084a
2016-01-14 23:28:51 +00:00
Jeffrey Vander Stoep
a654d9f3aa Merge "fc_sort: initial commit" am: 2dea4525f3
am: faddabe6f5

* commit 'faddabe6f58f30f81938b928597ee7a792c34984':
  fc_sort: initial commit
2016-01-14 20:19:47 +00:00
William Roberts
29d146887e fc_sort: initial commit
Ordering matters in fc files; the last match wins. In builds where
many BOARD_SEPOLICY_DIRS are set, the order of that list becomes
increasingly important in order to maintain a cohesive built
file_contexts.

To correct this, we sort the device specific file_contexts entries
with the upstream fc_sort tool.

Change-Id: Id79cc6f434c41179d5c0d0d739c4718918b0b1dc
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2016-01-07 10:11:52 -08:00
Jeffrey Vander Stoep
9aa378ec31 Merge "Reduce socket ioctl perms" 2016-01-04 22:06:54 +00:00
Jeff Vander Stoep
cbaa2b7d37 Reduce socket ioctl perms
Reduce the socket ioctl commands available to untrusted/isolated apps.
Neverallow accessing sensitive information or setting of network parameters.
Neverallow access to device private ioctls i.e. device specific
customizations as these are a common source of driver bugs.

Define common ioctl commands in ioctl_defines.

Bug: 26267358
Change-Id: Ic5c0af066e26d4cb2867568f53a3e65c5e3b5a5d
2016-01-04 12:15:19 -08:00
Daniel Cashman
efeac86de4 Merge changes from topic \'sepolicy-makefile-cleanup\' am: 1e5b7a1962
am: 26f06d172d

* commit '26f06d172dc2b55c42b1543c7ef02563241efce1':
  Android.mk: cleanse all set but not unset variables
  Android.mk: clean dependencies and clear variables
2015-12-29 17:39:18 +00:00
William Roberts
50a478ef72 Android.mk: cleanse all set but not unset variables
Discovered by diffing the set of "set variables" with
the set of "cleared variables".

Script:

mydir=$(mktemp -d)

grep -E '(^[a-z].)[a-z0-9_\.]*\s*:?=.' Android.mk  | cut -d' ' -f 1-1 | sort | uniq > $mydir/set_vars
grep -E '(^[a-z].)[a-z0-9_\.]*\s*:?=$' Android.mk | cut -d' ' -f1-1 | sort | uniq > $mydir/unset_vars
diff $mydir/set_vars $mydir/unset_vars
rm -rf $mydir

Change-Id: Ib50abac6b417a1bcc1894d9a7bafdbdca371006a
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2015-12-28 16:19:54 -08:00
William Roberts
46749752e5 Android.mk: clean dependencies and clear variables
Dependencies being built with newline files in between
were also including the list of files without the newlines,
thus make would have to process 3n-1 files instead of 2n-1
where n is the number of files to process.

Additionally the *_with_nl variables were not being cleared
out and polluting Make's global name-space.

Change-Id: I76ea1a3dfae994b32991730aea7e4308da52a583
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2015-12-28 16:17:24 -08:00
William Roberts
4b412232c1 sectxfile_nl: fix superfluous dependencies am: cb1ab9858e
am: aeb403f233

* commit 'aeb403f233ada241a099777ccd0ef3b007e935e2':
  sectxfile_nl: fix superfluous dependencies
2015-12-16 23:44:41 +00:00
William Roberts
cb1ab9858e sectxfile_nl: fix superfluous dependencies
The target sectxfile_nl, which is an auto-generated newline file,
has dependencies on itself and the other files. The dependencies
should be on the other files and this newline file, not the other
way around. Ideally, the *_contexts recipes should have the
dependency recorded for their "contexts" files and the newline
file.

Additionally, recipe dependencies for building the *_contexts files
depended on the list of all the contexts files with the newline file
in that list, however an additional explicit addition of the newline
file was also added in. Remove this, since its in the full list of
files.

Change-Id: Iac658923f23a8d9263d392c44003b6bda4064646
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2015-12-16 14:01:58 -08:00
Jeffrey Vander Stoep
e927937f2d Merge "checkfc: add attribute test" am: d48773ab3e
am: c435b7590b

* commit 'c435b7590bd7d7f0594d48976fe931d1f6c07f32':
  checkfc: add attribute test
2015-12-16 16:35:36 +00:00
William Roberts
ad3cb39e54 checkfc: add attribute test
Enable checkfc to check *_contexts against a set of valid attributes
which must be associated with all types in the contexts file that
is being checked.

Since it's imperative that checkfc knows which file its checking to
choose the proper attribute set, the -s option is introduced to
indicate the service_contexts file. The property_contexts file continues
to use the existing -p and file_contexts requires no specification, aka
it's the default.

Failure examples:
file_contexts:
Error: type "init" is not of set: "fs_type, dev_type, file_type"

service_contexts:
Error: type "init_exec" is not of set: "service_manager_type"

property_contexts:
Error: type "bluetooth_service" is not of set: "property_type"

Change-Id: I62077e4d0760858a9459e753e14dfd209868080f
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2015-12-14 23:37:10 +00:00