Commit Graph

461 Commits

Author SHA1 Message Date
Petr Lautrbach e6c99f34a1
Update VERSIONs to 3.7-rc3 for release.
Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
2024-06-20 14:49:08 +02:00
Petr Lautrbach 9ef1a83563
Update VERSIONs to 3.7-rc2 for release.
Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
2024-06-05 20:28:35 +02:00
Petr Lautrbach 6a223cb1c2
Update VERSIONs to 3.7-rc1 for release.
Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
2024-05-22 17:21:32 +02:00
Christian Göttsche a1fa1c8ad7 libsemanage: support huge passwd entries
getpwnam_r(3) might return ERANGE in case the supplied buffer was too
short for the passwd entry.  Retry with a bigger buffer.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2024-01-25 12:51:16 -05:00
Petr Lautrbach 97fa708d86
Update VERSIONs to 3.6 for release.
Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
2023-12-13 15:46:22 +01:00
Cameron Williams 89dd980c1e Add CPPFLAGS to Makefiles
This patch adds CPPFLAGS to all of the Makefiles as suggested.

Signed-off-by: Cameron Williams <ckwilliams.work@gmail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2023-12-06 13:35:32 -05:00
Sergei Trofimovich 2a46979ea3 libsemanage: fix src/genhomedircon.c build on `gcc-14` (`-Werror=alloc-size`)
`gcc-14` added a new `-Walloc-size` warning that makes sure that size of
an individual element matches size of a pointed type:

    https://gcc.gnu.org/PR71219

`libsemanage` triggers it on `calloc()` calls where member size is used
as `1` (instead of member count):

    genhomedircon.c: In function 'ignore_setup':
    genhomedircon.c:152:21:
      error: allocation of insufficient size '1' for type 'ignoredir_t'
        {aka 'struct IgnoreDir'} with size '16' [-Werror=alloc-size]
      152 |                 ptr = calloc(sizeof(ignoredir_t),1);
          |                     ^

Signed-off-by: Sergei Trofimovich <slyich@gmail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2023-12-06 13:34:35 -05:00
Petr Lautrbach 0f5a8dd3ac
Update VERSIONs to 3.6-rc2 for release.
Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
2023-11-22 16:01:56 +01:00
Petr Lautrbach 1aaf594346
Update VERSIONs to 3.6-rc1 for release.
Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
2023-11-08 12:51:35 +01:00
James Carter 14f35fde50 Do not automatically install Russian translations
Since they are being removed, there will be nothing to install.

Suggested-by: Petr Lautrbach <plautrba@redhat.com>
Signed-off-by: James Carter <jwcart2@gmail.com>
Acked-by: Petr Lautrbach <lautrbach@redhat.com>
2023-08-16 13:33:47 -04:00
James Carter 1303a6af48 libsemanage: Remove the Russian translations
The Russian translations have not been maintained and are out of
date, so remove them.

