Commit Graph

5094 Commits

Author SHA1 Message Date
Chris PeBenito fad0c3f126 Merge pull request #96 from fishilico/systemd-modules-load-sysfs 2019-09-07 16:34:34 -04:00
Dominick Grift 210b64f10a Remove shell automatic domain transitions to unconfined_t from various pam login programs
I think these may have been adopted from the old Red Hat targeted policy (that model only had unconfined users)

Some aspect to note:

1. The ssh_sysadm_login boolean now applies to unconfined_t as well
2. remotelogin only allows unpriv logins

The rshd module also calls unconfined_shell_domtrans() but I ignored that one because that policy currently does not have support for manual transitions with pam_selinux.

Signed-off-by: Dominick Grift <dac.override@gmail.com>
2019-09-07 16:26:49 -04:00
Nicolas Iooss 233e13cb44
systemd: allow systemd-modules-load.service to read sysfs
systemd-modules-load.service needs to read file
/sys/module/${MODULE}/initstate for each ${MODULE} defined in
/etc/modules-load.d/. These files are labeled sysfs_t.

This fixes:

    type=AVC msg=audit(1567804818.331:138713): avc:  denied  { read }
    for  pid=31153 comm="systemd-modules" name="initstate" dev="sysfs"
    ino=14778 scontext=system_u:system_r:systemd_modules_load_t
    tcontext=system_u:object_r:sysfs_t tclass=file permissive=0

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-09-06 23:28:40 +02:00
Chris PeBenito 51c4812c23 INSTALL: Fix build requirements.
Closes #85.

Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2019-09-03 19:47:48 -04:00
Chris PeBenito 5d636c2d16 various: Module version bump.
Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2019-09-03 19:47:12 -04:00
Chris PeBenito 9d80ada777 Merge pull request #78 from fishilico/debian-dynamic-motd 2019-09-03 19:44:13 -04:00
Chris PeBenito 2fa4070b60 Merge pull request #63 from fishilico/systemd-privatedev 2019-09-03 19:39:18 -04:00
Chris PeBenito f907287428 Merge pull request #79 from fishilico/corecommands-no-backslash-d 2019-09-03 19:34:47 -04:00
Chris PeBenito 05e9bc96f3 Merge pull request #80 from fishilico/typo-libraries-fc 2019-09-03 19:34:16 -04:00
Chris PeBenito 57562d974a Merge pull request #81 from fishilico/unnecessary-paren-java-fc 2019-09-03 19:33:43 -04:00
Chris PeBenito 39fd1ed486 Merge pull request #83 from fishilico/vagrant-devel 2019-09-03 19:30:48 -04:00
Chris PeBenito dadf53bd6e Merge pull request #84 from fishilico/systemd-timesyncd-networkd 2019-09-03 19:30:13 -04:00
Dominick Grift 3228c2b997 domain: unconfined access to bpf
Signed-off-by: Dominick Grift <dac.override@gmail.com>
2019-09-03 19:25:41 -04:00
Nicolas Iooss aa7e8d4091
ntp: allow systemd-timesyncd to read network status
systemd-timesyncd uses network_is_online() [1], which calls
sd_network_get_operational_state() [2], which reads
/run/systemd/netif/state [3]:

    r = parse_env_file(NULL, "/run/systemd/netif/state", "OPER_STATE", &s);

On a Debian virtual machine created with Vagrant,
/run/systemd/netif/state contains:

    # This is private data. Do not parse.
    OPER_STATE=routable
    DNS=192.168.121.1 172.28.128.1

systemd-timesyncd's access produces the following logs:

    type=AVC msg=audit(1567359197.660:323): avc:  denied  { read } for
    pid=230 comm="systemd-timesyn" name="state" dev="tmpfs" ino=24564
    scontext=system_u:system_r:ntpd_t
    tcontext=system_u:object_r:systemd_networkd_var_run_t tclass=file
    permissive=1

    type=AVC msg=audit(1567359197.660:324): avc:  denied  { open } for
    pid=230 comm="systemd-timesyn" path="/run/systemd/netif/state"
    dev="tmpfs" ino=24564 scontext=system_u:system_r:ntpd_t
    tcontext=system_u:object_r:systemd_networkd_var_run_t tclass=file
    permissive=1

    type=AVC msg=audit(1567359197.660:325): avc:  denied  { getattr }
    for  pid=230 comm="systemd-timesyn" path="/run/systemd/netif/state"
    dev="tmpfs" ino=24564 scontext=system_u:system_r:ntpd_t
    tcontext=system_u:object_r:systemd_networkd_var_run_t tclass=file
    permissive=1

