Commit graph

4605 commits

Author SHA1 Message Date
Thiébaud Weksteen
b719dd3a3a Add tweek@ to OWNERS
Test: n/a
Change-Id: I3bcf558c3d703023f8a7c5114ec494c235c832a0
2022-01-10 10:19:39 +11:00
Joel Galenson
f3f21a93a3 Remove self from OWNERS
Test: None
Change-Id: I8320bdd444e632345ef9431d7118db3294132d8e
2022-01-06 10:00:05 -08:00
Thiébaud Weksteen
671624ef61 Merge upstream '3.3' into update_3_3
Followed the following steps:
    # aosp mirror does not have the upstream tags. Manually mark the
    # 3.3 release. See
    # https://github.com/SELinuxProject/selinux/releases/tag/3.3
    git tag 3.3 7f600c40bc
    repo start update_3_3 .
    git merge 3.3 --no-ff # No merge conflicts were found.
    lunch && m
    repo upload .

Bug: 37755687
Test: Build aosp_bramble-userdebug and manually compare the generated
    /{system,vendor,product}/etc/selinux* files with their previous
    versions. All are identical.
Change-Id: I6a514d7db9a752c44cc61d343f7c1a60f750f317
2021-12-22 09:15:13 +11:00
Jiyong Park
58458b0578 Make libselinux_bindgen available to the virt APEX am: c3375d1e70
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/1900793

Change-Id: I321727c0585f88b7d9b2ca381bd58972b72663dd
2021-11-26 00:29:00 +00:00
Jiyong Park
c3375d1e70 Make libselinux_bindgen available to the virt APEX
Bug: 204852957
Test: m
Change-Id: I652c42c38a568883bb05d7756e9012adc12b4194
2021-11-24 22:10:20 +09:00
Xin Li
23e247c389 Merge sc-qpr1-dev-plus-aosp-without-vendor@7810918
Bug: 205056467
Merged-In: I5a645d9b7617f7f9bfabbfa50b365e0d2cb7b668
Change-Id: Ifa99eb1d37bfaf6110ece9b9cf416eaa014aa84e
2021-11-10 08:05:45 +00:00
Jeffrey Vander Stoep
80860326a9 Merge "Remove references to nonplat sepolicy" am: 4f48fac399
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/1882049

Change-Id: Ia40fb9279d4dff9b778896ff97af934b381fa64a
2021-11-08 07:25:43 +00:00
Jeffrey Vander Stoep
4f48fac399 Merge "Remove references to nonplat sepolicy" 2021-11-08 07:02:40 +00:00
Jeff Vander Stoep
d835556651 Remove references to nonplat sepolicy
"nonplat" was renamed to "vendor" in Android Pie, but was retained
here for Treble compatibility.

We're now outside of the compatbility window for these devices so
it can safely be removed.

Test: build boot cuttlefish device. adb remount, modify
/system/etc/selinux/plat_sepolicy_and_mapping.sha256 to force
on-device policy compilation. reboot. Verify that device boots
without new selinux denials.

Change-Id: Ifec2d60810e4b2742f34b09d646db5e4ff6bb83b
2021-11-05 09:45:59 +01:00
Treehugger Robot
4528875ee1 Merge "[BugFix] avoid SEGV because info maybe nullptr on restorecon_sb" am: 7713594f48
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/1836240

Change-Id: If6aaae5cc702219b4110091e9d8a203f069e6b2a
2021-11-03 16:38:08 +00:00
Treehugger Robot
7713594f48 Merge "[BugFix] avoid SEGV because info maybe nullptr on restorecon_sb" 2021-11-03 16:23:34 +00:00
Thiébaud Weksteen
344ca48ccb Merge changes from topic "revert-1832308-revert-1827311-update_libselinux-DZVXTWIYPG-NRMUCFJHWR" am: 653b39808f
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/1869475

Change-Id: If13b9afa7dfabf6b7ed7e750888efb4218373ede
2021-10-27 23:51:57 +00:00
Thiébaud Weksteen
bda3988cee Revert "Revert "Merge remote-tracking branch 'aosp/upstream-mast..." am: 454466e2e4
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/1869474

