Commit graph

6191 commits

Author SHA1 Message Date
Christian Boltz
90b312c55a Merge branch 'cboltz-samba-lmb2' into 'master'
abstractions/samba: allow ldb2 paths

See merge request apparmor/apparmor!821

Note: https://bugzilla.opensuse.org/show_bug.cgi?id=1192684 was made public in the meantime.

Acked-by: Jon Tourville <jon.tourville@canonical.com>
2022-01-18 12:53:52 +00:00
John Johansen
2b270216aa Merge abstractions/openssl: allow /etc/ssl/{engdef,engines}.d/
These directories were introduced in openssl in https://patchwork.ozlabs.org/project/openwrt/patch/20210429153530.10020-2-cotequeiroz@gmail.com/

I propose this patch for 3.0 and master. Optionally also for older branches, even if it's unlikely that systems using 2.13.x or older get a new-enough openssl to need this ;-)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/818
Acked-by: John Johansen <john.johansen@canonical.com>
2022-01-17 20:07:29 +00:00
Christian Boltz
901f2ea9cd
abstractions/samba: allow ldb2 paths
libldb packaging in openSUSE changes to use "ldb2" in the path, adjust
the abstraction accordingly.

Patch by Samuel Cabrero <scabrero@suse.de>
via https://build.opensuse.org/request/show/947009

References:
- https://bugzilla.opensuse.org/show_bug.cgi?id=1192684 (non-public)
- https://build.opensuse.org/request/show/946250 (ldb packaging change)
- https://build.opensuse.org/request/show/946251 (samba packaging change)
2022-01-17 20:03:13 +01:00
Christian Boltz
cf35cfe8c2 Merge branch 'cboltz-tunables-order' into 'master'
Define @{HOMEDIRS} before using it in @{HOME}

See merge request apparmor/apparmor!820

Acked-by: Georgia Garcia  <georgia.garcia@canonical.com>
2022-01-06 12:22:58 +00:00
Christian Boltz
867d32950e
Define @{HOMEDIRS} before using it in @{HOME}
The old order is not really wrong / a bug because the order doesn't
matter, but defining the variables it in the "right" order helps to
prevent confusion.

Fixes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1003158
2022-01-05 21:00:50 +01:00
Christian Boltz
fc4d1f76fa Merge branch 'bsc1192336' into 'master'
profiles/apparmor.d: Fix file_mmap violation for bsc#1192336.

See merge request apparmor/apparmor!819

Acked-by: Christian Boltz <apparmor@cboltz.de> for 3.0 and master
2021-12-20 18:06:40 +00:00
Noel Power
e19abd3bdf profiles/apparmor.d: Fix file_mmap violation for bsc#1192336.
- Fix 'apparmor="DENIED" operation="file_mmap" profile="samba-bgqd"
      name="/usr/lib64/samba/samba-bgqd" pid=2876 comm="samba-bgqd"
      requested_mask="m" denied_mask="m" fsuid=0 ouid=0'

entries appearing in SLE15-SP4

Signed-off-by: Noel Power <noel.power@suse.com>
2021-12-20 15:01:19 +00:00
Christian Boltz
e58dd798f0
abstractions/openssl: allow /etc/ssl/{engdef,engines}.d/
These directories were introduced in openssl in
https://patchwork.ozlabs.org/project/openwrt/patch/20210429153530.10020-2-cotequeiroz@gmail.com/
2021-12-19 22:36:05 +01:00
Christian Boltz
4cbd2684b8 Merge branch 'cboltz-aa-dict' into 'master'
Change 'aa' from hasher to dict

See merge request apparmor/apparmor!817

Acked-by: Jon Tourville <jon.tourville@canonical.com>
2021-12-14 18:21:35 +00:00
Christian Boltz
529c408d9e Merge branch 'cboltz-abstractions-python' into 'master'
abstractions/python: merge /usr/ and /usr/local/ rules, and add some new rules

See merge request apparmor/apparmor!814

