Commit graph

177 commits

Author SHA1 Message Date
Dan Willemsen
fb12c6b8aa Convert sepolicy-analyze to Android.bp
The LOCAL_COMPATIBILITY_SUITES variable has been removed, as the users
are now embedding this binary the same way they do the rest of the
sepolicy tools.

Bug: 122331947
Bug: 130696912
Test: treehugger
Change-Id: Ia83025b18da87204d87684f2c0af025d9cecc824
2020-01-29 13:20:47 -08:00
liwugang
85ce153283 version_policy: avoid fclose a NULL file pointer
Test: Pass a not cil file to version_policy and see no crash appeared.
example: out/host/linux-x86/bin/version_policy -b  `which ls`  -m -n 10000.0 -o target

Change-Id: If2b950a02dd94a4813b74377617f90c7a75a9f27
Signed-off-by: liwugang <liwugang@xiaomi.com>
2019-07-01 16:47:20 +08:00
Treehugger Robot
5dda7f70db Merge "fix memory leaks in sepolicy-analyze tool" 2019-05-17 17:14:20 +00:00
Jinguang Dong
ee62756a7c fix memory leaks in sepolicy-analyze tool
Test: check sepolicy-analyze tool can work well
 sepolicy-analyze out/target/product/<board>/root/sepolicy typecmp -e
 sepolicy-analyze out/target/product/<board>/root/sepolicy typecmp -d
 sepolicy-analyze out/target/product/<board>/root/sepolicy dups
 sepolicy-analyze out/target/product/<board>/root/sepolicy permissive
 sepolicy-analyze out/target/product/<board>/root/sepolicy booleans
 sepolicy-analyze out/target/product/<board>/root/sepolicy attribute <name>

Change-Id: I09d30967f00062c6a807ae4711ccc87b0fd6064c
2019-05-17 09:57:43 +08:00
Stephen Hines
5c081803fc Ensure avrule is initialized.
Bug: http://b/131390872
Test: Builds with -Wconditional-initialize
Change-Id: I14b9316ca392f299745342d61e4fd45ab8e9e307
2019-05-08 17:14:34 -07:00
Nick Kralevich
795add585c Remove isV2App
This selector is no longer used.

Bug: 123605817
Bug: 111314398
Test: compiles and boots
Change-Id: I61bb6b9f17ba4534569bd4a1c0489023cdaf698d
2019-04-16 16:01:08 -07:00
Jeff Vander Stoep
1ca7a4c8f5 fc_sort: delete c version, migrate to python version
Test: build aosp_blueline-userdebug, run build-time tests
Change-Id: I9c466cd718602e6068ee31abd6de7dbab84f4949
2019-04-11 10:19:16 -07:00
Inseob Kim
98c7ade609 Fix fc_sort to be deterministic
fc_sort uses its own implementation of merge sort, but it's
unnecessarily complex and sorting criteria isn't clear: it only
compares lengths and existences of fields. So it can give different
results on the same input (same set of entries, different order).

This fixes it so that output is always deterministic, regardless of
the order of lines in input files.

Bug: N/A
Test: try to run fc_sort several times on same input with different
      line orders, and see the results.

Change-Id: I982a35a4ae9e115030a8598027bbf1181ee77a7d
2019-04-10 07:42:10 +00:00
Treehugger Robot
2456c37021 Merge "Fix memory leaks" 2019-03-20 01:14:58 +00:00
George Burgess IV
bf2f927019 Fix memory leaks
This CL fixes leaks of the policy that we're building up. The analyzer
only caught the leaks on the error path, but I assume that
`check_assertions` does nothing to free the object that it's handed.

Analyzer warnings:

system/sepolicy/tools/sepolicy-analyze/neverallow.c:439:9: warning:
Potential leak of memory pointed to by 'avrule'
[clang-analyzer-unix.Malloc]

