Commit graph

233 commits

Author SHA1 Message Date
Inseob Kim
c256de4169 Amend CTS data upon finalization
Ignore-AOSP-First: vFRC

Bug: 337978860
Test: run script manually
Change-Id: I5ce97864e3cb38bfff03c3093681d98dffda6a43
2024-05-03 14:58:16 +09:00
Ellen Arteca
3a3e46e6ff Merge "Fix the neverallow parser so it can parse comments" into main am: 1c90737732 am: 1bba783fd9
Original change: https://android-review.googlesource.com/c/platform/system/sepolicy/+/3052962

Change-Id: I4564c9dcb257e0e4eb70e674a51efbfc81492ebf
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-04-25 17:47:52 +00:00
Ellen Arteca
7cf8c71868 Fix the neverallow parser so it can parse comments
The neverallow parser has a bug where it cannot parse multiline neverallow
rules that have inline comments. For example (taken from the bug description):
```
    neverallow appdomain
            system_server:udp_socket
          {accept append bind create ioctl listen lock name_bind  relabelfrom relabelto setattr shutdown };
```

Initially, the plan to fix this was to use the existing `avrule_read` function the
libsepol parser, however this function expects a compiled `policy` file that represents
the policies to be read in, while the neverallow parser reads from a `.te` file or a string.

This CL implements a fix to this parsing issue by pre-parsing the string
(either read in from a file or passed in as a string directly) and removing
the comments, before proceeding with the parsing as before.

Bug: 334697757
Test: atest android.security.cts.SELinuxNeverallowRulesTest
Change-Id: Ica67dedc23ca9c8b5ba8566198b6bfa785780921
2024-04-25 00:56:49 +00:00
Inseob Kim
421612b0f8 Fix bpfmt am: ff2018fa84 am: 3d27e55c5b
Original change: https://android-review.googlesource.com/c/platform/system/sepolicy/+/3045893

Change-Id: Idb354ab157b475c7287ec80a4379696bdfb3c793
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-04-17 01:33:43 +00:00
Inseob Kim
ff2018fa84 Fix bpfmt
Bug: N/A
Test: N/A
Flag: NONE trivial format change
Change-Id: I8f6293dcc47a4ead347c4861ba929d4b3042c311
2024-04-17 09:55:49 +09:00
Inseob Kim
6f18a17ff8 Finalize prebuilt CTS artifacts
These three files, general_sepolicy.conf / mapping.cil /
plat_sepolicy.cil will be used to test vendor sepolicy's neverallow
rules.

Ignore-AOSP-First: vFRC

Bug: 330671085
Test: build
Change-Id: I763c9a1e647d614b84c0f7fe3d69affbe64f6153
2024-04-15 17:19:54 +09:00
Inseob Kim
6b1db84ec0 Fix bpfmt generated Android.bp
Ignore-AOSP-First: vFRC

Bug: 326134149
Test: TH
Change-Id: I63a7811074f31e4cedcf2f829d2120b99f1cc30d
2024-03-19 11:07:55 +09:00
Inseob Kim
61036d9987 Fix finalization script
Ignore-AOSP-First: vFRC

Test: finalize and build prebuilt modules
Change-Id: I0b9739631311c8971b2ad88061607e4a0734aca2
2024-02-21 13:18:49 +09:00
Inseob Kim
d9fd42eb5e Rename finalization scripts regarding vFRC
Ignore-AOSP-First: b/304316873#comment10

Bug: 318888479
Test: ABTD run with fina-1 and fina-2
Change-Id: Idd03e9b4d8a285aee6da1a5bdc776a654ee75a72
2024-01-30 01:38:20 +00:00
Sandro Montanari
4db0e27a50 Introduce sdk_sandbox_audit SELinux domain
Bug: 295861450
Test: atest CtsSdkSandboxInprocessTests and adb shell ps -Z
Change-Id: I9c5873181c925c6b8ebb411328d30aa519053acf
2023-10-26 08:50:26 +00:00
Thiébaud Weksteen
09021255b6 checkfc: validate that all rules are matching
For the file backend, libselinux keeps track of which rules has matched.
Set up the callback and capture any log message from selinux_stats. If,
at least one rule has not been used, exit with the status code 1.

