Commit graph

5796 commits

Author SHA1 Message Date
John Johansen
3a87b33af7 Merge Rewrite parse_profile_start() tests to use tests[] array
No functional changes, just more readable.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/709
Acked-by: John Johansen <john.johansen@canonical.com>
2021-02-14 21:53:13 +00:00
Christian Boltz
7e5c02e3d4
Rewrite parse_profile_start() tests to use tests[] array
No functional changes, just more readable.
2021-02-14 19:26:40 +01:00
Christian Boltz
33f2b3692b
Un-hardcode rule list in ProfileList delete_preamble_duplicates()
Note that before this change, boolean variable definitions were not
checked in delete_preamble_duplicates().
2021-02-14 18:26:24 +01:00
Christian Boltz
718fa5b9da
profile_list: add preamble_ruletypes
... instead of keeping the list in ProfileList init_file()
2021-02-14 18:26:18 +01:00
Rose Kunkel
ee5303c8a0 Fix nscd conflict with systemd-homed
My main user account is managed by systemd-homed. When I enable
AppArmor and have nscd running, I get inconsistent behavior with my
user account - sometimes I can't log in, sometimes I can log in but
not use sudo, etc.

This is the output of getent passwd:
  $ getent passwd
  root0:0::/root:/usr/bin/zsh
  bin1:1::/:/sbin/nologin
  daemon2:2::/:/sbin/nologin
  mail8:12::/var/spool/mail:/sbin/nologin
  ftp14:11::/srv/ftp:/sbin/nologin
  http33:33::/srv/http:/sbin/nologin
  nobody65534:65534:Nobody:/:/sbin/nologin
  dbus81:81:System Message Bus:/:/sbin/nologin
  [...]
  rose1000:1000:Rose Kunkel:/home/rose:/usr/bin/zsh

But getent passwd rose and getent passwd 1000 both return no output.
Stopping nscd.service fixes these problems. Checking the apparmor
logs, I noticed that nscd was denied access to
/etc/machine-id. Allowing access to that file seems to have fixed the
issue.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/707
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/145
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-02-11 22:53:07 -08:00
Seth Arnold
656f2103ed profiles: firefox Add support for widevine DRM
Ubuntu 18.04, Firefox 60.0.1+build2-0ubuntu0.18.04.1

Running firefix, then going to netflix.com and attempting to play a
movie. The widevinecdm plugin crashes, the following is found in
syslog:

Jun 15 19:13:22 xplt kernel: [301351.553043] audit: type=1400 audit(1529046802.585:246): apparmor="DENIED" operation="file_mmap" profile="/usr/lib/firefox/firefox{,*[^s][^h]}" name="/home/xav/.mozilla/firefox/wiavokxk.default-1510977878171/gmp-widevinecdm/1.4.8.1008/libwidevinecdm.so" pid=16118 comm="plugin-containe" requested_mask="m" denied_mask="m" fsuid=1000 ouid=1000
Jun 15 19:13:22 xplt kernel: [301351.553236] audit: type=1400 audit(1529046802.585:247): apparmor="DENIED" operation="ptrace" profile="/usr/lib/firefox/firefox{,*[^s][^h]}" pid=24714 comm="firefox" requested_mask="trace" denied_mask="trace" peer="/usr/lib/firefox/firefox{,*[^s][^h]}"
Jun 15 19:13:22 xplt kernel: [301351.553259] plugin-containe[16118]: segfault at 0 ip 00007fcdfdaa76af sp 00007ffc1ff03e28 error 6 in libxul.so[7fcdfb77a000+6111000]
Jun 15 19:13:22 xplt snmpd[2334]: error on subcontainer 'ia_addr' insert
...

Fixes: https://bugs.launchpad.net/ubuntu/+source/firefox/+bug/1777070
Reported-by: Xav Paice <xav.paice@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/684
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2021-02-11 19:38:57 -08:00
John Johansen
681c976550 parser: fixup "fix --jobs so jobs scaling is applied correctly"
65ba20b955 provides a fix for job
scaling but during a merge conflict part of the patch got dropped.
This is the missing portion of the patch that was approved as part
of MR703

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/703
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-02-10 19:24:43 -08:00
John Johansen
65ba20b955 parser: fix --jobs so job scaling is applied correctly
job scaling allows the parser to resample the number of cpus available
and increase the number of jobs that can be launched if cpu available
increases.

Unfortunately job scaling was being applied even when a fixed number
of jobs was specified. So
  --jobs=2

doesn't actually clamp the compile at 2 jobs.