Change-Id: Id2a28c027e91fc1aba61a72c123d4d2df871de4e
2021-10-27 23:51:55 +00:00
Thiébaud Weksteen
653b39808f Merge changes from topic "revert-1832308-revert-1827311-update_libselinux-DZVXTWIYPG-NRMUCFJHWR"
* changes:
  Revert^2 "Fix build and use new cil_write_build_ast"
  Revert "Revert "Merge remote-tracking branch 'aosp/upstream-mast..."
2021-10-27 23:34:39 +00:00
Thiébaud Weksteen
454466e2e4 Revert "Revert "Merge remote-tracking branch 'aosp/upstream-mast..."
Revert^2 "Use cil_write_build_ast"

bde09de39feec91cf8220f0f798a6e52154d69e9

Change-Id: I3ab19bda9c1968409ad5a4f4d0866649036c683c
2021-10-27 04:50:56 +00:00
Thiébaud Weksteen
e1de766bff Revert^2 "Fix build and use new cil_write_build_ast"
f4408b8e8e

Change-Id: I68eca0e6b3bea874561a414733d5320e6ffa62c9
2021-10-27 04:50:56 +00:00
Petr Lautrbach
7f600c40bc
Update VERSIONs to 3.3 for release.
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2021-10-21 16:31:23 +02:00
James Carter
c3ad59cc97 libselinux: Fix potential undefined shifts
An expression of the form "1 << x" is undefined if x == 31 because
the "1" is an int and cannot be left shifted by 31.

Instead, use "UINT32_C(1) << x" which will be an unsigned int of
at least 32 bits.

Signed-off-by: James Carter <jwcart2@gmail.com>
2021-10-12 13:44:55 -04:00
James Carter
ce815bd11b checkpolicy: Fix potential undefined shifts
An expression of the form "1 << x" is undefined if x == 31 because
the "1" is an int and cannot be left shifted by 31.

Instead, use "UINT32_C(1) << x" which will be an unsigned int of
at least 32 bits.

Signed-off-by: James Carter <jwcart2@gmail.com>
2021-10-12 13:44:55 -04:00
James Carter
974da80e08 libsepol/cil: Fix potential undefined shifts
An expression of the form "1 << x" is undefined if x == 31 because
the "1" is an int and cannot be left shifted by 31.

Instead, use "UINT32_C(1) << x" which will be an unsigned int of
at least 32 bits.

This bug was found by the secilc-fuzzer.

Signed-off-by: James Carter <jwcart2@gmail.com>
2021-10-12 13:44:22 -04:00
James Carter
14197e613c libsepol: Fix potential undefined shifts
An expression of the form "1 << x" is undefined if x == 31 because
the "1" is an int and cannot be left shifted by 31.

Instead, use "UINT32_C(1) << x" which will be an unsigned int of
at least 32 bits.

Signed-off-by: James Carter <jwcart2@gmail.com>
2021-10-08 16:36:19 -04:00
Petr Lautrbach
5319c49d8a
Update VERSIONs to 3.3-rc3 for release.
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2021-10-06 13:28:15 +02:00
Petr Lautrbach
db3863d551 libselinux/semodule: Improve extracting message
The code doesn't check the default priority, it just looks for the
highest.

Fixes:

    # semodule -E testmodule
    Module 'testmodule' does not exist at the default priority '400'. Extracting at highest existing priority '400'.

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
Acked-by: James Carter <jwcart2@gmail.com>
2021-10-06 12:04:03 +02:00
James Carter
85d0a069ce libsepol/cil: Do not skip macros when resolving until later passes
Since only tunableifs need to be resolved in a macro before the macro
is copied for each call, macros were being skipped after resolving
tunableifs. Statments not allowed to be in macros would be found during
the pass that resolved tunableifs. Unfortunately, in-statments are
resolved after tunableifs and they can be used to add statements to
macros that are not allowed.