system/sepolicy/tools/sepolicy-analyze/neverallow.c:439:9: warning:
Potential leak of memory pointed to by 'neverallows'
[clang-analyzer-unix.Malloc]

Bug: None
Test: Treehugger; reran the analyzer
Change-Id: I79a0c34e8b53d33a1f01497337590eab660ad3ec
2019-03-19 12:10:51 -07:00
Jeff Vander Stoep
ecd288f41d Android.bp: set sepolicy version for use by init
Init needs to be aware of the policy version defined in sepolicy
for on-device compilation.

Bug: 124499219
Test: build and boot a device. Try both precompiled and on-device
compiled policy.

Change-Id: Iba861aeb4566405aedcbe3c2bad48e1e50126370
2019-03-14 17:49:14 +00:00
Joel Galenson
3fbd303d1c Reduce the number of parallel compiles.
Running this script sometimes completely hangs all of our computers.
This change seems to work better for me.

Test: Use script to compile many Androids.
Change-Id: I95539034b35a4ff6dbc39cd67856b0bd7e20d587
2019-03-04 14:04:49 -08:00
liwugang
eb74dd9f86 checkseapp: check the size of key value pairs
OOB write if the size of the key value pairs exceeds the max.

Test: Add a long line to the seapp_contexts file

Change-Id: Iaa3e697e7ac134eb6829b8b36b090997ca344b3a
Signed-off-by: liwugang <liwugang@xiaomi.com>
2018-11-29 00:43:50 +00:00
liwugang
57d66ef1c2 Fix the bound size and the variable name
It will not end when other words appeared because of the wrong bound and variable,
rule_map->length will exceed the actual length in the rule_map_new function,
it will lead to crash in the rule_map_validate function because of strcmp(NULL, str).

Test: 1.add "user=shell doman=system_app" to private/seapp_contexts
      2.exec "checkseapp private/seapp_contexts" and it will not be crashed

Change-Id: I600206448b38cf2c9b61f9141b40f920b05696c8
Signed-off-by: liwugang <liwugang@xiaomi.com>
2018-11-14 16:39:39 +08:00
Yabin Cui
ffa2b61330 Add runas_app domain to allow running app data file via run-as.
Calling execve() on files in an app's home directory isn't allowed
for targetApi >=29. But this is needed by simpleperf to profile
a debuggable app via run-as.
So workaround it by adding runas_app domain, which allows running
app data file. And add a rule in seapp_contexts to use runas_app
domain for setcontext requests from run-as.

Bug: 118737210
Test: boot marlin and run CtsSimpleperfTestCases.
Change-Id: I5c3b54c95337d6d8192861757b858708174ebfd5
2018-11-07 18:11:40 +00:00
Joel Galenson
b5806c47c5 Add code to check for unescaped periods in file_contexts.
Test: Run script and find unescaped periods.
Change-Id: I35a4366aa576d5c6036d0dcfb068ca4e0f27fff9
2018-10-06 13:39:38 -07:00
Nick Kralevich
5fe07c724b version_policy.c: be less verbose at build time
Avoid generating build time noise so that real errors stand out.

https://en.wikipedia.org/wiki/Unix_philosophy

  Rule of Silence
  Developers should design programs so that they do not print
  unnecessary output. This rule aims to allow other programs
  and developers to pick out the information they need from a
  program's output without having to parse verbosity.

Test: Info messages no longer show up at build time.
Bug: 115998215
Change-Id: I33c18e2c7d77ed1bb4132debe13de2ae0907c34c
2018-09-21 10:31:54 -07:00
Treehugger Robot
13e4eb8ca4 Merge "Add a script to check for ways to cleanup SELinux policy." 2018-09-13 16:16:09 +00:00
Joel Galenson
c43273162f Add a script to check for ways to cleanup SELinux policy.
This scripts checks for common problems with SELinux policy,
including:
- Declared types that are not assigned to any files
- Files that don't exist on a running device
- Rules defined in the wrong file
- Using the wrong version of _file_perms/_dir_perms

