Commit Graph

114 Commits

Author SHA1 Message Date
Panu Matilainen a77c1d0670 Fix libintl linkage and include directories (cmake transition fallout)
We checked for libintl in the top-level CMakeLists.txt but then never
used it for anything. This only ever worked on glibc where this all
is bundled in. Unfortunately Intl only becomes an importable target
in cmake >= 3.20 which is too new for us to rely on for now.

Python bindings are omitted here because we don't have any translated
messages in there. Whether we should is another topic.
2024-01-08 12:32:35 +02:00
Panu Matilainen 54a79a19c4 Fix a bunch of integer size mismatch warnings on 32bit builds 2023-11-27 15:46:33 +02:00
Panu Matilainen fd8eaa52cc Add a new plugin to enable Linux-specific namespace functionality
A plugin is a convenient place to hide Linux-specific functionality.
Implemented in this initial version are:

- Optional private mounts during scriptlet execution, useful for
  protecting the system from scriptlets (eg /home) and the scriptlets
  from themselves (eg insecure /tmp usage)
- Optionally disable network access during scriptlet execution

Note that at this time, scriplets executed with the embedded Lua
interpreter are not covered by this because they run inside the main rpm
process instead of forking (#2635).

Add a testcase for private /tmp

Suggested-by: Johannes Segitz <jsegitz@suse.de>

Fixes: #2632
Fixes: #2665
2023-10-11 09:52:22 +03:00
Panu Matilainen c284d09e81 Argh, unbreak plugins from the previous commit
Rpm is probably the only software in existence that uses a prefix
instead of a suffix for detecting it's own macro files. Commit
ce7210d584 got it exactly wrong.
Too many meetings must have melted my brains.

The great irony here is that this breakage occurs while developing a
test-case for plugin-development. Oh well.
2023-10-05 09:57:00 +03:00
Panu Matilainen ce7210d584 Split plugin config macros to per-plugin macros.d files
Carrying the plugin config in the main macros file for plugins that
might not even have been built+installed seems dumb, but considering
that we didn't even *have* macros.d back then, more excusable. It no
longer is, though. Split the macros to their own files, to be installed
only along with a built plugin.
2023-10-05 09:28:19 +03:00
Panu Matilainen ab28534f9e Make our plugin directory a global cache configurable and export it
Make the plugin directory a cache item and honor wrt it wrt macros.
Export the info in both pkg-config and our cmake package info.
2023-10-03 15:40:04 +03:00
Panu Matilainen 959b4e4750 Make the plugin API public
We've procrastinated on making this API public for about ten years now,
and in the meanwhile there has been exactly one disruptive change to
the API. As in, it might've just as well been public all along.

There will always be more things to improve wrt any API, but we're not
going to hold this hostage to one more thing or another anymore. Some
of them we'd like to do before this goes to a stable release (ie 4.20)
but doing this now to kinda enforce this actually happens this time
around, through come hell or high water.

Fixes: #1536
2023-09-13 14:51:25 +03:00
Panu Matilainen 1c98b67911 Drop top-level source for our global include directories
Having everything accessible to everything encourages fast and loose
includes from places one shouldn't be using, and makes it easy for
those cases to hide in plain sight as well. There were reasons for
the top-level include back in 2007 but our codebase is a rather
different beast these days. Limiting access through per-target
include directories on everything nicely highlights the exceptions
and makes the whole more controllable and manageable.

This change looks huge, but it's just due to stripping no longer valid
prefixes from all the gazillion internal includes. No rpm-side
functionality is affected, this is just source-level hygiene operation.
2023-09-13 13:34:17 +03:00
Panu Matilainen 34d983fa2a Fix compile regression from 071be753cf
A declaration immediately following a label is not valid C99, as crazy
as it is in a language that otherwise allows free placement of declarations.
It looks like something people forgot to update in the standard, first
in C99 and apparently C11 too. Recent gcc doesn't complain about it
but it doesn't make it right.

Suggested-by: Dmitry Mikushin <dmitry@kernelgen.org>
2023-09-13 11:04:33 +03:00
Panu Matilainen 5f23d76eb9 Emit a debug message instead of silence when DBus unavailable
Make systemd_inhibit plugin behave identically to dbus_announce in the
previous commit: when DBus service isn't available, emit a debug level
message rather than completely suppressing the message to keep things
troubleshootable.
2023-09-01 11:21:44 +03:00
Panu Matilainen 071be753cf Suppress inhibition lock warning message when DBus service is not available
Same as commit 708e61307b, this message
will just annoy and confuse users in situations where DBus service is
not running at all, such as single-user mode and minimal container type
environments. Like our own test-suite. Rather than entirely suppress
the error, issue a debug log though.
2023-09-01 11:21:44 +03:00
Panu Matilainen 27c2a7ba97 Drop unnecessary internal includes from the fsverity plugin
Same as 995d1b3fc9, don't know how I
missed this despite actually looking.
2023-06-20 12:14:08 +03:00
Panu Matilainen 995d1b3fc9 Drop unnecessary internal includes from the IMA plugin 2023-06-13 12:57:26 +03:00
Florian Festi 51c596a6c8 Move dbus announce plugin config to DATADIR
Users are not supposed to meddle with this. So it really should not go
into /etc.

Use the DATADIR from dbus-1 and not our own install prefix.

Resolves: #2474
2023-06-05 10:18:39 +03:00
Panu Matilainen acfe252822 Fix undefined symbols from plugins in some circumstances
Another bit lost in the cmake transition: plugin linkage to librpm and
librpmio. In rpm itself this doesn't really matter because the running
process supplies the necessary symbols but it's a different story when eg
a Python process uses dlopen()'ed bindings.
2023-05-22 17:29:23 +02:00
Florian Festi 2080896ce5 Install /etc/dbus-1/system.d/org.rpm.conf
which was accidentially dropped when converting to cmake

Use CMAKE_INSTALL_FULL_SYSCONFDIR as it expands to /etc instead of
/usr/etc

Resolves: #2474
2023-04-11 15:49:44 +03:00
Panu Matilainen 64dea7618b Implement proper imaevm detection in the cmake build
Abort the build if imaevm enabled but header+library not present, use
detected values. Check for lsetxattr() availability. Drop unnecessary
imaevm linkage from the plugin, the plugin only manipulates xattrs and
does not need the IMA library.
2022-12-13 13:37:02 +02:00
Panu Matilainen 71fe36cdc5 Use cmake imported targets to let it sort out the compiler flag details
These imported targets passed to target_link_library() are supposed to
handle all the pesky compilation, linkage etc details behind the scenes.
I was pretty sure I was missing a trick with this, but this sure isn't
exactly underlined in the documentation.

Unroll the supposedly helpful loop for handling plugins: turns out doing
this cmake native way is plenty shorter and more obvious too. The unroll
kinda belongs to a separate commit but that'd be rather painful for very
little if any gain.

Fixes: #2269 and a whole class of similar cases, allegedly
2022-11-28 11:31:21 +02:00
Panu Matilainen e9f03dec40 Fix fsverity plugin build, obviously never worked with cmake before, doh 2022-11-03 14:45:49 +02:00
Panu Matilainen 3dcf09b0f2 Fix libacl and libaudit linkage to use info from pkg-config 2022-11-03 14:35:02 +02:00
Panu Matilainen 6f1c67ffb1 Remove autotools build
There are some missing bits and pieces still to be done for cmake build,
but that is so much easier if you don't have to worry about keeping
compatibility with the system you're about to remove that it doesn't
make sense to drag this on any further. The sooner this is over, the
sooner it is over and we can start making use of cmake's advantages
instead of just trying to bend over backwards to maintain compatibility
with the autotools build.
2022-10-21 09:03:05 +03:00
Panu Matilainen 96888e99c5 Add a handler for libselinux log messages (RhBug:2123719, RhBug:2050774)
libselinux logs to stderr by default, which up to now has been just fine
with us. However somewhere around libselinux 3.2 it begun issuing
log messages for events discovered in selinux_status_updated().
We only call that to see whether the status *was* updated behind our
back and are not interested in these audit-style messages for our
functionality, but to suppress them while preserving actually relevant
errors and warnings, we need to have a log callback of our own. Might as
well forward them to rpmlog then.

SELINUX_ERROR and SELINUX_WARNING are pretty obvious, of SELINUX_AVC
selinux_set_callback(3) says it should be treated as SELINUX_ERROR if
not audited. The rest we suppress to debug messages, they may be handy
for diagnostics some day.

Note that this intentionally avoids explicit SELINUX_POLICYLOAD and
SELINUX_SETENFORCE cases in the switch: we don't want to introduce
libselinux >= 3.2 dependency just because of this silly thing.
2022-10-18 09:40:26 +03:00
Radovan Sroka 534fd1f0c8 fapolicyd: Make write() nonblocking
- switch to read only and non blocking mode for pipe
- add 1 minute loop to wait for pipe to reappear

Sometimes during the system update/upgrade fapolicyd
get restarted e.g. when systemd gets updated.
That can lead to the situation where fapolicyd pipe
has been removed and created again.
In such cases rpm-plugin-fapolicyd gets stuck on
write() to the pipe which does not exist anymore.
After switching to non blocking file descriptor
we can try to reopen the pipe if there is an error
from write(). Assuming that a new pipe should appear
when fapolicyd daemon starts again.
If not then after 1 minute of waiting we expect
fapolicyd daemon to be not active and we let the
transaction continue.

Signed-off-by: Radovan Sroka <rsroka@redhat.com>
2022-09-13 10:12:48 +03:00
Panu Matilainen 8c3fb5eb01 Add an experimental CMake build system
This is an incomplete release-early version, NOT intended or
suitable for production use. It is intended to replace the autotools
based buildsystem in rpm 4.20, until then it'll be developed alongside
it. This causes some extra complications of course, but then we avoid
a huge flag-day, and that matters more.

To those wondering why cmake and not ${myfavorite}: the community around
us effectively made that choice for us. We've made a lot of noise about
bootstrap dependencies. When libsolv, dnf and all the related stack is
powered by cmake build, it'd be just foolish to go with anything else.
This way people working on the rpm stack have only one build system to
learn, there's peer support available nearby and bootstrap dependencies
are reduced, not increased. It also doesn't hurt that cmake is actually
and actively maintained.
2022-06-28 16:33:33 +03:00
Panu Matilainen b1fed31a99 Drop support for ancient libselinux
setexecfilecon() is in libselinux version 2.3 in 2014, we don't need to
worry about it's availability anymore. Instead, use it to determine
libselinux suitability in the configure check, eliminating another
redundant check and a bunch of unused code.
2022-06-16 09:17:34 +03:00
Panu Matilainen 650ba79f22 Eliminate the strange include pre-build install machinery
Introduced back in 2007 in 5831404601 the
point was to fake up a sane public header structure with minimal
internal disruption, TEMPORARILY. I think 15 years is temporary enough.

The machinery has worked rather well for what it is, but having the
headers appear in multiple locations is weird and confusing to people,
plus this "physical" separation makes it far more clearer what is
a public header and what isn't.
2022-03-10 08:40:07 +02:00
Panu Matilainen 2f0f3be64d Use proper addressing for our public headers everywhere 2022-03-10 08:40:07 +02:00
Panu Matilainen d44be2cbc1 Rename pgpHexStr() to rpmhex(), but preserve ABI for now
Fixup internal callers to use rpmhex(), deprecate pgpHexStr().
pgpHexStr() should be dropped at next soname bump, whenever that
happens.
2022-02-25 11:08:25 +01:00
Darren Kenny 7db2efa95d ima: Install on filesystems without xattr support without failing
If an RPM contains IMA signed digests and rpm-plugin-ima is installed,
then any attempt to install to a filesystem that doesn't support
extended attributes will cause the RPM installation to fail.

This can be seen, for example, if installing a file /boot, which is
usually a vFAT filesystem.

The rpm-plugin for selinux fixed this some time back, and that same
logic can be applied to IMA too - where, if a failure to set an extended
attribute results in an errno that is set to EOPNOTSUPP, then this
should not cause a complete failure, but should instead just be logged
at a debug level.

Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
2022-02-23 10:36:25 +02:00
Panu Matilainen 35195684d2 Pass file descriptor to file prepare plugin hook, use when possible
Sadly the thing that allegedly makes things better mostly just makes
things more complicated as symlinks can't be opened, so we'll now have
to deal with both cases in plugins too. To make matters worse, most
APIs out there support either an fd or a path, but very few support
the *at() style dirfd + basename approach so plugins are stuck with
absolute paths for now.

This is of course a plugin API/ABI change too.
2022-02-16 10:57:18 +02:00
Panu Matilainen a388d5e8ab Fix missing includes revealed by c2ef4dd2a7 2021-11-18 09:49:40 +02:00
Justus Winter c2ef4dd2a7 Include rpmpgp.h only where it is actually needed
Include necessary headers that were previously transitively included
by including rpmpgp.h.
2021-11-17 14:21:06 +02:00
Florian Festi 2a03b8fa12 Add dbus-announce plugin
The plugin announces start and end of transactions
2021-08-12 13:42:34 +03:00
Radovan Sroka 6d61b7118a Fix resource leaks in fapolicyd plugin
Issues were found by coverity scan.

Signed-off-by: Radovan Sroka <rsroka@redhat.com>
2021-03-10 13:14:34 +02:00
Radovan Sroka 39595ccee3 Added fapolicyd rpm plugin
Fapolicyd (File Access Policy Daemon) implements application whitelisting
to decide file access rights. Applications that are known via a reputation
source are allowed access while unknown applications are not.

The rpm plugin allows us to use rpm database as a source of trust.
We used dnf plugin since the beggining but it only provides notification
when transaction ends. With "integrity checking" requirement we need
a continual addition of files which are installed during the system
update. With fapolicyd rpm plugin we can allow using of recently
added/updated files in scriptlets during rpm transaction.

The fapolicyd plugin gathers metadata of currently installed files.
It sends the information about files and about ongoing rpm transaction
to the fapolicyd daemon. The information is written to Linux pipe which
is placed in /var/run/fapolicyd/fapolicyd.fifo.

The data format is "%s %lu %64s\n". [path, size, sha256]

The fapolicyd rpm plugin can be enabled with "--with-fapolicyd"
configure option.

Related PRs:
https://github.com/linux-application-whitelisting/fapolicyd/pull/105
https://github.com/linux-application-whitelisting/fapolicyd/pull/106

Signed-off-by: Radovan Sroka <rsroka@redhat.com>
2021-01-28 16:35:35 +02:00
Panu Matilainen dd5c0446a3 Stop using deprecated security_context_t
In libselinux >= 3.1 these cause deprecation warnings on build.

security_context_t always was nothing but typedef to plain old "char *"
so just using that is entirely backwards compatible too.
2020-10-28 10:40:22 +02:00
Jes Sorensen bd02416cd3 fsverity plugin: Use tag for algorithm
This uses the algorithm from the tag, if available. Fallback is SHA256.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2020-09-04 13:22:38 +03:00
Jes Sorensen 9b3a65ef06 plugins/fsverity: Install fsverity signatures
This plugin installs fsverity signatures for regular files, when a signature
is found in the RPM. It tries to enable them unconditionally, but fails
gracefully if fsverity isn't supported or enabled.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2020-09-04 13:22:38 +03:00
Panu Matilainen 153c5c2198 Use common error logic regardless of setexecfilecon() availability
Refactor the custom exec context setting code to look like setexecfilecon()
in case the real one is not available to eliminate pesky behavioral
differences between the two cases.

This fixes a concrete bug of libselinux setexecfilecon() returning with
an error when security_getenforce() returns with -1 (such as a bare
chroot with no /sys mounts etc), causing us to spit out useless error
messages in that case ever since fixing the bogus if-logic in
commit ab601b882b.

Fixes: #1077
2020-02-19 14:26:15 +01:00
Panu Matilainen 4ddab4fb7e Fix a minor memory leak on suppressed inhibition lock warning message
Commit 708e61307b introduced a memory leak
on the error object: if the message is suppressed then the error object
is never freed. Test for the suppression conditions separately to fix.
2020-01-29 15:19:18 +01:00
Panu Matilainen 4a71a3eccd Silence spurious error message from lsetfilecon() on -EOPNOTSUPP
We already filter out -EOPNOTSUPP and return OK, but the message was
getting logged before the filtering so we'd spit out spurious error
messages on filesystems that don't support SELinux (RhBug:1777502)
2019-12-13 13:49:03 +01:00
Panu Matilainen 9b512ac829 Revert "Fully shutdown DBUS on systemd_inhibit cleanup (RhBug:1714657)"
Turns out this isn't a safe thing to do, as an API user could have
their own dbus connections in the same process and shutting those
down is a rather impolite thing to do (and causes crash, burn and
other injuries, eg RhBug:1750575)

This reverts commit d5f201345f.
2019-10-16 14:08:13 +03:00
Panu Matilainen ab601b882b Fix suspicious condition in selinux plugin
Misplaced parenthesis introduced in commit 148e82833a.

Fixes #872
2019-10-07 14:40:41 +03:00
Shogo Matsumoto 708e61307b Suppress inhibition lock warning message when DBus service is not available
The message may just confuse users if DBus is not running as default,
e.g. single-user mode. We suppress it when DBus is not available,
which is done by checking two cases:
socket does not exist (DBUS_ERROR_FILE_NOT_FOUND), or
unable to connect to server (DBUS_ERROR_NO_SERVER).
Note that this is an approximate but not an exact way to detect
whether DBus service should be running in the environment or not.
2019-09-18 15:44:52 +03:00
Panu Matilainen d5f201345f Fully shutdown DBUS on systemd_inhibit cleanup (RhBug:1714657)
dbus_shutdown() frees internal DBUS memory allocations that will otherwise
show up as memory leaks. This is of little consequence in practise
but shuts up valgrind...
2019-05-29 11:22:32 +02:00
Panu Matilainen ad16a04b6e Add plugin for logging audit events for package operations as per OSPP v4.2
When enabled, log audit events for package install, update and remove.
The log includes the operation, package nevra, signature check result,
whether signatures are being enforced enforced and overall operation
result code. Package install/update/remove are logged as such,
obsoletion is logged as install + remove (whereas the erasure element
on updates is silent). Enable compilation in CI.

Loosely based on initial RHEL 7-8 implementations by Pavlina Moravcova
Varekova and Florian Festi (RhBug:1555326, RhBug:1607612)
2019-04-09 11:04:02 +02:00
Panu Matilainen 8cbe8baf9c Log RPMLOG_ERR level messages on actual errors in selinux plugin, doh.
When there's an actual error, people will want to know without having
to rerun in verbose mode. Such as in RhBug:1641631 where configured
selinux policy differs from what is installed - the former message

    error: Plugin selinux: hook tsm_pre failed

...is not particularly helpful to anybody, whereas this actually provides
some clues now:

    error: selabel_open: (/etc/selinux/ponies/contexts/files/file_contexts) No such file or directory
    error: Plugin selinux: hook tsm_pre failed
2019-02-14 13:12:49 +02:00
Panu Matilainen 66e0c929b2 Fix testing for wrong variable in selinux plugin debug log
The strerror() case couldn't be reached as we were testing for the
wrong rc, spotted by covscan.
2018-10-10 12:00:38 +03:00
Stefan Berger 99887fec10 ima: Also apply signatures to config files
Even though config files may be close to what could be described as
'mutuable files', we now want to give the user control over the
installation of signatures on these files as well. We enable this
through a variable in the macro file. For this, we should be aware
that the signatures of these files may become incorrect or missing
once RPM post installation scripts or other programs have modified
these configuration files.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com
2018-02-12 10:21:40 +02:00
Panu Matilainen 014246b050 Test for lsetxattr() presence, don't try building IMA plugin without it
Came up in PR #260 review, we shouldn't assume the presence of this
Linux-specific API.
2017-10-27 12:49:29 +03:00