Commit graph

2974 commits

Author SHA1 Message Date
Logan Chien
122c68c862 Mark libselinux as VNDK in Android.bp
This commit marks libselinux.so as VNDK, so that vendor variant of
libselinux.so can be installed into /system/lib[64]/vndk instead of
/vendor/lib[64].  This makes it easier to apply security patches
through system-only OTAs.

Before this commit, libselinux was not an VNDK library because there
was a concern with selabel database file format.  This is no longer a
concern because the file backend is disabled in vendor variant.

Bug: 69587962
Bug: 63866913
Test: /system/lib64/vndk/libselinux.so shows up in GSI
Change-Id: I9d3be760bb5b3f8bf50b96ce6d8b938bf75c620a
2017-11-22 10:22:40 +08:00
Jiyong Park
adec3cd8b3 Remove libselinux_vendor
am: 57071adff4

Change-Id: Ia3db2e542b63b92bfd8b23fffe8364db13fda4fa
2017-10-20 01:10:46 +00:00
Jiyong Park
57071adff4 Remove libselinux_vendor
libselinux_vendor is removed and merged to libselinux by using
vendor_available:true.

Bug: 66914194
Test: lunch aosp_arm64_ab-userdebug; m libselinux.vendor

Change-Id: Idc04eccf8a9803b9acf6277a9d078a1528ed29c9
2017-10-19 17:28:21 +09:00
Dan Cashman
aa604d7ad5 Merge "libsepol: cil: Keep type[attribute] declarations when attributizing."
am: 970199321d

Change-Id: I5bcfbd00f4d4ec38718142a98720007d2b0b2632
2017-10-15 03:08:47 +00:00
Treehugger Robot
970199321d Merge "libsepol: cil: Keep type[attribute] declarations when attributizing." 2017-10-13 20:45:09 +00:00
Chih-Hung Hsieh
c14edd65d9 resolve merge conflicts of 74770629 to stage-aosp-master
Test: I solemnly swear I tested this conflict resolution.
Exempt-From-Owner-Approval: fix merge conflict
Change-Id: I7af3ed74c62c9004c17fcb080acfff7ff408945c
2017-10-12 23:28:31 +00:00
Treehugger Robot
7477062939 Merge "Use -Werror in external/selinux" 2017-10-12 22:51:41 +00:00
Dan Cashman
85850171a9 libsepol: cil: Keep type[attribute] declarations when attributizing.
cil_android_attributize() uses a source policy to identify types and
attributes to be versioned according to the given version number, and
then proceeds to modify the provided target policy to provide this
versioning.  Previously, the versioned policy relied on a base policy
for the declarations of these type[attribute]s, but with multiple_decl
support added, the declarations can be made in both places.  This will
make the policy more robust and allow for greater flexibility and the
types of base policy used.

Bug: 37915794
Test: Builds 'n' boots.  non_plat_sepolicy.cil now contains the public
type[attribute] declarations.

Change-Id: Iaa084211a9e2774a7ed391888fb21c4c0cf955db
2017-10-11 12:59:43 -07:00
Nick Kralevich
119e93fdd7 Merge remote-tracking branch 'aosp/upstream-master' into mymerge
am: 28749e4d40

Change-Id: Ic2b710b3ecf329d5933c10aa52c9793678d9db3d
2017-10-09 19:51:24 +00:00
Nick Kralevich
28749e4d40 Merge remote-tracking branch 'aosp/upstream-master' into mymerge
Followed the following steps:

  # In repo client
  cd external/selinux
  repo sync .
  repo start mymerge .
  git merge aosp/upstream-master --no-ff # resolve any conflicts
  repo upload .

Test: compiles/boots no problems.
Change-Id: I4e7ee3fddfe021d128ebd70a663374367914b825
2017-10-09 09:11:41 -07:00
Jeff Vander Stoep
77fcc9d929 (re)declare versioned attributes in mapping file
am: 1fd1f27bb3

Change-Id: I1456fe993914889b1315cf20bae0d118bbb508f0
2017-10-08 04:08:16 +00:00
Jeff Vander Stoep
1fd1f27bb3 (re)declare versioned attributes in mapping file
Public types get versioned for Treble compatibility. The versioned
attribute is declared in vendor policy. Then a mapping between the
newer system policy occurs on the system partition. This causes
on-device compilation to fail in AOSP because the vendor image stays
static and thus the mapping file references undeclared typeattributes.

This can be solved by declaring, or redeclaring all versioned types
in the mapping file. Support for this was added to secilc in commit
fafe4c212b 'libsepol: cil: Add ability
to redeclare types[attributes]'