Allow these accesses.

[1] https://github.com/systemd/systemd/blob/v242/src/timesync/timesyncd.c#L158
[2] https://github.com/systemd/systemd/blob/v242/src/libsystemd/sd-network/network-util.c#L13
[3] https://github.com/systemd/systemd/blob/v242/src/libsystemd/sd-network/sd-network.c#L27

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-09-01 20:44:14 +02:00
Nicolas Iooss 82e7ff119f
Vagrantfile: add a Debian virtual machine
Configure a Debian 10 "buster" VM in order to use SELinux with
refpolicy.

This is useful in order to test refpolicy on a minimal Debian system,
for example to debug issues related to Debian patches such as the one
fixed in https://github.com/SELinuxProject/refpolicy/pull/78.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-09-01 18:58:29 +02:00
Nicolas Iooss ea8a79e36a
Vagrantfile: build and install refpolicy on Fedora VM
Add provisioning commands that set-up refpolicy with the required build
configuration for Fedora.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-09-01 18:58:11 +02:00
Nicolas Iooss 0db0cd3057
java: remove unnecessary parentheses in pattern
/usr/lib/jvm/java(.*/)bin(/.*)? uses misleading parentheses around
".*/". In some cases, a pattern with (.*/) is a mispelling to (.*/)?,
but not here (/usr/lib/jvm/javabin/ never exists).

Moreover, using .* here is right, as the pattern matches the content of
subdirectories of /usr/lib/jvm/ which names are prefixed by java. More
precisely, the pattern matches for example:

- programs in /usr/lib/jvm/java-10-openjdk/bin
- programs in /usr/lib/jvm/java-8-openjdk/jre/bin

In the end, the pattern does not have any error, but the parentheses are
misleading. Remove them.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-09-01 16:06:32 +02:00
Nicolas Iooss 6901075d7f
libraries: fix some misspellings in patterns
In libraries.fc:

- "(/.*?)" is very likely a misspelling for (/.*)?
- "sidecars/*" with "--" as file type is very likely a misspelling for
  sidecars/.+, in order to match files that are shared libraries.
- "/opt/netbeans(.*/)?jdk" matches "/opt/netbeansjdk", which is buggy.

In Apache NetBeans 11.1 downloaded from
https://netbeans.apache.org/download/nb111/nb111.html, there are files
such as profiler/lib/deployed/jdk16/linux-amd64/libprofilerinterface.so.
Several websites document installing NetBeans in directories such as
/opt/netbeans-11.1/, so the installed .so files are probably installed in
/opt/netbeans-11.1/profiler/lib/deployed/jdk16/linux-amd64/libprofilerinterface.so.
There is thus an issue with the current pattern:

    /opt/netbeans(.*/)?jdk.*/linux/.+\.so(\.[^/]*)*

This pattern requires "/linux/" in the path, not "/linux-amd64/".