Instead, do not skip macros until after the pass that resolves in-
statements that are to be resolved after block inheritance. This
allows blocks, blockinherits, blockabstracts, and macros that were
added by an in-statement to be found and an error reported.

This bug was found by the secilc-fuzzer.

Signed-off-by: James Carter <jwcart2@gmail.com>
Acked-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2021-10-06 12:03:48 +02:00
James Carter
4b2e2a248e libsepol/cil: Limit the amount of reporting for bounds failures
Type bounds are checked when creating the CIL binary using libsepol
functions on the binary policy db. The bad rule is reported and, to
provide better error reporting, a search is made for matching rules
in the CIL policy. These matching rules as well as their parents are
written out with their locations to make it easier to find the rules
that violate the type bounds.

It is possible to craft CIL policies where there are many rules
that violate a bounds check each with many matching rules as well.
This can make the error messages very difficult to deal with. For
example, if there are 100 rules in the binary policy db that violate
a type bounds and each of these rules has 100 matches, then 10,000
matching rules along with their parents will be written out as part
of the error message.

Limit the error reporting to two rules for each type bounds violation
along with two matches for each of those rules.

This problem was found with the secilc-fuzzer.

Signed-off-by: James Carter <jwcart2@gmail.com>
Acked-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2021-10-06 12:03:14 +02:00
Nicolas Iooss
b2891256cb GitHub Actions: do not use macOS latest runner for now
GitHub is currently migrating its macos-latest runner to macOS 11:
https://github.com/actions/virtual-environments/issues/4060

Unfortunately, installing VirtualBox and Vagrant on this new version of
macOS is not easy, and the current macos-11 runner does not support
running virtual machines using Vagrant. This issue is being fixed on
https://github.com/actions/virtual-environments/pull/4010 .

Until this Pull Request is merged, use macos-10.15 runner instead of
macos-latest, to continue using Vagrant to run the SELinux testsuite in
a virtual machine.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
Acked-by: Ondrej Mosnacek <omosnace@redhat.com>
2021-10-04 09:50:46 -04:00
Nicolas Iooss
60bde947d6 README: update continuous integration badges
The CI now uses GitHub Actions to run tests and the SELinux testsuite in
a virtual machine. Replace the Travis CI badge with the ones for these
workflows.