Bug: 299839280
Test: checkfc -t ./private/file_contexts ./tests/plat_file_contexts_test
Change-Id: I33d88b4234756cd13e29c5c8c081d97b6590810e
2023-10-23 10:51:11 +11:00
Thiébaud Weksteen
9a924ba875 Add checkfc mode to validate file_contexts against test data
A new mode for checkfc is introduced (-t) which takes a file_contexts
and a test data file. Each line in the test data file contains a path
and the expected type. checkfc loads the file_contexts and repeatedly
calls selabel_lookup(3) to verify that the computed type is as expected.

This mode can be used to confirm that any modification to file_contexts
or its build process is benign.

A test data file (plat_file_contexts_test) is added. This file was
manually created based on private/file_contexts. Each static path was
copied as-is. Each regular expression was expanded into a couple of
entries. For instance, /dev/adf[0-9]* generated /dev/adf, /dev/adf0 and
/dev/adf123.

libselinux keeps track of which specification is being hit when using
selabel_lookup. When calling selabel_stats(3), the file backend will
output a warning if a specification has not been used. This can be
leveraged to ensure that each rule is at least hit once. This property
will be leveraged in a follow-up change (by running the test as part of
the build process), to ensure that the plat_file_contexts_test file
remains up-to-date (that is, when an entry is added to
private/file_contexts, the build will fail unless a test is also added
to plat_file_contexts_test to exercice the specification/regular
expression).

Test: m checkfc && checkfc -t ./private/file_contexts ./tests/plat_file_contexts_test
Bug: 299839280
Change-Id: Ibf56859a16bd17e1f878ce7b0570b2aead79c7e0
2023-10-17 15:43:06 +11:00
Inseob Kim
9ca80edf2a Fix sepolicy finalization build error
Bug: 304532197
Test: manually run finalization script
Change-Id: I62caa28b45940753c11cb6d44c1270a4637c120a
2023-10-11 22:58:45 +09:00
Treehugger Robot
531e26d991 Merge "Revert^3 "Start tracking vendor seapp coredomain violations"" into main 2023-09-18 05:06:32 +00:00
Inseob Kim
8bc8b75f95 Revert^3 "Start tracking vendor seapp coredomain violations"
This reverts commit b193c80986.

Reason for revert: Fix is merged

Change-Id: Ia2dcd6584ee763c6da3f3b7fdd9f4710ffde9bfc
2023-09-18 04:08:19 +00:00
Inseob Kim
5d94d75e38 Merge "Revert^2 "Start tracking vendor seapp coredomain violations"" into main 2023-09-15 03:59:23 +00:00
Inseob Kim
b193c80986 Revert^2 "Start tracking vendor seapp coredomain violations"
This reverts commit 6ec4e5f048.

Reason for revert: breaking build

Change-Id: If99f309fd8d5dd5b42a871259451c10530e1769d
2023-09-15 03:58:00 +00:00
Treehugger Robot
430c93557f Merge "Revert "Start tracking vendor seapp coredomain violations"" into main 2023-09-15 03:06:00 +00:00
Inseob Kim
6ec4e5f048 Revert "Start tracking vendor seapp coredomain violations"
This reverts commit 292f22a33b.

Reason for revert: removed all attribute usages; no need

Change-Id: Iab489f1a94733438ba0c552fb9e3eb354423a156
2023-09-14 15:57:04 +00:00
Inseob Kim
5d7423ff3d Build prebuilt policy with Soong
... and remove redundant Makefile codes. This also updates commit hook
as we now only use Soong to build sepolicy.

Bug: 296875906
Test: m selinux_policy
Change-Id: I93f0d222a0c10e31c51c9380780a8927c47d62b1
2023-09-07 16:32:30 +09:00
Inseob Kim
e65098d4a7 Reland "Make coredomain violation as a build error"
This reverts commit 3bda1c9761.

Reason for revert: The fix ag/24590089 is verified with ABTD and merged

Change-Id: I17124df1ddfd52cbd2a17b1a90e0f332eb4e41f9
2023-08-30 00:24:06 +00:00
Samuel Wu
3bda1c9761 Revert "Make coredomain violation as a build error"
This reverts commit 9289cf6fa7.