As this pattern was introduced in 2007 by commit 02d968c581 ("trunk:
several fc updates from dan."), consider it as outdated and remove it.

If the .so files in /opt/netbeans/ really need a label such as
textrel_shlib_t, a file pattern will need to be written with less issues
than the one which is removed.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-09-01 15:47:57 +02:00
Nicolas Iooss 2da886dccf
corecommands: no longer use \d
In order to detect bugs like the one fixed by commit d938683bf4
("drbd: fix pattern for /usr/lib/ocf/resource.d/linbit/drbd"), forbid
the use of \d in the policy. This was actually only used to match

    /usr/share/apr-1/build/...

with

    /usr/share/apr(-\d)?/build/[^/]+\.sh --	gen_context(system_u:object_r:bin_t,s0)
    /usr/share/apr(-\d)?/build/libtool --	gen_context(system_u:object_r:bin_t,s0)

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-09-01 15:26:55 +02:00
Nicolas Iooss 58189f4965
entropyd: haveged service uses PrivateDevices=yes
On Debian, haveged fails to start with "haveged: Couldn't open random
device: Permission denied". strace shows:

    openat(AT_FDCWD, "/dev/random", O_RDWR) = -1 EACCES (Permission denied)

audit.log has:

    type=AVC msg=audit(1566048720.132:1338): avc:  denied  { search }
    for  pid=20235 comm="haveged" name="/" dev="tmpfs" ino=76666
    scontext=system_u:system_r:entropyd_t
    tcontext=system_u:object_r:tmpfs_t tclass=dir permissive=0

With systemd, /dev is a temporary filesystem (tmpfs_t), so haveged needs
the search permission to it in order to open /dev/random. Use the
newly-added interface to allow this access.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-09-01 13:47:45 +02:00
Nicolas Iooss c021287125
Allow Debian to generate a dynamic motd when users log in
Debian's PAM configuration uses a patched pam_motd module that runs
files in /etc/update-motd.d/ in order to generate a dynamic Message Of
The Day (MOTD). By default, there is only one script:

    $ cat /etc/update-motd.d/10-uname
    #!/bin/sh
    uname -snrvm

According to https://wiki.debian.org/motd, the script is executed
through run-parts:

    if (!system("/usr/bin/env -i
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    run-parts --lsbsysinit /etc/update-motd.d >
    /run/motd.dynamic.new"))
        rename("/run/motd.dynamic.new", "/run/motd.dynamic");

This requires allowing pam_motd users to execute bin_t commands
(/usr/bin/env) and shells (/bin/sh), and to manage /run/motd.dynamic*
files.

Allow relevant accesses for Debian-based systems.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-09-01 13:44:28 +02:00
Nicolas Iooss 83797144d1
Vagrantfile: upgrade VM to Fedora 30
Use the official Fedora cloud image as a base for the virtual machine.

Allow defining other virual machines by putting the configuration of
Fedora's one into a sub-level.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-08-31 16:17:08 +02:00
Chris PeBenito 6b11dcef89 Various: Module version bump.
Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2019-08-31 06:55:57 -04:00
Chris PeBenito b43aebcc2f Merge pull request #70 from fishilico/typo-dot-star-question-fc 2019-08-31 06:26:00 -04:00
Chris PeBenito e88ca002eb Merge pull request #75 from fishilico/fc-escape-single-dot 2019-08-31 06:24:06 -04:00
Nicolas Iooss a7e3407606
systemd: introduce an interface for services using PrivateDevices=yes
When a service is configured with PrivateDevices=yes, its /dev directory
has label tmpfs_t. This requires allowing more accesses in order for the
service to use /dev.

This is related to https://github.com/SELinuxProject/refpolicy/pull/61

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-08-29 20:05:29 +02:00
Nicolas Iooss d00eddb885
libraries: drop a pattern specific to Python 2.4
Apply comment https://github.com/SELinuxProject/refpolicy/pull/75#discussion_r318831927

    We don't support any systems that are so old they have Python 2.4.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-08-29 20:03:02 +02:00
Nicolas Iooss d386950b0d
Fix use of buggy pattern (.*)?
The pattern "(.*)?" means "match anything including the nothing, or
nothing": the question mark is redundant. This is likely to be a
mispelling for "(/.*)?", which means "match a slash and anthing, or
nothing", or for ".*", or for other patterns.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-08-29 19:57:05 +02:00
Chris PeBenito 0b2ab72127 files: Module version bump.
Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2019-08-28 19:22:27 -04:00
Chris PeBenito 72693a37fc Merge pull request #72 from fishilico/files-usr-include-reduce-scope 2019-08-28 19:18:13 -04:00
Nicolas Iooss f0cade07b2
Remove unescaped single dot from the policy
In a pattern, a dot can match any character, including slash. It makes
sense when it is combined with ?, + or *, but makes little sense when
left alone.

Most of the time, the label was for file containing dots, where the dot
was not escaped. A few times, the dot was really intended to match any
character. In such case, [^/] better suits the intent.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-08-27 23:38:09 +02:00
Nicolas Iooss c9602a0cac
files: reduce the scope of the pattern matching /usr/include
The pattern that matches /usr/include uses a dot, in order probably to
avoid calling m4's function include(). This also matches other paths
such as /usr/inclu/e. Such a side-effect can be avoided by inserting an
empty string which is removed by m4's preprocessing.

Mailing-list discussion: https://lore.kernel.org/selinux-refpolicy/CAJfZ7=krh_TaCBQzFxLM394Sc5-82ZO0DdcfvWON-RXu-wqBVw@mail.gmail.com/t/#u

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-08-27 22:39:37 +02:00
Chris PeBenito b0fb76565b rpcbind: Module version bump.
Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2019-08-27 00:36:40 -04:00
Chris PeBenito 373a1c090a Merge pull request #73 from fishilico/rpcbind-redundant-pid-fc 2019-08-27 00:36:18 -04:00
Chris PeBenito 68b74385a4 various: Module version bump.
Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2019-08-27 00:28:34 -04:00
Chris PeBenito 95c4192509 Merge pull request #64 from fishilico/haveged-unit 2019-08-27 00:20:24 -04:00
Chris PeBenito 7e5503155c Merge pull request #65 from fishilico/haveged-cmd-socket 2019-08-27 00:19:57 -04:00
Chris PeBenito 20f1151192 Merge pull request #66 from fishilico/ulogd-fix-context 2019-08-27 00:19:10 -04:00
Chris PeBenito 1106d0b692 Merge pull request #67 from fishilico/typo-monit-s9 2019-08-27 00:18:47 -04:00
Chris PeBenito 5c9d60245b Merge pull request #68 from fishilico/typo-java-fc 2019-08-27 00:18:24 -04:00
Chris PeBenito de3e9befcc Merge pull request #69 from fishilico/typo-lib-adobe-fc 2019-08-27 00:17:46 -04:00
Chris PeBenito f3b7aeb872 Merge pull request #71 from fishilico/typo-drbd-fc 2019-08-27 00:09:47 -04:00
Nicolas Iooss 6875a1b0a5
rpcbind: remove redundant file context for /run/rpc.statd.pid
There are two patterns that define file contexts for /run/rpc.statd.pid:

* in policy/modules/services/rpcbind.fc:

    /run/rpc.statd\.pid	--	gen_context(system_u:object_r:rpcbind_var_run_t,s0)

* in policy/modules/services/rpc.dc:

    /run/rpc\.statd\.pid	--	gen_context(system_u:object_r:rpcd_var_run_t,s0)

They coexist even though their labels differ because the first one uses
a unescaped dot. As it does not seem to exist other files matching the
first pattern, remove it in order to only keep the second one.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-08-22 21:49:28 +02:00
Nicolas Iooss d938683bf4
drbd: fix pattern for /usr/lib/ocf/resource.d/linbit/drbd
In order to match /usr/lib/ocf/resource.d/linbit/drbd, the dot needs to
be escaped, not the d.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-08-21 23:03:01 +02:00
Nicolas Iooss 1b44cb6c2e
libraries: match a digit in Adobe Reader directories
Patterns using this have a small issue:

    /opt/Adobe/Reader.?/Reader/intellinux

The issue is that the dot can also match a slash. A bettern pattern
would be:

    /opt/Adobe/Reader[^/]?/Reader/intellinux

In this specific case, the intent is to match digits (like
/opt/Adobe/Reader9). Use [0-9] for this.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-08-21 21:43:56 +02:00
Nicolas Iooss 3d97e06a8d
java: reduce the scope of the pattern in for java entry points
The following pattern seems to match much more than intended:

    /usr/(.*/)?bin/java[^-]*

According to the commit which introduced it
(0190325c18),
the aim was to match java1.4, java5, java6, and not java-config nor
java-check-environment. The issue is that the pattern also matches
sub-directories such as:

    /usr/share/my-application/bin/java/myfile

Prevent this by adding / in the character blacklist of the pattern.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-08-21 21:41:11 +02:00
Nicolas Iooss 271352c1c2
monit: use s0 instead of s9
This seems to be a misspelling, and there is no reason which would
explain why monit's init script would be labeled with a different
sensitivity while the main binary uses s0.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-08-21 21:39:26 +02:00
Nicolas Iooss 2bfb67d339
ulogd: fix pattern for /run/ulog directory
The pattern only matched /run/ulog, not its content.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-08-18 21:38:00 +02:00
Nicolas Iooss d7f66dce04
entropyd: allow haveged to create a Unix socket to received commands
haveged listens to commands using a Unix socket
(at path "\0/sys/entropy/haveged" according to
https://github.com/jirka-h/haveged/blob/1.9.4/src/havegecmd.h#L34).
The implementation of this server is available on
https://github.com/jirka-h/haveged/blob/1.9.4/src/havegecmd.c .

This fixes the following denial:

    type=AVC msg=audit(1551002989.396:27): avc:  denied  { listen } for
    pid=262 comm="haveged"
    path=002F7379732F656E74726F70792F68617665676564
    scontext=system_u:system_r:entropyd_t
    tcontext=system_u:system_r:entropyd_t tclass=unix_stream_socket
    permissive=1

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-08-18 21:34:52 +02:00
Nicolas Iooss 1ab82b1150
entropyd: label the unit file of haveged
Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-08-18 21:20:27 +02:00