Acked-by: Georgia Garcia <georgia.garcia@canonical.com>
2021-12-13 17:02:46 +00:00
Christian Boltz
32acb228f9
Change 'aa' from hasher to dict
If there's still some code left that tries to access an uninitialized
item in 'aa' (reading or writing), this will result in a very visible
crash instead of silently seeming to work.

Testing shows that we seem to correctly initialize each item in 'aa' (no
crashes), therefore let's hope the best ;-)
2021-12-11 20:24:41 +01:00
Christian Boltz
ebd4143ca2 Merge branch 'cboltz-parser-typo' into 'master'
Fix comment typo in parser/lib.c

See merge request apparmor/apparmor!815

Acked-by: Jon Tourville <jon.tourville@canonical.com>
2021-12-07 18:45:01 +00:00
Christian Boltz
854cbae52e
Fix comment typo in parser/lib.c 2021-12-05 18:16:53 +01:00
Christian Boltz
cac848e240
abstractions/python: add several permissions
- allow reading *.so.*
- allow directory listings in .../site-packages/
- allow reading various metadata files

These additions are based on denials seen on openSUSE Leap 15.3 with
python 3.9.
2021-12-04 20:54:52 +01:00
Christian Boltz
5491b75872
abstractions/python: merge /usr/ and /usr/local/ rules
This keeps all existing permissions, and adds a few that were out of
sync:
- /usr/lib*/python3.*/lib-dynload/*.so missed 3.1[0-9]
- /usr/lib/python3/... was missing, only /usr/local/python3/ was allowed
2021-12-04 20:09:52 +01:00
Georgia Garcia
21e5a721ab replace deprecated distutils with setuptools
Adds python3 setuptools as a build dependency for libapparmor

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/202
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/813
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2021-11-11 20:23:35 -03:00
Alistair Young
a6360d9db2 Add explicit WSL detection to is_container_with_internal_policy 2021-11-08 21:21:09 +00:00
John Johansen
ca276d2bfd Merge Add support for reading s390x and aarch64 wtmp file
Both aarch64 and s390x have a bigger wtmp record size (16 bytes more than x86_64, 400 bytes total).

The byte position of the timestamp is also different on each architecture. To make things even more interesting, s390x is big endian.

Note that this MR includes more things, like
* moving `get_last_login_timestamp()` to the new `apparmor/notify.py` file
* add unit tests for it
* add wtmp example files from various architectures, including a hand-edited one claiming to be from 1999
* fixing a bug in `get_last_login_timestamp()` that unpacked `type` from too many bytes - which accidently worked on x86_64
* detecting from which architecture the wtmp file comes (luckily the timestamps are located at different locations)

See the individual commits for details.

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1181155
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/809
Acked-by: John Johansen <john.johansen@canonical.com>
2021-11-08 20:50:34 +00:00
John Johansen
ee9e61aad2 Merge Add missing /proc permissions to avahi-daemon profile
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/203

MR:https://gitlab.com/apparmor/apparmor/-/merge_requests/811
Acked-by: John Johansen <john.johansen@canonical.com>
2021-10-30 09:16:37 +00:00
Christian Boltz
8c1243e43f
Add missing /proc permissions to avahi-daemon profile
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/203
2021-10-26 13:54:51 +02:00
Christian Boltz
1da0305c89
Add tests for sane_timestamp
Ensure that pre-2000 and post-2050 dates get rejected, and something in
between gets accepted.

This also extends coverage to 100% - before, the post-2050 branch was
not covered.
2021-10-24 17:24:43 +02:00
Christian Boltz
63f1a58bef
Add truncated and ancient wtmp example to tests
A too-small file can't contain something useful.

Also, a wtmp file with a timestamp from pre-2000 is beyond what you'd
expect on a 2021 system.
2021-10-24 17:24:43 +02:00
Christian Boltz
255716b90a
Add support for reading s390x and aarch64 wtmp file
Both aarch64 and s390x have a bigger wtmp record size (16 bytes more
than x86_64, 400 bytes total).

The byte position of the timestamp is also different on each
architecture. To make things even more interesting, s390x is big endian.

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1181155
2021-10-24 17:24:43 +02:00
Christian Boltz
f79b335b6c
fix reading 'type' from wtmp
'type' is a short (see "ut_type" in wtmp(5)), therefore only read two
bytes and unpack them as short. Afterwards read two padding bytes to
/dev/null.

This accidently worked on x86_64 because it's little endian, but will
fail on big endian architectures.
2021-10-24 17:24:43 +02:00
Christian Boltz
905b89a5c7
Add unittest for get_last_login_timestamp
... starting with a x86_64 wtmp example file
2021-10-24 14:23:53 +02:00
Christian Boltz
6dc9884c8e
Move get_last_login_timestamp() into apparmor.notify
This is a preparation to make adding tests easier.
2021-10-24 14:23:15 +02:00
John Johansen
b6551618d8 Merge Generate af_names.h similar to cap_names.h
This adds a base_af_names.h file similar to base_cap_names.h to support newer address families in policy when built against older headers.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/195
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/808
Acked-by: John Johansen <john.johansen@canonical.com>
2021-10-20 21:16:24 +00:00
Jon Tourville
90620cb64f Generate af_names.h similar to cap_names.h 2021-10-18 15:55:57 -05:00
Georgia Garcia
fb3283f37e add snap-browsers profile
Whenever the evince deb package tries to open a snap browser which was
selected as the default, we get the following denial:

audit[2110]: AVC apparmor="DENIED" operation="exec" profile="/usr/bin/evince" name="/usr/bin/snap" pid=2110 comm="env" requested_mask="x" denied_mask="x" fsuid=1000 ouid=0

As a short-term solution, we are adding a snap-browsers profile
which restricts what snaps opened by evince can do.
The long-term solution is currently not available, but could be
accomplished by using enhanced environment variable filtering/mediation
and delegation of open fds.

Bug: https://launchpad.net/bugs/1794064

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2021-10-18 09:44:52 -03:00
John Johansen
9d14d6ebfb Merge abstractions/samba: allow use of /run/lock/samba
Some distros use /run/lock/samba as the Samba lock directory, so allow
that in the samba abstraction in addition to /run/samba.

MR: https://gitlab.com/apparmor/apparmor!805
Acked-by: John Johansen <john.johansen@canonical.com>
2021-10-16 07:10:09 +00:00
John Johansen
8db7e70395 Merge Add profile for samba-bgqd
... and some rules in the smbd profile to execute it and send it a term
signal.

samba-bgqd is (quoting its manpage) "an internal helper program
performing asynchronous printing-related jobs."

samba-bgqd was added in Samba 4.15.

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1191532
MR: https://gitlab.com/apparmor!807
Acked-by: John Johansen <john.johansen@canonical.com>
2021-10-16 07:02:34 +00:00
Christian Boltz
85e53a5d04
Add profile for samba-bgqd
... and some rules in the smbd profile to execute it and send it a term
signal.

samba-bgqd is (quoting its manpage) "an internal helper program
performing asynchronous printing-related jobs."

samba-bgqd was added in Samba 4.15.

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1191532
2021-10-15 22:06:05 +02:00
Cameron Nemo
f5c9003d41 abstractions/samba: allow use of /run/lock/samba
Some distros use /run/lock/samba as the Samba lock directory, so allow
that in the samba abstraction in addition to /run/samba.
2021-10-05 22:51:18 -07:00
Steve Beattie
a24cda5ae1
binutils/aa-features-abi: fix a couple of minor issues
A small patch set to fix two issues with binutils/aa-features-abi:

1. The `aa-features-abi -f` short argument was not added to the
   `getopt_long()` set of short arguments, resulting in the command
   incorrectly failing when passed -f

2. Due to variable shadowing the file descriptor for the `--file`
   argument was not being autoclosed.

- binutils/aa-features-abi: make -f short arg actually be accepted
- binutils/aa-features-abi: fix failure to close fd due to shadowed
  var decl

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/804
2021-09-27 13:09:17 -07:00
Steve Beattie
ffc6529bef
binutils/aa-features-abi: fix failure to close fd due to shadowed var decl
The variable used to store the file descriptor for the --file ended up
being declared twice, resulting in the autoclose attribute attached to
the first declaration being removed by the shadowed second declaration.
Fix this by converting the second declaration to just be an assignment,
as was intended.

strace output before:

  [...]
  ) = 1925
  close(1)                                = 0
  exit_group(0)                           = ?
  +++ exited with 0 +++

strace output after removing shadow declaration:

  ) = 1925
  close(1)                                = 0
  close(3)                                = 0
  exit_group(0)                           = ?
  +++ exited with 0 +++

(File descriptor 3 is what is returned by the open() call on the
 --file argument.)

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/804
2021-09-27 13:07:11 -07:00
Steve Beattie
8137beb265
binutils/aa-features-abi: make -f short arg actually be accepted
The aa-features-abi -f short argument was not added to the
getopt_long() set of short arguments, resulting in the command
incorrectly failing like so:

  $ ./aa-features-abi -f /etc/apparmor.d/abi/3.0
  ./aa-features-abi: invalid option -- 'f'
  USAGE: ./aa-features-abi [OPTIONS] <SOURCE> [OUTPUT OPTIONS]
  [...]

The long --file option works as expected.

Fix this by adding f to the set of short arguments passed to
getopt_long().

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/804
2021-09-27 13:05:59 -07:00
Christian Boltz
b0bc0d5323 Merge branch 'fix-lexer' into 'master'
parser: Fix unknown state condition RLIMIT_MODEINCLDE

See merge request apparmor/apparmor!803

Acked-by: Christian Boltz for all branches
2021-09-24 11:26:21 +00:00
John Johansen
dc7755e544 parser: Fix unknown state condition RLIMIT_MODEINCLDE
The parser is broken on RLIMIT parsing when receiving unexpected input
because the shared state for this specifies RLIMIT_MODEINCLUDE which
is an unknown start condition resulting in the following warning

  parser_lex.l:745: undeclared start condition RLIMIT_MODEINCLUDE

and also means RLIMIT and INCLUDE are not properly handled

Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-09-24 00:48:27 -07:00
John Johansen
0700b47df8 Merge aa-unconfined: Improve fallback handling to attr/current
If /proc/*/attr/apparmor/current exists, only read that - instead of
falling back to /proc/*/attr/current if a process is for example
unconfined so that read_proc_current returns None.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/199
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/801
Acked-by: John Johansen <john.johansen@canonical.com>
2021-09-18 20:44:48 +00:00
Christian Boltz
f39d5c7c09
aa-unconfined: Improve fallback handling to attr/current
If /proc/*/attr/apparmor/current exists, only read that - instead of
falling back to /proc/*/attr/current if a process is for example
unconfined so that read_proc_current returns None.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/199
2021-09-18 19:02:56 +02:00
John Johansen
3b6257edea Merge dnsmasq: allow paths for podman dnsname plugin
The dnsname plugin in podman needs access to some files in
/run/containers/cni/dnsname/*/