Bug: 67092827
Bug: 37915794
Test: build and boot aosp_sailfish with new type declared in public
    policy
Change-Id: I04a884db6d0eaf42ee189b0669833dd0860b626f
2017-10-06 17:08:06 -07:00
Vit Mojzis
393bafd3c5 python/semanage: Enable listing file_contexts.homedirs
Include entries from file_contexts.homedirs when listing file contexts
via "semanage fcontext -l"

"semanage fcontext -l" so far ignored content of file_contexts.homedirs
file, which is confusing for users (more specific rules may be ignored in
favor of rules unseen to the user since file_contexts.homedirs has
higher priority than file_contexts).

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1409813

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2017-10-04 14:18:58 -04:00
Vit Mojzis
bc161a9e94 libsemanage: Add support for listing fcontext.homedirs file
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1409813

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2017-10-04 14:18:58 -04:00
Vit Mojzis
5007687feb libsemanage: Keep copy of file_contexts.homedirs in policy store
This will allow listing the correct file_contexts.homedirs
using libsemanage regardless of selected policy store.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1409813

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2017-10-04 14:18:58 -04:00
Chih-Hung Hsieh
7ae97e062d Use -Werror in external/selinux
* Use -Wno-error= to keep existing warnings to fix later.

Bug: 66996870
Test: build with WITH_TIDY=1
Change-Id: I0e84d5fb2ae2ae68a687a0b6b81eb64a983db57c
2017-10-04 00:59:43 +00:00
Dan Willemsen
786d898c51 Rename target.linux[_x86[_64]] to target.linux_glibc[_x86[_64]]
am: 4a89b6358f

Change-Id: I390dec68c89e5e03ec7cb5df4c714d1edeb30456
2017-10-03 02:50:46 +00:00
Dan Willemsen
4a89b6358f Rename target.linux[_x86[_64]] to target.linux_glibc[_x86[_64]]
In the future, target.linux will apply to all targets running a linux kernel
(android, linux_glibc, linux_bionic). So move all current users to the specific
linux_glibc.

There will be another cleanup pass later that will move some instances back to
target.linux if the properties should be shared with target.android and
target.linux_bionic, but target.linux needs to be removed first.

Test: out/soong/build.ninja identical before/after
Change-Id: I30ea2790de2588ba0f5cfe1cd3bb6dc66f00a537
Exempt-From-Owner-Approval: build system cleanup
2017-10-02 10:41:09 -07:00
Nicolas Iooss
ef61301d7e gui: remove mappingsPage
This page is not used anywhere and seems to be an incomplete version of
loginsPage.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-10-02 01:51:49 +08:00
Nicolas Iooss
7b0f5a12f4 gui: delete overridden definition of usersPage.delete()
Function delete() is defined twice in class usersPage and the first one
invoke semanagePage.delete(), which does not exist.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-10-02 01:51:49 +08:00
Nicolas Iooss
3b5e8fb842 gui: fix parsing of "semodule -lfull" in tab Modules
The output of "semodule -lfull" changed from "module version" to
"priority module kind". Update system-config-selinux to use this new
format in its tab "Policy Module".

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-10-02 01:51:49 +08:00
Nicolas Iooss
d689e3dc16 gui: remove the status bar
The status bar of system-config-selinux's main window is not used and
takes some room. Remove it.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-10-02 01:51:49 +08:00
Nicolas Iooss
305aacbc4b sepolicy: support non-MLS policy in gui
Several "sepolic gui" tabs raise exceptions when using a policy without
MLS because some dictionaries describing users and logins lack level and
range properties. Use conditions and get() where appropriate in order
to make "sepolicy gui" usable again with a non-MLS policy.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-09-25 12:59:29 -04:00
Nicolas Iooss
175efbf3ae sepolicy: ignore comments and empty lines in file_contexts.subs_dist
In refpolicy, file_contexts.subs_dist begins with comments:

    # This file can is used to configure base path aliases as in:
    #
    # /aliased_path /original_path_as_configured_in_file_contexts
    #

The first line gets parsed in read_file_equiv even though it is not a
valid path substitution and the second line triggers an exception when
accessing f[1]:

    IndexError: list index out of range

Parse substitutions only for lines which are not comment.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-09-25 12:58:16 -04:00
Nicolas Iooss
6d9258e5a0 Travis-CI: fix configuration after September's update
The latest update to Travis-CI build environment splitted sugilite
environment into amethyst and garnet and deprecated sugilite. As garnet
provides tools for languages C and Python, and as it is automatically
selected according to
https://travis-ci.org/fishilico/selinux/jobs/278927391 , remove "group:
sugilite" from Travis-CI configuration file.

