Commit graph

5339 commits

Author SHA1 Message Date
Christian Göttsche
858f660831 libsepol: rename parameter name
Do not use `bool` as a parameter name, for future C version support.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-08-09 09:52:40 -04:00
Christian Göttsche
9e6f8ed70e libsepol: operate on const pointers during validation
The actual policy should not be modified during validation, thus use
const pointers.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-08-09 09:52:37 -04:00
Christian Göttsche
d192e4d937 libsepol: support const avtab_t pointer in avtab_map()
The access vector table itself is not modified in avtab_map() thus
support passing a const pointer.

Logically the content might be changed by the passed callback, but C
does not support transitive const-ness well, and C also does not support
function overloading, e.g. like for strchr(3).

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-08-09 09:52:34 -04:00
Christian Göttsche
938530171b libsepol: rename validate_policydb to policydb_validate
Most global functions operating on a policy database use policydb as
prefix.

Since this function is not exported there should not be any external
use.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-08-09 09:52:31 -04:00
Christian Göttsche
fc7bb9f05a libsepol: skip superfluous memset calls in ebitmap operations
The three members of struct ebitmap_node are all unconditionally
initialized.  Hinder compilers to optimize malloc() and memset() into
calloc(), which might be slightly slower.  Especially affects
ebitmap_or().

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-08-09 09:52:28 -04:00
Christian Göttsche
f174045525 libsepol: optimize ebitmap_xor
Iterate on nodes instead of single bits to save node resolution for each
single bit.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-08-09 09:52:25 -04:00
Christian Göttsche
efcd008148 libsepol: optimize ebitmap_and
Iterate on nodes instead of single bits to save node resolution for each
single bit.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-08-09 09:52:22 -04:00
Christian Göttsche
12a8a00bf2 libsepol: optimize ebitmap_not
Iterate on nodes instead of single bits to save node resolution for each
single bit.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-08-09 09:52:19 -04:00
Christian Göttsche
bc8f7b502b libsepol/cil: use ebitmap_init_range
Especially in the case of __cil_permissionx_expr_range_to_bitmap_helper()
it substitutes hundreds of thousand of calls to ebitmap_set_bit() during
semodule(8) on a policy widely using extended permissions.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-08-09 09:52:15 -04:00
Christian Göttsche
6f9e682c15 libsepol: add ebitmap_init_range
Add an initializer for ebitmaps that sets all bits in a given range to
save node traversals for each bit to set, compared to calling
ebitmap_init() followed by iterating ebitmap_set_bit().

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-08-09 09:52:13 -04:00
Christian Göttsche
490cd409e3 libsepol/tests: add ebitmap tests
Preparation for several ebitmap related optimizations.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-08-09 09:52:10 -04:00
Christian Göttsche
65b3f695be libsepol: enclose macro parameters and replacement lists in parentheses
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-08-09 09:52:06 -04:00
Christian Göttsche
85e73a22ff libsepol: include necessary headers in headers
Include policydb header file required for typedef policydb_t.

This is for example helpful when working with an IDE, which needs to
resolve those symbols.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-08-09 09:52:03 -04:00
Christian Göttsche
12beafe7ce libsepol: break circular include
Since `struct type_set` is forward declared including
policydb/policydb.h is not necessary and creates a circular include.

Also drop the unnecessary forward declaration of `struct policydb`.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-08-09 09:52:00 -04:00
Christian Göttsche
ba9820a002 libselinux: set errno to EBADF on O_PATH emulation ENOENT failure
When the O_PATH emulation fails due to getxattr(2)/setxattr(2) failing
with ENOENT, e.g. because no procfs being available, override the errno
value to EBADF.  This avoids confusion to the caller as it would suggest
the target of the operation does not exist, which is not the case:

    setfiles: Could not set context for /:  No such file or directory

Fixes: a782abf2 ("libselinux: emulate O_PATH support in fgetfilecon/fsetfilecon")
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-08-09 09:51:55 -04:00
Thiébaud Weksteen
a1c2601727 Ignore incorrect user data paths am: 3db4e2df82 am: 4e23d89b61 am: 269a9a60d0 am: d7daeda4c4 am: 3f38719e8e
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2175785

Change-Id: I01863019cee7b7b1e7c4c184088129303e5b47f0
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-08 12:25:10 +00:00
Thiébaud Weksteen
3f38719e8e Ignore incorrect user data paths am: 3db4e2df82 am: 4e23d89b61 am: 269a9a60d0 am: d7daeda4c4
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2175785

Change-Id: I002a85e1589dc33f70bd7711e32901bc2cea6ab5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-08 12:07:49 +00:00
Thiébaud Weksteen
d7daeda4c4 Ignore incorrect user data paths am: 3db4e2df82 am: 4e23d89b61 am: 269a9a60d0
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2175785

Change-Id: I37be5e718377c22b55ef270e6927d9090ed7ea5d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-08 11:52:33 +00:00
Thiébaud Weksteen
269a9a60d0 Ignore incorrect user data paths am: 3db4e2df82 am: 4e23d89b61
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2175785