This is also documented upstream:
https://github.com/containers/dnsname/blob/main/README_PODMAN.md
but nobody thought about telling us to just update the profile :-/

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1190271
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/800
Acked-by: John Johansen <john.johansen@canonical.com>
2021-09-16 21:33:02 +00:00
Christian Boltz
254ebacbd8
dnsmasq: allow paths for podman dnsname plugin
The dnsname plugin in podman needs access to some files in
/run/containers/cni/dnsname/*/

This is also documented upstream:
https://github.com/containers/dnsname/blob/main/README_PODMAN.md
but nobody thought about telling us to just update the profile :-/

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1190271
2021-09-16 23:10:38 +02:00
John Johansen
c37586cd11 Merge Avoid aa-notify crash on log events without operation=
Some STATUS log events trigger a crash in aa-notify because the log
line doesn't have operation=. Examples are:

    type=AVC msg=audit(1630913351.586:4): apparmor="STATUS" info="AppArmor Filesystem Enabled" pid=1 comm="swapper/0"

    type=AVC msg=audit(1630913352.610:6): apparmor="STATUS" info="AppArmor sha1 policy hashing enabled" pid=1 comm="swapper/0"

Fix this by not looking at log events without operation=

Also add one of the example events as libapparmor testcase.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/194
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/797
Acked-by: John Johansen <john.johansen@canonical.com>
2021-09-13 23:02:15 +00:00
John Johansen
92d5bec86e Merge libapparmor: fix debug build of log parsing
Fix log parsing for void Linux default log format.


Fixes: https://gitlab.com/apparmor/apparmor/-/issues/196
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/799
Georgia Garcia <georgia.garcia@canonical.com>
2021-09-13 22:58:28 +00:00
John Johansen
b32b898a9a libapparmor: fix log parsing for socklogd
The default log format for void linux is not handled by current log
parsing. The following example message results in an invalid record
error.

2021-09-11T20:57:41.91645 kern.notice: [  469.180605] audit: type=1400 audit(1631392703.952:3): apparmor="ALLOWED" operation="mkdir" profile="/usr/bin/kak" name="/run/user/1000/kakoune/" pid=2545 comm="kak" requested_mask="c" denied_mask="c" fsuid=1000 ouid=1000

This log message fails on parsing

  kern.notice:

which differs from the expect syslog format of
  host_name kernel:

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/196
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/799
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-09-13 15:04:06 -07:00
John Johansen
1192dae561 libapparmor: fix memory leaks in logparsing
bison reports the follow warnings on the parser

/home/jj/apparmor/apparmor-jjohansen.git/libraries/libapparmor/src/grammar.y:245.48-62: warning: unused value: $4 [-Wother]
 	| syslog_date TOK_ID TOK_SYSLOG_KERNEL TOK_DMESG_STAMP TOK_AUDIT TOK_COLON key_type audit_id audit_user_msg_partial_tail
                                                ^^^^^^^^^^^^^^^
/home/jj/apparmor/apparmor-jjohansen.git/libraries/libapparmor/src/grammar.y:247.48-62: warning: unused value: $4 [-Wother]
 	| syslog_date TOK_ID TOK_SYSLOG_KERNEL TOK_DMESG_STAMP TOK_AUDIT TOK_COLON key_type audit_id audit_user_msg_tail
                                                ^^^^^^^^^^^^^^^
which it turns out are memory leaks.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/799
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-09-12 23:11:39 -07:00
John Johansen
4fe5387b69 libapparmor: fix debug build of log parsing
When building with YYDEBUG=1 the following failure occurs

grammar.y:49:46: error: unknown type name ‘no_debug_unused_’; did you mean ‘debug_unused_’?
 void aalogparse_error(unused_ void *scanner, no_debug_unused_ char const *s)
                                              ^~~~~~~~~~~~~~~~
                                              debug_unused_
g

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/799
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-09-12 23:11:31 -07:00
Christian Boltz
88595722f6
Avoid aa-notify crash on log events without operation=
Some STATUS log events trigger a crash in aa-notify because the log
line doesn't have operation=. Examples are:

    type=AVC msg=audit(1630913351.586:4): apparmor="STATUS" info="AppArmor Filesystem Enabled" pid=1 comm="swapper/0"

    type=AVC msg=audit(1630913352.610:6): apparmor="STATUS" info="AppArmor sha1 policy hashing enabled" pid=1 comm="swapper/0"

Fix this by not looking at log events without operation=

Also add one of the example events as libapparmor testcase.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/194
2021-09-06 16:54:33 +02:00
John Johansen
d11f2d5923 Merge Include local customization
The current setup for the profile sanitized_helper does not include a local
profile for adjustments.

Fixes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=990499
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/796
Acked-by: John Johansen <john.johansen@canonical.com>
2021-09-03 11:59:12 +00:00
Shai4she
de5966671f Include local customization, cf. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=990499 2021-09-03 08:27:02 +00:00