These are heuristics, mainly because it does not fully parse regular
expressions and because policy might still be needed even if the
relevant file does not exist on a single device.  But it hopefully is
a start at helping cleanup policy.

Bug: 30003114
Bug: 70702017
Test: Run script on core and device-specific policy.
Test: Verify that most of its results are correct.
Change-Id: I1ded4e9b18816841198dcbf72da65f046441d626
2018-08-31 13:55:34 -07:00
Chih-Hung Hsieh
e0db1651e6 Free type_rules before return or exit.
Test: make with WITH_TIDY=1 and clang-analyzer-* checks.
Change-Id: Ide1eaf8880132c566545710e6287f66a5a2b393c
2018-08-31 10:11:09 -07:00
Dan Willemsen
207fb14549 Merge "Remove unused tags property from Android.bp files" am: d32437e975
am: 526080303a

Change-Id: I1f4060617ada8a1202bec741cc59d9c10f1a9a60
2018-05-08 23:15:36 -07:00
Dan Willemsen
76b7f7b311 Remove unused tags property from Android.bp files
The tags property is (and has always been) unused by Soong. The property has
been defined as a list of strings, and the `androidmk` converted any
LOCAL_MODULE_TAGS entries over to it, but we've never done anything with it.

In preparation for removing the definition from Soong, I'm removing it from all
Android.bp files in the tree.

Since this has never done anything, this is a no-op, but if you really did want
the Android.mk behavior, the proper way to define a module to be installed in
userdebug / eng builds is to use PRODUCT_PACKAGES_DEBUG or PRODUCT_PACKAGES_ENG
in the appropriate product makefile.

Change-Id: Ia9a9b1c35533e02047cbb183b317ab93f1eeec6b
Exempt-From-Owner-Approval: global no-op build change
Test: remove `tags` from Soong, see errors go away.
2018-05-08 17:15:33 -07:00
Tri Vo
f7831bc3d3 Build sepolicy tools with Android.bp. am: 594488f8b0
am: 98e7cdf408

Change-Id: I7138922e28326d4bb05901101fb636360c2717c8
2018-05-07 15:56:48 -07:00
Tri Vo
594488f8b0 Build sepolicy tools with Android.bp.
Bug: 33691272
Test: make clean && mmma system/sepolicy
Change-Id: I6bbd6271c375338e7d24cd6089c6f826080c98b6
2018-05-07 12:51:54 -07:00
Ryan Longair
50fec5f819 Fix sepolicy-analyze makefile so it is included in STS builds
Bug:74022614
Test: `sts-tradefed run sts -m CtsSecurityHostTestCases -t
android.cts.security.SELinuxNeverallowRulesTest`

Change-Id: I53f7bef927bcefdbe0edd0b919f11bdaa134a48b
2018-03-01 10:07:11 -08:00
Jeff Vander Stoep
c08fcbe0c5 tools/build_policies.sh make tool executable am: be6489d1bf am: fc83906f50
am: fb814c6d1f

Change-Id: I02404a15dd274795900075021c63de0fb186db56
2018-01-30 22:15:00 +00:00
Jeff Vander Stoep
be6489d1bf tools/build_policies.sh make tool executable
chmod +x

Test: build all sepolicy targets.
Change-Id: I9e47b78667e4a213c31ecce0e37fe7f84abd9655
2018-01-30 10:08:34 -08:00
Joel Galenson
abc8cc8cd6 Merge "Add a script to build multiple SELinux targets." am: 6b81d43537 am: 7e6235c97a
am: 393357531a

Change-Id: Ibfd98c8d9642d4d9ee5f9ca86376638a2b2883b3
2018-01-30 02:59:25 +00:00
Joel Galenson
c17c5abe22 Add a script to build multiple SELinux targets.
This script will build the SELinux policy for multiple targets in parallel.