Change-Id: I50439d5358efb18d51f667cec4f121e6fe273b9a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-08 11:20:06 +00:00
Thiébaud Weksteen
4e23d89b61 Ignore incorrect user data paths am: 3db4e2df82
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2175785

Change-Id: Idad8e553655fcec5eeedb06c6cb8422be0006802
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-08 11:01:19 +00:00
Thiébaud Weksteen
3db4e2df82 Ignore incorrect user data paths
In commit 7d69031, pkgdir_selabel_lookup was updated to return an error
in case of invalid path. Such errors were previously ignored, relying on
the default file_contexts for such path. For example, if the security
context of /data/user/0a is restored, the parsing would fail and the
security context of /data/ used instead (i.e., system_data_file).

Restore this behaviour to avoid spurious error messages.

Test: build & boot bramble; check logcat for "Could not set context for"
Bug: 241150859
Change-Id: I5d78b558307bb4a02431783da69c92ea5a47de91
2022-08-08 16:00:03 +10:00
Thiébaud Weksteen
4a202407f9 Merge "Include userid when restoring context for /data" am: 413194a2ba am: ad8247b9b9 am: 53060d719b am: dca9d67be1 am: 89b13c5cc3
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2169703

Change-Id: Ia1a947294306f3bfefd8585b27c2523b0dec385c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-02 02:44:32 +00:00
Thiébaud Weksteen
89b13c5cc3 Merge "Include userid when restoring context for /data" am: 413194a2ba am: ad8247b9b9 am: 53060d719b am: dca9d67be1
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2169703

Change-Id: If581efec0145829c5880c55bc166c2a172ca55de
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-02 02:19:04 +00:00
Thiébaud Weksteen
dca9d67be1 Merge "Include userid when restoring context for /data" am: 413194a2ba am: ad8247b9b9 am: 53060d719b
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2169703

Change-Id: Ifa40c6e6615927bd7ee0cce52c839d5d27ffd85f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-02 02:01:21 +00:00
Thiébaud Weksteen
53060d719b Merge "Include userid when restoring context for /data" am: 413194a2ba am: ad8247b9b9
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2169703

Change-Id: Ic2eab63fcd235a979596766e6c5423b1b0ca70a7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-02 01:45:29 +00:00
Thiébaud Weksteen
ad8247b9b9 Merge "Include userid when restoring context for /data" am: 413194a2ba
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2169703

Change-Id: If5fda92c47677971883b6e2727083977019dcce9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-02 01:26:30 +00:00
Thiébaud Weksteen
413194a2ba Merge "Include userid when restoring context for /data" 2022-08-02 01:05:30 +00:00
Matthew Maurer
2d48e4a40b rust: Visibility exports for bindgen am: 5e71873288 am: c99543a674 am: a88c5ca616 am: 1038d315da am: 163c3c66fa
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2169587

Change-Id: Id0e224bac10713fcbeab3478e6aad2132fefbc4f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-01 22:26:06 +00:00
Matthew Maurer
163c3c66fa rust: Visibility exports for bindgen am: 5e71873288 am: c99543a674 am: a88c5ca616 am: 1038d315da
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2169587

Change-Id: I7e93094a9c2b6dad52203ddf985df2214dd9196e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-01 22:15:02 +00:00
Matthew Maurer
1038d315da rust: Visibility exports for bindgen am: 5e71873288 am: c99543a674 am: a88c5ca616
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2169587

Change-Id: Id7142e2360b2b244b3418455c60f0de8c1086ab7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-01 21:49:51 +00:00
Matthew Maurer
a88c5ca616 rust: Visibility exports for bindgen am: 5e71873288 am: c99543a674
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2169587

Change-Id: I43da171fc9ed45d32b8f61aabc84cd8f53523f5b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-01 21:31:12 +00:00
Matthew Maurer
c99543a674 rust: Visibility exports for bindgen am: 5e71873288
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2169587

Change-Id: Ie3c8a2d5c5e9aa4b33c1108e86c6882d4866427a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-01 21:05:53 +00:00
Thiébaud Weksteen
7d6903103f Include userid when restoring context for /data
Previously, if restorecon was called for a /data subdirectory, the
userid (id of the physical user) was not taken into account. Capture the
userid from the file path and use it to set the security context.

Test: flash & adb push xxx /data/user/10/xxx & verify security context
Bug: 223254943
Change-Id: Ia20e192cb31435d810e43aa35eccbf55f721419a
2022-08-01 09:47:11 +10:00
Matthew Maurer
5e71873288 rust: Visibility exports for bindgen
We are now default restricting bindgen visibility to subpackages. This
change is part of a set of changes adding explicit visibility for
bindgen libraries which are already being used elsewhere.

* If these visibility rules are to allow access by the safe bindings
  library which lives elsewhere in the codebase, no action is needed.
* If safe bindings do not exist, and you own this library, now is a good
  time to think about producing them and transitioning your (now
  enumerated) client list.
* If safe bindings exist, but there is a surprise client of the raw
  bindings on this list, now is a good time to talk to them about why
  they don't want to use your safe bindings.