Suggested-by: Petr Lautrbach <plautrba@redhat.com>
Signed-off-by: James Carter <jwcart2@gmail.com>
Acked-by: Petr Lautrbach <lautrbach@redhat.com>
2023-08-16 13:33:22 -04:00
Christian Göttsche 8e3a532880 libsemanage/tests: use strict prototypes
utilities.c:39:22: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    int create_test_store() {
                         ^
                          void
    utilities.c:171:23: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    int destroy_test_store() {
                          ^
                           void

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
2023-08-16 13:33:12 -04:00
Christian Göttsche 3be312e0cf libsemanage: fix memory leak in semanage_user_roles
The output parameter `role_arr` of semanage_user_get_roles() is an array
of non-owned role names.  Since the array is never used again, as its
contents have been copied into the return value `roles`, free it.

Example leak report from useradd(8):

    Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x5597624284a8 in __interceptor_calloc (./shadow/src/useradd+0xee4a8)
    #1 0x7f53aefcbbf9 in sepol_user_get_roles src/user_record.c:270:21
2023-05-03 09:15:34 -04:00
Christian Göttsche b5dffcd9a1 libsemanage/tests: rename bool identifiers
Avoid using the identifier `bool` to improve support with future C
standards.  C23 is about to make `bool` a predefined macro (see N2654).

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2023-05-03 09:15:26 -04:00
Ondrej Mosnacek a171ba62bb
libsemanage: include more parameters in the module checksum
The check_ext_changes option currently assumes that as long as the
module content is unchanged, it is safe to assume that the policy.linked
file doesn't need to be rebuilt. However, there are some additional
parameters that can affect the content of this policy file, namely:
* the disable_dontaudit and preserve_tunables flags
* the target_platform and policyvers configuration values

Include these in the checksum so that the option works correctly when
only some of these input values are changed versus the current state.

Fixes: 286a679fad ("libsemanage: optionally rebuild policy when modules are changed externally")
Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
2023-03-20 10:44:08 +01:00
Jason Zaman d6e96c5929
Update VERSIONs to 3.5 for release.
Signed-off-by: Jason Zaman <jason@perfinion.com>
2023-02-23 05:16:11 -08:00
Jason Zaman 83e56c8a8b
Update VERSIONs to 3.5-rc3 for release.
Signed-off-by: Jason Zaman <jason@perfinion.com>
2023-02-10 22:32:13 -08:00
Jason Zaman 3ccea01c69
Update VERSIONs to 3.5-rc2 for release.
Signed-off-by: Jason Zaman <jason@perfinion.com>
2023-01-15 15:40:55 -08:00
Jason Zaman 013ecfd7fa Update VERSIONs to 3.5-rc1 for release.
Signed-off-by: Jason Zaman <jason@perfinion.com>
2022-12-22 13:10:26 -08:00
Vit Mojzis c84b977b17 libsemanage: Use more conscious language
https://inclusivenaming.org/word-lists/tier-1/

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-12-16 16:30:19 -05:00
James Carter 33e56c9b2e libsemanage: Remove dependency on the Python module distutils
The distutils package is deprecated and scheduled to be removed in
Python 3.12. Use the sysconfig module instead.

Signed-off-by: James Carter <jwcart2@gmail.com>
Acked-by: Petr Lautrbach <plautrba@redhat.com>
2022-11-09 07:51:21 -05:00
Paul Moore a0a216ff7d docs: provide a top level LICENSE file
Provide a top level LICENSE file explaining how multiple the SELinux
userspace is released under multiple different licenses.  Also ensure
that all the different license files share a consistent file name,
LICENSE, to make it easier for people to identify the license files.

This is to help meet the OpenSSF Best Practices requirements.

Signed-off-by: Paul Moore <paul@paul-moore.com>
2022-10-05 08:20:38 -04:00
Matt Sheets 01b5ef48dc libsemanage: Allow user to set SYSCONFDIR
This change will allow a user to set the location of their
sysconfdir, defaulted to /etc, if they are installing into
nonstandard locations.

Signed-off-by: Matt Sheets <masheets@linux.microsoft.com>
Reviewed-by: Daniel Burgener <dburgener@linux.microsoft.com>
2022-10-05 08:15:00 -04:00
Ondrej Mosnacek bdbe52be1b
libsemanage: always write kernel policy when check_ext_changes is specified
For the use case of rebuilding the policy after package updates, we need
the check_ext_changes operation to always do at least the do_write_kernel
step, because the various semanage dbs may have also changed content
relative to the current binary policy. As this step is itself relatively
fast, we can do it unconditionally.

Fixes: 286a679fad ("libsemanage: optionally rebuild policy when modules are changed externally")
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Acked-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2022-06-30 21:09:00 +02:00
Petr Lautrbach 0a8c177dac
Update VERSIONs to 3.4 for release.
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2022-05-18 16:51:03 +02:00
Petr Lautrbach 9df28c241a
Update VERSIONs to 3.4-rc3 for release.
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2022-05-04 19:20:37 +02:00
Petr Lautrbach 2a167d1156
Update VERSIONs to 3.4-rc2 for release.
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2022-04-20 21:48:57 +02:00
Christian Göttsche 0ba7e23189 libsemanage: ignore missing prototypes in swig generated code
The code generated by swig triggers the following warning:

    semanageswig_wrap.c:2759:24: warning: no previous prototype for ‘PyInit__semanage’ [-Wmissing-prototypes]
     2759 | #  define SWIG_init    PyInit__semanage
          |                        ^~~~~~~~~~~~~~~~
    semanageswig_wrap.c:17772:1: note: in expansion of macro ‘SWIG_init’
    17772 | SWIG_init(void) {
          | ^~~~~~~~~

Ignore -Wmissing-prototypes for swig generated source files.

Acked-by: James Carter <jwcart2@gmail.com>
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2022-04-20 14:03:44 -04:00
James Carter e1b7b29027 libsemanage/tests: Remove unused functions
The functions helper_port_validate_local_proto(), get_type(), and
get_fcontext_new() are not used, so remove them.

Signed-off-by: James Carter <jwcart2@gmail.com>
2022-04-20 14:03:44 -04:00
James Carter 031c033046 libsemanage/tests: Declare file local functions as static
This is needed to use "-Wmissing-prototypes".

Signed-off-by: James Carter <jwcart2@gmail.com>
2022-04-20 14:03:44 -04:00
Christian Göttsche fd67b2f4b1 Correct misc typos
Found by typos[1].

[1]: https://github.com/crate-ci/typos

Acked-by: James Carter <jwcart2@gmail.com>
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2022-04-12 13:09:52 -04:00
Christian Göttsche e205e3e84a libsemanage: avoid double fclose
The cleanup goto block in `semanage_direct_set_enabled()` closes the
file stream pointer fp if not NULL.  Set the stream to NULL after a
manual fclose(3), even on failure.

    direct_api.c: In function ‘semanage_direct_set_enabled’:
    direct_api.c:2130:25: error: pointer ‘fp’ may be used after ‘fclose’ [-Werror=use-after-free]
     2130 |         if (fp != NULL) fclose(fp);
          |                         ^~~~~~~~~~
    direct_api.c:2092:29: note: call to ‘fclose’ here
     2092 |                         if (fclose(fp) != 0) {
          |                             ^~~~~~~~~~

Acked-by: James Carter <jwcart2@gmail.com>
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2022-04-12 13:09:50 -04:00
Petr Lautrbach 73562de8fc
Update VERSIONs to 3.4-rc1 for release.
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2022-04-06 19:53:39 +02:00
Petr Lautrbach 28510556f8 libsemanage: Fix USE_AFTER_FREE (CWE-672) in semanage_direct_get_module_info()
>From fclose(3):
Upon successful completion, 0 is returned.  Otherwise, EOF is returned
and errno is set to indicate the error. In either case, any further
access (including another call to fclose()) to the stream results in
undefined behavior.

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
Acked-by: James Carter <jwcart2@gmail.com>
2022-04-06 10:54:58 +02:00
Petr Lautrbach c7a3b93e31 libsemanage: Fall back to semanage_copy_dir when rename() fails
In some circumstances, like semanage-store being on overlayfs, rename()
could fail with EXDEV - Invalid cross-device link. This is due to the
fact that overlays doesn't support rename() if source and target are not
on the same layer, e.g. in containers built from several layers. Even
though it's not atomic operation, it's better to try to copy files from
src to dst on our own in this case. Next rebuild will probably not fail
as the new directories will be on the same layer.

Fixes: https://github.com/SELinuxProject/selinux/issues/343

Reproducer:

    $ cd selinux1

    $ cat Dockerfile
    FROM fedora:35
    RUN dnf install -y selinux-policy selinux-policy-targeted

    $ podman build -t localhost/selinux . --no-cache

    $ cd ../selinux2

    $ cat Dockerfile
    FROM localhost/selinux
    RUN semodule -B

    $ podman build -t localhost/selinux2 . --no-cache
    STEP 2/2: RUN semodule -B
    libsemanage.semanage_commit_sandbox: Error while renaming /var/lib/selinux/targeted/active to /var/lib/selinux/targeted/previous. (Invalid cross-device link).
    semodule:  Failed!
    Error: error building at STEP "RUN semodule -B": error while running runtime: exit status 1

With the fix:

    $ podman build -t localhost/selinux2 . --no-cache
    STEP 2/2: RUN semodule -B
    libsemanage.semanage_rename: Warning: rename(/var/lib/selinux/targeted/active, /var/lib/selinux/targeted/previous) failed: Invalid cross-device link, fall back to non-atomic semanage_copy_dir_flags()

    COMMIT localhost/selinux2
    --> d2cfcebc1a1
    Successfully tagged localhost/selinux2:latest
    d2cfcebc1a1b34f1c2cd661ac18292b0612c3e5fa71d6fa1441be244da91b1af

Reported-by: Joseph Marrero Corchado <jmarrero@redhat.com>
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
Acked-by: Ondrej Mosnacek <omosnace@redhat.com>
2022-04-06 10:44:05 +02:00
Vit Mojzis c79d38ff0c libsemanage: allow spaces in user/group names
"semanage login -a" accepts whitespaces in user/group name
(e.g. users/groups from Active Directory), which may lead to issues down
the line since libsemanage doesn't expect whitespaces in
/var/lib/selinux/targeted/active/seusers and other config files.

Fixes:
  Artificial but simple reproducer
  # groupadd server_admins
  # sed -i "s/^server_admins/server admins/" /etc/group
  # semanage login -a -s staff_u %server\ admins
  # semanage login -l  (or "semodule -B")
  libsemanage.parse_assert_ch: expected character ':', but found 'a' (/var/lib/selinux/targeted/active/seusers: 6):
  %server admins:staff_u:s0-s0:c0.c1023 (No such file or directory).
  libsemanage.seuser_parse: could not parse seuser record (No such file or directory).
  libsemanage.dbase_file_cache: could not cache file database (No such file or directory).
  libsemanage.enter_ro: could not enter read-only section (No such file or directory).
  FileNotFoundError: [Errno 2] No such file or directory

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2022-03-03 12:10:03 -05:00
Ondrej Mosnacek 286a679fad libsemanage: optionally rebuild policy when modules are changed externally
In Fedora/RHEL's selinux-policy package we ship a pre-built SELinux
policy store in the RPMs. When updating the main policy RPM, care must
be taken to rebuild the policy using `semodule -B` if there are any
other SELinux modules installed (whether shipped via another RPM or
manually installed locally).

However, this way of shipping/managing the policy creates complications
on systems, where system files are managed by rpm-ostree (such as Fedora
CoreOS or Red Hat CoreOS), where the "package update" process is more
sophisticated.

(Disclaimer: The following is written according to my current limited
understanding of rpm-ostree and may not be entirely accurate, but the
gist of it should match the reality.)

Basically, one can think of rpm-ostree as a kind of Git for system
files. The package content is provided on a "branch", where each
"commit" represents a set of package updates layered on top of the
previous commit (i.e. it is a rolling release with some defined
package content snapshots). The user can then maintain their own branch
with additional package updates/installations/... and "rebase" it on top
of the main branch as needed. On top of that, the user can also have
additional configuration files (or modifications to existing files) in
/etc, which represent an additional layer on top of the package content.

When updating the system (i.e. rebasing on a new "commit" of the "main
branch"), the files on the running system are not touched and the new
system state is prepared under a new root directory, which is chrooted
into on the next reboot.

When an rpm-ostree system is updated, there are three moments when the
SELinux module store needs to be rebuilt to ensure that all modules are
included in the binary policy:
1. When the local RPM installations are applied on top of the base
   system snapshot.
2. When local user configuartion is applied on top of that.
3. On system shutdown, to ensure that any changes in local configuration
   performed since (2.) are reflected in the final new system image.

Forcing a full rebuild at each step is not optimal and in many cases is
not necessary, as the user may not have any custom modules installed.

Thus, this patch extends libsemanage to compute a checksum of the
content of all enabled modules, which is stored in the store, and adds a
flag to the libsemanage handle that instructs it to check the module
content checksum against the one from the last successful transaction
and force a full policy rebuild if they don't match.

This will allow rpm-ostree systems to potentially reduce delays when
reconciling the module store when applying updates.

I wasn't able to measure any noticeable overhead of the hash
computation, which is now added for every transaction (both before and
after this change a full policy rebuild took about 7 seconds on my test
x86 VM). With the new option check_ext_changes enabled, rebuilding a
policy store with unchanged modules took only about 0.96 seconds.

Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
2022-02-18 11:08:39 -05:00
Ondrej Mosnacek df9f71ab50 libsemanage: clean up semanage_direct_commit() a bit
Do some minor cosmetic cleanup, mainly to eliminate the 'rebuilt' goto
label.

Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
2022-02-18 11:08:36 -05:00
Ondrej Mosnacek d01ec02fb9 libsemanage: move compressed file handling into a separate object
In order to reduce exisiting and future code duplication and to avoid
some unnecessary allocations and copying, factor the compressed file
utility functions out into a separate C/header file and refactor their
interface.

Note that this change effectively removes the __fsetlocking(3) call from
semanage_load_files() - I haven't been able to figure out what purpose
it serves, but it seems pointless...

Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
2022-02-18 11:08:34 -05:00
Ondrej Mosnacek 67e6201bc8 semodule,libsemanage: move module hashing into libsemanage
The main goal of this move is to have the SHA-256 implementation under
libsemanage, since upcoming patches will make use of SHA-256 for a
different (but similar) purpose in libsemanage. Having the hashing code
in libsemanage will reduce code duplication and allow for easier hash
algorithm upgrade in the future.

Note that libselinux currently also contains a hash function
implementation (for yet another different purpose). This patch doesn't
make any effort to address that duplicity yet.

This patch also changes the format of the hash string printed by
semodule to include the name of the hash. The intent is to avoid
ambiguity and potential collisions when the algorithm is potentially
changed in the future.

Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
2022-02-18 11:08:30 -05:00
Ondrej Mosnacek 6f9e771987 libsemanage: add missing include to boolean_record.c
It uses asprintf(3), but doesn't directly include <stdio.h> - fix it.

Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
2022-02-18 11:08:27 -05:00
Christian Göttsche f7ec4b4a84 libsemanage: add extern prototype for legacy function
modules.c:171:13: warning: no previous prototype for ‘semanage_module_get_version’ [-Wmissing-prototypes]
      171 | const char *semanage_module_get_version(semanage_module_info_t * modinfo
          |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2021-11-15 16:00:54 -05:00
Christian Göttsche 35273aa2bf libsemanage: include paired header for prototypes
context_record.c:11:13: warning: no previous prototype for ‘semanage_context_get_user’ [-Wmissing-prototypes]
       11 | const char *semanage_context_get_user(const semanage_context_t * con)
          |             ^~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2021-11-15 16:00:54 -05:00
Christian Göttsche 1927c1dfcc libsemanage: mark local functions static
utilities.c:295:18: warning: no previous prototype for ‘list_addafter_controlmem’ [-Wmissing-prototypes]
      295 | semanage_list_t *list_addafter_controlmem(semanage_list_t * item, char *data)
          |                  ^~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2021-11-15 16:00:54 -05:00
Markus Linnala 7e30a10ba9 Use IANA-managed domain example.com in examples
See: RFC 2606

foo.com seems to be privately owned.

Signed-off-by: Markus Linnala <Markus.Linnala@knowit.fi>
Acked-by: Petr Lautrbach <plautrba@redhat.com>
2021-11-15 10:53:27 +01:00
Christian Göttsche fe01a91a79
libsemanage/tests: free memory
Free all memory in test cases, reported by LeakSanitizer.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2021-11-11 22:40:30 +01:00
Christian Göttsche ea539017fb
libsemanage: do not sort empty records
Do not sort empty records to avoid calling qsort(3) with a NULL pointer.
qsort(3) might be annotated with the function attribute nonnull and
UBSan then complains:

    database_join.c:80:2: runtime error: null pointer passed as argument 1, which is declared to never be null

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
2021-11-11 22:40:26 +01: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
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 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