This update introduced two issues:

- Ruby 2.1 is no longer provided. As it has reached End Of Life
  according to https://www.ruby-lang.org/en/downloads/, remove it from
  the tested versions

- Python 3.3, 3.4 and 3.5 are no longer installed by default. When
  Travis-CI builds Python projects using these versions, it
  automatically download and extract an archive from
  https://s3.amazonaws.com/travis-python-archives/binaries/ubuntu/14.04/x86_64/.
  Implement this process in .travis.yml directly (because Travis-CI does
  not support multi-language projects which use several versions of C
  compilers and Python and Ruby interpreters).

Last but not least, it is now possible to build with PyPy3. Enable this
interpreter in the build environment matrix.

More information about the Travis-CI update is available at
https://docs.travis-ci.com/user/build-environment-updates/2017-09-06/

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-09-25 12:56:02 -04:00
Nicolas Iooss
0f3beeb00e gui: port to Python 3 by migrating to PyGI
PyGTK has been deprecated in favor of PyGI+GTK and thus has never been
ported to python3. Using pygi-convert.sh from
https://git.gnome.org/browse/pygobject/tree/pygi-convert.sh helps
migrating most of the API but gnome-python.

The glade file has been converted to GtkBuilder using

  gtk-builder-convert system-config-selinux.glade system-config-selinux.ui

and some fixes in order to provide an application window (object
GnomeApp disappeared, GtkVBox is deprecated, etc.). The associated
Python code also needed some modifications in order to migrate to
GtkBuilder.

The result has been tested on Arch Linux with Python 3.6. There are some
bugs in the GUI itself, for which patches will be sent afterwards.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-09-25 12:54:12 -04:00
Jeff Vander Stoep
59e59ed1bb Expand all compile-time generated attributes
am: d47503f8dc

Change-Id: If8653e330397aeaf0369741f3cdf53dc88f983ee
2017-09-22 21:01:55 +00:00
Jeff Vander Stoep
d47503f8dc Expand all compile-time generated attributes
Cutting down on the number of attributes associated with each type
speeds up policy lookup times when there is an access vector cache
miss.

This commit reduces the number of attributes in the policy binary from
607 to 159.

(cherry-pick of commit: 574926fe67)

Bug: 36508258
Test: build and boot Marlin
Change-Id: I42c778fe9e760abf62d4ec1f7b7e748e28ac5497
2017-09-22 12:36:44 -07:00
Nicolas Iooss
8f0ea463bc sepolicy: do not fail when file_contexts.local or .subs do not exist
On a system without any file context customizations, "sepolicy gui"
fails to load because it tries to read a non-existing file:

    FileNotFoundError: [Errno 2] No such file or directory:
    '/etc/selinux/refpolicy-git/contexts/files/file_contexts.local'

Once this issue is fixed, another one is triggered:

    FileNotFoundError: [Errno 2] No such file or directory:
    '/etc/selinux/refpolicy-git/contexts/files/file_contexts.subs

Use try/except to catch these exceptions and use OSError/errno.ENOENT to
keep the code compatible with Python 2.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-09-21 16:15:54 -04:00
Jan Zarsky
77059c39e8 libsepol: fix memory leak in sepol_bool_query()
When sepol_bool_query() returns NULL response, variable name is not
freed. Fix this by calling free() before returning.

Signed-off-by: Jan Zarsky <jzarsky@redhat.com>
2017-09-20 16:29:31 -04:00
Dan Cashman
6cef90d0ee Merge remote-tracking branch 'aosp/upstream-master' into mymerge
am: 8f76b0cd3e

Change-Id: Ia92454d490cc9d14ecd7f07462550955fa12f1e5
2017-09-20 00:28:55 +00:00
Dan Cashman
8f76b0cd3e Merge remote-tracking branch 'aosp/upstream-master' into mymerge
Test: Builds.
Change-Id: I5069d965a008bb9b27a6652794ea76131949f35f
2017-09-19 14:25:41 -07:00
Yifan Hong
fa0823f66a Merge "Fix libselinux_vendor private header dependencies."
am: bf3627db98

Change-Id: I89c9f62c744d8582ff07f6d0052ed5e2a04c26b9
2017-09-11 21:23:41 +00:00
Treehugger Robot
bf3627db98 Merge "Fix libselinux_vendor private header dependencies." 2017-09-11 20:48:49 +00:00
Martijn Coenen
742d0341ad Don't load nonplat_service_contexts on full-treble.
am: 57fdb1f490