Reason for revert:
DroidMonitor-triggered revert due to breakage https://android-build.corp.google.com/builds/quarterdeck?branch=git_main&target=cf_x86_64_auto-trunk_staging-userdebug&lkgb=10733608&lkbb=10733914&fkbb=10733779, bug b/298102197

Bug: 298102197

Change-Id: Ia68dc64d3a7b02195e72d1c85ae8c9280fa665cc
2023-08-29 23:40:24 +00:00
Inseob Kim
9289cf6fa7 Make coredomain violation as a build error
Also add how to fix the volations.

Bug: 280547417
Test: m selinux_policy with violations
Change-Id: Icdce73bf0c3b3d98297606958e45e5dd9192f8a0
2023-08-29 01:15:14 +00:00
Inseob Kim
61d6beb39e Skip building compat files if REL
Bug: 296780580
Test: build with next
Change-Id: I588d249f35fc7049d0db3b64692ed818050af0ed
2023-08-23 08:41:44 +00:00
Inseob Kim
292f22a33b Start tracking vendor seapp coredomain violations
As part of Treble, enforce that vendor's seapp_contexts can't label apps
using coredomains. Apps installed to system/system_ext/product should be
labeled with platform side sepolicy.

This change adds the violators attribute that will be used to mark
violating domains that need to be fixed.

Bug: 280547417
Test: manual
Change-Id: I64f3bb2880bd19e65450ea3d3692d1b424402d92
2023-08-18 15:24:59 +09:00
Inseob Kim
d7d3609af7 Ensure vendor seapp contexts can't use coredomain
Bug: 280547417
Test: build
Change-Id: Iadff17523767f91f073c6569400e17f1da55fbdc
2023-07-28 16:18:11 +09:00
Mugdha Lakhani
49075f9cab Add canary restrictions for sdk_sandbox
Apply sdk_sandbox_next it if a new input selector,
isSdkSandboxNext, is true. This is set to true by libselinux
if a flag is set in the seInfo passed to it.

This enables some testers to test out the set of restrictions
we're planning for the next SDK version.
sdk_sandbox_next is not the final set of restrictions of the next SDK
version.

Bug: b/270148964
Test: atest PackageManagerLocalTest SdkSandboxDataIsolationHostTest
SdkSandboxRestrictionsTest

Change-Id: Idbc3ab39a2d9ef6e1feaf8c212d81a1c79b0f787
2023-05-11 17:42:48 +00:00
Charles Chen
eb1290f511 Merge "Update seapp_contexts with isIsolatedComputeApp selector" 2023-02-01 17:34:48 +00:00
Inseob Kim
338f81baac Add comments on compat files
To prevent further confusion.

Bug: 258029505
Test: manual
Change-Id: Iaa145e4480833a224b1a07fc68adb7d3e8a36e4b
2023-01-31 09:57:26 +09:00
Charles Chen
307049222a Update seapp_contexts with isIsolatedComputeApp selector
Provide isIsolatedComputeApp selector for apps reusing _isolated user to run in domains other than isolated_app. Processes match the selector will have a default domain isolated_compute_app assigned. Also updated _isolated neverallow statements.

Bug: 265540209
Bug: 265746493
Test: m && atest --host libselinux_test with change on android_unittest.cpp
Change-Id: Ia05954aa6a9a9a07d6a8d1e3235a89e7b37dead9
2023-01-27 14:36:40 +00:00
Inseob Kim
f87eb38696 Generate compat files and modules with scripts
The steps have been done by hand, which is highly errorprone.

Bug: 207344718
Test: run the script manually
Change-Id: I9deb367b0cbd8d357147f83964bc214cd00266f7
2022-10-19 18:32:01 +09:00
Inseob Kim
bf2a967f1f Fix wrongly hardcoded version
Also removed 10000.0 as there is no 10000.0 in the cil (only 10000_0
exists)

Test: manual
Change-Id: I8c88622e75847388394ba7a0e2e16ceb600ac4f1
2022-10-19 18:31:07 +09:00
Inseob Kim
73172d83ca Remove deprecated distutils dependency
Test: manual
Change-Id: I18747dc6dc47d8e865cadb87dee4a88d1ec32d49
2022-10-19 18:25:23 +09:00
Pawan Wagh
a103fde7ea sepolicy: updating error message for fuzzer bindings
BUG: 249122938
Test: m
Change-Id: I562cc9207f821025180c647d4a07e433abb2cc6c
2022-09-28 19:38:31 +00:00
Pawan
588ebd5e74 sepolicy : Updating error message with doc link
Updating error message with aidl fuzzing link.