To use it, run:
./build_policies.sh <Android root directory> <output directory> [specific targets to build]

If you do not pass any individual targets, it will build all targets it can find.

It will print out the list of failing targets.  You can open up the corresponding log file in the output directory to see the exact errors.

This script is still a work in progress.  It currently cannot discover all build targets (it misses ones "lunch" does not list).

Bug: 33463570
Test: Ran script to build multiple targets with and without failures.
Change-Id: Iee8ccf4da38e5eb7ce2034431613fe10c65696ab
2018-01-29 15:48:15 -08:00
Jaekyun Seok
e0909f482c Merge "Whitelist exported platform properties" am: 70d2bb432a am: 42f8d7b27a
am: f00d05634b

Change-Id: Id6276f733fb5d52b2437927e13343d40c7d53007
2018-01-10 23:53:09 +00:00
Jaekyun Seok
e49714542e Whitelist exported platform properties
This CL lists all the exported platform properties in
private/exported_property_contexts.

Additionally accessing core_property_type from vendor components is
restricted.
Instead public_readable_property_type is used to allow vendor components
to read exported platform properties, and accessibility from
vendor_init is also specified explicitly.

Note that whitelisting would be applied only if
PRODUCT_COMPATIBLE_PROPERTY is set on.

Bug: 38146102
Test: tested on walleye with PRODUCT_COMPATIBLE_PROPERTY=true
Change-Id: I304ba428cc4ca82668fec2ddeb17c971e7ec065e
2018-01-10 16:15:25 +00:00
Nicholas Sauer
3257295a0f Make sepolicy-analyze for ATS.
bug: 69430536
Test: make ats-tradefed && ats-tradefed run ats -m
GtsSecurityHostTestCases

Change-Id: I617a7d08b1bf480f970bc8b4339fa6bbdc347311
2017-11-28 13:19:09 -08:00
Xin Li
c667a0ed64 Merge commit 'd9664064dd09ae254aa3e6ce28fec5fde68c1fb6' into HEAD
Change-Id: Icec8dfff5cff17cf1b557882db62b148a7218b98
2017-11-14 11:46:58 -08:00
Chih-Hung Hsieh
92dacd1ef9 Merge "Use -Werror in system/sepolicy" am: 0d2303be0c am: b03597d1b4
am: 52313b4ce8

Change-Id: I724e29b61036248d06aeadd604084857b5a2936a
2017-10-19 23:34:17 +00:00
Treehugger Robot
0d2303be0c Merge "Use -Werror in system/sepolicy" 2017-10-19 22:53:57 +00:00
William Roberts
71ebf07cfd Merge "fc_sort: rectify with upstream" am: adef499d29 am: 9b1affaa07
am: 6091bbc363

Change-Id: I5e16838c9b81d23b113dc0d0cadf74419d279d38
2017-10-19 19:35:23 +00:00
William Roberts
1cf1064baa fc_sort: rectify with upstream
Code review of:
  - https://android-review.googlesource.com/#/c/platform/system/sepolicy/+/512420/

had some comments. These were addressed and upstreamed here:
  - 65620e0f94

Bring these changes back into the AOSP tree.

Test: verify that output sorted device files did not change hashes when built.

Change-Id: I7f07d3f74923cf731e853629034469784fc669f7
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2017-10-19 16:04:24 +00:00
Chih-Hung Hsieh
038e322f3b Use -Werror in system/sepolicy
Bug: 66996870
Test: build with WITH_TIDY=1
Change-Id: I5df432c6d2f7ee19db89f44fbe3adec2bbcc0b41
2017-10-18 16:19:42 -07:00
William Roberts
ce6c74327e Merge "fc_sort: update to latest" am: f54c8ea95c am: c73fb57045
am: 2f22694a6b

Change-Id: Ia78d8ac42c7986a6a64a575cf47b386a5f1f045b
2017-10-18 00:08:53 +00:00
Keun Soo Yim
5f6fc9c9be package sepolicy-analyze as part of VTS
am: 67b2da4431