Change-Id: Ic964603c3efff7a7127454cd4c1310721834cea9
2017-09-11 03:12:20 +00:00
Yifan Hong
1e5bced8e3 Fix libselinux_vendor private header dependencies.
Do not include private/android_filesystem_config.h
for libselinux_vendor.

Test: mma -j
Test: BOARD_VNDK_VERSION=current mma -j

Bug: 33241851

Change-Id: I4f4328dceaa8609d1891b4b7129669ad7040865a
Merged-In: I4f4328dceaa8609d1891b4b7129669ad7040865a
2017-09-06 10:35:40 -07:00
Nicolas Iooss
7e9d1344db Makefile: define a default value for CFLAGS
When building the project with "make DESTDIR=... install", the root
Makefile defines CFLAGS and LDFLAGS without any warning flags ("CFLAGS
+= -I$(DESTDIR)/usr/include" and "LDFLAGS += -L$(DESTDIR)/usr/lib"). As
the Makefiles in subdirectories do not override the flags with warning
flags, the code gets compiled without any enabled warning.

This leads for example to code being introduced which breaks building
libsepol from its directory, while building it from the root Makefile
still works fine.

This issue can be fixed by defining a set of flags in the root Makefile
which are used by all Makefiles in subdirectories. The flags have been
chosen following these principles:
* they are compatible with both clang and gcc,
* they already appear in at least one Makefile, and
* they are not triggered with the current git master version.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-09-05 12:37:41 -04:00
Nicolas Iooss
04fb15deb7 restorecond: check write() and daemon() results
When compiling restorecond with -Wunused, gcc 4.8.4 (from Ubuntu 14.04)
reports the following warnings:

    restorecond.c: In function ‘main’:
    restorecond.c:208:9: error: ignoring return value of ‘daemon’,
    declared with attribute warn_unused_result [-Werror=unused-result]
       daemon(0, 0);
             ^

    restorecond.c: In function ‘write_pid_file’:
    restorecond.c:106:2: error: ignoring return value of ‘write’,
    declared with attribute warn_unused_result [-Werror=unused-result]
      (void)write(pidfd, val, (unsigned int)len);
      ^

If any of these calls returns an error, it is currently silently
discarded. Add a message in order to warn about such an error.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-09-05 12:37:29 -04:00
Nicolas Iooss
13e5fa3b6b libsepol/cil: drop wrong unused attribute
cil_gen_node() has been using its argument "db" since commit
fafe4c212b ("libsepol: cil: Add ability to redeclare
types[attributes]"). Drop attribute "unused" on this argument.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-09-05 12:37:23 -04:00
Nicolas Iooss
12f3ef8280 libsepol/cil: fix -Wwrite-strings warning
cil_defaults_to_policy() defines its third argument as non-const "char
*kind" even though it is called with literal strings. This makes gcc
report the following warning when compiling with -Wwrite-strings:

    ../cil/src/cil_policy.c: In function ‘cil_gen_policy’:
    ../cil/src/cil_policy.c:1931:60: error: passing argument 3 of
    ‘cil_defaults_to_policy’ discards ‘const’ qualifier from pointer
    target type [-Werror=discarded-qualifiers]

      cil_defaults_to_policy(out, lists[CIL_LIST_DEFAULT_USER],
                             "default_user");
                             ^~~~~~~~~~~~~~

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-09-05 12:37:20 -04:00
Nicolas Iooss
3ab3a218f2 libsepol/cil: __cil_post_db_neverallow_attr_helper() does not use extra_args
Since commit 67b410e80f ("libsepol/cil: Keep attributes used by
generated attributes in neverallow rules") gcc reports the following
warning when building libsepol:

    ../cil/src/cil_post.c: In function
    ‘__cil_post_db_neverallow_attr_helper’:
    ../cil/src/cil_post.c:1322:17: error: unused variable ‘db’
    [-Werror=unused-variable]
      struct cil_db *db = extra_args;
                     ^~

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-09-05 12:37:16 -04:00
Nicolas Iooss
51bc21036c libsepol: use IN6ADDR_ANY_INIT to initialize IPv6 addresses
When compiling libsepol with clang and some warning flags, the compiler
complains about the way IPv6 addresses are initialized:

    kernel_to_cil.c:2795:35: error: suggest braces around initialization
    of subobject [-Werror,-Wmissing-braces]
            struct in6_addr subnet_prefix = {0};
                                             ^
                                             {}

When replacing the initializer as suggested, gcc 4.8.4 complains:

    kernel_to_cil.c: In function ‘write_selinux_ibpkey_rules_to_cil’:
    kernel_to_cil.c:2795:9: error: missing initializer for field
    ‘__in6_u’ of ‘struct in6_addr’ [-Werror=missing-field-initializers]
      struct in6_addr subnet_prefix = {};
             ^

Thankfully netinet/in.h provides a macro to initialize struct in6_addr
variables:

    #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }

Both clang and gcc no longer report warnings when using this macro.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-09-05 12:37:13 -04:00
Martijn Coenen
57fdb1f490 Don't load nonplat_service_contexts on full-treble.
On full Treble devices, servicemanager should only
host services served from processes on /system; don't load
nonplat_service_contexts.

Bug: 36866029
Test: builds, boot Taimen, boot Sailfish
Change-Id: Ia093c4c6b342335e35648db35e340e2df54fdcf3
Merged-In: Ia093c4c6b342335e35648db35e340e2df54fdcf3
(cherry picked from commit e3ab0e6086)
2017-09-04 15:25:14 +08:00
Dan Willemsen
734731c0b5 Turn off libc++ for libsepol, turn off host sanitize
am: 300e83bfe4

Change-Id: Iaec24a4131911bb653d4b9fd5a7b087e61d6a7bd
2017-09-01 23:38:12 +00:00
Dan Willemsen
300e83bfe4 Turn off libc++ for libsepol, turn off host sanitize
libsepol is entirely C, so it doesn't need libc++. On the host,
libsepolwrap loads libsepol into the system python, which does not have
the sanitizer runtime.

Test: SANITIZE_HOST=true m treble_sepolicy_tests
Test: mmma external/selinux
Change-Id: If22a6b3d492170871bdb70e71bba8148c607af01
2017-09-01 14:09:46 -07:00
James Carter
67b410e80f libsepol/cil: Keep attributes used by generated attributes in neverallow rules
In order to reduce policy size, CIL removes attributes that are not used
by a policy rule in the generated binary policy. However, CIL keeps
attributes used by neverallow rules (which are checked at compile time
and not in the binary policy) even if the attribute is not used anywhere
else in the policy. This behavior is useful to Google who pulls neverallow
rules out of the original policy.conf for compatibility testing, but
converts the policy.conf to CIL and uses the CIL compiler to generate
policy. Without this behavior, the generated binary policy might not have
an attribute referred to by one of the neverallow rules used for testing.

The one exception to this behavior is for attributes generated in
module_to_cil (these have an "_typeattr_" in the middle of their name).
Since these attributes are only created because CIL does not allow a
type expression in an AV rule, they are removed if they only appear in
a neverallow rule (which is the case for most of them) or if the
option to expand generated attributes (-G or --expand-generated) is
specified for secilc when compiling the policy.

Removing generated attributes causes a problem, however, if the type
expression that the generated attribute is replacing uses an attribute
that is removed. In this case, the original neverallow rule will refer
to an attribute that does not exist in the generated binary policy.

Now any non-generated attribute used in a typeattributeset rule for a
generated attribute which is used in a neverallow rule will be treated
like it was used in a neverallow rule.

This does not change the behavior of an expandtypeattribute rule for
the attribute. That rule, if it exists, will take precedence.

Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2017-08-31 14:44:59 -04:00
Dan Cashman
fafe4c212b libsepol: cil: Add ability to redeclare types[attributes]
Modify cil_gen_node() to check to see if the cil_db supports multiple
declarations, and if so, to check whether or not the
repeated symbol is eligible to share the existing, already-stored datum. The
only types considered so far are CIL_TYPE and CIL_TYPEATTRIBUTE, both of
which intall empty datums during AST building, so they automatically return
true.

Test: Build policy with multilpe type and attribute declarations, and
without. Policies are binary-identical.

Signed-off-by: Dan Cashman <dcashman@android.com>
Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2017-08-31 14:42:25 -04:00
Jan Zarsky
1346746d82 libsepol: reset pointer after free
In cil_strpool_destroy(), cil_strpool_tab is freed but it is not reset to NULL.
When cil_strpool_init() is called again it assumes that cil_strpool_tab was
already initialized. Other functions then work with invalid data.

Signed-off-by: Jan Zarsky <jzarsky@redhat.com>
2017-08-28 15:50:13 -04:00
Stephen Smalley
53bb2a11c2 checkpolicy,libselinux,libsepol,policycoreutils: Update my email address
Update my email address since epoch.ncsc.mil no longer exists.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-08-17 14:17:12 -04:00
Grégoire Colbert
f77ad59b46 Fixed bad reference in roleattribute
"roleattribute" was referencing "typeattributeset", but I believe it should be referencing "roleattributeset" instead.

Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2017-08-17 13:05:43 -04:00