Test: m
Bug: 242104782
Change-Id: I96ffc8f55319da6d3acb2deffd4717bfd9727346
2022-09-14 23:34:05 +00:00
Pawan
0ecf99def5 sepolicy : Recommend fuzzers for new services
Adding soong module and tool to check if there is fuzzer present
for every service in private/service_contexts. Whenever a service is
added, its is recommended to update
$ANDROID_BUILD_TOP/system/sepolicy/soong/build/service_fuzzer_bindings.go
with service name and its corresponding fuzzer.

Test: m
Bug: 242104782
Change-Id: Id9bc45f50bebf464de7c91c7469d4bb6ff153ebd
2022-09-13 18:18:46 +00:00
Sandro
8978204264 seamendc: prefetch binary policy in memory before parsing
This optimization improves the runtime of seamendc by ~6-7ms.

Bug: 236691128
Test: atest seamendc-test && atest SeamendcHostTest
Change-Id: Id1e86a5f51d035fac415a0e6ae05b99b3bd774d4
2022-07-28 14:25:03 +00:00
George Burgess IV
3f0bbd132d seamendc: fix potential double-free
If we don't set `buff = NULL` after it's freed by this loop, a later
iteration over the loop where e.g., `stat` fails will call
`free(buff)` again.

Bug: 206470603
Test: TreeHugger
Change-Id: Ic19195adb7398fe2f8ab682ed451f24463872562
2022-07-19 17:31:52 +00:00
sandrom
b246b1dc35 Add seamendc binary
Bug: 236691128
Test: adb shell seamendc -b <binary_policy> -o <output_policy> <test.cil> <test-redefinitions.cil>

Change-Id: Id51271e89261a2a612cf25e7b56147d5931c76f9
2022-07-11 09:23:52 +00:00
Treehugger Robot
8817edcbb4 Merge "Revert^2 "Migrate contexts tests to Android.bp"" 2022-02-16 04:23:47 +00:00
Inseob Kim
b5e235346e Revert^2 "Migrate contexts tests to Android.bp"
This reverts commit baa93cc651.

Reason for revert: amlogic build fixed

Change-Id: I8b046dc810d47a2d87012f02a668873889fce705
2022-02-16 02:26:11 +00:00
Inseob Kim
9eadc83220 Implement compat file generator
sepolicy_generate_compat is a binary that creates a new compat file when
freezing sepolicy API.

Suppose that we are adding {ver} compat file, after freezing {ver}
sepolicy. Then the workflow would be:

1) copy prebuilts to system/sepolicy/prebuilts/api/{ver}
2) add {ver} to PLATFORM_SEPOLICY_COMPAT_VERSIONS under
   build/make/core/config.mk
3) touch the following three files
  - system/sepolicy/private/compat/{ver}/{ver}.cil
  - system/sepolicy/private/compat/{ver}/{ver}.compat.cil
  - system/sepolicy/private/compat/{ver}/{ver}.ignore.cil
  - system/sepolicy/prebuilts/api/{ver}/vendor_sepolicy.cil
  - system/sepolicy/prebuilts/api/{ver}/plat_pub_versioned.cil
  * This step is to build base compat files, and won't be needed in the
    future.
4) add compat module files (won't be needed in the future)
  - {ver}.cil
  - {ver}.compat.cil
  - {ver}.ignore.cil
  * This step is to build base compat files, and won't be needed in the
    future.
5) run the following command to update above three files:
  $ source build/envsetup.sh && lunch aosp_arm64-userdebug
  $ m sepolicy_generate_compat
  $ sepolicy_generate_compat --branch=(branch_for_ver) \
        --build latest --target-version {ver} \
        --latest-version {ver-1}
6) upload build/make and system/sepolicy changes.

This script still lacks:
- handling of plat_pub_versioned.cil
- test cases
We will tackle such problems with follow-up changes.