Instead job scaling should only be applied when --jobs=auto or when
jobs are set to a multiple of the cpus.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/703
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2021-02-10 19:06:26 -08:00
John Johansen
136502acd9 parser: enable the parser to do some rough tuning based on memory and cpu
The parsers default settings can OOM smaller special use systems
when building or loading policy. Use basic memory info and cpus to
tune the parser for lower resource environments.

Currently this just sets the jobs parameters if the default values
haven't been modified by user config or parameters. But in the
future this could add cache control and compile parameters.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/702
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2021-02-10 18:51:39 -08:00
John Johansen
d50262cf2c parser: fix warning for rule not enforced
If af_unix rules are not supported but network rules are and
--warn=rule-downgraded is not set then the parser will incorrectly
output warning when the rule is actually being downgraded.

  Warning from profile test-profile (./prof): extended network unix socket rules not enforced

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/699
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/144
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2021-02-10 18:48:28 -08:00
John Johansen
a83f5d7a85 Merge Update profile usr.sbin.ntpd and abstractions/ssl_certs
* abstractions/ssl_certs
  * On Arch Linux certificates are extracted to `/etc/ca-certificates/` by the [update-ca-trust](https://github.com/archlinux/svntogit-packages/blob/packages/ca-certificates/trunk/update-ca-trust) script.
  * `/etc/libressl/` is used by Arch Linux's [libressl](https://archlinux.org/packages/community/x86_64/libressl/) package.
* usr.sbin.ntpd:
  * Add `abstractions/ssl_certs`. OpenNTPD requires access to CA certificates when using the HTTPS constraint feature.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/698
Acked-by: John Johansen <john.johansen@canonical.com>
2021-02-08 11:17:38 +00:00
John Johansen
1bd0d8f2ff Merge Add make coverage-regression
... to find regressions or improvements in the python code coverage.

`make coverage-regression` will error out if a file looses its 100% coverage, or if a file improved to 100% coverage.

Other coverage changes (for example 45% -> 47%) will be ignored.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/697
Acked-by: John Johansen <john.johansen@canonical.com>
2021-02-08 11:13:56 +00:00
Steve Beattie
15e897cad0 profiles: add new deny path for kwallet (used in KDE 5)
Acked-by: Steve Beattie <steve@nxnw.org>
Merge branch 'cboltz-kwallet-path' into 'master'
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/704
2021-02-08 05:55:31 +00:00
Steve Beattie
0ee0b9a9e8 parser: drop unused extern int debug_cache
The external reference definitions appear to have been overlooked
in `(f5c4927c) parser: convert remaining pwarn() to flag controlled warns`

Acked-by: Steve Beattie <steve@nxnw.org>
Merge branch 'cboltz-unused-debug-cache' into 'master'
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/705
2021-02-07 22:49:32 +00:00
Christian Boltz
7bd1f48799
drop unused extern int debug_cache
Reported by arekmx on IRC.
2021-02-07 16:02:20 +01:00
Christian Boltz
f1c53e125f
add new path for kwallet (used in KDE 5)
Reported on IRC by finalspacevoid
2021-02-07 14:19:46 +01:00
nl6720
c5ef2d2f9e
usr.sbin.ntpd: add abstractions/ssl_certs
openntpd requires access to CA certificates when using the HTTPS constraint feature.
2021-01-28 08:50:25 +02:00
nl6720
63bcad086f
abstractions/ssl_certs: add /etc/ca-certificates/ and /etc/libressl/
- On Arch Linux certificates are extracted to /etc/ca-certificates/ by the update-ca-trust script.
- /etc/libressl/ is used by Arch Linux's libressl package.
- Combine rules to reduce number of lines.
2021-01-28 08:50:25 +02:00
John Johansen
cb65ab92d0 Merge fix setting proc_attr_base
There is currently a case in which proc_attr_base won't get set when asprintf is able to generate the path, but the file doesn't exist, it will exit proc_attr_base_init_once() without proc_attr_base having been set as the fall-through if/else logic will get bypassed when asprintf is successful.

Without this fix, various commands like aa-status will not properly display which processes have an apparmor profile enforced because it proc_attr_base will always be NULL and therefore the proc attr path won't be able to be generated.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/701
Acked-by: John Johansen <john.johansen@canonical.com>
2021-01-22 20:46:01 +00:00
Aaron U'Ren
cc113f4820 fix setting proc_attr_base
There is currently a case in which proc_attr_base won't get set when
asprintf is able to generate the path, but the file doesn't exist, it
will exit proc_attr_base_init_once() without proc_attr_base having been
set as the fall-through if/else logic will get bypassed when asprintf is
successful.
2021-01-22 11:01:13 -06:00
Christian Boltz
e38be7b14f
enable utils coverage-regression checks in CI
This also needs installing python3-coverage in the test environment.
2021-01-11 13:51:54 +01:00
Christian Boltz
69c6ac3073
Add make coverage-regression
... to find regressions or improvements in the python code coverage.

`make coverage-regression` will error out if a file looses its 100%
coverage, or if a file improved to 100% coverage.

Other coverage changes (for example 45% -> 47%) will be ignored.
2021-01-10 20:53:44 +01:00
John Johansen
d86b7acd31 Merge Enable minitools tests
To get them running in the CI,

* call them with `--configdir ./`
* skip testing `aa-unconfined` if securityfs is not available

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/696
Acked-by: John Johansen <john.johansen@canonical.com>
2021-01-10 11:43:18 +00:00
John Johansen
7e02f254a3 Merge add re_match_include_parse() test with invalid rule name
... to increase test coverity of regex.py to 100%.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/695
Acked-by: John Johansen <john.johansen@canonical.com>
2021-01-10 11:38:57 +00:00
John Johansen
cc28ebaab4 Merge Add missing test for ProfileList add_alias()
... to ensure that it errors out if a wrong parameter type is given.

This also increases the test coverage of ProfileList to 100%.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/694
Acked-by: John Johansen <john.johansen@canonical.com>
2021-01-10 11:35:03 +00:00
John Johansen
ca344a3601 Merge Add and use BooleanRule and BooleanRuleset classes to handle boolean variable definitions
Add the BooleanRule and BooleanRuleset classes, add handling of boolean variable definitions in ProfileList and adjust `parse_profile_data()` to use BooleanRule. As usual, add tests for the added code.

See the individual commits for the details.

Note that this MR is also a bugfix - the previous code in (3.0 and master) saved boolean variables at a wrong place, and they were silently lost when writing the profile.
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/693
Acked-by: John Johansen <john.johansen@canonical.com>
2021-01-10 11:33:01 +00:00
John Johansen
d7ce5f0d2e Merge branch 'cboltz-comment-fix' into 'master'
Fix comment in split_name() tests

See merge request apparmor/apparmor!692
2021-01-10 11:24:32 +00:00
Christian Boltz
2e6bdc0b64
skip testing aa-unconfined if securityfs is not available 2020-12-25 21:24:42 +01:00
Christian Boltz
8d422ff66e
Test minitools with --configdir ./ 2020-12-25 21:07:18 +01:00
Christian Boltz
70bbc321db
Enable minitools tests in 'make check`
... by renaming them to test-*.py
2020-12-25 20:50:44 +01:00
Christian Boltz
c3d3203a60
add re_match_include_parse() test with invalid rule name
... to increase test coverity of regex.py to 100%.
2020-12-25 19:57:20 +01:00
Christian Boltz
32b11c0375
Add missing test for ProfileList add_alias()
... to ensure that it errors out if a wrong parameter type is given.

This also increases the test coverage of ProfileList to 100%.
2020-12-25 18:48:27 +01:00
Christian Boltz
f7e6f795c3
parse_profile_data(): Use BooleanRule
... and save rules at the right place (ProfileList) where they actually
get written when writing the profile.

This is also a bugfix - the previous code saved boolean variables at a
wrong place, and they were silently lost when writing the profile.

Extend cleanprof_test.{in,out} to ensure that this doesn't break again.

Also remove boolean_bad_[2-4] from the test-parser-simple-tests.py
exception_not_raised list because these test profiles now get correctly
detected as invalid.
2020-12-25 18:03:41 +01:00
Christian Boltz
a108934091
ProfileList: add handling of boolean variable definitions
This means adding the add_boolean() function and handling boolean
variables in get_clean() and get_raw().

Also add some tests to cover the added code.
2020-12-25 18:03:38 +01:00
Christian Boltz
3f11eebc17
Add BooleanRule and BooleanRuleset
These two classes are meant to handle the definition of boolean rules
like `$foo = true`.

Also extend RE_PROFILE_BOOLEAN to provide named matches.

As usual, add tests for the new classes.
2020-12-25 18:03:33 +01:00
Christian Boltz
2cbd0d94be
Fix comment in split_name() tests 2020-12-25 13:24:42 +01:00
John Johansen
20234d240e Merge apparmor.vim: add support for abi rules
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/690
Acked-by: John Johansen <john.johansen@canonical.com>
2020-12-11 22:52:39 +00:00
zt1024
c43bdf2e8b parser: don't abort profile compile if the kernel is missing caps/mask
3.0 added the ability to extract and use the kernels cap mask
to augment its internal capability list as a stop gap measure to
support new capabilities.

Unfortunately not all kernel export the cap/mask and this is causing
the policy compile to fail. If the kernel doesn't export a cp/mask
just use the internal list.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/140
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/691
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-12-11 04:01:40 -08:00
John Johansen
c2d105f81b Merge Honor global LDFLAGS when building python library
libraries/libapparmor/swig/python/Makefile.am: Add global LDFLAGS when building the python library. When only applying the custom PYTHON_LDFLAGS (which are in fact `python-config --ldflags`) distributions are unable to build the library with e.g. full RELRO.

Closes #129
PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/689
Acked-by: John Johansen <john.johansen@canonical.com>
2020-12-11 11:04:48 +00:00
Christian Boltz
c421fcd38a
apparmor.vim: add support for abi rules 2020-12-09 22:44:33 +01:00
David Runge
b646bbf21b
Honor global LDFLAGS when building python library
libraries/libapparmor/swig/python/Makefile.am:
Add global LDFLAGS when building the python library.
When only applying the custom PYTHON_LDFLAGS (which are in fact
`python-config --ldflags`) distributions are unable to build the library
with e.g. full RELRO.

Fixes #129
Related to #138
2020-12-08 10:28:53 +01:00
John Johansen
6e5dba4f49 libapparmor: Sync library version bump done for the 3.0.1 release
Keep library version bump in sync so that dev does not fall behind
3.0.x

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-12-02 04:16:28 -08:00
John Johansen
d26da6c42f libapparmor: fix failure in procattr accesses due to domain change
libapparmor on startup does detection of whether the new stacking
proc interfaces are available and then store a var for which interface
should be used. This avoids libapparmor needing to detect which interface
to use on each proc based api call.

Unfortunately if the domain is changed on the task via change_hat or
change_profile and the proc interface is used after the domain change
it is possible that access to the interface will be denied by policy.
This is not a problem in and of it self except policy may have been
created assuming the old interface.

Fix this by adding a fallback that tries the old interface if we
are using the new interface by default and the failure was due to
an EACCES denial (policy based).

Also refactor the code a bit so this retry is isolated to one function
instead of adding it in two places.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/131
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/681
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-12-01 20:33:53 -08:00
Steve Beattie
4a7b029246 Merge branch 'codespell-fixes' into 'master'
treewide: spelling fixes identified partially by codespell

See merge request apparmor/apparmor!687
2020-12-01 20:57:34 +00:00
Steve Beattie
8782f53593
parser: spelling fixes in aare_rules.c
Adjust function and variable names to spell separator correctly. Kept
as a distinct change in case someone wants to cherrypick other fixes.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/687
2020-12-01 12:47:26 -08:00
Steve Beattie
05547ac8f6
treewide: spelling fix in logprof.conf and profile comments
Kept separate from other fixes because conf file changes can cause
problems for packagers.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/687
2020-12-01 12:47:23 -08:00
Steve Beattie
8b708d3b45
treewide: spelling/typo fixes in code strings
Fix spelling errors in code strings. Some strings are translatable.
This fixes are potentially user visible.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/687
2020-12-01 12:47:18 -08:00
Steve Beattie
461d9c2294
treewide: spelling/typo fixes in comments and docs
With the exception of the documentation fixes, these should all be
invisible to users.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/687
2020-12-01 12:47:11 -08:00
John Johansen
7c88f02d6a aa-notify: don't crash if the logfile is not present due to rotation
If aa-notify races file rotation it may crash with a trace back to
the log file being removed before the new one is moved into place.

    Traceback (most recent call last):
       File "/usr/sbin/aa-notify", line 570, in <module>
         main()
       File "/usr/sbin/aa-notify", line 533, in main
          for message in notify_about_new_entries(logfile, args.wait):
       File "/usr/sbin/aa-notify", line 145, in notify_about_new_entries
         for event in follow_apparmor_events(logfile, wait):
       File "/usr/sbin/aa-notify", line 236, in follow_apparmor_events
         if os.stat(logfile).st_ino != log_inode:
    FileNotFoundError: [Errno 2] No such file or directory: '/var/log/audit/audit.log'

If we hit this situation sleep and then retry opening the logfile.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/130
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/688
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-11-30 05:19:28 -08:00
John Johansen
e0ef309542 Merge create_new_profile(): check if abstractions exist
... instead of blindly adding them to the profile, and later crash (and/or cause parser errors) because they don't exist.

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1178527
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/683
Acked-by: John Johansen <john.johansen@canonical.com>
2020-11-28 13:19:13 +00:00