Fixes: https://github.com/SELinuxProject/selinux/issues/299
Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
Acked-by: Ondrej Mosnacek <omosnace@redhat.com>
2021-10-04 09:49:46 -04:00
Christian Göttsche
eac7fb001a checkpolicy: delay down-cast to avoid align warning
Delay the down-cast from hashtab_datum_t, alias void*, to the actual
type once its kind has been determined.

    module_compiler.c:174:19: warning: cast from 'symtab_datum_t *' (aka 'struct symtab_datum *') to 'level_datum_t *' (aka 'struct level_datum *') increases required alignment from 4 to 8 [-Wcast-align]
                            *dest_value = ((level_datum_t *)s)->level->sens;
                                           ^~~~~~~~~~~~~~~~~~

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2021-10-04 09:25:18 -04:00
Christian Göttsche
44ed3074bb checkpolicy: drop incorrect cast
The function require_symbol takes the type hashtab_datum_t (alias void*)
as third argument. Do not cast to hashtab_datum_t* alias void**. Since
explicit casting to void* is unnecessary, drop the casts.

    module_compiler.c:1002:36: warning: cast from 'cond_bool_datum_t *' (aka 'struct cond_bool_datum *') to 'hashtab_datum_t *' (aka 'void **') increases required alignment from 4 to 8 [-Wcast-align]
                require_symbol(SYM_BOOLS, id, (hashtab_datum_t *) booldatum,
                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    module_compiler.c:1092:40: warning: cast from 'cat_datum_t *' (aka 'struct cat_datum *') to 'hashtab_datum_t *' (aka 'void **') increases required alignment from 4 to 8 [-Wcast-align]
            retval = require_symbol(SYM_CATS, id, (hashtab_datum_t *) cat,
                                                  ^~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2021-10-04 09:25:15 -04:00
Christian Göttsche
7a1c7e7a82 checkpolicy: update documentation
Add missing command-line arguments to synopsis and highlight mentions of
other tools in man pages.

Add missing space between arguments in help message.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2021-10-04 09:25:12 -04:00
Christian Göttsche
e32809155b checkpolicy: print reason of fopen failure
Print the reason why opening a source policy file failed, e.g:

    checkpolicy:  unable to open policy.conf:  No such file or directory

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2021-10-04 09:25:10 -04:00
Christian Göttsche
3d27e5a410 checkpolicy: policy_define: cleanup declarations
The variable curfile is nowhere used.

Static functions do not need to be forward declared if not used before
their definition.

The error buffer errormsg can be a simple scoped variable. Also
vsnprintf(3) always NUL-terminates the buffer, so the whole length can
be passed.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2021-10-04 09:25:07 -04:00
Christian Göttsche
6c81478456 libsepol/cil: silence clang void-pointer-to-enum-cast warning
Add an intermediate cast to uintptr_t to silence the clang specific
warning about casting a void pointer to an enum.

    ../cil/src/cil_verify.c:1749:28: error: cast to smaller integer type 'enum cil_flavor' from 'void *' [-Werror,-Wvoid-pointer-to-enum-cast]
                                                    enum cil_flavor op = (enum cil_flavor)i->data;
                                                                         ^~~~~~~~~~~~~~~~~~~~~~~~

Similar to 32f8ed3d6b.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2021-10-04 09:25:05 -04:00
Christian Göttsche
e0968a8640 libsepol: resolve GCC warning about null-dereference
GCC reports a NULL dereference of the return value of stack_peek(). This
function explicitly returns NULL in case of 'stack->pos == -1'.

Error out on NULL returned.

    module_to_cil.c: In function ‘block_to_cil’:
    module_to_cil.c:3357:55: error: potential null pointer dereference [-Werror=null-dereference]
     3357 |         struct list *alias_list = typealias_lists[decl->decl_id];
          |                                                   ~~~~^~~~~~~~~

There are more occurrences of unconditionally dereferencing the return
value of stack_peek(), but the callers should ensure a valid stack, so
just silence this single warning.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2021-10-04 09:24:56 -04:00
Christian Göttsche
a9f4a2cb32 libsepol: use correct cast
The function hashtab_insert takes the type hashtab_datum_t (alias void*)
as third argument. Do not cast to hashtab_datum_t* alias void**. The
casts could be dropped, as explicit casting to void* is unnecessary, but
to fit the overall style of this file keep the casts.

    expand.c:246:41: error: cast from 'perm_datum_t *' (aka 'struct perm_datum *') to 'hashtab_datum_t *' (aka 'void **') increases required alignment from 4 to 8 [-Werror,-Wcast-align]
            ret = hashtab_insert(s->table, new_id, (hashtab_datum_t *) new_perm);
                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2021-10-04 09:24:53 -04:00
Christian Göttsche
1ba9d982a7 libsepol: ebitmap: mark nodes of const ebitmaps const
Mark pointers to nodes of const ebitmaps also const. C does not enforce
a transitive const-ness, but it clarifies the intent and improves
maintainability.

Follow-up of 390ec54d27

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2021-10-04 09:24:49 -04:00
chenguanyou
78041af5bb [BugFix] avoid SEGV because info maybe nullptr on restorecon_sb
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x18
backtrace:
00 pc 0000000000015c6c  /system/lib64/libselinux.so (restorecon_sb+688)
01 pc 0000000000014f6c  /system/lib64/libselinux.so (selinux_android_restorecon_common+480)

Test: manual

Signed-off-by: chenguanyou <chenguanyou@xiaomi.com>
Change-Id: I771394b3d96df94fd1a57df2381c5dac3e83e923
2021-10-02 14:22:24 +08:00
Christian Göttsche
b1a3c2030c Correct some typos
Found by codespell

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: Petr Lautrbach <plautrba@redhat.com>
2021-09-30 15:42:11 -04:00
Petr Lautrbach
0b833973bf
Update VERSIONs to 3.3-rc2 for release.
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2021-09-22 17:14:25 +02:00
Thiébaud Weksteen
425fba351e Merge changes from topic "revert-1827311-update_libselinux-DZVXTWIYPG" am: e9d4c554c2 am: 6711360d92 am: 8938bd4ea6
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/1832310

Change-Id: I5a645d9b7617f7f9bfabbfa50b365e0d2cb7b668
2021-09-22 11:07:16 +00:00
Thiébaud Weksteen
8938bd4ea6 Merge changes from topic "revert-1827311-update_libselinux-DZVXTWIYPG" am: e9d4c554c2 am: 6711360d92
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/1832310

Change-Id: I284f1e2aadce1e3dfb07444fa42794c66e2b269d
2021-09-22 10:58:30 +00:00
Thiébaud Weksteen
6711360d92 Merge changes from topic "revert-1827311-update_libselinux-DZVXTWIYPG" am: e9d4c554c2
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/1832310

Change-Id: I91af411a249fb8667a1f97ff46bffaec7cfac627
2021-09-22 10:49:27 +00:00
Thiébaud Weksteen
e9d4c554c2 Merge changes from topic "revert-1827311-update_libselinux-DZVXTWIYPG"
* changes:
  Revert "Merge remote-tracking branch 'aosp/upstream-master' into..."
  Revert "Fix build and use new cil_write_build_ast"
2021-09-22 10:38:02 +00:00
Christian Göttsche
ffa73128ea libselinux/utils: drop requirement to combine compiling and linking
The extra dependency of sefcontext_compile on its object file causes the
compile and link step to be separated.
During the link step the CFLAGS are not passed, which might contain
optimization or sanitizer flags.

Reorder the LDLIBS requirements to avoid the symbol 'pcre_fullinfo'
being unresolvable at link time.

Current behavior:

    gcc-11 **custom CFLAGS** -I../include -D_GNU_SOURCE     -c -o sefcontext_compile.o sefcontext_compile.c
    gcc-11 -L../src  sefcontext_compile.o ../src/regex.o  -lselinux  -lpcre ../src/libselinux.a -lsepol -o sefcontext_compile

Changed:

    gcc-11 **custom CFLAGS** -I../include -D_GNU_SOURCE    -L../src  sefcontext_compile.c  -lselinux  ../src/libselinux.a -lpcre -lsepol -o sefcontext_compile

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2021-09-22 12:31:53 +02:00
Thiébaud Weksteen
c65aca49bb Revert "Merge remote-tracking branch 'aosp/upstream-master' into..."
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: Iec17732997ab203787f021f437f31e51ef886425
2021-09-22 09:15:53 +00:00
Thiébaud Weksteen
f4408b8e8e Revert "Fix build and use new cil_write_build_ast"
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: I7b34185a9205c550cdfee2ac29acad1bea7879a4
2021-09-22 09:15:53 +00:00
Thiébaud Weksteen
8e052874bc Merge changes from topic "update_libselinux" am: 8650cdd628 am: 391d0c5990 am: fd6f7acacc
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/1827311

Change-Id: I668125a4104231a2585197d2174d991531bffe44
2021-09-22 08:49:07 +00:00
Thiébaud Weksteen
fd6f7acacc Merge changes from topic "update_libselinux" am: 8650cdd628 am: 391d0c5990
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/1827311

Change-Id: I452e4f6569446422b59d628400541920c3d48be4
2021-09-22 08:39:23 +00:00
Thiébaud Weksteen
391d0c5990 Merge changes from topic "update_libselinux" am: 8650cdd628
Original change: https://android-review.googlesource.com/c/platform/external/selinux/+/1827311

Change-Id: I9eb5aa01c516dbbc2a6e48c176a21183c6f88bb6
2021-09-22 08:25:47 +00:00
Thiébaud Weksteen
8650cdd628 Merge changes from topic "update_libselinux"
* changes:
  Fix build and use new cil_write_build_ast
  Merge remote-tracking branch 'aosp/upstream-master' into update_3_3
2021-09-22 08:10:11 +00:00