Change-Id: I1bbf9b95f0c38fd5f20412e4afb2251ed2c3948e
2017-10-17 03:52:11 +00:00
Keun Soo Yim
67b2da4431 package sepolicy-analyze as part of VTS
Bug: 67848572
Test: mma
Change-Id: I75520b6aa19e44854129697b3c3e375427356e6a
2017-10-16 14:21:07 -07:00
William Roberts
9a6b240b1f fc_sort: update to latest
Update to commit:
  - 5490639ac9

This solves all reported clang analyzer issues and is inline with upstream.

Test: veerify that md5sum of output files do not change.

Change-Id: I942145b8f9748c8ecd185f730c94d57cb77f5acc
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2017-10-16 10:04:46 -07:00
Dan Cashman
91d398d802 Sync internal master and AOSP sepolicy.
Bug: 37916906
Test: Builds 'n' boots.
Change-Id: Ia1d86264446ebecc1ca79f32f11354921bc77668
Merged-In: I208ec6a864127a059fb389417a9c6b259d7474cb
2017-09-26 14:38:47 -07:00
Jeffrey Vander Stoep
59005d3761 Merge "Fix possible memory leak warning." am: 3b24ce5090 am: dfdb96280e
am: dfea667d3f

Change-Id: Ic835bf45ab8a2334bdeec6540678d73dddfffa6d
2017-09-20 03:41:13 +00:00
Luis A. Lozano
635e3eccfb Fix possible memory leak warning.
Static analyzer complains the memory pointed by list in bcurrent is not
deallocated before returning. But since this code is in "main" routine,
we don't care about the deallocation. Just ignore the warning.

Bug: b/27101951
Test: Verified warning is gone.
Change-Id: I58d784b61a5ad30d1406bd7c6b28c5713abf2b34
2017-08-22 18:24:56 -07:00
Yifan Hong
43473a00e1 Merge "Make sepolicy-analyze for GTS." into oc-mr1-dev
am: 7c55e171de

Change-Id: Iff2eb18c5898ae5d05c00a3c888d98286b36374a
2017-08-17 01:01:28 +00:00
Yifan Hong
9ffea2f94b Make sepolicy-analyze for GTS.
Test: gts-tradefed run gts-dev --module=GtsSecurityHostTestCases
Bug: 64127136
Change-Id: Ib50294488bb1a5d46faed00d6954db64648fed20
2017-08-15 15:26:07 -07:00
Manoj Gupta
508db351a1 Merge "Fix static analyzer warnings."
am: 4b547a1516

Change-Id: Id5b85ec29220cdbc15aab72ddf4dfbd2d4ef2fc7
2017-08-02 02:47:37 +00:00
Manoj Gupta
3cdd4a4b0d Fix static analyzer warnings.
Fix the following warnings:

system/sepolicy/tools/sepolicy-analyze/neverallow.c:346:9: warning:
Potential leak of memory pointed to by '__s1'
system/sepolicy/tools/sepolicy-analyze/neverallow.c:346:9: warning:
Potential leak of memory pointed to by 'id'
system/sepolicy/tools/sepolicy-analyze/neverallow.c:364:13: warning:
Potential leak of memory pointed to by 'classperms'
system/sepolicy/tools/sepolicy-analyze/neverallow.c:364:13: warning:
Potential leak of memory pointed to by 'node'

Bug: b/27101951
Test:Warnings are gone.
Change-Id: Ib9b2e0b9f19950b4b764d438ee58340e6c022ef5
2017-08-01 15:46:44 -07:00
Andreas Gampe
d1e5758596 Merge "fc_sort: Fix leaks" am: 7f4b2ad584 am: acbf2ad328
am: 274c4e3352

Change-Id: Ic46f83ae348c57ad306748d03456e62c9a4600d4
2017-05-01 23:40:57 +00:00