Bug: 166332519
Test: m
Change-Id: I967811c6cf563725d591e1d8536f7c6e19535996
2022-07-29 09:49:44 -07:00
Elijah Conners
ebb4a170c0 python: remove IOError in certain cases
In certain cases, IOError caused the much more general exception OSError
to be unreachable.

Signed-off-by: Elijah Conners <business@elijahpepe.com>
Acked-by: Petr Lautrbach <plautrba@redhat.com>
2022-07-19 11:10:08 +02:00
sandrom
6735991b66 Add cil_amend_policydb to android.c am: ef1f345fc9 am: 1c782789a5 am: 097a5cbc7b am: a126795dac am: f92ca77e5c
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2102624

Change-Id: I63f6b6adc212a3003da9be0485b2bde2a55d02f5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-11 14:05:55 +00:00
sandrom
f92ca77e5c Add cil_amend_policydb to android.c am: ef1f345fc9 am: 1c782789a5 am: 097a5cbc7b am: a126795dac
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2102624

Change-Id: Ia2fb80dcc6eea55991cafddef347f51639b13ab7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-11 13:32:14 +00:00
sandrom
a126795dac Add cil_amend_policydb to android.c am: ef1f345fc9 am: 1c782789a5 am: 097a5cbc7b
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2102624

Change-Id: Icbe63264981fb2881d59ea37f940c05ffdf57ff3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-11 12:27:05 +00:00
sandrom
097a5cbc7b Add cil_amend_policydb to android.c am: ef1f345fc9 am: 1c782789a5
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2102624

Change-Id: I76e1c6d2079f4382b169cfec871f036288d66b7c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-11 11:57:22 +00:00
sandrom
1c782789a5 Add cil_amend_policydb to android.c am: ef1f345fc9
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/2102624

Change-Id: I19c31ad734c36be9daa21049bfbac31c050769b6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-11 11:30:19 +00:00
Christian Göttsche
2651989d3b libsepol: do not modify policy during write
Do not modify the in memory default_range value of a class datum while
writing a policy.

While on it fix indentation.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-07-06 15:57:27 -04:00
Christian Göttsche
36bf1be1ca libsepol/utils: improve wording
A request is denied with SEPOL_COMPUTEAV_RBAC if the source role is not
allowed to transition to the target role, granted via a

    allow source_role target_role;

statement.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-07-06 15:57:24 -04:00
Nicolas Iooss
301cd64636 CircleCI: do not add Debian-specific parameter when invoking setup.py
Runners on https://circleci.com/ use a custom version of Python without
Debian-specific patches which added option --install-layout=deb. This
leads to the following error:

    error: option --install-layout not recognized

Fix this by creating a new environment variable dedicated to detect
CircleCI platform.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
Acked-by: James Carter <jwcart2@gmail.com>
2022-07-06 15:57:21 -04:00
Nicolas Iooss
d2fecbb97b libsepol: initialize s in constraint_expr_eval_reason
clang's static analyzer reports that s[0] can be uninitialized when used
in:

    sprintf(tmp_buf, "%s %s\n",
                    xcontext ? "Validatetrans" : "Constraint",
                    s[0] ? "GRANTED" : "DENIED");

Silence this false-positive issue by making s always initialized.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
Acked-by: James Carter <jwcart2@gmail.com>
2022-07-06 15:57:18 -04:00
Christian Göttsche
f505a73b06 libsepol: avoid potential NULL dereference on optional parameter
The parameter `reason` of `context_struct_compute_av()` is optional and
can be passed in as NULL, like from `type_attribute_bounds_av()`.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-07-06 15:57:15 -04:00
sandrom
ef1f345fc9 Add cil_amend_policydb to android.c
Bug: 236691128
Test: atest seamendc-test
Change-Id: Ifde234bc5e9e15f8439292b0c6af3d5945a4f318
2022-07-06 14:42:11 +00:00
Colin Cross
5aff2ef77f Manual merge of mirror-aosp-master to stage-aosp-master am: ca8aba0b86 am: 0d577cb7bc am: 3514ac089f am: 542a9ac69c
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/selinux/+/19135333

Change-Id: I0a1d45e3dff6c147bd7336cde1f19e6271972ca1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-01 03:00:58 +00:00
Colin Cross
542a9ac69c Manual merge of mirror-aosp-master to stage-aosp-master am: ca8aba0b86 am: 0d577cb7bc am: 3514ac089f
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/selinux/+/19135333

Change-Id: Iaa9bccef94afe7e91f6e1de90a6bc7368583e0f1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-01 02:14:24 +00:00
Colin Cross
3514ac089f Manual merge of mirror-aosp-master to stage-aosp-master am: ca8aba0b86 am: 0d577cb7bc
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/selinux/+/19135333

Change-Id: I7fe67c8b581d94c265468c238aa88d27b24c5809
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-01 01:48:09 +00:00
Colin Cross
0d577cb7bc Manual merge of mirror-aosp-master to stage-aosp-master am: ca8aba0b86
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/selinux/+/19135333

Change-Id: I6775d8dead29e36718378555f301c48ed25b7ff5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-01 01:28:33 +00:00