Bug: 214336258
Test: manual
Change-Id: I21723a0832e5adadae7c22797c5aba867dc0174e
2022-02-07 13:06:49 +09:00
Inseob Kim
cbc95ea5e2 compat_generator: find new types and removed types
To generate compat files, we need:

- base plat sepolicy
- old plat sepolicy
- base plat pub sepolicy
- mapping file from the device
- latest compat files

Generator now triggers the build system itself to get necessary base
files, and then uses the artifacts to extract new types and removed
types.

For the next step, the new/removed types will be mapped to old types,
based on the latest compat files.

Bug: 214336258
Test: sepolicy_generate_compat --branch sc-v2-dev --target-version \
    32.0 --latest-version 31.0 -vvvv --build latest
Change-Id: I1f228233c1e3638e78bc0630ae51e48667a12ef5
2022-01-24 10:51:18 +09:00
Inseob Kim
29e357e898 Add a skeleton sepolicy compat generator
sepolicy_generate_compat will be used to generate compat files for ToT,
based on the mapping file from aosp_arm64-userdebug target of {ver}
source tree. For now, it only supports downloading a mapping file
system/etc/selinux/mapping/{ver}.cil from the Android build server.

Bug: 214336258
Test: sepolicy_generate_compat --branch sc-v2-dev --version 32.0
Change-Id: I48043c71a6866aa385ecd67462f7678561cc5a38
2022-01-17 17:05:46 +09:00
Inseob Kim
baa93cc651 Revert "Migrate contexts tests to Android.bp"
This reverts commit f612656adf.

Reason for revert: breaking amlogic build

Change-Id: I129b5cb74259c9c028483e84c9b2ac3597c24701
2022-01-14 06:13:28 +00:00
Inseob Kim
f612656adf Migrate contexts tests to Android.bp
Now that we have sepolicy module in Android.bp, we can migrate contexts
tests. Also vendor_service_contexts_test will be run, as we now include
vendor_service_contexts unconditionally.

Unfortunately, vendor_service_contexts_test is now broken, due to a
malformed type hal_power_stats_vendor_service. We will temporarily
exempt the type from the test, to speed up migrating to Android.bp.

Bug: 33691272
Test: m selinux_policy and see tests running
Test: add a malformed type other than hal_power_stats_vendor_service and
      run tests
Change-Id: Ic60eb38b9a7c79006f0b5ff4453768e03006604b
2022-01-14 10:59:59 +09:00
Thiébaud Weksteen
9870725336 Migrate insertkeys.py to Python3
PEM files are ASCII-encoded, open them as text file (as opposed to
binary). Avoid relying on __del__. Introduce a prologue and epilogue
methods to emit the <policy> tag only once per output.

Test: build plat_mac_permissions.xml on bramble and compare with
      previous version; identical
Test: build product_mac_permissions.xml on bramble and compare with
      previous version; identical
Test: build system_ext_mac_permissions.xml on bramble and compare with
      previous version; identical
Test: build vendor_mac_permissions.xml on bramble and compare with
      previous version; identical
Bug: 200119288
Change-Id: Iced0acf75bff756453918a411aecb9f4ef8f825d
2021-12-06 13:46:23 +11:00
Thiébaud Weksteen
1c574576b5 Revert^2 "Use cil_write_build_ast"
bde09de39f

Change-Id: I1c94eb98d1b37216096dfba297434377f805eed9
2021-10-27 04:50:56 +00:00
Thiébaud Weksteen
bde09de39f Revert "Use cil_write_build_ast"
Revert submission 1827311-update_libselinux

Reason for revert: b/200771997 
Reverted Changes:
I088d1e94c:Fix build and use new cil_write_build_ast
I14dc4dc58:Merge remote-tracking branch 'aosp/upstream-master...
I7b77f4469:Use cil_write_build_ast

Change-Id: Ib4983288feb0139ed12cb3a07edd60d2d457022f
2021-09-22 09:15:53 +00:00
Thiébaud Weksteen
8e057d189a Use cil_write_build_ast
libsepol now provides its own function to output the AST.

Bug: 190808996
Change-Id: I7b77f446972b42eca63c2ef7c18dff01508014e8
2021-09-15 16:21:46 +02:00