2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-31 14:25:52 +00:00

Compare commits

...

1922 Commits

Author SHA1 Message Date
John Johansen
f9e9954f12 Prepare for AppArmor 3.1.6 release
- update version file

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-06-21 14:13:41 -07:00
John Johansen
3ec3fc47a1 Merge fix mount regression in 3.1.5
Mount has regressed in two ways. That are affecting snapd confinement, since landing the mount fixes for CVE-2016-1585 in 3.1.4 and the fix for the mount change type regression in 3.1.5

Bug Reports:

https://bugs.launchpad.net/apparmor/+bug/2023814

https://bugzilla.opensuse.org/show_bug.cgi?id=1211989

Issue 1:
Denial of Mount
```
[ 808.531909] audit: type=1400 audit(1686759578.010:158): apparmor="DENIED" operation="mount" class="mount" info="failed mntpnt match" error=-13 profile="snap-update-ns.test-snapd-lp-1803535" name="/tmp/.snap/etc/" pid=14529 comm="5" srcname="/etc/" flags="rw, rbind"
```

when the profile contains a rule that should match
```
mount options=(rw, rbind) "/etc/" -> "/tmp/.snap/etc/",
```

Issue 2: change_type failure.
Denial of Mount in log
```
type=AVC msg=audit(1686977968.399:763): apparmor="DENIED" operation="mount" class="mount" info="failed flags match" error=-13 profile="snap-update-ns.authy" name="/var/cache/fontconfig/" pid=26702 comm="5" srcname="/var/lib/snapd/hostfs/var/cache/fontconfig/" flags="rw, bind"
...
```

snapd error
```
- Run configure hook of "chromium" snap if present (run hook "configure": 
-----
update.go:85: cannot change mount namespace according to change mount (/var/lib/snapd/hostfs/usr/share/doc /usr/share/doc none bind,ro 0 0): permission denied
update.go:85: cannot change mount namespace according to change mount (/var/lib/snapd/hostfs/usr/share/fonts /usr/share/fonts none bind,ro 0 0): permission denied
update.go:85: cannot change mount namespace according to change mount (/var/snap/cups/common/run /var/cups none bind,rw 0 0): permission denied
cannot update snap namespace: cannot create writable mimic over "/snap/chromium/2475": permission denied
snap-update-ns failed with code 1
```

and NO mount rules in the profiles.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1054
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-06-21 02:54:53 +00:00
John Johansen
86d193e183 parser: fix rule flag generation change_mount type rules
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1048
made it so rules like

  mount slave /snap/bin/** -> /**,

  mount /snap/bin/** -> /**,

would get passed into change_mount_type rule generation when they
shouldn't have been. This would result in two different errors.

1. If kernel mount flags were present on the rule. The error would
   be caught causing an error to be returned, causing profile compilation
   to fail.

2. If the rule did not contain explicit flags then rule would generate
   change_mount_type permissions based on souly the mount point. And
   the implied set of flags. However this is incorrect as it should
   not generate change_mount permissions for this type of rule. Not
   only does it ignore the source/device type condition but it
   generates permissions that were never intended.

   When used in combination with a deny prefix this overly broad
   rule can result in almost all mount rules being denied, as the
   denial takes priority over the allow mount rules.

Fixes: https://bugs.launchpad.net/apparmor/+bug/2023814
Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1211989
Fixes: 9d3f8c6cc ("parser: fix parsing of source as mount point for propagation type flags")
Fixes: MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1048

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-06-20 09:02:06 -07:00
John Johansen
ca7f79174e parser: Deprecation warning should not have been backported
Outputing the deprecation warning is a change in behavior that is not
a bug fix.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-06-17 14:00:41 -07:00
John Johansen
515d93ab1a Merge abstractions/base: Add transparent hugepage support
Found in testing a slimmed-down `usr.sbin.sshd` profile:
```
Jun  8 21:09:38 testvm kernel: [   54.847014] audit: type=1400 audit(1686272978.009:68): apparmor="DENIED" operation="open" profile="/usr/sbin/sshd" name="/sys/kernel/mm/transparent_hugepage/hpage_pmd_size" pid=1035 comm="sshd" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
```
Not sure what glibc/system call uses this, but it seems pretty broadly applicable, and read access is presumably harmless. [THP reference](https://www.kernel.org/doc/html/latest/admin-guide/mm/transhuge.html)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1050
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit ad3750058d)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-06-09 01:48:05 -07:00
John Johansen
ad6833bb34 Merge abstractions/authentication: Add GSSAPI mechanism modules config
Found in testing a slimmed-down `usr.sbin.sshd` profile:
```
Jun  8 21:09:37 testvm kernel: [   54.770501] audit: type=1400 audit(1686272977.933:67): apparmor="DENIED" operation="open" profile="/usr/sbin/sshd" name="/etc/gss/mech.d/" pid=1036 comm="sshd" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
```
([Reference](https://web.mit.edu/kerberos/krb5-1.21/doc/admin/host_config.html#gssapi-mechanism-modules) for  GSSAPI mechanism modules)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1049
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit b41fcdce16)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-06-09 01:47:40 -07:00
John Johansen
3c5d40e84a Prepare for AppArmor 3.1.5 release
- update version file

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-06-08 23:48:36 -07:00
John Johansen
eac7202808 Merge profiles: allow reading of /etc/ld-musl-*.path
/etc/ld-musl-*.path is required to perform dynamic linking on musl libc.
The wildcard is to match all CPU architectures, like x86_64.

type=AVC msg=audit(1686087677.497:67): apparmor="DENIED" operation="open" class="file" profile="syslog-ng" name="/etc/ld-musl-x86_64.path" pid=25866 comm="syslog-ng" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

Closes #333

Signed-off-by: Nikita Romaniuk <kelvium@yahoo.com>

Closes #333
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1047
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit 6e0d776f65)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-06-08 19:00:38 -07:00
John Johansen
3b61d42f79 Merge parser: fix parsing of source as mount point for propagation type flags
Before 300889c3a, mount rules would compile policy when using source
as mount point for rules that contain propagation type flags, such as
unbindable, runbindable, private, rprivate, slave, rslave, shared, and
rshared. Even though it compiled, the rule generated would not work as
expected.

This commit fixes both issues. It allows the usage of source as mount
point for the specified flags, albeit with a deprecation warning, and
it correctly generates the mount rule.

The policy fails to load when both source and mount point are
specified, keeping the original behavior (reference
parser/tst/simple_tests/mount/bad_opt_10.sd for example).

Fixes: https://bugs.launchpad.net/bugs/1648245
Fixes: https://bugs.launchpad.net/bugs/2023025

It should be backported to versions 2.13, 3.0, 3.1.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1048
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit 1e0d7bcbb7)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-06-08 18:54:04 -07:00
John Johansen
f34d60b1e8 Merge [3.0, 3.1] Fix invalid aa-status --json
The previous patch changed the final  }}  to  }  - which is correct in
master, but breaks the code in the 3.x branches.

I propose this patch for 3.0 and 3.1.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1046
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-06-06 21:42:28 +00:00
Christian Boltz
29b21b09d4 Fix invalid aa-status --json
The previous patch changed the final  }}  to  }  - which is correct in
master, but breaks the code in the 3.x branches.
2023-06-06 23:29:14 +02:00
Georgia Garcia
96395d9b82 Merge profiles: add lock file permission to snap browsers
When opening snap browsers with evince using the snap_browsers
abstraction, we get the following AppArmor denials which prevent the
browsers from opening

audit: type=1400 audit(1685996894.479:225): apparmor="DENIED" operation="open" class="file" profile="/usr/bin/evince//snap_browsers" name="/var/lib/snapd/inhibit/firefox.lock" pid=13282 comm="snap" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

audit: type=1400 audit(1685997517.142:259): apparmor="DENIED" operation="file_lock" class="file" profile="/usr/bin/evince//snap_browsers" name="/var/lib/snapd/inhibit/firefox.lock" pid=14200 comm="snap" requested_mask="k" denied_mask="k" fsuid=1000 ouid=0

This MR should be cherry-picked into 2.13, 3.0, 3.1

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1045
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>


(cherry picked from commit a00ece5b6e)

daec4bc8 profiles: add lock file permission to snap browsers
2023-06-06 11:15:48 +00:00
John Johansen
9980ae76d8 Merge Fix use-after-free of 'name' in parser_regex.c
'name' gets used in the error message. Make sure it only gets freed
afterwards.

This bug was introduced in be0d2fa947 /
https://gitlab.com/apparmor/apparmor/-/merge_requests/727

Fixes coverity CID 254465:  Memory - illegal accesses  (USE_AFTER_FREE)

I propose this fix for 3.0..master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1040
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit 8d6358fa6d)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-29 15:38:58 -07:00
John Johansen
dd136f4dd9 Merge Fix order of if conditions to avoid unreachable code
If `else if (preprocess_only)` is true, the more strict condition
`else if (!include_file && preprocess_only)` won't be reached if it gets
checked after the shorter condition.

Exchange the two sections so that both code paths can be reached.

Fixes coverity CID 312499:  Control flow issues  (DEADCODE)

This was probably introduced in 7dcf013bca / https://gitlab.com/apparmor/apparmor/-/merge_requests/743 which means we'll need to backport this fix to 3.0 and 3.1.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1039
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit dc8cbebdef)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-29 15:30:26 -07:00
John Johansen
e5a3c03357 Prepare for AppArmor 3.1.4 release
- update version file
- update library version

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-23 17:10:26 -07:00
John Johansen
6831a8f440 Merge extend test profiles for mount
- in bad_?.sd, explain why the profile is bad (conflicting options)
- add a good profile with two space-separated options

This is a follow-up for https://gitlab.com/apparmor/apparmor/-/merge_requests/1029

If we backport !1029, we should also backport these test changes.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1035
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit d700f87d3e)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-23 14:41:58 -07:00
John Johansen
ea5b52d3b2 Merge aa-status: Fix malformed json output
In some cases (if profiles in complain _and_ enforce mode are loaded), the `i` loop runs more
than once, which also means `j == 0` is true in the middle of the json.
This causes invalid json.

This patch fixes this.

This is a regression related to 22aa9b6161
/ https://gitlab.com/apparmor/apparmor/-/merge_requests/964 /
https://gitlab.com/apparmor/apparmor/-/issues/295
which fixed another case of invalid json if a process was unconfined
while having a profile defined.

Note: I also tested this patch for the "unconfined, but has a profile
defined" case to ensure it doesn't break what
22aa9b6161 fixed.

This fix is needed in all branches that also got !964 (which means 3.1 and 3.0).

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1036
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/295
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
backported-from: 88d2bf45a Merge aa-status: Fix malformed json output
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-19 16:31:41 -07:00
Christian Boltz
3cdeb140a1 Merge nscd: add permission to allow supporting unscd
`unscd` is a drop-in replacement for `nscd` that uses the same binary location (`/usr/sbin/nscd`) and config file (`/etc/nscd.conf`). The `usr.sbin.nscd` profile only needs one additional permission to support it.

```
May 9 18:07:42 darkstar kernel: [ 2706.138823] audit: type=1400
audit(1683670062.580:839): apparmor="DENIED" operation="sendmsg"
profile="nscd" name="/run/systemd/notify" pid=4343 comm="nscd"
requested_mask="w" denied_mask="w" fsuid=125 ouid=0
```

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1031
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit dec3815f07)

bd0d401b nscd: add permission to allow supporting unscd
2023-05-10 10:54:34 +00:00
Jon Tourville
8c49449e46 Merge Merge Issue 312: added missing kernel mount options
This patch adds the following mount options: 'nostrictatime',
'lazytime', and 'nolazytime'.

The MS_STRICTATIME mount flag already existed, and 'nostrictatime' was
listed along with 'strictatime' in the comments of parser/mount.cc, so
this patch adds a mapping for 'nostrictatime' to clear MS_STRICTATIME.

Additionally, the Linux kernel includes the 'lazytime' option with
MS_LAZYTIME mapping to (1<<25), so this patch adds MS_LAZYTIME to
parser/mount.h and the corresponding mappings in parser/mount.cc for
'lazytime' and 'nolazytime'.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1005
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit c37be61d17)
Signed-off-by: Jon Tourville <jon.tourville@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1026
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Jon Tourville <jon.tourville@canonical.com>
2023-05-04 12:00:20 +00:00
Christian Boltz
a3685436eb Merge [3.1] CI: check extra profiles for local/ includes
Picked from MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1012
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>


(cherry picked from commit 46c8dbe886)

3ddb1677 CI: check extra profiles for local/ includes

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1027
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2023-05-04 10:33:57 +00:00
John Johansen
2610fe4e80 Merge CI: check extra profiles for local/ includes
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1012
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>


(cherry picked from commit 46c8dbe886)

3ddb1677 CI: check extra profiles for local/ includes
2023-05-03 18:15:19 +00:00
John Johansen
c7f761b710 Merge Issue 312: added missing kernel mount options
This patch adds the following mount options: 'nostrictatime',
'lazytime', and 'nolazytime'.

The MS_STRICTATIME mount flag already existed, and 'nostrictatime' was
listed along with 'strictatime' in the comments of parser/mount.cc, so
this patch adds a mapping for 'nostrictatime' to clear MS_STRICTATIME.

Additionally, the Linux kernel includes the 'lazytime' option with
MS_LAZYTIME mapping to (1<<25), so this patch adds MS_LAZYTIME to
parser/mount.h and the corresponding mappings in parser/mount.cc for
'lazytime' and 'nolazytime'.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1005
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit c37be61d17)
Signed-off-by: Jon Tourville <jon.tourville@canonical.com>
2023-05-03 17:00:15 +02:00
Jon Tourville
f00f296201 Merge Merge expand mount tests
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1006
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit e6e5e7981f)
Signed-off-by: Jon Tourville <jon.tourville@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1022
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Jon Tourville <jon.tourville@canonical.com>
2023-05-03 14:54:32 +00:00
Jon Tourville
83772acf00 Check for newer mount options in regression test
The mount options MS_LAZYTIME and MS_NOSYMFOLLOW were added in
kernels 4.0 and 5.10, respectively. Update the mount test script
and helper to skip testing those options if they are not available.

Signed-off-by: Jon Tourville <jon.tourville@canonical.com>
(cherry picked from commit 9a760def8d)
Signed-off-by: Jon Tourville <jon.tourville@canonical.com>
2023-05-03 13:48:02 +02:00
John Johansen
1d35eedef8 Merge Support rule qualifiers in regression tests
This allows regression tests to generate profiles that use rule qualifiers,
such as allow, deny, and audit. Qualifiers can be specified for a rule by
prepending 'qual=', followed by a comma-separated list of rule qualifiers,
then a ':', then the rule itself.

Signed-off-by: Jon Tourville <jon.tourville@canonical.com>
(cherry picked from commit f6bfd141bd)
Signed-off-by: Jon Tourville <jon.tourville@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1018
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2023-05-02 12:00:13 +00:00
John Johansen
a597a612a7 Merge expand mount tests
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1006
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit e6e5e7981f)
Signed-off-by: Jon Tourville <jon.tourville@canonical.com>
2023-05-02 11:01:12 +02:00
Jon Tourville
64463c8686 Support rule qualifiers in regression tests
This allows regression tests to generate profiles that use rule qualifiers,
such as allow, deny, and audit. Qualifiers can be specified for a rule by
prepending 'qual=', followed by a comma-separated list of rule qualifiers,
then a ':', then the rule itself.

Signed-off-by: Jon Tourville <jon.tourville@canonical.com>
(cherry picked from commit f6bfd141bd)
Signed-off-by: Jon Tourville <jon.tourville@canonical.com>
2023-05-02 10:12:23 +02:00
John Johansen
7bd1c4d8ef Merge fix af_unix tests for v8 networking.
The unix network tests are not being run on a v8 network capable kernel. Under v8 there needs to be some adjustments to the tests because unix rules get downgraded to the socket rule ```network unix,``` which does not have the same set of conditionals or fine grained permissions, meaning some tests that would fail under af_unix (like missing permission tests) will pass under v8 network rules.

Signed-off-by: John Johansen <john.johansen@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/893
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit 59b4109a8b)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-01 05:17:20 -07:00
John Johansen
c7bd872071 Merge abstractions/freedesktop.org: allow custom cursors
... by allowing to read all files below ~/.icons instead of only the
directory listing.

I propose this patch for all branches.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1008
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>


(cherry picked from commit fa86a7f1d9)

954b11fc abstractions/freedesktop.org: allow custom cursors
2023-04-25 19:44:27 +00:00
John Johansen
3d33fd440b Merge Fix error when choosing named exec with plane profile names
When a user choooses to execute to a named profile (not: named child),
make sure to get the profile filename in the correct way to avoid a crash.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/314

I propose this patch for 2.13..master. (Note: I verified that the bug already exists in 2.13, and that this patch fixes it.)

Closes #314
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1013
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>


(cherry picked from commit 30dd1cec42)

103be8e1 Fix error when choosing named exec with plane profile names
2023-04-25 19:42:26 +00:00
Christian Boltz
e37cbd43c9 Merge Sync apparmor-3.1 profiles with master
This MR is similar to !1009, only it targets the `apparmor-3.1` branch.

There are also three commits here, but the first one only updates comments, and the last one is much smaller. After merging, `git diff apparmor-3.1 master -- profiles` will likewise produce no output.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1010
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2023-04-19 20:21:58 +00:00
Daniel Richard G
f91f33f2c6 profiles: sync with master
(Don't remove rules from the usr.sbin.{dnsmasq,nmbd,winbindd} profiles,
however, as these have been transferred to abstractions which might not
be correctly updated on a user system)
2023-04-18 20:24:32 -04:00
Daniel Richard G
51751aa687 profiles/Makefile: sync with master 2023-04-12 20:48:57 -04:00
Daniel Richard G
89f1a84dfe profiles: partial sync with master
This commit only updates comments.
2023-04-12 20:48:57 -04:00
Christian Boltz
d984b3edb6 Merge abstractions/base: allow reading tzdata ICU zoneinfo DB
This is used by various applications including libreoffice etc so it may as well
be added to the base abstraction along with the existing zoneinfo DB access.

AVC apparmor="DENIED" operation="open" class="file" profile="snap.libreoffice.calc" name="/usr/share/zoneinfo-icu/44/le/zoneinfo64.res" pid=44742 comm="soffice.bin" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

Signed-off-by: Alex Murray <alex.murray@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1007
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit 8d9985ac0b)

c691b11d abstractions/base: allow reading tzdata ICU zoneinfo DB
2023-04-11 19:21:29 +00:00
John Johansen
2a7ddbc773 Merge Ignore 'x' in mixed file mode log events
Probably thanks to O_MAYEXEC, denials for file access can now contain a
mix of x (exec) and other file permissions.

The actual exec should appear in a separate "exec" log event, therefore
ignore 'x' in file events for now if it's mixed with other permissions.

Note that file events ("open", "link" etc.) that contain denied_mask="x"
without another permission will still cause an error. (So far, this
hasn't been seen in the wild.)

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/303

Also add the log line from the bugreport and the (for now) expected
result as test_multi testcase.

I propose this patch for all branches.

Closes #303
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1001
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit cf6539b217)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-03-31 20:14:17 -07:00
John Johansen
54bb7dccf0 Merge syslogd: allow reading /dev/kmsg
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/307

I propose this patch for master and 3.x (the profile in 2.13 is very different which makes automatic merging impossible)

Closes #307
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1003
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit 6f65faa164)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-03-31 20:08:12 -07:00
John Johansen
aff29ef0ee Merge Fix mount rules encoding
This is a partial fix for CVE-2016-1585, it address the frontend rule encoding problems particularly
- Permissions being given that shouldn't happen
- Multiple option conditionals in a single rule resulting in wider permission instead of multiple rules
- optional flags not being handled correctly
- multiple backend rules being created out of one frontend rule when they shouldn't be

it does not address the backend issue of short cut permissions not being correctly updated when deny rules carve out permissions on an allow rule that has a short cut permission in the encoding.

Thanks to the additional work by Alexander Mikhalitsyn for beating this MR into shape so we can land it

Alexander Changelog:
- rebased to an actual tree
- addressed review comments from @wbumiller and @setharnold
- fixed compiler warnings about class_mount_hdr is uninitialized
- infinite loop fix
- MS_MAKE_CMDS bitmask value fixed
- fixed condition in `gen_flag_rules` to cover cases like `mount options in (bind) /d -> /4,` when flags are empty and only opt_flags are present
- marked some tests as a FAIL case behavior was changed after `parser: add conflicting flags check for options= conditionals` commit

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/333
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit c1a1a3a923)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-03-29 10:41:47 -07:00
John Johansen
26e85c17bd Merge parser: fix definitely and possibly lost memory leaks
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/992
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit 05595eccda)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-03-28 20:21:09 -07:00
Georgia Garcia
bdcd76a8ea Merge tests: force dbus-daemon to generate an abstract socket
dbus 1.14.4 changed the behavior of unix:tmpdir to be equivalent to
unix:dir, which cases dbus-daemon to generate path based sockets,
instead of the previous abstract sockets. [1]
In this change we force dbus-daemon to generate an abstract socket by
specifying the abstract socket address in the command.

[1] https://gitlab.freedesktop.org/dbus/dbus/-/blob/dbus-1.14/NEWS#L64

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/999
Approved-by: John Johansen <john@jjmx.net>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>


(cherry picked from commit 904b733948)

53d4e341 tests: force dbus-daemon to generate an abstract socket
2023-03-28 14:23:13 +00:00
Christian Boltz
e69cb50479 Merge [3.x] several fixes for samba-related profiles and the kerberos abstraction
See the individual commits for details.

Signed-off-by: Noel Power <noel.power@suse.com>

This is a backport of https://gitlab.com/apparmor/apparmor/-/merge_requests/989

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/991
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2023-03-14 20:22:28 +00:00
Noel Power
5a25bc6240 prevent rename_src requesting 'r' access DENIES messages
nmbd, windbind & smbd all trigger

apparmor="DENIED" operation="rename_src" profile="/usr/sbin/nmbd" name="/var/log/samba/log.nmbd

type messages.

Signed-off-by: Noel Power <noel.power@suse.com>
(cherry picked from commit e5654f1f81)
2023-03-14 21:08:39 +01:00
Noel Power
06e15a7789 add kerberosclient to included abstractions for winbindd
prevent messages like

apparmor="DENIED" operation="file_mmap" profile="/usr/sbin/winbindd" name="/usr/lib64/krb5/plugins/authdata/sssd_pac_plugin.so" pid=2798 comm="winbindd" requested_mask="m" denied_mask="m" fsuid=52311 ouid=0

Signed-off-by: Noel Power <noel.power@suse.com>
(cherry picked from commit 0593a035f5)
2023-03-14 21:08:33 +01:00
Noel Power
d0e086e93a Update kerberosclient abstraction for access to authdata directory
For example winbindd when configured on a samba system using
sssd can trigger

apparmor="DENIED" operation="file_mmap" profile="/usr/sbin/winbindd" name="/usr/lib64/krb5/plugins/authdata /sssd_pac_plugin.so" pid=2798 comm="winbindd" requested_mask="m" denied_mask="m" fsuid=52311 ouid=0

Signed-off-by: Noel Power <noel.power@suse.com>
(cherry picked from commit 6e94794c68)
2023-03-14 21:08:28 +01:00
Noel Power
0e6b48cc78 adjust winbindd profile to cater for sssd kdcinfo access
winbindd (with nsswitch sssd configuration) is now getting

type=AVC msg=audit(1677832823.657:119): apparmor="DENIED" operation="open" profile="/usr/sbin/winbindd" name="/var/lib/sss/pubconf/kdcinfo.TESTDOMAIN1.MY.COM" pid=3026 comm="winbindd" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

Signed-off-by: Noel Power <noel.power@suse.com>
(cherry picked from commit b4f5414882)
2023-03-14 21:08:10 +01:00
John Johansen
c8eefe440c Prepare for AppArmor 3.1.3 release
- update version file
- update library version

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-02-27 17:24:32 -08:00
John Johansen
df3b9601de Merge [3.x] Update samba profiles
samba-dcerpcd requires access to `/var/cache/samba/names.tdb`.

    audit: type=1400 audit(1676835286.187:62): apparmor="DENIED" operation="open" profile="samba-dcerpcd" name="/var/cache/samba/names.tdb" pid=6948 comm="samba-dcerpcd" requested_mask="wrc" denied_mask="wrc" fsuid=0 ouid=0

See also https://bbs.archlinux.org/viewtopic.php?id=281411

Since `usr.sbin.winbindd` already has a rule for it, and `usr.sbin.nmbd`
has similar ones, simply add `/var/cache/samba/*.tdb rwk` to
`abstractions/samba`.

(cherry picked from commit 763c4ecd23,
with cleanup of now-superfluous rules in usr.sbin.nmbd and
usr.sbin.winbindd dropped)

Also allow access to samba pid files directly in /run/

This is a backport of !987, with the cleanup of now-superfluous rules removed.

I propose this patch for 3.x (also for 2.13 if it cleanly applies)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/988
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-02-27 19:52:17 +00:00
nl6720
a9fa20a456 profiles/apparmor.d/samba*: allow access to pid files directly in /run/
On Arch Linux, `samba-dcerpcd.pid` is in `/run/`, not `/run/samba/`.

   apparmor="DENIED" operation="mknod" profile="samba-dcerpcd" name="/run/samba-dcerpcd.pid" pid=80920 comm="samba-dcerpcd" requested_mask="c" denied_mask="c" fsuid=0 ouid=0

The same is true for `nmbd.pid`, `smbd.pid` and probably others too.

(cherry picked from commit 6f0d2ef7fe)
2023-02-27 20:37:38 +01:00
nl6720
089064439d profiles/apparmor.d/abstractions/samba: allow modifying /var/cache/samba/*.tdb
samba-dcerpcd requires access to `/var/cache/samba/names.tdb`.

    audit: type=1400 audit(1676835286.187:62): apparmor="DENIED" operation="open" profile="samba-dcerpcd" name="/var/cache/samba/names.tdb" pid=6948 comm="samba-dcerpcd" requested_mask="wrc" denied_mask="wrc" fsuid=0 ouid=0

See also https://bbs.archlinux.org/viewtopic.php?id=281411

Since `usr.sbin.winbindd` already has a rule for it, and `usr.sbin.nmbd`
has similar ones, simply add `/var/cache/samba/*.tdb rwk` to
`abstractions/samba`.

(cherry picked from commit 763c4ecd23,
with cleanup of now-superfluous rules in usr.sbin.nmbd and
usr.sbin.winbindd dropped)
2023-02-27 20:36:30 +01:00
John Johansen
1759c1bd24 Merge Add abstractions/groff with lots of groff/nroff helpers
contributed by Werner Fink via
https://bugzilla.opensuse.org/show_bug.cgi?id=1065388 comment 25

Note that - compared to the file in bugzilla - I removed the `rix` rules
for /usr/bin/groff and /usr/bin/nroff so that people can choose to ix,
Px or Cx groff/nroff as they wish, and then include the abstraction
inside the target profile to allow executing all the helpers.

I also added `include if exists <abstractions/groff.d>`

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/973
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit 238eb8150b)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-02-26 13:57:12 -08:00
John Johansen
68de30cf76 Merge abstractions/openssl: allow reading /etc/ssl/openssl-*.cnf
openSUSE Tumbleweed uses /etc/ssl/openssl-1_1.cnf to make the migration
to openssl 3 possible.

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1207911

I propose this patch for at least 3.1 and master, ideally for all branches (as long as it can easily be merged)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/984
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit f223ed063e)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-02-25 17:06:33 -08:00
Christian Boltz
925ccfe482 Merge Backport Recent Python Bugfixes to 3.1
This MR backports bugfixes from !985, bringing them from `master` to `apparmor-3.1`.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/986
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2023-02-24 20:21:00 +00:00
Georgia Garcia
dc4b38acf0 libapparmor: add support for class in logparsing
We want to use the class field to identify operations such as
posix_mqueue

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
(cherry picked from commit 5cc7a26e78)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-02-24 04:09:12 -08:00
Georgia Garcia
9f25b5f6ff libapparmor: add support for requested and denied on logparsing
In order to decrease the number of characters in the audit logs
from the kernel, we will drop the "_mask" from the fields
"requested_mask" and "denied_mask".

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
(cherry picked from commit a05c9483f3)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-02-24 04:08:57 -08:00
Mark Grassi
6e2eabd424 Fix AttributeError caused by Python 3 migration
(cherry picked from commit cc7f8fb4d6)
2023-02-23 22:39:28 -05:00
Mark Grassi
c8ce78e00c Replace mutable default arguments in utils
(cherry picked from commit 2742d1f1ee)
2023-02-23 22:39:25 -05:00
Mark Grassi
7526ba4b0a Add missing comma to tuple
(cherry picked from commit 2be41315e7)
2023-02-23 22:39:21 -05:00
Mark Grassi
0eaf6d3649 Replace mutable default arguments in tests
(cherry picked from commit 14e01b5d73)
2023-02-23 22:39:17 -05:00
Christian Boltz
e44e9187ae Merge abstractioms/nvidia: add new cache directory
Some applications (like Firefox or Steam, but for some reason not
glxgears) now writes to ~/.cache/nvidia/*:

```
type=AVC msg=audit(1676115846.764:605): apparmor="DENIED" operation="open" profile="firefox" name="/home/vincas/.cache/nvidia/GLCache/2c0cfcdab4d7b05f8130d8f
ba8838943/ec9a05ca3988cfd1/1fee83e04c0ea4d8.toc" pid=26827 comm="firefox" requested_mask="rac" denied_mask="rac" fsuid=1000 ouid=1000^]FSUID="vincas" OUID="v
incas"
```

```
type=AVC msg=audit(1676134465.264:2166): apparmor="DENIED" operation="open" profile="steam" name="/home/vincas/.cache/nvidia/GLCache/95f6d95b1adf9af310bc94af5f19e509/6b24ef0587ddc7e4/23b502f99abb563c.toc" pid=56082 comm="steam" requested_mask="wr" denied_mask="wr" fsuid=1000 ouid=1000^]FSUID="vincas" OUID="vincas"
```

Update nvidia abstraction to allow create caches in .cache subdirectory.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/982
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit d713f75086)

15b92cd2 abstractioms/nvidia: add new cache directory
2023-02-16 17:41:49 +00:00
Christian Boltz
677051bd02 Merge nvidia_modprobe: update for driver families and /sys path
Debian have split NVIDIA drivers into current, tesla and legacy:

```
$ apt-file search /etc/nvidia/ | grep -P -o -e
"(?<=/etc/nvidia/).[^/]*/" | sort -u
current/
current-open/
legacy-340xx/
legacy-390xx/
tesla/
tesla-418/
tesla-450/
tesla-460/
tesla-470/
tesla-510/
```

These paths are used by nvidia_modprobe -> kmod:

```
type=AVC msg=audit(1676135718.796:2592): apparmor="DENIED" operation="open" profile="nvidia_modprobe//kmod" name="/etc/nvidia/tesla-470/nvidia-blacklists-nouveau.conf" pid=62094 comm="modprobe" requested_mask="r" denied_mask="r" fsuid=0 ouid=0FSUID="root" OUID="root"
type=AVC msg=audit(1676135718.796:2593): apparmor="DENIED" operation="open" profile="nvidia_modprobe//kmod" name="/etc/nvidia/tesla-470/nvidia-options.conf" pid=62094 comm="modprobe" requested_mask="r" denied_mask="r" fsuid=0 ouid=0FSUID="root" OUID="root"
type=AVC msg=audit(1676135718.796:2594): apparmor="DENIED" operation="open" profile="nvidia_modprobe//kmod" name="/etc/nvidia/tesla-470/nvidia-modprobe.conf" pid=62094 comm="modprobe" requested_mask="r" denied_mask="r" fsuid=0 ouid=0FSUID="root" OUID="root"
```

Also, additional /sys path is accessed:

```
type=AVC msg=audit(1676136251.680:2956): apparmor="DENIED" operation="open" profile="nvidia_modprobe//kmod" name="/sys/module/drm/initstate" pid=63642 comm="modprobe" requested_mask="r" denied_mask="r" fsuid=0 ouid=0FSUID="root" OUID="root"
```

Update nvidia_modprobe profile to this these denials.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/983
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit 94d2faab71)

8e50c351 nvidia_modprobe: update for driver families and /sys path
2023-02-14 18:39:27 +00:00
John Johansen
21ca572de6 Merge postfix-tlsmgr: allow reading openssl.cnf
Seen/needed on openSUSE Tumbleweed

I propose this patch for all branches.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/981
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit 3e89b4aab2)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-02-09 00:17:43 -08:00
John Johansen
6c240a473b Merge avahi-daemon needs attach_disconnected
... for var/lib/nscd/passwd and var/lib/nscd/group

I propose this patch for all branches.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/960
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit 2c72dd5541)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-02-03 21:27:10 -08:00
John Johansen
eec9086ecf Merge [3.1] firefox.sh: Adjust local include to match master
The local include in firefox.sh was just added today. Change it to the
value we have in master (as soon as !975 gets accepted).

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/976
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-02-02 18:16:03 +00:00
John Johansen
81d8af7c13 Merge nscd: allow using systemd-userdb
If systemd-userdb is used to configure some users, nscd needs to read
the userdb files.

See also https://www.freedesktop.org/software/systemd/man/nss-systemd.html
for the list of possible filenames (and symlinks).

Fixes: http://bugzilla.opensuse.org/show_bug.cgi?id=1207698

I propose this patch for all branches.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/977
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit 5df8da3c37)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-02-01 19:56:03 -08:00
John Johansen
a9bea8a377 Merge Fix mode not being printed when debugging AF_UNIX socket rules.
This was due to the values being defined in both af_unix and af_rule leaving the latter values unset.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/979
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit da7d3a2101)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-02-01 19:50:55 -08:00
Georgia Garcia
3aa895073a Merge Fix spacing when printing out AF_UNIX addresses
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/978
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
(cherry picked from commit 608560ee43)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-02-01 19:50:37 -08:00
Christian Boltz
dcf7e9a0d5 firefox.sh: Adjust local include to match master
The local include in firefox.sh was just added today. Change it to the
value we have in master (as soon as MR 975 gets accepted).
2023-01-30 12:11:21 +01:00
Christian Boltz
57fec9624d Merge Ensure all profiles in extras/ have optional local include + comment
Recently got bitten by `usr.sbin.lighttpd` not having the local include, so I figured I'd bring all the `extras/` profiles up to parity.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/974
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit 8895e00ef1)

d0e32a32 Ensure all profiles in extras/ have optional local include + comment
2023-01-30 10:16:20 +00:00
John Johansen
aee9bf56c0 Merge libapparmor: add scanner support for dbus method
In the [merge request that adds AppArmor support on D-Bus Broker](https://github.com/bus1/dbus-broker/pull/286), the word "method" is used instead of "member" on the auditing logs.
So we are adding support to parse "method" the same way as "member" on D-Bus audit logs.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/958
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit a96fa35bd5)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-01-25 13:08:31 -08:00
John Johansen
0295fadab3 Merge add dbus-broker support on regression tests
dbus-broker requires some modification of the test suite. In summary:

* refactor to support starting and stopping both dbus and dbus-broker.
* Make it so we can run the tests on each, where appropriate
* skip unrequested reply and eavesdrop tests for dbus broker because they are not supported.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/965
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit 223036d952)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-01-24 16:39:44 -08:00
John Johansen
5bc35342ed Merge Fix: Opening links with Brave
Resolves #292.

This fix is the same as !830 but for Brave.
Opening links in Brave now works as intended.

Note that now a separate denial is caused, related to WidevineCDM, is produced:
```
[ERROR:content_main_runner_impl.cc(415)] Unable to load CDM /home/username/.config/BraveSoftware/Brave-Browser/WidevineCdm/4.10.2557.0/_platform_specific/linux_x64/libwidevinecdm.so (error: /home/username/.config/BraveSoftware/Brave-Browser/WidevineCdm/4.10.2557.0/_platform_specific/linux_x64/libwidevinecdm.so: failed to map segment from shared object)
```

In the syslog:
```
audit: type=1400 audit(1671108748.090:117): apparmor="DENIED" operation="file_mmap" profile="/usr/bin/evince//sanitized_helper" name="/home/username/.config/BraveSoftware/Brave-Browser/WidevineCdm/4.10.2557.0/_platform_specific/linux_x64/libwidevinecdm.so" pid=65765 comm="brave" requested_mask="m" denied_mask="m" fsuid=1000 ouid=100
```

I'm not sure if granting permission(s) for this is desirable. In either case, the potential relevant changes are out of the scope of this MR.

If I disable WidevineCDM in Brave, I get the following denial on cap sys_admin:
```
audit: type=1400 audit(1671112807.666:174): apparmor="DENIED" operation="capable" profile="/usr/bin/evince//sanitized_helper" pid=112098 comm="brave" capability=21  capname="sys_admin"
```
which is fine, as mentioned by @jjohansen [here](https://gitlab.com/apparmor/apparmor/-/merge_requests/830#note_831915024).

Closes #292
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/957
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit 5fd8c25745)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-01-24 16:32:30 -08:00
John Johansen
6cc9160246 Merge Extend crypto and ssl_certs abstractions
- ssl_certs: /{etc,usr/share}/pki/trust/ has more than the 'anchors' subdirectory
- crypoto: allow reading /etc/gcrypt/hwf.deny

I propose this patch for 3.0..master (2.13 doesn't have abstractions/crypto).

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/961
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>


(cherry picked from commit bb30df7843)

d15bfa99 Extend crypto and ssl_certs abstractions
2023-01-24 23:10:21 +00:00
Christian Boltz
5452053f5b Merge Add pipewire client.conf to audio abstractions
Fixes: https://bugs.launchpad.net/bugs/2003702

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/970
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit dedb5d94cb)

b5a7641d Add pipewire client.conf to audio abstractions
2023-01-23 20:35:14 +00:00
Christian Boltz
da906cda8c Merge profiles: dnsmasq: add Waydroid pid file
Waydroid uses LXC and some lxc-net equivalent scripts. Allow that.

b910c89174/data/scripts/waydroid-net.sh
https://web.archive.org/web/20221202141315/https://docs.waydro.id/debugging/known-issues

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/969
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit d61ccafcb3)

977e45c1 profiles: dnsmasq: add Waydroid pid file
2023-01-22 18:11:28 +00:00
John Johansen
a19754f52f Merge regression tests: fix bogon patch characters in Makefile
Commit 8cf3534a5 ("tests regression: fix failure on older versions of
Make") from https://gitlab.com/apparmor/apparmor/-/merge_requests/639
was incorrectly applied, including the `+` prefixes from the proposed
patch. This causes the sysctl syscall() checks to not correctly be
applied and results in a mismatch of expectations in the
syscall_sysctl.sh test script, causing it and the testsuite to fail.

Thus, remove the bogon `+` characters from the Makefile, to make
USE_SYSCTL be set correctly.

Fixes: 8cf3534a5 ("tests regression: fix failure on older versions of Make")
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/963
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Approved-by: Christian Boltz <apparmor@cboltz.de>
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit f0bc1a89a4)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-01-04 16:45:22 -08:00
John Johansen
379a486b87 Merge aa-status: Fix malformed json output with unconfined processes
As reported in issue #295, the json output from aa-status would be invalid if
there were profiles defined for processes that were unconfined. Fix this by
ensuring the json for the processes array is closed properly.

Signed-off-by: Alex Murray <alex.murray@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/964
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit dfc9847f89)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-01-04 09:33:59 -08:00
Georgia Garcia
5ad91d482d Merge log parsing fixes
small fixes on log parsing

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/959
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
(cherry picked from commit 4f2d2a8cab)
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-12-16 16:55:31 -03:00
John Johansen
19bbc5dfc3 Merge parser: Fix invalid reference to transitions when building the chfa
States are not guaranteed to have transitions, but when inserting
a state into the chfa table there is an unconditional dereference
to the states first transition.

This will result in a bad reference and could result in an OOB
flag being set on the state when it shouldn't be.

Fixes: 16b67ddbd ("add ability to use out of band transitions"
Closes: https://gitlab.com/apparmor/apparmor/-/issues/290
Reported-by: Nobel Barakat <nobelbarakat@google.com>
Reported-by: Oleksandr Tymoshenko <ovt@google.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>

Closes #290
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/956
Approved-by: Seth Arnold <seth.arnold@gmail.com>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit a7bce9be98)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-12-09 23:03:54 -08:00
John Johansen
66cb0ed739 Merge smbd: allow reading /var/lib/nscd/netgroup
(reported on the opensuse-factory mailinglist)

I propose this patch for 2.13..master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/948
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit ba01d479e2)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-11-29 12:56:21 -08:00
Christian Boltz
d179a704e7 Merge abstractions/nvidia: allow reading @{pid}/comm
On Debian Sid, NVIDIA driver spams log with:

```
type=AVC msg=audit(1669542108.552:11855): apparmor="DENIED"
operation="open" profile="qtox" name="/proc/21222/comm" pid=21222
comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000
ouid=1000FSUID="vincas" OUID="vincas"
```

```
type=AVC msg=audit(1669541506.703:11329): apparmor="DENIED"
operation="open" profile="skypeforlinux" name="/proc/19851/comm"
pid=19851 comm="skypeforlinux" requested_mask="r" denied_mask="r"
fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"
```

Read is initiated within libnvidia-glcore.so:

```
Thread 1 "qtox" hit Catchpoint 1 (call to syscall openat), 0x00007fb797b16ed0 in __libc_open64 (file=file@entry=0x7fb742adbb50 "/proc/self/comm", oflag=0) at ../sysdeps/unix/sysv/linux/open64.c:41
41	in ../sysdeps/unix/sysv/linux/open64.c
$27 = 0x7fb742adbb50 "/proc/self/comm"
0  0x00007fb797b16ed0 in __libc_open64 (file=file@entry=0x7fb742adbb50 "/proc/self/comm", oflag=0) at ../sysdeps/unix/sysv/linux/open64.c:41
1  0x00007fb797aa0862 in __GI__IO_file_open (fp=fp@entry=0x55795176e600, filename=filename@entry=0x7fb742adbb50 "/proc/self/comm", posix_mode=<optimized out>, prot=prot@entry=438, read_write=8, is32not64=<optimized out>) at ./libio/fileops.c:188
2  0x00007fb797aa0a1b in _IO_new_file_fopen (fp=fp@entry=0x55795176e600, filename=filename@entry=0x7fb742adbb50 "/proc/self/comm", mode=<optimized out>, mode@entry=0x7fb7428effe2 "r", is32not64=is32not64@entry=1) at ./libio/fileops.c:280
3  0x00007fb797a950f9 in __fopen_internal (filename=0x7fb742adbb50 "/proc/self/comm", mode=0x7fb7428effe2 "r", is32=1) at ./libio/iofopen.c:75
4  0x00007fb7423d791f in ?? () from /lib/x86_64-linux-gnu/libnvidia-glcore.so.470.141.03
5  0x00007fb7423d4515 in ?? () from /lib/x86_64-linux-gnu/libnvidia-glcore.so.470.141.03
6  0x00007fb7423d0226 in ?? () from /lib/x86_64-linux-gnu/libnvidia-glcore.so.470.141.03
7  0x00007fb7423e1961 in ?? () from /lib/x86_64-linux-gnu/libnvidia-glcore.so.470.141.03
8  0x00007fb74824bc79 in ?? () from /lib/x86_64-linux-gnu/libGLX_nvidia.so.0
9  0x00007fb7482b1c56 in ?? () from /lib/x86_64-linux-gnu/libGLX_nvidia.so.0
10 0x000000000000001d in ?? ()
11 0x00005579518975f0 in ?? ()
12 0x0000000000000001 in ?? ()
13 0x00007fb74824b1eb in ?? () from /lib/x86_64-linux-gnu/libGLX_nvidia.so.0
14 0x00005579518975f0 in ?? ()
15 0x00007fb79b2dda79 in call_init (env=0x7ffd92d7aac8, argv=0x7ffd92d7aab8, argc=-1831363648, l=0x7fb748516f70) at ./elf/dl-init.c:56
16 call_init (l=0x7fb748516f70, argc=-1831363648, argv=0x7ffd92d7aab8, env=0x7ffd92d7aac8) at ./elf/dl-init.c:26
17 0x00007fb79b2ddba4 in _dl_init (main_map=0x5579518975f0, argc=1, argv=0x7ffd92d7aab8, env=0x7ffd92d7aac8) at ./elf/dl-init.c:117
18 0x00007fb797b6def4 in __GI__dl_catch_exception (exception=<optimized out>, operate=<optimized out>, args=<optimized out>) at ./elf/dl-error-skeleton.c:182
19 0x00007fb79b2e430e in dl_open_worker (a=a@entry=0x7ffd92d79f20) at ./elf/dl-open.c:808
20 0x00007fb797b6de9a in __GI__dl_catch_exception (exception=<optimized out>, operate=<optimized out>, args=<optimized out>) at ./elf/dl-error-skeleton.c:208
21 0x00007fb79b2e46a8 in _dl_open (file=0x557951888020 "libGLX_nvidia.so.0", mode=<optimized out>, caller_dlopen=0x7fb78d7d4d27, nsid=<optimized out>, argc=1, argv=0x7ffd92d7aab8, env=0x7ffd92d7aac8) at ./elf/dl-open.c:884
22 0x00007fb797aa42d8 in dlopen_doit (a=a@entry=0x7ffd92d7a190) at ./dlfcn/dlopen.c:56
23 0x00007fb797b6de9a in __GI__dl_catch_exception (exception=exception@entry=0x7ffd92d7a0f0, operate=<optimized out>, args=<optimized out>) at ./elf/dl-error-skeleton.c:208
24 0x00007fb797b6df4f in __GI__dl_catch_error (objname=0x7ffd92d7a148, errstring=0x7ffd92d7a150, mallocedp=0x7ffd92d7a147, operate=<optimized out>, args=<optimized out>) at ./elf/dl-error-skeleton.c:227
25 0x00007fb797aa3dc7 in _dlerror_run (operate=operate@entry=0x7fb797aa4280 <dlopen_doit>, args=args@entry=0x7ffd92d7a190) at ./dlfcn/dlerror.c:138
26 0x00007fb797aa4389 in dlopen_implementation (dl_caller=<optimized out>, mode=<optimized out>, file=<optimized out>) at ./dlfcn/dlopen.c:71
27 ___dlopen (file=<optimized out>, mode=<optimized out>) at ./dlfcn/dlopen.c:81
28 0x00007fb78d7d4d27 in ?? () from /lib/x86_64-linux-gnu/libGLX.so.0
29 0x00007fb78d7d6335 in ?? () from /lib/x86_64-linux-gnu/libGLX.so.0
30 0x00007fb78d7cf9f8 in glXChooseFBConfig () from /lib/x86_64-linux-gnu/libGLX.so.0
31 0x00007fb748646f6a in ?? () from /usr/lib/x86_64-linux-gnu/qt5/plugins/xcbglintegrations/libqxcb-glx-integration.so
32 0x00007fb748644450 in ?? () from /usr/lib/x86_64-linux-gnu/qt5/plugins/xcbglintegrations/libqxcb-glx-integration.so
33 0x00007fb7486421b7 in ?? () from /usr/lib/x86_64-linux-gnu/qt5/plugins/xcbglintegrations/libqxcb-glx-integration.so
34 0x00007fb79838262d in QOpenGLContext::create() () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
35 0x00007fb74bb4303c in ?? () from /usr/lib/x86_64-linux-gnu/qt5/plugins/platformthemes/KDEPlasmaPlatformTheme.so
36 0x00007fb797eb7aaf in qt_call_pre_routines () at kernel/qcoreapplication.cpp:317
37 QCoreApplicationPrivate::init (this=<optimized out>) at kernel/qcoreapplication.cpp:849
38 0x00007fb7983379dc in QGuiApplicationPrivate::init() () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
39 0x00007fb798b684c9 in QApplicationPrivate::init() () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
40 0x0000557950f1d597 in main ()
```

Add read rule to allow reading @{pid}/comm.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/954
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit 2597fd5db8)

948cbb56 abstractions/nvidia: allow reading @{pid}/comm
2022-11-27 13:06:48 +00:00
Christian Boltz
4244737f65 Merge lsb_release: allow cat and cut
lsb_release fails on Debian Sid:

```
$ sudo aa-exec -p lsb_release lsb_release
/usr/bin/lsb_release: 70: cut: Permission denied
/usr/bin/lsb_release: 70: cut: Permission denied
```

```
$ sudo aa-exec -p lsb_release lsb_release -h
/usr/bin/lsb_release: 11: cat: Permission denied
```

```
type=AVC msg=audit(1669540199.087:2680): apparmor="DENIED"
operation="exec" profile="lsb_release" name="/usr/bin/cut" pid=17419
comm="lsb_release" requested_mask="x" denied_mask="x" fsuid=0
ouid=0FSUID="root" OUID="root"
```

```
type=AVC msg=audit(1669540392.244:2944): apparmor="DENIED"
operation="exec" profile="lsb_release" name="/usr/bin/cat" pid=17847
comm="lsb_release" requested_mask="x" denied_mask="x" fsuid=0
ouid=0FSUID="root" OUID="root"
```

Update profile to allow lsb_release script to invoke required
executables.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/953
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit 495f68c797)

f596a176 lsb_release: allow cat and cut
2022-11-27 13:00:19 +00:00
Christian Boltz
e617f04681 Merge Include profile name in error message on directory exec
... to make the error message more helpful.

Inspired by https://gitlab.com/apparmor/apparmor/-/issues/285

I propose this patch for 3.1 and master.
(3.0 uses a different variable name - if we want it there, it needs a slightly different patch.)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/949
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit dd5a6c2e0a)

ef5c4b50 Include profile name in error message on directory exec
2022-11-21 12:59:51 +00:00
Christian Boltz
9d826aae65 Merge Catch PermissionError when trying to write a profile
... and re-raise it as AppArmorException so that only the actual error
(without a backtrace) gets displayed.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/282

I propose this patch for 3.0..master.

Closes #282
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/946
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit 50074a3c01)

d0ec2aca Catch PermissionError when trying to write a profile
2022-11-15 20:46:12 +00:00
Christian Ehrhardt
465c861b02 Allow access to possible cpus for glibc-2.36
Glibc in 2.36 and later will [1] access sysfs at
/sys/devices/system/cpu/possible when usig sysconf
for _SC_NPROCESSORS_CONF.

That will make a lot of different code, for example
anything linked against libnuma, trigger this apparmor
denial.

  apparmor="DENIED" operation="open" class="file" ...
  name="/sys/devices/system/cpu/possible" ...
  requested_mask="r" denied_mask="r" fsuid=0 ouid=0

This entry seems rather safe, and it follows others
that are already in place. Instead of fixing each
software individually this should go into the base
profile as well.

Initially reported via
https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1989073
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/267
MR: none - ML
Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
(cherry picked from commit c159d0925a)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-11-14 21:47:18 -08:00
John Johansen
dc85d04805 Merge Adds WSL programmatic management of /etc/resolv.conf.
When WSL automatically generates a resolv.conf for an instance, the /etc/resolv.conf file is a symlink to /mnt/wsl/resolv.conf. This patch adds an entry for this to the other policies to handle such management.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/935
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>


(cherry picked from commit 8fa77e9e6c)

5232eaa2 Adds /mnt/wsl/resolv.conf to nameservices.
2022-11-08 18:13:57 +00:00
John Johansen
a40923006c Merge Allow reading /sys/devices/system/cpu/possible
... in the dnsmasq//libvirt_leaseshelper profile

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1202849

I propose this patch for 3.0, 3.1 and master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/917
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>


(cherry picked from commit 37f0f77425)

ace8e044 Allow reading /sys/devices/system/cpu/possible
2022-11-08 18:11:23 +00:00
John Johansen
1fe80c0f85 Prepare for AppArmor 3.1.2 release
- update version file
- update library version

Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-11-07 10:44:48 -08:00
John Johansen
8043dda3f6 Merge Hardcode and check the expected libapparmor.so name/number
... to prevent wrong/unexpected numbering (like
https://gitlab.com/apparmor/apparmor/-/issues/266) in future releases.

I propose this patch for master and 3.1.

Backporting to 3.0 and 2.x might also make sense, but of course needs a different .so number.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/915
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit bed1471144)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-10-29 03:08:56 -07:00
John Johansen
e95080e140 Merge libapparmor: allow parsing of logs with 0x1d + uppercase items
audit.log lines on Arch have an additional FSUID="username" OUID="username",
separated from the previous part of the log line with 0x1d.

Extend the log parsing to accept 0x1d as whitespace, and to recognize
(and ignore) FSUID and OUID.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/271

Also add one of the log lines from #271 as test_multi test case.

I propose this patch for 3.0..master.

Closes #271
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/940
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit 0d61139e2a)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-10-29 03:06:30 -07:00
John Johansen
45125cedd3 Merge syslog-ng: allow reading *.journal in flatter directory structure
On openSUSE Leap 15.4 (and probably also 15.3), the journal lives in
/var/log/journal/*.journal - without an additional subdirectory level.

I propose this patch for 2.13..master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/932
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-10-28 05:56:57 -07:00
Christian Boltz
969a8f7618 Merge samba-rpcd-spoolss: allow mkdir /var/cache/samba/printing/
Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1993572

I propose this fix for 3.0..master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/937
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit fab4b4e762)

6920daea samba-rpcd-spoolss: allow mkdir /var/cache/samba/printing/
2022-10-27 22:34:12 +00:00
Christian Boltz
770b8f1e88 Merge abstactions/kde: update for kwinrc, kdedefaults/* files
GUI applications such as KDE dragon player, qTox, LibreOffice tries to
access .config/kwinrc, .config/kdedefaults/kwinrc and
.config/kdedefaults/kdeglobals.

Update abstractions/kde to fix denials for applications running under
KDE.

Some examples:
```
type=AVC msg=audit(1666458796.112:5561): apparmor="DENIED" operation="open" profile="libreoffice-soffice" name="/home/vincas/.config/kdedefaults/kdeglobals" pid=43868 comm="soffice.bin" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"
type=AVC msg=audit(1666458796.204:5683): apparmor="DENIED" operation="open" profile="libreoffice-soffice" name="/home/vincas/.config/kdedefaults/kwinrc" pid=43868 comm="soffice.bin" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"

```
```
type=AVC msg=audit(1666462415.255:3640): apparmor="DENIED" operation="open" profile="kde-dragon-player" name="/home/vincas/.config/kdedefaults/kdeglobals" pid=8344 comm="dragon" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"
type=AVC msg=audit(1666462415.343:3641): apparmor="DENIED" operation="open" profile="kde-dragon-player" name="/home/vincas/.config/kdedefaults/kwinrc" pid=8344 comm="dragon" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"
```

```
type=AVC msg=audit(1666459466.968:5852): apparmor="DENIED" operation="open" profile="qtox" name="/home/vincas/.config/kdedefaults/kdeglobals" pid=44561 comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"
type=AVC msg=audit(1666459467.076:6057): apparmor="DENIED" operation="open" profile="qtox" name="/home/vincas/.config/kdedefaults/kwinrc" pid=44561 comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"
type=AVC msg=audit(1666459467.076:6058): apparmor="DENIED" operation="open" profile="qtox" name="/home/vincas/.config/kwinrc" pid=44561 comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"

```

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/936
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit 18d1b06b0c)

d9dc0b61 abstactions/kde: update for kwinrc, kdedefaults/* files
2022-10-22 19:28:38 +00:00
Christian Boltz
3345250f72 Merge parser: fix DISTRO variable in Makefile
A single '$()' results in variable expansion, which makes
"$(rpm --eval ..)" always an empty string.

Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/928
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit 05d7bdd655)

1df547ee parser: fix DISTRO variable in Makefile
2022-10-07 19:54:08 +00:00
John Johansen
51cf0848c7 Merge profiles/apparmor.d: Update samba profile
Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1990692
Signed-off-by: Spyros Seimenis <spyros.seimenis@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/926
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>


(cherry picked from commit e1cc90f3a2)

96aff5a5 profiles/apparmor.d: Update samba profile
2022-10-01 10:20:32 +00:00
Christian Boltz
e0c0a6a6a5 Merge Prevent crash on log entries for non-existing profile
If audit.log contains entries for a profile that doesn't exist (for
example when working with a log file from another system), skip these
log entries instead of crashing.

Reproducer (crashes without this patch):

    aa-logprof -f <(echo 'type=AVC msg=audit(1661739121.578:77893): apparmor="DENIED" operation="open" profile="no_such_profile" name="/run/" pid=33099 comm="no" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0')

I propose this patch for 3.1 and master. (3.0 and older are not affected and do not need this fix.)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/919
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit f5594fbb7c)

94c7c79c Prevent crash on log entries for non-existing profile
2022-08-29 19:56:17 +00:00
Steve Beattie
ea127f13cd common/Version: bump version for 3.1.1 release
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2022-08-26 23:35:24 -07:00
Christian Boltz
480cb56553 Merge profiles: permit php-fpm pid files directly under run/
The upstream php-fpm.conf file carries the following pid file example
path:
  [global]
  ; Pid file
  ; Note: the default prefix is @EXPANDED_LOCALSTATEDIR@
  ; Default Value: none
  ;pid = run/php-fpm.pid

Add this path to profiles/apparmor.d/php-fpm, alongside the current
nested "@{run}/php{,-fpm}/php*-fpm.pid" wildcard.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/267

Suggested-by: Ali Abdallah <ali.abdallah@suse.com>
Signed-off-by: David Disseldorp <ddiss@suse.de>

Closes #267
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/914
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit d024100efe)

d8533ec8 profiles: permit php-fpm pid files directly under run/
2022-08-26 10:36:11 +00:00
Georgia Garcia
075c69a4eb Merge [3.1] libapparmor: fix mistaken SO version bump
In commit 7c7224004 ("Prepare for AppArmor 3.1 release"), as preperation
for the AppArmor 3.1.0 release, the SO versioning information was
adjusted, using a more significant bump to give prior AppArmor releases
room to address bugs in libapparmor without ending up with conflicting
SO versions. Unfortunately, that process was untested and because
AA_LIB_AGE was not incremented by the same amount as AA_LIB_CURRENT,
this resulted in an accidental major SO versions bump with the library
SO version being:

  libapparmor.so.4.9.0

This commit increments AA_LIB_AGE by the same amount, resulting in a
library versioned as:

  libapparmor.so.1.12.0

and adds a note to mention that AA_LIB_AGE needs to be incremented
in the same way as AA_LIB_CURRENT. This fix is intended to address
this for the 3.1 branch; I'd like to find a better approach for
the development branch that can be used in future AppArmor primary
releases.

In general, thanks to symbol versioning (see
`libraries/libapparmor/src/libapparmor.map`) we should not need to
ever bump the SO version except in an extreme case.

Fixes: 7c7224004 ("Prepare for AppArmor 3.1 release")
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Bug: https://gitlab.com/apparmor/apparmor/-/issues/266

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/913
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-08-25 20:10:30 +00:00
Steve Beattie
f9dbaa38ec [3.1] libapparmor: fix mistaken SO version bump
In commit 7c7224004 ("Prepare for AppArmor 3.1 release"), as preperation
for the AppArmor 3.1.0 release, the SO versioning information was
adjusted, using a more significant bump to give prior AppArmor releases
room to address bugs in libapparmor without ending up with conflicting
SO versions. Unfortunately, that process was untested and because
AA_LIB_AGE was not incremented by the same amount as AA_LIB_CURRENT,
this resulted in an accidental major SO versions bump with the library
SO version being:

  libapparmor.so.4.9.0

This commit increments AA_LIB_AGE by the same amount, resulting in a
library versioned as:

  libapparmor.so.1.12.0

and adds a note to mention that AA_LIB_AGE needs to be incremented
in the same way as AA_LIB_CURRENT. This fix is intended to address
this for the 3.1 branch; I'd like to find a better approach for
the development branch that can be used in future AppArmor primary
releases.

In general, thanks to symbol versioning (see
`libraries/libapparmor/src/libapparmor.map`) we should not need to
ever bump the SO version except in an extreme case.

Fixes: 7c7224004 ("Prepare for AppArmor 3.1 release")
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Bug: https://gitlab.com/apparmor/apparmor/-/issues/266
2022-08-25 11:55:42 -07:00
John Johansen
7c7224004c Prepare for AppArmor 3.1 release
- update version file
- update library version

Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-08-23 13:39:18 -07:00
John Johansen
db246ddbb5 parser: begin deprecation process for #include
by adding a warning flag that is disabled by default. This will enable
devs to find when and where #include is in use by adding the compile
flag

  --warn=pound-include

and can even abort policy compiles by using

  --warn=pound-include --Werror=pound-include

The resulting messages look like

  Warning from /etc/apparmor.d/usr.sbin.cupsd (/etc/apparmor.d/usr.sbin.cupsd line 5): deprecated use of '#include'

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Time-out
2022-08-22 15:03:26 -07:00
John Johansen
a382452a54 libapparmor: update rules around the library version
This change tries to give us some room to deal with versioning issues
like we had in

  145136f6 Fix 2.13 libapparmor so version

which revered the library version bump in
  5c47e448 libapparmor: Bump revision in preparation for release.

which was done because of the symbol added by
  351014c3 libapparmor: add _aa_asprintf to private symbols

unfortunately this collided with the 3.0 library symbol versioning
which had a different set of symbols with the same version numbering.
Leaving us no way to increase the version number to when fixing an
exported symbol version in a released library.

Ideally this would have been fixed with library version synchs but
in this case that option wasn't open as we were dealing with two
released versions of the library.

Bumping the current version by 5 on the larger releases gives us room
to deal with these kind of bugs in the future.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Time-out
2022-08-22 14:52:37 -07:00
John Johansen
f51049ea2e Merge dnsmasq: Add missing r permissions for libvirt_leaseshelper
Note: This was reported for /usr/libexec/libvirt_leaseshelper, but since
this is probably unrelated to the path or a path change, this commit
also adds r permissions for the previous path.

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1202161

I propose this patch for 3.0 and master (optionally also for 2.12 and 2.13 - please tell me if you want that after reviewing the patch, or just merge ;-)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/905
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-08-22 21:44:12 +00:00
Christian Boltz
406b6398af Merge dnsmasq: allow paths for podman dnsname plugin in rootless mode
In rootless mode, files needed to access are under /run/user/, so those needs to be defined separately.

similar change than https://gitlab.com/apparmor/apparmor/-/merge_requests/800 but adds permissions for rootless mode.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/909
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-08-22 11:57:21 +00:00
Christian Boltz
bcffe7c92c Merge Address Style Guide Infractions
This MR addresses much of #241. Each commit handles a different aspect of the style guide. All commits are style-only. Lacking from this MR are changes that would alter behavior and/or break backward-compatibility.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/906
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-08-22 10:47:33 +00:00
IIkka Ollakka
86069dd934 dnsmasq: allow paths for podman dnsname plugin in rootless mode
In rootless mode, files needed to access are under /run/user/, so those needs to be defined separately.
2022-08-22 13:20:40 +03:00
Mark Grassi
2f9068e37c Remove duplicate regex "or" comments. 2022-08-21 11:15:07 -04:00
Mark Grassi
46a2be31a7 Remove outdated/incorrect comment. 2022-08-21 11:15:07 -04:00
Mark Grassi
e8b60e46fe Improve regex formatting. 2022-08-21 11:15:07 -04:00
Mark Grassi
b1c2aeaa76 Be consistent with return statements when only returning None. 2022-08-21 11:15:07 -04:00
Mark Grassi
091c6ad59d Use string startswith() and endswith() methods instead of slicing to check for prefixes and suffixes. 2022-08-21 11:15:07 -04:00
Mark Grassi
854602c0d9 Use the fact that empty sequences are false. 2022-08-21 11:15:07 -04:00
Mark Grassi
68e3f12c2c Avoid escaping quotation marks where possible. 2022-08-21 11:15:07 -04:00
Mark Grassi
c57138f255 Order imports and module-level dunder name assignments. 2022-08-21 11:15:07 -04:00
Mark Grassi
ea3fb60007 Break lines before binary operators. 2022-08-21 11:15:07 -04:00
Mark Grassi
ef2e6c62e7 Ensure variables inside functions are lower_case_with_underscores. 2022-08-21 11:15:07 -04:00
Mark Grassi
dc384c48a8 Use triple double-quoted strings for docstrings. 2022-08-21 11:15:07 -04:00
Mark Grassi
de3aa3c5f0 Correct misspelling. 2022-08-21 11:15:07 -04:00
Mark Grassi
f590a66e50 Remove redundant backslashes, and unnecessary semicolons and pass statements. 2022-08-21 11:15:07 -04:00
Mark Grassi
813c831468 Ensure non-membership tests are "not in". 2022-08-21 11:15:07 -04:00
Mark Grassi
96f7121944 Fix most PEP 8 whitespace, indentation, and major line length violations. 2022-08-21 11:15:07 -04:00
Mark Grassi
e4f88cc3a8 Indent line continuations per PEP 8. 2022-08-21 11:15:07 -04:00
Mark Grassi
aff9bb8f81 Ensure no bool comparisons use equality comparisons. 2022-08-21 11:15:07 -04:00
Mark Grassi
62f99465e9 Ensure all None comparisons use is or is not. 2022-08-21 11:15:07 -04:00
Mark Grassi
0375ea1257 Change tabs to spaces in Python files. 2022-08-21 11:15:07 -04:00
Christian Boltz
c06ea77445 Merge Set (instead of compare) exresult
Interestingly this accidentally worked because `if exresult` is true for
both a non-empty string ("PASS") as well as a real `True` value.

Found by Mark Grassi as part of
https://gitlab.com/apparmor/apparmor/-/merge_requests/906

I propose this patch for all branches.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/907
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-08-16 19:25:49 +00:00
Christian Boltz
5a2fb8569c Set (instead of compare) exresult
Interestingly this accidentally worked because `if exresult` is true for
both a non-empty string ("PASS") as well as a real `True` value.

Found by Mark Grassi as part of
https://gitlab.com/apparmor/apparmor/-/merge_requests/906
2022-08-14 12:33:56 +02:00
Christian Boltz
c9c5208f77 dnsmasq: Add missing r permissions for libvirt_leaseshelper
Note: This was reported for /usr/libexec/libvirt_leaseshelper, but since
this is probably unrelated to the path or a path change, this commit
also adds r permissions for the previous path.

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1202161
2022-08-08 20:48:58 +02:00
Georgia Garcia
a555ccd9f4 Merge Fix setuptools version detection in buildpath.py
libraries/libapparmor/swig/python/test/buildpath.py:
The changes introduced in
cc7f549665
targetted a wrong setuptools version (61.2).
The change in build directory naming has been introduced with 62.0.

Fixes #259 
Fixes #39

Closes #39 and #259
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/904
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-08-03 17:21:50 +00:00
David Runge
1ff0c2c7d6 Use basepath.py in profiles Makefile
profiles/Makefile:
Set PYTHON_DIST_BUILD_PATH using
libraries/libapparmor/swig/python/test/buildpath.py as it solves the
problem of setting the build directory generically.
2022-08-03 10:56:51 +02:00
David Runge
fda390983f Fix setuptools version detection in buildpath.py
libraries/libapparmor/swig/python/test/buildpath.py:
The changes introduced in
cc7f549665
targetted a wrong setuptools version (61.2).
The change in build directory naming has been introduced with 62.1
(1c23f5e1e4).
2022-08-03 10:56:47 +02:00
John Johansen
b65fbf5fbd Sync Library version from 3.0.5 release
See v3.0.5 704c82c574

Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-07-25 15:29:12 -07:00
Georgia Garcia
0afc2cbb84 parser: fix LTO build
The previous fix for LTO builds in b6d3daa7 did not take into
consideration that LTO support could be added through CFLAGS,in which
case the fix would not be applied.

This patch applied the fix -flto-partition=none even if CFLAGS is
already defined.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
Closes #214
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/901
Acked-by: John Johansen <john@jjmx.net>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-07-25 17:34:27 -03:00
Christian Boltz
1f3a817c11 Merge dirtest.sh: don't rely on apparmor_parser -N's output sort order to be deterministic
I've seen this test fail because "apparmor_parser -N" returned the expected
lines, but in a different order than what's expected (dirtest.out).

To fix this, sort both the expected and actual output.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/900
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-07-25 20:09:16 +00:00
intrigeri
c0815d0e0f dirtest.sh: don't rely on apparmor_parser -N's output sort order to be deterministic
I've seen this test fail because "apparmor_parser -N" returned the expected
lines, but in a different order than what's expected (dirtest.out).

To fix this, sort both the expected and actual output.
2022-07-25 10:14:31 +00:00
Christian Boltz
c0b5d90848 Merge Resolve "Python: Ensure opened files are closed."
This MR closes #239. In the temporary file commit, `tempfile.NamedTemporaryFile` is preferred over `tempfile.mkstemp` because it allows for simpler use of context managers and lets you choose what mode to open the file in. Also in this commit, note that in `aa.py` and `easyprof.py` destination files are now written directly, instead of writing to temp files and then renaming them.

Closes #239
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/898
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-07-20 19:34:16 +00:00
Mark Grassi
e6cbdef4ab Implement code review comments. 2022-07-19 20:32:03 -04:00
Christian Boltz
ea0dc96050 Merge Support setuptools >= 61.2 in Python tests
Fix for #253, by mirroring the change from 1c23f5e1e4

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/897
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-07-19 20:29:38 +00:00
Ben Greiner
d442584a0a reviewed edits 2022-07-19 21:47:02 +02:00
Mark Grassi
cf6606d380 Ensure opened temporary files are closed. 2022-07-17 21:52:55 -04:00
Ben Greiner
85734c3bac add setuptools to test-utils CI job 2022-07-16 20:42:07 +02:00
Ben Greiner
47d68dac0f use new build_platlib path with setuptools >= 61.2 2022-07-16 17:47:18 +02:00
Mark Grassi
0c1eb3ec92 Ensure opened files are closed. 2022-07-12 18:34:29 -04:00
Christian Boltz
97bd86c7c6 Merge Remove Python 2 support.
Per the discussion in #243, this MR removes Python 2 compatibility. Namely, this merge request:
- removes code behind `sys` and `platform` interpreter version checks
- removes `unicode` vs. `str` handling
- removes unnecessary `__future__` imports
- removes unnecessary `object` inheritance
- removes unnecessary `super()` arguments
- uncomments commented-out code with "uncomment when python3 only" notes or some variant of that message

Regarding the `unicode` vs. `str` handling, it's arguably more Pythonic to check `isinstance(x, str)` as opposed to `type(x) is str`, but I didn't want to alter code behavior.

A change needs to be made to the `INCOMPLETE_COVERAGE` setting in `utils/test/Makefile` to get the pipeline to pass. I didn't get anywhere tweaking the setting myself, so someone else with more AppArmor experience will have to make that change.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/894
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-07-12 18:26:29 +00:00
Steve Beattie
0859b42ba2 profiles: merge Update syslogd for inetutils-syslogd
The inetutils syslogd implementation integrates the kmsg support in the
main server, it has support for syslog.d configuration fragment files.
and it uses a slightly different pid filename.

Signed-off-by: Guillem Jover <guillem@hadrons.org>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/888
Approved-by: Steve Beattie <gitlab@nxnw.org>
Merged-by: Steve Beattie <gitlab@nxnw.org>
2022-07-08 05:12:46 +00:00
Christian Boltz
e1011d646d Merge rc.apparmor.functions: only use systemd-detect-virt if it's present
This is a follow-up on !812, which added a call to systemd-detect-virt.
Everywhere else we don't assume that program is present,
and first check if it's there before we run it.
Let's do the same here.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/896
Approved-by: Christian Boltz <apparmor@cboltz.de>
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-07-06 21:45:39 +00:00
Mark Grassi
db4939cf6a Improve variable name. 2022-07-06 13:51:57 -04:00
Mark Grassi
44c814e76c Update code coverage settings. 2022-07-06 13:29:32 -04:00
intrigeri
06f86e2a02 rc.apparmor.functions: only use systemd-detect-virt if it's present
This is a follow-up on !812, which added a call to systemd-detect-virt.
Everywhere else we don't assume that program is present,
and first check if it's there before we run it.
Let's do the same here.
2022-07-06 06:41:35 +00:00
Mark Grassi
df97cf89bd Remove Python 2 support. 2022-06-29 20:41:38 -04:00
Christian Boltz
57eebd6cdb Merge zgrep: allow executing egrep and fgrep
egrep and fgrep also need to execute grep and write to /dev/tty in the
helper child profile.

Fixes: https://progress.opensuse.org/issues/113108

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/892
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-06-29 13:25:14 +00:00
Christian Boltz
df37c299e1 zgrep: allow executing egrep and fgrep
egrep and fgrep also need to execute grep and write to /dev/tty in the
helper child profile.

Fixes: https://progress.opensuse.org/issues/113108
2022-06-28 23:27:10 +02:00
Christian Boltz
08da556e4e Merge Fix inconsistent return length.
Correct issue discussed in !889.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/890
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-06-28 18:59:37 +00:00
Mark Grassi
728dbde5e4 Fix inconsistent return length. 2022-06-28 08:30:31 -04:00
Christian Boltz
43f419458e Merge Speed up list creations, and change lists to tuples where appropriate.
Tuples [are quite a bit faster than lists](https://stackoverflow.com/a/22140115). If you don't need mutability, a tuple is almost always the better collection to choose. This merge request changes lists to tuples where appropriate, and speeds up some list creations by changing `list()` calls into `[]` literals. It also changes a few function calls to use tuple unpacking, i.e. `func(*tup)`, as opposed to `func(tup[0], tup[1], ...)`. This yields yet another performance improvement, as well as a readability improvement.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/889
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-06-27 18:56:10 +00:00
Mark Grassi
7581c9e113 Speed up list creations, and change lists to tuples where appropriate.. 2022-06-26 22:18:56 -04:00
Christian Boltz
36c704ce04 Merge Avoid unnecessary memory copies when enlarging lists.
This merge request addresses issue #240.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/886
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-06-26 12:06:22 +00:00
Mark Grassi
ca9920cf92 Avoid unnecessary memory copies when enlarging lists. 2022-06-26 12:06:22 +00:00
Guillem Jover
8175d26cc3 Update syslogd for inetutils-syslogd
The inetutils syslogd implementation integrates the kmsg support in the
main server, it has support for syslog.d configuration fragment files.
and it uses a slightly different pid filename.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2022-06-25 21:15:51 +02:00
Christian Boltz
50a45c6a39 Merge Ensure opened files are closed.
This partially addresses issue #239. There are still some remaining instances where opened files are not properly closed, e.g. the `NamedTemporaryFile` in `utils/apparmor/config.py`.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/885
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-06-22 17:20:49 +00:00
Christian Boltz
df1ca957d6 Merge Fix spelling and grammar errors.
I found a few spelling and grammar errors while working on my other merge requests. I figured it'd be wise to separate these fixes from the code changes.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/887
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-06-22 17:09:42 +00:00
Mark Grassi
c255968e63 Fix spelling and grammar errors. 2022-06-18 16:14:45 -04:00
Mark Grassi
bf819bc8e6 Ensure opened files are closed. 2022-06-18 14:40:58 -04:00
John Johansen
d7e3f33aa8 Merge abstraction/exo-open: Remove dbus deny rule
Abstractions should not generally include deny rules as this can unduly
constrain profiles which include them due to the precedent matching rules
between deny vs allow rules. Also as per the comment, this is not required
for exo-open to work, so simply omit it from the abstraction for
now. Finally, in Ubuntu, the evince profile includes the exo-open
abstraction and this deny rule causes evince to fail to initialise
correctly as it then assumes it cannot use gvfs.

Signed-off-by: Alex Murray <alex.murray@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/884
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-06-16 17:08:11 +00:00
Alex Murray
cd91492d53 abstraction/exo-open: Remove dbus deny rule
Abstractions should not generally include deny rules as this can unduly
constrain profiles which include them due to the precedent matching rules
between deny vs allow rules. Also as per the comment, this is not required
for exo-open to work, so simply omit it from the abstraction for
now. Finally, in Ubuntu, the evince profile includes the exo-open
abstraction and this deny rule causes evince to fail to initialise
correctly as it then assumes it cannot use gvfs.

Signed-off-by: Alex Murray <alex.murray@canonical.com>
2022-06-15 14:54:19 +09:30
Christian Boltz
48fc233d05 Merge samba profiles: support paths used by Arch Linux
On Arch Linux `rpcd_classic`, `rpcd_epmapper`, `rpcd_fsrvp`, `rpcd_lsad`, `rpcd_mdssvc`, `rpcd_rpcecho`, `rpcd_spoolss`, `rpcd_winreg`, `samba-bgqd`, `samba-dcerpcd` and `smbspool_krb5_wrapper` are in `/usr/lib/samba/samba/`.

See https://archlinux.org/packages/extra/x86_64/samba/files/ and https://bugs.archlinux.org/task/74614.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/883
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-06-06 10:53:53 +00:00
nl6720
deadcc0d11 samba profiles: support paths used by Arch Linux
On Arch Linux rpcd_classic, rpcd_epmapper, rpcd_fsrvp, rpcd_lsad, rpcd_mdssvc, rpcd_rpcecho, rpcd_spoolss, rpcd_winreg, samba-bgqd, samba-dcerpcd and smbspool_krb5_wrapper are in /usr/lib/samba/samba/.
See https://archlinux.org/packages/extra/x86_64/samba/files/ and https://bugs.archlinux.org/task/74614.
2022-06-06 11:57:14 +03:00
John Johansen
2a3140cb93 parser: fix min length calculation for inverse character sets
The inverse character set lists the characters it doesn't match. If
the inverse character set contains an oob then that is NOT considered
a match. So length should be one.

However because of oobs are handle not containing an oob doesn't mean
there is a match either. Currently the only way to match an oob is
via a positive express (no inverse matches are possible).

Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-05-23 15:39:14 -07:00
John Johansen
6e0b660709 Merge Update for the mesa abstraction
I noticed that some apps return the following errors when launched:

```
  kernel: audit: type=1400 audit(1651244478.255:5501): apparmor="DENIED" operation="open" profile="some_app" name="/sys/devices/pci0000:00/0000:00:02.0/revision" pid=1877976 comm="some_app" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
  kernel: audit: type=1400 audit(1651244478.255:5502): apparmor="DENIED" operation="open" profile="some_app" name="/sys/devices/pci0000:00/0000:00:02.0/config" pid=1877976 comm="some_app" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
```

Blocking the files results in the following errors when the app is executed in a terminal:

```
  MESA: error: Failed to query drm device.
  libGL error: failed to create dri screen
  libGL error: failed to load driver: crocus
  MESA: error: Failed to query drm device.
  libGL error: failed to create dri screen
  libGL error: failed to load driver: crocus
```

Since they have something to do with MESA, I think the mesa abstraction should
be updated to fix the issue.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/879
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-05-23 22:35:59 +00:00
John Johansen
8490fa1db5 Merge Add missing permissions for dovecot-{imap,lmtp,pop3}
References: https://bugzilla.opensuse.org/show_bug.cgi?id=1199535

I propose this patch for 3.0 and master. (2.13 and older have more different dovecot profiles which might make backporting a bit harder.)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/881
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-05-23 22:33:36 +00:00
John Johansen
a61ae7b2f0 Merge parser/capability.h: add missing <cstdint> include
Without the change apparmor build fails on this week's gcc-13 snapshot as:

    capability.h:66:6: error: variable or field '__debug_capabilities' declared void
       66 | void __debug_capabilities(uint64_t capset, const char *name);
          |      ^~~~~~~~~~~~~~~~~~~~
    capability.h:66:27: error: 'uint64_t' was not declared in this scope
       66 | void __debug_capabilities(uint64_t capset, const char *name);
          |                           ^~~~~~~~
    capability.h:23:1: note: 'uint64_t' is defined in header '<cstdint>'; did you forget to '#include <cstdint>'?
       22 | #include <linux/capability.h>
      +++ |+#include <cstdint>
       23 |

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/882
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-05-23 22:24:53 +00:00
Sergei Trofimovich
64a64be7ff parser/capability.h: add missing <cstdint> include
Without the change apparmor build fails on this week's gcc-13 snapshot as:

    capability.h:66:6: error: variable or field '__debug_capabilities' declared void
       66 | void __debug_capabilities(uint64_t capset, const char *name);
          |      ^~~~~~~~~~~~~~~~~~~~
    capability.h:66:27: error: 'uint64_t' was not declared in this scope
       66 | void __debug_capabilities(uint64_t capset, const char *name);
          |                           ^~~~~~~~
    capability.h:23:1: note: 'uint64_t' is defined in header '<cstdint>'; did you forget to '#include <cstdint>'?
       22 | #include <linux/capability.h>
      +++ |+#include <cstdint>
       23 |
2022-05-23 23:13:14 +01:00
Christian Boltz
ad8df7f88f Add missing permissions for dovecot-{imap,lmtp,pop3}
References: https://bugzilla.opensuse.org/show_bug.cgi?id=1199535
2022-05-15 20:53:35 +02:00
Christian Boltz
ab19f5599d Merge profiles/apparmor.d: update samba-dceprpc & samba-rpcd-* profiles
aarch64 needs some additional rules on tumbleweed to handle for
example

apparmor="DENIED" operation="file_mmap" profile="samba-dcerpcd" name="/usr/lib64/samba/samba-dcerpcd" pid=897 comm="samba-dcerpcd" requested_mask="m" denied_mask="m" fsuid=0 ouid=0

The other new rpcd_* services exhibit similar errors

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1198309

Signed-off-by: Noel Power <noel.power@suse.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/880
Approved-by: Christian Boltz <apparmor@cboltz.de> for 3.0 and master
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-05-11 19:44:43 +00:00
Noel Power
6a621616d9 profiles/apparmor.d: update samba-dceprpc & samba-rpcd-* profiles
aarch64 needs some additional rules on tumbleweed to handle for
example

apparmor="DENIED" operation="file_mmap" profile="samba-dcerpcd" name="/usr/lib64/samba/samba-dcerpcd" pid=897 comm="samba-dcerpcd" requested_mask="m" denied_mask="

The other new rpcd_* services exhibit similar errors

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1198309

Signed-off-by: Noel Power <noel.power@suse.com>
2022-05-11 15:55:01 +01:00
Mikhail Morfikov
a54409eb94 Update for the mesa abstraction
I noticed that some apps return the following errors when launched:

  kernel: audit: type=1400 audit(1651244478.255:5501): apparmor="DENIED" operation="open" profile="some_app" name="/sys/devices/pci0000:00/0000:00:02.0/revision" pid=1877976 comm="some_app" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
  kernel: audit: type=1400 audit(1651244478.255:5502): apparmor="DENIED" operation="open" profile="some_app" name="/sys/devices/pci0000:00/0000:00:02.0/config" pid=1877976 comm="some_app" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

Blocking the files results in the following errors when the app is executed in a terminal:

  MESA: error: Failed to query drm device.
  libGL error: failed to create dri screen
  libGL error: failed to load driver: crocus
  MESA: error: Failed to query drm device.
  libGL error: failed to create dri screen
  libGL error: failed to load driver: crocus

Since they have something to do with MESA, I think the mesa abstraction should
be updated to fix the issue.
2022-04-29 22:58:37 +02:00
Christian Boltz
62bf2f773b Merge zgrep profile: also allow zstd
openSUSE works on extending zgrep to also support zstd-compressed files.

References: http://bugzilla.opensuse.org/show_bug.cgi?id=1198922

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/878
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-04-28 23:01:21 +00:00
Christian Boltz
c5a51a080f zgrep profile: also allow zstd
openSUSE works on extending zgrep to also support zstd-compressed files.

References: http://bugzilla.opensuse.org/show_bug.cgi?id=1198922
2022-04-27 22:15:17 +02:00
John Johansen
c7d060a7dd Merge Add some empty and cut-off bad abi rules
Credits go to Seth who proposed these tests in
https://gitlab.com/apparmor/apparmor/merge_requests/196#note_108500403

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/875
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-04-19 18:54:51 +00:00
John Johansen
3083ce7a39 Merge Allow reading all of /etc/php[578]/** in abstractions/php
... and with that, make a rule in the php-fpm profile (which missed
php8) superfluous.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/229
Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1186267#c11
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/876
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-04-19 18:43:19 +00:00
John Johansen
bfa67b369d Merge profiles: update snap_browsers permissions
The snap_browsers abstraction requires more permissions
due to updates on snaps.
    
Some of the permissions are not required in older versions of
Ubuntu that use 2.12 and 2.13, but are introduced for unification
and ease of maintenance purposes. These include:
```
    all dbus permissions,
    @{PROC}/sys/kernel/random/uuid r,
    owner @{PROC}/@{pid}/cgroup r,
    /var/lib/snapd/sequence/{chromium,firefox,opera}.json r,
```


I also propose a cherry-pick of this commit to 2.12, 2.13 and 3.0

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/877
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-04-19 18:35:52 +00:00
Georgia Garcia
eb828dde6f profiles: update snap_browsers permissions
The snap_browsers abstraction requires more permissions
due to updates on snaps.

Some of the permissions are not required in older versions of
Ubuntu that use 2.12 and 2.13, but are introduced for unification
and ease of maintenance purposes. These include:
all dbus permissions,
@{PROC}/sys/kernel/random/uuid r,
owner @{PROC}/@{pid}/cgroup r,
/var/lib/snapd/sequence/{chromium,firefox,opera}.json r,

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-04-18 21:18:26 -03:00
Christian Boltz
c946f0bf75 Allow reading all of /etc/php[578]/** in abstractions/php
... and with that, make a rule in the php-fpm profile (which missed
php8) superfluous.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/229

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1186267#c11
2022-04-18 20:52:39 +02:00
Christian Boltz
69302067b0 Merge tools.py: inline check_profile_dir() into __init__()
... which was the only caller of this tiny function.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/874
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-04-18 11:47:22 +00:00
Christian Boltz
a2ff041e98 Merge zgrep profile: allow executing /usr/bin/expr
expr is used for parsing commandline options in zgrep.

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1198531

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/873
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-04-18 11:46:52 +00:00
Christian Boltz
8cb81ec25f Add some empty and cut-off bad abi rules
Credits go to Seth who proposed these tests in
https://gitlab.com/apparmor/apparmor/merge_requests/196#note_108500403
2022-04-17 00:38:18 +02:00
Christian Boltz
484247355e tools.py: inline check_profile_dir() into __init__()
... which was the only caller of this tiny function.
2022-04-16 23:38:17 +02:00
Christian Boltz
ad8c5f0be3 zgrep profile: allow executing /usr/bin/expr
expr is used for parsing commandline options in zgrep.

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1198531
2022-04-16 22:32:01 +02:00
Christian Boltz
3d27977b1c Merge profiles/apparmor.d: Add new profiles needed for samba-4.16
samba-4.16 has a completely new dcerpc subsystem, services that
used to be built into the smbd daemon itself (and deployed in forked
instances) are now hosted in standalone binaries. The following new
binaries now need new profiles

  rpcd_classic
  rpcd_epmapper
  rpcd_fsrvp
  rpcd_lsad
  rpcd_mdssvc
  rpcd_rpcecho
  rpcd_spoolss
  rpcd_winreg
  samba-dcerpcd

Additionally smbd & winbindd need new entries because the exec
samba-dcerpcd

Signed-off-by: Noel Power <noel.power@suse.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/871
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-04-15 12:52:19 +00:00
Noel Power
c785bcbe47 profiles/apparmor.d: Add new profiles needed for samba-4.16
samba-4.16 has a completely new dcerpc subsystem, services that
used to be built into the smbd daemon itself (and deployed in forked
instances) are now hosted in standalone binaries. The following new
binaries now need new profiles

  rpcd_classic
  rpcd_epmapper
  rpcd_fsrvp
  rpcd_lsad
  rpcd_mdssvc
  rpcd_rpcecho
  rpcd_spoolss
  rpcd_winreg
  samba-dcerpcd

Mostly these are captured in a single common profile 'samba-rpcd'

Additionally smbd & winbindd need new entries because they exec
samba-dcerpcd

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1198309

Signed-off-by: Noel Power <noel.power@suse.com>
2022-04-15 12:10:07 +01:00
John Johansen
41b4436710 Merge Add zgrep and xzgrep profile
This prevents exploiting https://www.openwall.com/lists/oss-security/2022/04/08/2
aka CVE-2022-1271 (file write and code execution via "funny" filenames)

I propose this addition for 3.0 and master.

(Tested on openSUSE Tumbleweed - tests on other distros welcome ;-)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/870
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2022-04-12 05:18:11 +00:00
John Johansen
52e82516d7 Merge add a common reload_profile() function to aa.py
This function is based on reload_profile() in tools.py, but also
replaces most of reload_base() in aa.py.

For bonus points, we get rid of shell=True when calling apparmor_parser.

Note: This slightly changes the behaviour of aa-logprof and aa-genprof -
if the parser errors out ($? > 0), the output no longer gets hidden.
However, this will not raise an exception, and aa-logprof and aa-genprof
won't abort on parser errors.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/855
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-04-12 05:17:50 +00:00
John Johansen
103603277a Merge sbin.rpc.statd: add hosts_access abstraction, /etc/nfs.conf{,.d/}
Observed these denials on an Ubuntu jammy system, when a user with an NFS homedir logs in:
```
Mar 29 06:57:14 darkstar kernel: [ 5988.206958] audit: type=1400 audit(1648551434.502:72): apparmor="DENIED" operation="open" profile="rpc.statd" name="/etc/nfs.conf" pid=3195 comm="rpc.statd" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Mar 29 06:57:14 darkstar kernel: [ 5988.207023] audit: type=1400 audit(1648551434.502:73): apparmor="DENIED" operation="open" profile="rpc.statd" name="/etc/nfs.conf.d/" pid=3195 comm="rpc.statd" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Mar 29 10:48:49 darkstar kernel: [19883.319957] audit: type=1400 audit(1648565329.710:74): apparmor="DENIED" operation="open" profile="rpc.statd" name="/etc/hosts.allow" pid=3196 comm="rpc.statd" requested_mask="r" denied_mask="r" fsuid=111 ouid=0
Mar 29 10:48:49 darkstar kernel: [19883.320016] audit: type=1400 audit(1648565329.710:75): apparmor="DENIED" operation="open" profile="rpc.statd" name="/etc/hosts.deny" pid=3196 comm="rpc.statd" requested_mask="r" denied_mask="r" fsuid=111 ouid=0
Mar 29 17:07:33 darkstar kernel: [  162.642366] audit: type=1400 audit(1648588053.026:72): apparmor="DENIED" operation="file_lock" profile="rpc.statd" name="/etc/nfs.conf" pid=1697 comm="rpc.statd" requested_mask="k" denied_mask="k" fsuid=0 ouid=0
```

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/866
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-04-12 05:16:23 +00:00
John Johansen
4537a5014b Merge profiles/apparmor.d/abstraction: Squash noisey setsockopt calls.
systemd will attempt to force socket buffer size using setsockopt
and param SO_SNDBUFFORCE (which require net_admin cap) if it's previous
attempt to set size was clipped by kernel limit.

- Silence 'type=AVC msg=audit(1648725005.727:201): apparmor="DENIED" operation="capable" profile="smbd" pid=3054 comm="smbd" capability=12  capname="net_admin"'

type entries.

Signed-off-by: Noel Power <noel.power@suse.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/867
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-04-12 05:14:24 +00:00
Christian Boltz
4c853dc74d Add zgrep and xzgrep profile
This prevents exploiting https://www.openwall.com/lists/oss-security/2022/04/08/2
aka CVE-2022-1271 (file write and code execution via "funny" filenames)
2022-04-12 00:04:22 +02:00
Christian Boltz
52b6b97c98 Merge dirtest.sh: error out on unexpected success
... if a test is expected to fail, but succeeds.

Also fix the copyright year - the test was created in 2022, not in 2013.

This fixes my comments on
bd78b6b292

The original MR !850 was merged into 3.0 and master, therefore I also propose this patch for 3.0 and master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/868
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-04-04 11:14:15 +00:00
Christian Boltz
2036f6fa9d dirtest.sh: error out on unexpected success
... if a test is expected to fail, but succeeds.

Also fix the copyright year - the test was created in 2022, not in 2013.

This fixes my comments on
bd78b6b292
2022-04-03 17:45:24 +02:00
Noel Power
90f97357af profiles/apparmor.d/abstraction: Squash noisey setsockopt calls.
systemd will attempt to force socket buffer size using setsockopt
and param SO_SNDBUFFORCE (which require net_admin cap) if it's previous
attempt to set size was clipped by kernel limit.

- Silence 'type=AVC msg=audit(1648725005.727:201): apparmor="DENIED" operation="capable" profile="smbd" pid=3054 comm="smbd" capability=12  capname="net_admin"'

type entries.

Signed-off-by: Noel Power <noel.power@suse.com>
2022-03-31 12:23:00 +01:00
Daniel Richard G
8e845c2e7f sbin.rpc.statd: add hosts_access abstraction, /etc/nfs.conf{,.d/}
Also update to use @{run}
2022-03-30 01:04:26 -04:00
Christian Boltz
83685ba703 Merge Allow dovecot to use all signals
similar to commit 2f9d172c64
we discovered that there was a service outage
when dovecot tried to send a usr1 signal

type=AVC msg=audit(1648024138.249:184964): apparmor="DENIED" operation="signal" profile="dovecot" pid=1690 comm="dovecot" requested_mask="send" denied_mask="send" signal=usr1 peer="dovecot-imap-login"

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/865
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-03-25 20:52:49 +00:00
Christian Boltz
ff9e457189 Merge abstractions/ssh_certs: extend pki/trust directories
- add pki/blacklist and pki/blocklist
- add /usr/share/pki/ in adddition to /etc/pki/

pki/blocklist was suggested by @darix, the other changes are things I noticed while adding it.

I propose this patch for 3.0 and master. (`abstractions/ssl_certs` on 2.x branches is quite different and needs a manual backport (or more cherry-picks) if you want to backport this MR.)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/864
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-03-23 20:34:02 +00:00
Bernhard M. Wiedemann
f0919f83f1 Allow dovecot to use all signals
similar to commit 2f9d172c64
we discovered that there was a service outage
when dovecot tried to send a usr1 signal

type=AVC msg=audit(1648024138.249:184964): apparmor="DENIED" operation="signal" profile="dovecot" pid=1690 comm="dovecot" requested_mask="send" denied_mask="send" signal=usr1 peer="dovecot-imap-login"
2022-03-23 14:27:13 +01:00
Christian Boltz
32cd90eb88 abstractions/ssh_certs: extend pki/trust directories
- add pki/blacklist and pki/blocklist
- add /usr/share/pki/ in adddition to /etc/pki/

pki/blocklist was suggested by @darix, the other changes are things I noticed while adding it.
2022-03-22 12:36:42 +01:00
Christian Boltz
e2319167d0 Merge profiles/apparmor.d: Fix read access denied on /proc/*/fd bsc#1196850
- Fix "type=AVC msg=audit(1646702374.347:182): apparmor="DENIED"
       operation="open" profile="samba-bgqd" name="/proc/1933/fd/"
       pid=1933 comm="samba-bgqd" requested_mask="r" denied_mask="r"
       fsuid=0 ouid=0"

entries appearing in SLE15-SP4

Signed-off-by: Noel Power <noel.power@suse.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/860
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-03-14 12:16:20 +00:00
Noel Power
6b83ba91c1 profiles/apparmor.d: Fix read access denied on /proc/*/fd bsc#1196850
- Fix "type=AVC msg=audit(1646702374.347:182): apparmor="DENIED"
       operation="open" profile="samba-bgqd" name="/proc/1933/fd/"
       pid=1933 comm="samba-bgqd" requested_mask="r" denied_mask="r"
       fsuid=0 ouid=0"

entries appearing in SLE15-SP4

Signed-off-by: Noel Power <noel.power@suse.com>
2022-03-14 10:30:03 +00:00
John Johansen
c3f64513f2 Merge smbd, samba-bgqd: allow reading openssl.cnf
References: https://bugzilla.opensuse.org/show_bug.cgi?id=1195463#c10

I propose this patch for 3.0 and master. (<= 2.13 don't have the samba-bgpd profile - if we want to backport to 2.x, we'll have to pick only the smbd part.)

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1195463#c10
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/862
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-03-13 15:05:46 +00:00
Christian Boltz
16444e9c29 smbd, samba-bgqd: allow reading openssl.cnf
References: https://bugzilla.opensuse.org/show_bug.cgi?id=1195463#c10
2022-03-13 11:24:35 +01:00
John Johansen
8f7768cd02 Merge abstractions/nss-systemd: Allow access for systemd-machined names
See downstream bug at
https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1964325

Signed-off-by: Alex Murray <alex.murray@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/861
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-03-10 04:07:56 +00:00
Alex Murray
9e260a8d79 abstractions/nss-systemd: Allow access for systemd-machined names
See downstream bug at
https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1964325

Signed-off-by: Alex Murray <alex.murray@canonical.com>
2022-03-10 11:57:13 +10:30
John Johansen
bd78b6b292 parser: dirtest that was supposed to be part of the previous commit
libapparmor: fix handling of failed symlink traversal, fixed a couple
of directory walk issues that could cause failures. The test included
in this commit was supposed to be included in the previous commit,
but was accidentally dropped. Even worse the make file changes did
make it causing the previous commit to break the CI.

Fixes: MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/85
Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-02-27 01:03:22 -08:00
John Johansen
acc6ba1cb7 libapparmor: fix handling of failed symlink traversal
Ideally we would have a flag or something so the caller could choose
to handle symlinks, or traverse them. But since all callers currently
don't handle symlinks just handle them in the iterator.

Beyond fixing the early termination due to a failed symlink this also
fixes another case of failure in one job cause dir based loads to
terminate early. Which can result in partial loads.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/215
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/850
Signed-off-by: John Johansen <john.johansen@canonical.com>
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-02-27 00:55:41 -08:00
John Johansen
6f18326232 Merge GTK abstraction: add support for gtk4.
The recently added gtk abstraction (!825) lack the support for the new gtk4.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/857
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2022-02-22 19:53:48 +00:00
Alexandre Pujol
8074ff4fd1 GTK abstraction: add support for gtk4. 2022-02-22 19:34:59 +00:00
Christian Boltz
7c725782a3 Merge aa-genprof: reduce and improve subprocess calls
Get rid of subprocess with shell=True

Simplify logmark used in syslog.

Instead of using `date | md5sum` and parsing the output to get the actual md5sum (without the stdin filename), use the current unixtime with a `logmark-` prefix.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/856
Acked-by: Seth Arnold <seth.arnold@gmail.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-02-21 22:10:27 +00:00
Christian Boltz
95d89dfbac Simplify logmark used in syslog
Instead of using `date | md5sum` and parsing the output to get the
actual md5sum (without the stdin filename), use the current unixtime
with a `logmark-` prefix.
2022-02-21 22:52:14 +01:00
Christian Boltz
c0734411ee aa-genprof: get rid of subprocess with shell=True 2022-02-21 22:43:29 +01:00
Christian Boltz
c6dabdf1e8 add a common reload_profile() function to aa.py
This function is based on reload_profile() in tools.py, but also
replaces most of reload_base() in aa.py.

For bonus points, we get rid of shell=True when calling apparmor_parser.

Note: This slightly changes the behaviour of aa-logprof and aa-genprof -
if the parser errors out ($? > 0), the output no longer gets hidden.
However, this will not raise an exception, and aa-logprof and aa-genprof
won't abort on parser errors.
2022-02-21 22:05:59 +01:00
John Johansen
6e5fdb5c05 Merge smbd: allow reading under /usr/share/samba
Today, a normal user connected and did something (dunno what) that caused smbd to try to `/usr/share/samba/mdssvc/elasticsearch_mappings.json`:

Samba logs:

```
root@smb:~# journalctl -b0 -u smbd
-- Logs begin at Fri 2022-01-21 14:17:01 UTC, end at Thu 2022-02-17 23:56:02 UTC. --
Feb 17 14:01:20 smb systemd[1]: Starting Samba SMB Daemon...
Feb 17 14:01:26 smb smbd[113]: [2022/02/17 14:01:26.904865,  0] ../../lib/util/become_daemon.c:135(daemon_ready)
Feb 17 14:01:26 smb systemd[1]: Started Samba SMB Daemon.
Feb 17 14:01:26 smb smbd[113]:   daemon_ready: daemon 'smbd' finished starting up and ready to serve connections
Feb 17 21:05:35 smb smbd[3084]: pam_unix(samba:session): session opened for user jdoe by (uid=0)
Feb 17 21:05:37 smb smbd[3084]: [2022/02/17 21:05:37.735182,  0] ../../source3/rpc_server/mdssvc/mdssvc_es.c:92(mdssvc_es_init)
Feb 17 21:05:37 smb smbd[3084]:   mdssvc_es_init: Opening mapping file [/usr/share/samba/mdssvc/elasticsearch_mappings.json] failed: unable to open /usr/share/samba/mdssvc/elasticsearch_mappings.json: Permission denied
Feb 17 21:05:37 smb smbd[3084]: [2022/02/17 21:05:37.735436,  0] ../../source3/rpc_server/mdssvc/mdssvc.c:1490(mdssvc_init)
Feb 17 21:05:37 smb smbd[3084]:   mdssvc_init: backend init failed
Feb 17 21:05:37 smb smbd[3084]: [2022/02/17 21:05:37.735562,  0] ../../source3/rpc_server/mdssvc/srv_mdssvc_nt.c:152(_mdssvc_open)
Feb 17 21:05:37 smb smbd[3084]:   _mdssvc_open: Couldn't create policy handle for partage
Feb 17 23:56:02 smb smbd[3084]: pam_unix(samba:session): session closed for user jdoe
```

Since the 'smb' machine is a container, the Apparmor denial ended up in the host's log:

```
$ journalctl -o cat --grep samba -k --since today | cat
audit: type=1400 audit(1645131937.730:98): apparmor="DENIED" operation="open" namespace="root//lxd-smb_<var-snap-lxd-common-lxd>" profile="smbd" name="/usr/share/samba/mdssvc/elasticsearch_mappings.json" pid=35359 comm="smbd" requested_mask="r" denied_mask="r" fsuid=166549 ouid=165536

```

It is the first time it occurs in years of use but it seems legitimate as:

1) this file is installed by the package
2) `git grep -F elasticsearch_mappings` in Debian samba's source shows many hits:
```
$ git grep -F elasticsearch_mappings
debian/samba.install:usr/share/samba/mdssvc/elasticsearch_mappings.json
docs-xml/manpages/mdsearch.1.xml:         <filename>/usr/share/samba/mdssvc/elasticsearch_mappings.json</filename>
docs-xml/smbdotconf/misc/elasticsearchmappings.xml:  <value type="default">&pathconfig.SAMBA_DATADIR;/elasticsearch_mappings.json</value>
docs/manpages/mdfind.1:/usr/share/samba/mdssvc/elasticsearch_mappings\&.json
docs/manpages/smb.conf.5:\fI\fIelasticsearch:mappings\fR\fR\fI = \fR\fI${prefix}/var/samba/elasticsearch_mappings\&.json\fR\fI \fR
selftest/selftest.pl:   elasticsearch:mappings = $srcdir_abs/source3/rpc_server/mdssvc/elasticsearch_mappings.json
selftest/target/Samba3.pm:      elasticsearch:mappings = $srcdir_abs/source3/rpc_server/mdssvc/elasticsearch_mappings.json
source3/rpc_server/mdssvc/es_parser_test.c:             "%s/mdssvc/elasticsearch_mappings.json",
source3/rpc_server/mdssvc/mdssvc_es.c:          "%s/mdssvc/elasticsearch_mappings.json",
source3/rpc_server/wscript_build:                          'mdssvc/elasticsearch_mappings.json')
```

While only the `mdssvc` sub-dir could be authorized, the whole dir content seemed OK for read access anyway:

```
root@smb:~# ll /usr/share/samba/
total 53
drwxr-xr-x  5 root root   10 Feb  1 14:08 ./
drwxr-xr-x 67 root root   67 Jun 22  2021 ../
-rwxr-xr-x  1 root root 1163 Jan 31 13:11 addshare.py*
drwxr-xr-x  3 root root    4 Feb  1 14:08 admx/
drwxr-xr-x  2 root root    3 Feb  1 14:08 mdssvc/
-rwxr-xr-x  1 root root 2059 Jan 31 13:11 panic-action*
-rwxr-xr-x  1 root root 1333 Jan 31 13:11 setoption.py*
drwxr-xr-x  5 root root   57 Feb  1 14:08 setup/
-rw-r--r--  1 root root 8942 Jan 31 13:11 smb.conf
-rwxr-xr-x  1 root root 2682 Jan 31 13:11 update-apparmor-samba-profile*
```

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/853
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-02-21 20:04:49 +00:00
John Johansen
40402e2436 Merge Revert "gitlab: testing: temporarily disable secret-detect"
It appears secret detection is failing if the master branch in the tree a merge request is being made from is too (some unknown value) far behind the branch of the tree it is being merged into.

This is problematic as it is not started practice to refresh the upstream branches of forked trees, but to keep multiple remotes in a single local tree, branch from mainline master, work on the branch and push to the fork for the merge request. This will require contributors to refresh their forked trees in secret-detection fails. Which may be problematic for some contributors, but since we don't know how bad this is going to be, for now re-enable secret detection.

This reverts commit 8b4344c17b.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/854
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: John Johansen <john@jjmx.net>
2022-02-21 19:58:36 +00:00
John Johansen
51615755f8 Revert "gitlab: testing: temporarily disable secret-detect"
This reverts commit 8b4344c17b.
2022-02-21 11:31:44 -08:00
John Johansen
8b4344c17b gitlab: testing: temporarily disable secret-detect
Unfortunately secret detection is failing with
   fatal: error in object: unshallow sha1

and blocking merge requests. Unfortuntely all suggested work arounds
from https://gitlab.com/gitlab-org/gitlab/-/issues/351976 failed to
work.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-02-18 00:19:31 -08:00
Simon Deziel
9e0adcfd07 smbd: allow reading under /usr/share/samba
Signed-off-by: Simon Deziel <simon@sdeziel.info>
2022-02-17 18:54:54 -05:00
Georgia Garcia
5001431cdf Merge parser: fix building with link time optimization (lto)
Libapparmor was fixed for lto builds on commit 7cde91f5 but
the parser was also failing due to the same reasons when lto
was enabled.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/214
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

Closes #214
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/851
Acked-by: Approved-by: John Johansen <john@jjmx.net>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-02-17 17:09:13 +00:00
John Johansen
6fa2d528e9 Merge Update apache2-common so that other processes can trace the hats that include...
Update apache2-common so that other processes can trace the hats that include this file. The main `usr.sbin.apache2` profile includes `abstractions/base` which has these lines in it, which is why `ss -tnlp` sometimes fails and sometimes works.

See also: [Debian Bug #1003153](https://bugs.debian.org/1003153) for more details about how this occurs.

Fixes: https://bugs.debian.org/1003153
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/852
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-02-17 09:16:20 +00:00
Craig Small
071935b914 Update apache2-common so that other processes can trace the hats that include this file. The main includes abstractions/base which has these lines in it, which is why ss -tnlp sometimes fails.
See also: https://bugs.debian.org/1003153 for more details about how this occurs.
2022-02-17 07:57:55 +00:00
Georgia Garcia
b6d3daa715 parser: fix building with link time optimization (lto)
Libapparmor was fixed for lto builds on commit 7cde91f5 but
the parser was also failing due to the same reasons when lto
was enabled.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/214
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-02-16 20:49:42 -03:00
John Johansen
e71e27c574 Merge smbd: include snippet generated at runtime on Debian and openSUSE
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/838
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-02-15 21:29:02 +00:00
Christian Boltz
19abc66425 smbd: include snippet generated at runtime on openSUSE 2022-02-15 21:52:15 +01:00
John Johansen
ba14227bb5 Merge make test-aa-notify test_help_contents () less strict
Python 3.10 generates a slightly different --help output.

Fixes https://gitlab.com/apparmor/apparmor/-/issues/220

Closes #220
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/848
Acked-by: Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-02-15 19:17:30 +00:00
Christian Boltz
39f4132ab9 make test-aa-notify test_help_contents () less strict
Python 3.10 generates a slightly different --help output.

Fixes https://gitlab.com/apparmor/apparmor/-/issues/220
2022-02-15 19:39:32 +01:00
John Johansen
583e1905e9 Merge profile-load: use safer and less ambiguous shell constructs
Thanks to @cboltz for noticing this on https://gitlab.com/apparmor/apparmor/-/merge_requests/841#note_842436025.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/849
Acked-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-02-15 08:16:38 +00:00
intrigeri
322b3f4d3e profile-load: use less ambiguous if/then construct
As shellcheck taught me
today (https://github.com/koalaman/shellcheck/wiki/SC2015),
"A && B || C is not if-then-else. C may run when A is true".

It does not matter here in practice, because worst case we would run "true" once
too many, but still.
2022-02-15 07:34:17 +00:00
intrigeri
35f23a6da1 profile-load: use safer "read" construct
In this case it does not matter, we're merely testing if we can actually
read from that file, but let's make this robust (and shellcheck happy)
for future's sake.

Reference: https://www.shellcheck.net/wiki/SC2162
2022-02-15 07:28:27 +00:00
John Johansen
5a41024bbe Merge Make the systemd unit a no-op in containers with no internal policy
In 73e124d4fb I've upstreamed the `is_container_with_internal_policy()` function, but so far it was not used anywhere upstream. This is the missing bit.

I could trace the history of that patch back to 2012 (2.7.102-0ubuntu3):

    * debian/apparmor.init: do nothing in a container.  This can be
      removed once stacked profiles are supported and used by lxc.
      (LP: #978297)

Context: I lack both knowledge and motivation to keep maintaining this as part of the Debian delta. I'd rather see upstream, and in particular folks more knowledgeable than me about LXC/LXD, or with external motivation factors to work on this part of the stack, take care of it.

Note: Debian has similar code in its [sysvinit script](https://salsa.debian.org/apparmor-team/apparmor/-/blob/debian/master/debian/apparmor.init). I'm not touching that one.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/840
Acked-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-02-14 22:11:28 +00:00
John Johansen
26b7ddee36 Merge Allow access to socket directory used by recent ibus-daemon
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/837
Acked-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-02-14 22:07:19 +00:00
John Johansen
4300953dc8 Merge CI: enable Secret-Detection and a few SAST analyzers
This MR depends on !843, mostly for convenience and to avoid having to rework it once !843 is merged. If this turns out to be a blocker, I can rebase it `--onto` master.

It's based on the draft from !584 and !716, but on top of copying'n'pasting the examples from the GitLab documentation, which was necessary but not sufficient, in this MR I tried my best to make these features work in our context: it actually passes CI, it does not clutter the CI UI with jobs that are not applicable here, and it yields a manageable amount of output (as opposed to hundreds of "OMG you're using format strings", that I don't think any of us is going to triage one by one any time soon).

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/844
Acked-by: Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-02-14 08:38:33 +00:00
John Johansen
6f0e361c8e Merge CI: parallelize across multiple jobs, only install necessary dependencies
This makes the pipeline run time about 30% shorter and, perhaps more importantly, this gives us more direct access to test failures: they are not hidden in the middle of the huge `test-all` log anymore.

As a bonus, this gives us much faster feedback for tests with a short duration.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/843
Acked-by: Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-02-14 08:17:47 +00:00
John Johansen
6a54d59172 Merge Import profile-load script from Debian
This script is used at least by LXC upstream and MySQL in Debian:
https://codesearch.debian.net/search?q=%2Flib%2Fapparmor%2Fprofile-load

Presumably it could be useful elsewhere if it was more readily available.

Similarly to !840, this is another user of the `is_container_with_internal_policy()` function. I'd like all the callers of this function to live in harmony under the same roof, upstream.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/841
Acked-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-02-14 06:23:51 +00:00
John Johansen
046442741f Merge Add .desktop file for aa-notify
This allows distributions to start aa-notify automatically, should they wish so, by installing that file in a suitable location, such as `/etc/xdg/autostart`.

This file was introduced in Ubuntu 2.8.95~2430-0ubuntu3 package in 2014, replacing the `/etc/X11/Xsession.d` snippet that Ubuntu had added in 2010.

I'd like to stop having to care about this file as part of the Debian delta and to enable greater collaboration.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/839
Acked-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-02-14 06:21:22 +00:00
Christian Boltz
1bb684b474 Merge shellcheck: skip files generated during libapparmor build
libtool generates horrible shell code, you don't want to see the
shellcheck results for it ;-)

This is only relevant for local testing (not in CI) because these files
don't exist in git and therefore don't exist when the shellcheck CI job
runs.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/847
Acked-by: Approved-by: intrigeri <intrigeri@boum.org>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-02-13 21:21:37 +00:00
intrigeri
bf4134e705 Provide examples of how to disable a Bandit SAST analyzer warning 2022-02-13 21:05:54 +00:00
intrigeri
8c8965a720 CI: don't run the Bandit SAST analyzer on our test suites
Let's focus for now on code that runs on our users' systems.
2022-02-13 21:05:54 +00:00
intrigeri
086fb04f21 CI: disable SemGrep SAST analyzer
It runs the flawfinder checks, so let's disable this one for the same reason
we disabled flawfinder.
2022-02-13 21:05:54 +00:00
intrigeri
9bbbcd8447 CI: disable ESLint SAST analyzer
We have no JavaScript code, let's make the GitLab CI user interface leaner.
2022-02-13 21:05:54 +00:00
intrigeri
8655cf162a CI: disable flawfinder SAST analyzer
It reports hundreds of issues, lots of them with critical severity.
The GitLab UI allows dismissing them one-by-one very quickly,
but I'm not a good person to do that.
Let's try to have a better signal/noise ratio for this first iteration.
2022-02-13 21:05:54 +00:00
intrigeri
9240e12e73 CI: disable Dependency Scanning
According to
https://docs.gitlab.com/ee/user/application_security/dependency_scanning/,
"dependency scanning lets you know if your application uses an external (open
source) library that is known to be vulnerable".

AppArmor is not the kind of project that benefits from it: we don't link
statically against our dependencies, nor bundle them into released
artifacts.
2022-02-13 21:05:54 +00:00
intrigeri
7d69e55074 CI: disable spotbugs SAST analyzer
It requires building our Ant projects, which have not been touched in years.
2022-02-13 21:05:54 +00:00
intrigeri
9f8c0d25e3 CI: only run Debian'ish commands on jobs run on Debian'ish systems 2022-02-13 21:05:52 +00:00
Eric Rosenberg
2a7bd3aa9e CI: enable SAST, Secret-Detection, and Dependency Scanning 2022-02-13 21:04:18 +00:00
intrigeri
099f99a395 CI: ensure test-utils runs all intended tests 2022-02-13 21:02:58 +00:00
intrigeri
368625a9d3 utils/test/README.md: document not-totally-obvious cross-tree semi-dependency
Thanks to @cboltz for the explanation.
2022-02-13 21:02:58 +00:00
intrigeri
f0ff344e2a CI: normalize indentation 2022-02-13 21:02:58 +00:00
intrigeri
694b3348da CI: parallelize across multiple jobs, only install necessary dependencies 2022-02-13 21:02:56 +00:00
intrigeri
3c1163825b CI: don't install unneeded python-all-dev (Python 2) 2022-02-13 21:01:24 +00:00
Christian Boltz
6ae7b1566c shellcheck: skip files generated during libapparmor build
libtool generates horrible shell code, you don't want to see the
shellcheck results for it ;-)

This is only relevant for local testing (not in CI) because these files
don't exist in git and therefore don't exist when the shellcheck CI job
runs.
2022-02-13 21:41:54 +01:00
Christian Boltz
73c24a8b12 Merge Lint shell code and add shellcheck CI job
This should avoid unconsciously introducing regressions wrt. best practices for shell code.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/842
Acked-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-02-13 20:06:55 +00:00
intrigeri
56dd267a24 Mark variables as dummy in a way that shellcheck 0.7.0 supports
The "_" prefix is only supported in shellcheck > 0.7.2.
2022-02-13 19:43:48 +00:00
intrigeri
529d386775 CI: enable all shellcheck severity levels
The few previous commits make this pass, let's profit.
2022-02-13 19:43:48 +00:00
intrigeri
6db9ebfd15 aa-decode: "fix" all remaining shellcheck style violations 2022-02-13 19:43:48 +00:00
intrigeri
985f9ca788 CI: set shellcheck minimum severity to info
The few previous commits make this pass, let's profit.
2022-02-13 19:43:48 +00:00
intrigeri
825f761c77 aa-decode, aa-remove-unknown: fix remaining shellcheck info-level violations
For details, see:

- https://www.shellcheck.net/wiki/SC2086
- https://www.shellcheck.net/wiki/SC2162
2022-02-13 19:43:48 +00:00
intrigeri
e55a9b3735 CI: set shellcheck minimum severity to warning
The few previous commits make this pass, let's profit.
2022-02-13 19:43:48 +00:00
intrigeri
af76d98fce utils/test/: drop support for running with Python 2 2022-02-13 19:43:48 +00:00
intrigeri
8d219e1f31 aa-remove-unknown: mark dummy variable as such
For details, see https://www.shellcheck.net/wiki/SC2034.
2022-02-13 19:43:48 +00:00
intrigeri
cfcc271b3c aa-remove-unknown: prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
For details, see https://www.shellcheck.net/wiki/SC2166.
2022-02-13 19:43:48 +00:00
intrigeri
804e8f94a6 CI: prepare for enabling shellcheck warnings and info
- Assume /bin/sh has dash's features and ignore corresponding false positives

- Exclude parser/tst, tests and utils/test directories: they have tons
  of shellcheck violations but they don't *directly* impact our users.
  Let's first focus on code that runs on production systems.

- Exclude rc.apparmor.slackware: I don't know anything about Slackware's
  /bin/sh.
2022-02-13 19:43:48 +00:00
intrigeri
5a6f6c2fc8 CI: add shellcheck job, with minimum severity set to error
We have way too many warnings to enable lower severity levels,
but let's at least we don't introduce new errors.
2022-02-13 19:43:48 +00:00
intrigeri
398f584710 Test suite: don't use fragile "-e with globs" construction
For details, see https://github.com/koalaman/shellcheck/wiki/SC2144.
2022-02-13 19:43:48 +00:00
intrigeri
14d35c651c Test suite: don't use fragile shell construct mixing string and array
The previous code happened to work only because we always pass either 0 or 1
arguments to these functions. If we ever passed them 2+ arguments,
unexpected things would happen.

For details, see https://www.shellcheck.net/wiki/SC2145
2022-02-13 19:43:48 +00:00
intrigeri
fb94661937 rc.apparmor.functions: mark intentionally unused variable as dummy
Thanks, shellcheck!
2022-02-13 19:43:48 +00:00
intrigeri
2e0fb86a94 rc.apparmor.functions: check command exit status directly
Thanks, shellcheck!
2022-02-13 19:43:48 +00:00
intrigeri
0bae8bf82a rc.apparmor.functions: disable shellcheck false positive 2022-02-13 19:43:48 +00:00
intrigeri
8eeb8c48c5 rc.apparmor.functions: quote to prevent word splitting and syntax error on empty output
Thanks, shellcheck!
2022-02-13 19:43:48 +00:00
Christian Boltz
0f194ca1a0 Merge Remove unused init scripts, minor improvement to Slackware init script output
Based on !418, where all these changes have been discussed already.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/845
Acked-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-02-13 18:39:23 +00:00
Christian Boltz
a744564fa4 Merge Drop superfluous shebang from python module
Found by rpmlint.

I propose this fix for 3.0 and master to keep the file in sync.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/846
Acked-by: Approved-by: intrigeri <intrigeri@boum.org> for 3.0 and master
Merged-by: Christian Boltz <gitlab2@cboltz.de>
2022-02-13 18:34:56 +00:00
Christian Boltz
749234f5a1 Drop superfluous shebang from python module
Found by rpmlint.
2022-02-13 18:29:34 +01:00
intrigeri
2019519e34 Delete Red Hat initscript
Even if there are Red Hat / Fedora systems that use AppArmor, chances are that
they use systemd, and not an initscript. And even if somehow they do use an
initscript, chances are that it's not this one, as last time it has seen
a non-cosmetic change was in 2007.
2022-02-13 16:53:44 +00:00
Chris Novakovic
7f64db1f19 Display improvements in rc.apparmor.functions
* Don't call aa_log_action_end after calling aa_log_failure_msg, because
  a generic "failure" message will be outputted twice by the Red Hat and
  Slackware init scripts.
* Don't append a space to the initial output from apparmor_stop, in line
  with other usages of aa_log_daemon_msg.
2022-02-13 16:53:27 +00:00
Chris Novakovic
2f2eab3b21 Remove Debian init script
Debian doesn't use the init script provided in parser/rc.apparmor.debian,
instead preferring to patch parser/rc.apparmor.functions and call its
functions directly in an init script they maintain themselves (something
they have done since 2006). Since this script is no longer used, and
currently doesn't work correctly anyway because it lacks definitions for
several functions that are relied upon in parser/rc.apparmor.functions,
it can be removed.
2022-02-13 16:53:22 +00:00
intrigeri
c7e68d7009 Import profile-load script from Debian
This script is used at least by LXC upstream and MySQL in Debian:
https://codesearch.debian.net/search?q=%2Flib%2Fapparmor%2Fprofile-load

Presumably it could be useful elsewhere if it was more readily available.
2022-02-12 10:34:38 +00:00
intrigeri
c44e93d856 Make the systemd unit a no-op in containers with no internal policy 2022-02-12 10:23:39 +00:00
intrigeri
bd06a9d214 Add .desktop file for aa-notify
This allows distributions to start aa-notify automatically,
should they wish so.
2022-02-12 09:34:26 +00:00
Jamie Strandboge
9505724d72 Allow access to socket directory used by recent ibus-daemon 2022-02-12 08:38:23 +00:00
intrigeri
9af832f48a smbd: include snippet generated at runtime on Debian 2022-02-12 08:36:10 +00:00
John Johansen
fb35ee4efc Merge aa-remove-unknown: abort on parser failure
If `apparmor_parser -N` (in `profiles_names_list()`) fails,
`aa-remove-unknown` possibly gets an incomplete list of profiles in
`/etc/apparmor.d/` and therefore might remove more profiles than it
should.

Replace the `profiles_names_list()` call with a direct `apparmor_parser`
call, and abort aa-remove-unknown if it exits with $? != 0

Before:
```
aa-remove-unknown -n
AppArmor parser error for /etc/apparmor.d/broken in profile /etc/apparmor.d/broken at line 1: syntax error, unexpected TOK_ID, expecting TOK_OPEN
Would remove 'delete_me'
```

After:
```
./aa-remove-unknown -n
AppArmor parser error for /etc/apparmor.d in profile /etc/apparmor.d/zbroken at line 1: syntax error, unexpected TOK_ID, expecting TOK_OPEN
apparmor_parser exited with failure, aborting.
```

And of course, after fixing the broken profile:
```
./aa-remove-unknown -n
Would remove 'delete_me'
```

Also drop the now-unused profiles_names_list() from rc.apparmor.functions - the only user was aa-remove-unknown.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/836
Acked-by:  John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-02-11 22:55:41 +00:00
Christian Boltz
db0a8aacd5 Drop now-unused profiles_names_list() from rc.apparmor.functions
The only user was aa-remove-unknown - until the previous commit.
2022-02-11 22:59:01 +01:00
Christian Boltz
5053a01d84 aa-remove-unknown: abort on parser failure
If apparmor_parser -N (in profiles_names_list()) fails,
aa-remove-unknown possibly gets an incomplete list of profiles in
/etc/apparmor.d/ and therefore might remove more profiles than it
should.

Replace the profiles_names_list() call with a direct apparmor_parser
call, and abort aa-remove-unknown if it exits with $? != 0

Before:
```
aa-remove-unknown -n
AppArmor parser error for /etc/apparmor.d/broken in profile /etc/apparmor.d/broken at line 1: syntax error, unexpected TOK_ID, expecting TOK_OPEN
Would remove 'delete_me'
```

After:
```
./aa-remove-unknown -n
AppArmor parser error for /etc/apparmor.d in profile /etc/apparmor.d/zbroken at line 1: syntax error, unexpected TOK_ID, expecting TOK_OPEN
apparmor_parser exited with failure, aborting.
```

And of course, after fixing the broken profile:
```
./aa-remove-unknown -n
Would remove 'delete_me'
```
2022-02-11 22:59:01 +01:00
John Johansen
e726ebe376 Merge Drop unused failstop_system() from rc.apparmor.functions
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/835
Acked-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-02-11 08:28:07 +00:00
John Johansen
872747f173 Merge Simplify profiles_names_list()
... which is used by aa-remove-unknown.

apparmor_parser can read a whole directory, therefore we don't need to
do the directory listing, excluding *.rpmnew etc. ourself.

Also drop the now-unused skip_profile()

Related to https://gitlab.com/apparmor/apparmor/-/issues/148

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/834
Acked-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-02-11 08:27:07 +00:00
Christian Boltz
8e1a4924d5 Drop unused failstop_system() from rc.apparmor.functions 2022-02-10 23:45:20 +01:00
John Johansen
2ba5575f7b libapparmor: sync library version change with the 3.0.4 release
Library versioning requires we keep these changes in sync. Since the
3.0.4 release bumped revision we need to do it here as well.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-02-10 14:20:06 -08:00
Christian Boltz
8476786252 Drop skip_profile()
Its last user was profiles_names_list(), but since the previous commit
it lets apparmor_parser do this job.

Related to https://gitlab.com/apparmor/apparmor/-/issues/148
2022-02-10 22:56:16 +01:00
Christian Boltz
d38376c9c4 Simplify profiles_names_list()
... which is used by aa-remove-unknown.

apparmor_parser can read a whole directory, therefore we don't need to
do the directory listing, excluding *.rpmnew etc. ourself.

Related to https://gitlab.com/apparmor/apparmor/-/issues/148
2022-02-10 22:53:48 +01:00
John Johansen
9aa1a5b492 Merge Drop now-obsolete comment about skip_profile()
... which became superfluous after dropping use of xargs as fallback
when loading profiles in 0b8ea047e8

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/833
Acked-by: Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2022-02-09 18:32:44 +00:00
Christian Boltz
5527c20833 Drop now-obsolete comment about skip_profile()
... which became superfluous after dropping use of xargs as fallback
when loading profiles in 0b8ea047e8
2022-02-09 18:32:51 +01:00
John Johansen
5041a6235a Merge Add 'mctp' network domain keyword
Reported as comment on https://build.opensuse.org/request/show/951354
(update to glibc 2.35)

I propose this patch for at least 3.0 and master. Backporting it to older releases can't hurt, even if seeing a new-enough glibc or kernel with them is less likely.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/832
Acked-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-02-08 18:20:59 +00:00
Christian Boltz
977af8c5ac Add 'mctp' network domain keyword
Reported as comment on https://build.opensuse.org/request/show/951354
(update to glibc 2.35)
2022-02-08 19:09:24 +01:00
John Johansen
7cde91f57f libapparmor: fix building with link time optimization (lto)
Currently libapparmor fails to build when lto is used because it uses
the asm directive to provide different version of some symbols.
Unfortunately gcc does not recognize this and the symbols defined by
asm are lost and optimized out by lto and then the link fails.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/214
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/831
Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-02-04 15:01:36 -08:00
John Johansen
72c06c4d35 Merge Enable AppArmor to run properly under WSL/systemd
The AppArmor systemd scripts correctly detect the Windows Subsystem for Linux as a container, since all Linux distros executing under WSL 2 are containerized; however, unlike the majority of containers (since there is no accessible host distribution above them trying to set AppArmor policies that might interfere), AppArmor itself functions without problems in the WSL environment.

This patch adds WSL detection to the is_container_with_internal_policy function, allowing AppArmor to be started and operate normally in a WSL-plus-systemd environment.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/812
Acked-by: John Johansen <john@jjmx.net>
2022-02-04 10:25:14 +00:00
John Johansen
0b8ea047e8 rc.apparmor: drop use of xargs as fallback when loading profiles
LP:1377338 <https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1377338>

has been fixed for quite awhile and we don't need to call xargs as
a fallback when loading policy fails.

In addition we really don't want to be doing this because we want to
be moving to atomic profile loads where if one profile fails the
whole load fails. This is a step in that direction.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2022-02-04 02:22:39 -08:00
John Johansen
08f32ac703 Merge Fix: Opening links with Chrome
Permission denied when Evince tries to use Chrome to open link.

In config is missing the bin: `/opt/google/chrome/crashpad_handler`.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/830
Acked-by: John Johansen <john@jjmx.net>
2022-02-04 10:14:31 +00:00
Cristiano Nunes
f0d3d6748f Fix: Opening links with Chrome 2022-02-03 09:42:36 -03:00
Georgia Garcia
64703c7158 Merge tests: add attach_disconnected tests
This test uses unix_fd_server to open a file and pass
its file descriptor to the attach_disconnected tests, which
then mounts, pivots root and then tries to open the file.

Since the server execs the client, this MR also inverts the order
of the parameters to allow the server to forward the client's args
along with the unix_socket path.

I'm also refactoring out the unix_fd_client logic into unix_fd_common,
so we can use this implementation when creating other clients, which is the case
for the test binary attach_disconnected

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/810
Acked-by: Approved-by: John Johansen <john@jjmx.net>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-01-27 13:48:18 +00:00
Georgia Garcia
cb4a397b1e tests: add attach_disconnected tests
This test uses unix_fd_server to open a file and pass
its file descriptor to the attach_disconnected tests, which
then mounts, pivots root and then tries to open the file.

Since the server execs the client, this commit also inverts the order
of the parameters to allow the server to forward the client's args
along with the unix_socket path.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/810
Acked-by: John Johansen <john.johansen@canonical.com>
2022-01-27 10:36:14 -03:00
Georgia Garcia
b07a532a6f unix_fd_common tests: refactor out unix_fd_client code into common
The code from unix_fd_client can be used by other clients which
will receive the fd of a file using SCM rights.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/810
Acked-by: John Johansen <john.johansen@canonical.com>
2022-01-27 10:35:29 -03:00
John Johansen
a19ff53674 Merge tests: disable file query test for kernels that don't provide the query feature
The file query test on query_label.sh fails on kernels
before 4.4 because of the lack of support. Since there
is no feature file to examine for this feature, we
needed to check for the kernel version. Refer to [qa-regression-testing](https://git.launchpad.net/qa-regression-testing/tree/scripts/test-apparmor.py#n1653).

As discussed on !767, we might need a more complicated test than
only checking for the kernel version, since this feature might
be available in out-of-tree Ubuntu kernels such as saucy (3.13).

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/769
Acked-by: John Johansen <john@jjmx.net>
2022-01-27 08:38:46 +00:00
John Johansen
d9afe25a0d Merge 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>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/806
Acked-by: John Johansen <john@jjmx.net>
2022-01-27 08:35:05 +00:00
John Johansen
c67681a5a9 Merge Add the GTK abstraction
GTK/QT apps need to read some config files in order to properly render their windows in a graphical session. There are some `qt5` abstractions already, but it looks like the `gtk` abstraction is missing.

The `*gtk*` rules are basically the location of the GTK config files I found on the internet when I was trying to compose this abstraction. Some of the paths are missing in Debian, but different distros can use (or were using) them. Since GTK apps use themes, the abstraction also include the whole `/usr/share/themes/` , `@{HOME}/.themes/` and `@{HOME}/.local/share/themes/` dirs. I'm not sure whether this should be tightened. The `.Xauthority` file is generally needed when you deal with GUI apps under Xserver. Also since all GUI apps redirect output/error to the `~/.xsession-errors` file, this file also was included here.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/65
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/168
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/825
Acked-by: John Johansen <john.johansen@canonical.com>
2022-01-27 08:23:59 +00:00
John Johansen
6154925c62 Merge tests: add built test files to gitignore
The following files generated during the build were not ignored by git: aa_policy_cache at_secure dbus_common.o dbus_eavesdrop dbus_message dbus_service dbus_unrequested_reply fd_inheritance fd_inheritor introspect pivot_root query_label socketpair syscall_ioperm syscall_iopl transition unix_socket unix_socket_client unix_socket_common.o uservars.inc xattrs_profile

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/826
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2022-01-27 08:19:27 +00:00
John Johansen
1ca30e35b0 libapparmor: Fix ruby 3.1 build for libapparmor
The Hack used to build the libapparmor swig interface for ruby fails
with ruby 3.1.  Instead of trying to do black magic in ruby to rename
the generated Makefile to Makefile.new, just save off the Makefile
and restore after ruby's setup has been called.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/206
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2022-01-26 23:12:27 -08:00
John Johansen
0e52b555ae Merge init: make xargs invocation busybox-compatible
busybox xargs does not have -d nor long --max-procs options, instead use -0 (and separate arguments with printf "%s\\0") and -P which are more portable. While we are here, also add -r (--no-run-if-empty, which also has no long equivalent for busybox) as we likely don't want to run anything if no profile were found

This is useful for alpine systems where findutils is not installed by default, but busybox xargs is available.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/828
Acked-by: John Johansen <john.johansen@canoical.com>
2022-01-27 03:23:50 +00:00
Dominique Martinet
76163f801d init: make xargs invocation busybox-compatible
busybox xargs does not have -d nor long --max-procs options,
instead use -0 (and separate arguments with printf "%s\0")
and -P which are more portable.
While we are here, also add -r (--no-run-if-empty, which also has
no long equivalent for busybox) as we likely don't want to run
anything if no profile were found

This is useful for alpine systems where findutils is not installed by
default, but busybox xargs is available.
2022-01-27 11:48:05 +09:00
Georgia Garcia
c0ee4a9a8a tests: add built test files to gitignore
The following files generated during the build were not ignored by git:
  aa_policy_cache
  at_secure
  dbus_common.o
  dbus_eavesdrop
  dbus_message
  dbus_service
  dbus_unrequested_reply
  fd_inheritance
  fd_inheritor
  introspect
  pivot_root
  query_label
  socketpair
  syscall_ioperm
  syscall_iopl
  transition
  unix_socket
  unix_socket_client
  unix_socket_common.o
  uservars.inc
  xattrs_profile

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-01-26 11:00:41 -03:00
Mikhail Morfikov
93d49a3945 add the GTK abstraction 2022-01-21 18:37:22 +01:00
John Johansen
457ab38b93 aa-status: fix crash due to \n in profile name
This fixes a crash when a profile name contains a \n character which
breaks profile name parsing. The fix is minimal in that it ignores
the bad profile name and continues processing.

Ideally this name would not exist and is indicative of a bug in the kernel.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/211
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/824
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2022-01-20 13:40:02 -08:00
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
Steve Beattie
4559a2997c utils: Add new python versions to logprof.conf
Adding everything up to 3.19 should make the file future-proof for a
while ;-)

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/193
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/795
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2021-08-26 17:43:43 +00:00
Georgia Garcia
c8ff8799cc Merge cleanup imports from apparmor.common
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/794
Acked-by: Georgia Garcia <georgia.garcia@canonical.com>
2021-08-25 21:58:08 +00:00
Christian Boltz
b570e6134c Add new python versions to logprof.conf
Adding everything up to 3.19 should make the file future-proof for a
while ;-)

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/193
2021-08-25 13:50:28 +02:00
Christian Boltz
0ee225b498 import hasher from apparmor.common
... instead of indirectly using it via apparmor.aa
2021-08-24 22:48:19 +02:00
Christian Boltz
c09e0b6ef3 import is_skippable_file from apparmor.common
... instead of indirectly using it via apparmor.aa
2021-08-24 22:47:39 +02:00
Christian Boltz
8b2fe01c7d aa-easyprof: use AppArmorException from apparmor.common
... instead of keeping an own version of it witht the exact same code
and a TODO note to use the one from common.

Also adjust the aa-easyprof tests to directly import AppArmorException
from apparmor.common.
2021-08-24 22:35:59 +02:00
Christian Boltz
79e7a204cf import AppArmorException from apparmor.common
... instead of indirectly using the one imported into apparmor.aa
2021-08-24 22:31:11 +02:00
Christian Boltz
7f64902f24 aa-unconfined: import specific items from apparmor.common
... instead of importing the whole apparmor.common
2021-08-24 22:20:27 +02:00
John Johansen
7711baae4a Merge aa-decode: use grep -E instead of egrep
egrep and fgrep are deprecated and will print a warning in the next grep release (3.8)

https://git.savannah.gnu.org/cgit/grep.git/commit/?id=a9515624709865d480e3142fd959bccd1c9372d1

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/792
Acked-by: John Johansen <john.johansen@canonical.com>
2021-08-24 08:29:04 +00:00
John Johansen
c258976ff8 Merge utils: use internal which implementation
* removes runtime dependency on which
* fixes aa-unconfined when ss is installed outside {/usr,}/bin

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/784
Signed-off-by: Michal Vasilek <michal.vasilek@nic.cz>
Acked-by: John Johansen <john.johansen@canonical.com>
2021-08-24 08:23:29 +00:00
Michal Vasilek
e8f3a1b878 aa-decode: use grep -E instead of egrep
egrep and fgrep are deprecated and will print a warning in the next grep
release (3.8)

https://git.savannah.gnu.org/cgit/grep.git/commit/?id=a9515624709865d480e3142fd959bccd1c9372d1
Signed-off-by: Michal Vasilek <michal.vasilek@nic.cz>
2021-08-24 10:16:29 +02:00
Michal Vasilek
c31d49234f utils: use internal which implementation
* removes runtime dependency on which
* fixes aa-unconfined when ss is installed outside {/usr,}/bin

Signed-off-by: Michal Vasilek <michal.vasilek@nic.cz>
2021-08-24 09:29:32 +02:00
John Johansen
1a190f2e30 Merge aa-remove-unknown: Drop superfluous $0 parameter from usage()
$0 is always the name of the script, even if using it inside a function.
Therefore use $0 directly, and no longer hand it over as a parameter.

Also `chmod +x aa-remove-unknown` to make in-tree testing easier.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/785
Acked-by: John Johansen <john.johansen@canonical.com>
2021-08-21 07:43:49 +00:00
John Johansen
5068f54cf1 Merge ProfileStorage: Store empty xattrs as empty string
... instead of None.

This avoids the need to allow type changes (None vs. str).

Also adjust the tests accordingly.

While on it, simplify the tests for attachment.

attachment is always a str, therefore adjust the test to expect an empty
str ('') instead of None - and later converting that None to ''.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/786
Acked-by: John Johansen <john.johansen@canonical.com>
2021-08-20 21:55:22 +00:00
John Johansen
572c342a2b Merge SeverityVarsTest: Make order of variable replacements constant
... using [] instead of {}

This should keep the order of checking (and therefore code coverage)
constant, and should fix the randomly appearing partial coverage in
severity.py handle_variable_rank(). In some random cases (depending in
which order the replacements were done and checked for their severity),
the coverage report indicated that the 'elif' condition was never false.

Note: This is only "coverage cosmetics". In "real users", it doesn't
matter in which order the variable replacements are checked because the
result doesn't depend on the ordering.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/790
Acked-by: John Johansen <john.johansen@canonical.com>
2021-08-20 21:52:23 +00:00
Christian Boltz
4fd7bcc289 Merge branch 'fix-video-abstraction' into 'master'
add a missing slash at the end of the sys rule

See merge request apparmor/apparmor!791

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.12..master
2021-08-20 18:16:03 +00:00
Mikhail Morfikov
b3dcd02dff add a missing slash at the end of the sys rule 2021-08-20 00:38:14 +02:00
Christian Boltz
d4b17ef904 SeverityVarsTest: Make order of variable replacements constant
... using [] instead of {}

This should keep the order of checking (and therefore code coverage)
constant, and should fix the randomly appearing partial coverage in
severity.py handle_variable_rank(). In some random cases (depending in
which order the replacements were done and checked for their severity),
the coverage report indicated that the 'elif' condition was never false.

Note: This is only "coverage cosmetics". In "real users", it doesn't
matter in which order the variable replacements are checked because the
result doesn't depend on the ordering.
2021-08-19 12:52:56 +02:00
Alex Murray
516733950e regression tests: fix aa_policy_cache when using system parser
When using the system parser ${parser_config} will be empty and so if this
is quoted when passed as  argument to the parser then this gets in
interpreted as the name of a file to be compiled and hence the parser just
prints:

File  not found, skipping...
File  not found, skipping...
File  not found, skipping...
...

for all the aa_policy_cache tests - instead fix this by just not quoting
this argument as suggested by cboltz.

This fixes the regression tests to run to completion without error when
USE_SYSTEM=1 is set.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/788
Signed-off-by: Alex Murray <alex.murray@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2021-08-19 11:02:10 +09:30
Christian Boltz
131ae8425b Merge branch 'cboltz-typo' into 'master'
Fix typo in manpage

Closes #192

See merge request apparmor/apparmor!789

Acked-by: Acked-by: Seth Arnold <seth.arnold@canonical.com> for all branches
2021-08-17 18:25:51 +00:00
Christian Boltz
1459f49b7a Fix typo in manpage
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/192
2021-08-17 19:43:53 +02:00
Christian Boltz
8cecc14d2d aa-remove-unknown: Drop superfluous $0 parameter from usage()
$0 is always the name of the script, even if using it inside a function.
Therefore use $0 directly, and no longer hand it over as a parameter.
2021-08-16 19:59:34 +02:00
Christian Boltz
169d305b2b chmod +x aa-remove-unknown 2021-08-16 19:59:34 +02:00
Christian Boltz
e69f46ac3f ProfileStorage: simplify tests for attachment
attachment is always a str, therefore adjust the test to expect an empty
str ('') instead of None - and later converting that None to ''.
2021-08-16 19:59:05 +02:00
Christian Boltz
337ebcd032 ProfileStorage: Store empty xattrs as empty string
... instead of None.

This avoids the need to allow type changes (None vs. str).

Also adjust the tests accordingly.
2021-08-16 19:59:02 +02:00
Georgia Garcia
bbe52a1eec Merge CI: always collect test artifacts
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/787

Acked-by: Georgia Garcia <georgia.garcia@canonical.com>
2021-08-16 13:51:12 +00:00
Christian Boltz
266ac13e10 CI: always collect test artifacts
The default is to collect them on success, but that's not helpful to
debug failure cases.
2021-08-15 16:28:35 +02:00
John Johansen
a79e800ebe Merge libapparmor:fix error value returned from features_lookup functions.
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/780
Acked-by: John Johansen <john.johansen@canonical.com>
2021-08-13 20:49:53 +00:00
John Johansen
31fda3eee7 Merge Update abstractions/python and profiles for python 3.10
Add support for python 3.10 in abstractions and profiles.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/187
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/783
Acked-by: John Johansen <john.johansen@canonical.com>
2021-08-13 20:13:59 +00:00
Steve Beattie
0db428a67b Revert "regression tests: fix aa_policy_cache when using system parser"
This reverts merge request !782
2021-08-12 06:59:41 +00:00
Steve Beattie
8d0b48df12 regression tests: fix aa_policy_cache when using system parser
Merge branch 'fix-policy-cache-regression-tests' into 'master'

When using the system parser ${parser_config} will be empty and so if this
is unconditionally passed as an argument to the parser then this gets in
interpreted as the name of a file to be compiled and hence the parser just
prints:

File  not found, skipping...
File  not found, skipping...
File  not found, skipping...
...

for all the aa_policy_cache tests - instead fix this to pass a single args
argument to the parser which will only include parser_config if it is not
empty.

This fixes the regression tests to run to completion without error when
USE_SYSTEM=1 is set.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/782
Signed-off-by: Alex Murray <alex.murray@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2021-08-12 05:32:07 +00:00
Christian Boltz
ea7b201ba4 Update abstractions/python and profiles for python 3.10
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/187
2021-08-11 21:37:40 +02:00
Alex Murray
0f2a33e7fb regression tests: fix aa_policy_cache when using system parser
When using the system parser ${parser_config} will be empty and so if this
is unconditionally passed as an argument to the parser then this gets in
interpreted as the name of a file to be compiled and hence the parser just
prints:

File  not found, skipping...
File  not found, skipping...
File  not found, skipping...
...

for all the aa_policy_cache tests - instead fix this to pass a single args
argument to the parser which will only include parser_config if it is not
empty.

This fixes the regression tests to run to completion without error when
USE_SYSTEM=1 is set.

Signed-off-by: Alex Murray <alex.murray@canonical.com>
2021-08-11 18:02:36 +09:30
John Johansen
bbdd563955 library: bump version number to stay in sync with 3.0.2 release
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-08-05 22:26:59 -07:00
John Johansen
8dce557f01 bump Version to indicate dev branch
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-08-05 22:25:47 -07:00
Georgia Garcia
656a48b900 tests: check for loopback module on pivot_root test
mount -o loop fails when the loopback module is not loaded with
permission denied. Add a check if /dev/loop0 exists. If not, load
the loop module.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/781
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2021-08-03 10:09:55 -03:00
Mingjun.Yang
348bb8b3d7 libapparmor:fix error value returned from features_lookup functions. 2021-07-31 11:21:47 +08:00
John Johansen
3f46d96aca libapparmor: fix comments about kernel exporte interfaces
Some basic fixes to comments, that were found after !713 was merged.

Fixes: https://gitlab.com/apparmor/apparmor/-/merge_requests/713
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/777
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2021-07-22 14:24:00 -07:00
John Johansen
29215b4784 Merge libapparmor: Adjust stacking interface check
libapparmor performs a test for the new stacking interface, however
how it does this test is problematic as it requires all confined
tasks to be given read access to the task introspection interface.
This results in tasks needing to be given read access to the interface
even if they don't need it. Making it possible for tasks to discover
their confinement even if they are not supposed to be able to.
Instead change the check to using state on the parent directory.
This will generate a getattr request instead of read and make it
on the directory instead of on any interface file that could be
used to obtain information.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/713
Signed-off-by: John Johansen john.johansen@canonical.com
Acked-by: Timeout
2021-07-21 15:44:23 -07:00
John Johansen
a98469eb09 [7/7] abstractions: Make "available" readable as part of the enabled api
Understacking AppArmor if it is not the major LSM may set the enabled
field to false, to keep userspace from hitting the old shared proc
interfaces. The parameter "available" is added to indicate apparmor
is available but not present on the older interfaces.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/150
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/713
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-07-21 14:31:44 -07:00
John Johansen
c60fc809a9 [6/7] parser: update the parser to add interface rules for change_X
For change_hat and change_profile instead of a single interface
rule we need to add some readonly interfaces for discovery and
the new and old proc interface for writing.

Consolidate into a single shared routine.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/150
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/713
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-07-21 14:31:44 -07:00
John Johansen
35e58273e6 [5/7] libapparmor: rework trying original interface if new interface fails
Adjust the interface check and fallback. Unfortunately there is no
solution that will fix all failure cases. Instead try to minimize
the failure cases and bias towards failures that don't cause a
regression under an old parser/policy.

Note: In cases where we absolutely know the interface should not
      be accessed fail those accesses imediately instead of relying
      on what ever LSM active to handle it.

While we are at it document the interfaces and failure cases.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/150
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/713
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-07-21 14:31:44 -07:00
John Johansen
d0c4fc7d68 [4/7] libapparmor: fix available and enabled checks
Make it easier to separate errors from an actual answer, and ensure
we do a fallback check if there was an error.

Also fix the error code returned from aa_is_enabled() which got
broken by the addition of the private_enabled() check.

Finally make sure the private enabled error code is documented.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/150
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/713
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-07-21 14:31:44 -07:00
John Johansen
3fb4c4b876 [3/7] libapparmor: Fix AppArmor private interface availability check
The parameter that is landing upstream in "available" not
"private_enabled".

Also set the correct variable, as previously we were not.

Note: that skipping checking available for the private apparmor
proc interfaces is okay, as the dedicated apparmor interfaces will
fail correctly if available is False.

This just gives a clear way for userspace to query this info without
having to resort to error codes that access to the private interfaces
would return.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/150
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/713
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-07-21 14:31:44 -07:00
John Johansen
6c4ed2af8d [2/7] libapparmor: Adjust stacking interface check
libapparmor performs a test for the new stacking interface, however
how it does this test is problematic as it requires all confined
tasks to be given read access to the task introspection interface.

This results in tasks needing to be given read access to the interface
even if they don't need it. Making it possible for tasks to discover
their confinement even if they are not supposed to be able to.

Instead change the check to using stat on the parent directory.
This will generate a getattr request instead of read and make it
on the directory instead of on any interface file that could be
used to obtain information.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/150
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/713
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-07-21 14:31:44 -07:00
John Johansen
0be67ec840 [1/7] libapparmor: fix check for asprintf failure in proc init fn()
The fn() handling proc base address init is not checking for asprintf
failure. Fix it.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/150
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/713
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-07-21 14:31:44 -07:00
John Johansen
d8ec3dafb7 Merge allow Prometheus metrics end-point in dovecot/stats
Patch by Michael Ströder <michael@stroeder.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/776
Acked-by: John Johansen <john@jjmx.net>
2021-07-21 19:28:41 +00:00
Christian Boltz
f3dd0d1911 allow Prometheus metrics end-point in dovecot/stats
Patch by Michael Ströder <michael@stroeder.com>
2021-07-19 22:36:28 +02:00
Jon Tourville
598131696e Merge Parser check fix
This resolves an issue in the parser's job handling when running on a machine with >8 CPU cores. The test library was updated to resolve failures in the caching tests caused by the features directory entries being unsorted in the tests.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/775
Acked-by: John Johansen [john@jjmx.net](mailto:john@jjmx.net)
2021-07-19 20:01:57 +00:00
Jon Tourville
efe39e7590 parser: fix comment for jobs_max default value 2021-07-19 13:53:09 -05:00
John Johansen
710bf66e51 Merge Allow reading /etc/login.defs.d/ in abstraction/authentication
This directory can include login.defs config sniplets in openSUSE
Tumbleweed.

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1188296

See also
https://en.opensuse.org/openSUSE:Packaging_UsrEtc#pam.2Fpam-config

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/774
Acked-by: John Johansen <john.johansen@canonical.com>
2021-07-16 22:07:34 +00:00
Jon Tourville
e82a23dfe4 parser: sort feature directory entries in to match libapparmor's directory traversal 2021-07-16 08:57:57 -05:00
Christian Boltz
b6b89478aa Allow reading /etc/login.defs.d/ in abstraction/authentication
This directory can include login.defs config sniplets in openSUSE
Tumbleweed.

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1188296

See also
https://en.opensuse.org/openSUSE:Packaging_UsrEtc#pam.2Fpam-config
2021-07-15 13:04:44 +02:00
John Johansen
3d1232e640 parser: fix cache time stamp check to include dir time stamps
Currently for directory includes the directory timestamp is ignored.
This is wrong as operations like removing a file from the dir won't
be considered in the timestamp check.

Fix this by updating the timestamp check to include the included
directories timestamp.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/760
Signed-off-by: John Johansen <john@jjmx.net>
Acked-by: Georgia Garcia  <georgia.garcia@canonical.com>
2021-07-13 18:08:55 -07:00
Christian Boltz
f466e80d18 Merge branch 'cboltz-gcrypt' into 'master'
add abstractions/crypto, allowing reading @{etc_ro}/gcrypt/random.conf r, and move several rules around

See merge request apparmor/apparmor!772

Acked-by: John Johansen <john.johansen@canonical.com>
2021-07-13 21:52:25 +00:00
Christian Boltz
b5241282e8 move @{PROC}/sys/crypto/fips_enabled r, rule
... from openssl to crypto abstraction
2021-07-13 21:56:29 +02:00
Christian Boltz
ba8087927f Move crypto-policies rules from ssl_certs to crypto
No additional include rule needed since crypto is included in base.
2021-07-13 21:56:29 +02:00
Christian Boltz
534a6d3057 move @{PROC}/sys/crypto/* permissions from base to crypto 2021-07-13 21:56:29 +02:00
Christian Boltz
9830031314 Add crypto abstraction and include it in base
crypto allows reading /etc/gcrypt/random.conf, which is possibly needed
for all programs that use libgcrypt.

Reported by darix, he has seen it with vivaldi.
2021-07-13 21:56:29 +02:00
Christian Boltz
4e8ca5696e Merge branch 'cboltz-test-profiles' into 'master'
Test if active and extra profiles can be parsed by the tools

See merge request apparmor/apparmor!677

Acked-by: John Johansen <john.johansen@canonical.com>
2021-07-13 19:51:27 +00:00
Christian Boltz
26d7c13f94 Add option to skip reading specific profiles
If a profile uses features not supported by the tools yet, add a
skiplist to (hopefully temporarily) exclude it from the tests.

This is meant to avoid blocking usage of new features in profiles.

When doing a release, the skip lists should be empty.
2021-07-13 21:09:36 +02:00
Christian Boltz
b02c59a730 Test if active and extra profiles can be parsed by the tools
The added test makes sure that the python code can parse all profiles
shipped with AppArmor. If this fails, read_profiles() /
read_inactive_profiles() will raise an exception.

Checking for the number of read profiles is mostly done to ensure
*something* is read (to make sure an empty or non-existing directory
won't make the test useless).
2021-07-13 21:09:36 +02:00
Christian Boltz
92883d7e6c Fix extra profiles path in utils/test/logprof.conf 2021-07-13 21:09:35 +02:00
Christian Boltz
bacfe785fe Merge branch 'cboltz-ci-artifacts' into 'master'
Generate and keep html in utils coverage-regression

See merge request apparmor/apparmor!771

Acked-by: Georgia Garcia  <georgia.garcia@canonical.com>
2021-07-13 18:07:29 +00:00
Christian Boltz
8d9e2489a2 Generate and keep html in utils coverage-regression
We sometimes have random coverage changes that are not reproducible and
therefore hard to debug.

Generate html coverage as part of make coverage-regression, and keep the
resulting utils/test/htmlcov/ as artifact to make debugging easier.

coverage-html needs JS files from various libjs-* packages, install them
in before_script
2021-07-13 18:40:59 +02:00
Jon Tourville
5910b50926 parser: correctly calculate max number of jobs 2021-07-12 10:09:16 -05:00
Georgia Garcia
bf59925a6b tests: disable file query test for kernels before 4.4
The file query test on query_label.sh fails on kernels
before 4.4 because of the lack of support. Since there
is no feature file to examine for this feature, we
need to check for the kernel version.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2021-07-02 17:20:01 -03:00
Georgia Garcia
12957eba4d parser: CAP_AUDIT_READ is only available after Linux 3.16
The parser was not compiling on older versions of Ubuntu
(trusty) because the capability CAP_AUDIT_READ that was
defined on base_cap_names.h was not available until
kernel version 3.16.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/767
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2021-07-02 17:05:19 -03:00
John Johansen
8c8da7c67d parser: move ifdefs for capabilities to single common file
Unfortunately the parser was doing ifdef checks for capabilities
in two places. Move all the capability ifdefs into capability.h

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/768
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Georgia Garcia  <georgia.garcia@canonical.com>
2021-07-02 12:48:47 -07:00
John Johansen
e6e112fba1 tests: regression: fix test failure due to mmap semantic changes
The regression tests are failing on some older kernels due to
commit 9f834ec18defc369d73ccf9e87a2790bfa05bf46 being cherry-picked
back to them without the corresponding apparmor patch
34c426acb75cc21bdf84685e106db0c1a3565057.

This means we can not rely on a simple features/flag check to determine
how the kernel is behaving with regard to mmap. Since this test is
not concerned with testing mmap, instead of adding a more complex
conditional simplify by always adding the m permission.

Fixes: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1830984
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Georgia Garcia  <georgia.garcia@canonical.com>
2021-07-01 14:15:02 -07:00
John Johansen
db94b436dd Merge Fix crash caused by ask_exec()
ask_exec still uses aa[profile][hat], therefore
- use full_profile when accessing hashlog
- correctly split the merged profile name to profile and hat
- avoid accidently initializing non-existing aa[profile][hat]

This fixes a regression from converting lots of code to use flat
profile//hat array keys.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/763
Acked-by: John Johansen <john@jjmx.net>
2021-06-30 06:36:55 +00:00
John Johansen
80ae7491c4 Merge Make 'transitions' a dict instead of Hasher
It's used like a plain dict, therefore no further code changes are
needed.

Also simplify generating the 'context' key that is used with
'transitions'.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/764
Acked-by: John Johansen <john@jjmx.net>
2021-06-30 06:33:28 +00:00
Christian Boltz
93bd9a1d5b Merge branch 'cboltz-crypto-policies' into 'master'
abstractions/ssl_certs: allow reading crypto policies

See merge request apparmor/apparmor!720

Acked-by: Seth Arnold <seth.arnold@canonical.com>
2021-06-29 12:41:40 +00:00
Christian Boltz
13a8221622 abstractions/ssl_certs: allow reading crypto policies
See https://gitlab.com/redhat-crypto/fedora-crypto-policies for details.

Reported by darix and also my own audit.log - the actual denial was for
/usr/share/crypto-policies/DEFAULT/openssl.txt.

Also allow the /etc/crypto-policies/ counterpart.

(I'm aware that the crypto policies are not really certificates, but
since they are used by several crypto libraries, ssl_certs is probably
the best place for them even if the filename doesn't match.)
2021-06-28 22:04:08 +02:00
Georgia Garcia
458a981b62 tests: fix i18n.sh regression test on arm64
The following errors are happening on the regression tests
of i18n.sh on arm64 hirsute/impish:

Error: open failed. Test 'i18n (194) OPEN (octal) "/tmp/sdtest.3654-6536-J2ZwFM/file__post" RW' was expected to 'pass'. Reason for failure 'FAIL: open /tmp/sdtest.3654-6536-J2ZwFM/file__post failed - Permission denied'
...

The cause is a bash bug handling UTF-8 on subshells.

Fixes: https://bugs.launchpad.net/apparmor/+bug/1932331
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/765

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2021-06-28 15:30:33 -03:00
Christian Boltz
5aa35195f4 Make 'transitions' a dict instead of Hasher
It's used like a plain dict, therefore no further code changes are
needed.

Also simplify generating the 'context' key that is used with
'transitions'.
2021-06-27 21:37:22 +02:00
Christian Boltz
755b5d11e1 Fix crash caused by ask_exec()
ask_exec still uses aa[profile][hat], therefore
- use full_profile when accessing hashlog
- correctly split the merged profile name to profile and hat
- avoid accidently initializing non-existing aa[profile][hat]

This fixes a regression from converting lots of code to use flat
profile//hat array keys.
2021-06-27 21:21:53 +02:00
Georgia Garcia
9ff713957c Add README on tests regarding single test execution
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/761

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2021-06-22 12:15:18 +00:00
Georgia Garcia
f46dd62aa0 Merge branch 'profile-check' into 'master'
profiles: Fix config dir on make check

Closes #177

See merge request apparmor/apparmor!762
2021-06-21 19:41:28 +00:00
Georgia Garcia
644d36003c profiles: Fix config dir on make check
The check-logprof test in the profiles Makefile specifies
the configuration directory as --configdir ../utils/test,
but when aa-logprof looks for severity.db in the configdir,
it cannot find it.

This fix points the configdir to utils. Note that the
logprof.conf on utils uses the configuration for files
created during the libapparmor installation on the system.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/177
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2021-06-21 14:20:34 +00:00
John Johansen
9fb1398b63 Merge remove always-True write_flags parameter from write_piece() and get_header()
All the calling code (directly or indirectly) uses write_flags=True,
therefore drop the parameter to simplify the code.

See the individual commits for details. Also, reviewing the individual commits is probably easier than reviewing the full diff (especially the test changes).

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/759
Acked-by: John Johansen <john@jjmx.net>
2021-05-25 10:16:33 +00:00
Christian Boltz
5d8f66c9e3 get_header() tests: drop write_flags, add xattrs
Drop unused write_flags parameter from AaTest_get_header and
AaTest_get_header_01. This is a cleanup for the previous commit.

While on it, add xattrs parameter to AaTest_get_header, and add two
tests with non-empty xattrs.
2021-05-25 11:31:10 +02:00
Christian Boltz
6e6b94ab57 get_header(): remove always-True write_flags parameter
All the calling code (directly or indirectly) uses write_flags=True,
therefore drop the parameter to simplify the code.

A few tests called get_header() with write_flags=False. Adjust or drop
those tests.

Note: to keep the diff readable, the test changes are as small as
possible. The next commit will cleanup the now-superfluous write_flags
values in the tests.
2021-05-25 11:31:10 +02:00
Christian Boltz
a7b44cb1ac write_piece(): remove always-True write_flags parameter
All the calling code (directly or indirectly) uses write_flags=True,
therefore drop the parameter to simplify the code.
2021-05-25 11:31:08 +02:00
John Johansen
c07a5bb3d3 Merge change_profile_flags(): use ProfileStorage.parse()
... instead of "manually" creating a ProfileStorage object

Also preserve profile keyword and comment in ProfileStorage.parse()

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/758
Acked-by: John Johansen <john@jjmx.net>
2021-05-25 08:55:15 +00:00
Christian Boltz
2351bf74bf change_profile_flags(): use ProfileStorage.parse()
... instead of "manually" creating a ProfileStorage object
2021-05-24 14:50:52 +02:00
Christian Boltz
b7e9928941 Preserve profile keyword and comment in ProfileStorage.parse() 2021-05-24 14:50:46 +02:00
John Johansen
e00e3fed85 Merge When changing flags, use correct amount of whitespace
.. instead of preserving the original leading whitespace.

This change affects the behaviour of aa-complain, aa-enforce and aa-audit.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/757
Acked-by: John Johansen <john@jjmx.net>
2021-05-24 10:21:07 +00:00
John Johansen
18ad8e94a8 Merge Merge hat parsing into ProfileStorage.parse()
... and into parse_profile_start_line() (which is used by
ProfileStorage.parse()).

With this change, the section handling RE_PROFILE_HAT_DEF in
parse_profile_data() becomes superfluous.

A nice side effect is that two simple_tests parse failures get
accidently ;-) fixed.

Also preserve 'hat' keyword in ProfileStorage instead of always writing hats as '^hat'.

When writing a profile, prepending '^' or 'hat' to a hat name moves from
aa.py write_piece() to ProfileStorage.get_header().

Finally, extend cleanprof_test.* with 'hat bar {...}'.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/756
Acked-by: John Johansen <john@jjmx.net>
2021-05-24 10:18:35 +00:00
John Johansen
ea57aaa617 Merge abstractions/php: support PHP 8
Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1186267
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/755
Acked-by: John Johansen <john@jjmx.net>
2021-05-24 10:07:21 +00:00
Christian Boltz
f0a445dd7d When changing flags, use correct amount of whitespace
.. instead of preserving the original leading whitespace.

This change affects the behaviour of aa-complain, aa-enforce and aa-audit.
2021-05-23 19:00:06 +02:00
Christian Boltz
97aece024a Preserve 'hat' keyword in ProfileStorage
... instead of always writing hats as '^hat'.

When writing a profile, prepending '^' or 'hat' to a hat name moves from
aa.py write_piece() to ProfileStorage.get_header().

Also extend cleanprof_test.* with 'hat bar {...}'.
2021-05-23 18:19:28 +02:00
Christian Boltz
6f15bea74c Merge hat parsing into ProfileStorage.parse()
... and into parse_profile_start_line() (which is used by
ProfileStorage.parse()).

With this change, the section handling RE_PROFILE_HAT_DEF in
parse_profile_data() becomes superfluous.

A nice side effect is that two simple_tests parse failures get
accidently ;-) fixed.
2021-05-23 17:52:03 +02:00
Christian Boltz
5853f52233 abstractions/php: support PHP 8
References: https://bugzilla.opensuse.org/show_bug.cgi?id=1186267
2021-05-21 22:50:54 +02:00
John Johansen
0325ba06da Merge ProfileStorage: change 'profile' to 'is_hat', and move parse_profile_start{,_to_storage}() into ProfileStorage
The 'profile' flag means "this profile is a profile or a child profile, but not a hat". Since that's true for most cases, rename the flag to 'is_hat'.

Note that `'profile' == True` translates to `'is_hat' == False`

Also adjust all code to switch from 'profile' to 'is_hat'.

Further down the commit list,

* move parse_profile_start{,_to_storage}() into ProfileStorage
* merge parse_profile_start() into parse()
* add some missing tests

See the individual commits for details.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/754
Acked-by: John Johansen <john@jjmx.net>
2021-05-16 23:46:34 +00:00
Christian Boltz
055ca8f857 Add a test to ensure nested childs cause an Exception
... and add some tests for other error conditions that don't imply
nested childs, so that the intended failure gets tested.
(This is probably a leftover of the `hat == profile` -> `hat = None`
(while not in a hat/child profile) change.)
2021-05-16 18:15:03 +02:00
Christian Boltz
42fe65de71 ProfileStorage: merge parse_profile_start() into parse()
... which avoids handing several values around.

Also adjust the tests so that only the end result (of parse() gets
tested.
2021-05-16 18:15:03 +02:00
Christian Boltz
1642fea228 Move parse_profile_start{,_to_storage}() into ProfileStorage
... and make them class functions of ProfileStorage.

parse_profile_start_to_storage() gets renamed to parse().

Also move the tests for parse_profile_start() and
parse_profile_start_to_storage() to test-profile-storage.py.
2021-05-16 18:15:03 +02:00
Christian Boltz
2a97d6b6bc ProfileStorage: change 'profile' to 'is_hat'
The 'profile' flag means "this profile is a profile or a child profile,
but not a hat". Since that's true for most cases, rename the flag to
'is_hat'.

Note that `'profile' == True` translates to `'is_hat' == False`

Also adjust all code to switch from 'profile' to 'is_hat'.
2021-05-16 18:15:03 +02:00
John Johansen
52de1a226f Merge Update postfix profiles
... with paths and needed permissions seen on latest Tumbleweed

I propose these additions for 3.0 and master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/753
Acked-by: John Johansen <john@jjmx.net>
2021-05-10 08:15:52 +00:00
John Johansen
adee3e5a4c Merge parse_profile_start(): get rid of pps_set_profile
This value is True if we are in a child profile (not: hat), but that's information we get "for free", so there's no need to hand it around. Besides that, it was wrongly set to False for main profiles (which are not hats).

Remove the pps_set_profile return value from parse_profile_start(), and always assume True unless we were parsing a hat. For completeness, explicitely set it to False when parsing a hat.

To make sure child profiles and hats don't get mixed up, add a child profile to cleanprof_test.{in,out}.

test-libapparmor-test_multi.py always interpreted foo//bar as being a hat, therefore explicitely mark them as such. (Technically not really needed since this is the default, but it helps to make things clear.)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/751
Acked-by: John Johansen <john@jjmx.net>
2021-05-10 08:14:18 +00:00
Christian Boltz
d78db0502f Update postfix profiles
with paths and needed permissions seen on latest Tumbleweed
2021-05-09 17:45:13 +02:00
John Johansen
33a53c2664 Merge Fix comment wording in file_cache.h
Fixes: https://gitlab.com/apparmor/apparmor/-/merge_requests/743
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/752
Acked-by: John Johansen <john.johansen@canonical.com>
2021-05-02 09:40:17 +00:00
Christian Boltz
e31015a11a Fix comment wording in file_cache.h
This fixes https://gitlab.com/apparmor/apparmor/-/merge_requests/743#note_562522101
2021-05-02 11:29:41 +02:00
Christian Boltz
e1af0cdeca parse_profile_start(): get rid of pps_set_profile
This value is True if we are in a child profile (not: hat), but that's
information we get "for free", so there's no need to hand it around.
Besides that, it was wrongly set to False for main profiles (which are
not hats).

Remove the pps_set_profile return value from parse_profile_start(), and
always assume True unless we were parsing a hat. For completeness,
explicitely set it to False when parsing a hat.

To make sure child profiles and hats don't get mixed up, add a child
profile to cleanprof_test.{in,out}.

test-libapparmor-test_multi.py always interpreted foo//bar as being
a hat, therefore explicitely mark them as such. (Technically not really
needed since this is the default, but it helps to make things clear.)
2021-04-28 21:22:08 +02:00
Steve Beattie
92c76e04fe tests: add a test with recursive include in preamble
... just to be sure that the recursion check works everywhere ;-)


MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/750
Acked-By: Steve Beattie <steve@nxnw.org>
See merge request apparmor/apparmor!750
2021-04-28 14:23:53 +00:00
Christian Boltz
f0221f4bca Add a test with recursive include in preamble 2021-04-28 13:32:08 +02:00
John Johansen
74bc4275a5 parser: Fix invalid reference to name in attachment warning
The name var is being improperly used in a warning. Not only is
it being used after it is freed, it also never had the correct value
as the "name" variable contained the value being used as the base
attachment.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: time out
2021-04-27 21:06:21 -07:00
John Johansen
be0d2fa947 parser: fix filter slashes for profile attachments
The parser is failing to properly filter the slashes in the profile
attachment after variable expansion. Causing matche failures when
multiple slashes occur.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/154
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/727
Reported-by: Mikhail Morfikov <mmorfikov@gmail.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: time out
2021-04-27 21:06:05 -07:00
John Johansen
71bf9e132f Merge parser: add include dedup cache to handle include loops
Profile includes can be setup to loop and expand in a pathalogical manner that causes build failures. Fix this by caching which includes have already been seen in a given profile context.

In addition this can speed up some profile compiles, that end up re-including common abstractions. By not only deduping the files being included but skipping the need to reprocess and dedup the rules within the include.

Fixes: https://bugzilla.suse.com/show_bug.cgi?id=1184779
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/743
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2021-04-28 04:00:54 +00:00
Steve Beattie
c00b0d325b parser: add a simple one-level recursive include test
This adds a recursive include that otherwise parses correctly, to check
that the parser handles one-level recursion loop acceptably. When the
utils can support it, we should have tests that exercise deeper levels
of looping, e.g. include a -> include b -> include c -> include a or
deeper.

Without the fix in
https://gitlab.com/apparmor/apparmor/-/merge_requests/743, the parser
does fail due to hitting its file descriptor limit.

(The test at

  https://gitlab.com/apparmor/apparmor/-/blob/master/parser/tst/simple_tests/include_tests/recursive.sd

includes itself, which will result in a recursive profile definition
which isn't accepted by the parser.)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/743
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-04-27 20:27:33 -07:00
John Johansen
7dcf013bca parser: add include dedup cache to handle include loops
Profile includes can be setup to loop and expand in a pathalogical
manner that causes build failures. Fix this by caching which includes
have already been seen in a given profile context.

In addition this can speed up some profile compiles, that end up
re-including common abstractions. By not only deduping the files
being included but skipping the need to reprocess and dedup the
rules within the include.

Fixes: https://bugzilla.suse.com/show_bug.cgi?id=1184779
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/743
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2021-04-27 20:26:57 -07:00
John Johansen
a7816e1a8f Merge Rework internal profile storage and handling in the aa-* tools to use merged profile names instead of [profile][hat]
Change the tools to use merged profile names (`var['foo//bar']`) instead of the profile/hat layout (`var[profile][hat]`) in many places. Also storage gets moved to ProfileList instead of using a hasher.

Already changed places (in this MR) are parsing profiles, writing profiles, handling and storing of extra profiles, log handling and asking the user about profile additions.

Remaining usage of the `var[profile][hat]` layout are the `aa` and `original_aa` hashers, they'll be replaced in a separate MR.

See the individual commits for details. I'd also recommend to do the review on the individual commits, because the big diff is probably unreadable ;-)

While this is a big chain of changes, each commit contains working code, converting between the two storage layouts with `split_to_merged()` and `merged_to_split()` as needed, with merged layout "bubbling up" in more and more functions.

The long-term goal of these changes is to enable support for nested child profiles in the tools, but - one step after the other ;-)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/736
Acked-by: John Johansen <john.johansen@canonical.com>
2021-04-27 10:16:58 +00:00
John Johansen
bf70a8e4ec Merge get_new_profile_filename(): use better variable name
The function decides on the filename of a profile, therefore use 'filename' as variable name instead of the somewhat confusing 'profile' and 'full_profilename'.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/749
Acked-by: John Johansen <john.johansen@canonical.com>
2021-04-27 00:37:51 +00:00
John Johansen
ea61100ab6 Merge .gitignore: Add aa-features-abi and utils coverage files
I propose this addition for master and 3.0 (to keep the file in sync, and because most additions \[except `utils/test/coverage-report.txt`\] already make sense in 3.0)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/748
Acked-by: John Johansen <john.johansen@canonical.com>
2021-04-27 00:33:34 +00:00
John Johansen
a0844f194e Merge Rewrite gen-dbus in python
The generated files are exactly the same.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/747
Acked-by: John Johansen <john.johansen@canonical.com>
2021-04-27 00:31:42 +00:00
Christian Boltz
54eb2baae7 get_new_profile_filename(): use better variable name
The function decides on the filename of a profile, therefore use
'filename' as variable name instead of the somewhat confusing 'profile'
and 'full_profilename'.
2021-04-25 20:35:37 +02:00
Christian Boltz
5c0609453c .gitignore: Add aa-features-abi and utils coverage files 2021-04-25 20:10:48 +02:00
Christian Boltz
2b00d21e2e Rewrite gen-dbus in python
The generated files are exactly the same.
2021-04-25 18:31:38 +02:00
John Johansen
8aa15c7fbe Merge Detect endless #include loop when parsing profiles
If an include file includes itsself (for example if local/foo has '#include <local/foo>'), print a warning instead of calling load_include() again and again.

This fixes a crash when hitting such a case: RecursionError: maximum recursion depth exceeded while calling a Python object

Fixes: https://bugzilla.suse.com/show_bug.cgi?id=1184779 for the tools. The parser will also need a fix.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/742
Acked-by: John Johansen <john.johansen@canonical.com>
2021-04-21 20:06:49 +00:00
Mikhail Morfikov
92e27f5566 abstractions: Add trash abstraction
I noticed that some apps have support for moving files to trash, but
currently there's no abstraction that would provide rules to make this
action possible.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/160
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/738
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2021-04-21 13:01:43 -07:00
John Johansen
cf809ea928 parser: Fix make DEBUG=1
When building the parser with DEBUG=1 enabled the build fails with
the following error and warnings

    In file included from parser_main.c:47:0:
    parser_main.c: In function ‘void auto_tune_parameters()’:
     parser_main.c:1421:35: error: ‘estimate_jobs’ was not declared in this scope
        PDEBUG("Auto tune: --jobs=%d", estimate_jobs);
                                   ^
    parser.h:201:37: note: in definition of macro ‘PDEBUG’
      fprintf(stderr, "parser: " fmt, ## args); \
                                     ^~~~
    parser_main.c:1421:35: note: suggested alternative: ‘estimated_jobs’
        PDEBUG("Auto tune: --jobs=%d", estimate_jobs);
                                   ^
    parser.h:201:37: note: in definition of macro ‘PDEBUG’
      fprintf(stderr, "parser: " fmt, ## args); \
                                     ^~~~
    parser.h:201:41: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long int’ [-Wformat=]
      fprintf(stderr, "parser: " fmt, ## args); \
                                         ^
    parser_main.c:1428:5: note: in expansion of macro ‘PDEBUG’
         PDEBUG("Auto tune: --jobs=%d", jobs);
     ^~~~~~
    Makefile:234: recipe for target 'parser_main.o' failed

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/745
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2021-04-21 12:57:05 -07:00
Christian Boltz
30323a2ded Detect endless #include loop when parsing profiles
If an include file includes itsself (for example if local/foo has
'#include <local/foo>'), print a warning instead of calling
load_include() again and again.

This fixes a crash when hitting such a case:
    RecursionError: maximum recursion depth exceeded while calling a Python object

Fixes: https://bugzilla.suse.com/show_bug.cgi?id=1184779 for the tools.
The parser will also need a fix.
2021-04-16 00:00:02 +02:00
Christian Boltz
e54b13a97a write_piece(): use merged profile names
... and adjust the callers accordingly.

While on it, simplify the write_piece() code that prepends '^' to hats a bit.
2021-04-15 12:53:08 +02:00
Christian Boltz
0e5dca1083 serialize_profile(): use merged profile names in parameter
... and adjust all callers accordingly.
2021-04-15 12:53:08 +02:00
Christian Boltz
0802f34b35 deduplicate code in read_profile() and autodep()
if a profile doesn't have an attachment specified and the profile name
starts with '/', set the attachment to the profile name. This allows to
have one add_profile() call instead of two very similar ones.
2021-04-15 12:53:08 +02:00
Christian Boltz
8f84e125fd simplify logic in read_profile()
exit early if profile_data is empty (which means we did read an empty
file). This allows to simplify the if conditions to "if active_profile:"
and "else:".
2021-04-15 12:53:08 +02:00
Christian Boltz
e04c8151bb autodep(): use merged profile names
This means getting rid of several merged_to_split() and
split_to_merged() calls.
2021-04-15 12:53:08 +02:00
Christian Boltz
5cf7a28130 change get_profile() to return merged profile names
... and adjust its only caller accordingly.
2021-04-15 12:53:08 +02:00
Christian Boltz
5a68d96c11 extend create_new_profile() tests to cover required hats 2021-04-15 12:53:08 +02:00
Christian Boltz
c65206f16c create_new_profile(): use and return merged profile names
... and adjust all callers and the tests.

For bonus points ;-) this also removes a hasher usage, and extends the
test to check that only the expected profile gets created.
2021-04-15 12:53:08 +02:00
Christian Boltz
286761271b Store extra profiles in 'extra_profiles' ProfileList
... instead of the 'extras' hasher.

Also adjust all code that previously used 'extras' to use
'extra_profiles'. This affects get_profile() and read_profile().
2021-04-15 12:53:08 +02:00
Christian Boltz
179168f566 ProfileList: add get_profile_and_childs()
... and a test for it
2021-04-15 12:53:08 +02:00
Christian Boltz
b1a1b5dc1b ProfileList: allow storing actual profile data
Add a prof_storage parameter to add_profile() to hand over the actual
profile data/rules as ProfileStorage.

Also adjust several tests to hand over a (dummy) ProfileStorage object.

Note: For now, the parameter is optional because it needs some more changes
in aa.py to be really useable. This will change in a later commit.
2021-04-15 12:53:08 +02:00
Christian Boltz
ba53ff3045 Change ask_the_questions() to work with merged profile names
... instead of converting log_dict to traditional [profile][hat] layout
in do_logprof_pass().

A nice side effect is that we get sorting the main profile before its
hats for free and can remove the sorting code.

Also update a comment in ask_rule_questions().

Finally, adjust aa-mergeprof so that it hands over a merged log_dict (using
split_to_merged())
2021-04-15 12:53:08 +02:00
Christian Boltz
a20865008f collapse_log(): return merged profile names
... instead of the old [profile][hat] structure.

This needs changes in do_logprof_pass() when calling ask_the_questions()
(using merged_to_split() for now).

Also adjust test-libapparmor-test_multi.py logfile_to_profile() to
expect the merged structure.
2021-04-15 12:53:08 +02:00
Christian Boltz
bd3b62a8a1 Change collapse_log to internally use merged profile names
... and convert them back to the [profile][hat] layout at the end so
that callers still get the expected result.

As a side effect, log_dict no longer needs to be a hasher().
2021-04-15 12:53:08 +02:00
Christian Boltz
338a7774f1 parse_profile_data(): return merged profile names
... instead of the old [profile][hat] structure.

This needs changes in read_profile() (now using the merged profile name)
and attach_profile_data() (using merged_to_split() for now).

Also adjust test-aa.py to expect the merged structure.
2021-04-15 12:53:08 +02:00
Christian Boltz
d3816b5bcf add split_to_merged()
... to convert a traditional compat['foo']['bar'] to a profile['foo//bar'] list
2021-04-15 12:53:08 +02:00
Christian Boltz
64a261f5ba parse_profile_data(): use merged profile names internally
Change parse_profile_data() to internally use merged profile names
(`foo//bar`) instead of separate profile and hat, and only split it up
again to the [profile][hat] layout at the very end with
merged_to_split().

A nice side effect is that we get rid of a hasher() usage.

parse_profile_data() also gets changed to use `hat = None` (instead of
`hat = profile`) if not inside a child profile. As a result,
parse_profile_start() and one of its tests need a small change.

Besides that small change, calling code should not see a difference, and
the tests also stay working.
2021-04-15 12:53:08 +02:00
Christian Boltz
24e0631bd2 Add combine_profname() to combine profile name parts into joint name
... and add some tests for it.
2021-04-15 12:53:07 +02:00
Christian Boltz
4642d4c9c3 add merged_to_split()
... and a little test for it.

This function is meant to convert a merged foo['profile//hat'] to
old-style foo_compat['profile']['hat'].
2021-04-15 12:53:05 +02:00
John Johansen
472383a429 Merge Increase include and abi rule test coverage to 100%
... by adding some tests.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/741
Acked-by: John Johansen <john.johansen@canonical.com>
2021-04-14 22:36:01 +00:00
Christian Boltz
86edd48487 Increase include and abi rule test coverage to 100%
... by adding some tests.
2021-04-15 00:24:38 +02:00
Mikhail Morfikov
f19f9ae1fa abstractions: update video abstraction
the video abstraction currently it only contains the following rules:

  @{sys}/class/video4linux r,
  @{sys}/class/video4linux/** r,

Judging by the v4l path, this abstraction should be used whenever some
app wants to use for instance a webcam or other USB cameras to stream
video usually in chat apps. I was testing some apps, and it looks like
the following rules are needed to make the video streaming possible:

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/159
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/740
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-04-14 14:51:09 -07:00
John Johansen
3ee4f9c75f Merge severity.py: bump test coverage to 100%
... by adding some new tests, and by marking two lines as "pragma: no branch" because I didn't find a testcase that doesn't let them continue with the next line.

Finally, remove severity.py from the "not 100% covered" list in test/Makefile.

Also run severity tests with the official severity.db instead of the slightly outdated copy in test/.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/737
Acked-by: John Johansen <john.johansen@canonical.com>
2021-04-14 21:23:35 +00:00
Christian Boltz
a07515bdd4 Run severity tests with official severity.db
... instead of the slightly outdated copy in test/
2021-04-14 21:37:53 +02:00
Christian Boltz
d9cb8df696 severity.py: bump test coverage to 100%
... by adding some new tests, and by marking two lines as "pragma: no
branch" because I didn't find a testcase that doesn't let them continue
with the next line.

Finally, remove severity.py from the "not 100% covered" list in
test/Makefile.
2021-04-14 21:37:01 +02:00
Steve Beattie
94b7704e56 utils: ProfileStorage - add tests with invalid type
Add tests with invalid type to ensure error handling works as expected.

Merge branch 'cboltz/cboltz-profile-storage-tests'

[Fixed conflict with prior change to utils/test/test-profile-storage.py]
Acked-by: Steve Beattie <steve@nxnw.org>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/735
2021-04-11 16:54:43 -07:00
Steve Beattie
d270b2c3d0 utils: move and rename write_header() to ProfileStorage.get_header()
Merge branch 'cboltz-move-write_header' into 'master'

As a preparation, change change_profile_flags() to use ProfileStorage,
and replace some regex usage with startswith() to make the code easier
to read and (probably) more performant.

See the individual commits for details.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/734
Acked-by: Steve Beattie <steve@nxnw.org>
2021-04-11 22:36:59 +00:00
Christian Boltz
38c63026a4 ProfileStorage: add tests with invalid type
... to ensure error handling works as expected.
2021-04-11 21:54:36 +02:00
Christian Boltz
6a170ddaa1 Move and rename write_header() to ProfileStorage.get_header()
Also adjust the calling code to use get_header() instead of
write_header().

Finally, move the tests to test-profile-storage.py and do a few
adjustments needed by the change. Part of these adjustments is to hand
over empty params with the correct type instead of just "None".
2021-04-11 15:05:12 +02:00
Christian Boltz
4ef975fb97 change_profile_flags(): use ProfileStorage
... instead of a dict faking it.
2021-04-11 15:03:41 +02:00
Christian Boltz
9494238eec write_header(): replace regex with startswith()
... to make the code easier to read and (probably) more performant.
2021-04-11 15:03:34 +02:00
John Johansen
edf52a7531 Merge read_profile(): use actual profile name
... instead of profile_data\[profile\]\[profile\]\['name'\] which is not always correct.

Note: setting 'name' will be fixed in a later commit/MR, but don't hold your breath for it ;-)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/733
Acked-by: John Johansen <john.johansen@canonical.com>
2021-04-08 06:53:25 +00:00
John Johansen
09dfbb97e5 Merge logparser: don't return empty AUDIT section
AUDIT events get skipped when parsing the log (they are not relevant for updating a profile), therefore stop returning an always-empty AUDIT section when reading the log.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/731
Acked-by: John Johansen <john.johansen@canonical.com>
2021-04-08 06:50:06 +00:00
Christian Boltz
f9078c4b01 read_profile(): use actual profile name
... instead of profile_data[profile][profile]['name'] which is not
always correct.

Note: setting 'name' will be fixed in a later commit, but don't hold
your breath for it ;-)
2021-04-04 14:04:48 +02:00
Steve Beattie
eb1328f18a utils: ask_conflict_mode: drop superfluous parameters
Merge branch 'cboltz-ask-conflict-mode' into 'master'
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/732
Acked-by: Steve Beattie <steve@nxnw.org>
2021-04-02 21:58:09 +00:00
Christian Boltz
f931daa771 ask_conflict_mode: drop superfluous parameters
profile and hat are not needed by this function.
2021-04-02 17:58:41 +02:00
Christian Boltz
9aa70ab710 logparser: don't return empty AUDIT section
AUDIT events get skipped when parsing the log (they are not relevant for
updating a profile), therefore stop returning an always-empty AUDIT
section when reading the log.
2021-04-02 17:37:23 +02:00
John Johansen
c734839551 profiles: dhclient: allow setting task comm name
dhclient wants to set its thread names to functional names for
introspection purposes. Eg.

$ pstree -at 3395
dhclient ens3
  ├─{isc-socket}
  ├─{isc-timer}
  └─{isc-worker0000}

When denied this can result in dhclient breaking and failing to obtain
IPv4 addresses.

Fixes: https://bugs.launchpad.net/ubuntu/+source/isc-dhcp/+bug/1918410
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2021-03-30 17:16:50 -07:00
John Johansen
c32c970d00 Merge look up python-config using AC_PATH_TOOL
Doing so adds the $ac_tool_prefix during cross compilation and will end up using the correct, architecture-dependent python-config.

This is the second and last upstreamable change from https://bugs.debian.org/984582. It looks a little simpler here, because apparmor evolved upstream compared to the Debian version. Fortunately, it got a lot simpler in the process.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/729
Acked-by: John Johansen <john.johansen@canonical.com>
2021-03-20 10:00:25 +00:00
Helmut Grohne
af4800f3b8 look up python-config using AC_PATH_TOOL
Doing so adds the $ac_tool_prefix during cross compilation and will end
up using the correct, architecture-dependent python-config.

Link: https://bugs.debian.org/984582
2021-03-20 09:42:16 +00:00
John Johansen
f17143b5c3 Merge Do not abuse AC_CHECK_FILE
AC_CHECK_FILE is meant to check for host files and therefore fails hard during cross compilation unless one supplies a cached check result. Here we want to know about the presence of a build system file though, so AC_CHECK_FILE is the wrong tool.

This is part of https://bugs.debian.org/984582.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/728
Acked-by: John Johansen <john.johansen@canonical.com>
2021-03-20 08:18:07 +00:00
Helmut Grohne
60e6847e85 Do not abuse AC_CHECK_FILE
AC_CHECK_FILE is meant to check for host files and therefore fails hard during cross compilation unless one supplies a cached check result. Here we want to know about the presence of a build system file though, so AC_CHECK_FILE is the wrong tool.
2021-03-20 05:41:48 +00:00
John Johansen
277677daf3 profiles: dhcpd: add rule for port_range
The following AppArmor denial errors are shown on startup:

Oct 25 00:52:00 xxx kernel: [  556.231990] audit: type=1400 audit(1603601520.710:32): apparmor="DENIED" operation="open" profile="/usr/sbin/dhcpd" name="/proc/sys/net/ipv4/ip_local_port_range" pid=1982 comm="dhcpd" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

Oct 25 00:52:00 xxx kernel: [  556.232257] audit: type=1400 audit(1603601520.710:33): apparmor="DENIED" operation="open" profile="/usr/sbin/dhcpd" name="/proc/sys/net/ipv4/ip_local_port_range" pid=1982 comm="dhcpd" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

Fixes: https://bugs.launchpad.net/bugs/1901373
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/726
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2021-03-15 23:56:19 -07:00
John Johansen
4101d74de6 man: apparmor.7 add info about complain mode and kernel parameters
Add additional info about complain mode, its behavior, how to enable
it and add warnings about its use.

In addition add info on how to set kernel parameters on boot for
the various options that are covered.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/722
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2021-03-15 15:24:43 -07:00
Mikhail Morfikov
5ad5dd0bcb abstractions: Fix wayland abstraction for compositors based on wlroots
Apparmor provides the wayland abstraction, but it looks like it misses
some rules. For instance, there are many wayland compositors which are
based on wlroots, and it looks like that when you try to use such
compositor, all GUI apps executed in the graphical environment can't
work properly (they don't event start). They all want the following
rule:

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/143
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/725
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-03-15 05:54:39 -07:00
John Johansen
2852e1ecdf parser: fix filter slashes for link targets
The parser is failing to properly filter the slashes in the link name
after variable expansion. Causing match failures when multiple slashes
occur.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/153
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/723
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2021-03-15 00:45:58 -07:00
Mikhail Morfikov
d4e0a94511 abstractions: Add missing rule in wutmp abstraction
Currently the wutmp abstraction has the following rules:
  /var/log/lastlog  rwk,
  /var/log/wtmp     wk,
  @{run}/utmp       rwk,

According to what I see in my apparmor profiles, just a few apps want
to interact with the files listed above, especially with the
/var/log/wtmp . But when the apps do this, they sometimes want the
read access to this file. An example could be the last command. Is
there any reason for not having the r in the rule?  The second thing
is the file /var/log/btmp (which isn't included in the
abstracion). Whenever I see an app, which wants to access the
/var/log/wtmp file, it also tries to interact with the /var/log/btmp
file, for instance lightdm/sddm or su . Most of the time they need
just wk permissions, but sometimes apps need also r on this file, an
example could be the lastb command, which is just a link to last.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/152
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/724
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-03-14 11:50:43 -07:00
John Johansen
fe477af62a libapparmor: alphasort directory traversals
Directory traversal does not have a guaranteed walk order which can
cause ordering problems on profile loads when explicit dependencies
are missing.

Combined with MR:703 this provides a userspace work around for issue
147.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/147
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/706
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2021-03-14 07:22:59 -07:00
John Johansen
855dbd4ac8 parser: fix rule downgrade for unix rules
Rule downgrades are used to provide some confinement when a feature
is only partially supported by the kernel.

  Eg. On a kernel that doesn't support fine grained af_unix mediation
      but does support network mediation.

        unix (connect, receive, send)
              type=stream
              peer=(addr="@/tmp/.ICE-unix/[0-9]*"),

      will be downgraded to

        network unix type=stream,

Which while more permissive still provides some mediation while
allowing the appication to still function. However making the rule
a deny rule result in tightening the profile.

  Eg.
        deny unix (connect, receive, send)
              type=stream
              peer=(addr="@/tmp/.ICE-unix/[0-9]*"),

      will be downgraded to

        deny network unix type=stream,

and that deny rule will take priority over any allow rule. Which means
that if the profile also had unix allow rules they will get blocked by
the downgraded deny rule, because deny rules have a higher priority,
and the application will break. Even worse there is no way to add the
functionality back to the profile without deleting the offending deny
rule.

To fix this we drop deny rules that can't be downgraded in a way that
won't break the application.

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1180766
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/700
Signed-off-by: John Johansen <john.johansen@canonical.com>
2021-03-14 07:16:24 -07:00
John Johansen
3f51877220 Merge Improve and simplify profile parsing in the tools
This is done by introducing a match_line_against_rule_classes() function to get of repeating code in parse_profile_data().

A side effect is a better separation of preamble and profile data, which needed changes at several places - especially include rules in the preamble were funny\[tm\].

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/719
Acked-by: John Johansen <john.johansen@canonical.com>
2021-03-14 11:59:36 +00:00
Christian Boltz
aaad284d8d Handle include rules in match_line_against_rule_classes()
This needed several changes because so far data for all includes was
stored in include[]. However, preamble data for everything else gets
stored in active_profiles (and with this commit, preamble includes also
get stored in active_profiles).

The needed changes to store preamble includes in active_profiles are:

* include_list_recursive(): add and honor in_preamble flag

* add this flag at several places calling include_list_recursive() for
  a preamble

* parse_profile_data(): call active_profiles.init_file() for all files.
  Before, empty/comment-only files weren't (indirectly) added to
  active_profiles because none of the add_$ruletype functions was
  called, which could lead to KeyErrors for comment-only preamble include
  files (prevented by the now-obsolete and removed check in
  get_all_merged_variables()).
2021-03-08 01:15:12 +01:00
Christian Boltz
3448127ca6 Also parse preamble rules with match_line_against_rule_classes()
For this, we have to hand over in_preamble, and to do a slightly
different handling for preamble and profile rules.

For adding preamble rules to ProfileList, add a add_rule() function that
accepts the rule type as parameter. This is easier than using one of the
add_$type functions depending on the rule type.

With this change, match_line_against_rule_classes() handles nearly all
rule types that have a *Rule class, with the exception of include rules
which need some additional work.
2021-03-07 21:33:36 +01:00
Christian Boltz
accc380326 Add in_preamble parameter to profile loading/parsing functions
in_preamble keeps track of the current parsing position.

It's True while parsing the preamble of a profile file, and when loading
an include file that is included in the preamble (typically tunables/*).

While inside a profile or parsing abstractions/*, it is False.

This commit only hands the information around and keeps in_preamble
updated, but it doesn't really get used yet.

Also adjust the tests to hand over the additional parameter to
parse_profile_data().
2021-03-07 21:33:36 +01:00
Christian Boltz
d442620102 Add match_line_against_rule_classes()
... to handle parsing of lines that are managed with a *Rule

This needs 'ruletypes' to also know about *Rule, not only about
*Ruleset.

Also switch over handling of most rules that live inside a profile from
parse_profile() to match_line_against_rule_classes() to make
parse_profile() more readable.

Exceptions are:
- include and abi, which can also exist in the preamble
- file rules, because they'd need to be handled later (after variable
  definitions)
2021-03-07 21:33:36 +01:00
John Johansen
089b266c03 Merge Use parse() instead of _parse() in LogprofHeaderTest
The \*LogprofHeaderTest accidently used the private `_parse()` insteaf of the official `parse()`.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/718
Acked-by: John Johansen <john.johansen@canonical.com>
2021-03-07 17:43:46 +00:00
John Johansen
55a7c89117 Merge update postfix profiles
Update postfix profiles:

* cleanup postfix profiles - /etc/postfix/\*.db is covered by abstractions/postfix-common
* postfix: allow access to \*.lmdb files in addition to \*.db files. (openSUSE Tumbleweed now uses the lmdb format by default.)
* postfix-flush and -showq: add permissions needed with latest postfix as seen on openSUSE Tumbleweed

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/717
Acked-by: John Johansen <john.johansen@canonical.com>
2021-03-07 17:28:47 +00:00
Christian Boltz
4c77f7193b Use parse() instead of _parse() in LogprofHeaderTest
The *LogprofHeaderTest accidently used the private _parse() insteaf of
the official parse().
2021-03-07 18:28:27 +01:00
John Johansen
c2718e2677 Merge Improve AARE documentation in apparmor.d manpage
... as discussed on the mailinglist

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/715
Acked-by: John Johansen <john.johansen@canonical.com>
2021-03-07 17:25:36 +00:00
John Johansen
447ce37b47 Merge loadincludes(): only load tunables and abstractions
Also split out parts of the function into loadincludes_dir() to keep the code readable.

Note: This change might affect the list of includes proposed by aa-logprof.

Also drop is_skippable_dir()

Since loadincludes() now only loads a specified list of subdirectories, we no longer need a directory blacklist.

The only possibly remaining part are .git subdirectories (for example tunables/.git or abstractions/.git). Since it's very unlikely that someone would have only a subdirectory of /etc/apparmor.d/ in git, drop that check.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/714
Acked-by: John Johansen <john.johansen@canonical.com>
2021-03-07 17:22:35 +00:00
Christian Boltz
08719eebc1 postfix-flush and -showq: add permissions needed with latest postfix
... as seen on openSUSE Tumbleweed
2021-03-07 14:33:59 +01:00
Christian Boltz
a07f30e25d postfix: allow access to *.lmdb files
... in addition to *.db files.

openSUSE Tumbleweed now uses the lmdb format by default.
2021-03-07 14:33:49 +01:00
Christian Boltz
32bd2bcec3 cleanup postfix profiles
/etc/postfix/*.db is covered by abstractions/postfix-common
2021-03-07 14:33:37 +01:00
Christian Boltz
cc2d71023b Improve AARE documentation in apparmor.d manpage
... as discussed on the mailinglist
2021-03-01 19:40:50 +01:00
Christian Boltz
d0693b09b5 Drop is_skippable_dir()
Since loadincludes() now only loads a specified list of subdirectories,
we no longer need a directory blacklist.

The only possibly remaining part are .git subdirectories (for example
tunables/.git or abstractions/.git). Since it's very unlikely that
someone would have only a subdirectory of /etc/apparmor.d/ in git, drop
that check.
2021-02-25 13:08:22 +01:00
Christian Boltz
bb5ca91e7e loadincludes(): only load tunables and abstractions
Also split out parts of the function into loadincludes_dir() to keep the
code readable.

Note: This change might affect the list of includes proposed by
aa-logprof.
2021-02-25 12:59:12 +01:00
Christian Boltz
0f21ca6173 Merge branch 'cboltz-parse-profile-start' into 'master'
split off parse_profile_start_to_storage() from parse_profile_data()

See merge request apparmor/apparmor!710

Acked-by: Steve Beattie <steve.beattie@canonical.com>
2021-02-25 11:20:52 +00:00
Christian Boltz
0f1d5fdba4 Merge branch 'cboltz-preamble-ruletypes' into 'master'
profile_list: add preamble_ruletypes

See merge request apparmor/apparmor!708

Acked-by: Steve Beattie <steve.beattie@canonical.com>
2021-02-25 11:20:04 +00:00
John Johansen
d5de9692ab Merge parser: replace dynamic_cast with is_type method
The dynamic_cast operator is slow as it needs to look at RTTI information and even does some string comparisons, especially in deep hierarchies. Profiling with callgrind showed that dynamic_cast can eat a huge portion of the running time, as it takes most of the time that is spent in the simplify_tree() function. For some complex profiles, the number of calls to dynamic_cast can be in the range of millions.

This commit replaces the use of dynamic_cast in the Node hierarchy with a method called is_type(), which returns true if the pointer can be casted to the specified type. It works by looking at an Node object field that is an integer with bits set for each type up in the hierarchy. Therefore, dynamic_cast is replaced by a simple bits operation.

In my tests, for complex profiles the improvement in speed even made running apparmor_parser with "-O no-expr-simplify" slower that when simplifying, apparently because the smaller trees obtained after the expression simplification require less calls to DFA::update_state_transitions(), and that compensates the now significantly slower time spent in simplify_tree(). This opens the door to maybe avoid "-O no-expr-simplify" in the snapd daemon, thus allowing faster run-time checks in the kernel.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/711
Acked-by: John Johansen <john.johansen@canonical.com>
2021-02-17 03:44:23 +00:00
John Johansen
b6fbe10d11 parser: fix build issue with REALLOCARRAY check
On some systems the build of the parser is spitting out

cc: fatal error: no input files
compilation terminated.

This is being caused by the REALLOCARRAY checkfailing due to cpp trying
to check for both input and output files and not correctly falling
back to stdin/stdout if infile and outfile aren't specified.

Fix this by being explicit that infile and outfile are supposed to
use stdin and stdout.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/712
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2021-02-16 04:50:34 -08:00
Alfonso Sánchez-Beato
5aab543a3b parser: replace dynamic_cast with is_type method
The dynamic_cast operator is slow as it needs to look at RTTI
information and even does some string comparisons, especially in deep
hierarchies like the one for Node. Profiling with callgrind showed
that dynamic_cast can eat a huge portion of the running time, as it
takes most of the time that is spent in the simplify_tree()
function. For some complex profiles, the number of calls to
dynamic_cast can be in the range of millions.

This commit replaces the use of dynamic_cast in the Node hierarchy
with a method called is_type(), which returns true if the pointer can
be casted to the specified type. It works by looking at a Node object
field that is an integer with bits set for each type up in the
hierarchy. Therefore, dynamic_cast is replaced by a simple bits
operation.

This change can reduce the compilation times for some profiles more
that 50%, especially in arm/arm64 arch. This opens the door to maybe
avoid "-O no-expr-simplify" in the snapd daemon, as now that option
would make the compilation slower in almost all cases.

This is the example profile used in some of my tests, with this change
the run-time is around 1/3 of what it was before on an x86 laptop:

profile "test" (attach_disconnected,mediate_deleted) {
dbus send
    bus={fcitx,session}
    path=/inputcontext_[0-9]*
    interface=org.fcitx.Fcitx.InputContext
    member="{Close,Destroy,Enable}IC"
    peer=(label=unconfined),
dbus send
    bus={fcitx,session}
    path=/inputcontext_[0-9]*
    interface=org.fcitx.Fcitx.InputContext
    member=Reset
    peer=(label=unconfined),
dbus receive
    bus=fcitx
    peer=(label=unconfined),
dbus receive
    bus=session
    interface=org.fcitx.Fcitx.*
    peer=(label=unconfined),
dbus send
    bus={fcitx,session}
    path=/inputcontext_[0-9]*
    interface=org.fcitx.Fcitx.InputContext
    member="Focus{In,Out}"
    peer=(label=unconfined),
dbus send
    bus={fcitx,session}
    path=/inputcontext_[0-9]*
    interface=org.fcitx.Fcitx.InputContext
    member="{CommitPreedit,Set*}"
    peer=(label=unconfined),
dbus send
    bus={fcitx,session}
    path=/inputcontext_[0-9]*
    interface=org.fcitx.Fcitx.InputContext
    member="{MouseEvent,ProcessKeyEvent}"
    peer=(label=unconfined),
dbus send
    bus={fcitx,session}
    path=/inputcontext_[0-9]*
    interface=org.freedesktop.DBus.Properties
    member=GetAll
    peer=(label=unconfined),
dbus (send)
    bus=session
    path=/org/a11y/bus
    interface=org.a11y.Bus
    member=GetAddress
    peer=(label=unconfined),
dbus (send)
    bus=session
    path=/org/a11y/bus
    interface=org.freedesktop.DBus.Properties
    member=Get{,All}
    peer=(label=unconfined),
dbus (receive, send)
    bus=accessibility
    path=/org/a11y/atspi/**
    peer=(label=unconfined),
dbus (send)
    bus=system
    path=/org/freedesktop/Accounts
    interface=org.freedesktop.DBus.Introspectable
    member=Introspect
    peer=(label=unconfined),
dbus (send)
    bus=system
    path=/org/freedesktop/Accounts
    interface=org.freedesktop.Accounts
    member=FindUserById
    peer=(label=unconfined),
dbus (receive, send)
    bus=system
    path=/org/freedesktop/Accounts/User[0-9]*
    interface=org.freedesktop.DBus.Properties
    member={Get,PropertiesChanged}
    peer=(label=unconfined),
dbus (send)
    bus=session
    interface=org.gtk.Actions
    member=Changed
    peer=(name=org.freedesktop.DBus, label=unconfined),
dbus (receive)
    bus=session
    interface=org.gtk.Actions
    member={Activate,DescribeAll,SetState}
    peer=(label=unconfined),
dbus (receive)
    bus=session
    interface=org.gtk.Menus
    member={Start,End}
    peer=(label=unconfined),
dbus (send)
    bus=session
    interface=org.gtk.Menus
    member=Changed
    peer=(name=org.freedesktop.DBus, label=unconfined),
dbus (send)
    bus=session
    path="/com/ubuntu/MenuRegistrar"
    interface="com.ubuntu.MenuRegistrar"
    member="{Register,Unregister}{App,Surface}Menu"
    peer=(label=unconfined),
}
2021-02-16 10:23:10 +01:00
Christian Boltz
f7a365f89f Simplify handling of in_contained_hat
in_contained_hat is needed to know if we are already in a profile or
not. (Simply checking if we are in a hat doesn't work, because something
like "profile foo//bar" will set profile and hat at once, and later
(wrongfully) expect another "}".

However, the way how this variable was set became too complicated.

To simplify the code, set in_contained_hat directly in
parse_profile_data() RE_PROFILE_START instead of returning it via
parse_profile_start() and parse_profile_start_to_storage()

Since this change removes a return value from two functions, also adjust
the tests accordingly.
2021-02-14 23:08:38 +01:00
Christian Boltz
7cfda2772d split off parse_profile_start_to_storage() from parse_profile_data()
parse_profile_start_to_storage() converts the result of
parse_profile_start() into a ProfileStorage object.

No functional change, but parse_profile_data() becomes more readable.

Also extend tests to cover parse_profile_start_to_storage().
2021-02-14 23:08:30 +01:00
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
John Johansen
44aa30cf2a Merge aa-autodep: load abstractions on start
So far, aa-autodep "accidently" loaded the abstractions when parsing the existing profiles. Obviously, this only worked if there is at least one profile in the active or extra profile directory.

Without any existing profiles, aa-autodep crashed with KeyError: '/tmp/apparmor.d/abstractions/base'

Prevent this crash by explicitely loading the abstractions on start.

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1178527
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/682
Acked-by: John Johansen <john.johansen@canonical.com>
2020-11-28 13:10:18 +00:00
John Johansen
e5733d726d Merge Convert gen-xtrans from perl to python
The generated files are exactly the same, but the code is a bit more readable.

Additional differences:

* added test_gen_list() to verify the result of gen_list()
* null_target has a non-empty value to avoid that it gets skipped in loops as empty value
* invert_save has an additional entry for ''
* copyright header added (based on git log of gen-xtrans.pl)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/673
Acked-by: John Johansen <john.johansen@canonical.com>
2020-11-28 13:06:17 +00:00
John Johansen
0af37358e6 Merge Add --configdir to all aa-* utils
Since this option is mostly meant for testing, it will not show up in `--help`.

`aa-notify` was the only tool that honored the `__AA_CONFDIR` env variable. Drop it in favor of the `--configdir` option.

Note: Since we now pass `confdir=` to `init_aa()` (in most cases `None`), setting the default needs to be moved inside the function.

Also use `--configdir` in the tests.

See the individual commits for details.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/670
Acked-by: John Johansen <john.johansen@canonical.com>
2020-11-28 13:02:06 +00:00
John Johansen
af0f16a3bf Merge abstractions/X: Allow (only) reading X compose cache
... (/var/cache/libx11/compose/\*), and deny any write attempts

Reported by darix, https://git.nordisch.org/darix/apparmor-profiles-nordisch/-/blob/master/apparmor.d/teams

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/685
Acked-by: John Johansen <john.johansen@canonical.com>
2020-11-17 10:05:01 +00:00
Christian Boltz
78bd811e2a abstractions/X: Allow (only) reading X compose cache
... (/var/cache/libx11/compose/*), and deny any write attempts

Reported by darix,
https://git.nordisch.org/darix/apparmor-profiles-nordisch/-/blob/master/apparmor.d/teams
2020-11-16 20:42:00 +01:00
Christian Boltz
dfd7c245cd 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.

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1178527#c1 [1]
2020-11-08 15:26:51 +01:00
Christian Boltz
f6b3de7116 aa-autodep: load abstractions on start
So far, aa-autodep "accidently" loaded the abstractions when parsing the
existing profiles. Obviously, this only worked if there is at least one
profile in the active or extra profile directory.

Without any existing profiles, aa-autodep crashed with
KeyError: '/tmp/apparmor.d/abstractions/base'

Prevent this crash by explicitely loading the abstractions on start.

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1178527#c1 [1]
2020-11-08 14:41:33 +01:00
John Johansen
c29357a294 Merge Fix invalid Pux (should be PUx) permissions in dhclient-script
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/676
Acked-by: John Johansen <john.johansen@canonical.com>
2020-11-01 09:43:28 +00:00
John Johansen
e57174589c Merge Fix hotkey conflict in utils de.po and id.po
This is needed to catch conflicts between uppercase and lowercase hotkeys of the same letter, as seen with `(B)enannt` and `A(b)lehnen` in the german utils translations.

Also fix conflicting hotkeys in utils de.po, id.po and sv.po.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/675
Acked-by: John Johansen <john.johansen@canonical.com>
2020-11-01 09:25:18 +00:00
Christian Boltz
7cf54f2cd8 Fix hotkey conflict in utils de.po, id.po and sv.po 2020-10-31 21:59:32 +01:00
Christian Boltz
d08d1a00a3 Fix invalid Pux (should be PUx) permissions in dhclient-script 2020-10-31 20:52:30 +01:00
Christian Boltz
07bd11390e Check hotkey conflicts case-insensitive
This is needed to catch conflicts between uppercase and lowercase
hotkeys of the same letter, as seen with `(B)enannt` and `A(b)lehnen` in
the german utils translations.
2020-10-31 20:21:29 +01:00
Christian Boltz
f3a816d6a5 use aa-notify --configdir in test-aa-notify.py 2020-10-29 21:24:15 +01:00
Christian Boltz
87eec0d62d use aa-logprof --configdir ../utils in profile testsuite
(except if USE_SYSTEM is given)

This also needs an additional parser path in utils/test/logprof.conf,
which then needs an update in test-config.py.
2020-10-29 21:24:15 +01:00
Christian Boltz
ab6e9b2de2 Add --configdir to all aa-* utils
Since this option is mostly meant for testing, it will not show up in
--help.

aa-notify was the only tool that honored the __AA_CONFDIR env variable.
It still does if --configdir is not given.

Note: Since we now pass confdir= to init_aa() (in most cases None),
setting the default needs to be moved inside the function.
2020-10-29 21:24:15 +01:00
John Johansen
53d812cfd2 Merge Update dovecot for SIGKILL and dh.pem denials
Running dovecot on Debian 10 (buster) produced these denials:

```
type=AVC msg=audit(1601314853.031:9327): apparmor="DENIED"
operation="signal" profile="dovecot" pid=21223 comm="dovecot"
requested_mask="send" denied_mask="send" signal=kill
peer="/usr/lib/dovecot/auth"

type=AVC msg=audit(1601315453.655:9369): apparmor="DENIED"
operation="signal" profile="dovecot" pid=21223 comm="dovecot"
requested_mask="send" denied_mask="send" signal=kill
peer="/usr/lib/dovecot/pop3"

type=AVC msg=audit(1602939754.145:101362): apparmor="DENIED"
operation="signal" profile="dovecot" pid=31632 comm="dovecot"
requested_mask="send" denied_mask="send" signal=kill
peer="/usr/lib/dovecot/pop3-login"
```

And:

```
type=AVC msg=audit(1603647096.369:24514): apparmor="DENIED"
operation="open" profile="dovecot" name="/usr/share/dovecot/dh.pem"
pid=28774 comm="doveconf" requested_mask="r" denied_mask="r" fsuid=0
ouid=0
```

These are fixed in respective comits.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/671
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-26 22:14:50 +00:00
Christian Boltz
6b96a9badc Convert gen-xtrans from perl to python
The generated files are exactly the same, but the code is a bit more
readable.

Additional differences:
- added test_gen_list() to verify the result of gen_list()
- null_target has a non-empty value to avoid that it gets skipped in
  loops as empty value
- invert_save has an additional entry for ''
- copyright header added (based on git log of gen-xtrans.pl)
2020-10-26 00:28:16 +01:00
Vincas Dargis
9d8e111abe dovecot: allow reading dh.pem
Dovecot is hit with this denial on Debian 10 (buster):
```
type=AVC msg=audit(1603647096.369:24514): apparmor="DENIED"
operation="open" profile="dovecot" name="/usr/share/dovecot/dh.pem"
pid=28774 comm="doveconf" requested_mask="r" denied_mask="r" fsuid=0
ouid=0
```

This results in fatal error:

```
Oct 25 19:31:36 dovecot[28774]: doveconf: Fatal: Error in configuration
file /etc/dovecot/conf.d/10-ssl.conf line 50: ssl_dh: Can't open file
/usr/share/dovecot/dh.pem: Permission denied
```

Add rule to allow reading dh.pem.
2020-10-25 19:30:10 +02:00
Vincas Dargis
2f9d172c64 dovecot: allow kill signal
Dovecot might try to kill related processes:

```
type=AVC msg=audit(1601314853.031:9327): apparmor="DENIED"
operation="signal" profile="dovecot" pid=21223 comm="dovecot"
requested_mask="send" denied_mask="send" signal=kill
peer="/usr/lib/dovecot/auth"

type=AVC msg=audit(1601315453.655:9369): apparmor="DENIED"
operation="signal" profile="dovecot" pid=21223 comm="dovecot"
requested_mask="send" denied_mask="send" signal=kill
peer="/usr/lib/dovecot/pop3"

type=AVC msg=audit(1602939754.145:101362): apparmor="DENIED"
operation="signal" profile="dovecot" pid=31632 comm="dovecot"
requested_mask="send" denied_mask="send" signal=kill
peer="/usr/lib/dovecot/pop3-login"
```
This discovered on low-power high-load machine (last resort timeout
handling?).

Update signal rule to allow SIGKILL.
2020-10-25 19:12:42 +02:00
John Johansen
11d3218519 Merge Fix typos
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/669
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-25 12:01:27 +00:00
intrigeri
d6e18b0db8 Fix typos
Spotted by Lintian.
2020-10-25 11:54:56 +00:00
intrigeri
0da70b173c apparmor_xattrs.7: fix whatis entry
Spotted by Lintian (bad-whatis-entry).
2020-10-25 11:54:47 +00:00
John Johansen
0cb35fda84 Merge profiles/apparmor.d/abstractions/X: make x11 socket writable again
Unfortunately in apparmor sockets need `rw` access. Currently x11 can only work if abstract socket is available and used instead so those restrictions won't trigger.

partially reverts c7b8368216

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/664
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-25 11:32:06 +00:00
John Johansen
24855edd11 Merge Add Fontmatrix to abstractions/fonts
[Fontmatrix](https://github.com/fontmatrix/fontmatrix) [adds \~/.Fontmatrix/Activated to fonts.conf](https://github.com/fontmatrix/fontmatrix/blob/75552e2/src/typotek.cpp#L1081-L1088). This causes programs which use [Fontconfig](https://gitlab.freedesktop.org/fontconfig/fontconfig) (directly or indirectly through libraries such as [Pango](https://pango.gnome.org/)) to include that directory in their font search path, which causes errors such as:

```
audit: type=1400 audit(1602678958.525:53): apparmor="DENIED" operation="open" profile="fr.emersion.Mako" name="/home/username/.Fontmatrix/Activated/.uuid" pid=48553 comm="mako" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000
audit: type=1400 audit(1602678958.525:54): apparmor="DENIED" operation="open" profile="fr.emersion.Mako" name="/home/username/.Fontmatrix/Activated/" pid=48553 comm="mako" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000
```

if the program does not explicitly include this directory in its AppArmor profile. As with other common font locations, add `~/.Fontmatrix/Activated` to the fonts abstraction for read-only access.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/657
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-25 11:24:58 +00:00
John Johansen
32d748ab0f Merge add Dovecot and other mail related profiles
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/644
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-25 11:22:24 +00:00
John Johansen
1961bb7719 Merge Adjust to support brave in ubuntu abstractions
See Bug-Ubuntu: https://launchpad.net/bugs/1889699

Fixes: https://launchpad.net/bugs/1889699
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/667
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-25 11:13:43 +00:00
John Johansen
3ff07adda5 Merge Adjust ubuntu-integration to use abstractions/exo-open
see Bug-Ubuntu: https://launchpad.net/bugs/1891338

Fixes: https://launchpad.net/bugs/1891338
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/666
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-25 11:11:39 +00:00
Christian Boltz
dbb1b900b8 Merge branch 'adjust-for-new-ICEauthority-path-in-run' into 'master'
Adjust for new ICEauthority path in /run

Bug-Ubuntu: https://launchpad.net/bugs/1881357

See merge request apparmor/apparmor!668


Acked-by: Christian Boltz <apparmor@cboltz.de> for 3.0 and master
2020-10-25 10:16:26 +00:00
Jamie Strandboge
1abe101734 Adjust for new ICEauthority path in /run
Bug-Ubuntu: https://launchpad.net/bugs/1881357
2020-10-25 09:56:34 +00:00
Francois Marier
9b30f9306d Adjust to support brave in ubuntu abstractions
Bug-Ubuntu: https://launchpad.net/bugs/1889699
2020-10-25 09:53:44 +00:00
Jamie Strandboge
9ff0bbb69e Adjust ubuntu-integration to use abstractions/exo-open
Bug-Ubuntu: https://launchpad.net/bugs/1891338
2020-10-25 09:48:25 +00:00
John Johansen
6039d1580a Merge abstractions: mesa - tightens cache location and add fallback
This tightens the cache location in @{HOME}/.cache and also adds the tmp fallback location.

Currently there are the following entries in the mesa abstraction:

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/91
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/652
Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-10-25 09:14:40 +00:00
John Johansen
cfc57c08e6 Merge profiles: nscd: service fails with apparmor 3.0.0-2 on Arch Linux
After a recent upgrade of apparmor on Arch Linux the nscd systemd service fails to start. Arch Linux has /var/db/nscd and that path is missing from the profile AFAICT.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/124
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/651
Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-10-25 09:08:06 +00:00
Erick555
81867f9424 profiles/apparmor.d/abstractions/X: make x11 socket writable again
Unfortunately in apparmor sockets need rw access. Currently x11 can only work if abstract socket is available and used instead so those restrictions won't trigger. This partially reverts c7b8368216
2020-10-23 12:22:10 +00:00
John Johansen
15dc06248c utils: fix make -C profiles check-logprof fails
On arch
  make -C profiles check-logprof

fails with
  *** Checking profiles from ./apparmor.d against logprof

  ERROR: Can't find AppArmor profiles in /etc/apparmor.d
  make: *** [Makefile:113: check-logprof] Error 1
  make: Leaving directory '/build/apparmor/src/apparmor-2.13.3/profiles'

because /etc/apparmor.d/ is not available in the build environment
and aa-logprofs --dir argument, is not being passed to init_aa()
but used to update profiles_dir after the fact.

Fix this by passing profiledir as an argument to init_aa()

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/36
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/663
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-10-22 14:56:09 -07:00
John Johansen
8ea7630b6d aa-notify: Stop aa-notify from exit after 100s of polling
When run with the -p flag, aa-notify works fine for 100 seconds and then it exits.
I suspect that the issue arises from the following check on line 259 in utils/aa-notify
if debug_logger.debug_level <= 10 and int(time.time()) - start_time > 100:
    debug_logger.debug('Debug mode detected: aborting notification emitter after 100 seconds.')
    sys.exit(0)
together with line 301 in utils/apparmor/common.py which initializes debug_logger.debug_level to logging.DEBUG which has the numerical value 10.
A simple solution might be to just remove the check as I'm not quit sure why one would want aa-notify to exit when run in debug mode in the first place.
Alternatively, one could check against debug_logger.debugging (initialized to False) or change the initialization of debug_logger.debug_level to something else, but I don't know how that would affect other consumers of utils/apparmor/common.py.

For now just add dbugger_logger.debugging as an additional check as the
reason for timing out after 100s during debugging are unclear.

Suggested-by: vicvbcun
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/126
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/660
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Otto Kekäläinen <otto@kekalainen.net>
2020-10-21 16:59:28 -07:00
John Johansen
43eb54d13c utils: split linting with PYFLAKES into a separate target.
This a step towards addressing the linting of the utils causing
problems in a build vs dev environment. See
  https://gitlab.com/apparmor/apparmor/-/issues/121

Split off linting with PYFLAKES into its own target as a step towards
making the running of the lint checks as a configuration option.

https://gitlab.com/apparmor/apparmor/-/merge_requests/662
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-10-21 16:55:41 -07:00
John Johansen
38c611ed31 Merge Revert "Merge dnsmasq: Permit access to /proc/self/fd/"
This reverts merge request !628. My reason for this proposal is that commit 88c142c6 already provided this change, something I must have missed when I opened the initial merge request. This resulted in duplicate entries in the profile, something that is also potentially confusing to users or other contributors.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/659
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-19 22:22:23 +00:00
FallenWarrior2k
e0b20a4d2f Revert "Merge dnsmasq: Permit access to /proc/self/fd/"
This reverts merge request !628
2020-10-19 20:29:43 +00:00
John Johansen
89fc65592b Merge Add CAP_CHECKPOINT_RESTORE to severity.db
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/656
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-15 09:48:42 +00:00
Kevin Locke
17cb8f0418 Add Fontmatrix to abstractions/fonts
[Fontmatrix] [adds ~/.Fontmatrix/Activated to fonts.conf].  This causes
programs which use [Fontconfig] (directly or indirectly through
libraries such as [pango]) to include that directory in their font
search path, which causes errors such as:

    audit: type=1400 audit(1602678958.525:53): apparmor="DENIED" operation="open" profile="fr.emersion.Mako" name="/home/username/.Fontmatrix/Activated/.uuid" pid=48553 comm="mako" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000
    audit: type=1400 audit(1602678958.525:54): apparmor="DENIED" operation="open" profile="fr.emersion.Mako" name="/home/username/.Fontmatrix/Activated/" pid=48553 comm="mako" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000

if the program does not explicitly include this directory in its
AppArmor profile.  As with other common font locations, add
~/.Fontmatrix/Activated to the fonts abstraction for read-only access.

[Fontconfig]: https://gitlab.freedesktop.org/fontconfig/fontconfig
[Fontmatrix]: https://github.com/fontmatrix/fontmatrix
[Pango]: https://pango.gnome.org/
[adds ~/.Fontmatrix/Activated to fonts.conf]: https://github.com/fontmatrix/fontmatrix/blob/75552e2/src/typotek.cpp#L1081-L1088

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2020-10-14 19:45:23 -06:00
Christian Boltz
2c2dbdc3a3 Add CAP_CHECKPOINT_RESTORE to severity.db 2020-10-14 14:01:55 +02:00
John Johansen
4a226637f5 translations: update generated pot files
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-10-14 03:56:38 -07:00
John Johansen
644a473971 parser: Add support for CAP_CHECKPOINT_RESTORE
Linux 5.9 added CAP_CHECKPOINT_RESTORE add it to the set of supported
capabilities.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/654
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2020-10-13 21:30:19 -07:00
John Johansen
71a51fcb18 Merge regression test: Fix regression tests when using in tree parser
When using the in tree parser we should not be using the system parser.conf file, as if the system apparmor is newer than the tree being tested the parser.conf file could contain options not understood by the in tree apparmor_parser.

Use --config-file to specify the default in tree parser.conf

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/653
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-10-13 12:01:22 +00:00
John Johansen
1033e19171 regression tests: fix aa_policy_cache to use correct config file
The aa_policy_cache test is using the system parser.conf file even
when the tests are set to use source. This can lead to failures
if the system parser.conf contain options not understood by
the source parser.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/653
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-10-13 04:49:59 -07:00
John Johansen
5ac368bce7 regression test: Fix regression tests when using in tree parser
When using the in tree parser we should not be using the system
parser.conf file, as if the system apparmor is newer than the
tree being tested the parser.conf file could contain options not
understood by the in tree apparmor_parser.

Use --config-file to specify the default in tree parser.conf

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/653
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-10-13 04:48:15 -07:00
Mikhail Morfikov
5aa6db68e0 abstractions: mesa - tightens cache location and add fallback
This tightens the cache location in @{HOME}/.cache and also adds
the tmp fallback location.

Currently there are the following entries in the mesa abstraction:

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/91
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-10-11 05:08:32 -07:00
glitsj16
821f9fe42d profiles: nscd: service fails with apparmor 3.0.0-2 on Arch Linux
After a recent upgrade of apparmor on Arch Linux the nscd systemd service fails to start. Arch Linux has /var/db/nscd and that path is missing from the profile AFAICT.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/651
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/124
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-10-11 04:50:49 -07:00
John Johansen
40b7019d72 Merge Fix wording of some warnings
pwarn() prints "Warning" itsself, therefore it doesn't make sense to include/repeat that word in the actual warning text.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/650
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-11 11:34:29 +00:00
John Johansen
21060e802a parser: Fix warning message when complain mode is forced
when a profile is being forced to complain a variation of the
following message is displayed

  Warning from /etc/apparmor.d/usr.sbin.sssd (/etc/apparmor.d/usr.sbin.sssd line 54): Warning failed to create cache: usr.sbin.sssd

This is incorrect in that the parser doesn't even try to create the
cache, it just can't cache force complain profiles.

Output a warning message for this case that is correct.

Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1899218
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/649
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-10-11 03:34:37 -07:00
Christian Boltz
01f5954b5c Fix wording of some warnings
pwarn() prints "Warning" itsself, therefore it doesn't make sense to
include/repeat that word in the actual warning text.
2020-10-11 12:22:23 +02:00
John Johansen
ec19ff9f72 parser: fix parser.conf commenting on pinning an abi
The comments describing the example rules to pin the abi are wrong.
The comments of the two example rules are swapped resulting in confusion.

While we are at it. Add a reference to the wiki doc on abi, and
how to disable abi warnings without pinning.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/648
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2020-10-09 13:25:49 -07:00
John Johansen
042a75a6a5 Merge Fix dhclient and dhclient-script profiles to work on debian buster
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/645
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-08 06:33:08 +00:00
John Johansen
05acf374b1 Merge aa_status: Fix build issue with musl
add limits.h

aa_status.c:269:22: error: 'PATH_MAX' undeclared (first use in this function); did you mean 'AF_MAX'? | 269 | real_exe = calloc(PATH_MAX + 1, sizeof(char));

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/647
Signed-off-by: Armin Kuster [akuster808@gmail.com](mailto:akuster808@gmail.com)
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-08 06:31:02 +00:00
Armin Kuster
0dbcbee700 parser/Makefile: dont force host cpp to detect reallocarray
In cross build environments, using the hosts cpp gives incorrect
detection of reallocarray. Change cpp to a variable.

fixes:
parser_misc.c: In function 'int capable_add_cap(const char*, int, unsigned int, capability_flags)':
| parser_misc.c:297:37: error: 'reallocarray' was not declared in this scope
|   297 |   tmp = (struct capability_table *) reallocarray(cap_table, sizeof(struct capability_table), cap_table_size+1);

Signed-off-by: Armin Kuster <akuster808@gmail.com>
2020-10-07 20:55:52 -07:00
Bernhard M. Wiedemann
bd1e22ad07 profiles: add pyzorsocket and razorsocket
Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
2020-10-07 20:26:01 +02:00
Bernhard M. Wiedemann
c343f052c0 profiles: add haproxy
Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
2020-10-07 20:26:01 +02:00
Bernhard M. Wiedemann
2eea414c68 profiles: add clamd
Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
2020-10-07 20:26:01 +02:00
Bernhard M. Wiedemann
8319bc5dc7 profiles: Add 3 more dovecot services
Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
2020-10-07 20:26:01 +02:00
Bernhard M. Wiedemann
286f071259 profile: Allow SSL access to freshclam
Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
2020-10-07 20:12:45 +02:00
Bernhard M. Wiedemann
6e908f28d6 profiles: Drop duplicate line
already covered by dovecot-common

Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
2020-10-07 20:12:45 +02:00
Armin Kuster
a2a0d14b9c aa_status: Fix build issue with musl
add limits.h

aa_status.c:269:22: error: 'PATH_MAX' undeclared (first use in this function); did you mean 'AF_MAX'?
|   269 |    real_exe = calloc(PATH_MAX + 1, sizeof(char));

Signed-off-by: Armin Kuster <akuster808@gmail.com>
2020-10-07 09:10:43 -07:00
Christian Boltz
17c55b3bf8 Merge branch 'master' into 'master'
apparmor: fix manpage order

See merge request apparmor/apparmor!646

Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-10-07 15:48:28 +00:00
Armin Kuster
37b9028499 apparmor: fix manpage order
It trys to create a symlink before the man pages are installed.

 ln -sf aa-status.8 /(path}/apparmor/3.0-r0/image/usr/share/man/man8/apparmor_status.8
 | ln: failed to create symbolic link '{path}/apparmor/3.0-r0/image/usr/share/man/man8/apparmor_status.8': No such file or directory

...

install -d /{path}/apparmor/3.0-r0/image/usr/share/man/man8 ; install -m 644 aa-status.8 /{path}/apparmor/3.0-r0/image/usr/share/man/man8;

Signed-off-by: Armin Kuster <akuster808@gmail.com>
2020-10-07 06:30:33 -07:00
Anton Nesterov
9b70ef4fb7 Fix dhclient and dhclient-script profiles to work on debian buster 2020-10-06 19:51:07 +00:00
John Johansen
6e7d1b6baa Merge Skip test if it can not access /var/log/wtmp
utils/test/test-aa-notify.py: Change `AANotifyTest.test_entries_since_login()` to be decorated by a `skipUnless()` checking for existence of **/var/log/wtmp** (similar to `AANotifyTest.test_entries_since_login_verbose()`). The test otherwise fails trying to access /var/log/wtmp in environments where the file is not available.

Closes https://gitlab.com/apparmor/apparmor/-/issues/120
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/641
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-05 00:01:22 +00:00
John Johansen
1909561150 Merge Test for full parser error messages, not parts
By using assertIn, we test if a given message is contained in the parser error message. This can (and actually does) hide errors if the error message changes outside the checked part.

Change the test to assertEqual to test the full error message, and add '\\n' to all expected error messages to make them still match.

Note: test_modefail() has an outdated error message which went unnoticed so far, and should cause the (updated) tests to fail.

I'll add another commit that adjusts the expected test_modefail() error message as soon as we have an official test failure.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/632
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-04 23:58:52 +00:00
Christian Boltz
3f752fac5f Ensure empty stderr if no errors are expected
... instead of not checking stderr if it's expected to be empty.
2020-10-04 19:51:54 +02:00
Christian Boltz
37552669d4 Test for full parser error messages, not parts
By using assertIn, we test if a given message is contained in the parser
error message. This can (and actually does) hide errors if the error
message changes outside the checked part.

Change the test to assertEqual to test the full error message, and add
'\n' to all expected error messages to make them still match.

Depending on the kernel version and patches, there can be an additional
message
    Cache read/write disabled: interface file missing. (Kernel needs AppArmor 2.4 compatibility patch.)
which will be ignored by the check.
2020-10-04 19:51:54 +02:00
John Johansen
e6e54dc9e7 Merge libapparmor: add missing include for socklen_t
While `include/sys/apparmor.h` makes use of `socklen_t`, it doesn't include the `<sys/socket.h>` header to make its declaration available. While this works on systems using glibc via transitive includes, it breaks compilation on musl libc.

Fix the issue by including the header.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/642
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-03 20:15:17 +00:00
John Johansen
4a89067c1a Merge Symbol visibility
This fixes two issues with symbol visibility that's exposed when linking `apparmor_parser`.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/643
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-03 19:21:15 +00:00
Patrick Steinhardt
9a8fee6bf1 libapparmor: add _aa_asprintf to private symbols
While `_aa_asprintf` is supposed to be of private visibility, it's used
by apparmor_parser and thus required to be visible when linking. This
commit thus adds it to the list of private symbols to make it available
for linking in apparmor_parser.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2020-10-03 21:08:41 +02:00
Patrick Steinhardt
c9255a0343 libapparmor: add aa_features_new_from_file to public symbols
With AppArmor release 3.0, a new function `aa_features_new_from_file`
was added, but not added to the list of public symbols. As a result,
it's not possible to make use of this function when linking against
libapparmor.so.

Fix the issue by adding it to the symbol map.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2020-10-03 21:08:37 +02:00
Patrick Steinhardt
47263a3a74 libapparmor: add missing include for socklen_t
While `include/sys/apparmor.h` makes use of `socklen_t`, it doesn't
include the `<sys/socket.h>` header to make its declaration available.
While this works on systems using glibc via transitive includes, it
breaks compilation on musl libc.

Fix the issue by including the header.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2020-10-03 20:42:51 +02:00
David Runge
e0200b1b16 Skip test if it can not access /var/log/wtmp
utils/test/test-aa-notify.py:
Change `AANotifyTest.test_entries_since_login()` to be decorated by a
`skipUnless()` checking for existence of **/var/log/wtmp** (similar to
`AANotifyTest.test_entries_since_login_verbose()`).
The test otherwise fails trying to access /var/log/wtmp in environments
where the file is not available.

Fixes #120
2020-10-02 23:58:53 +02:00
John Johansen
5d51483bfe Prepare for AppArmor 3.0 release
- update Version file
- keep lib version updated in beta

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-10-01 09:50:10 -07:00
John Johansen
c9d5ba4a0d Merge parser: Fix parser FTBS due to reallocarray
Older glibcs and alternate libcs don't have reallocarray()

So define it if not defined by libc.

Closes item 3 of https://gitlab.com/apparmor/apparmor/-/issues/109
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/639
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-10-01 02:37:31 -07:00
John Johansen
8cf3534a5b tests regression: fix failure on older versions of Make
Older versions of Make will choke on the # character in the $(shell
expression, treating it as the beginning of a comment. Resulting in
the following error

make unterminated call to function 'shell': missing ')'.  Stop.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/639
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-10-01 02:33:12 -07:00
John Johansen
709fd0e930 parser: Fix parser FTBS due to reallocarray
Older glibcs and alternate libcs don't have reallocarray()

So define it if not defined by libc.

Fixes: #3 of https://gitlab.com/apparmor/apparmor/-/issues/109
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/639
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-10-01 02:33:12 -07:00
John Johansen
bee9f94eab parser: fix bison error message output when built against bison 3.6+
bison change the default text past to yerror in bison 3.6, this
breaks make check as some tests are comparing against the error
output

======================================================================
FAIL: test_modefail (__main__.AAErrorTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jj/apparmor.git/parser/tst/testlib.py", line 50, in new_unittest_func
    return unittest_func(self)
  File "./errors.py", line 58, in test_modefail
    self._run_test(
  File "./errors.py", line 40, in _run_test
    self.assertIn(message, outerr, report)
AssertionError: 'AppArmor parser error for errors/modefail.sd in profile errors/modefail.sd at line 6: syntax error, unexpected TOK_ID, expecting TOK_MODE' not found in 'AppArmor parser error for errors/modefail.sd in profile errors/modefail.sd at line 6: syntax error\n' :
Command: ../apparmor_parser --config-file=./parser.conf -S -I errors errors/modefail.sd
Exit value:1
STDERR
AppArmor parser error for errors/modefail.sd in profile errors/modefail.sd at line 6: syntax error

To fix this we need to add

define parse.error=verbose

to bison. Unfortunately define parse.error was only added in bison 3.0
and and older versions of bison will break if that is defined in
parser_yacc.y

Instead test for the version of bison available and set define parse.error
as a build flag if supported by the version of bison being called.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/640
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-10-01 02:17:09 -07:00
John Johansen
882380ad3d parser: enable variable expansion for mount type= and options=
Currently mount options type= and options= do not expand variables
but they should. Fix it.

Note: this does not treat either as paths because their use is
too device dependent for it to be safe to filter slashes.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/638
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-10-01 02:11:37 -07:00
John Johansen
2e5a266eb7 regression tests: Don't build syscall_sysctl if missing kernel headers
sys/sysctl.h is not guaranteed to exist anymore since
https://sourceware.org/pipermail/glibc-cvs/2020q2/069366.html

which is a follow on to the kernel commit
61a47c1ad3a4 sysctl: Remove the sysctl system call

While the syscall_sysctl currently checks if the kernel supports
sysctrs before running the tests. The tests can't even build if the
kernel headers don't have the sysctl defines.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/119
Fixes: https://bugs.launchpad.net/apparmor/+bug/1897288
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/637
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-09-29 11:21:01 -07:00
John Johansen
0f1493d640 Merge parser: Fix expansion of variables in the profile rules
The parser is not handling variable expansion/rule conditionals
correctly in some cases. Eg. NOT treating unix addr as a path and
filtering slashes after variable expansion. This can lead to errors
where

@{foo}=/a/ unix bind addr=@{foo}/bar,

will always fail because addr is being matched as /a//bar instead of
/a/bar.

Note: this is a first pass and may not fix all cases. Eg. There is a
known issue with profile names not being able to begin with a
variable.

Signed-off-by: John Johansen john.johansen@canonical.com
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-09-29 04:46:32 -07:00
Steve Beattie
74df38e284 parser sanity tests: add more mount options tests
Attempt to get clarity on what is valid syntax for mount options and
fstype options.

Note that simple_tests/mount/bad_opt_27.sd is marked TODO, as the
parser accepts it but should not.

Also mark the tests as expecting to fail to raise an exception by the
python utils.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:39:16 -07:00
Steve Beattie
8f382f5c6b parser: add unix peer addr slash filter equality tests
Test to ensure that slash filtering occurs properly in unix file
peer socket addr paths.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Bug: https://bugs.launchpad.net/apparmor/+bug/1856738
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:39:16 -07:00
Steve Beattie
51aedb2118 parser: add mount path slash filtering equality tests
Test to ensure that slash filtering occurs properly in mount path
components.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:39:16 -07:00
Steve Beattie
80d7e33432 parser: add dbus path slash filtering equality tests
Test to ensure that slash filtering occurs properly in dbus path
components.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:39:16 -07:00
Steve Beattie
9cee676558 parser: add unix addr slash filter equality tests
Test to ensure that slash filtering occurs properly in unix file socket
addr paths.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Bug: https://bugs.launchpad.net/apparmor/+bug/1856738
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:39:16 -07:00
John Johansen
a1978fb1b2 parser: call filter slashes for mount conditionals
The mnt_point and devices conditionals in mount rules are generally
paths and should have slashes filtered after variable expansion.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:14:35 -07:00
John Johansen
35f6d49ec6 parser: call filter slashes for the dbus path conditional
Similar to unix addr rules, the dbus path conditional is more a path
than a profile name and should get its slashes filtered after variable
expansion.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:14:35 -07:00
John Johansen
6af05006d9 parser: Fix expansion of variables in unix rules addr= conditional
The parser is not treating unix addr as a path and filtering slashes
after variable expansion. This can lead to errors where

@{foo}=/a/
unix bind addr=@{foo}/bar,

will always fail because addr is being matched as /a//bar instead of
/a/bar.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Fixes: https://bugs.launchpad.net/apparmor/+bug/1856738
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:14:35 -07:00
John Johansen
46c355345e Merge Add support for upstream v8 abi network mediation in the 4.17 kernel
This adds support for the new v8 network mediation in the 4.17 and later kernels.

It requires that policy either be tagged with an abi rule that support the v8 network, or the policy be pinned with --policy-features= with a feature abit that supports v8 network.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/521
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-09-29 10:44:46 +00:00
John Johansen
0a52cf81e3 parser: add support for autobind sockets
af_unix allows for sockets to be bound to a name that is autogenerated.
Currently this type of binding is only supported by a very generic
rule.

  unix (bind) type=dgram,

but this allows both sockets with specified names and anonymous
sockets. Extend unix rule syntax to support specifying just an
auto bind socket by specifying addr=auto

eg.

  unix (bind) addr=auto,

It is important to note that addr=auto only works for the bind
permission as once the socket is bound to an autogenerated address,
the addr with have a valid unique value that can be matched against
with a regular

  addr=@name

expression

Fixes: https://bugs.launchpad.net/apparmor/+bug/1867216
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/521
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 03:34:56 -07:00
John Johansen
c9d01a325d parser: don't apply exec mapping computations to the policydb
v8 network permissions extend into the range used by exec mapping
so it is important to not blindly do execmapping on both the
file dfa and policydb dfa any more.

Track what type of dfa and its permissions we are building so
we can properly apply exec mapping only when building the
file dfa.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/521
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 03:34:47 -07:00
John Johansen
e92478a9c5 parser: add support for kernel 4.17 v8 networking
Make it so the parser can properly support network socket mediation
in the upstream kernel,

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/521
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 03:33:55 -07:00
John Johansen
82cfc9ccc5 Merge Add dovecot-script-login profile
... and allow dovecot to Px to it.

The profile is based on a profile I received in a bugreport, with the actual script factored out. Note that you'll *need* to add a rule to the local/ include to allow executing the actual script, but since the script to execute is configurable, it's basically impossible to add a default rule for it.

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1166007

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/635
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-27 23:56:45 +00:00
John Johansen
037bcecc0e Merge Avoid crash on exec without log events for target profile
If an exec gets denied in enforce mode, there are no log events for the target binary/profile. Therefore, trying to set the final_name for the target will crash with a KeyError.

Check for the existence of hashlog\[aamode\]\[target_profile\] in all exec options to prevent this crash.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/634
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-27 23:54:22 +00:00
John Johansen
11ef957274 binutils: Add tool to enable extraction of the kernel features abi
Add a basic tool for manipulating the apparmor features abi via
libapparmor. This serves as a basic tool and as an example of using
the library api.

Currently its function is limited to extracting the kernel feature
abi and loading a feature abi from a file and then outputing it.

In the future it will pickup the ability to verify the feature
abi, and merge feature abis.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/613
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-09-27 16:28:27 -07:00
Christian Boltz
6e59f454b1 Add dovecot-script-login profile
... and allow dovecot to Px to it.

The profile is based on a profile I received in a bugreport, with the
actual script factored out. Note that you'll _need_ to add a rule to the
local/ include to allow executing the actual script, but since the
script to execute is configurable, it's basically impossible to add a
default rule for it.

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1166007
2020-09-27 16:26:28 +02:00
Christian Boltz
68396e9ae5 Avoid crash on exec without log events for target profile
If an exec gets denied in enforce mode, there are no log events for the
target binary/profile. Therefore, trying to set the final_name for the
target will crash with a KeyError.

Check for the existence of hashlog[aamode][target_profile] in all exec
options to prevent this crash.
2020-09-27 15:05:12 +02:00
John Johansen
4a5db481f1 Merge Add change_profile support to aa-logprof
Note that the log doesn't include enough information for EXEC MODE and EXEC COND, therefore aa-logprof will always propose ALL as EXEC COND (comm= might give a hint about EXEC COND, but isn't good enough).

With the added support in aa-logprof, remove the changeprofile tests from the known-failing list in test-libapparmor-test_multi.py.

Also add another test log (from darix) / expected profile to the libapparmor testsuite.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/631
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-25 10:15:07 +00:00
John Johansen
0dcac24510 Merge aa-logprof: propose 'include' instead of '#include' rules
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/630
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-25 10:12:20 +00:00
John Johansen
1cb8c7885e Merge Remove all conflicting modes when switching profile mode
When switching to complain or enforce mode (for example with aa-complain and aa-enforce), remove conflicting flags like kill and unconfined.

As ground work, change add_or_remove_flag() to allow to add or remove multiple flags. Multiple flags can be given as string (will be split) or as array.

Also add some tests confirming that everything works as expected.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/633
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-25 10:10:24 +00:00
Christian Boltz
de0d4f688e Remove all conflicting modes when switching profile mode
When switching to complain or enforce mode (for example with aa-complain
and aa-enforce), remove conflicting flags like kill and unconfined.
2020-09-24 23:21:54 +02:00
Christian Boltz
a2d3a382a8 add_or_remove_flag(): allow to add or remove multiple flags
Multiple flags can be given as string (will be split) or as array.

Also add some tests confirming that everything works as expected.
2020-09-24 23:21:54 +02:00
John Johansen
692f78cf3f init: Add note about snapd policy and early boot to rc.apparmor.functions
Snapd now loads its own policy via its own systemd unit
https://github.com/snapcore/snapd/pull/8467

If A distro is not using snapd systemd unit then dropping snapd policy
from the apparmor unit is a breaking change, distros will either need
to use the snapd systemd unit or revert

0164fd05 init: stop loading snap policy

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-22 12:23:17 -07:00
Jamie Strandboge
0164fd05d6 init: stop loading the snap policy
snapd now loads its snap policy via its own systemd unit, so stop
loading the snap policy in /var/lib/snapd/apparmor/profiles

Fixs: https://launchpad.net/bugs/1871148
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-22 12:09:47 -07:00
Christian Boltz
7918d8980b Add change_profile support to aa-logprof
Note that the log doesn't include enough information for EXEC MODE and
EXEC COND, therefore aa-logprof will always propose ALL as EXEC COND
(comm= might give a hint about EXEC COND, but isn't good enough).

With the added support in aa-logprof, remove the changeprofile tests
from the known-failing list in test-libapparmor-test_multi.py.

Also add another test log (from darix) / expected profile to the
libapparmor testsuite.
2020-09-20 17:07:18 +02:00
Christian Boltz
eada7a8d44 aa-logprof: propose 'include' instead of '#include' rules 2020-09-20 14:42:25 +02:00
John Johansen
29ef901289 Merge aa-unconfined: support /proc/$pid/attr/apparmor/current and kill mode
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/629
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-18 11:49:00 +00:00
Christian Boltz
f0c27b57b0 aa-unconfined: add support for 'kill' profile mode
... when reading /proc/$pid/attr/{apparmor/,}current

Also add a comment about _not_ adding support for the 'unconfined'
profile mode, because that would give a quite confusing output.
2020-09-18 13:38:50 +02:00
Christian Boltz
5a31e94394 aa-unconfined: also read /proc/$pid/attr/apparmor/current
This means moving the code that reads the 'current' file into a new
function read_proc_current()Then call that function for both
/proc/$pid/attr/apparmor/current (preferred) and /proc/$pid/attr/current
(fallback).
2020-09-18 13:38:43 +02:00
John Johansen
a680c949af Merge dnsmasq: Permit access to /proc/self/fd/
As of [48755ebf](https://www.openhub.net/p/dnsmasq/commits/1679009518), dnsmasq iterates through directory entries in /proc/self/fd/ to find which file descriptors are open to avoid the potentially costly operation of closing all possible file descriptors.

While the current profile does not make dnsmasq inoperable, this change permits AppArmor users running dnsmasq to avoid falling back on the generic code path.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/628
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-18 11:20:01 +00:00
Christian Boltz
324d745656 Merge branch 'fix-hats' into 'master'
profiles: update profiles for the new proc attr interfaces

See merge request apparmor/apparmor!627

Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-09-18 11:17:42 +00:00
John Johansen
9d6db05b52 profiles: update profiles for the new proc attr interfaces
New kernels provide an alternative proc attr interface for apparmor
which is needed for LSM stacking.

Update the remaining profiles that use the old interface to
include access to the new interface.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-18 04:07:24 -07:00
FallenWarrior2k
93a3a30ffd dnsmasq: Permit access to /proc/self/fd/
As of [48755ebf], dnsmasq iterates through directory entries in
/proc/self/fd/ to find which file descriptors are open to avoid the
potentially costly operation of closing all possible file descriptors.

[48755ebf]: https://www.openhub.net/p/dnsmasq/commits/1679009518
2020-09-18 12:56:13 +02:00
John Johansen
1a7d9d9da0 Merge parser: Fix MR625 to emit proc attr access for all situations
MR625 fixed hats not emitting the rule to access the proc interface needed for change_hat, but it broke the rule being emitted for the parent (which used to work).

The proc attr access rule should be emitted for any profile that is a hat OR any profile that contains hats.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/626
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-09-18 10:30:30 +00:00
John Johansen
c05905fff1 Merge Rename postfix.* to postfix-* to match profile names
39ca2adff6 removed the usr.lib.postfix prefix from the filename, but missed to change the remaining dot to a "-" to fully match the profile names.

Note: This affects only master. 2.13 and older still have the `usr.lib.postfix.*` filenames.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/624
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-09-18 10:22:33 +00:00
John Johansen
d1be977667 parser: add equality test to check that change_hat rule is being inserted
This add a test to ensure that the parser is inserting rules to allow
access to the proc interface for change_hat.

Unfortunately the rule the parser inserts is a bare owner write that
we can't replicate in policy as policy write perm maps to create,
append and write.

So to test equality compare profiles using rules granting access to
the proc attr interface except one uses the append permission and
the other uses write. They will differ in permissions unless the
parser inserts the proc attr write rule for change_hat in which
case the permissions will get merged and we have equivalence.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/626
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-18 03:19:33 -07:00
John Johansen
3328225bd4 abstractions: update change_profile abstraction for stacking patch
LSM stacking adds new interfaces
   /proc/<pid>/attr/apparmor/*

that should be used in preference of the old interface files in
   /proc/<pid>/attr/*

The library has already been updated to use the new path but the
abstraction for change_profile has not so accessing the new interface
in a confined application fails.

Fix this by making the abstraction cover the old and new interfaces.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/626
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-17 19:28:36 -07:00
John Johansen
06d403bdac parser: Fix MR625 to emit proc attr access for all situations
MR625 fixed hats not emitting the rule to access the proc interface
needed for change_hat, but it broke the rule being emitted for the
parent (which used to work).

The proc attr access rule should be emitted for any profile that
is a hat OR any profile that contains hats.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/626
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-17 19:28:23 -07:00
John Johansen
5b850c154f parser: Fix automatic adding of rule for change_hat interface
The parser is supposed to add a rule to profiles if they are a hat
or contain hats granting write access to the kernel interfaces
used to perform the change_hat operation.

Unfortunately the check is broken and currently won't add the
rule to hats (it does add it for the parent).

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/625
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-09-17 15:02:37 -07:00
Christian Boltz
405f05aa5d Rename postfix.* to postfix-* to match profile names
39ca2adff6 removed the usr.lib.postfix
prefix from the filename, but missed to change the remaining dot to a
"-" to fully match the profile names.
2020-09-15 22:39:47 +02:00
John Johansen
d6f332ab03 Merge Fix aa-genprof crash if extra profile exists
serialize_profile() assumes that active_profiles has the /etc/apparmor.d/ filename of a profile initialized.

This patch makes sure this is true even when using an extra profile by initializing it in get_profile().

Ideally serialize_profile() shouldn't always use active_profiles, but that will be part of a bigger change.

Reported by zt1024 including a proposed patch on https://gitlab.com/apparmor/apparmor/-/merge_requests/604 but of course ;-) this patch is better because it selectively does the initialization only in the case that needs it.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/623
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-15 10:07:46 +00:00
Christian Boltz
b3f79f4efb Fix aa-genprof crash if extra profile exists
serialize_profile() assumes that active_profiles has the
/etc/apparmor.d/ filename of a profile initialized.

This patch makes sure this is true even when using an extra profile by
initializing it in get_profile().

Ideally serialize_profile() shouldn't always use active_profiles, but
that will be part of a bigger change.

Reported by zt1024 including a proposed patch on
https://gitlab.com/apparmor/apparmor/-/merge_requests/604
but of course ;-) this patch is better because it selectively does the
initialization only in the case that needs it.
2020-09-12 20:25:48 +02:00
John Johansen
69a705707f Merge Pdebug immunix
Convert the two commented-out fprintf() lines in is_merged_x_consistent() to useful debug logging using PDEBUG macro.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/616
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-10 01:06:34 +00:00
John Johansen
37d7f8d8d3 Merge parser: Fix build error when compiling with DEBUG=1
A copy/paste error leads to a build failure due to an undefined variable "name" in parser_misc.c:clear_cap_flag().

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/608
Signed-off-by: Mike Salvatore <mike.salvatore@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-10 01:01:51 +00:00
John Johansen
6055bbd541 Merge postfix-master: allow access to postlog socket
1/1 - allow access to postlog socket

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/622
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-09 03:34:11 +00:00
Christian Boltz
d55ca8b624 postfix-master: allow access to postlog socket 2020-09-08 21:50:39 +02:00
Christian Boltz
358f7192aa Merge branch 'cboltz-rename-php-fpm-profile' into 'master'
Rename php-fpm profile file to just "php-fpm"

See merge request apparmor/apparmor!620
2020-09-08 19:31:18 +00:00
Christian Boltz
a1e03860d9 Rename php-fpm profile file to just "php-fpm"
Nice profile names should also result in nice filenames, at least for
new profiles.

Also update the local include filename.
2020-09-08 20:41:58 +02:00
Christian Boltz
c3fbc3c801 Merge branch 'pulls/php-fpm-fix-profile-name' into 'master'
php-fpm: fix profile name in php-worker

This is analogous to 9892a032.  It allows php-fpm to manage the worker threads by allowing the threads to receive signals from php-fpm (rather than the nonexistent profile `/usr/sbin/php-fpm*`).

See merge request apparmor/apparmor!619

Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-09-06 18:08:33 +00:00
Antonio Russo
8798d44ebe php-fpm: fix profile name in php-worker
Signed-off-by: Antonio Russo <antonio.e.russo@gmail.com>
2020-09-06 05:26:45 -06:00
Christian Boltz
4f781eac3f Merge branch 'fix-php-fpm' into 'master'
Revert "php-fpm: allow only one pid file"

Closes #115

See merge request apparmor/apparmor!617

Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-09-06 09:26:41 +00:00
Mike Salvatore
ec27d87777 parser: Add a debug msg to reset_parser()
A debug message in reset_parser() gives developers more data about how
the parser is behaving. In addition, it provides much needed context to
the relatively vague debug message in clear_cap_flag().

Another solution might be to pass the profile name into
clear_cap_flag(), however, clear_cap_flag() does not need the profile
name, except potentially for debugging purposes.

Signed-off-by: Mike Salvatore <mike.salvatore@canonical.com>
2020-09-05 20:07:21 -04:00
Mike Salvatore
5eaf46b4c0 parser: Fix build error when compiling with DEBUG=1
A copy/paste error leads to a build failure due to an undefined variable
"name" in parser_misc.c:clear_cap_flag().

Signed-off-by: Mike Salvatore <mike.salvatore@canonical.com>
2020-09-05 20:07:15 -04:00
John Johansen
0dfb2b28bb Revert "php-fpm: allow only one pid file"
This reverts commit 64ae865675.

On Debian (unstable), the PID file is stored with the 7.4 version:

/run/php/php-fpm.sock
/run/php/php7.4-fpm.pid
/run/php/php7.4-fpm.sock

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/115
Reported-by:  Antonio Russo <www.antonioerusso.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/617
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-05 11:50:27 -07:00
Mike Salvatore
b947ad96f9 parser: convert commented out fprintf() in immunix.h to PDEBUG() 2020-09-05 09:38:53 -04:00
John Johansen
9e3aaf34af Merge postfix-common: allow reading icu *.dat
several postfix-\* binaries on openSUSE Tumbleweed need to read /usr/share/icu/\[0-9\]*.\[0-9\]*/\*.dat.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/615
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-05 09:42:53 +00:00
Christian Boltz
39ef7c508f postfix-common: allow reading icu *.dat
several postfix-* binaries on openSUSE Tumbleweed need to read
/usr/share/icu/[0-9]*.[0-9]*/*.dat.
2020-09-04 23:14:54 +02:00
Mike Salvatore
e2237057af parser: Fix formatting in immunix.h:is_merged_x_consistent() 2020-09-04 12:10:35 -04:00
John Johansen
0dc86bfeb3 profiles: fixup chromium profile
- drop out dated maintenance comment
- cleanup profile name rules, and fix a few broken references
- /usr/lib -> /{usr,}/lib
- lib -> lib{,32,64}

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/611
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-09-03 11:44:19 -07:00
John Johansen
6e5ad15adf Merge nvidia_modprobe: allow creating /dev/nvidia-modeset
On Debian Sid we get this denial:

```
type=AVC msg=audit(1599065006.981:527): apparmor="DENIED"
operation="mknod" profile="nvidia_modprobe" name="/dev/nvidia-modeset"
pid=12969 comm="nvidia-modprobe" requested_mask="c" denied_mask="c"
fsuid=0 ouid=0
```

Update nvidia_modprobe profile to allow creating device file.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/614
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-03 18:01:49 +00:00
Vincas Dargis
e6dbe3bfd3 nvidia_modprobe: allow creating /dev/nvidia-modeset
On Debian Sid we get this denial:

```
type=AVC msg=audit(1599065006.981:527): apparmor="DENIED"
operation="mknod" profile="nvidia_modprobe" name="/dev/nvidia-modeset"
pid=12969 comm="nvidia-modprobe" requested_mask="c" denied_mask="c"
fsuid=0 ouid=0
```

Update nvidia_modprobe profile to allow creating device file.
2020-09-03 18:20:33 +03:00
John Johansen
761008f1b6 parser: fix yyerror message to not duplicate file name output
yyerror is outputting the file name twice when not in a profile or
the profilename global is not defined. Drop the second output of
the file name as it just clutters up the error message.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/610
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Mike Salvatore <mike.salvatore@canonical.com>
2020-09-03 07:19:21 -07:00
John Johansen
fe0d4e8aa3 parser: Fix debug build of flex scanner
yyno_top_state was set as part of getting rid of the need to link against
libfl.

However we actually need to ability when the scanner is built with
debugging. Fix it so the option and libfl linking are conditionally
used based on whether DEBUG is defined.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/609
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Mike Salvatore <mike.salvatore@canonical.com>
2020-09-02 15:38:12 -07:00
John Johansen
375b75bdc2 Merge Warn flags and -Werror support
Add flags to be able to control parser warnings, and convert warnings into errors.

Flags can be enabled by using `--warn` followed by a single flag. If multiple flags need to be set --warn can be specified multiple times.

Eg.

```
  --warn=deprecated --warn=rule-downgrade
```

Flags can be disabled no prefix the flag name with `no-`

Eg.

```
  --warn=no-config
```

The set of currently enabled flags can be seen by specifying

```
  --warn=show
```

and the set of supported flags can be seen by specifying

```
  --help=warn
```

The default set of warning flags that are enabled are

```
  WARN_CONFIG - config warnings
  WARN_CACHE - cache warnings that were not hidden behind debug-cache
  WARN_JOBS - warnings around job failures
  WARN_UNEXPECTED - warnings about internal consistency checks against what is expected from kernel
  WARN_OVERRIDE - warnings about overriding some option, currently limited to forcing an override on a namespace.
```

Warnings can be converted into errors by specifying `-Werror`. It supports all the same options as \`\`\`--warn\`. A warning must be turned on before the warning can be converted into an error message.

```
   --warn=deprecated --Werror=all
```

Will create error messages for deprecation warnings but not for rule-downgrades. -Werror is disabled by default.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-09-02 02:56:48 +00:00
John Johansen
dadc39507b parser: fix --warn and --Werror so they work with --config-file
--config-file is processed early in a separate argument processing
pass. Adjust --warn and --Werror processing so they are done in
both the early and late arg processing pass.

--warn and --Werror must be run in both argument processing passes
so that
1. They can be used with --config-file as long as they are specified
   before --config-file (early pass)
2. They are not overriden by any flags set in the config file, as
   command line options take priority over what is in the config
   file (hence the need for reprocessing in the second pass)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
3d7cfb29f9 parser: enable printing Werror flag settings
Make it so --Werror=show can display which flags have been set.

In addition update its --help=Werror flag table to display

   ./apparmor_parser --Werror=[Option]

instead of --Warn

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
9c1803d62a parser: cleanup/fix flagtable display for the warn, dump, and Optimize options
This changes the flagtable header from

     warn: --./apparmor_parser [Option]
     -O: --./apparmor_parser [Option]
     dump: --./apparmor_parser [Option]

  to
     ./apparmor_parser: --warn=[Option]
     ./apparmor_parser: -O [Option]
     ./apparmor_parser: --dump=[Option]

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
6e6f99e0b8 parser: add the ability to print what flags are set in option flag tables
Add the ability to show which warnings are enabled by specifying "show"
as an to the --dump, --warn, and --Optimize options

  Eg.
     --warn=show

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
db07b131b5 parser: unify flagtable printing for warn, dump and optimize
warn, dump, and optize share common printing of their option flag
tables, refactor and unify.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
3d54324db0 parser: allow specifying --warn=no-XXX to turn off warnings
Some warning flags are enabled by default, allow a warning to
be disbaled by specifying no- infront of the warning.

  Eg.
    --warn=no-deprecated

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
343024b4a3 parser: Add option --Werror to enable turning warnings into errors
Add basic ability to treat a warning as an error and abort the compile
by specifying the new option --Werror.

  --Werror

will turn all warnings into errors. Where if an warning type is
specified only that type of warning will be turned into an error.

  --Werror=deprecated.

The full list of supported warning types can be found by using

     apparmor_parser --help=warn
   or
     apparmor_parser --help=Werror

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
f5c4927c85 parser: convert remaining pwarn() to flag controlled warns
Make all warnings that go through pwarn() controllable by warning
flags. This adds several new warning control flags, documented in

  --help=warn

Convert --debug-cache to be unified with warning flags. So it can be
set by either
    --debug-cache
  or
    --warn=debug-cache

Also add an "all" option to be able to turn on all warnings.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
d50ada7159 parser: Add warning flag that can toggle a set of developer warnings
Add the flag
  --warn=dev

to be able to toggle several developer warnings with a single flag.

Note: --warn=all is being reserved for a larger patch to warnings
when all warnings are setup with control flags.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
c530c880b1 parser: Add warning flag that can toggle deprecation warnings
Add the flag
  --warn=deprecated

to be able to toggle deprecation warnings

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
0d0686becc parser: Add warning flag for ABI messages
ABI warnings can be to much for a deployed system. Add

  --warn=abi

to control output of abi warnings

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
eb8f9302aa profiles: Add a hosts_access abstraction
Host files accessed by tcp_wrapper can reference other files, from man
5 hosts.allow

```
A string that begins with a '/' character is treated as a file name. A host name or address is matched if it matches any host name or address pattern listed in the named file. The file format is zero or more lines with zero or more host name or address patterns separated by whitespace. A file name pattern can be used anywhere a host name or address pattern can be used.
```

This means adding a file to hosts requires updating multiple profiles
Add a hosts abstraction so users only have to modify a single location.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/605
Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1864466
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-09-01 19:39:59 -07:00
John Johansen
e1ba76375b profiles: Add chromium-browser profile from Ubuntu
Ubuntu is dropping their chromium-browser profile because
chromium-browser has been made a snap on ubuntu. Suck in the profile
upstream as a reference profile for those who want to confine
chromium outside of a snap, and update its includes.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/606
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-08-31 21:56:59 -07:00
John Johansen
cc97494528 Merge Fix access to Fips 140-2 library integrity files
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/595
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2020-08-31 17:41:11 +00:00
John Johansen
33112c324c Merge php-fpm: /run path update and peer name fixes
* fix profile name in signal and change_profile rule
* php-fpm profile: adjust /run paths

Thanks to Darix for pointing out that openSUSE now uses /run/php-fpm/

Also switch to using @{run}.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/601
Acked-by: John Johansen <john.johansen@canonical.com>
2020-08-31 06:48:33 +00:00
Christian Boltz
64ae865675 php-fpm: allow only one pid file
According to Darix, the pid is only in the main config, and it doesn't
make sense to have multiple pid files
2020-08-30 23:24:22 +02:00
Christian Boltz
9892a03270 php-fpm: fix profile name in signal and change_profile rule
Note: the change_profile rule was not really correct and only worked by
accident. We want to specify the target profile, therefore add the '->'.
2020-08-30 22:39:30 +02:00
Christian Boltz
6cf58457d7 Merge branch 'patch-1' into 'master'
Fix /usr/lib/postfix binary paths in postfix+dovecot profiles

See merge request apparmor/apparmor!602

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.12..master
2020-08-30 18:57:11 +00:00
Alexis Grey
04394d0749 Fix /usr/lib/postfix binary paths in postfix+dovecot profiles
This makes it consistent with the other Postfix profiles.
2020-08-30 18:57:11 +00:00
Christian Boltz
112e2bc9fb Merge branch 'update-nvidia-modprobe' into 'master'
nvidia_modprobe: allow reading driver parameters

See merge request apparmor/apparmor!603

Acked-by: Christian Boltz <apparmor@cboltz.de> for master and 2.13
2020-08-30 18:49:41 +00:00
Vincas Dargis
a98a4f734f nvidia_modprobe: allow reading driver parameters
On Debian Sid nvidia_modprobe is not permissive enough:

```
type=AVC msg=audit(1598788812.837:495): apparmor="DENIED"
operation="open" profile="nvidia_modprobe"
name="/proc/driver/nvidia/params" pid=31586 comm="nvidia-modprobe"
requested_mask="r" denied_mask="r" fsuid=0 ouid=0
```

Update profile to all reading /proc/driver/nvidia/params

Fixes Debian bug 969267 [0]

[0] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=969267
2020-08-30 19:24:29 +03:00
Christian Boltz
3a4dc1f885 php-fpm profile: adjust /run paths
Thanks to Darix for pointing out that openSUSE now uses /run/php-fpm/

Also switch to using @{run}.
2020-08-28 22:23:13 +02:00
John Johansen
398bb20dfd policy: Provide example and base abi to pin pre 3.0 policy
Provide example rules in parser.conf to pin pre 3.0 policy and
appropriate abi files.

abis for vanilla upstream kernels and outoftree network patched
kernels are provided. With both ABIs dropping v8 support from
advertised by the kernel as 2.x policy/userspace did not support it.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/598
Acked-by: Steve Beattie <steve.beattie@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-08-28 12:57:00 -07:00
Steve Beattie
efc6590409 regression tests/prologue: adjust sed to not use ~ as regex separators
prologue.inc:settest() in same cases invokes a sed command that uses
'~' as a pattern separator, on things that can contain filesystem
paths. However, in the debian/ubuntu world, '~' can be used in version
strings, particularly for pre-release versions, and when this happens
and the version is embedded in the path, the sed command breaks
because of the extraneous separator. Fix this by using '#' as a
separator, which has the benefit of being considered a comment if
accidentally interpreted by a shell.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/599
2020-08-27 15:43:28 -07:00
John Johansen
139fac6062 parser: Add warning to capability_table about the need to update the Makefile
The autogenerated capabilities comparison needs to be updated if the
capability_table structure changes. Add a note by the structure to
make sure the Makefile will get updated if the structure is changed.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/597
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2020-08-27 01:17:26 -07:00
Steve Beattie
4d802d6835 parser: fix cap list check
Merge branch 'parser-fix_cap_list_check' into 'master'

The sed command to manipulate the known cap list (`base_cap_names.h`) into
a format to match the generated_cap_names.h was buggy because the
trailing `}` would never match anything, leading to failures when built
against 5.8 kernel headers, due to it not raplcing the base capabilities
correctly.
    
Fix this by removing the trailing `}` match and instead match the third
comma-delimited field that matches a capability name, and replace that.

See merge request apparmor/apparmor!596
2020-08-27 04:26:56 +00:00
Steve Beattie
a7fc8bb500 parser/Makefile: fix generated cap comparison against known list
The sed command to manipulate the known cap list (base_cap_names.h) into
a format to match the generated_cap_names.h was buggy because the
trailing '}' would never match anything, leading to failures when built
against 5.8 kernel headers, due to it not replacing the base capabilities
correctly.

Fix this by removing the trailing '}" match and instead match the third
comma-delimited field that matches a capability name, and replace that.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/596
2020-08-26 20:58:14 -07:00
John Johansen
33ff79a9e5 parser/Makefile: use LC_ALL=C when invoking sed
Acked-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/596
2020-08-26 20:57:34 -07:00
Steve Beattie
ec62254b04 regression tests: add FIPS-140-2 lib validation hmac files
DBus services link against libgcrypt, and thus when libgcrypt has had
patches applied to make it FIP 140-2 compliant, the dbus based tests
confined by apparmor need access to the associated library integrity validation
file. Fix this by causing mkprofile to grant read access in all
generated profiles by default.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Bug: https://bugs.launchpad.net/bugs/1891664
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/595
2020-08-24 23:07:16 -07:00
Steve Beattie
e463f9ad44 profiles: add FIPS-140-2 lib validation hmac files to abstractions/base
Cryptographic libraries that have had FIPS 140-2 patches applied with
read from and validate themselves against a validation file, which is in
the same directory as the library itself. As an example, A FIPS 140-2
version libgcrypt on x86-64 has the following shared library and hmac file:

  /lib/x86_64-linux-gnu/libgcrypt.so.20.2.1
  /lib/x86_64-linux-gnu/.libgcrypt.so.20.hmac

A similarly named version of libgcrypt + hmac file can be seen for SUSE
systems in:

  https://csrc.nist.gov/CSRC/media/projects/cryptographic-module-validation-program/documents/security-policies/140sp2464.pdf

and Red Hat:

  https://csrc.nist.gov/CSRC/media/projects/cryptographic-module-validation-program/documents/security-policies/140sp2657.pdf

The libraries provided by FIPS 140-2 compliant versions of OpenSSL also
include this.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/595
2020-08-24 23:06:54 -07:00
John Johansen
9ef98e89e4 apparmor: bump versions for AppArmor 3.0 beta1
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-08-24 03:00:59 -07:00
Christian Boltz
94aaf2e0e3 Merge branch 'master' into 'master'
fix bug that some rules will be added to the profile repeatedly

The ask_exec() function may cause some rules to be added to the profile repeatedly.

See merge request apparmor/apparmor!593

Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-08-23 15:06:38 +00:00
zt1024
85b5ead6aa fix bug that some rules will be added to the profile repeatedly 2020-08-20 23:46:48 +08:00
John Johansen
6cfbb3ff95 Merge parser: replace duplicate warn_once() with common function
The warn_once() function is duplicated in 6 different places. A common, reusable version has been added to parser_common.c.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/590
Acked-by: John Johansen <john.johansen@canonical.com>
2020-08-20 08:54:52 +00:00
John Johansen
d2ceea34c1 Merge parser: fix abi rule and pinned feature file interaction
In AppArmor 2 distros could pin the feature file being used by setting
the feature-file option in the config file.

With AppArmor 3 policy is now explicitly tagged with an abi rule.

The problem is the interaction on systems that have a mixture of
AppArmor 2 and AppArmor 3 policy and use feature pinning.

The feature pinning is required to make the apparmor 2 policy behave
as expected but it also overrides the abi rules that are explicitly
set as part of the policy. This means we either have the apparmor 2
pinned policy working as desired or the apparmor 3 policy, but not
both.

To fix this make setting the flag in the config file have lower
priority than the feature abi rule. But still allow the config option
specified on the command line to override the config file and the
feature abi rule.

The Priority ordering to determine the policy abi to use is
1. Use abi rules if present
2. if no abi rule use command line option
3. if no abi rule or command line option use config setting
4. if none of the above use the default abi

v2:
add priority ordering to documentation
reorder priority so existing config/command line options behave as expected, make ABI rules highest priority
add new option --override-policy-ABI to allow overriding of abi rules
move arg processing from numbers to defines

v3
update patch description around how the abi pinning problem is being fixed
add MR: tags to patches

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/579
2020-08-20 01:26:24 -07:00
John Johansen
a4182119e2 parser: switch arg processing to use constant defines instead of numbers
I screwed up adding the last option, yet again because
EARLY_ARG_CONFIG_FILE was define out of order, and adding the new
option seems to skip a number, ...

Switch to defines to make it easier to update, and keep all these
define numbers together in order.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/579
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-08-20 01:22:03 -07:00
John Johansen
dcc2918665 parser: add an option to allow overriding feature ABI rules
Add an option to allow setting/pinning the feature ABI and overriding
of ABI rules if they exist.

  --override-policy-abi

This option is primarily for profile development and testing without
allowing adjusting feature abis temporarily without modifying the
profile.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/579
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-08-20 01:22:03 -07:00
John Johansen
acb45dc4b0 parser: fix abi rule and pinned feature file interaction
In AppArmor 2 distros could pin the feature file being used by setting
the feature-file option in the config file.

With AppArmor 3 policy is now explicitly tagged with an abi rule.

The problem is the interaction on systems that have a mixture of
AppArmor 2 and AppArmor 3 policy and use feature pinning.

The feature pinning is required to make the apparmor 2 policy behave
as expected but it also overrides the abi rules that are explicitly
set as part of the policy. This means we either have the apparmor 2
pinned policy working as desired or the apparmor 3 policy, but not
both.

To fix this make setting the flag on command line or in config file
lower priority than an abi rule specified in policy. The ability
to override abi rules will be added in a separate patch.

The Priority ordering to determine the policy abi to use is
1. Use abi rules if present
2. if no abi rule use command line option
3. if no abi rule or command line option use config setting
4. if none of the above use the default abi

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/579
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-08-20 01:22:03 -07:00
John Johansen
2f5d5e1b24 Merge utils make check_severity_db: say ERROR for failing the build
utils `make check_severity_db` will fail the build if a (probably new) capability in not listed in severity.db. This also means it should print out an ERROR, not a warning.

This is a follow-up of lp#1890547 and https://gitlab.com/apparmor/apparmor/-/merge_requests/589

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/591
Acked-by: John Johansen <john.johansen@canonical.com>
2020-08-20 08:09:18 +00:00
John Johansen
345f4eaeff Merge abstractions/gnome: allow /usr/share/gtk-3.0/settings.ini
GTK+ 3 has a global settings file (see https://gitlab.gnome.org/GNOME/gtk/-/blob/gtk-3-24/gtk/gtksettings.c#L345) that should be readable as well.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/592
Acked-by: John Johansen <john.johansen@canonical.com>
2020-08-20 08:07:11 +00:00
John Johansen
eebd1bdfba Merge Add php-fpm isolation with apparmor hats
Adapted from https://nordisch.org/posts/php-fpm-apparmor/, port the nextcloud-independent portion of the php-fpm worker abstractions and php-fpm isolation for more general usage.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/577
Acked-by: John Johansen <john.johansen@canonical.com>
2020-08-20 08:05:03 +00:00
Jonas Witschel
af6fe026e1 abstractions/gnome: allow /usr/share/gtk-3.0/settings.ini
GTK+ 3 has a global settings file that should be readable as well.
2020-08-18 12:28:53 +02:00
Antonio Russo
660ce39937 Add php-fpm isolation with apparmor hats
Adapted from https://nordisch.org/posts/php-fpm-apparmor/, port the
nextcloud-independent portion of the php-fpm worker abstractions and
php-fpm isolation for more general usage.

Signed-off-by: Antonio Russo <antonio.e.russo@gmail.com>
2020-08-16 12:11:00 -06:00
Christian Boltz
46920dd3ef utils make check_severity_db: say ERROR for failing the build
utils `make check_severity_db` will fail the build if a (probably new)
capability in not listed in severity.db. This also means it should print
out an ERROR, not a warning.

This is a follow-up of lp#1890547 and
https://gitlab.com/apparmor/apparmor/-/merge_requests/589
2020-08-14 20:16:49 +02:00
Mike Salvatore
52d9529d1b parser: replace duplicate warn_once() with common function
The warn_once() function is duplicated in 6 different places. A common,
reusable version has been added to parser_common.c.

Signed-off-by: Mike Salvatore <mike.salvatore@canonical.com>
2020-08-09 17:56:31 -04:00
John Johansen
4aabc40d1f Merge Add CAP_BPF and CAP_PERFMON to severity.db
These capabilities were introduced in Linux 5.8

Fixes: https://bugs.launchpad.net/bugs/1890547
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/589
Acked-by: John Johansen <john.johansen@canonical.com>
2020-08-07 20:48:13 +00:00
Christian Boltz
ae01250209 Add CAP_BPF and CAP_PERFMON to severity.db
These capabilities were introduced in Linux 5.8

References: https://bugs.launchpad.net/bugs/1890547
2020-08-07 22:37:53 +02:00
John Johansen
04a1c9dbf1 Merge Handle symlink log events in aa-logprof
Nobody told the tools that log events with operation="symlink" exist. Add this keyword to the list of file or network operations (I don't expect network symlinks ;-) but keeping everything in that list makes things easier than special-casing it.)

Also add the log sample and expected result to the libapparmor tests.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/107
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/587
Acked-by: John Johansen <john.johansen@canonical.com>
2020-08-06 18:17:32 +00:00
John Johansen
ae12688167 Merge Fix pod syntax bug in aa_features_pod
Fixes: part 1 of https://gitlab.com/apparmor/apparmor/-/issues/109
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/588
Acked-by: John Johansen <john.johansen@canonical.com>
2020-08-06 17:26:50 +00:00
Christian Boltz
2d730f4507 Fix pod syntax bug in aa_features_pod
Fixes: part 1 of https://gitlab.com/apparmor/apparmor/-/issues/109
2020-08-06 19:06:27 +02:00
Christian Boltz
98bf187323 Handle symlink log events in aa-logprof
Nobody told the tools that log events with operation="symlink" exist.
Add this keyword to the list of file or network operations (I don't
expect network symlinks ;-) but keeping everything in that list makes
things easier than special-casing it.)

Also add the log sample and expected result to the libapparmor tests.

Fixes https://gitlab.com/apparmor/apparmor/-/issues/107
2020-08-02 19:49:18 +02:00
Steve Beattie
f318def665 tests: fix profiles and utils tests to find and use the swig python libraries
The fixes that landed for #98 are incomplete: they only added a check to
ensure that the parser is built, and not libapparmor as well, and also
didn't adjust the invocation of aa-logprof to actually make use of the
built libapparmor or its swig python library.

Furthermore, neither it nor the tests in utils/ add the location of the
swig libapparmor C library to the library search path, meaning that if
the system one does not exist, it will not be found and the test will
fail.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
Bug: https://gitlab.com/apparmor/apparmor/-/issues/98
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/586
2020-07-24 23:57:26 -07:00
Steve Beattie
0f3c860768 utils/tests: add libaparmor swig library path
Similar to the profiles/ check using the python utilities, the
tests for the python utilities were not including the path for the
swig libapparmor library in the LD_LIBRARY_PATH variable, only in
PYTHONPATH. This commit fixes that, renaming the variable used for
the built libapparmor check.

v2:
 - actually use the LIBAPPARMOR_PATH variable when defining
   LD_LIBRARY_PATH

Bug: https://gitlab.com/apparmor/apparmor/-/issues/98
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/586
2020-07-24 23:52:45 -07:00
Steve Beattie
76162d4b84 profiles/Makefile: fix aa-logprof invocation
The commit c8b6d8b393 ("profiles: Update 'make check' to select tools
based on USE_SYSTEM") set a bunch of variables but neglected to apply
them when invoking aa-logprof. This commit addresses this by:

  * correcting the PYTHONPATH used with aa-logprof
  * setting LD_LIBRARY_PATH when invoking aa-logprof
  * adjusting LD_LIBRARY_PATH to include both the directory location
    of libapparmor but also the swig libapparmor library needed for
    python tools to function.
  * adjusts the test for the presence of libapparmor to not use
    LD_LIBRARY_PATH but instead a libapparmor specific variable
    LIBAPPARMOR_PATH

Bug: https://gitlab.com/apparmor/apparmor/-/issues/98
Fixes: c8b6d8b393
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/586
2020-07-24 23:52:36 -07:00
Steve Beattie
2d94faeb5b profiles/Makefile: add check for built libapparmor
When running the 'check-logprof' test using tools in the tree,
libapparmor needs to have been built for the python utilities to work.
Add a check for its existence to the test-dependencies target.

Bug: https://gitlab.com/apparmor/apparmor/-/issues/98
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/586
2020-07-24 23:52:27 -07:00
Steve Beattie
75c02604be profiles/Makefile: local target does not depend on parser
The "local" make target does not depend on the parser having been
built. Create a separate "test-dependencies" target and have the tests
that need them depend on that and the "local" target, when validating
the profile set against the apparmor tools.

Fixes: c8b6d8b393
Bug: https://gitlab.com/apparmor/apparmor/-/issues/98
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/586
2020-07-24 23:52:16 -07:00
John Johansen
28e0cd85f6 Merge Introduce tunables/etc with @{etc_ro} and @{etc_rw}
1 unresolved thread

This helps to adjust profiles in a readable way for https://en.opensuse.org/openSUSE:Packaging_UsrEtc and similar initiatives.

Also convert the abstractions using /{usr/,}etc/ to use @{etc_ro}

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/585
Acked-by: John Johansen <john.johansen@canonical.com>
2020-07-25 03:51:17 +00:00
Christian Boltz
4c14516341 Convert abstractions from /{usr/,}etc/ to @{etc_ro}
The authentication, base and nameservice abstraction used /{usr/,}etc/
in several rules. Switch that to the more readable (and tunable)
@{etc_ro} variable.
2020-07-23 20:51:25 +02:00
Christian Boltz
715589f8dd Introduce tunables/etc with @{etc_ro} and @{etc_rw}
This helps to adjust profiles in a readable way for
https://en.opensuse.org/openSUSE:Packaging_UsrEtc
and similar initiatives.
2020-07-23 20:51:25 +02:00
John Johansen
fd980639e2 logo: Add default bitmap renderings of logo
Add a couple of bitmap renderings of the logo for convenience

128x128 pixel rendering of the logo
700x700 pixel rendering of the logo

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-23 10:52:13 -07:00
John Johansen
c8b6d8b393 profiles: Update 'make check' to select tools based on USE_SYSTEM
The profiles dirs make check is not always using the correct tools.
Update it to be similar to other Makefiles where the var USE_SYSTEM

  make check USE_SYSTEM=1

is used to indicated that the system installed tools should be used
and

  make check

is used to run the tests against the in tree tools

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/580
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-07-22 13:37:43 -07:00
John Johansen
d3f6f79276 Merge abstractions/X: add another xauth path
Future sddm version will use $XDG_RUNTIME_DIR/xauth_XXXXXX

References:

* https://bugzilla.opensuse.org/show_bug.cgi?id=1174290
* https://bugzilla.suse.com/show_bug.cgi?id=1174293
* https://github.com/sddm/sddm/pull/1230
* https://github.com/jonls/redshift/issues/763

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/581
Acked-by: John Johansen <john.johansen@canonical.com>
2020-07-21 22:42:33 +00:00
John Johansen
b8be1c3ff8 libapparmor: fix hashing of the feature set
The hashing of the featue set is wrong because it is hashing the
whole feature structure instead of just the feature string.

This results in the refcount and hash field becoming part of the
hash and the feature string not being completely hashed as the
bytes of the refcount and hash field are being counted in the
as part of the string length when the hash is taken.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/583
Reported-by: Samuele Pedroni <samuele.pedroni@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-07-21 15:16:09 -07:00
Christian Boltz
35f033ca7c abstractions/X: add another xauth path
Future sddm version will use $XDG_RUNTIME_DIR/xauth_XXXXXX

References:
- https://bugzilla.opensuse.org/show_bug.cgi?id=1174290
- https://bugzilla.suse.com/show_bug.cgi?id=1174293
- https://github.com/sddm/sddm/pull/1230
- https://github.com/jonls/redshift/issues/763
2020-07-20 20:30:34 +02:00
Steve Beattie
0ab18ff39d Merge branch 'cboltz-path-join' into 'master'
Use os.path.join() everywhere

See merge request apparmor/apparmor!576
2020-07-09 21:35:54 +00:00
John Johansen
4392073709 Merge update capability handling to be able handle changes in what capabilities are available
This adds support for the new PERFMON, and BPF capabilities.

In addition this updates AppArmor's handling in several ways.

* Move to a static capability list that is compared to the automatically generated capability list, and fail the build if new capabilities are detected. This is required to ensure backwards mapping of capabilities is properly handled.
* allow an already built apparmor to dynamically detect any new additions of capabilities so a release patch doesn't need to be made to support new capabilities. This however will be missing support for backwards mapping of capabilities
* support backwards mapping of new capabilities that have been split of existing capabilities for older kernels (eg. CAP_PERFMON was split off of CAP_SYS_ADMIN)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/578
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2020-07-07 16:58:03 +00:00
John Johansen
da4bab8368 profiles: add support for perfmon and bpf caps to the supported abi
To be able to use perfmon and bpf in policy they need to be in the abi file.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00
John Johansen
c810c755b1 parser: allow backwards mapping of a capability
If a capability is known in policy but not by the kernel, check to see if it has
a backwards mapping to a different capability and use that instead.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00
John Johansen
3880ef5b54 parser: Use the kernel and policy abis to detect new capabilities
The kernel and policy abis can be used to detect and support new
capabilities without having to update base_cap_names.h and and
rebuilding the compiler.

This is not perfect however in that the does not provide any backwards
compatibility mappings, so we still need to keep the internal
capability table.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00
John Johansen
c3b0e835b5 libapparmor: add lookup of features value
Currently features doesn't provide a way to query a features
value. So add an api to extract the value string of a feature.

The value string returned is a raw text value and may contain
leading spaces, etc that the caller may need to be aware of.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00
John Johansen
7b4197f0da parser: convert to dynamically allocated capability list
We need to be able to dynamically add capabilities to the capability
list so switch to using a dynamically allocated table that we can
extend.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00
John Johansen
48974e552c parser: add a set of flags to the capability tables
We need a set of flags to track where a capability can from so we know
how to processes it for policy compatibility purposes.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00
John Johansen
8a1260db47 parser: move cap code around to consolidate
Just some basic cleanup bringing capability structs and fns together.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00
John Johansen
168b141cc2 parse: add backmapping capability information
Some capabilities like perfmon and bpf have been split out from
another capability, likely cap sys_admin. Add this backmapping
infomation so that the parser can take advantage of it to support
policy on older kernels that don't support the new capabilities.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00
John Johansen
fb9c5f9bcf parser: unify capability name handling
There are currently two capability name tables the one that is
autogenerated and an internal hardcoded name table.

Now that the autogenerated table has been converted to a base
static table we can drop the internal static table. This
removes the chance of getting the tables getting out of sync.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00
John Johansen
fdba3a571c parser: cleanup capability_table generation by dropping cap sys_log
The static cap sys_log declaration is no longer needed as
base_cap_names.h contains it and ensures that it will always be
present.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00
John Johansen
270fb0a2b2 parser: Move to a pre-generated cap_names.h
The auto-generated cap_names.h has problems when the parser if the
parser is built against a kernel with a smaller capability list than
the kernel policy is being compiled for.

Moving to a pre-generated list lets us support all capabilities even
when we build against older kernels. However we don't want to only use
the pre-generated list as that would make it too easy to miss when a
new capability has been added.

Keep auto generating the caps list and compare it to the pre-generated
caps list so we can detect when new capabilities are added, and fail
the build so that the pre-generated list can be updated. We screen the
diff for only additions so that the parser can continue to build on
older kernels that don't have the full capability list without errors.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00
Christian Boltz
9e37e8830b Use os.path.join() everywhere
... instead of merging paths with string operations
2020-06-28 13:00:32 +02:00
Christian Boltz
5b4a40ea58 Merge branch 'update-debian-fonts' into 'master'
Update fonts abstraction for Debian

Closes #94

See merge request apparmor/apparmor!575

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.12..master
2020-06-27 18:34:51 +00:00
Vincas Dargis
7b7e98a549 Update fonts abstraction for Debian
Mikhail Morfikov has discovered [0] that some font packages in Debian
ships font files in /usr/bin/fonts-foo-bar (like
/usr/share/fonts-font-awesome/ for example). This produces denials for
GUI applications.

Update fonts abstraction to allow reading /usr/bin/fonts-* directories.

Also, refactor abstraction to aggregate two old rules into one.

Closes #94

[0] https://gitlab.com/apparmor/apparmor/-/issues/94
2020-06-27 11:48:22 +03:00
Steve Beattie
d84ae2331d enchant abstraction: support libenchant-2-2
Merge branch 'libenchant-2-2' into 'master'

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/573
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-06-19 07:50:01 +00:00
Christian Boltz
429bfa0a07 Merge branch 'cboltz-abs-include' into 'master'
Change internal include file storage to absolute paths

See merge request apparmor/apparmor!562

Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-17 11:12:25 +00:00
Jochen Sprickerhof
178f5d5e77 Support libenchant-2-2 2020-06-17 09:20:25 +02:00
John Johansen
bb4925e273 Merge Add abi rule when creating a new profile
When aa-autodep or aa-genprof create a new profile, always add an abi rule. (Hardcoded to <abi/3.0> for now to keep things simple.)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/571
Acked-by: John Johansen <john.johansen@canonical.com>
2020-06-13 21:31:36 +00:00
Christian Boltz
4f50f16c50 Add abi rule when creating a new profile
When aa-autodep or aa-genprof create a new profile, always add an abi
rule. (Hardcoded to <abi/3.0> for now to keep things simple.)
2020-06-13 22:48:15 +02:00
John Johansen
f3f72a9471 parser: add dbus to the default features abi
This fixes a regression introduced by the abi patches for policy that
is not tagged with an abi rule.

Specifically if the current apparmor (apparmor 3) is used with a
kernel that supports unix rules, and policy has network rules but has
not been updated to use abi rules, without this patch the policy unix
rules will stop working and unix mediation will not be enforced.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/568
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-12 15:38:57 -07:00
John Johansen
aeb1359b3d Merge Fix parser lexer
The lexer is broken and passing echo input to stdout that it doesn't match in some states ignoring the error.

First add `%option nodefault` to guarantee the lexer won't ever echo the unknown input to stdout, this will cause the parser to error out with

```
flex scanner jammed
```

and $?=2 if a profile contains unknown/invalid parts. That's not really a helpful error message, but still better than ignoring errors.

Next improve the error message output,

```
AppArmor parser error for tst/simple_tests//vars/vars_simple_assignment_14.sd line 8: Lexer found unexpected character: '
' (0xa) in state: SUB_ID_WS
```

using flex's error output only if there is an mistake made when introducing new states.

Finally fix bugs that are found.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/569
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-06-12 22:36:15 +00:00
John Johansen
1e9987a719 Merge Dovecot profile updates
* allow reading my.cnf in dovecot-dict profile (seen with the mail users in a mysql database)
* allow /proc/\*/attr/current in dovecot imap and lmtp (needed when using the "apparmor" plugin which means dovecot switches to user-specific hats)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/566
Acked-by: John Johansen <john.johansen@canonical.com>
2020-06-12 21:23:22 +00:00
John Johansen
21498ff9a4 parser: update rule to process newlines to include states that eat WS
Newlines should generally be treated as whitespace. Expand the list
of states using the newline rule to include almost all rules that
eat WS.

There are two exceptions assign and comment which have special handling
of newlines.

this fixes the failures

not ok 71543 - ./simple_tests//vars/vars_simple_assignment_13.sd: quoted commas should not trigger an error

not ok 71544 - ./simple_tests//vars/vars_simple_assignment_14.sd: quoted commas should not trigger an error

found by introducing nodefault

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/569
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-12 14:18:04 -07:00
John Johansen
fffca2ffa0 parser: split newline and end of rule handling into separate rules
Split the newline processing into a separate rule block so that it can
be shared with states that need to process newlines without processing
end of rule conditions.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/569
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-12 14:18:04 -07:00
John Johansen
1a4288886b parser: add missing states to the default rule and improve the error msg
There were several states missing from the default rule which catches
unexpected input in a state.

Update the default rule to catch all input including newlines and
update its error message to include information about which state the
failure occured in. Also update the comment about what to do when
adding new states.

While the lexer now has the "nodefault" option set, it doesn't provide
as much information as the default rule does, so we prefer states
to use our provided default rule.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/569
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-12 14:18:04 -07:00
Christian Boltz
7d062917aa Remove TODO for half-quoted abi rule
With %option nodefault, the parser now errors out as expected, even if
the error message isn't too helpful.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/569
Signed-off-by: Christian Boltz <apparmor@cboltz.de>                            Acked-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-12 14:18:49 -07:00
Christian Boltz
c01ed1d57b Error out on unhandled parts when parsing a profile
... (using `%option nodefault`) instead of echoing the unknown parts to
stdout, and ignoring the error.

This will cause the parser to error out with

    flex scanner jammed

and $?=2 if a profile contains unknown/invalid parts. That's not really
a helpful error message, but still better than ignoring errors.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/569
Signed-off-by: Christian Boltz <apparmor@cboltz.de>
Acked-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-12 14:18:04 -07:00
Steve Beattie
777a819fcb profiles: fix sbin.dhclient profile
Merge branch 'antnesterov/apparmor-fix-dhclient-profile'

@smb: converted read permission to /etc/openssl.cnf to use the openssl
abstraction instead.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/570
2020-06-12 10:00:21 -07:00
Anton Nesterov
48d9414776 Fix sbin.dhclient profile 2020-06-12 15:54:06 +00:00
John Johansen
e15fdd1be9 Merge add profile names to dovecot profiles
Update the dovecot profiles to use names instead of pathnames.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/565
Acked-by: John Johansen <john.johansen@canonical.com>
2020-06-12 10:25:32 +00:00
John Johansen
8da6cd9f6f parser: add v7 network and af_unix to the default feature abi
This fixes a regression due on older policy due to the abi patches.

Specifically if the current apparmor is used with a kernel that
supports v7 networking, and policy has network rules but has not been
updated to use abi rules, without this patch the policy network rules
will stop working and network mediation will be unenforced.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/564
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-11 18:59:52 -07:00
Christian Boltz
f7ab91f423 allow reading my.cnf in dovecot-dict profile
Seen on openSUSE Tumbleweed with the mail users in a mysql database.
2020-06-11 15:07:10 +02:00
Christian Boltz
6a388859f8 Allow /proc/*/attr/current in dovecot imap and lmtp
This is needed when using the "apparmor" plugin which means dovecot
switches to user-specific hats.

Seen on openSUSE Tumbleweed.
2020-06-11 15:05:14 +02:00
Christian Boltz
39f7e5723c add profile names to dovecot profiles 2020-06-11 12:57:53 +02:00
John Johansen
f7c6d71186 Merge Profile kill
Add profile flags enforce, kill and unconfined.

enforce - is the default mode and is not required but this allows the mode reported by introspection to be used in the profile.

kill - a modified enforce mode that kills tasks instead of returning a denial.

unconfined - allow a named profile to behave as if it is unconfined.

Eg.

profile example flags=(enforce) { ... }

profile example flags=(kill) { ... }

profile example flags=(unconfined) { ... }

Closes #7
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/440
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-10 12:47:30 +00:00
John Johansen
0c9884550c parser: support enforce, kill and unconfined profile modes
The enforce profile mode is the default but specifying it explicitly
has not been supported. Allow enforce to be specified as a mode. If
no mode is specified the default is still enforce.

The kernel has supported kill and unconfined profile modes for a
long time now. And support to the parser so that profiles can make
use of these modes.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/440
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/7
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-10 05:35:37 -07:00
Christian Boltz
e0d061d15a Merge branch 'cboltz-include' into 'master'
Change `#include` to `include` in profiles and abstractions

See merge request apparmor/apparmor!563

Acked-by: Seth Arnold <seth.arnold@canonical.com>
2020-06-09 22:12:23 +00:00
Christian Boltz
71a730fe39 Change #include to include in extra profiles 2020-06-09 23:35:11 +02:00
Christian Boltz
f0491d0d64 Change #include to include in active profiles 2020-06-09 23:30:24 +02:00
Christian Boltz
9aa5e3f388 Change #include to include in abstractions and tunables 2020-06-09 23:28:41 +02:00
Christian Boltz
8296c107cf Drop profile_dir parameter from ProfileList get_all_merged_variables()
This parameter is superfluous and unused since some commits.

Also adjust all callers.
2020-06-05 20:02:33 +02:00
Christian Boltz
2a742b3e6b drop now unused get_include_path()
... and a comment mentioning it
2020-06-05 20:02:33 +02:00
Christian Boltz
0aa58536f0 include_dir_filelist(): simplify to only handle absolute paths
This is not a real change - since some commits, include_dir_filelist()
gets only called with absolute paths.

Add a check to ensure this, drop the now superfluous get_include_path()
call, and replace usage of include_name_abs with include_name (which are
the same now).

Also drop the superfluous profile_dir parameter, and adjust the only
caller accordingly.
2020-06-05 20:02:33 +02:00
Christian Boltz
7e8430575c load_include(): get rid of incfile_abs
With the check that incfile starts with a '/', incfile and incfile_abs
(as returned by get_include_path()) are always the same.

Drop the get_include_path() call and setting incfile_abs, and replace
usage of incfile_abs with incfile.

This is just a cleanup, no behaviour change.
2020-06-05 20:02:33 +02:00
Christian Boltz
4a265e4121 Add checks to load_include() to ensure absolute paths
Also update the tests to the new behaviour.
2020-06-05 20:02:33 +02:00
Christian Boltz
9eb7a7581f match_includes(): don't propose local/ files
This fixes the behaviour change inctroduced two commits ago.
2020-06-05 20:02:33 +02:00
Christian Boltz
221725c7d4 match_includes(): return proposals without profile_dir prefix
... so that the include rules proposed by aa-logprof continue to be
relative to the profile directory.

This fixes the behaviour change introduced in the previous commit.
2020-06-05 20:02:33 +02:00
Christian Boltz
2f522fe45b Change internal include file storage to absolute paths
This removes the need to remove profile_dir from include paths at
various places.

A side effect is that aa-logprof / match_includes() now propose more
include rules, for example matching local/ files.

Another side effect is that proposals for include rules
(match_includes() again) now come with the full path.

Both side effects will be fixed in the next commits.
2020-06-05 19:58:09 +02:00
Christian Boltz
de8fa87051 convert profile_dir to abspath in init_aa()
This is needed for running the tests, because test/logprof.conf contains
a relative path, and tests only "manually" set the profile_dir if they
need/have a modified copy of the profiles.
2020-06-05 19:58:09 +02:00
Christian Boltz
6fe4b5e59a fix setting apparmor.aa.profile_dir in some tests 2020-06-05 19:58:06 +02:00
John Johansen
9d339deb93 Merge Fix warnings
Fix various warnings in C code that have been surfaced since the warning flags cleanup

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/561
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-06-03 23:51:44 +00:00
John Johansen
596c687ae5 parser: Fix warnings in chfa.cc
chfa.cc:348:4: warning: this statement may fall through [-Wimplicit-fallthrough=]
    os.put((char)(*pos >> 16));
    ^~
chfa.cc:349:3: note: here
   case 2:
   ^~~~
chfa.cc:350:4: warning: this statement may fall through [-Wimplicit-fallthrough=]
    os.put((char)(*pos >> 8));
    ^~
chfa.cc:351:3: note: here
   case 1:
   ^~~~
chfa.cc: In function ‘void write_flex_table(std::ostream&, int, Iter, Iter) [with Iter = __gnu_cxx::__normal_iterator<unsigned int*, std::vector<unsigned int> >]’:
chfa.cc:348:4: warning: this statement may fall through [-Wimplicit-fallthrough=]
    os.put((char)(*pos >> 16));
    ^~
chfa.cc:349:3: note: here
   case 2:
   ^~~~
chfa.cc:350:4: warning: this statement may fall through [-Wimplicit-fallthrough=]
    os.put((char)(*pos >> 8));
    ^~
chfa.cc:351:3: note: here
   case 1:
   ^~~~
chfa.cc: In function ‘void write_flex_table(std::ostream&, int, Iter, Iter) [with Iter = __gnu_cxx::__normal_iterator<short unsigned int*, std::vector<short unsigned int> >]’:
chfa.cc:348:4: warning: this statement may fall through [-Wimplicit-fallthrough=]
    os.put((char)(*pos >> 16));
    ^~
chfa.cc:349:3: note: here
   case 2:
   ^~~~
chfa.cc:350:4: warning: this statement may fall through [-Wimplicit-fallthrough=]
    os.put((char)(*pos >> 8));
    ^~
chfa.cc:351:3: note: here
   case 1:
   ^~~~

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/561
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-03 16:29:58 -07:00
John Johansen
c36a5769e6 parser: Change Fall through comment to remove warning
-Wimplicit-fallthrough only recognizes specic comment patterns
switch to a comment it recognizes.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/561
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-03 16:29:55 -07:00
John Johansen
1de9768180 binutils: Fix unused var warning in aa_status.c
aa_status.c: In function ‘get_processes’:
aa_status.c:236:10: warning: unused variable ‘len’ [-Wunused-variable]
   size_t len = 0;
          ^~~

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/561
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-03 16:29:51 -07:00
John Johansen
c63598a4aa binutils: drop unused var in aa_enabled.c
Cleanup unused var warning

aa_enabled.c: In function ‘exit_with_error’:
aa_enabled.c:34:6: warning: unused variable ‘err’ [-Wunused-variable]
  int err;

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/561
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-03 16:29:45 -07:00
John Johansen
b32501003a pam_apparmor: fix unused parameter warnings
Tag unused parameters so the -Wunused-parameter won't complain about
them.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/561
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-03 16:29:40 -07:00
John Johansen
1305dfcecf mod_apparmor: fix unused parameter warnings
Tag unused parameters so the -Wunused-parameter won't complain about
them.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/561
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-03 16:29:36 -07:00
John Johansen
9623bcd575 libapparmor: Fix build of features.c when debug is enabled
PDEBUG is defined away when debug isn't configure in the build, this
hides the bad format string and argument.

Fix this and make sure we can still have the debug output that was
supposed to be printed.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/561
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-03 16:29:32 -07:00
John Johansen
4c37806a11 libapparmor: fix warnings in private.c
private.c: In function ‘_aa_is_blacklisted’:
private.c:140:35: warning: comparison of integer expressions of different signedness: ‘long int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
  140 |        found - name + suffix->len == name_len ) {
      |                                   ^~
private.c: In function ‘readdirfd’:
private.c:352:16: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘ssize_t’ {aka ‘long int’} [-Wsign-compare]
  352 |  for (i = 0; i < n; ) {
      |                ^
private.c:378:17: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘ssize_t’ {aka ‘long int’} [-Wsign-compare]
  378 |   for (i = 0; i < n; i++)
      |                 ^

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/561
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-03 16:29:25 -07:00
John Johansen
cdda6ba57b libapparmor: fix api of aa_getpeercon_raw to use unsigned len param
The len parameter returns a value that correlates to a getsockopt
parameter which is typed to socklen_t which is an unsigned int.

This technically changes the fn() api but old code using this is
already broken if the getsockopt parameter is large enough to overflow
the value.

In reality what is returned shouldn't ever be negative and the value
should never be large enough to trip the overflow. This is just
cleaning up a corner case.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/561                  Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-03 16:29:14 -07:00
John Johansen
82b14bd472 libapparmor: Fix warnings in kernel.c
kernel.c: In function ‘aa_getpeercon_raw’:
kernel.c:823:14: warning: comparison of integer expressions of different signedness: ‘socklen_t’ {aka ‘unsigned int’} and ‘int’ [-Wsign-compare]
  823 |   if (optlen < *len) {
      |              ^
kernel.c: In function ‘query_label’:
kernel.c:966:10: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
  966 |  if (ret != size) {
      |          ^~

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/561                  Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-03 16:29:06 -07:00
John Johansen
a1e91bda87 libapparmor: Fix warning in grammer.y
grammar.y: In function ‘aalogparse_error’:
grammar.y:40:29: warning: unused parameter ‘scanner’ [-Wunused-parameter]
   40 | void aalogparse_error(void *scanner, char const *s)
      |                       ~~~~~~^~~~~~~
grammar.y:40:50: warning: unused parameter ‘s’ [-Wunused-parameter]
   40 | void aalogparse_error(void *scanner, char const *s)
      |                                      ~~~~~~~~~~~~^

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/561
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-03 16:28:40 -07:00
Christian Boltz
fd66451054 Merge branch 'cboltz-include-sort' into 'master'
IncludeRule: sort files in included directory

... instead of relying on the filesystem(!) ordering, which will look
random to both users and unittests.

Also partially revert the test changes from
c5a7bcd50e /
https://gitlab.com/apparmor/apparmor/-/merge_requests/548 -
sorting the result only in the tests is a bad idea.

See merge request apparmor/apparmor!552

Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-06-03 11:31:10 +00:00
John Johansen
870dcc9bc0 Merge Add abi rules to some extra profiles
... which were missed in 730db17607

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/555
Acked-by: John Johansen <john.johansen@canonical.com>
2020-06-01 08:56:12 +00:00
John Johansen
3b4e9ed7e3 Merge Define abi when checking abstractions
This fixes lots of warnings like

```
*** Checking abstractions from ./apparmor.d/abstractions against apparmor_parser
Warning from stdin (stdin line 1): ../parser/apparmor_parser: File 'stdin' missing feature abi, falling back to default policy feature abi
Warning from stdin ([...]/profiles/./apparmor.d/abstractions/apparmor_api/change_profile line 9): ../parser/apparmor_parser: [...]/profiles/./apparmor.d/abstractions/apparmor_api/change_profile features abi 'abi/3.0' differes from policy declared feature abi, using the features abi declared in policy
```

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/554
Acked-by: John Johansen <john.johansen@canonical.com>
2020-06-01 08:54:17 +00:00
John Johansen
ad834c4183 Merge abstractions: remove '#' from 'include if exists'
This matches what we use in the profiles for local abstractions.

Also adjust the check in the Makefile to expect the variant without '#'.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/553
Acked-by: John Johansen <john.johansen@canonical.com>
2020-06-01 08:52:17 +00:00
John Johansen
0426f49f50 Merge Fix comparison of signed/unsigned int in hex_to_string()
```
libaalogparse.c: In function 'hex_to_string':
libaalogparse.c:144:16: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
  144 |  for (i = 0; i < len; i++) {
      |                ^
```

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/558
Acked-by: John Johansen <john.johansen@canonical.com>
2020-06-01 07:49:02 +00:00
John Johansen
e3fb699bf5 Merge Fix whitespace in aa_change_hat.pod and aa_stack_profile.pod
This was reported by podchecker as

\*\*\* WARNING: line containing nothing but whitespace in paragraph

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/559
Acked-by: John Johansen <john.johansen@canonical.com>
2020-06-01 07:47:13 +00:00
John Johansen
000a165ac6 Merge add parser/default_features.o to .gitignore
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/556
Acked-by: John Johansen <john.johansen@canonical.com>
2020-06-01 07:45:35 +00:00
John Johansen
4569a8a26d Merge build: unify compiler flags
Following up on !549, this patchset unifies most of the compiler warnings settings to use EXTRA_WARNINGS as newly defined in `common/Make.rules` and then adds the `-Wimplicit-fallthrough` compiler warning to the default set.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/551
Acked-by: John Johansen <john.johansen@canonical.com>
2020-06-01 07:44:06 +00:00
Christian Boltz
f7ab5ceff5 Fix comparison of signed/unsigned int in hex_to_string()
```
libaalogparse.c: In function 'hex_to_string':
libaalogparse.c:144:16: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
  144 |  for (i = 0; i < len; i++) {
      |                ^
```

`i` gets used/changed as counter variable in the for loop and only gets
increased (starting at 0), so making it an (unsigned) size_t should be
safe.
2020-05-31 21:35:42 +02:00
Christian Boltz
1ddfcc7405 Fix whitespace in aa_change_hat.pod and aa_stack_profile.pod
This was reported by podchecker as

*** WARNING: line containing nothing but whitespace in paragraph
2020-05-31 18:58:46 +02:00
Christian Boltz
a68fe50fda add parser/default_features.o to .gitignore 2020-05-31 01:27:00 +02:00
Christian Boltz
7b176cbb48 Add abi rules to some extra profiles
... which were missed in 730db17607
2020-05-31 01:05:52 +02:00
Christian Boltz
35a6676744 Define abi when checking abstractions
This fixes lots of warnings like

```
*** Checking abstractions from ./apparmor.d/abstractions against apparmor_parser
Warning from stdin (stdin line 1): ../parser/apparmor_parser: File 'stdin' missing feature abi, falling back to default policy feature abi
Warning from stdin ([...]/profiles/./apparmor.d/abstractions/apparmor_api/change_profile line 9): ../parser/apparmor_parser: [...]/profiles/./apparmor.d/abstractions/apparmor_api/change_profile features abi 'abi/3.0' differes from policy declared feature abi, using the features abi declared in policy
```
2020-05-31 00:45:17 +02:00
Christian Boltz
9fc8e43c67 abstractions: remove '#' from 'include if exists'
This matches what we use in the profiles for local abstractions.

Also adjust the check in the Makefile to expect the variant without '#'.
2020-05-30 19:53:49 +02:00
John Johansen
bf8aa7809d Merge Add policy feature abi support
AppArmor 3.0 tags policy with the feature abi it was developed under. This fixes issues with kernel upgrades that add new mediation features and reduces the need to pin policy.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/491
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-05-29 08:27:34 +00:00
John Johansen
730db17607 policy: tag policy with the AppArmor 3.0 abi
Tag profiles and abstractions with abi information.

Tagging abstractions is not strictly necessary but allows the parser
to detect when their is a mismatch and that policy will need an
update for abi.

We do not currently tag the tunables because variable declarations
are not currently affected by abi.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/491
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-05-29 00:23:17 -07:00
John Johansen
162da1ba48 parser: add basic support for feature abis
Add basic support for policy to specify a feature abi. Under the
current implementation the first feature abi specified will be
used as the policy abi for the entire profile.

If no feature abi is defined before rules are processed then the
default policy abi will be used.

If multiple feature abi rules are encountered and the specified
abi is different then a warning will be issued, and the initial abi
will continue to be used. The ability to support multiple policy
feature abis during a compile will be added in a future patch.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/491
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-05-29 00:23:37 -07:00
John Johansen
a29e232831 parser: feature abi: setup parser to intersect policy and kernel features
The features abi adds the ability to track the policy abi separate
from the kernel. This allow the compiler to determine whether policy
was developed with a certain feature in mind, eg. unix rules.

This allows the compiler to know whether it should tell the kernel to
enforce the feature if the kernel supports the rule but the policy
doesn't use it.

To find if a feature is supported we take the intersection of what is
supported by the policy and what is supported by the kernel.

Policy encoding features like whether to diff_encode policy are not
influenced by policy so these remain kernel only features.

In addition to adding the above intersection of policy rename
--compile-features to --policy-features as better represents what it
represents. --compile-features is left as a hidden item for backwards
compatibility.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/491
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-05-29 00:23:17 -07:00
John Johansen
f951f1de28 Merge Add AliasRule and AliasRuleset, and switch alias handling to them
As usual, the classes come with some tests.

A side effect of the change is a fix for the "last one wins" bug if a profile has two alias rules with the same path on the left side.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/550
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-29 07:10:34 +00:00
Steve Beattie
43fd972bb5 common/Make.rules: add -Wimplicit-fallthrough compiler warning
Add -Wimplicit-fallthrough to the default set of compiler warnings.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-28 16:56:26 -07:00
Steve Beattie
e093815ab1 build: add and use global EXTRA_WARNINGS from common/Make.rules
Define EXTRA_WARNINGS in the common/Make.rules helper so that adding
additional warnings can be done in one(-ish) location, and replace
locally defined C compiler warning flags with EXTRA_WARNINGS in most
locations in the build tree.

v2: issue a warning for any compiler option that the compiler does not
    support

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-28 16:55:50 -07:00
Christian Boltz
c4db85c66a IncludeRule: sort files in included directory
... instead of relying on the filesystem(!) ordering, which will look
random to both users and unittests.

Also partially revert the test changes from
c5a7bcd50e /
https://gitlab.com/apparmor/apparmor/-/merge_requests/548 -
sorting the result only in the tests is a bad idea.
2020-05-28 20:17:29 +02:00
Christian Boltz
e3af898ca4 Switch alias handling to AliasRule and AliasRuleset
This fixes cases when two aliases with the same left side were
configured - instead of "last one wins" in the dict, AliasRuleset now
keeps both.

ProfileList add_alias() changes its parameters and now expects an
AliasRule object. Adjust all callers to that.

Drop the no longer needed write_alias().

Also adjust the tests to use AliasRule and add a dedup test promised in
an earlier patch series.
2020-05-28 20:08:57 +02:00
Steve Beattie
d29bf02d7b libapparmor/policy_cache.c: asprintf returns a signed int
asprintf(3) returns a signed int, so storing the result in a size_t is
and then comparing that stored value against -1 is not such a good idea.

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/549
2020-05-28 09:27:12 -07:00
Steve Beattie
5250ca079d C Makefiles: make C warning flag usage consistent
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/549
2020-05-28 09:24:56 -07:00
Christian Boltz
5bf9b51d4d Add AliasRule and AliasRuleset classes
Also add some tests for them.
2020-05-27 14:05:38 +02:00
Christian Boltz
f0fd410fd1 Extend RE_PROFILE_ALIAS to provide named matches 2020-05-27 14:05:35 +02:00
Christian Boltz
09896bd5f1 Merge branch 'cboltz-variable' into 'master'
Add VariableRule and VariableRuleset and use it for variable handling

Besides the usual advantages of switching to classes, we finally get rid of the `filelist` hasher.

While on it, also fix some bugs around variable handling, including https://bugs.launchpad.net/apparmor/+bug/1331856 and some that maybe nobody noticed before.

As usual, see the individual commits for details.

See merge request apparmor/apparmor!544

Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-27 11:43:29 +00:00
Christian Boltz
d19735340a Detect invalid trailing commas in variable definitions
Trailing commas in variable values are not allowed (unless they are
quoted). Fix the regex to avoid "eating" the comma, and add a check to
detect invalid commas.

As usual, add some tests, and remove some testcases from the
exception_not_raised list.
2020-05-27 13:32:44 +02:00
Christian Boltz
0629215f2a Check for variable names not ending with }
... and add a test to ensure that everything works as expected.

Note that broken variable names like '@{foo' match the (quite
permissive) regex, but are invalid nevertheless.
2020-05-27 13:32:44 +02:00
Christian Boltz
e9b8139cee Check variable errors when parsing simple_tests
... by calling active_profiles.get_all_merged_variables()

Also remove vars/vars_bad_add_assignment_1.sd from the
exception_not_raised list again - now it raises an exception as
expected.
2020-05-27 13:32:44 +02:00
Christian Boltz
7d86bf9fe2 severity: replace load_variables() with set_variables()
Add set_variables() to severity.py to set the variables for severity
rating. It typically gets the data from the get_all_merged_variables()
result.

This replaces the slightly broken load_variables() that parsed profile
files for variables. (For example, parsing "@{foo} = /bar" resulted
in a variable name "@{foo} " with trailing space.)

Also adjust aa.py and the severity tests to use set_variables() (with
get_all_merged_variables()) instead of load_variables().

This also re-adds the checks that were removed in the "Store variables
in active_profiles (ProfileList)" commit earlier, while still fixing
lp:1331856.

With this change, unload_variables() becomes useless (the variables get
overwritten in set_variables() anyway), drop it and its calls.

Note that load_variables() silently ignored non-existing files while the
get_all_merged_variables() call only works for existing files that are
known to active_profiles. Since the input of ask_the_questions() and
ask_exec() comes from log_dict (= audit.log or a profile to merge), add
a check if that profile actually exists in the set of active profiles.

Also adjust the severity tests to use set_variables().

Finally, drop the tests that check for handling non-existing include
files, redefining and adding to non-existing variables - all these
things get now handled in include_list_recursive() and
get_all_merged_variables() and their tests.

Fixes: https://bugs.launchpad.net/apparmor/+bug/1331856
2020-05-27 13:32:44 +02:00
Christian Boltz
7451c341a6 add get_all_merged_variables()
This function returns a dict with all variables and their values for a
given profile file. It also checks for redefined variables, and adding
to non-existing variables, and errors out in both cases. Note that it
does not check the include order and is therefore more forgiving than
apparmor_parser.

Also add some tests for get_all_merged_variables().

Note: the tests are based on reading "real" profiles, therefore we need
to initialize apparmor.aa and call some of its functions.

The alternative would be to construct ProfileList objects for some
profiles and includes manually, but doing that in a way that can replace
the tests with "real" profiles would be quite some work, and I'm not
bored enough for that ;-)
2020-05-27 13:32:44 +02:00
Christian Boltz
b13037e36d Move reset_aa() from aa-mergeprof to aa.py
Some tests in the next commit also need it.
2020-05-27 13:32:44 +02:00
Christian Boltz
6155b356b3 VariableRuleset: add get_merged_variables()
This function returns a dict with variables, both definitions (=) and
value additions (+=).

Also add some tests.
2020-05-27 13:32:44 +02:00
Christian Boltz
9d2a10dec7 ProfileList: merge get_clean_first() into get_clean()
Now that ProfileList handles the whole preamble, there's no need to keep
two half functions.
2020-05-27 13:32:44 +02:00
Christian Boltz
fe3c0b0ef8 Get rid of the 'filelist' hasher()
Everything handled in 'filelist' gets handled in active_profiles now.

Note: the 'elif' branch in delete_all_duplicates() was probably never
hit because `if include.get(...)` always matched. The only possible
exception might be non-existing include files, but those cause a 'file
not found' error anyway.
2020-05-27 13:32:44 +02:00
Christian Boltz
430120879c Drop now unused store_list_var() and its tests 2020-05-27 13:32:44 +02:00
Christian Boltz
abe0e2b246 ProfileStorage: Drop 'lvar' and write_list_vars()
Since the previous commit, variables never get stored in ProfileStorage,
and write_list_vars() is unused.
2020-05-27 13:32:44 +02:00
Christian Boltz
e5d38807df Store variables in active_profiles (ProfileList)
... instead of filelist[file]['lvar'], and also write them from there.

Also fix detection of variable definitions inside a profile, which is
not allowed.

Note that ProfileList has a different write order than the old code -
first includes, then variable definitions. This makes more sense because
typical profiles first include tunables/global, and then define
additonal variables (that might use variables from tunables/global) or
extend variables defined in tunables/global.

This change also fixes some problems with the simple_test test profiles.
The "adding to non-existing variable" check currently doesn't exist,
which "fixes" lp:1331856.

OTOH this also means that such cases are not detected, therefore add
vars_bad_add_assignment_1.sd to the exception_not_raised list.

The check will be re-added in a later commit
in get_all_merged_variables().
2020-05-27 13:32:44 +02:00
Christian Boltz
2a58e0ada2 Extend ProfileList to handle (store/write) variables
... and also add some tests.
2020-05-27 13:32:43 +02:00
Christian Boltz
61db5595aa VariableRuleset: Prevent re-defining variables
When adding a variable with a name that is already known to the
VariableRuleset, raise an exception.

Also add a test for this.
2020-05-27 13:32:43 +02:00
Christian Boltz
39eb1939ba Split variables
... and enable tests related to this
2020-05-27 13:32:43 +02:00
Christian Boltz
1eb9791ed7 move separate_vars() from aa.py to VariableRule
... and also move its tests to test-variable.py
2020-05-27 13:32:43 +02:00
Christian Boltz
215ec38ae3 Add VariableRule and VariableRuleset
... and a set of tests for them.

Note that the tests include some TODOs, these will be handled in the
following commits.
2020-05-27 13:32:43 +02:00
Steve Beattie
c5a7bcd50e utils/tests: test-include.py sometimes fails due to ordering
With the includes rule class landing, this particular test failed
in a test vm due to the sort ordering being different. It's not
clear that there should be an expectation of ordering returned from
get_full_paths(), so sort the result.

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/548
2020-05-27 01:03:56 -07:00
John Johansen
7fa74521fb Merge Fix strip_quotes() to handle empty strings
strip_quotes() assumed its parameter is at least one character long, and errored out on an empty string.

It also converted a string consisting of a single quote to an empty string because that single quote had a quote as first and last char.

This commit fixes these two bugs.

Also rewrite TestStripQuotes to use tests\[\], and add some test for an empty string, a one-char path (just a slash) and a single quote.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/545
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-26 07:40:56 +00:00
John Johansen
1aa80fd14d Merge Allow to read icu *.dat files in postfix-related profiles
This is needed for postdrop, postmap, postqueue and sendmail

Seen on openSUSE Tumbleweed.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/546
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-26 07:38:41 +00:00
Christian Boltz
5d04922f00 Merge branch 'dnsmasq-trust-anchors' into 'master'
dnsmasq: allow reading DNSSEC trust anchors

See merge request apparmor/apparmor!547

Acked-by: Christian Boltz <apparmor@cboltz.de
2020-05-25 17:05:03 +00:00
Christian Boltz
b23aa00b81 Allow to read icu *.dat files in postfix-related profiles
This is needed for postdrop, postmap, postqueue and sendmail

Seen on openSUSE Tumbleweed.
2020-05-25 13:33:07 +02:00
intrigeri
1b9469eb31 dnsmasq: allow reading DNSSEC trust anchors
At least on Debian, when DNSSEC validation is enabled, dnsmasq needs to read
/usr/share/dnsmasq-base/trust-anchors.conf

Bug-Debian: https://bugs.debian.org/934869
2020-05-25 10:42:26 +00:00
Christian Boltz
373e8e23b1 Fix strip_quotes() to handle empty strings
strip_quotes() assumed its parameter is at least one character long, and
errored out on an empty string.

It also converted a string consisting of a single quote to an empty
string because that single quote had a quote as first and last char.

This commit fixes these two bugs.

Also rewrite TestStripQuotes to use tests[], and add some test for an empty
string, a one-char path (just a slash) and a single quote.
2020-05-24 13:41:13 +02:00
Christian Boltz
7629d18e04 convert RE_PROFILE_VARIABLE to named match groups
(no behaviour change, just easier to use)
2020-05-22 00:51:18 +02:00
John Johansen
f891dad070 Merge vulkan: fix device and driver enumeration
vkcube test application produces these DENIED messages on current Debian Sid:

```
type=AVC msg=audit(1589815066.509:868): apparmor="DENIED"
operation="open" profile="/usr/bin/vkcube"
name="/sys/devices/pci0000:00/0000:00:02.0/drm/card0/gt_min_freq_mhz"
pid=32553 comm="vkcube" requested_mask="r" denied_mask="r" fsuid=1000
ouid=0
```

```
type=AVC msg=audit(1590082079.377:1155): apparmor="DENIED"
operation="open" profile="/usr/bin/vkcube"
name="/sys/devices/pci0000:00/0000:00:02.0/drm/card0/gt_max_freq_mhz"
pid=51348 comm="vkcube" requested_mask="r" denied_mask="r" fsuid=1000
ouid=0
```

```
type=AVC msg=audit(1590082107.057:1249): apparmor="DENIED"
operation="open" profile="/usr/bin/vkcube"
name="/sys/devices/pci0000:00/0000:00:02.0/drm/card0/metrics/" pid=51459
comm="vkcube" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
```

```
type=AVC msg=audit(1590082519.937:1408): apparmor="DENIED"
operation="open" profile="/usr/bin/vkcube"
name="/sys/devices/pci0000:00/0000:00:02.0/drm/card0/metrics/403d8832-1a27-4aa6-a64e-f5389ce7b212/id"
pid=51960 comm="vkcube" requested_mask="r" denied_mask="r" fsuid=1000
ouid=0
```

```
type=AVC msg=audit(1590082842.193:1829): apparmor="DENIED"
operation="open" profile="/usr/bin/vkcube"
name="/etc/glvnd/egl_vendor.d/" pid=53000 comm="vkcube"
requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
```

```
type=AVC msg=audit(1590082842.193:1830): apparmor="DENIED"
operation="open" profile="/usr/bin/vkcube"
name="/usr/share/glvnd/egl_vendor.d/" pid=53000 comm="vkcube"
requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
```

Add appropriate rules to fix these enumerations.
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/543
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-21 19:53:20 +00:00
John Johansen
51c5251d8c Merge binutils: add -Wformat to fix compiler warning
The warning is/was:

cc1: warning: '-Wformat-security' ignored without '-Wformat' \[-Wformat-security\]

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/542
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-21 19:50:18 +00:00
John Johansen
1fccf0458f Merge aa-status: append \n to --json and --pretty-json output
... so that - if someone calls aa-status from the commandline - the next prompt doesn't get displayed in the same line as the json output.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/541
Acked-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-21 19:48:14 +00:00
John Johansen
7daed8eb79 Merge Error out on conflicting aa-exec parameters
If multiple -p/--profile or -n/--namespace parameters are given to aa-exec, they are handled on a "last one wins" base.

This probably isn't expected behaviour, and erroring out in case of conflicting parameters probably makes more sense.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/540
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-21 19:11:00 +00:00
Vincas Dargis
21bbfc0652 vulkan: fix device and driver enumeration
vkcube test application produces these DENIED messages on current Debian
Sid:
```
type=AVC msg=audit(1589815066.509:868): apparmor="DENIED"
operation="open" profile="/usr/bin/vkcube"
name="/sys/devices/pci0000:00/0000:00:02.0/drm/card0/gt_min_freq_mhz"
pid=32553 comm="vkcube" requested_mask="r" denied_mask="r" fsuid=1000
ouid=0
```

```
type=AVC msg=audit(1590082079.377:1155): apparmor="DENIED"
operation="open" profile="/usr/bin/vkcube"
name="/sys/devices/pci0000:00/0000:00:02.0/drm/card0/gt_max_freq_mhz"
pid=51348 comm="vkcube" requested_mask="r" denied_mask="r" fsuid=1000
ouid=0
```

```
type=AVC msg=audit(1590082107.057:1249): apparmor="DENIED"
operation="open" profile="/usr/bin/vkcube"
name="/sys/devices/pci0000:00/0000:00:02.0/drm/card0/metrics/" pid=51459
comm="vkcube" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
```

```
type=AVC msg=audit(1590082519.937:1408): apparmor="DENIED"
operation="open" profile="/usr/bin/vkcube"
name="/sys/devices/pci0000:00/0000:00:02.0/drm/card0/metrics/403d8832-1a27-4aa6-a64e-f5389ce7b212/id"
pid=51960 comm="vkcube" requested_mask="r" denied_mask="r" fsuid=1000
ouid=0
```

```
type=AVC msg=audit(1590082842.193:1829): apparmor="DENIED"
operation="open" profile="/usr/bin/vkcube"
name="/etc/glvnd/egl_vendor.d/" pid=53000 comm="vkcube"
requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
```

```
type=AVC msg=audit(1590082842.193:1830): apparmor="DENIED"
operation="open" profile="/usr/bin/vkcube"
name="/usr/share/glvnd/egl_vendor.d/" pid=53000 comm="vkcube"
requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

```

Add appropriate rules to fix these enumerations.
2020-05-21 21:00:13 +03:00
Christian Boltz
91781aecde binutils: add -Wformat to fix compiler warning
The warning is/was:

cc1: warning: '-Wformat-security' ignored without '-Wformat' [-Wformat-security]
2020-05-21 17:54:24 +02:00
Christian Boltz
0b8839932a aa-status: append \n to --json and --pretty-json output
... so that - if someone calls aa-status from the commandline - the next
prompt doesn't get displayed in the same line as the json output.
2020-05-21 17:52:23 +02:00
Christian Boltz
02df146f31 Error out on conflicting aa-exec parameters
If multiple -p/--profile or -n/--namespace parameters are given to
aa-exec, they are handled on a "last one wins" base.

This probably isn't expected behaviour, and erroring out in case of
conflicting parameters probably makes more sense.
2020-05-21 17:04:40 +02:00
John Johansen
4b79a58c25 Merge Switch handling of include rules from filelist to IncludeRule
This patch series moves include rule handling away from the `filelist` hasher to using IncludeRule and IncludeRuleset. This means that only variable handling is left in `filelist`.

As usual, check the individual commits for details.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/537
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-21 08:52:49 +00:00
Christian Boltz
1d2e710b26 parse_profile_data(): drop old code for parsing include rules
With this, all include rules (with and without 'if exists') get handled
by the code that handles IncludeRule.
2020-05-20 18:57:54 +02:00
Christian Boltz
cefc64522d Drop now unused 'include' from ProfileStorage and ProfileList 2020-05-20 18:57:54 +02:00
Christian Boltz
60e8c1ff41 No longer write to filelist['include] or profile['include']
All code is migrated to IncludeRuleset / 'inc_ie'], so there's no point
in filling 'include' anymore.
2020-05-20 18:57:54 +02:00
Christian Boltz
5cfab9b81b serialize_profile(): write preamble without checking filelist
filelist is getting emptier and emptier, and checking against a
nearly-empty filelist would result in not writing the preamble.
2020-05-20 18:57:54 +02:00
Christian Boltz
f0fa69a010 Convert compare_profiles() to use inc_ie / IncludeRule 2020-05-20 18:57:54 +02:00
Christian Boltz
706138ed67 Convert remove_duplicate_rules() to use inc_ie / IncludeRule
Besides switching to 'inc_ie', also drop the old code that removed
duplicate 'include' rules.
2020-05-20 18:57:54 +02:00
Christian Boltz
c8fa3dec0a aa-cleanprof: don't check profile includes against preamble includes
remove_duplicate_rules() composed the 'includes' list from a) the
include rules in the profile and b) the file_includes (preamble
includes), and then checked the profile includes against this
combination of profile and preamble includes.

Checking profile includes against preamble includes is wrong, and the
only reason why this went unnoticed for years is that preamble include
files (like tunables) won't work inside a profile and therefore never
appear there.

In theory this might be a backport candidate, even if this shouldn't
cause a real-world bug.
2020-05-20 18:57:54 +02:00
Christian Boltz
6161641bcf Convert match_includes() to use inc_ie / IncludeRule 2020-05-20 18:57:54 +02:00
Christian Boltz
cfdbcb20cc add include_list_recursive()
This function returns a list of all includes in a profile and its
included files.

It's split off from is_known_rule() and get_file_perms() which shared
lots of common code to recursively get the include list. These functions
now use include_list_recursive().
2020-05-20 18:57:54 +02:00
Christian Boltz
6f1245ede9 Convert is_known_rule() to use inc_ie / IncludeRule
While on it, also add a missing check to avoid checking the same file
twice.
2020-05-20 18:57:54 +02:00
Christian Boltz
9f1b2f4014 collapse_log(): avoid accidently initializing aa[profile]
... or calling is_known_rule() on events for non-existing hats.

It's the usual hasher() "fun" again - accessing a non-existing element
will create its parent.

In theory this commit might be worth a backport. In practise, it doesn't cause
any visible problem.

However, starting with the next commit, it will cause lots of test errors.

Also add a missing is_known_rule() call for dbus rules, which might have
caused similar hasher() "fun".
2020-05-20 18:57:54 +02:00
Christian Boltz
fa67815698 Convert get_file_perms() to use inc_ie / IncludeRule 2020-05-20 18:54:53 +02:00
Christian Boltz
0cfef21713 IncludeRuleset: add get_all_full_paths()
This function returns a list of full paths of all includes.

Also add some tests.
2020-05-20 18:54:53 +02:00
Christian Boltz
057c916032 parse_profile_data(): call load_include() for IncludeRule
rule_obj.get_full_paths() handles directories and non-existing files
(depending on 'if exists'), so we can simply feed the resulting list
into load_include()
2020-05-20 18:54:53 +02:00
Christian Boltz
f3f597ff0b IncludeRule: add get_full_paths()
This function returns a list of paths for an include rule. This can be
- a single path if the include file is a file and exists
- a single path if the include file doesn't exist, but doesn't have
  'if exists' (this will cause a 'file not found' error when used)
- a list of paths if the include is a directory
- an empty list if the rule has 'if exists' and the file doesn't exist

Also add some tests for get_full_paths()
2020-05-20 18:54:53 +02:00
Christian Boltz
d799195e0a move is_skippable_file() from aa.py to common.py
IncludeRuleset needs to import it (next commit), which is impossible
when it lives in aa.py (would cause recursive import loop because aa.py
imports IncludeRuleset)
2020-05-20 18:54:53 +02:00
Christian Boltz
3f0f7154f7 Let aa-cleanprof remove duplicate preamble rules
Technically, this is done in the new function
delete_preamble_duplicates() in ProfileList.

Also add some tests to ensure this works as expected.
2020-05-20 18:54:53 +02:00
Christian Boltz
0cf15d54b6 aa-mergeprof: drop separate code asking for include rules
... because this is now done via IncludeRule, and keeping the separate
code would mean asking twice.

Note that the user interface changes slightly.

The old workflow was

    1 - #include <foo>
    2 - #include <bar>
    3 - #include <baz>
    [select 2 and (A)dd, then get the next question for the remainder]

    1 - #include <foo>
    2 - #include <baz>
    [(A)dd another one, or (I)gnore the remainder]

The new workflow will ask separately for each abstraction, and you can
(A)dd or (I)gnore it. This is probably easier to understand because it's
basically a yes/no question.
2020-05-20 18:52:16 +02:00
Christian Boltz
23af115fa5 store include rules (also) in 'inc_ie' (IncludeRueset)
... and write them (only) from 'inc_ie' (IncludeRuleset), which can
handle both "include" and "include if exists" rules.

This duplicates storage of include rules because 'include' is still used
and needed at various places that work on/with the include rules.

With this, we get removal of duplicate include lines insinde a profile
in aa-cleanprof "for free" - extend cleanprof_test.in to confirm this.
2020-05-20 18:50:20 +02:00
Christian Boltz
7144bd7181 Merge branch 'drop-includes' into 'master'
aa-notify: don't load policy includes

See merge request apparmor/apparmor!538

Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-05-19 17:12:03 +00:00
John Johansen
cc869c901e aa-notify: don't load policy includes
aa-notify does not need to load the policy includes for its current
features, so drop the unneeded overhead.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-05-19 02:47:21 -07:00
John Johansen
a7a727b1b0 Merge Make save_profiles() usable for aa-mergeprof
... and replace the aa-mergeprof code that asks about saving the profile with a call to save_profiles().

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/536
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-18 08:27:10 +00:00
John Johansen
69eeca80dd Merge aa-mergeprof: simplify internal parameter handover
Instead of stuffing two variables into a list and split them again, hand them over as plain separate variables.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/535
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-18 08:22:26 +00:00
John Johansen
500acf7119 Merge valid_include(): move out unrelated check
alid_include() checks if the given include file exists or is whitelisted in cfg\['settings'\]\['custom_includes'\].

The check if that include file is already part of the profile is unrelated to that. Move it to match_includes() where it fits much better (and drop the now superfluous profile parameter from valid_include())

In theory is_known_rule() should prevent that case from ever happening, but let's restrict this commit to moving the code around and keep this check just to be sure.

While on it, add some documentation to both functions.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/534
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-18 08:19:54 +00:00
John Johansen
c4d1cfa487 Merge split off ask_rule_questions() from ask_the_questions()
Also rename aa.py delete_duplicates() and make ruletypes a parameter.

See the commit messages for details.

This reduces usage of global variables.

The final change is that aa-genprof now asks about preamble rules that are \*Rule classes (currently `abi` and `include if exists`).

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/532
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-18 08:16:48 +00:00
Christian Boltz
34d4d9f5af Make save_profiles() usable for aa-mergeprof
... and replace the aa-mergeprof code that asks about saving the profile
with a call to save_profiles().
2020-05-17 16:50:01 +02:00
Christian Boltz
ed0f2fe505 aa-mergeprof: simplify internal parameter handover
Instead of stuffing two variables into a list and split them again, hand
them over as plain separate variables.
2020-05-14 23:29:31 +02:00
Christian Boltz
7f7fc973f8 valid_include(): move out unrelated check
valid_include() checks if the given include file exists or is
whitelisted in cfg['settings']['custom_includes'].

The check if that include file is already part of the profile is
unrelated to that. Move it to match_includes() where it fits much
better (and drop the now superfluous profile parameter from
valid_include())

In theory is_known_rule() should prevent that case from ever happening,
but let's restrict this commit to moving the code around and keep this
check just to be sure.

While on it, add some documentation to both functions.
2020-05-14 22:48:20 +02:00
Christian Boltz
e0f9b7cb07 Merge branch 'cboltz-fail-verbose' into 'master'
read_profile(): don't fail silently

See merge request apparmor/apparmor!530

Acked-by: Steve Beattie <steve.beattie@canonical.com> for 2.11..master
2020-05-12 19:43:44 +00:00
John Johansen
d1dca1f2d4 Merge ProfileList: add __repr__() with list of filenames
Even if incomplete (it doesn't print the whole ProfileList content), this should make debugging easier.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/531
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-12 07:44:12 +00:00
Christian Boltz
85f2cd4ed4 Let aa-mergeprof ask about more preamble (*Rule) rules
For now, that means aa-mergeprof will ask for `abi` and `include if
exists` rules (currently hardcoded).

This needs storing of `active_profiles` in the Prof object - the
preamble `abi` and `include if exists` rules are stored there.

Since several functions expect an `include` dict, add an empty one to
ProfileList to prevent lots of errors and breakage. It can be removed
again when handling of `include` rules gets moved to IncludeRule.
2020-05-11 23:41:25 +02:00
Christian Boltz
3e0f4e1dba rename aa.py delete_duplicates() and make ruletypes a parameter
Rename delete_duplicates() to delete_all_duplicates() to make the
function easier grep-able - the *rule classes have delete_duplicates()
which might be confused with the old name.

Also hand over 'ruletypes' as parameter to delete_all_duplicates()
instead of using the global variable.
2020-05-11 23:03:23 +02:00
Christian Boltz
ca693db3b0 split off ask_rule_questions() from ask_the_questions()
ask_the_questions() stays the "main" function, loops over all profiles,
and calls ask_rule_questions() for each profile.

ask_rule_questions() asks the questions for all events in a specific
profile or hat.

This reduces the usage of global variables in ask_rule_questions().
2020-05-11 23:01:06 +02:00
Christian Boltz
e841c866d3 ProfileList: add __repr__() with list of filenames
Even if incomplete (it doesn't print the whole ProfileList content),
this should make debugging easier.
2020-05-11 22:46:29 +02:00
Christian Boltz
af8b9dc5bb read_profile(): don't fail silently
If a profile file can't be read, print a warning so that the user is
aware of the problem.
2020-05-11 22:23:20 +02:00
Steve Beattie
da2ce3ac67 utils: Use ProfileList to handle aliases
Merge branch 'cboltz-alias' into 'master'

Acked-by: Steve Beattie <steve.beattie@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/526
2020-05-11 08:51:42 +00:00
Christian Boltz
cb44e6d47d Merge branch 'cboltz-drop-is-active-profile' into 'master'
Drop is_active_profile()

See merge request apparmor/apparmor!529

Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-11 08:37:16 +00:00
Christian Boltz
a5434e562d Merge branch 'cboltz-drop-write-rules' into 'master'
Drop / inline write_rules()

See merge request apparmor/apparmor!528

Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-10 23:03:47 +00:00
Christian Boltz
ae70ecfbaa Merge branch 'cboltz-vim-alias' into 'master'
apparmor.vim: allow leading whitespace for alias rules

See merge request apparmor/apparmor!527

Acked-by: Steve Beattie <steve.beattie@canonical.com> for 2.11..master
2020-05-10 22:54:34 +00:00
Christian Boltz
710d5ae466 Drop is_active_profile()
... and inline it at the only place that uses it
2020-05-10 23:49:16 +02:00
Christian Boltz
5c48eb7aa7 Drop / inline write_rules()
The TODO in write_rules() was long solved - remove the safety net type
check, it's no longer needed.

Without this, the function becomes a simple .get_rules_clean() call
which can easily be inlined into write_piece() at the two places where
it's called.
2020-05-10 18:09:14 +02:00
Christian Boltz
3c9c162951 write_alias(): drop depth parameter
... which is always '0' anyways, and therefore superfluous
2020-05-10 17:42:55 +02:00
Christian Boltz
8855c60f23 move write_alias to ProfileList
It's only needed in the preamble, which makes ProfileList the perfect
place.
2020-05-10 17:40:53 +02:00
Christian Boltz
fc6bd72781 Drop alias handling from ProfileStorage
ProfileStorage handles the profile content, but not the preamble. This
also means it will never see any aliases.
2020-05-10 17:39:02 +02:00
Christian Boltz
c636580f18 apparmor.vim: allow leading whitespace for alias rules 2020-05-10 17:24:09 +02:00
Christian Boltz
c0da20cf2c Use ProfileList to handle aliases 2020-05-10 13:37:05 +02:00
Christian Boltz
77a22979ed ProfileList: Add support for alias rules
... and also some tests
2020-05-10 13:37:05 +02:00
John Johansen
13bea6f4a7 Merge Introduce and use AbiRule to handle abi rules
See the individual commits for details.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/525
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-10 02:24:01 +00:00
John Johansen
676df24182 Merge Replace filelist[file_name]['profiles'] with using ProfileList
Replace usage of filelist\[file_name\]\['profiles'\] with the `active_profiles` ProfileList which already has the same data.

Add `profiles_in_file()` to ProfileList as a nice interface to get the list of profiles in a file.

For more details, check the individual commits.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/523
Avked-by: John Johansen <john.johansen>
2020-05-09 19:16:54 +00:00
Christian Boltz
66d3d92de3 Use AbiRule in ProfileStorage (for abi rules inside profiles)
This also drops the last usage of write_abi(), drop it.
2020-05-09 21:02:06 +02:00
Christian Boltz
d003cf814c Use AbiRule for profile preamble 2020-05-09 21:02:06 +02:00
Christian Boltz
5efccd146e ProfileList: Use AbiRuleset and add add_abi()
... and also tests for it
2020-05-09 21:02:06 +02:00
Christian Boltz
50d896705f Add AbiRule and testsuite
This is probably the shortest rule class we'll ever have because it can
inherit most things from IncludeRule.
2020-05-09 21:02:06 +02:00
Christian Boltz
3d13ddb30a Un-hardcode 'include' and 'IncludeRule' in IncludeRule
... as a preparation to recycle the class
2020-05-09 21:02:06 +02:00
Christian Boltz
e9557284a3 re_match_include_parse() raise bug exceptions only for include
... but not for abi rules, which (according to the simple_tests
profiles) do not share these bugs)

For unquoted paths, make sure that the path doesn't include whitespace.
2020-05-09 21:02:06 +02:00
Christian Boltz
8ca486715f extend re_match_include_parse() to also match abi rules
... and add some tests
2020-05-09 20:08:48 +02:00
Christian Boltz
b96fd81184 split out common parts of RE_INCLUDE and RE_ABI
... into RE_MAGIC_OR_QUOTED_PATH
2020-05-09 18:57:25 +02:00
John Johansen
28cdd08131 Merge add binutils/aa-status compiled files to .gitignore
Make so git ignores the generated files that result from building aa-status.

https://gitlab.com/apparmor/apparmor/-/merge_requests/524
Acked-by: John Johansen <john.johansen@canical.com>
2020-05-09 15:53:45 +00:00
Christian Boltz
c9ce3d3ab4 add binutils/aa-status compiled files to .gitignore 2020-05-09 13:29:24 +02:00
Steve Beattie
5574af0390 parser tests: convert makefile error tests to python script
Make the error and warning message tests a first class test script; in
gitlab CI, failures would not necessarily result in output being
captured.

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/522
2020-05-08 15:44:41 -07:00
Steve Beattie
500cbf89a7 parser testlib: restructure command run functions
Don't commingle stderr and stdout by default, and provide a
function that provides the exit value, stderr, and stdout as a
tuple. Also, expect UTF-8 output by default from the commands (with
universal_newlines), rather than bytes.

(Nifty commands like subprocess.run() weren't added to python until
python 3.5.)

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/522
2020-05-08 15:43:34 -07:00
Christian Boltz
874d3385a3 Stop writing to filelist[file]['profiles']
... because after the previous three commits, nothing reads/needs this
anymore

Note: file_name in ask_exec() was only used in the (dropped) filelist
usage.
2020-05-08 23:00:35 +02:00
Christian Boltz
4e09f315c3 Use active_profiles.profiles_in_file()
... instead of filelist[file_name]['profiles']
2020-05-08 22:40:38 +02:00
Christian Boltz
01e46ab453 Add profiles_in_file() to ProfileList
... and some tests for it.
2020-05-08 22:37:45 +02:00
Christian Boltz
34a0457090 parse_profile_data(): better way to check for duplicate hats
Instead of checking filelist[file]['profiles'] for duplicate hats, check
profile_data[profile][hat].

With this, the duplicate hat check is done in the same way as the check
for duplicate profiles and child profiles.

Also add tests for duplicate child profiles and duplicate hats.
2020-05-08 22:15:10 +02:00
Christian Boltz
6b55794074 Merge branch 'cboltz-less-shell' into 'master'
less shell ;-)

See merge request apparmor/apparmor!520

Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-07 17:59:06 +00:00
Christian Boltz
48bae9e3b0 less shell ;-)
Using a list as parameter for subprocess.call is more secure, and avoids
funny problems if the filename to display contains spaces or other funny
characters.
2020-05-07 19:45:39 +02:00
John Johansen
74c90c797c Merge drop unused get_pager()
The only usage was dropped/replaced when switching to `UI_ShowFile()` in https://gitlab.com/apparmor/apparmor/-/merge_requests/514

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/515
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-07 17:40:36 +00:00
Christian Boltz
d459cbf0f4 drop unused get_pager()
The only usage was dropped/replaced when switching to UI_ShowFile() in
https://gitlab.com/apparmor/apparmor/-/merge_requests/514
2020-05-07 12:13:20 +02:00
Steve Beattie
aca65e8d3c aa-status: fix exposed compiler warnings
Fix signed/unsigned comparison warnings, and silence unused parameter
warnings due to the "cleverness" of the function pointer array and
wanting to print out the command as invoked in the usage statement.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
https://gitlab.com/apparmor/apparmor/-/merge_requests/517
2020-05-07 01:12:38 -07:00
Steve Beattie
05747a9e1d binutils: actually use listed compiler warning flags
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
https://gitlab.com/apparmor/apparmor/-/merge_requests/517
2020-05-07 01:12:38 -07:00
Steve Beattie
5fc2cb5524 bintutils: delete the tools on make clean
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
https://gitlab.com/apparmor/apparmor/-/merge_requests/517
2020-05-07 01:12:37 -07:00
Steve Beattie
3d0d0c69bc aa_status: separate out version info
Separate out the aa-status json version info out from being a magic
element embedded in a string in the middle of the json emitter, and move
it to an early location, along with a comment to edit it whenthe format
changes.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
https://gitlab.com/apparmor/apparmor/-/merge_requests/517
2020-05-07 01:12:37 -07:00
John Johansen
2acb93c21a aa-status: add json pretty printing using cJSON
This restores aa-status ability to pretty print json by using
DaveGamble's cJSON: https://github.com/DaveGamble/cJSON

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/493
2020-05-07 01:12:28 -07:00
Christian Boltz
986b4f2b72 Merge branch 'cboltz-fix-genprof-json' into 'master'
Fix showing the local inactive profile in json mode

See merge request apparmor/apparmor!514

Acked-by: John Johansen <john.johansen@canonical.com> for 2.11..master
2020-05-06 22:43:35 +00:00
Christian Boltz
7b8f7d645e Merge branch 'cboltz-utils-cleanup' into 'master'
cleanup get_profile()

See merge request apparmor/apparmor!513

Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-06 22:42:48 +00:00
Christian Boltz
68a258b006 Fix showing the local inactive profile in json mode
When aa-genprof proposes a local inactive profile, it had a hardcoded
call to 'less' to display that profile.

Unsurprisingly, this doesn't work in JSON mode and breaks YaST (luckily
it's only a case of "the button doesn't work").

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1171315
2020-05-06 23:20:07 +02:00
Christian Boltz
bb3803b931 Split off UI_ShowFile() from UI_Changes
UI_ShowFile() is more generic and can be used to display various (text)
files, not only diffs.
2020-05-06 23:16:47 +02:00
Christian Boltz
4906bbf965 get_profile(): get rid of profile_type
It's always set to 'INACTIVE_LOCAL' - no need to set and later check it.

Also add a TODO note ;-)
2020-05-06 22:53:57 +02:00
Christian Boltz
f96304fe33 get_profile(): get rid of profile_data variable
... which also makes the code easier to understand
2020-05-06 22:53:22 +02:00
Christian Boltz
476848da46 get_profile: convert profile_hash from hasher() to dict 2020-05-06 22:53:22 +02:00
Christian Boltz
47620e10cb Rewrite get_profile() to exit early if no extra profile exists 2020-05-06 22:53:22 +02:00
Christian Boltz
2d2fc41cc1 inline get_inactive_profile() into get_profile()
... which is the only user of get_inactive_profile()
2020-05-06 22:53:22 +02:00
Steve Beattie
e6cf0d44d1 utils + parser: minor test cleanups
Fix a typo, some shellcheck warnings, and move one test script from using bash to dash.

See merge request apparmor/apparmor!512

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Christian Boltz <opensuse@cboltz.de>
https://gitlab.com/apparmor/apparmor/-/merge_requests/512
2020-05-06 20:35:28 +00:00
Christian Boltz
16c14737e4 Merge branch 'cboltz-fix-genprof' into 'master'
Fix aa-genprof/aa-autodep crash

See merge request apparmor/apparmor!511

Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-06 11:31:14 +00:00
Christian Boltz
c7949ba6c4 Read all profiles on aa-genprof startup instead of later
... which can mean "too late" in some special cases (if a profile
already exists in /etc/apparmor.d/$non_default_filename).

However, the main reason is that without this change
- the new profile will be added to (otherwise empty) active_profiles
- the first do_logprof_pass() will read all profiles, including the new
  one, and add them to active_profiles - which unsurprisingly results in
  an error like `ERROR: Profile /usr/sbin/vsftpd exists in
  /etc/apparmor.d/usr.sbin.vsftpd and /etc/apparmor.d/usr.sbin.vsftpd`

To fix this,
- change do_logprof_pass to never call read_profiles() (and get rid of
  the 'passno' parameter)
- adjust its callers (aa-logprof and aa-genprof) to call read_profiles()
  themself
- move printing the 'Updating AppArmor profiles in $directory.' message
  to read_profiles(), but only display it if requested (to keep the
  current UI behaviour)
2020-05-05 23:56:55 +02:00
Christian Boltz
db9f8d38b0 Fix aa-genprof/aa-autodep crash
Since 4b7108f1e5, aa-genprof and
aa-autodep crashed with

    apparmor.common.AppArmorBug: /etc/apparmor.d/usr.sbin.vsftpd not listed in ProfileList files

because the profile was not added to active_profiles.

Add the profile to active_profiles to fix this regression, and to have
all the needed data in active_profiles.
2020-05-05 22:24:08 +02:00
Christian Boltz
3d99683105 Merge branch 'cboltz-drop-repo-code' into 'master'
Drop profile repo code from utils

See merge request apparmor/apparmor!510

Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-05 20:07:14 +00:00
Steve Beattie
65f9d0e2ee parser: use /bin/sh for minimize test
There are no bashisms in the minimize.sh test script, so convert to
using to /bin/sh

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Bug: https://gitlab.com/apparmor/apparmor/issues/18
2020-05-05 12:14:04 -07:00
Steve Beattie
a5c0ef282d parser: shellcheck fixups on test scripts
Make the equality and minimize test scripts more shellcheck compliant.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-05 12:09:15 -07:00
Steve Beattie
253073b798 utils test: fix typo in simple_tests output
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-05 11:54:49 -07:00
Christian Boltz
256f55925c Drop profile repo code from utils
The profile repo is dead since years and most likely won't come back, so
there's no point in keeping and maintaining the code for uploading and
downloading profiles.
2020-05-05 13:09:16 +02:00
Steve Beattie
08c6c6eecf parser error tests: add filename profile deprecation checks
This add a couple of tests for
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/506

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-05-05 02:16:23 -07:00
John Johansen
91deb0cf13 parser: Display a deprecated warning when using filenames as a profile name
The use of filenames for a profile name has been deprecated in
AppArmor 3.0 so output a warning when ever a profile with a filename
based name is encountered.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/506
Acked-by: Steve Beattie <steve.beattie@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-05-05 02:16:23 -07:00
Steve Beattie
b2c706516f parser tests: add include in preamble tests
The parser tests were missing include tests for include entries in the
preamble section of a profile. This commit adds both #include and
include variants, as well as include if exists variants.

Also added is an exception list for the utils tests -- though it should
be noted that the utils silently drop the "#include if exists" format if
it's in the preamble without raising an exception.

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/509
2020-05-05 00:30:18 -07:00
John Johansen
5d52ab0783 Merge Handle preamble "include if exists" rules in ProfileList
Add support for handling `include if exists` rules in profile preambles in the `ProfileList` class.

Besides that, do some groundwork for future changes - see the individual commits for details and spoilers ;-)

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/507
Acked-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-05 07:18:09 +00:00
John Johansen
65f1d33a88 aa-status: bump the json version that aa-status outputs
aa-status output has changed slightly to account for the newer profile
modes. This means the json version needs to be bumped so consumers
can detect the change.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/508
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-05 00:14:36 -07:00
John Johansen
c386d93581 docs: update documentation to point bug reporting to gitlab
Move suggested bug reporting from launchpad to gitlab

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-05 00:10:53 -07:00
John Johansen
7ca90ab637 Docs: man apparmor.d: Document the profile header
Documentation of the profile header: name, attachments and flags
is missing. Add basic documentation describing the header and
it components.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/505
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-04 18:59:42 -07:00
Christian Boltz
4b7108f1e5 Store and write 'include if exists' rules in the preamble
... using the new storage in ProfileList.

Also add a test rule to cleanprof.{in,out} to ensure the rule is kept.
2020-05-04 22:14:52 +02:00
Christian Boltz
07b52134f4 Extend ProfileList to store and write include rules
- add_inc_ie() stores include and include if exists rules
- get_clean() and get_raw() return the profile preamble (currently only
  the include rules)

Also add tests for the new functions.
2020-05-04 22:14:44 +02:00
Christian Boltz
1569136180 Add get_clean_unsorted() to BaseRuleset
This is similar to get_clean(), but keeps the original rule order
instead of sorting them.

This is useful for include rules in the preamble, where the order might
be relevant - for example if the first include defines a variable that
is then used or extended in the second include file.
2020-05-04 21:59:02 +02:00
Christian Boltz
10fbdb28d3 ProfileList: keep track of profiles in each file
(not used yet, but will be useful later to replace
aa.filelist[$file]['profiles'] ;-)
2020-05-04 21:59:02 +02:00
Christian Boltz
c670d294eb Rename TestAdd and its functions to TestAdd_profile
This is a follow-up of 5983598ef5
2020-05-04 21:59:02 +02:00
Steve Beattie
64be247aae utils: ProfileList: rename add() to add_profile()
Merge branch 'cboltz-profile-list-rename-add' into 'master'

See merge request apparmor/apparmor!502
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-04 19:47:17 +00:00
Steve Beattie
e416f51c26 regression tests: add permissions for stacking LSM environments
With the addition of commits to make libapparmor LSM stacking aware, several tests were failing due to:

- aa_getpeercon() having an added aa_enabled() check
- aa_getprocattr() looking in /proc/pid/attr/apparmor/current first

Fix the specific failing testcases with additional permissions, and grant default profiles and hat generated by mkprofile.pl write access to /proc/*/attr/apparmor/current.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/504
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-04 18:56:27 +00:00
Steve Beattie
2444060617 regression tests: make stackprofile stacking LSM aware
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-03 20:13:58 -07:00
Steve Beattie
6e66065877 regression tests: add stacked attr/current access by default
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-03 20:13:54 -07:00
Steve Beattie
fb773fec36 socketpair regression test: add aa_getpeercon() enabled perm
Because of the need to be stacking LSM aware, aa_getpeercon() calls
aa_enable to ensure that apparmor is enabled. Without the permission,
aa_getpeercon() fails, causing test failures.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-03 20:11:52 -07:00
John Johansen
278bd918f9 regression tests: Make the xattr_profile.sh depend on outofband transitions
While xattr attachments exist without outofband transitions, they are
broken when values contain the null character. The addition of
outofband transitions fixes this problem.

While we could make the test requirement for outofband transitions
specific to a few tests, since the parser currently requires outofband
transitions to generate xattr attachment conditionals, for a first
pass just make the whole test suite require them.

Revisit this when/if the parser will allow xattr attachments without
outofband transitions.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-05-03 20:06:55 -07:00
Christian Boltz
dc2b971a7f Merge branch 'cboltz-better-failure-description' into 'master'
Better descriptions why some example profiles fail with the tools

See merge request apparmor/apparmor!501

Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-03 21:37:31 +00:00
Christian Boltz
5983598ef5 ProfileList: rename add() to add_profile()
This makes the syntax more clear, and is a preparation to allow adding
some more things (like global includes and variable definitions)
2020-05-03 22:37:20 +02:00
Christian Boltz
e8561236c1 Merge branch 'cboltz-local-if-exists' into 'master'
switch local includes to "include if exists"

See merge request apparmor/apparmor!489

Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-03 20:11:49 +00:00
Christian Boltz
6c4054fa91 Better descriptions why some example profiles fail with the tools 2020-05-03 22:07:25 +02:00
Christian Boltz
bb2409f935 adjust check for local/ includes to "include if exists" 2020-05-03 22:01:16 +02:00
Christian Boltz
110d6d214c switch local includes to "include if exists" 2020-05-03 22:01:13 +02:00
Christian Boltz
8661676eb4 Merge branch 'cboltz-utils-include-if-exists' into 'master'
Add support for 'include if exists' to the tools

See merge request apparmor/apparmor!499

Acked-by: Steve Beattie <sbeattie@ubuntu.com>
2020-05-03 19:59:11 +00:00
Christian Boltz
a4864146e2 Merge branch 'cboltz-vim-if-exists' into 'master'
apparmor.vim: support 'include if exists'

See merge request apparmor/apparmor!500

Acked-by: John Johansen <john.johansen@canonical.com> for 2.12..master
2020-05-03 19:27:57 +00:00
Steve Beattie
9b250ef63d test profiles: fix typo in descriptions
Merge branch 'cboltz-parser-tst-typo' into 'master'

See merge request apparmor/apparmor!498
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-05-03 19:17:08 +00:00
Christian Boltz
c2ac1b5669 Merge branch 'cboltz-superfluous-cast' into 'master'
Remove superfluous self-cast in Invalid*Test

See merge request apparmor/apparmor!495

Acked-by: John Johansen <john.johansen@canonical.com>
2020-05-03 12:32:19 +00:00
Christian Boltz
efa7c6d6b6 apparmor.vim: support 'include if exists' 2020-05-03 14:27:59 +02:00
Christian Boltz
6643d0b07a Add a 'include if exists' rule to cleanprof testcases
... to ensure it is kept.
2020-05-03 13:58:37 +02:00
Christian Boltz
295bb6469a Enable usage of IncludeRule in the tools
For now, only 'include if exists' rules will be handled by IncludeRule.
Using it also for 'include' rules needs some more code changes so that
included files still get checked etc.

Also remove some testcases from test-parser-simple-tests.py unknown_line
which no longer fail.
2020-05-03 13:55:03 +02:00
Christian Boltz
4df5ac780d Add IncludeRule and IncludeRuleset including tests
These classes are meant to handle 'include' and 'include if exists'
rules.

Due to restrictions in re_match_include_parse(), some cases in
is_covered_localvars() and is_equal_localvars() can't be reached in the
unittests.

Also, IncludeRule isn't used in aa-logprof (yet?), which means
logprof_header_localvars() result format isn't decided yet, and
therefore not tested.

This means test coverage for the new classes isn't 100% this time ;-)
2020-05-03 13:41:19 +02:00
Christian Boltz
0948df3de0 Fix typo in description of several test profiles
Several bare_include_tests and include_tests test profiles had "existss"
instead of "exists" in their description
2020-05-03 12:28:57 +02:00
John Johansen
dca5b452a5 LSM stacking: add missing permissions for using new kernel interfaces
LSM stacking adds the new /proc/<pid>/attr/apparmor directory
dedicated to apparmor so that it won't collide with other LSMs.

The library has already been switched to using this interface by
default, but the parser need to add permissions to access this
location when hats and/or change_profile rules are defined.

Also make sure to update the apache abstraction to support the new
interface as well.

Signed-off-by: John Johansen <john.johansen@canonical.com
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2020-05-03 01:00:18 -07:00
Christian Boltz
7b009a909e Remove superfluous self-cast in Invalid*Test 2020-05-02 22:13:34 +02:00
Christian Boltz
6b9b928f9d Add tests for re_match_include_parse()
Also extend tests for re_match_include() to make sure it doesn't match
"include if exists" rules.
2020-05-02 19:44:36 +02:00
Christian Boltz
d2dbf41137 add basic support for parsing "include if exists" rules
- extend RE_INCLUDE to also match "include if exists"
- rename re_match_include() to re_match_include_parse() and extend it to
  also support "include if exists" rules. The return value also includes
  "ismagic" now to avoid another future change, but that's not used yet.
- add re_match_include() which is now a wrapper around
  re_match_include_parse() and behaves exactly as the old
  re_match_include()
2020-05-02 19:44:06 +02:00
Christian Boltz
6557e06019 Merge branch 'parser-fix-deprecation-warnings' into 'master'
parser/caching test: fix deprecation warnings

See merge request apparmor/apparmor!492

Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-04-30 19:46:45 +00:00
Steve Beattie
e3e25fe86e parser/caching test: fix deprecation warnings
Newer python.unittest prefers assertNotEqual() over assertNotEquals():

  caching.py:143: DeprecationWarning: Please use assertNotEqual instead.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-30 11:26:36 -07:00
John Johansen
69a0c80a40 aa-status: reindent from spaces to tabs
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-29 16:56:58 -07:00
John Johansen
de8f1ba17d aa-status: add support for kill and unconfined profile modes
AppArmor 3 exposes kernel support for the kill and unconfined profile
modes. Make sure aa-status has basic support for these modes.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-29 16:56:58 -07:00
John Johansen
e3185cadf3 aa-status: add output for for stacked processes in mixed mode
Processes that are confined by multiple profiles in a stack can have
more than one profile mode applied. Allow aa-status to report
processes that are in a mixed profile confinement mode.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-29 16:56:58 -07:00
John Johansen
68811fa42b aa-status: switch aa-status to use libapparmor proc accessor and splitcon
Switch aa-status over to using the libapparmor proc accessor. This
will ensure that aa-status works correctly under LSM stacking kernels,
and if other new interfaces are added in the future.

Also at the same time switch over the splitting of context's to
the library provided aa_splitcon() fn.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-29 16:56:58 -07:00
John Johansen
8015535882 binutils: make aa-enabled LSM stacking aware
Make aa-enabled able to distinguish being enabled and enabled without
access to the shared LSM iterfaces.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-04-29 15:30:54 -07:00
John Johansen
f23125c265 libapparmor: make libapparmor LSM stacking aware
With LSM stacking apparmor may be available even if it is not
enabled. If apparmor is available but not enabled it does not own
the /proc/<pid>/attr/* interface and should not use it as they
will not provide apparmor context.

Note: this also applies to the SO_PEERSEC interface, currently we
only fail is apparmor does not own the interface. Once the new interface
command is finalized supprt to use that will be added.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-29 15:12:27 -07:00
John Johansen
fb219b5ba1 libapparmor: add support for the new dedicated apparmor interface
LSM stacking makes the old /proc/<pid>/attr/* interfaces potentially
be shared such that the values returned might be for a different LSM
than apparmor.

Use the new apparmor dedicated interface at /proc/<pid>/attr/apparmor/*
if it is present.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-29 15:12:08 -07:00
Christian Boltz
4281b58c89 Merge branch 'privacy' into 'master'
Privacy statement

See merge request apparmor/apparmor!441

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.11..master
2020-04-26 11:43:14 +00:00
John Johansen
f550c21545 Merge let logprof only propose abstractions without '# LOGPROF-SUGGEST: no'
This implements one part of https://gitlab.com/apparmor/apparmor/issues/15

(the --all-abstractions parameter is still missing, and the not-to-be-proposed abstractions obviously need the comment added)

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/254
Acked-by: John Johansen <john.johansen@canonical.com>
2020-04-26 10:44:49 +00:00
John Johansen
955439cbb3 libapparmor: force library configuration to search for python3
libapparmor and the pyton tools now require python3 but on systems
where python2 is the default the build will fail unless the PYTHON=
env var is set to the systems python3.

Instead just force autoconf to search for python3 as the python
version to use.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-04-26 03:05:48 -07:00
John Johansen
4e242fed7a Merge CI: Drop specifying python and pyflakes version
Since https://gitlab.com/apparmor/apparmor/-/merge_requests/482 python 3.x will be used by default (as the only python version), which makes it superfluous to explicitely specify it.

Note: requires fix: https://gitlab.com/apparmor/apparmor/-/merge_requests/486

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/483
Acked-by: John Johansen <john.johansen@canonical.com>
2020-04-26 10:04:55 +00:00
John Johansen
9ba2334423 Merge Fixings for crosscompilation
This series adds a couple of patches to make the software more crosscompilation friendly. They are based on the work I'm doing to fix the package on buildroot

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/485
Acked-by: John Johansen <john.johansen@canonical.com>
2020-04-26 09:45:04 +00:00
Angelo Compagnucci
6d682cf138 parser: binutils: fix compilation with libintl
When libintl is available on the system, we need to link against the
libintl library too.

Signed-off-by: Angelo Compagnucci <angelo@amarulasolutions.com>
2020-04-25 17:31:49 +02:00
Angelo Compagnucci
ed4e0a2551 parser: fix parallel install order
In order to have all the prerequisite folders before actually installing
os dependent configuration files, we need to guarantee the correct
install sequence.

Signed-off-by: Angelo Compagnucci <angelo@amarulasolutions.com>
2020-04-24 17:35:38 +02:00
John Johansen
d2464d6dcb Merge branch 'aa-status-in-c' into 'master'
Port aa-status from python to C

See merge request apparmor/apparmor!473
2020-04-24 05:43:48 +00:00
Alex Murray
8f9046b1b1 Merge Port aa-status from python to C
This allows aa-status to be used without a python runtime to support things like https://bugs.launchpad.net/bugs/1865519

Fixes: https://bugs.launchpad.net/bugs/1865519
PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/473
Acked-by: John Johansen <john.johansen@canonical.com>
2020-04-24 05:43:47 +00:00
John Johansen
e9c2a6087d Merge README: require python 3.3 for utils
... and drop the long-deprecated python 2.7 option, which no longer works.

This is a follow-up of https://gitlab.com/apparmor/apparmor/-/merge_requests/481 which did this change on the code side.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/482
Acked-by: John Johansen <john.johansen@canonical.com>
2020-04-20 22:19:33 +00:00
Christian Boltz
2c5d3cb381 CI: Drop specifying python and pyflakes version
Since https://gitlab.com/apparmor/apparmor/-/merge_requests/482
python 3.x will be used by default (as the only python version),
which makes it superfluous to explicitely specify it.
2020-04-20 13:28:09 +02:00
Christian Boltz
baab417059 README: require python 3.3 for utils
... and drop the long-deprecated python 2.7 option, which no longer
works.

This is a follow-up of
https://gitlab.com/apparmor/apparmor/-/merge_requests/481 which did this
change on the code side.
2020-04-20 13:10:43 +02:00
Christian Boltz
b6cbe57bd9 Merge branch 'python3' into 'master'
Switch python utils to only use Python3

See merge request apparmor/apparmor!481

Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-04-20 11:04:36 +00:00
John Johansen
ff7d1a4eb7 library: swig: require python 3 when building the swig interface
If Swig builds the library against python 2 and the utils/tests
run using python3, parts of the library are in accesible with
failures like

Traceback (most recent call last):
  File "test-pivot_root_parse.py", line 12, in <module>
    import apparmor.aa as aa
  File "/home/jj/apparmor/apparmor-jjohansen.git/utils/apparmor/aa.py", line 28, in <module>
    import apparmor.logparser
  File "/home/jj/apparmor/apparmor-jjohansen.git/utils/apparmor/logparser.py", line 19, in <module>
    import LibAppArmor
ImportError: No module named LibAppArmor

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-04-20 02:09:22 -07:00
John Johansen
9657d9b7e8 utils: default make check to pyflakes3
$ make check

will fail unless PYFLAKES=pyflakes3 is passed as an environment
variable. Fix it so make check will work by default.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-04-20 01:18:40 -07:00
John Johansen
af69088546 utils: only use python3 during testing
The apparmor python tools are written assuming python3. But the tests
are still using python2. This can result in failures of the test suite
on some systems, depending on how libapparmor is built.

Eg. on Ubuntu 18.04

apparmor.git/utils$ PYTHON=/usr/bin/python3 make check PYFLAKES=/usr/bin/pyflakes3
LANG=C podchecker -warning -warning *.pod
aa-audit.pod pod syntax OK.
aa-autodep.pod pod syntax OK.
aa-cleanprof.pod pod syntax OK.
aa-complain.pod pod syntax OK.
aa-decode.pod pod syntax OK.
aa-disable.pod pod syntax OK.
aa-easyprof.pod pod syntax OK.
aa-enforce.pod pod syntax OK.
aa-genprof.pod pod syntax OK.
aa-logprof.pod pod syntax OK.
aa-mergeprof.pod pod syntax OK.
aa-notify.pod pod syntax OK.
aa-remove-unknown.pod pod syntax OK.
aa-sandbox.pod pod syntax OK.
aa-status.pod pod syntax OK.
aa-unconfined.pod pod syntax OK.
logprof.conf.pod pod syntax OK.
aa-notify syntax OK
Checking aa-easyprof
Checking aa-genprof
Checking aa-logprof
Checking aa-cleanprof
Checking aa-mergeprof
Checking aa-autodep
Checking aa-audit
Checking aa-complain
Checking aa-enforce
Checking aa-disable
Checking aa-status
Checking aa-unconfined
Checking apparmor
Checking test/common_test.py
Checking test/minitools_test.py
Checking test/test-aa-decode.py
Checking test/test-aa-easyprof.py
Checking test/test-aa.py
Checking test/test-aamode.py
Checking test/test-aare.py
Checking test/test-baserule.py
Checking test/test-capability.py
Checking test/test-change_profile.py
Checking test/test-common.py
Checking test/test-config.py
Checking test/test-dbus.py
Checking test/test-example.py
Checking test/test-file.py
Checking test/test-libapparmor-test_multi.py
Checking test/test-logparser.py
Checking test/test-mount_parse.py
Checking test/test-network.py
Checking test/test-parser-simple-tests.py
Checking test/test-pivot_root_parse.py
Checking test/test-profile-list.py
Checking test/test-profile-storage.py
Checking test/test-ptrace.py
Checking test/test-regex_matches.py
Checking test/test-rlimit.py
Checking test/test-severity.py
Checking test/test-signal.py
Checking test/test-translations.py
Checking test/test-unix_parse.py
make[1]: Entering directory '/home/jj/apparmor/apparmor-jjohansen.git/utils/test'

=== test-example.py ===
.......
----------------------------------------------------------------------
Ran 7 tests in 0.000s

OK
.......
----------------------------------------------------------------------
Ran 7 tests in 0.000s

OK

=== test-pivot_root_parse.py ===
Traceback (most recent call last):
  File "test-pivot_root_parse.py", line 12, in <module>
    import apparmor.aa as aa
  File "/home/jj/apparmor/apparmor-jjohansen.git/utils/apparmor/aa.py", line 28, in <module>
    import apparmor.logparser
  File "/home/jj/apparmor/apparmor-jjohansen.git/utils/apparmor/logparser.py", line 19, in <module>
    import LibAppArmor
ImportError: No module named LibAppArmor
Makefile:81: recipe for target 'check' failed
make[1]: *** [check] Error 1
make[1]: Leaving directory '/home/jj/apparmor/apparmor-jjohansen.git/utils/test'
Makefile:95: recipe for target 'check' failed
make: *** [check] Error 2

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-04-20 01:18:12 -07:00
John Johansen
bfde89a62a infrastructure: Add privacy statement to the README
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-04-19 15:57:12 -07:00
Jamie Strandboge
5583569a29 allow accessing the libnss-systemd VarLink sockets and DBus APIs
https://systemd.io/USER_GROUP_API/ describes the libnss-systemd VarLink
socket APIs:

"
When a client wants to look up a user or group record, it contacts all
sockets bound in this directory in parallel, and enqueues the same query
to each. The first positive reply is then returned to the application,
or if all fail the last seen error is returned instead. (Alternatively
a special Varlink service is available, io.systemd.Multiplexer which
acts as frontend and will do the parallel queries on behalf of the
client, drastically simplifying client development.)
"

This updates the nameservice abstraction to allow read/write on
well-known systemd VarLink named sockets.

In addition, allow lookups for systemd-exec's DynamicUsers via D-Bus

References:
- https://systemd.io/USER_GROUP_API/
- https://systemd.io/USER_RECORD/
- https://www.freedesktop.org/software/systemd/man/nss-systemd.html
- https://www.freedesktop.org/software/systemd/man/systemd.exec.html
- https://launchpad.net/bugs/1796911
- https://launchpad.net/bugs/1869024

Modified by John Johansen by:
- moving rules nss-systemd include
- replacing /proc/ with @{proc}/
- moving and merging commit 16f9f688 rules into nss-systemd include

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/480
PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/474
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-04-16 10:21:04 -07:00
John Johansen
57c3d8e125 Merge test that '\*' from audit.log gets correctly escaped
convert_expression_to_aare() is expected to convert it to AARE `\\\*`

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/479
Acked-by: John Johansen <john.johansen@canonical.com>
2020-04-14 07:25:36 +00:00
John Johansen
333eb86734 Merge Get rid of is_covered_aare_compat()
This function was introduced as a temporary (ahem...) solution in 95404bb2f3 but was never really correct. It checked against other_value.regex (as a string!) and, while this was somewhat generous in the results, could have unintended side effects.

Better error out on the safe side and add/keep a few superfluous rules than having a wrong match in is_covered() and miss to add/keep a rule that would be needed.

The perfect solution would be to really compare one AARE against the other as the parser does. I'm not too keen to implement this in python, and will wait until someone provides this function (which the parser already has) via libapparmor ;-)

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/478
Acked-by: John Johansen <john.johansen@canonical.com>
2020-04-14 07:24:02 +00:00
John Johansen
2ebf742d31 Merge drop unused cmd_pipe() from easyprof.py
PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/477
Aked-by: John Johansen <john.johansen@canonical.com>
2020-04-14 07:20:58 +00:00
John Johansen
ef0c9160ce Merge branch ProfileStorage __setitem__(): restrict overwriting most keys
Only bool and str keys may be overwritten.

Other key types (list, dict, \*Ruleset) can have their content modified (not **setitem**()s job), but replacing the whole collection should never happen.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/476
Acked-by: John Johansen <john.johansen@canonical.com>
2020-04-14 07:19:07 +00:00
Christian Boltz
ddd9bd57e4 ProfileStorage __setitem__(): restrict overwriting most keys
Only bool and str keys may be overwritten.

Other key types (list, dict, *Ruleset) can have their content modified
(not __setitem__()s job), but replacing the whole collection should
never happen.
2020-04-13 19:55:54 +02:00
Christian Boltz
c9c4f4ce9c test that '\*' from audit.log gets correctly escaped
convert_expression_to_aare() is expected to convert it to AARE '\\\*'
2020-04-13 19:46:05 +02:00
Christian Boltz
ef0d675824 Get rid of is_covered_aare_compat()
This function was introduced as a temporary (ahem...) solution in
95404bb2f3 but was never really correct.
It checked against other_value.regex (as a string!) and, while this was
somewhat generous in the results, could have unintended side effects.

Better error out on the safe side and add/keep a few superfluous rules
than having a wrong match in is_covered() and miss to add/keep a rule
that would be needed.

The perfect solution would be to really compare one AARE against the
other as the parser does. I'm not too keen to implement this in python,
and will wait until someone provides this function (which the parser
already has) via libapparmor ;-)
2020-04-13 15:13:12 +02:00
Christian Boltz
30fa90a4ce drop unused cmd_pipe() from easyprof.py 2020-04-13 14:08:54 +02:00
Christian Boltz
acafe9de82 Merge branch 'profile-usr.sbin.dnsmasq' into 'master'
usr.sbin.dnsmasq: update to support dnsmasq 2.81

See merge request apparmor/apparmor!475

Acked-by: Christian Boltz for 2.11..master
2020-04-12 09:45:12 +00:00
nl6720
88c142c687 usr.sbin.dnsmasq: allow reading @{PROC}/@{pid}/fd/ as is needed by dnsmasq 2.81
See http://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=commitdiff;h=48755ebf093543113de96747a7f5f78e0640b333 .

Signed-off-by: nl6720 <nl6720@gmail.com>
2020-04-12 12:15:05 +03:00
John Johansen
a27ae2eb27 Merge Better error handling when creating apparmor.vim
See the individual commits for details and bug references.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/472
Acked-by: John Johansen <john.johansen@canonical.com>
2020-04-08 08:34:41 +00:00
Christian Boltz
0f891ba30e Delete (possibly broken) apparmor.vim on failure
If create-apparmor.vim.py fails, an empty apparmor.vim gets created. The
next "make" run will assume that apparmor.vim was already created (the
file exists and has a new-enough timestamp) and will therefore skip the
create-apparmor.vim.py run, keeping the broken apparmor.vim forever.

Adjust the Makefile to delete apparmor.vim if the script fails. This
ensures that make tries again in the next run.
2020-04-05 14:31:33 +02:00
Christian Boltz
9e7c4f88f9 create-apparmor.vim.py: split stdout and stderr
This will prevent that stderr output ends up in apparmor.vim

References:
- https://gitlab.com/apparmor/apparmor/issues/75
- https://bugs.archlinux.org/task/65450
- https://bugs.launchpad.net/apparmor/+bug/1187437
2020-04-05 14:26:15 +02:00
Rich McAllister
eeac8c11c9 abstractions: add /etc/mdns.allow to /etc/apparmor.d/abstractions/mdns
In focal users of mdns get denials in apparmor confined applications.
An exampel can be found in the original bug below.

It seems it is a common pattern, see
https://github.com/lathiat/nss-mdns#etcmdnsallow

Therefore I'm asking to add
   /etc/mdns.allow r,
to the file
   /etc/apparmor.d/abstractions/mdns"
by default.

--- original bug ---

Many repetitions of

audit: type=1400 audit(1585517168.705:63): apparmor="DENIED" operation="open" profile="/usr/sbin/chronyd" name="/etc/mdns.allow" pid=1983815 comm="chronyd" requested_mask="r" denied_mask="r" fsuid=123 ouid=0

in log. I use libnss-mdns for .local name resolution, so /etc/nsswitch.conf contains

hosts: files mdns [NOTFOUND=return] myhostname dns

and /etc/mnds.allow contains the domains to resolve with mDNS (in may case, "local." and "local"; see /usr/share/doc/libnss-mdns/README.html.)

Presumably cronyd calls a gethostbyX() somewhere, thus eventually trickling down through the name service switch and opening /etc/mdns.allow, which the AppArmor profile in the chrony package does not allow.

Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1869629
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-03-31 21:03:52 -07:00
John Johansen
b2d0d87eba Merge exo-open: allow reading ~/.local/share/xfce4/helpers/*.desktop
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/73
PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/467
Acked-by: John Johansen <john.johansen@canonical.com>
2020-03-31 23:05:51 +00:00
Christian Boltz
2a67d5e1ee exo-open: allow reading ~/.local/share/xfce4/helpers/*.desktop
Fixes https://gitlab.com/apparmor/apparmor/-/issues/73
2020-04-01 00:46:55 +02:00
Christian Boltz
f56bab3f75 Merge branch 'mesa-20.0' into 'master'
abstractions/mesa: allow checking if the kernel supports the i915 perf interface

See merge request apparmor/apparmor!464

Acked-by: Vincas Dargis <vindrg@gmail.com>
Acked-by: Christian Boltz <apparmor@cboltz.de> for master and 2.13
2020-03-31 19:49:26 +00:00
intrigeri
61571da1a8 abstractions/mesa: allow checking if the kernel supports the i915 perf interface
On current Debian sid, applications that use mesa need this access.
2020-03-31 09:15:14 +00:00
John Johansen
d4296d217c Merge: abstractions/nameservice: allow accessing /run/systemd/userdb/
On systems with systemd 245, `nss-systemd` additionally queries NSS records from `systemd-userdbd.service`. See https://systemd.io/USER_GROUP_API/ .

This does not bring full support for `systemd-homed`, but I don't use that service so I can't help with that.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/82
PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/459
Acked-by: John Johansen <john.johansen@canonical.com>
2020-03-29 08:51:55 +00:00
nl6720
16f9f6885a abstractions/nameservice: allow accessing /run/systemd/userdb/
On systems with systemd 245, nss-systemd additionally queries NSS records from systemd-userdbd.service. See https://systemd.io/USER_GROUP_API/ .

Signed-off-by: nl6720 <nl6720@gmail.com>
2020-03-29 11:08:38 +03:00
John Johansen
eafd3805a3 Merge fix capabilities in apparmor.vim
https://gitlab.com/apparmor/apparmor/-/merge_requests/461 / e92da079ca changed creating the capabilities to use a script.

A side effect is that the list is now separated by \\n instead of spaces. Adjust create-apparmor.vim.py to the new output.
PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/463
Acked-by: John Johansen <john.johansen@canonical.com>
2020-03-29 04:05:40 +00:00
Christian Boltz
60b005788e fix capabilities in apparmor.vim
https://gitlab.com/apparmor/apparmor/-/merge_requests/461 /
e92da079ca changed creating the
capabilities to use a script.

A side effect is that the list is now separated by \n instead of
spaces. Adjust create-apparmor.vim.py to the new output.
2020-03-29 00:07:11 +01:00
Vladimir “Equidamoid” Shapranov @equidamoid
e731b8a335 policy: invalid path to libvirt_leaseshelper in usr.sbin.dnsmasq
Another instance of using libvirt_leaseshelper without having
libexec access. As addressed in the previous patch.

issue: https://gitlab.com/apparmor/apparmor/-/issues/87
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-03-28 14:00:58 -07:00
Vladimir “Equidamoid” Shapranov @equidamoid
28fce5f76d Invalid path to libvirt_leaseshelper in usr.sbin.dnsmasq
The error:

type=AVC msg=audit(1585403559.846:34317577): apparmor="DENIED" operation="exec" profile="/usr/sbin/dnsmasq" name="/usr/libexec/libvirt_leaseshelper" pid=7162 comm="sh" requested_mas
k="x" denied_mask="x" fsuid=0 ouid=0
type=AVC msg=audit(1585403559.846:34317578): apparmor="DENIED" operation="open" profile="/usr/sbin/dnsmasq" name="/usr/libexec/libvirt_leaseshelper" pid=7162 comm="sh" requested_mas
k="r" denied_mask="r" fsuid=0 ouid=0

Looks like the path to libvirt_leasehelper is incorrect usr.sbin.dnsmasq, at least in gentoo. Patching the file fixes the problem:

issue: https://gitlab.com/apparmor/apparmor/-/issues/87
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-03-28 12:42:13 -07:00
John Johansen
ce2833a3cc Merge: Fixings for crosscompilation
This patch fixes a couple of nitpicks that I encountered packaging apparmor for buildroot:

1. In a cross-compiling environment, python executable cannot be trusted for getting the python settings because it is generally compiled for the host. For this reason, we should rely on target python-config.
1. Setup.py for libapparmor swig bindings is always called without taking into account the discovered settings from ac_python_devel.m4

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/462
2020-03-26 09:53:15 +00:00
Angelo Compagnucci
88c81d7b73 libapparmor: fixing setup.py call when crosscompiling
When crosscompiling, setupy.py should be called passing the settings
discovered by ac_python_devel.m4 and not using the default system
settings.

Signed-off-by: Angelo Compagnucci <angelo@amarulasolutions.com>
2020-03-25 22:22:14 +01:00
Angelo Compagnucci
64e5c6b23d m4: ac_python_devel: fixing for crosscompiling environments
In a crosscompiling environment it's common to have a python executable
running for the host system with a python-config reporting the host
configuration and a second python-config reporting the target configuration.
In such cases, relying on the default oython-config is wrong and breaks
the cross compilation.

This patch adds a PYTHON_CONFIG variable that can be pointed to the second
python-config and fixes the rest of the m4 accordingly.

Signed-off-by: Angelo Compagnucci <angelo@amarulasolutions.com>
2020-03-25 22:22:14 +01:00
John Johansen
d736fdb49e Generate CAPABILITIES in a script due to make 4.3
This way we could generate the capabilities in a way that works with every version of make. Changes to list_capabilities are intended to exactly replicate the old behavior.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/461
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-03-24 21:52:04 +00:00
Christian Boltz
5c1932d0d6 Merge branch 'master' into 'master'
Update usr.sbin.winbindd profile to allow krb5 rcache files locking

See merge request apparmor/apparmor!460

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.11..master
2020-03-23 20:14:27 +00:00
allgdante
e92da079ca Generate CAPABILITIES in a script due to make 4.3
This way we could generate the capabilities in a way that works with
every version of make.
Changes to list_capabilities are intended to exactly replicate the old
behavior.
2020-03-23 15:09:15 +00:00
Samuel Cabrero
2c3001c7a1 Update usr.sbin.winbindd profile to allow krb5 rcache files locking
Samba 4.12.0 together with krb5 1.18 needs file locking permissions in
the krb5 rache directory:

type=AVC msg=audit(1584708328.422:76): apparmor="DENIED" operation="file_lock"
  profile="winbindd" name="/var/cache/krb5rcache/krb5_20500.rcache2"
  pid=1461 comm="winbindd" requested_mask="k" denied_mask="k"
  fsuid=20500 ouid=20500

Signed-off-by: Samuel Cabrero <scabrero@suse.de>
2020-03-20 13:57:18 +01:00
John Johansen
02cfbc8b96 Sync library version with 2.13.4 release
The library version must be consistent across releases. Since 2.13.4
and master use the same library version it needs to be updated.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-03-12 04:20:29 -07:00
Steve Beattie
7c5572964d Translations: merge updates from launchpad
Omnibus collection of translations updates through 2020/03/05

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-03-07 16:29:42 -08:00
Launchpad Translations on behalf of apparmor-dev
f6c4461a2c Launchpad automatic translations update. 2020-03-07 16:10:25 -08:00
Launchpad Translations on behalf of apparmor-dev
58769a4765 Launchpad automatic translations update. 2020-03-07 16:10:18 -08:00
Steve Beattie
1af84c42f7 Translations: merge updates from launchpad
Omnibus collection of translations updates through 2020/02/22

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-24 10:01:32 -08:00
Launchpad Translations on behalf of apparmor-dev
ba232c0e9c Launchpad automatic translations update. 2020-02-24 09:59:44 -08:00
Launchpad Translations on behalf of apparmor-dev
33b48e727f Launchpad automatic translations update. 2020-02-24 09:59:43 -08:00
Launchpad Translations on behalf of apparmor-dev
300e3488ee Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-24 09:59:37 -08:00
John Johansen
9bccf457d1 Merge usr.sbin.dnsmasq: add configuration files created by openresolv
See https://roy.marples.name/projects/openresolv/configuration.html#dnsmasq .

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/457
Acked-by: John Johansen <john.johansen@canonical.com>
2020-02-20 16:55:15 +00:00
Christian Boltz
d9275d6f1d Merge branch 'run-fix' into 'master'
Add trailing slash to the run variable definition

See merge request apparmor/apparmor!456

Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-02-20 11:14:55 +00:00
nl6720
8b92f50e2c usr.sbin.dnsmasq: add configuration files created by openresolv
See https://roy.marples.name/projects/openresolv/configuration.html#dnsmasq .

Signed-off-by: nl6720 <nl6720@gmail.com>
2020-02-20 11:42:16 +02:00
nl6720
ef591a67ce Add trailing slash to the run variable definition
Signed-off-by: nl6720 <nl6720@gmail.com>
2020-02-20 10:43:21 +02:00
John Johansen
2cb932441c Merge usr.sbin.smbd: add usershare directory
See https://wiki.archlinux.org/index.php/Samba#Enable_Usershares .

AFAIK the `/var/lib/samba/usershares` directory is also used by Ubuntu.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/455
Acked-by: John Johansen <john.johansen@canonical.com>
2020-02-20 08:18:37 +00:00
John Johansen
6b6146d7cc Merge Add "run" variable
Split off from !212 . Add and use `@{run}`.

Also update a couple of profiles that don't use `@{PROC}`

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/454
Acked-by: John Johansen <john.johansen@canonical.com>
2020-02-20 08:15:58 +00:00
Steve Beattie
edb72fc4f7 Translations: merge updates from launchpad
Omnibus collection of translations updates.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:52:29 -08:00
Launchpad Translations on behalf of apparmor-dev
d87ce2e586 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:19 -08:00
Launchpad Translations on behalf of apparmor-dev
ad524d7a85 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:18 -08:00
Launchpad Translations on behalf of apparmor-dev
77dbb4e1a7 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:18 -08:00
Launchpad Translations on behalf of apparmor-dev
938d908462 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:17 -08:00
Launchpad Translations on behalf of apparmor-dev
4d758cc2ab Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:17 -08:00
Launchpad Translations on behalf of apparmor-dev
2aa6f56e4a Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:17 -08:00
Launchpad Translations on behalf of apparmor-dev
78a66a6676 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:16 -08:00
Launchpad Translations on behalf of apparmor-dev
fbf91cfde3 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:16 -08:00
Launchpad Translations on behalf of apparmor-dev
d0708bc782 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:15 -08:00
Launchpad Translations on behalf of apparmor-dev
7ecc948748 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:15 -08:00
Launchpad Translations on behalf of apparmor-dev
27fa9a2eaa Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:14 -08:00
Launchpad Translations on behalf of apparmor-dev
0adbd59dbf Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:14 -08:00
Launchpad Translations on behalf of apparmor-dev
47bae2b6e1 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:13 -08:00
Launchpad Translations on behalf of apparmor-dev
8b09271128 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:13 -08:00
Launchpad Translations on behalf of apparmor-dev
010e4fa5fe Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:12 -08:00
Launchpad Translations on behalf of apparmor-dev
9eb195d565 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:12 -08:00
Launchpad Translations on behalf of apparmor-dev
dc7c20ce6d Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:12 -08:00
Launchpad Translations on behalf of apparmor-dev
2b297c4606 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2020-02-17 19:21:07 -08:00
nl6720
c13cee8bbc usr.sbin.smbd: add usershare directory
Signed-off-by: nl6720 <nl6720@gmail.com>
2020-02-13 14:12:24 +02:00
nl6720
c9252827f4 Use "PROC" variable in profiles
Signed-off-by: nl6720 <nl6720@gmail.com>
2020-02-13 11:07:42 +02:00
nl6720
7a9a4824d4 Use "run" variable in profiles
Signed-off-by: nl6720 <nl6720@gmail.com>
2020-02-13 11:02:49 +02:00
nl6720
452b5b8735 Add "run" variable
Signed-off-by: nl6720 <nl6720@gmail.com>
2020-02-13 13:45:45 +02:00
Christian Boltz
ee8dcde452 let logprof only propose abstractions without '# LOGPROF-SUGGEST: no'
This implements one part of
https://gitlab.com/apparmor/apparmor/issues/15
2020-02-11 21:33:49 +01:00
Christian Boltz
962f1e7a7b Merge branch 'cboltz-exoopen-local' into 'master'
Add #include if exists <*.d> to new abstractions

See merge request apparmor/apparmor!453

Acked-by: Seth Arnold <seth.arnold@canonical.com>
2020-02-11 20:31:41 +00:00
Christian Boltz
aa8fa18552 Add #include if exists <*.d> to new abstractions
This was missing, and catched by a previously enabled test.
2020-02-08 17:14:38 +01:00
Christian Boltz
fbe8641026 Merge branch 'cboltz-nameservice-usretc' into 'master'
adjust abstractions/base and nameservice for /usr/etc/ move

See merge request apparmor/apparmor!447

Acked-by: John Johansen <john.johansen@canonical.com> for 2.12..master
2020-02-03 21:34:38 +00:00
John Johansen
d257afd309 Add xdg-open (and friends) abstraction
Implement set of abstractions to handle opening uris via xdg-open and similar helpers used on different desktop environments.

Abstractions are intended to be included into child profile, together with bundle abstractions such as ubuntu-browsers, ubuntu-email and others, for fine-grained control on what confined application can actually open via xdg-open and similar helpers.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/404
Acked-by: John Johansen <john.johansen@canonical.com>
2020-02-03 21:32:21 +00:00
Christian Boltz
65bb277d8b Merge branch 'cboltz-ci-check-includes' into 'master'
run "make -C profiles check-abstractions.d" in ci

See merge request apparmor/apparmor!449

Acked-by: John Johansen <john.johansen@canonical.com>
2020-02-03 21:30:22 +00:00
John Johansen
ffca515269 libapparmor_re: fix resource leaks detected by coverity.com
Fixes two resource leaks. https://scan.coverity.com/projects/apparmor

I don't actually know how to link to the individual reports but the first one comes from an early return. The second comes from an iterator potentially being empty.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/439
Acked-by: John Johansen <john.johansen@canonical.com>
2020-02-03 21:28:55 +00:00
Christian Boltz
f1fdf4db39 Merge branch 'cboltz-typo' into 'master'
Fix apparmor_xattrs typo in apparmor.d manpage

See merge request apparmor/apparmor!452

Acked-by: John Johansen <john.johansen@canonical.com>
2020-02-03 21:26:45 +00:00
Christian Boltz
cf15b241e7 adjust abstractions/base and nameservice for /usr/etc/ move
References: http://bugzilla.opensuse.org/show_bug.cgi?id=1161756
2020-02-03 22:23:15 +01:00
John Johansen
264777a409 Allow mysqld directory for MySQL PID file
Some distros, like Debian, use mysqld instead of mysql as the run directory.

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/450
Acked-by: John Johansen <john.johansen@canonical.com>
2020-02-03 21:18:44 +00:00
Christian Boltz
80bf920929 Merge branch 'run-uuidd-request' into 'master'
abstractions/base: allow read access to /run/uuidd/request

See merge request apparmor/apparmor!445

Acked-by: John Johansen <john.johansen@canonical.com> for 2.11..master
Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.11..master
2020-02-03 21:17:28 +00:00
Christian Boltz
3becbbab2c Merge branch 'gnome-abstraction-more-mimeapps' into 'master'
abstractions/gnome: also allow /etc/xdg/mimeapps.list

See merge request apparmor/apparmor!444

Acked-by: John Johansen <john.johansen@canonical.com> for 2.11..master
Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.11..master
2020-02-03 21:16:36 +00:00
Christian Boltz
24895ea302 Merge branch 'ecryptfs-top-dir' into 'master'
abstractions/base: allow read access to top-level ecryptfs directories

See merge request apparmor/apparmor!443

Acked-by: John Johansen <john.johansen@canonical.com> for 2.11..master
Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.11..master
2020-02-03 21:15:38 +00:00
Christian Boltz
e5fdf8275e Fix apparmor_xattrs typo in apparmor.d manpage 2020-02-02 17:12:40 +01:00
Ian Johnson
f4220a19be docs: fix typo in man doc of unix rules
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2020-01-30 12:51:09 -08:00
Alexis Grey
387e487699 Allow mysqld directory for MySQL PID file
Some distros, like Debian, use mysqld instead of mysql as the run directory.
2020-01-28 22:10:50 +00:00
Christian Boltz
e10a1b5ad9 Make check-abstractions.d compatible with more shells 2020-01-27 23:44:59 +01:00
Christian Boltz
07a15d651a run "make -C profiles check-abstractions.d" in ci
... to make sure we notice missing
    #include if exists <$abstraction_name.d/>
2020-01-27 20:43:55 +01:00
Christian Boltz
eae474bb5c Merge branch 'cboltz-abstractions-missing-include' into 'master'
add missing *.d include to dbus-network-manager-strict abstraction

See merge request apparmor/apparmor!448

Acked-by: Seth Arnold <seth.arnold@canonical.com>
2020-01-27 19:42:45 +00:00
Christian Boltz
50535283e8 add missing *.d include to dbus-network-manager-strict abstraction 2020-01-25 19:54:09 +01:00
Eric Chiang
4116f847df libapparmor_re: fix resource leaks detected by coverity.com
Fixes two resource leaks. https://scan.coverity.com/projects/apparmor

I don't actually know how to link to the individual reports but the
first one comes from an early return. The second comes from an iterator
potentially being empty.
2020-01-02 18:09:40 -08:00
Jamie Strandboge
45fffc129f abstractions/base: allow read access to /run/uuidd/request
/run/uuidd/request is hardcoded in libuuid from util-linux and uuidd
listens on this socket to provide random and time-based UUIDs in a
secure manner (man 8 uuidd). Some applications (eg, python's uuid)
prefer to use this socket, falling back to getrandom(), /dev/urandom,
etc. Eg:

$ strace -f aa-exec -p test -- \
  python3 -c 'import uuid ; print("%s\n" % str(uuid.uuid1()))'
...
socket(AF_INET, SOCK_DGRAM, IPPROTO_IP) = -1 EACCES (Permission denied)
getrandom("\x8e\x89\xa5\xe7\x39\x1b", 6, GRND_NONBLOCK) = 6
...

uuidd itself produces random numbers using getrandom() and
/dev/{,u}random (falling back to time-based if not), which are already
allowed in the base abstraction. The uuidd daemon, when available, runs
unprivileged under a dedicated user, so allowing read-only access to
/run/uuidd/request is reasonable.
2019-12-17 15:56:23 -06:00
Jamie Strandboge
67cf4fa340 abstractions/gnome: also allow /etc/xdg/mimeapps.list
References:
- https://launchpad.net/bugs/1792027
2019-12-17 15:52:47 -06:00
Jamie Strandboge
fbd8981e92 abstractions/base: allow read access to top-level ecryptfs directories
References:
- https://launchpad.net/bugs/1848919
2019-12-17 15:44:44 -06:00
John Johansen
098f0a7b5f gnome abstraction: allow reading per-user themes from $XDG_DATA_HOME
Bug-Debian: https://bugs.debian.org/930031

As per https://developer.gnome.org/gtk3/stable/ch32s03.html, since GTK+ 3.6, $XDG_DATA_HOME/themes is preferred over $HOME/.themes. We already support the latter, let's also support the former.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/442
Acked-by: John Johansen <john.johansen@canonical.com>
2019-12-11 07:43:55 +00:00
intrigeri
852c1e766d gnome abstraction: allow reading per-user themes from $XDG_DATA_HOME
Bug-Debian: https://bugs.debian.org/930031

As per https://developer.gnome.org/gtk3/stable/ch32s03.html,
since GTK+ 3.6, $XDG_DATA_HOME/themes is preferred over $HOME/.themes.
We already support the latter, let's also support the former.
2019-12-11 06:31:37 +00:00
Vincas Dargis
162e5086a5 xdg-open: update usage example
Add notes about optional abstractions that can be useful for making
(rare) message boxes created by *-open helpers work correctly.
2019-12-08 15:59:58 +02:00
Vincas Dargis
8b481d469b kde-open5: do not enable gstreamer support by default
Make kde-open5 abstraction more conservative by removing gstreamer
support by default. Update usage example to suggest conditionally including
gstreamer abstraction if required.
2019-12-08 15:53:36 +02:00
Vincas Dargis
d35faafdd2 kde-open5: do not enable a11y by default
Update kde-open5 abstraction to not include accessibility abstraction by
default.

Update documentation to suggest adding it manually in child profile when
using kde-open5 if accessibility access is required by profile author.
2019-12-08 15:25:52 +02:00
Vincas Dargis
e77abfa56a exo-open: update comment about DBUS denial
Make comment more clear about denied DBUS access, no need to raise
questions. Remove redundant comment.
2019-12-08 15:13:33 +02:00
Vincas Dargis
0a55babe9a exo-open: do not enable a11y by default
Update exo-open abstraction to not include accessibility abstraction by
default.

Update documentation to suggest adding it manually in child profile when
using exo-open if accessibility access is required by profile author.
2019-12-08 15:07:57 +02:00
Vincas Dargis
501aada843 gio-open: fix denies Ubuntu Eoan
gio-open abstraction is outdated for latest Ubuntu with Gnome.

Add rule to remove denial for reading snapd-related files.
2019-12-08 13:40:22 +02:00
Vincas Dargis
ac08dc66ec kde-open5: fix denies Ubuntu Eoan
kde-open5 abstraction is outdated for latest Ubuntu with KDE.

Add rules to make kde-open5 work again.
2019-12-08 13:17:38 +02:00
Vincas Dargis
80514906f0 kde-open5: use dbus-network-manager-strict abstraction
Remove inline dbus rules and include new dbus-network-manager-strict
abstraction instead.
2019-12-08 12:40:35 +02:00
Vincas Dargis
f07f077174 exo-open: Allow playing alert sounds
In case of error (for example failing to open provided uri) message box
is show, and alert sound is played. Currently `exo-open` abstraction
does not allow access to audio subsystems in result producing denials in
system logs.

Update abstraction to include `abstractions/audio`.
2019-12-08 12:22:52 +02:00
Vincas Dargis
af278ca691 exo-open: Fix denials on OpenSUSE
exo-open fails on OpenSUSE due to different/missing paths.

Update abstraction to fix denials on OpenSUSE.
2019-12-08 12:22:52 +02:00
Vincas Dargis
622fc44bd0 Add xdg-open (and friends) abstraction
Implement set of abstractions to handle opening uris via xdg-open and similar
helpers used on different desktop environments.

Abstractions are intended to be included into child profile, together
with bundle abstractions such as ubuntu-browsers, ubuntu-email and others, for
fine-grained control on what confined application can actually open via xdg-open
and similar helpers.
2019-12-08 12:22:52 +02:00
John Johansen
f421fbd92c CI: cat config.log if libapparmor configure fails
This helped a lot to debug the CI failure caused by 3db14e8e / !430 (merged), and won't add any noise as long as configure succeeds.

Note that this MR is based on master without !433 (merged) which means it will fail in CI (and display config.log). After !433 (merged) got merged, I'll rebase it to show that it won't add additional noise as long as everything works.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/434
Acked-by: John Johansen <john.johansen@canonical.com>
2019-11-27 20:45:44 +00:00
Christian Boltz
b3020dfaf5 CI: cat config.log if libapparmor configure fails
This helped a lot to debug the CI failure caused by
3db14e8e49 / !430, and won't add any noise
as long as configure succeeds.
2019-11-27 21:09:32 +01:00
Christian Boltz
1cfd4d4bbc Merge branch 'cboltz-usr-etc' into 'master'
Allow /usr/etc/ in abstractions/authentication

openSUSE (and hopefully some other distributions) work on moving shipped
config files from /etc/ to /usr/etc/ so that /etc/ only contains files
written by the admin of each system.

See https://en.opensuse.org/openSUSE:Packaging_UsrEtc for details and
the first moved files.

Updating abstractions/authentication is the first step, and also fixes
bugzilla.opensuse.org/show_bug.cgi?id=1153162

See merge request apparmor/apparmor!426

Acked-by: John Johansen <john.johansen@canonical.com> for 2.12..master
2019-11-27 19:40:47 +00:00
Christian Boltz
e90f01cd9d Merge branch 'cboltz-gitlab-ci-zlib' into 'master'
add zlib1g-dev to .gitlab-ci.yml

See merge request apparmor/apparmor!433

Acked-by: John Johansen <john.johansen@canonical.com>
2019-11-27 19:30:41 +00:00
John Johansen
a10fa57fb6 Add dbus-network-manager-strict abstraction
Some applications queries network configuration (using QNetworkConfigurationManager class in Qt and similar), and that produces DBus denials under AppArmor confinement when NetworkManager backend is used.

Add abstraction that allows most common read-only DBus queries for getting current network configuration from NetworkManager backend.


PR: https://gitlab.com/apparmor/apparmor/merge_requests/409
Acked-by: John Johansen <john.johansen@canonical.com>
2019-11-27 18:01:42 +00:00
John Johansen
48fdd0ef76 Remove a selection of obsolete support
Requires NPAPI which no major browsers support anymore: Mozplugger npviewer / nspluginwrapper

The following have been discontinued Google Talk (and plugin) f-spot conkeror galeon Mozilla Prism rekonq Adobe Reader for Linux

Other gnome-codec-install is not in Ubuntu anymore gstreamer0.10 was replaced by 1.0

PR: https://gitlab.com/apparmor/apparmor/merge_requests/417
Acked-by: John Johansen <john.johansen@canonical.com>
2019-11-27 06:14:05 +00:00
John Johansen
6757434350 libapparmor: force -fPIC on .a library generation
currently the .a version of the library is not being generated with
PIC code. This is a problem when you try to link it to PIE binaries.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/422
BugLink: http://bugs.launchpad.net/bugs/1824384
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Time Out
2019-11-26 21:40:45 -08:00
John Johansen
fb3fbd8da5 Out of band transitions
Add support for out of band transitions that be to separate elements that can contain any input character. Out of band transitions can only be triggered by explicit transitions in the code (instruction stream). They function the same as the null transition except they work for all input and when writing expressions there is no need to not match them.

The out of band transitions show up in the dfa as negative offsets from the base. Currently only a single out of band transition of -1 is supported, but it is fairly trivial to add new ones if needed. The negative offset for out of band transitions were chosen instead of positive offsets that are out of input range to leave open the option of extending the input range in the future.

kernel patches: apparmor-kernel!6

v2.

    fix spacing error identified by cboltz
    update commit messages and signed-off-bys
    allow globbing in xattrs to match NULL character
    free leaked xattr cond_entry_list
    make xattr generation conditional on kernel support

v3.

    fix crash in commit: parser: make sure xattr cond_entry_list is not leaked
    port eric's patch from !362 "support matching xattr keys but not values" to work with out of band transitions, and not a separate value array

v4.

    double free fix crash of xattr.name in parser: make sure xattr cond_entry_list is not leaked
    remove xattr/bad_XX tests that are no longer bad because attr names do not have to have a value specified

v5

    fix bug in append_rule where the out of band transition was being converted to character 255

v6

    fix bug in writing of dfa header flags value

v7

    fix bug in out of band transitions where they could in certain cases be matched by an expression and hence not function as a separator.
    fix xattr encoding so xattr presence can be determined distinctly from xattr value
    fix xattr encoding so xattrs are not treated as optional
    fix xattr encoding so that permissions are properly encoded at the end of each segment match
    update xattr regression tests to make failures unique and reflect that nul character values are now allowed

v8

    update transchar comment

v9

    update tranchar comment

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Time Out
2019-11-26 21:35:02 -08:00
John Johansen
3e3c8744f6 regression tests: update xattr_profile.sh to reflect recent improvements
Update the xattr_profile.sh tests so that
- each test can be uniquely identified
- the embedded nul tests are updated to the now supported/passing state

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
444b8e3836 parser: change xattr encoding and allow append_rule to embedd permissions
The current encoding makes every xattr optional and uses this to
propogate the permission from the tail to the individual rule match
points.

This however is wrong. Instead change the encoding so that an xattr
(unless optional) is required to be matched before allowing moving
onto the next xattr match.

The permission is carried on the end on each rule portion file match,
xattr 1, xattr 2, ...

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
e13af5dc96 parser: fix xattr match encoding so optional xattr is distinct
Make sure we can support optional xattrs distinct from optional xattr
values in the encoding.

Currently all xattrs specified are required to be present even
if there value is not specified. However under the old encoding there
was no way to distinguish if the presence of the xattr vs. the
xattr having a null length value.

Fix this so that if we decide to support optional xattrs it is possible
without having to change the abi.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
2416faac54 parser: support matching xattr keys but not values
Support profiles that choose to match the presence of an extended
attribute without validating its value. This lets AppArmor target xattrs
with binary data, such as security.ima and security.evm values. For
example, it's now possible to write a profile such as:

        profile signed_binaries /** xattrs=(security.ima) {
                # ...
        }

Both presence and value matches can be used in the same profile. To
match a signed xattr, target both the xattr and the security.ima value:

        profile python_script /** xattrs=(
                security.evm
                security.apparmor="python"
        ) {
                # ...
        }

Updated to work using out of band matching instead of separate data
array.

Signed-off-by: Eric Chiang <ericchiang@google.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
e5ea3e4a0d parser: Make xattr attachment generation conditional on kernel support
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
9b0a98d00e parser: make sure xattr cond_entry_list is not leaked
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
6b47b8de25 parser: Allow xattr globbing to match the NULL character
xattrs are a byte string that can contain all input characters including
the null character. Allow * ** and ? glob patterns to match the null
character while retaining their apparmor characteristics for '/'.

That is * and ? won't traverse a '/' treating it as a path element.
While ** will match anything.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
2992e6973f parser: convert xmatch to use out of band transitions
xattrs can contain NULL characters in their values which means we can
not user regular NULL transitions to separate values. To fix this
use out of band transition instead.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
53dffc5304 parser/libapparmor_re: add basic documentation about components
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
16b67ddbd6 add ability to use out of band transitions
Currently the NULL character is used as an out of band transition
for string/path elements. This works for them as the NULL character
is not valid for this data. However this does not work for binary
data that can contain a NULL character.

So far we have only dealt with fixed length fields of binary data
making the NULL separator either unnecessary.

However binary data like in the xattr match and mount data field are
variable length and can contain NULL characters. To deal with this
add the ability to specify out of band transitions, that can only
be triggered by code not input data.

The out of band transition can be used to separate variable length
data fields just as the NULL transition has been used to separate
variable length strings.

In the compressed hfa out of band transitions are expressed as a
negative offset from the states base. This leaves us room to expand
the character match range in the future if desired and on average
makes the range between the out of band transition and the input
transitions smaller than would be had if the out of band transition
had been stored after the valid input transitions.

Out of band transitions in the dfa will not break old kernels
that don't know about them, but they won't be able to trigger
the out of band transition match. So they should not be used unless
the kernel indicates that it supports them.

It should be noted that this patch only adds support for a single
out of band transition. If multiple out of band transitions are
required. It is trivial to extend.
- Add a tag indicating support in the kernel
- add a oob max range field to the dfa header so the kernel knows
  what the max range that needs verifying is.
- extend oob generation fns to generate oob based on value instead
  of a fixed -1.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
6062262ccd parser: fix writing dfa flags
Currently the parser is not correctly setting the dfa flag value
and it hasn't been caught because base policy uses a flag value
of 0.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
7c29bfebe3 parser: improve debug output of transhar
Make transchar stream output work with a broader range of values.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
72f93d9aba parser: rename uchar to transchar
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
daa10d3ce1 parser: rework backend to allow for more transitions
As a step in preparing for out of band transitions and double walk
transitions rework the backend from using a char index to a class
with an larger range than char.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
e958da7678 Nnp unconfined exception tests
Add nnp tests around the unconfined exception.

An unconfined task is allowed changing to a profile under nnp restrictions. However this has implications when the task has stacked confinement.

  profile//&unconfined

  profile//&:ns:unconfined

  ...

will not be caught by the unconfined test. Instead the unconfined exception needs to be tested as part of the subset test. Add tests to ensure we can catch regressions around a stacked unconfined profile.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/424
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-27 05:29:13 +00:00
Christian Boltz
6c85836be5 add zlib1g-dev to .gitlab-ci.yml
This fixes the CI failures introduced with
3db14e8e49 - either conf('BLDLIBRARY') or
$PYTHON_EXTRA_LIBS introduce a dependency on zlib-dev ("-lz").
2019-11-19 22:52:22 +01:00
Christian Boltz
663546c284 Merge branch 'cboltz-abstractions-kerberos' into 'master'
abstractions/kerberosclient: allow reading /etc/krb5.conf.d/

See merge request apparmor/apparmor!425

Acked-by: Steve Beattie <steve@nxnw.org> for 2.10..master
Acked-by: John Johansen <john.johansen@canonical.com> for 2.10..master
2019-11-18 21:35:29 +00:00
Christian Boltz
b017f8f8a9 Merge branch 'cboltz-drop-localinclude' into 'master'
Drop 'localinclude' in parse_profile_data() and ProfileStorage

See merge request apparmor/apparmor!427

Acked-by: John Johansen <john.johansen@canonical.com> for 2.12..master
Acked-by: Steve Beattie <steve@nxnw.org> for 2.12..master
2019-11-18 21:32:24 +00:00
Christian Boltz
3db14e8e49 Merge branch 'fix-autoconf-check-for-python-3.8' into 'master'
Fix a Python 3.8 autoconf check

See merge request apparmor/apparmor!430

Acked-by: Christian Boltz <apparmor@cboltz.de> for master and 2.13
Acked-by: Steve Beattie <steve@nxnw.org> for master and 2.13
2019-11-18 20:16:33 +00:00
John Johansen
095efb821f docs: update apparmor.d language description
Update the language description to provide some over arching
principles, such as the policy is declarative.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2019-11-09 14:05:22 -08:00
John Johansen
d6384641c2 added missing functions to slackware init script
There where some functions missing in the Slackware init script which has been added with this commit.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/432
Acked-by: John Johansen <john.johansen@canonical.com>
2019-11-09 11:00:01 +00:00
lmoeller
32105d0816 added missing functions to slackware init script 2019-11-08 13:49:48 +01:00
intrigeri
ccbf1e0bf1 Fix a Python 3.8 autoconf check
Bug-Debian: https://bugs.debian.org/943657

Author: Matthias Klose <doko@debian.org>
2019-10-29 17:53:11 +00:00
Christian Boltz
1567ea6f4c Merge branch 'cboltz-pyflakes-version' into 'master'
README: add PYFLAKES=/usr/bin/pyflakes3 env variable

See merge request apparmor/apparmor!429

Acked-by: John Johansen <john.johansen@canonical.com> for 2.11..master
2019-10-24 21:08:28 +00:00
Christian Boltz
556bb94aa5 README: add PYFLAKES=/usr/bin/pyflakes3 env variable
pyflakes 2.x nowadays complains about
    aa-genprof:60: undefined name 'PermissionError'

We already deprecated py2 support in 2.11 (and obviously nobody tests
with py2 anymore), therefore recommending pyflakes3 makes sense.

Maybe we should also change our Makefiles to use py3 and pyflakes3 by
default, but that will be another (master-only) commit.
2019-10-24 15:36:22 +02:00
Christian Boltz
001ea9e3af Drop 'localinclude' in parse_profile_data() and ProfileStorage
'localinclude' is/was meant to have 'local/*' includes separate, but
it's write-only and never used, which makes it useless.

Additionally, it causes a crash in the aa-* tools which gets fixed by
removing all the 'localinclude'-related code (what a big word for two
lines ;-)

References: https://bugs.launchpad.net/apparmor/+bug/1848227
2019-10-16 21:30:43 +02:00
Christian Boltz
ee7194a714 Allow /usr/etc/ in abstractions/authentication
openSUSE (and hopefully some other distributions) work on moving shipped
config files from /etc/ to /usr/etc/ so that /etc/ only contains files
written by the admin of each system.

See https://en.opensuse.org/openSUSE:Packaging_UsrEtc for details and
the first moved files.

Updating abstractions/authentication is the first step, and also fixes
bugzilla.opensuse.org/show_bug.cgi?id=1153162
2019-10-07 21:47:25 +02:00
Christian Boltz
5066dc6195 Merge branch 'profile-usr.sbin.winbindd' into 'master'
Update usr.sbin.winbindd profile

Winbind requires access to `/var/cache/samba/msg.lock/*`.

On Arch Linux Winbind's pid is set to `/run/winbindd.pid` ( https://git.archlinux.org/svntogit/packages.git/tree/trunk/winbindd.service?h=packages/samba ).

See merge request apparmor/apparmor!411

Acked-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-10-03 17:53:21 +00:00
Christian Boltz
a2d43e7546 Merge branch 'avoid-blhc-false-positive' into 'master'
Avoid blhc "CPPFLAGS missing" false positive.

See merge request apparmor/apparmor!403

Acked-by: John Johansen <john.johansen@canonical.com>
2019-09-30 21:53:50 +00:00
John Johansen
cb5aeec433 regression tests: add unconfined exception tests to nnp.sh
The unconfined exception needs to be applied even when a stack is
being used. When a stack is in use it prevents the unconfined
test from being used and instead it must be done as part of the
subset test.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-09-29 19:58:02 -04:00
Christian Boltz
dffed83161 abstractions/kerberosclient: allow reading /etc/krb5.conf.d/
Permit the use of /etc/krb5.conf.d configuration snippets

Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>

Originally submitted as https://build.opensuse.org/request/show/733763
2019-09-28 17:25:39 +02:00
Christian Boltz
0b94cbe516 Merge branch 'cboltz-drop-deprecated' into 'master'
drop deprecated perl code

* drop repair_obsolete_profiles (updated profiles for abstraction renames pre-2006)
* drop ancient perl aa-* tools and their modules (rewritten to python in 2.9)
* drop rc.aaeventd.{redhat,suse} initscripts (aaeventd was dropped long ago, therefore we don't need to keep its initscripts)

See merge request apparmor/apparmor!423

Acked-by: John Johansen <john.johansen@canonical.com>
2019-09-25 20:32:20 +00:00
Christian Boltz
523f21fb20 drop rc.aaeventd.{redhat,suse} initscripts
aaeventd was dropped long ago, therefore we don't need to keep its
initscripts.
2019-09-23 21:46:16 +02:00
Christian Boltz
12488fcc9a drop ancient perl aa-* tools and their modules
They were rewritten to python in 2.9.
2019-09-23 21:43:58 +02:00
Christian Boltz
506f51e6fd drop repair_obsolete_profiles
(updated profiles for abstraction renames pre-2006)
2019-09-23 21:40:27 +02:00
Christian Boltz
98fde52998 Merge branch 'drop-perl' into 'master'
drop deprecated perl code
* aa-repo.pl
* convert-profile.pl

See merge request apparmor/apparmor!416

Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-09-23 19:35:58 +00:00
Christian Boltz
b76567ce10 Merge branch 'cboltz-status-parenthesis' into 'master'
aa-status: handle profile names containing '('

Closes #51

See merge request apparmor/apparmor!415

Acked-by: John Johansen <john.johansen@canonical.com> for 2.10..master
2019-09-23 18:55:22 +00:00
John Johansen
094f9727fa Merge branch 'dont-allow-fontconfig-cache-write' into 'master'
abstractions/fonts: don't allow write of fontconfig cache files

See merge request apparmor/apparmor!420
2019-09-20 09:42:53 +00:00
John Johansen
c9fcc18b9a Fix setfcap Cap mispelling
PR: https://gitlab.com/apparmor/apparmor/merge_requests/421
Acked-by: John Johansen <john.johansen@canonical.com>
2019-09-17 10:01:03 +00:00
Paulo Gomes
2d19d4d159 Fix capability mispelling. 2019-09-17 10:38:09 +01:00
John Johansen
59e799a9ba abstractions/X: allow reading the Xauth file mutter passes to Xwayland.
Applications running under Xwayland in a GNOME+Wayland session need read access to this file since:

a8984a81c2

… that was first included in mutter 3.33.3.

This rule is presumably only needed for GNOME+Wayland sessions, so one could argue that it should live in abstractions/wayland instead, but Jamie argued that it should be in the X abstraction because Xwayland is a X server.

MR: https://gitlab.com/apparmor/apparmor/merge_requests/419
Bug-Debian: https://bugs.debian.org/935058
Acked-by: John Johansen <john.johansen@canonical.com>
2019-09-16 15:08:40 +00:00
Jamie Strandboge
c5968c70d0 abstractions/fonts: don't allow write of fontconfig cache files
879531b36ec3dfc7f9b72475c68c30e4f4b7b6af changed access for
@{HOME}/.{,cache/}fontconfig/** to include 'w'rite. Fontconfig has been
a source of CVEs. Confined applications should absolutely have read
access, but write access could lead to breaking out of the sandbox if a
confined application can write a malformed font cache file since
unconfined applications could then pick them up and be controlled via
the malformed cache. The breakout is dependent on the fontconfig
vulnerability, but this is the sort of thing AppArmor is meant to help
guard against.
2019-09-09 15:52:40 -05:00
intrigeri
c006f79141 abstractions/X: allow reading the Xauth file mutter passes to Xwayland.
Bug-Debian: https://bugs.debian.org/935058

Applications running under Xwayland in a GNOME+Wayland session need read access
to this file since:

  a8984a81c2

… that was first included in mutter 3.33.3.

This rule is presumably only needed for GNOME+Wayland sessions, so one could
argue that it should live in abstractions/wayland instead, but Jamie argued that
it should be in the X abstraction because Xwayland is a X server.
2019-09-08 07:41:36 +00:00
intrigeri
33c5f61c75 Merge branch 'utab' into 'master'
profiles/gnome: Allow access of /run/mount/utab

See merge request apparmor/apparmor!412
2019-09-08 06:58:44 +00:00
intrigeri
9acb17adf0 Merge branch 'cboltz-whitespace' into 'master'
fix whitespace and indentation in several files

See merge request apparmor/apparmor!413
2019-09-08 06:48:27 +00:00
Bryan Quigley
0401235949 Remove a selection of obsolete support.
Requires NPAPI which no major browsers support anymore:
Mozplugger
npviewer / nspluginwrapper

The following have been discontinued
Google Talk (and plugin)
f-spot
conkeror
galeon
Mozilla Prism
rekonq
Adobe Reader for Linux

Other
gnome-codec-install is not in Ubuntu anymore
gstreamer0.10 was replaced by 1.0
2019-08-24 09:50:34 -07:00
John Johansen
a00ac89be8 drop deprecated perl code
With the effort to remove perl, it makes no sense to keep the depracted
perl code around for new releases.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-08-21 18:31:34 -07:00
Christian Boltz
41d26b0197 aa-status: handle profile names containing '('
aa-status crashed if a profile name contains an opening parenthesis
because the regex enforces (simplified) '^[^(]* \(.*\)' when reading
/sys/kernel/security/apparmor/profiles

This obviously doesn't match if a profile name contains '(' which is
rare and strange, but still allowed, and the match result "None" then
crashes aa-status.

Adjust the regex to allow all chars instead of all except '(' to handle
these corner cases.

Note that '(enforce)' and '(complain)' still get read correctly because
the regex ends with '\((\w+)\)$' and therefore enforces matching
"something inside parenthesis at the end of the line".

This bug exists since aa-status was rewritten into python, and even
existed in the perl version before. However, in the perl version, the
regex matching was protected with an if so profile names with '(' were
skipped and hidden from the aa-status output.

Fixes: https://gitlab.com/apparmor/apparmor/issues/51
2019-08-16 22:10:36 +02:00
Christian Boltz
e246568819 fix whitespace and indentation in several files 2019-08-12 23:58:04 +02:00
Jörg Sommer
cd3532f792 profiles/gnome: Allow access of /run/mount/utab
When a filesystem is mounted with the option *user*, the file selection
dialogue, e.g. in *Evince*, triggers an access of */run/mount/utab*, which
comes from *libmount* and should be allowed.
2019-08-09 10:11:37 +02:00
nl6720
54dc60ff5b Update usr.sbin.winbindd profile
Winbind requires access to /var/cache/samba/msg.lock/*.
Move msg.lock/ to abstractions/samba.
On Arch Linux Winbind's pid is set to /run/winbindd.pid.

Signed-off-by: nl6720 <nl6720@gmail.com>
2019-08-08 19:37:37 +03:00
Christian Boltz
2e304f82fc Merge branch 'cboltz-logparser-simplify-prefilter' into 'master'
Simplify log prefilter in logparser.py

See merge request apparmor/apparmor!400

Acked-by: John Johansen <john.johansen@canonical.com>
2019-08-05 20:01:59 +00:00
Christian Boltz
095d65f4ae Simplify log prefilter in logparser.py
As discussed in https://gitlab.com/apparmor/apparmor/merge_requests/395
RE_LOG_ALL should be more broad so that it doesn't accidently
overlook/ignore valid log events.

Instead of adding more and more known log formats to logparser.py,
simplify the regex to do only a basic check.

If we really hand over a line to libapparmor that isn't an AppArmor log
event, worst thing that can happen is that we waste a few milliseconds
for handing over that line to libapparmor, and get AA_RECORD_INVALID as a
result.
2019-08-05 21:42:59 +02:00
Tyler Hicks
167e9207be Merge branch 'lp1838991' into 'master'
parser: Fix typoed example dbus rule in apparmor.d(5) man page

See merge request apparmor/apparmor!410

Bug: https://launchpad.net/bugs/1838991
Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-08-05 16:56:50 +00:00
Tyler Hicks
7df48adae5 parser: Fix typoed example dbus rule in apparmor.d(5) man page
Remove extra closing parenthesis.

Bug: https://launchpad.net/bugs/1838991
Fixes: 46586a6334 ("parser: Add example dbus rule for unconfined peers")
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2019-08-05 15:14:35 +00:00
Vincas Dargis
6cfeb55e0e Add dbus-network-manager-strict abstraction
Some applications queries network configuration (using
QNetworkConfigurationManager class in Qt and similar), and that produces
DBus denials under AppArmor confinement when NetworkManager backend is
used.

Add abstraction that allows most common read-only DBus queries for
getting current network configuration from NetworkManager backend.
2019-08-05 16:23:58 +03:00
Christian Boltz
39ac1e8ca3 Merge branch 'cboltz-exec-without-target' into 'master'
logparser.py: don't error out on exec events without target

See merge request apparmor/apparmor!405

Acked-by: John Johansen <john.johansen@canonical.com>
2019-08-02 12:00:44 +00:00
Tyler Hicks
5bd75cd0b7 Merge branch 'test-policy-cache-old-libapparmor' into 'master'
tests: Allow aa_policy_cache.c to build against old libapparmors

See merge request apparmor/apparmor!407

Acked-by: John Johansen <john.johansen@canonical.com>
2019-08-01 22:46:58 +00:00
Tyler Hicks
2893a6af05 Merge branch 'nnp-test' into 'master'
tests: Add NO_NEW_PRIVS regression tests

See merge request apparmor/apparmor!408

Acked-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2019-08-01 22:41:15 +00:00
Tyler Hicks
7670336a82 libapparmor, tests: Be explicit about value-if-true in ternary operator
Improve readability by being explicit about the value to use when the
conditional evaluates to true.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Suggested-by: John Johansen <john.johansen@canonical.com>
2019-08-01 22:31:07 +00:00
Tyler Hicks
83d0b99729 Merge branch 'parser-cachedir-usage-typo' into 'master'
parser: Fix minor typo in usage

See merge request apparmor/apparmor!406

Acked-by: John Johansen <john.johansen@canonical.com>
2019-08-01 21:11:19 +00:00
Tyler Hicks
a77ba80838 tests: Allow aa_policy_cache.c to build against old libapparmors
Commit ad81ea0e67 ("tests: Add option to dump policy cache dir with
the libapparmor wrapper") modified aa_policy_cache.c to call
aa_policy_cache_dir_path_preview(). That added a hard dependency on
libapparmor >= 2.13, which is the first version to add
policy_cache_dir_path_preview() to libapparmor. The dependency makes it
impossible to build and run the upstream regression tests against an
installed libapparmor older than 2.13 due to aa_policy_cache.c failing
to build.

Add a compatible aa_policy_cache_dir_path_preview() when building
aa_policy_cache.c against a libapparmor older than 2.13 and newer than
or equal to 2.10.

Fixes: ad81ea0e67 ("tests: Add option to dump policy cache dir with the libapparmor wrapper")
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2019-08-01 16:40:14 +00:00
Tyler Hicks
50e34b45c2 parser: Fix minor typo in usage
Correct the long option used to print the cache directory.

Fixes: e9d9395f91 ("parser: Add option to print the cache directory")
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2019-08-01 15:04:49 +00:00
Tyler Hicks
9160204008 tests: Add NO_NEW_PRIVS regression tests
Test the profile transition limits imposed by NO_NEW_PRIVS to ensure
that behavior doesn't unexpectedly change.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2019-08-01 14:58:32 +00:00
Christian Boltz
a0c1eb0abd logparser.py: don't error out on exec events without target
commit 7297e2f6a8 assumed that exec events
always have a "target=...", but this is only true for events in complain
mode. In enforce mode, the log line doesn't include "target=...".

This commits sets an empty target instead of erroring out on every exec
event in enforce mode.

Also adjust ask_exec() in aa.py to only update
hashlog[aamode][target_profile]['final_name'] if target_profile is set
(hashlog[aamode][''] doesn't exist and trying to write to it would error
out)
2019-07-27 22:48:30 +02:00
Christian Boltz
dc3d11bf0a add log testcases for exec with and without target=
- in complain mode, exec events include target=...
- in enforce mode, the log message doesn't include target=...

Note that the utils tests skip exec events (they'd be interactive),
therefore exec*.profile doesn't contain an exec rule.
2019-07-27 22:23:15 +02:00
intrigeri
c9b8cfa4a9 Avoid blhc "CPPFLAGS missing" false positive. 2019-07-17 20:51:48 +00:00
Christian Boltz
db1f391844 Merge branch 'cboltz-unbalanced-parenthesis' into 'master'
Fix crash on unbalanced parenthesis in filename

See merge request apparmor/apparmor!402

Seth Arnold <seth.arnold@canonical.com> for 2.10..master
2019-07-09 19:45:08 +00:00
Xiang Fei Ding
654d96a3f7 parser: allow overriding which ar(1) is invoked
When cross compiling apparmor-parser, Makefile will use ar for
creating the static library. However, ar produces libraries on
the build platform. The right ar could be prefixed with the target
platform triples.

Signed-off-by: Xiang Fei Ding <dingxiangfei2009@gmail.com>
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Ref: https://github.com/NixOS/nixpkgs/pull/63999
Bug: https://gitlab.com/apparmor/apparmor/issues/41
2019-07-08 12:28:30 -07:00
Christian Boltz
8f74ac02ca Fix crash on unbalanced parenthesis in filename
convert_regexp() needs to escape '(' and ')' in filenames taken from a
logfile to get rid of their special meaning, and to avoid a crash on
unbalanced parenthesis (which makes the regex invalid if they are not
escaped).

Note: The added tests include an example log line, but the tests itsself
don't/didn't trigger the crash because they don't call convert_regexp().

Fixes: https://bugs.launchpad.net/bugs/1835311
2019-07-07 22:24:12 +02:00
John Johansen
0349cf2d0a libapparmor: logparse: fix RECORD_INVALID for valid log
v2:
- parse partial log line broken at \n
- add testcase_dbus_10.* for partial log line
- remove quotes from  testcasw_dbus_09.profile

The following log format has been seen in the wild, and currently results
in a RECORD_INVALID

    [4835959.046111] audit: type=1107 audit(1561053426.749:186): pid=640 uid=103 auid=4294967295 ses=4294967295 msg='apparmor="ALLOWED" operation="dbus_method_call"  bus="system" path="/org/freedesktop/systemd1" interface="org.freedesktop.systemd1.Manager" member="LookupDynamicUserByName" mask="send" name="org.freedesktop.systemd1" pid=20596 label="/usr/sbin/sshd" peer_pid=1 peer_label="unconfined"
                      exe="/usr/bin/dbus-daemon" sauid=103 hostname=? addr=? terminal=?'

Test parsing the above message with and without the \n embedded between
peer_label= and exec=

Acked-by: Seth Arnold <seth.arnold@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-07-02 01:01:37 -07:00
Christian Boltz
8a8130d4dd Merge branch 'cboltz-whitespace-fix' into 'master'
Fix whitespace in ssl_* abstractions

See merge request apparmor/apparmor!399

Acked-by: John Johansen <john.johansen@canonical.com>
2019-06-30 07:16:06 +00:00
Christian Boltz
2d74c42c75 Fix whitespace in ssl_* abstractions
Drop superfluous whitespace introduced by
4d275bab69 and
3016ffb336
2019-06-29 23:23:07 +02:00
Christian Boltz
b0575b077b Merge branch 'master' into 'master'
Add for Certbot on openSUSE Leap

The default path is `/etc/certbot/archive/{some domain}/{file name}.pem`

See merge request apparmor/apparmor!397


Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-06-29 21:05:39 +00:00
Richard Chen
4d275bab69 Update ssl_keys 2019-06-28 07:31:10 +00:00
Richard Chen
3016ffb336 Add for CertBot on openSUSE Leap 2019-06-28 07:30:10 +00:00
Christian Boltz
0d327abf3a Merge branch 'cboltz-postfix-profiles' into 'master'
postfix/master needs to execute postfix/error

See merge request apparmor/apparmor!392

Acked-by: Seth Arnold <seth.arnold@canonical.com>
2019-06-27 14:41:41 +00:00
Christian Boltz
5aa17c1fa4 Merge branch 'cboltz-sfs-mountpoint' into 'master'
Fix and simplify setting SFS_MOUNTPOINT

See merge request apparmor/apparmor!394

Acked-by: Seth Arnold <seth.arnold@canonical.com>
2019-06-27 14:33:57 +00:00
Steve Beattie
7c7a4bc531 regression tests/mult_mount: bump size of created disk image
The mult_mount test creates a small disk image, formats it, and mounts
it in multiple locations in preparation for the tests. However, the
created raw file (80KB) is too small to make a working file system if
4K blocks are used by mkfs. In Ubuntu 19.10, the default was recently
changed for mkfs to default to always using 4K blocks, causing the
script to fail.

We could force mkfs to use 1K blocks, but instead, in case some future
version of mkfs decides not to support 1K blocks at all, we bump up the
size of the disk image to 512KB; large enough to work with 4K blocks
yet small enough to be workable in small scale test environments.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Bug: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1834192
MR: https://gitlab.com/apparmor/apparmor/merge_requests/396
2019-06-26 08:36:04 -07:00
Christian Boltz
61c27d8808 Fix and simplify setting SFS_MOUNTPOINT
Instead of setting SFS_MOUNTPOINT in is_apparmor_loaded() (which is
called in most cases) and in is_container_with_internal_policy() (which
covers/fixes the remaining cases), set it globally.

This also fixes a bug in is_container_with_internal_policy() (introduced
in f10e72a14f) where the variable
definition tried to use the no longer existing $MODULE variable and
therefore got a wrong path for $SFS_MOUNTPOINT.

Besides this bug, there's a minor behaviour change / improvement if
securityfs isn't mounted - "file not found" error messages will now
contain the full/correct path ;-)

This change/cleanup is a follow-up of
https://gitlab.com/apparmor/apparmor/merge_requests/363 and some IRC
discussions 2019-04-16.
2019-06-21 19:22:15 +02:00
Christian Boltz
f250e94240 postfix/master needs to execute postfix/error 2019-06-20 14:37:46 +02:00
John Johansen
a45d2c9dcd libapparmor: bump revision to match 2.13.3 release revision.
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-06-18 14:08:57 -07:00
Christian Boltz
ff287e9238 abstractions/dri-common: allow reading /dev/dri/
Fixes https://gitlab.com/apparmor/apparmor/issues/29

PR: https://gitlab.com/apparmor/apparmor/merge_requests/382
Signed-off-by: Christian Boltz <apparmor@cboltz.de>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-06-14 01:10:38 -07:00
Christian Boltz
c866bc276b update freshclam profile
freshclam needs to write more files in /var/lib/clamav/, and also needs
to write its pid file.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/381
Signed-off-by: Christian Boltz <apparmor@cboltz.de>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-06-14 01:05:16 -07:00
John Johansen
9144e39d25 Revert "utils/test-network.py: fix failing testcase"
This reverts commit 378519d23f.
this commit was meant for the 2.13 branch not master

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-06-14 01:05:16 -07:00
Steve Beattie
378519d23f utils/test-network.py: fix failing testcase
When dc010bc034 was
backported to the apparmor-2.13 branch (in commit
75236d62e2), it did not take into
account cb8c3377ba, which creates the
common/list_af_names.sh script as used in the test case, was not also
backported to the apparmor-2.13 branch.

Change the test case to get the list of network AF names via the same
make invocation taken by the utils/vim/create-apparmor.vim.py script
before the common/list_af_names.sh existed.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/391
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-06-14 00:04:00 -07:00
John Johansen
48e9f0ee2e Merge branch 'cboltz-postfix-profiles' into 'master'
update postfix profiles

On openSUSE Leap 15.1, the postfix binaries live in /usr/lib/postfix/bin/ which was not covered in the postfix.\* attachment and mrix rules.

Also add several permissions to the postfix.\* profiles needed on openSUSE Leap 15.1.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/380
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-06-14 04:31:14 +00:00
Jamie Strandboge
f10e72a14f set SFS_MOUNTPOINT in is_container_with_internal_policy()
is_container_with_internal_policy() is called independently of
apparmor_*() in the systemd unit and potentially other consumers of
rc.apparmor.functions. When the unit and rc.apparmor.functions functions
were rewritten, they were written so that SFS_MOUNTPOINT was only set in
is_apparmor_loaded(), but this is only called in apparmor_start(),
remove_profiles(), apparmor_kill(), apparmor_restart(), apparmor_try_restart()
and apparmor_status() and not is_container_with_internal_policy().

While it is clear that is_container_with_internal_policy() is meant to
be called before apparmor_start(), is is unclear why SFS_MOUNTPOINT is
only defined in is_apparmor_loaded(). There are several ways to fix
this:

1. update is_container_with_internal_policy() to call is_apparmor_loaded()
2. identify the callers of is_container_with_internal_policy() and have
   them call is_apparmor_loaded()
3. reorganize the code to remove duplicate calls and assignments
4. define SFS_MOUNTPOINT along with SECURITYFS and MODULE, at the top
   level
5. also define SFS_MOUNTPOINT in is_container_with_internal_policy()

'1' would result in redundant calls in many common cases since the
systemd unit would call is_apparmor_loaded() both in
is_container_with_internal_policy() and prior to other calls.

'2' would like break consumers of rc.apparmor.funcions, like
Debian/Ubuntu's profile-load.

'3' is perhaps ok, but requires more effort and is regression-prone.

'4' seems the simplest, most correct fix

'5' is what this patch implements, which is as simple as '4' but tries
to maintain the original author's intent of when to set SFS_MOUNTPOINT.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/363
Signed-off-by: Jamie Strandboge <jamie@strandboge.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-06-13 21:21:21 -07:00
John Johansen
5fd07de9f4 Merge branch 'cboltz-syslog-ng' into 'master'
syslog-ng: add abstractions/python for python-parser

When running syslog-ng with a defined python-parser, it needs access to python libraries.

For details about python-parser, see https://www.syslog-ng.com/community/b/blog/posts/format-your-log-messages-in-python

References: https://github.com/balabit/syslog-ng/issues/2625

PR: https://gitlab.com/apparmor/apparmor/merge_requests/361
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-06-14 00:39:30 +00:00
John Johansen
5b2f4e8b66 Merge branch 'master' into 'master'
parser: Fix parsing of arrow “px -> …”

The parser failed to read the profile name after the the arrow. Rules with `-> foo-bar;` failed with “Found unexpected character: '-'”. Rules with `-> @{tgt};` compiled fine, but failed at runtime with “profile transition not found”.

The patch was written by sbeattie and published on https://paste.ubuntu.com/p/tzxxmVwGJ8/

[https://matrix.to/#/!pNJIrowvqsuGgjXsEY:matrix.org/$15477566201815716pmube:matrix.org?via=matrix.org&via=alea.gnuu.de](https://matrix.to/#/!pNJIrowvqsuGgjXsEY:matrix.org/%2415477566201815716pmube:matrix.org?via=matrix.org&via=alea.gnuu.de)

PR: https://gitlab.com/apparmor/apparmor/merge_requests/334
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-06-14 00:32:55 +00:00
Mike Salvatore
82ff86bfbf Add a build-dep target to tests/regression/apparmor/Makefile
Add a target to install build dependencies for the apparmor regression
tests. Currently supports Ubuntu and Debian distros.

Signed-off-by: Mike Salvatore <mike.salvatore@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-06-13 17:29:00 -07:00
Steve Beattie
03c08cf989 utils: remove conflicting action in Swedish translation
The translated action character for Deny conflicted with the
untranslated action character for Finish in the Swedish translation.
Remote it, and hope for more action translations.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 15:03:06 -07:00
Steve Beattie
3ee468864d Translations: merge updates from launchpad
Omnibus collection of translations updates.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:45:25 -07:00
Launchpad Translations on behalf of apparmor-dev
9d226f5887 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:39:52 -07:00
Launchpad Translations on behalf of apparmor-dev
01656486ef Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:39:52 -07:00
Launchpad Translations on behalf of apparmor-dev
90a4b301bd Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:39:52 -07:00
Launchpad Translations on behalf of apparmor-dev
3b1c320cfc Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:30:01 -07:00
Launchpad Translations on behalf of apparmor-dev
5a62c68743 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:30:00 -07:00
Launchpad Translations on behalf of apparmor-dev
78c09e4337 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:30:00 -07:00
Launchpad Translations on behalf of apparmor-dev
2c614d4413 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:30:00 -07:00
Launchpad Translations on behalf of apparmor-dev
d14723b78c Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:30:00 -07:00
Launchpad Translations on behalf of apparmor-dev
fe2faeb24f Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:30:00 -07:00
Launchpad Translations on behalf of apparmor-dev
9650201928 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:29:59 -07:00
Launchpad Translations on behalf of apparmor-dev
2b936e25a8 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:29:59 -07:00
Launchpad Translations on behalf of apparmor-dev
02ba8523c6 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:29:59 -07:00
Launchpad Translations on behalf of apparmor-dev
72bcf23c5d Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:29:59 -07:00
Launchpad Translations on behalf of apparmor-dev
9f9294b48b Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:29:59 -07:00
Launchpad Translations on behalf of apparmor-dev
41b5fecbcf Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:29:59 -07:00
Launchpad Translations on behalf of apparmor-dev
dc98e8ff55 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:29:09 -07:00
Launchpad Translations on behalf of apparmor-dev
ba3dc9fc85 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:28:53 -07:00
Launchpad Translations on behalf of apparmor-dev
42b43d58d0 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:28:40 -07:00
Launchpad Translations on behalf of apparmor-dev
301857ef5d Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:28:10 -07:00
Launchpad Translations on behalf of apparmor-dev
303deea3a8 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:27:22 -07:00
Launchpad Translations on behalf of apparmor-dev
894c6cd6d2 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:26:56 -07:00
Launchpad Translations on behalf of apparmor-dev
eb38db5953 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:26:30 -07:00
Launchpad Translations on behalf of apparmor-dev
5cc8718965 Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:26:01 -07:00
Jamie Strandboge
1f9cc702ed Merge branch 'cache-fix' into 'master'
parser: Don't skip cache just because optimizations are specified

See merge request apparmor/apparmor!385
2019-06-06 21:54:06 +00:00
John Johansen
f6cd5c01c1 parser: Don't skip cache just because optimizations are specified
The parser currently skips the cache if optimizations are specified
because it can not determine if the cached policy was compiled
with the specified optimization. However this causes cache misses
even if policy is cached with those options, and distros are setting
some optimizations by default.

Instead of skipping reading the cache if optimizations are set, users
can force overwriting the cache if needed, until the parser can
store aditional meta info in the cache.

BugLink: http://bugs.launchpad.net/bugs/1820068
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-06-05 02:18:46 -07:00
John Johansen
a6ac6f4cfc libapparmor python: Fix 'aa_log_record' object has no attribute '__getattr__'
When building with swig 4 we are seeing the error

AttributeError: 'aa_log_record' object has no attribute '__getattr__'

Which forces swig to use modern classes which do not generate __getattr__
methods.

issue: https://gitlab.com/apparmor/apparmor/issues/33
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-06-04 21:43:48 -07:00
Christian Boltz
7016ac954b Add several permissions to the postfix.* profiles
... needed on openSUSE Leap 15.1
2019-06-02 18:39:43 +02:00
Christian Boltz
f668f31bf0 adjust postfix profiles for openSUSE path
On openSUSE Leap 15.1, the postfix binaries live in
/usr/lib/postfix/bin/ which was not covered in the postfix.* attachment
and mrix rules.
2019-06-02 18:39:43 +02:00
Christian Boltz
60d3be22cf Merge branch 'cboltz-finishing' into 'master'
drop unused 'finishing' in do_logprof_pass()

See merge request apparmor/apparmor!383

Acked-by: Eric Chiang <ericchiang@google.com>
2019-05-20 15:30:19 +00:00
Christian Boltz
5abfb08a3e drop unused 'finishing' in do_logprof_pass()
finishing was always false, resulting in always returning 'NORMAL'.

Remove the variable, remove the unused condition - and change the only
place (aa-genprof) that expected a return value from do_logprof_pass()
to not expect it anymore.

found by Coverity, CID 198637
2019-05-17 22:27:57 +02:00
Christian Boltz
758a6b214f Merge branch 'cboltz-rewrite-logparser' into 'master'
Rewrite log handling

logparser.py puts each log event on a big "stack" in self.pid. Later,
handle_children() in aa.py then converts that (named 'log' in aa.py) to
the prelog hasher.

This commit changes logparser.py to create a prelog-like structure itsself
(named hashlog), which
- removes one level of indirection
- probably saves some memory because the hashlog automatically
  de-duplicates events

In aa.py, collapse_log() gets updated to work with hashlog. (There's
also a handle_hashlog() function in this patch series, but it didn't 
survive the final patches ;-)

OTOH, the now superfluous code handling capability, network etc.
events gets removed from handle_children(). The remaining parts of
this function get split into ask_exec() and ask_addhat().

logparser.py gets a new function init_hashlog() to initialize hashlog
for each profile. It also gets changed to store capability, network etc.
events into hashlog instead of storing them in self.pid.

hashlog uses the full profile name as key, which is the first baby step
to support nested child profiles. (for now, collapse_log() still
splits the profile name into profile and hat.)

There are many more details, see the individual commits ;-)

See merge request apparmor/apparmor!377

Acked-by: Seth Arnold <seth.arnold@canonical.com>
2019-05-12 10:56:14 +00:00
John Johansen
ab0f2af1da tests/regression: fix mount test to use next available loop device
looping through the first 16 loop devices to find a free device will
fail if those mount devices are taken, and unfortunately there are
now services that use an excessive amount of loop devices causing
the regression test to fail.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2019-05-10 18:06:55 -07:00
John Johansen
30348ebe9d README make the subsections of Regression Tests more obvious
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-05-09 23:01:31 -07:00
John Johansen
c50eb09ebc Update README build instructions to have cross links
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-05-09 22:58:50 -07:00
John Johansen
74ade80cf1 Update README with instructions on USE_SYSTEM=1 for the regression tests
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-05-09 22:54:19 -07:00
Christian Boltz
205ae4a256 collapse_log(): don't overwrite existing ProfileStorage
When a user chooses the ix exec mode, don't overwrite the existing
ProfileStoragge to avoid loosing the already collected events.
2019-05-09 18:22:07 +02:00
Christian Boltz
836caca462 collapse_log: ignore events from null-* profiles
If final_name still includes null-*, that's most likely caused by nested
execs which aren't supported by the tools yet. Ignoring them is better
than creating a useless null-* hat.

Note: The tools always had this restriction, so this is not a regression ;-)

Also note that test-libapparmor-test_multi expects that null-* hats get
created (which makes sense because the one-line log sniplets don't have
any exec indication), therefore add an optional parameter to keep this
behaviour for the tests.
2019-05-09 18:14:18 +02:00
Christian Boltz
387d1646c8 Merge handle_hashlog() into collapse_log()
Now that all log events arrive in hashlog, having a separate 'prelog' no
longer makes sense. Changing collapse_log() to accept 'hashlog' directly
removes that level of indirection.
2019-05-09 17:29:26 +02:00
Christian Boltz
c5f0097f65 make 'prelog' non-global
It's only used by two functions:
- handle_hashlog() - writes to prelog, and now returns it
- collapse_log() - reads prelog, and now gets it as parameter
2019-05-09 17:29:26 +02:00
Christian Boltz
c77426ed62 Introduce 'final_name' to hashlog and handle exec choices
'final_name' by default is the profile name, but ask_exec() will change
it for the target profile (which is a null-* profile at this stage)
based on exec mode choice. ask_addhat() will also change it based on the
chosen hat.

Choosing "deny" or "unconfined" will result in an empty final_name and
ignoring these log events.

All other choices set final_name to the full profile name ("foo" for Px,
"foo//bar" for Cx, current profile for ix).

Also fix the order of handling log events - since ask_exec() changes the
hashlog final_name, it has to run first so that ask_addhat() (which
"only" adjusts the hat name in final_name) and handle_hashlog() can work
with the updated profile name.

Finally, update test-libapparmor-test_multi.py to ignore final_name when
checking if hashlog is empty, and fix the call order of ask_exec() etc.
2019-05-09 17:29:26 +02:00
Christian Boltz
d1b8772a1d ask_exec(): simplify to_name logic
At this stage of ask_exec(), to_name is always empty, therefore drop an
if condition that checks it (and the code inside that branch).
2019-05-09 17:15:35 +02:00
Christian Boltz
5953ac3dda ask_exec(): drop useless setting of profile and hat
profile and hat don't get used in the following lines, and later get
overwritten in the next round of the for loop.

The deleted code was last useful for setting the (dropped)
profile_changes array.
2019-05-09 17:15:35 +02:00
Christian Boltz
3ec4869adf ask_exec(): Get rid of unused context_new variable 2019-05-09 17:15:35 +02:00
Christian Boltz
48cc1b2837 add a split_name() function to split a profile name
... into profile and hat.

Also change several places to use split_name().
2019-05-09 17:15:35 +02:00
Christian Boltz
305b378bfd Delete apparmor/aamode.py and its testsuite
After the logparser cleanup, aamode.py and its overly complicated
permission handling is no longer needed.
2019-05-09 17:15:35 +02:00
Christian Boltz
45a3d8920a Drop unused 'pid' parameter from ReadLog.__init__()
... and self.pid which is also unused.

This simple change also means to adjust all the code that uses ReadLog.
We get rid of log_pid in aa.py, and have to change lots of test-*
2019-05-09 17:15:35 +02:00
Christian Boltz
9a92909a89 Change read_log to return only hashlog
self.log is unused, drop it.

Also change all places that call read_log() to match the simplified
return value.
2019-05-09 17:15:35 +02:00
Christian Boltz
d4512aa5d7 Drop add_to_tree and some superfluous code
After all the changes in this branch, parse_event_for_tree always
returns None, which makes the "if event is not None" branch dead code.

This branch was the only place where add_to_tree() was called, therefore
remove this function.

This also makes self.pid and self.log unused. They'll be removed with
separate commits.
2019-05-09 17:15:35 +02:00
Christian Boltz
3b77d63556 ask_exec(): don't overwrite 'hat' in cx handling
Otherwise we'd have to reset 'hat' in the next round of the for loop.

Using 'exec_target' instead of 'hat' in the cx code is much easier.
2019-05-09 17:15:35 +02:00
Christian Boltz
d2663b148a Transform handle_children() to ask_exec()
The only remaining job of handle_children() was to handle exec events.
(And recursively calling itsself if it hits nested log events, but
logparser.py never created such a log structure.)

Therefore:
- drop the dead code handling nested log (type != str)
- rename the remaining function to ask_exec()
- drop checks for typ = 'exec' (now done as part of the for loop
- drop the "else" branch for unknown event types
- change 'return' to 'continue' because ask_exec handles all exec events
  in a loop instead of being called multiple times
- oh, and of course switch over to using hashlog

Finally, change do_logprof_pass() and the tests to call ask_exec()
instead of handle_children().

While on it, update a comment in test-translations.py which held the
last reference to handle_children().
2019-05-09 17:15:35 +02:00
Christian Boltz
7297e2f6a8 parse_event_for_tree(): Move exec events to loghash
The 'hat' and 'prog' variables are no longer needed, drop them.

Also no longer include denied_mask in the event - operation='exec' means
an exec event, no need to additionally hand over 'x' permissions.

Note: This commit introduces a "brain split", which means exec handling
is temporarily broken. Later commits will fix this.
2019-05-03 23:25:55 +02:00
Christian Boltz
62adc8547c handle_children(): drop using 'prog' and checking for non-empty to_name
parse_event_for_tree() always sets prog = 'HINT' and to_name = '' for
exec events.

The only exception is in the 'mandatory profile missing' case where
prog = aamode and to_name = target_profile, but I've never seen that in
practise.

This means the prog != 'HINT' branch in exec handling never gets used
and can be dropped.

Erroring out "if to_name:" also never gets used (to_name is always ''),
therefore drop it as well.
2019-05-03 23:01:21 +02:00
Christian Boltz
460d1fda93 handle_children(): get rid of 'domainchange'
"if domainchange == 'change':" is always true, therefore get rid of this
check and the domainchange variable.
2019-05-03 22:54:46 +02:00
Christian Boltz
13f67d45d0 ask_addhat: print warning only if we have change_hat events
Printing the warning whenever a child profile exists is pointless. It
only makes sense if there are change_hat events inside the child profile.
2019-05-03 22:54:46 +02:00
Christian Boltz
f0db04d2b7 Merge branch 'feature/aa-notify-new-features' into 'master'
Minor improvements to aa-notify

See merge request apparmor/apparmor!372

Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-05-03 18:15:02 +00:00
Otto Kekäläinen
81d514d89a aa-notify: Always use aa.CONFDIR, don't assume "/etc/apparmor"
Also fix cosmetic comment.
2019-05-03 17:53:24 +03:00
Christian Boltz
1b7cdec70d Fix and simplify ask_addhat()
- replace/merge 'uhat' with 'hat'
- adjust ProfileStorage comment to the new function name
- initialize default hat if it gets chosen and doesn't exist yet
- don't exit the function if "Deny" gets chosen. Instead, continue with
  the next hat to (possibly) add
2019-05-03 00:12:46 +02:00
Christian Boltz
560fb6fabe Use hashlog for change_hat log events
Adjust logparser.py to store change_hat events in hashlog.

In aa.py,
- split off ask_addhat() from handle_children()
- change ask_addhat() to use hashlog
- call ask_addhat() from do_logprof_pass()

Also call ask_addhat() in test-libapparmor-test_multi.py to keep it in
sync with do_logprof_pass().
2019-05-03 00:12:46 +02:00
Christian Boltz
eeb70c4695 drop restriction on complain mode in change_hat handling
Also move/merge the remaining change_hat checks into the section
handling change_hat events.
2019-05-02 23:10:08 +02:00
Christian Boltz
49b8ca1e73 handle_children: don't initialize variables that get always set
All the variables initialized at the start of the function always get
overwritten in the loop, therefore it's superfluous to initialize them.

Also inline 'entries' to the only place that uses it.
2019-05-02 23:10:08 +02:00
Christian Boltz
a2870a71cb Drop handling of operation="clone"
According to John, this isn't supported since 10 years.

In case you wonder why this commit removes the "fork" handling in
handle_children() - logparser.py names clone events "fork" on the event
stack.
2019-05-02 23:10:03 +02:00
Christian Boltz
d11ed33d16 Stop ignoring profile_set events
According to John, this is no longer needed.
2019-05-02 20:24:15 +02:00
Christian Boltz
8b1b10babd Add tests for parse_event_for_tree() with invalid log lines
Also convert test-logparser.py to AATest.
2019-05-02 01:10:18 +02:00
Christian Boltz
a43c1da287 Remove superfluous code and checks in path log handling
In logparser parse_event_for_tree() path event handling, drop mapping
permissions for request_mask because request_mask never gets used.
Also drop the validate_log_mode() call because the function has its own,
more strict check since the last commit.

In aamode.py, drop the now unused validate_log_mode() and
hide_log_mode() functions and the LOG_MODE_RE regex.

Finally, drop the validate_log_mode() tests from test-aamode.py
2019-05-02 01:10:18 +02:00
Christian Boltz
3d3667f38b move path log event handling to hashlog
In logparser.py parse_event_for_tree, convert path handling to hashlog.
While on it, include 'owner' as part of hashlog so that aa.py doesn't
need to guess.

Also switch to a simple for loop instead of using log_str_to_mode() from
aamode.py to convert denied_mask to hasher keys (which would have been
needed to allow merging of several log events for the same path anyway).
Note that the check for 'mrawlk' (intentionally without 'x') is more
strict than the validate_log_mode(), but it should still cover all file
permissions. (validate_log_mode() also allows things like 'Px', which
we'll never hit in a logfile.)

In aa.py collapse_log() update the handling of path events to match the
additional [owner] key in hashlog/prelog. This makes the owner detection
in collapse_log() superfluous.

In aa.py handle_children(), remove 'path' handling from the 'path' or
'exec' section, and add an 'if True:' to avoid lots of whitespace
changes.

In aamode.py, drop the now unused split_mode() function, and
AA_OTHER_REMOVE() that was only used by split_mode().

Finally, remove sample log events with null-* hats from the list of
known failures in test-libapparmor-test_multi.py (we no longer filter
out null-* hats), and fix whitespace in two expected profiles.
2019-05-02 01:10:18 +02:00
Christian Boltz
1a46de1892 drop check if 'inode_permission' event means exec
According to John, 'inode_permission' wasn't used for 10 years.

This little change also means that we now have a clear separation
between "exec" and "normal" (mrwlk) file events.

Also drop the now superfluous makes peek_at_next_log_entry() and
throw_away_next_log_entry() functions.
2019-05-02 01:10:13 +02:00
Christian Boltz
61251dfd50 move dbus and ptrace log events to hashlog 2019-05-01 21:24:48 +02:00
Christian Boltz
6b63f49ad4 Remove a level of indirection on logparser.py
logparser.py puts each log event on a big "stack" in self.pid. Later,
handle_children() in aa.py then converts that (named 'log' in aa.py) to
the prelog hasher.

This commit changes logparser.py to create the prelog structure itsself
(named hashlog), which
- removes one level of indirection
- probably saves some memory because the hashlog automatically
  de-duplicates events

This commit does this for capability, network and signal events, and
adds the infrastructure needed for all event/rule types.

In aa.py, the new function handle_hashlog() copies the hashlog content
to prelog. OTOH, the now superfluous code handling capability, network
and signal events gets removed from handle_children().
Long-term, hashlog will replace log in aa.py. When this is done,
handle_hashlog() will be replaced by a simple prelog = hashlog.

logparser.py gets a new function init_hashlog() to initialize hashlog
for each profile. It also gets changed to store capability, network and
signal events into hashlog instead of storing them in self.pid.

hashlog uses the full profile name as key, which is the first baby step
to support nested child profiles. (for now, handle_hashlog() still
splits the profile name into profile and hat.)

Known issue: The new implementation doesn't handle exec yet, which means
that events get lost at the exec boundary (= in cases aa-logprof asks
which execute mode to use). This will be fixed in a later commit.
2019-05-01 21:22:36 +02:00
Christian Boltz
7282fbd8bf Merge branch 'cboltz-drop-set-process' into 'master'
Drop broken set_process() and the profile_changes array

See merge request apparmor/apparmor!376

Acked-by: Seth Arnold <seth.arnold@canonical.com>
2019-05-01 16:44:48 +00:00
Christian Boltz
8052fd0e1f Merge branch 'cboltz-link-cleanup' into 'master'
Drop no longer used set_allow_str()

See merge request apparmor/apparmor!375

Acked-by: Seth Arnold <seth.arnold@canonical.com>
2019-05-01 16:43:16 +00:00
Christian Boltz
14a3ca0439 Drop no longer used set_allow_str()
The old link rule implementation (which was replaced some commits ago)
was the last user of this function.
2019-04-30 00:59:09 +02:00
Christian Boltz
7099459f2c drop profile_changes array
... which is unused after dropping set_process()
2019-04-30 00:02:05 +02:00
Christian Boltz
b07459c854 Drop broken set_process()
This function was meant to set a process running under a null-* profile
to its "real" profile after deciding about the exec mode/target.
However, this is not supported in the kernel.

"Luckily" the function was also broken and exited early, which
successfully prevented erroring out.

All that means set_process() is useless and we can drop it.
2019-04-29 23:35:52 +02:00
Christian Boltz
382eb7a629 Merge branch 'cboltz-link' into 'master'
Move handling of 'link' rules to FileRule

See merge request apparmor/apparmor!371

Acked-by: Eric Chiang <ericchiang@google.com>
2019-04-29 19:09:32 +00:00
Christian Boltz
041cd95a98 Merge branch 'cboltz-link-man' into 'master'
Drop 'to' option for link rules from manpage

See merge request apparmor/apparmor!368

Acked-by: Eric Chiang <ericchiang@google.com>
2019-04-29 18:58:49 +00:00
Christian Boltz
f473e692c7 Merge branch 'cboltz-mergeprof-import' into 'master'
drop superfluous import apparmor.aamode from aa-mergeprof

See merge request apparmor/apparmor!373

Acked-by: Eric Chiang <ericchiang@google.com>
2019-04-29 18:58:07 +00:00
Christian Boltz
5501705f21 Merge branch 'cboltz-logparser' into 'master'
logparser cleanup

- drop old commented out code
- inline two small functions into the places calling them to make the callstack smaller and easier to understand
- rename 'netdomain' log events to 'network' to match rule name 
- handle_children: raise exception on unknown event type 

As usual, reading the individual commits makes the changes easier to understand.

See merge request apparmor/apparmor!374

Acked-by: Seth Arnold <seth.arnold@canonical.com>
2019-04-29 18:56:48 +00:00
Christian Boltz
53a2eb56b4 handle_children: raise exception on unknown event type
(shouldn't happen, but a check never hurts)
2019-04-28 17:57:37 +02:00
Christian Boltz
f5add27aaa rename 'netdomain' log events to 'network' to match rule name 2019-04-28 16:27:48 +02:00
Christian Boltz
b86fed1a57 drop commented out code from logparser.py 2019-04-28 14:37:43 +02:00
Christian Boltz
bed9ce35a1 inline parse_log_record() into parse_event_for_tree() and read_log() 2019-04-28 12:04:43 +02:00
Christian Boltz
1ce93a4c2d inline add_event_to_tree() into read_log() 2019-04-28 11:57:29 +02:00
Christian Boltz
9c11ce37c6 Merge branch 'cboltz-gitignore' into 'master'
Add several libapparmor/swig/ruby files to gitignore

See merge request apparmor/apparmor!366
2019-04-26 16:16:10 +00:00
Christian Boltz
3dd6fdad79 drop superfluous import apparmor.aamode from aa-mergeprof 2019-04-23 21:53:52 +02:00
Christian Boltz
99b476510f Remove 'owner link' tests from list of known-broken tests
... because they work now :-)
2019-04-23 00:22:25 +02:00
Christian Boltz
6bcfbb7a18 Remove old code for link rules 2019-04-23 00:22:25 +02:00
Christian Boltz
09a761ed80 Update and extend cleanprof tests for link rules 2019-04-22 23:41:08 +02:00
Christian Boltz
aa1e315e77 Add tests for link rules to test-file.py 2019-04-22 23:39:47 +02:00
Christian Boltz
f176baf904 Add support for link rules to FileRule 2019-04-22 23:39:47 +02:00
Christian Boltz
a477a06847 Extend RE_PROFILE_FILE_ENTRY to cover link rules 2019-04-22 23:39:47 +02:00
Christian Boltz
ee2185f4b6 Merge branch 'cboltz-link-owner' into 'master'
Add testcases for 'owner link' rules

See merge request apparmor/apparmor!369

Acked-by: Eric Chiang <ericchiang@google.com>
2019-04-22 17:59:06 +00:00
Christian Boltz
7d95e2658e Merge branch 'cboltz-typo' into 'master'
Fix typo in set_json_mode() comment

See merge request apparmor/apparmor!364

Acked-by: Eric Chiang <ericchiang@google.com>
2019-04-22 17:58:15 +00:00
Christian Boltz
c6128da1fc Merge branch 'cboltz-test-parse-profile-start' into 'master'
parse_profile_start: test with un-named profile

See merge request apparmor/apparmor!367

Acked-by: Eric Chiang <ericchiang@google.com>
2019-04-22 17:57:44 +00:00
Christian Boltz
233f7179ef Merge branch 'EmersonBernier/shellcheck' into 'master'
parser/rc.apparmor.functions: fix minor issues detected by shellcheck/shellharden

See merge request apparmor/apparmor!370

Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-04-22 14:18:13 +00:00
Emerson Bernier
fe6fc458e7 parser/rc.apparmor.functions: fix minor issues detected by shellcheck/shellharden 2019-04-22 15:02:45 +02:00
Christian Boltz
0facb1598c Add testcases for 'owner link' rules
.. and document that the tools don't support them yet
2019-04-22 13:36:33 +02:00
Christian Boltz
115a1d890e Drop 'to' option for link rules from manpage
The apparmor.d manpage listed 'to' as an alternative for '->' in link
rules.

However, the parser doesn't accept 'to', none of our examples and tests
include it, and nobody ever complained about it. Therefore I'll call
this a documentation bug ;-) and simply adjust the manpage to only list
'->' as valid syntax.
2019-04-22 12:46:37 +02:00
Christian Boltz
1d19bb7110 parse_profile_start: test with un-named profile
Also update the comment in _parse to match the updated return values.
2019-04-22 12:38:38 +02:00
Christian Boltz
7ed1a16af1 Add several libapparmor/swig/ruby files to gitignore
These files get created by swig, and deleted with make clean
2019-04-21 21:56:46 +02:00
Christian Boltz
e3f0a6ff63 Merge branch 'feature/aa-notify-in-python' into 'master'
Rewrite aa-notify in Python

Closes #16

See merge request apparmor/apparmor!341

Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-04-21 17:02:34 +00:00
Christian Boltz
cece787182 Merge branch 'bugfix/aa-always-logfile-fallback' into 'master'
Fix error 'KeyError: 'logfiles'' when no logprof.conf exists

See merge request apparmor/apparmor!365

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.12..master
2019-04-21 16:48:34 +00:00
Otto Kekäläinen
d4cab56ac7 aa-notify: Use fixed output width in tests so results always look same 2019-04-21 18:37:10 +03:00
Otto Kekäläinen
d5990da72a aa-notify: Use AATest class in tests since possible now with Python 2019-04-21 18:37:10 +03:00
Otto Kekäläinen
a74d7cf51c Re-implement aa-notify in Python (Closes: #16)
- Code layout based on aa-genprof example
- Extend Python dependencies to cover new need by aa-notify
- Update documentation after aa-notify is no longer in Perl
2019-04-21 18:37:10 +03:00
Otto Kekäläinen
3a1eec49d4 Add tests for shared aa library functions used in command line scripts 2019-04-21 18:37:10 +03:00
Otto Kekäläinen
3c7e1668bd aa.py: Indicate permission error if log file is found but cannot be opened 2019-04-21 18:35:33 +03:00
Otto Kekäläinen
455c441357 aa.py: Ensure there is always a fallback falue for the logfile location
Related to #22.

Fixes error message:

  Traceback (most recent call last):
    File "./aa-notify", line 523, in <module>
      main()
    File "./aa-notify", line 399, in main
      aa.set_logfile(args.file)
    File "/home/otto/koodia/apparmor/utils/apparmor/aa.py", line 1762,
    in set_logfile
      print(conf.find_first_file(cfg['settings']['logfiles']))
    File "/usr/lib/python3.6/configparser.py", line 1233, in __getitem__
      raise KeyError(key)
  KeyError: 'logfiles'
2019-04-20 23:34:04 +03:00
Christian Boltz
7153eb09d9 Fix typo in set_json_mode() comment 2019-04-19 22:25:30 +02:00
Christian Boltz
c01c867216 Merge branch 'feature/aa-test' into 'master'
Add tests for shared aa library functions used in command line scripts

See merge request apparmor/apparmor!328

Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-04-19 20:24:08 +00:00
Otto Kekäläinen
fdd13db13b Add tests for shared aa library functions used in command line scripts 2019-04-19 17:29:26 +03:00
Christian Boltz
234a924480 syslog-ng: add abstractions/python for python-parser
When running syslog-ng with a defined python-parser, it needs access to
python libraries.

For details about python-parser, see
https://www.syslog-ng.com/community/b/blog/posts/format-your-log-messages-in-python

References: https://github.com/balabit/syslog-ng/issues/2625
2019-04-05 19:16:46 +02:00
Christian Boltz
1e4dcbeb23 Merge branch 'cboltz-complex-profile-name' into 'master'
Add some tests for complex profile names

See merge request apparmor/apparmor!360

Acked-by: Eric Chiang <ericchiang@google.com>
2019-04-03 20:35:53 +00:00
Christian Boltz
9feebc4363 Add some tests for complex profile names
Add some tests with the complex profile name (including alternations and
wildcards) to ensure we don't break such cases in the future.

These tests are based on the log from the (invalid) bugreport
https://gitlab.com/apparmor/apparmor/issues/26
2019-03-31 17:34:55 +02:00
John Johansen
2b091491b0 Merge branch 'identd' into 'master'
identd: Add network netlink dgram

identd requires access to network netlink dgram.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/353
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-29 08:04:40 +00:00
John Johansen
52b3fc220e Adjust tests to match base abstraction update.
Since !345 the set of permissions that are granted (get_file_perms_2)
or suggested (propose_file_rules) has changed. These new sets are
expected due to the changes brought by this MR, so let's adjust
the test suite accordingly.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/358
Acked-by: Christian Boltz <apparmor@cboltz.de>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-29 07:56:23 +00:00
intrigeri
0170e98f9c Adjust tests to match base abstraction update.
Since !345 the set of permissions that are granted (get_file_perms_2)
or suggested (propose_file_rules) has changed. These new sets are
expected due to the changes brought by this MR, so let's adjust
the test suite accordingly.
2019-03-24 14:45:03 +00:00
John Johansen
9ba051c6ed Merge branch 'base-abstraction-allow-all-libraries' into 'master'
base abstraction: allow mr on *.so* in common library paths.

For example, VirtualBox guests have /usr/lib/VBoxOGL.so.

Without this changes, in a VirtualBox VM with VBoxVGA graphics,
at least one Qt5 application (OnionShare) won't start and display:

  ImportError: libGL.so.1: failed to map segment from shared object

… and the system logs have:

  apparmor="DENIED" operation="file_mmap" profile="/usr/bin/onionshare-gui" name="/usr/lib/VBoxOGL.so" pid=11415 comm="onionshare-gui" requested_mask="m" denied_mask="m" fsuid=1000 ouid=0

While this works fine with VBoxSVGA and VMSVGA when 3D acceleration is enabled.

So let's not assume all libraries have a name that starts with "lib".

Bug-Tails: https://redmine.tails.boum.org/code/issues/16414

Candidate for master and 2.13.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/345
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-24 07:04:14 +00:00
intrigeri
5cbb7df95e base abstraction: allow mr on *.so* in common library paths.
For example, VirtualBox guests have /usr/lib/VBoxOGL.so.

Without this changes, in a VirtualBox VM with VBoxVGA graphics,
at least one Qt5 application (OnionShare) won't start and display:

  ImportError: libGL.so.1: failed to map segment from shared object

… and the system logs have:

  apparmor="DENIED" operation="file_mmap" profile="/usr/bin/onionshare-gui" name="/usr/lib/VBoxOGL.so" pid=11415 comm="onionshare-gui" requested_mask="m" denied_mask="m" fsuid=1000 ouid=0

While this works fine with VBoxSVGA and VMSVGA when 3D acceleration is enabled.

So let's not assume all libraries have a name that starts with "lib".
2019-03-24 06:06:42 +00:00
John Johansen
5014f4a99c dovecot: master SIGTERM child that are slow to die
When doing a service reload, I noticed the following:

```Mar 22 15:52:27 smtp dovecot: master: Warning: SIGHUP received - reloading configuration
Mar 22 15:52:27 smtp dovecot: imap(simon): Server shutting down. in=35309 out=232805
Mar 22 15:52:27 smtp dovecot: imap(simon): Server shutting down. in=24600 out=1688166
Mar 22 15:52:27 smtp dovecot: imap(simon): Server shutting down. in=14026 out=95516
Mar 22 15:52:27 smtp dovecot: imap(simon): Server shutting down. in=13776 out=141513
Mar 22 15:52:33 smtp dovecot: master: Warning: Processes aren't dying after reload, sending SIGTERM.
Mar 22 15:52:33 smtp dovecot: master: Error: service(imap): kill(5806, 15) failed: Permission denied
Mar 22 15:52:33 smtp dovecot: master: Error: service(imap-login): kill(5804, 15) failed: Permission denied
Mar 22 15:52:33 smtp dovecot: master: Error: service(config): kill(506, 15) failed: Permission denied
Mar 22 15:52:33 smtp kernel: [65542.184326] audit: type=1400 audit(1553284353.609:82): apparmor="DENIED" operation="signal" profile="dovecot" pid=414 comm="dovecot" requested_mask="send" denied_mask="send" signal=term peer="/usr/lib/dovecot/imap"
Mar 22 15:52:33 smtp kernel: [65542.197596] audit: type=1400 audit(1553284353.625:83): apparmor="DENIED" operation="signal" profile="dovecot" pid=414 comm="dovecot" requested_mask="send" denied_mask="send" signal=term peer="/usr/lib/dovecot/imap-login"
Mar 22 15:52:33 smtp kernel: [65542.197635] audit: type=1400 audit(1553284353.625:84): apparmor="DENIED" operation="signal" profile="dovecot" pid=414 comm="dovecot" requested_mask="send" denied_mask="send" signal=term peer="/usr/lib/dovecot/config"
Mar 22 15:52:36 smtp dovecot: imap(simon): Server shutting down. in=17882 out=104004
```

The server was heavily loaded which is probably why it ended up trying to SIGTERM those.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/357
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-22 23:03:26 +00:00
Simon Deziel
f01fd38ca0 dovecot: master SIGTERM child that are slow to die
Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-03-22 18:33:14 -04:00
John Johansen
cfe20d2b63 Add support for profiles with xattrs matching
Add userland support for matching based on extended file attributes. This
leverages DFA based matching already in the kernel:

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=8e51f908
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=73f488cd

Matching is exposed via flags on the profile:

    /usr/bin/* xattrs=(user.foo=bar user.bar=foo) {
        # ...
    }

xattr values are appended to the existing xmatch via a null transition.

    $ echo '/usr/bin/* xattrs=(user.foo=foo user.bar=bar) {}' | \
        ./parser/apparmor_parser -QT -D expr-tree
    DFA: Expression Tree
    /usr/bin/[^\0000/]([^\0000/])*(\0000bar)?(\0000foo)?< 0x1>
    DFA: Expression Tree
    (\a|(\n|(\0002|\t)))< 0x4>

Tested manually on a 4.19 kernel via QEMU+KVM.

TODO:

  * ~~Add regression tests~~ (EDIT: done)
  * ~~EDIT: add support in the tools~~ (EDIT: done)

Questions for reviewers:

  * ~~parser/libapparmor: regex construction probably needs cleaning up~~ (EDIT: done)
  * ~~parser/parser_regex.c: confused what xmatch length is for~~ (EDIT: done)

/cc @mjg59

PR: https://gitlab.com/apparmor/apparmor/merge_requests/270
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-21 08:12:07 +00:00
John Johansen
9eb738e5f1 Get rid of $MODULE, replace usage with hardcoded "apparmor"
I slightly ;-) doubt we'll change the module name.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/354
Signed-off-by: Christian Boltz <apparmor@cboltz.de>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-21 08:10:12 +00:00
John Johansen
ad7ea230aa parser/libapparmor_re: remove unnecessary throw(int)
Compiling the parser currently prints a deprecation warning. Remove
throw(int) annotations from function signatures. These aren't required
to catch exceptions. This gets us closer to possibly enabling '-Werror'
in the future.

For example, the following program catches the exception without a
throw(int) annotation:

	#include <iostream>
	void throw_an_error()
	{
	        throw 3;
	        return;
	}
	int main ()
	{
	        try
	        {
	                throw_an_error();
	        }
	        catch (int e)
	        {
	                std::cout << "caught exception " << e << '\n';
	        }
	        return 0;
	}

This program prints:

	$ g++ -o error error.cc
	$ ./error
	caught exception 3

PR: https://gitlab.com/apparmor/apparmor/merge_requests/356
Signed-off-by: Eric Chiang <ericchiang@google.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-21 08:07:48 +00:00
Christian Boltz
777a3137e5 Merge branch 'cboltz-shellcheck' into 'master'
Make shellcheck happier

See merge request apparmor/apparmor!355

Acked-by: Eric Chiang <ericchiang@google.com>
2019-03-18 23:31:31 +00:00
Christian Boltz
7b68d820ea Add quotes around several variables
Note that $PARSER_OPTS has to stay without quotes because it can
sometimes be empty, and would (if quoted) be interpreted as empty
filename by apparmor_parser
2019-03-18 19:30:37 +01:00
Christian Boltz
5f46dedd6e replace deprecated egrep with grep -e 2019-03-18 19:17:16 +01:00
Christian Boltz
6c42cd9eae skip_profile: make tests posix-compatible
[ foo -o bar ] isn't supported everywhere, replace it with
[ foo ] || [ bar ]
2019-03-18 19:05:47 +01:00
Eric Chiang
48dcbb9dcb parser/libapparmor_re: remove unnecessary throw(int)
Compiling the parser currently prints a deprecation warning. Remove
throw(int) annotations from function signatures. These aren't required
to catch exceptions.

For example, the following program catches the exception without a
throw(int) annotation:

	#include <iostream>
	void throw_an_error()
	{
	        throw 3;
	        return;
	}
	int main ()
	{
	        try
	        {
	                throw_an_error();
	        }
	        catch (int e)
	        {
	                std::cout << "caught exception " << e << '\n';
	        }
	        return 0;
	}

This program prints:

	$ g++ -o error error.cc
	$ ./error
	caught exception 3

Signed-off-by: Eric Chiang <ericchiang@google.com>
2019-03-18 10:57:05 -07:00
Christian Boltz
e20e49c130 Get rid of $MODULE, replace usage with hardcoded "apparmor"
I slightly ;-) doubt we'll change the module name.
2019-03-18 18:53:42 +01:00
Christian Boltz
75dc438823 Merge branch 'cboltz-deprecate-kill' into 'master'
drop most of apparmor_kill()

See merge request apparmor/apparmor!351

Acked-by: Eric Chiang <ericchiang@google.com>
2019-03-18 17:49:59 +00:00
Christian Boltz
c9148a304c Merge branch 'cboltz-subshell' into 'master'
remove_profiles(): Fix returning $retval

See merge request apparmor/apparmor!352

Acked-by: Eric Chiang <ericchiang@google.com> for 2.11..master
2019-03-18 17:45:53 +00:00
Goldwyn Rodrigues
1d75abba3f identd: Add network netlink dgram
identd requires access to network netlink dgram.
2019-03-18 11:15:49 -05:00
Christian Boltz
dc010bc034 Merge branch 'cboltz-utils-keywords' into 'master'
update network keyword list in utils and add test

See merge request apparmor/apparmor!350

Acked-by: Eric Chiang <ericchiang@google.com> for 2.12..master
2019-03-18 16:02:20 +00:00
Christian Boltz
49849ed7a3 update network keyword list in utils and add test
The tools also have a list of network keywords, update it:
- add xdp and qipcrtr
- move ib and mpls to match the kernel order

Also add a test to ensure that (at least) the keywords provided by the
running kernel are listed in network_domain_keywords.
2019-03-16 12:52:37 +01:00
Christian Boltz
be02f008c3 remove_profiles(): Fix returning $retval
Extend the subshell so that the actual (possibly non-zero) value of
$retval gets returned. Before, the changed value was lost at "done"
(= leaving the subshell), and the initial $retval=0 was returned.

(found with shellcheck)
2019-03-15 23:12:17 +01:00
Christian Boltz
0e3d6ee43a drop most of apparmor_kill()
AppArmor can't be built as a kernel module since years, which also means
it's impossible to unload it.
2019-03-15 22:55:51 +01:00
Christian Boltz
6416ccebf6 Merge branch 'cboltz-network-keywords' into 'master'
apparmor.d manpage: update list of network domain keywords

See merge request apparmor/apparmor!349

Acked-by: Eric Chiang <ericchiang@google.com> for 2.12..master
2019-03-14 21:20:02 +00:00
Christian Boltz
6b2765637e apparmor.d manpage: update list of network domain keywords
- add 'qipcrtr' and 'xdp'
- sort other keywords to the order in apparmor.vim
2019-03-14 21:54:30 +01:00
Eric Chiang
02da244316 parser: add a man page for xattrs
Signed-off-by: Eric Chiang <ericchiang@google.com>
2019-03-14 10:47:54 -07:00
Eric Chiang
6e29ba9a7a tests/regression/apparmor: add regression tests for xattrs matching
Signed-off-by: Eric Chiang <ericchiang@google.com>
2019-03-14 10:47:54 -07:00
Eric Chiang
a42fd8c6f4 parser: add support for matching based on extended file attributes
Add userland support for matching based on extended file attributes.
This leverages DFA based matching already in the kernel:

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=8e51f908
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=73f488cd

Matching is exposed via flags on the profile:

  /usr/bin/* xattrs=(user.foo=bar user.bar=**) {
      # ...
  }

Profiles list the set of extended attributes that a file MUST have, and
a regex to match the value of that extended attributes. Additional
extended attributes on the file don't effect the match.

Signed-off-by: Eric Chiang <ericchiang@google.com>
2019-03-14 10:47:54 -07:00
John Johansen
6804731892 Policy cache fixes
Fix the `aa_policy_cache.sh` regression test to work correctly with the new(ish) multicache support in `libapparmor`. Then a couple subtle bugs that were uncovered by the fixed test.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/348
Acked-by: John Johansen <john.johansen@canoical.com>
2019-03-13 06:17:37 +00:00
Tyler Hicks
e28ffcdf7d libapparmor: Get rid of unnecessary variable
Remove the k variable since it really isn't necessary here.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2019-03-13 02:46:09 +00:00
Tyler Hicks
d7ac07afc4 libapparmor: Fix variable name overlap in merge() macro
The calling function and the merge() macro both make use of a variable
named "i" but this causes problems when merging. The aa_policy_cache.sh
test script experiences "bad file descriptor" failures due to the merged
list containing invalid fd values (-1).

Fix this by renaming merge()'s index variables from i and j to y and z
to hopefully prevent future overlap. The better fix here would be to
convert merge() to a function but that's a more intrusive change and I
don't have an easy way to test the overlay feature.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2019-03-13 02:46:00 +00:00
Tyler Hicks
8b21871820 libapparmor: Fix segfault when loading policy cache files
qsort()'s _size_ parameter is used to indicate the size of the elements
in the _base_ array parameter. Adjust the third argument to qsort() to
indicate that we're dealing with an array of struct dirent pointers
rather than an array of struct dirent.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2019-03-13 02:39:55 +00:00
Tyler Hicks
f31457b26e tests: Teach aa_policy_cache.sh about the cache location and subdirs
Adjust aa_policy_cache.sh to handle the additional layer in the
directory hierarchy when determining where the policy cache binaries are
stored. This is needed due to the multicache changes that allow multiple
policy caches to exist on a single system.

Differentiate between the cache location (the top level directory
containing all caches) and the cache directory (the directory used to
store the cached policies).

Use the libapparmor wrapper to get the cache directory for the given
cache location and the features of the currently running kernel.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2019-03-13 02:39:54 +00:00
Tyler Hicks
ad81ea0e67 tests: Add option to dump policy cache dir with the libapparmor wrapper
Print the policy cache directory path for the features of the currently
running kernel to stdout so that the aa_policy_cache.sh regression test
script can make use of it when writing out binary policy files.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2019-03-13 02:23:35 +00:00
John Johansen
abbca9435f library: fix segfault in overlaydirat_for_each
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Tyler Hicks <tyler.hicks@canonical.com>
2019-03-12 16:17:35 -07:00
John Johansen
2c4386a0d1 Merge branch 'xmatch_regex_priority' into 'master'
parser: determine xmatch priority based on smallest DFA match

The length of a xmatch is used to prioritize multiple profiles that
match the same path, with the intent that the more specific match wins.
Currently, the length of a xmatch is computed by the position of the
first regex character.

While trying to work around issues with no_new_privs by combining
profiles, we noticed that the xmatch length computation doesn't work as
expected for multiple regexs. Consider the following two profiles:

    profile all /** { }
    profile bins /{,usr/,usr/local/}bin/** { }

xmatch_len is currently computed as "1" for both profiles, even though
"bins" is clearly more specific.

When determining the length of a regex, compute the smallest possible
match and use that for xmatch priority instead of the position of the
first regex character.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/326
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-12 11:23:30 +00:00
John Johansen
a122764ddf dovecot: align {pop3,managesieve}-login to imap-login
Those 3 login daemons should have similiar needs and thus similar profiles. IMAP is likely the most tested one so let's align the other 2 with it. Unix and TCP sockets rules were added to pop3-login after the removal of abstractions/nameservice that included them implicitly.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/338
Signed-off-by: Simon Deziel [simon@sdeziel.info](mailto:simon@sdeziel.info)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-11 22:58:55 +00:00
John Johansen
6eea2bcd0d Merge branch 'desktop-abstractions' into 'master'
abstractions/qt5: read user configuration

See merge request apparmor/apparmor!335
2019-03-11 22:53:07 +00:00
Cameron Nemo
6d81563267 abstractions/qt5: read user configuration
Signed-off-by: Cameron Nemo <camerontnorman@gmail.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-11 15:50:45 -07:00
Christian Boltz
175a78c55a Merge branch 'profile-updates' into 'master'
profiles/gnome: add @{HOME}/.cache/gtk-3.0

Found this path is used by gtk_compose_hash_get_cache_path() in
gtkcomposetable.c.

See merge request apparmor/apparmor!342

Acked-by: Jamie Strandboge <jamie@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-03-07 18:59:22 +00:00
Christian Boltz
62d6ae22b8 Merge branch 'cboltz-assert-equals' into 'master'
Replace deprecated assertEquals with assertEqual

assertEquals is deprecated since Python 2.7 and 3.2.

See merge request apparmor/apparmor!347

Acked-by: Eric Chiang <ericchiang@google.com>
2019-02-26 20:50:51 +00:00
Christian Boltz
62abfe38e8 Replace deprecated assertEquals with assertEqual
assertEquals is deprecated since Python 2.7 and 3.2.
2019-02-26 21:27:00 +01:00
intrigeri
2ed3763a2f Merge branch 'bug1816470' into 'master'
tunables/share: fix buggy syntax that broke the ~/.local/share part of the @{user_share_dirs} tunable

See merge request apparmor/apparmor!344
2019-02-25 06:49:23 +00:00
intrigeri
cdeb618518 tunables/share: fix buggy syntax that broke the ~/.local/share part of the @{user_share_dirs} tunable
Fixes regression introduced in a91d199ab1.

Bug: https://bugs.launchpad.net/apparmor/+bug/1816470
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=920833, https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=921888
2019-02-24 15:20:17 +00:00
John Johansen
14f177e53a parser: update indentation of work_spawn() macro
Update the indetation of work_spawn to correct for the changes made in
cb43e57d27 ("parser: Fix parser failing to handle errors when setting up work")

the indetation was not updated in that patch to make the changes made
easier to review and see in diffs.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-02-22 02:28:43 -08:00
John Johansen
1259319508 parser: Fix parser failing to handle errors when setting up work
The parser is not correctly handling some error conditions when
dealing with work units. Failure to spawn work, access files, etc
should be returned where appropriate, and be able to abort processing
if abort_on_error is set.

In addition some errors are leading to a direct exit without checking
for abort_on_error.

BugLink: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=921866
BugLink: http://bugs.launchpad.net/bugs/1815294

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Eric Chiang <ericchiang@google.com>
2019-02-22 02:28:30 -08:00
Jörg Sommer
6da7ed2a78 profiles/gnome: add @{HOME}/.cache/gtk-3.0
Found this path is used by gtk_compose_hash_get_cache_path() in
gtkcomposetable.c.
2019-02-20 00:35:06 +01:00
Simon Deziel
e3fd962e36 dovecot: restrict access by owner to the dovecot/config socket
Being able to read the config means accessing ssl_key data so
should only be restricted to root https://wiki.dovecot.org/Services#config

Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-02-18 09:53:39 -05:00
Simon Deziel
bc36daa264 dovecot: align {pop3,managesieve}-login to imap-login
Those 3 login daemons should have similiar needs and thus similar
profiles. IMAP is likely the most tested one so let's align the
other 2 with it. Unix and TCP sockets rules were added to pop3-login
after the removal of abstractions/nameservice that included them
implicitly.

Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-02-17 17:33:24 -05:00
Christian Boltz
5e5b02b722 Merge branch 'dovecot-ssl' into 'master'
dovecot: remove SSL access to {imap,managesieve,pop3}-login

See merge request apparmor/apparmor!337

Acked-by: Christian Boltz <apparmor@cboltz.de> (master only)
2019-02-17 21:07:44 +00:00
Christian Boltz
e68beb988a Merge branch 'dovecot-fixes-no-doveadm' into 'master'
misc dovecot fixes (take #2)

See merge request apparmor/apparmor!336

Acked-by: Christian Boltz <apparmor@cboltz.de> for master..2.10
2019-02-17 21:04:27 +00:00
Simon Deziel
f509fa1675 dovecot: add OpenSSL access to {imap,managesieve,pop3}-login
Based on feedback from Christian Boltz

Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-02-17 15:55:32 -05:00
Simon Deziel
702411170d dovecot: remove SSL access to {imap,managesieve,pop3}-login
The certificates and keys are read by dovecot and
dovecot/config only.

Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-02-17 15:43:58 -05:00
Cameron Nemo
1b57591175 abstractions/qt5: read user configuration 2019-02-17 00:07:45 -08:00
Jörg Sommer
0e0663e99e parser: Fix parsing of arrow “px -> …”
The parser failed to read the profile name after the the arrow. Rules with
`-> foo-bar;` failed with “Found unexpected character: '-'”. Rules with
`-> @{tgt};` compiled fine, but failed at runtime with “profile transition
not found”.

The patch was written by sbeattie and published on
https://paste.ubuntu.com/p/tzxxmVwGJ8/

https://matrix.to/#/!pNJIrowvqsuGgjXsEY:matrix.org/$15477566201815716pmube:matrix.org?via=matrix.org&via=alea.gnuu.de
2019-02-16 10:18:54 +01:00
Simon Deziel
6a7c49b149 dovecot: add abstractions/ssl_certs to lmtp
It already has abstractions/ssl_keys

Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-02-14 21:01:23 -05:00
Simon Deziel
17db8f3884 dovecot: auth processes need to read from postfix auth socket
They also need rw on the auth-userdb socket

Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-02-13 22:50:14 -05:00
Simon Deziel
9afeb22548 dovecot: let dovecot/anvil rw the auth-penalty socket
Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-02-13 22:33:44 -05:00
Simon Deziel
d0aa863f6b dovecot: allow chroot'ing the auth processes
When using passdb/userdb not requiring root (!= /etc/shadow access)
it is recommended to run the auth processes as non root and chroot'ed

Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-02-13 22:27:08 -05:00
Christian Boltz
f729391deb Merge branch 'cboltz-test-setup_aa' into 'master'
add an example for setup_aa() to test-example.py

See merge request apparmor/apparmor!330

Acked-by: Steve Beattie <steve@nxnw.org>
2019-02-13 22:42:19 +00:00
Steve Beattie
b4ab8476e4 usr merge fixups
Debian and Ubuntu have releases coming out with usr-merge in place. For these systems, /bin and /sbin are symlinks to their respective /usr directories. This breaks a few tests in the python utils and in the regression tests. This patch series fixes them, mostly by performing realpath() calls when necessary. For the ptrace regression test, it copies the called /bin/true binary into the created temporary directory and executes it from there. (Good for other reasons, too.)

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>

These patches should be safe to backport to the supported releases (but I have not attempted that, yet).

See merge request apparmor/apparmor!331
2019-02-13 16:57:52 +00:00
Steve Beattie
8c09b32828 ptrace regression tests: fix usr-merge failures
In a usr-merge ubuntu/debian environment /bin is a symlink to
/usr/bin, which causes invalid apparmor policy to be generated for
/bin/true. Instead, copy /bin/true to the per test temporary directory
and execute it from there.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-02-12 23:17:59 -08:00
Steve Beattie
eb31fcf9c5 regression tests: use realpath when generating inierpreter profile
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-02-12 23:17:59 -08:00
Steve Beattie
45c26214cc utils: fixup test-aa.py tests that fail due to usr-merge
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-02-12 23:17:59 -08:00
Simon Deziel
a57f01d86b dovecot: allow FD passing between dovecot and dovecot's anvil 2019-02-10 21:36:10 -05:00
Christian Boltz
d6bc00b35b add an example for setup_aa() to test-example.py
(commented out, but having it documented is helpful nevertheless)
2019-02-10 23:24:29 +01:00
Christian Boltz
f2c0a11327 Merge branch 'update-vulkan' into 'master'
vulkan: allow reading /etc/vulkan/icd.d/

See merge request apparmor/apparmor!329

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.12..master
2019-02-10 13:40:53 +00:00
Vincas Dargis
e322c02c37 vulkan: allow reading /etc/vulkan/icd.d/
Recent Vulkan upgrades introduces new denies:

```
type=AVC msg=audit(1549749243.284:4250): apparmor="DENIED"
operation="open" profile="/usr/bin/vkcube" name="/etc/vulkan/icd.d/"
pid=16472 comm="vkcube" requested_mask="r" denied_mask="r" fsuid=1000
ouid=0
```

```
type=AVC msg=audit(1549800398.470:2612): apparmor="DENIED"
operation="open" profile="/usr/bin/vkcube"
name="/etc/vulkan/icd.d/test.j
son" pid=12230 comm="vkcube" requested_mask="r" denied_mask="r"
fsuid=1000 ouid=0
```

Update `vulkan` abstraction to allow reading new configuration directory.
2019-02-10 14:07:17 +02:00
Christian Boltz
a40dc49530 Merge branch 'feature/aa-notify-test' into 'master'
Add tests for aa-notify

See merge request apparmor/apparmor!324

Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-02-09 20:15:22 +00:00
Otto Kekäläinen
aaf7d0a27a Skip aa-notify tests if their requirements for running are missing
When run locally on a development machine or in production, the full test
is likely to run. However inside a CI system container 'last' might fail
to show last login or there might not be access to kern.log and the test
will automatically skip those without failing the whole test suite.
2019-02-09 13:50:02 +02:00
Otto Kekäläinen
f05a464369 Add tests for aa-notify
This will help ensure the future rewrite of aa-notify from Perl to Python
is less likely to introduce regressions. Tests run the command line utility
via a subprocess so it does not matter that the tests are in Python but
the aa-notify utility is in Perl (for now).
2019-02-09 13:12:01 +02:00
Eric Chiang
cc09794fbd parser: determine xmatch priority based on smallest DFA match
The length of a xmatch is used to prioritize multiple profiles that
match the same path, with the intent that the more specific match wins.
Currently, the length of a xmatch is computed by the position of the
first regex character.

While trying to work around issues with no_new_privs by combining
profiles, we noticed that the xmatch length computation doesn't work as
expected for multiple regexs. Consider the following two profiles:

    profile all /** { }
    profile bins /{,usr/,usr/local/}bin/** { }

xmatch_len is currently computed as "1" for both profiles, even though
"bins" is clearly more specific.

When determining the length of a regex, compute the smallest possible
match and use that for xmatch priority instead of the position of the
first regex character.
2019-02-08 13:51:02 -08:00
Christian Boltz
3b4d1ed0e4 Merge branch 'feature/debuglogger-stdout' into 'master'
Extend common DebugLogger with option to log to stderr

See merge request apparmor/apparmor!325

Acked-by: Eric Chiang <ericchiang@google.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-02-07 18:26:19 +00:00
Otto Kekäläinen
c04a0cadef Extend common DebugLogger with option to log to stderr
This makes it possible for e.g. command line tools to have the --debug
option and when invoked print the existing debug messages directly to
stderr so the user running the command can see them.
2019-02-07 01:05:32 +02:00
Christian Boltz
365bb375d5 Merge branch 'fix-kdeglobals' into 'master'
kde: fix global settings access for Kubuntu and openSUSE

See merge request apparmor/apparmor!322

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.12..master
2019-02-05 17:23:05 +00:00
Vincas Dargis
0f30a59021 kde: fix global settings access for Kubuntu and openSUSE
On Kubuntu, these denies are being produced:
```
type=AVC msg=audit(1549301888.419:91): apparmor="DENIED" operation="open"
profile="qtox"
name="/usr/share/kubuntu-default-settings/kf5-settings/kdeglobals" pid=1603
comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

type=AVC msg=audit(1549301964.008:126): apparmor="DENIED" operation="open"
profile="qtox" name="/usr/share/kubuntu-default-settings/kf5-settings/breezerc"
pid=1822 comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

type=AVC msg=audit(1549302031.194:155): apparmor="DENIED" operation="open"
profile="qtox"
name="/usr/share/kubuntu-default-settings/kf5-settings/baloofilerc" pid=1899
comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
```

Meanwhile, on openSUSE:
```
type=AVC msg=audit(1549302286.921:205): apparmor="DENIED" operation="open" profile="qtox" name="/etc/xdg/kdeglobals" pid=12781 comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
```

Add read only rules for allowing access to global KDE settings.
2019-02-05 18:46:39 +02:00
Christian Boltz
a18d03767e Merge branch 'feature/aa-decode-with-python' into 'master'
Rewrite aa-decode to use inline Python as Perl is to be deprecated

See merge request apparmor/apparmor!321

Acked-by: Eric Chiang <ericchiang@google.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-02-05 12:17:07 +00:00
Otto Kekäläinen
707ef17923 Rewrite aa-decode to use inline Python instead of to-be-deprecated Perl 2019-02-05 00:20:47 +02:00
Otto Kekäläinen
a3ae271d1e Bugfix aa-decode test: Get stderr correctly, don't ignore stderr contents
Defining 'stderr = subprocess.STDOUT' as a default value for function
did not work and the 'stderr' was always empty, thus also 'outerr' was
always empty and not standard error contents was ever considered in any
way.

Best in fact was to remove excess function arguments as they were not even
used and replace it with a simpler and less error prone structure.

Even after reading 'stderr' correctly it did not help much as all tests
used 'assertIn' which ignored excess output. Better replace the normal
output with the error output if there ever was something, since stderr
is most likely a serious thing and tests should stop on it.
2019-02-05 00:15:13 +02:00
Christian Boltz
544bed4b98 Merge branch 'feature/json-mode-documentation' into 'master'
Clean up and document AppArmor UI module

See merge request apparmor/apparmor!323

Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-02-04 20:54:46 +00:00
Otto Kekäläinen
eb378f46d5 Clean up and document AppArmor UI module
- Add documentation stub for what the UI module is and how JSON works
- Make indentation consistent
- Use pythonic 'if' clauses
- Add two spaces after function definitions (Python style)
2019-02-04 20:14:58 +02:00
John Johansen
d1634b8fb0 audio abstraction: grant read access to Alsa and libao config files
Fixes https://bugs.debian.org/920669 and https://bugs.debian.org/920670.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/320

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-01-31 11:27:45 +00:00
intrigeri
16c4713363 audio abstraction: grant read access to the libao configuration files.
Bug-Debian: https://bugs.debian.org/920670

Relevant documentation: https://xiph.org/ao/doc/config.html
2019-01-31 09:29:24 +00:00
intrigeri
2d72795f65 audio abstraction: grant read access to the system-wide asound.conf.
Bug-Debian: https://bugs.debian.org/920669

Relevant documentation: http://www.alsa-project.org/main/index.php/Asoundrc

We already grant read access to the corresponding per-user configuration file
(~/.asoundrc) so it makes sense to also grant access to the system-wide one.
2019-01-31 09:27:10 +00:00
Christian Boltz
fb256feb29 Merge branch 'cboltz/apparmor-cboltz-check-abstractions-d'
See https://gitlab.com/apparmor/apparmor/merge_requests/318

Acked-by: John Johansen <john.johansen@canonical.com>
2019-01-29 13:57:46 +01:00
Christian Boltz
85c01a56e6 add test to ensure abstractions have '#include if exists <*.d>'
Exceptions are
- ubuntu-browsers (because we already have ubuntu-browsers.d with
  different usage)
- ubuntu-helpers (which includes the sanitized_helper subprofile, so
  adding something in the global area wouldn't make much sense)

Also adjust abstractions/postfix-common to use the style all
abstractions use.
2019-01-27 20:41:28 +01:00
intrigeri
a5e74c3be3 Merge branch 'move-drircd' into 'master'
Move drirc.d access to dri-common abstraction

See merge request apparmor/apparmor!314
2019-01-27 16:37:22 +00:00
Vincas Dargis
2d8d2f06d5 Move drirc.d access to dri-common abstraction
Commit b5be596460 added ability to read
/usr/share/drirc.d/ directory to mesa abstraction.

This seems to be a mistake, as it was noted that not all GUI
applications, that need access to drirc.d, also need whole mesa-related
rules (including writing caches).

Move /usr/share/drirc.d/ access to different abstraction. This is not a
breaking change, because any GUI application will have included X
abstraction already, and in the end result - dri-common abstraction too.
2019-01-27 17:40:04 +02:00
John Johansen
b97587ec65 Make rc.apparmor.functions suitable for Debian and Ubuntu
Debian and Ubuntu currently don't use rc.apparmor.functions. They have their own code for loading profiles, their own initscript and systemd unit.

As discussed initially on https://bugs.debian.org/870697 and https://salsa.debian.org/apparmor-team/apparmor/merge_requests/6#note_29153, to fix that without introducing regressions on Debian/Ubuntu, we need to upstream a number of changes, which is what this branch is about.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/252
Acked-by: Christian Boltz <apparmor@cboltz.de>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-01-24 20:29:20 +00:00
John Johansen
330bd6c5f6 abstractions: fix merge conflict resoltion typo
Fix typo introduced when resolving a merge conflict for d9ab83281b
("Add support for local additions to abstractions")

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-01-24 04:34:03 -08:00
Matthew Garrett
d9ab83281b Add support for local additions to abstractions
Local policy may want to extend or override abstractions, so add support for including local updates to them.

Acked-by: Christian Boltz <apparmor@cboltz.de>
Acked-by: intrigeri <intrigeri@boum.org>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-01-24 03:06:03 -08:00
Marius Tomaschewski
b0bacba9db abstractions/nameservice: allow /run/netconfig/resolv.conf
Latest netconfig in openSUSE writes /run/netconfig/resolv.conf, and only
has a symlink to it in /etc

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1097370
Acked-by: Christian Boltz <apparmor@cboltz.de>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-01-24 02:43:02 -08:00
Eric Chiang
2609f356cb parser: fix warnings about unused functions
Signed-off-by: Eric Chiang <ericchiang@google.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-01-24 02:36:42 -08:00
John Johansen
803cb5558f drop failing corner-case check in logparser.py
aa-logprof errors out if it hits a log event for a non-existing profile
while a profile file with the default filename for that non-existing
profile exists. This can for example happen after adding a profile name
to a profile if audit.log still contains events for the attachment-based
profile name.

Since we ignore log events for non-existing profiles in general, drop
the code for the special case "but a file matching the default filename
for that non-existing profile exists" and also silently ignore events
for this very special non-existing profile.

Also drop the now unused function get_profile_filename()

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1120472

PR: https://gitlab.com/apparmor/apparmor/merge_requests/296
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-01-24 10:26:05 +00:00
John Johansen
3a0eea151b update mysqld profile
This updates the mysqld to what I use on my servers nowadays.

Note: my profile also has capability sys_resource,, but I'm not sure why I had to add this and therefore didn't include it in this merge request.

Speaking about "why I had added $whatever" - these changes were collected over the last years and of course ;-) I don't remember any details.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/310
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-01-24 04:25:34 +00:00
Christian Boltz
0199edf8e7 update mysqld profile
This updates the mysqld to what I use on my servers nowadays.
2019-01-24 00:30:34 +01:00
Eric Chiang
087340a97a Merge branch 'parser_make' into 'master'
*: ensure make apparmor_parser is cached

See merge request apparmor/apparmor!307
2019-01-23 15:50:17 +00:00
Eric Chiang
cb8c3377ba *: ensure make apparmor_parser is cached
This change updates parser/Makefile to respect target dependencies and
not rebuild apparmor_parser if nothing's changed. The goal is to allow
cross-compiled tests #17 to run on a target system without the tests
attempting to rebuild the parser.

Two changes were made:

* Generate af_names.h in a script so the script timestamp is compared.
* Use FORCE instead of PHONY for libapparmor_re/libapparmor_re.a

Changes to list_af_names are intended to exactly replicate the old
behavior.

Signed-off-by: Eric Chiang <ericchiang@google.com>
2019-01-22 15:30:51 -08:00
Christian Boltz
5d384d9625 Merge branch 'cboltz-dnsmasq-libvirtd' into 'master'
dnsmasq: allow peer=libvirtd to support named profile

See merge request apparmor/apparmor!304

Acked-by: Eric Chiang <ericchiang@google.com> for 2.12..master
2019-01-22 22:23:59 +00:00
Christian Boltz
91dc2c4c29 Merge branch 'update-mesa' into 'master'
mesa: allow reading drirc.d

See merge request apparmor/apparmor!308

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.12..master
2019-01-19 17:37:07 +00:00
Vincas Dargis
b5be596460 mesa: allow reading drirc.d
Recent Mesa update introduces new denies:

```
type=AVC msg=audit(1547905564.212:523): apparmor="DENIED"
operation="open" profile="supertuxkart" name="/usr/share/drirc.d/"
pid=15740 comm="supertuxkart" requested_mask="r" denied_mask="r"
fsuid=1000 ouid=0
```

```
type=AVC msg=audit(1547905896.307:548): apparmor="DENIED"
operation="open" profile="supertuxkart"
name="/usr/share/drirc.d/00-mesa-defaults.conf" pid=15963 c
omm="supertuxkart" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
```

Add rule to allow reading newly required paths.
2019-01-19 15:55:58 +02:00
Christian Boltz
027dcdb23f Merge branch 'fix-compose-cache' into 'master'
qt5-compose-cache-write: fix anonymous shared memory access

See merge request apparmor/apparmor!301

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.10..master
2019-01-14 20:51:10 +00:00
Christian Boltz
3e3c90152f Merge branch 'fix-qt5-settings' into 'master'
qt5-settings-write: fix anonymous shared memory access

See merge request apparmor/apparmor!302

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.10..master
2019-01-14 20:48:21 +00:00
Vincas Dargis
8f6a8fb194 Refactor qt5-settings-write
Merge symlink rules together with `rw` rules for brevity.
2019-01-14 19:23:49 +02:00
Christian Boltz
20fe099ced dnsmasq: allow peer=libvirtd to support named profile
The /usr/sbin/libvirtd profile will get a profile name ("libvirtd").

This patch adjusts the dnsmasq profile to support the named profile in
addition to the "old" path-based profile name.

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1118952#c3
2019-01-13 17:38:09 +01:00
Christian Boltz
808218d8ee Merge branch 'fix-alsa' into 'master'
audio: Fix alsa settings access

See merge request apparmor/apparmor!303

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.12..master
2019-01-13 16:11:41 +00:00
Vincas Dargis
73f01196bb audio: Fix alsa settings access
OpenAL application on Debian Buster produces deny message:
```
type=AVC msg=audit(1547295526.633:732): apparmor="DENIED"
operation="open" profile="supertuxkart" name="/etc/alsa/conf.d/"
pid=13963 comm="supertuxkart" reque
sted_mask="r" denied_mask="r" fsuid=1000 ouid=0
```

Add file rule to allow reading Alsa configuration files.
2019-01-12 14:23:28 +02:00
Vincas Dargis
f1200873b8 qt5-settings-write: fix anonymous shared memory access
*Add anonymous shared memory access rule for QtSettings.conf file
itself.
* Reduce strictness of anonymous shared memory file names - numbers in
them can be smaller or bigger.
* Fix consistency - require anonymous shared memory file names to end
with digit in all rules.
2019-01-12 12:50:19 +02:00
Vincas Dargis
1250402471 qt5-compose-cache-write: fix anonymous shared memory access
Qt5 applications produces deny message when saving compose cache files:

```
type=AVC msg=audit(1547287756.436:198): apparmor="DENIED"
operation="link" profile="qtox"
name="/home/vincas/.cache/qt_compose_cache_little_endian_4982ae57498642c5997565013f7ffe4e"
pid=2878 comm="qtox" requested_mask="l" denied_mask="l" fsuid=1000
ouid=1000 target="/home/vincas/.cache/#919806"
```

Add file rule to enable writing anonymous shared memory file.
2019-01-12 12:34:22 +02:00
intrigeri
fad38ca93f Merge branch 'make-tunables-share-play-well-with-aliases' into 'master'
Make tunables/share play well with aliases

See merge request apparmor/apparmor!300
2019-01-09 17:49:53 +00:00
intrigeri
a91d199ab1 Make tunables/share play well with aliases.
This reverts commit aa3022208f.

Space-separated list of values don't play well with aliases.
For example, in Tails, despite this alias rule:

  alias / -> /lib/live/mount/rootfs/*.squashfs/,

… the Tor Browser profile denies access to
/lib/live/mount/rootfs/filesystem.squashfs/usr/share/mime/mime.cache, which
should be equivalent to /usr/share/mime/mime.cache. That's fixed by using
alternations instead; too bad they're less readable.

Possibly related:
https://bugs.launchpad.net/apparmor/+bug/888077
https://bugs.launchpad.net/apparmor/+bug/1703692
https://bugs.launchpad.net/apparmor/+bug/1703692
2019-01-07 12:58:56 +00:00
Christian Boltz
a772ee0f8b Merge branch 'EmersonBernier/shellcheck' into 'master'
parser/apparmor.systemd: fix minor issues detected by shellcheck

See merge request apparmor/apparmor!293

Acked-by: Christian Boltz <apparmor@cboltz.de> for master and 2.13
2019-01-03 17:41:56 +00:00
Christian Boltz
1f53de174d Merge branch 'var-lib-dehydrated' into 'master'
abstractions/ssl_{certs,keys}: dehydrated uses /var/lib on Debian

See merge request apparmor/apparmor!299

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.10..master
2019-01-03 17:32:51 +00:00
Simon Deziel
04b2842e1c abstractions/ssl_{certs,keys}: allow reading ocsp.der maintained by dehydrated for OCSP stapling
Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-01-03 08:31:06 -05:00
Simon Deziel
c5a89d5daf abstractions/ssl_{certs,keys}: sort the alternation for dehydrated and drop the "-" from the filenames
Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-01-03 08:29:21 -05:00
Simon Deziel
1306f9a64d abstractions/ssl_{certs,keys}: dehydrated uses /var/lib on Debian
Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-01-02 19:33:19 -05:00
Christian Boltz
ed692337a5 Drop get_profile_filename() from logparser.py
This function is unused since the last commit.
2019-01-02 20:42:57 +01:00
Christian Boltz
03ea5b82b7 drop failing corner-case check in logparser.py
aa-logprof errors out if it hits a log event for a non-existing profile
while a profile file with the default filename for that non-existing
profile exists. This can for example happen after adding a profile name
to a profile if audit.log still contains events for the attachment-based
profile name.

Since we ignore log events for non-existing profiles in general, drop
the code for the special case "but a file matching the default filename
for that non-existing profile exists" and also silently ignore events
for this very special non-existing profile.

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1120472
2019-01-02 20:30:54 +01:00
intrigeri
775835db64 Fix is_apparmor_present() regression which breaks the Debian initscript.
Commit 0d5ab43d59 removed support for loading
modules and introduced a caller, in apparmor_start(), that passes no argument to
is_apparmor_present(), which breaks that function when /bin/sh → /bin/dash.

Passing a module name as argument does not make sense since we dropped support
for the long obsolete "subdomain" module, so let's simplify
is_apparmor_present() and adjust its callers accordingly.

Bug-Debian: https://bugs.debian.org/917874
2019-01-01 17:55:48 +00:00
intrigeri
1bd401bb35 Stop looking for apparmor.conf.
As per the discussion that starts at
https://gitlab.com/apparmor/apparmor/merge_requests/252#note_125983293,
apparmor.conf was never documented nor explicitly supported.
It's not really clear what problem it was meant to solve.
2018-12-28 16:34:17 +00:00
intrigeri
93f0c2d9ca Don't call the obsolete configure_owlsm function.
It was removed in commit 94ff870f.
2018-12-28 16:27:58 +00:00
intrigeri
3b997c79b4 Don't try to list files in a non-existent directory.
Thanks to Jamie Strandboge for spotting this during review.
2018-12-27 17:54:11 +00:00
intrigeri
10ba242b89 Make control flow clearer.
Let's add a safety net if we ever add another return code to skip_profile.
2018-12-27 17:46:43 +00:00
Emerson Bernier
b3937d19a4 parser/apparmor.systemd: fix minor issues detected by shellcheck 2018-12-21 19:50:10 +01:00
John Johansen
e0ed9c2cae Merge branch 'EmersonBernier/socket_read-only' into 'master'
profiles/apparmor.d/abstractions/X: make x11 socket read-only

Write access isn't needed for connecting to x11 socket. Also clear some duplicate and redundant rules in other abstractions.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/281

Acked-by: John Johansen <john.johansen@canonical.com>
2018-12-21 11:44:04 +00:00
Jamie Strandboge
ec7d8ba11e Merge branch 'fix-dhclient-dhcpd-lease-on-ipv6' into 'master'
Fix dhclient dhcpd lease on IPv6

See merge request apparmor/apparmor!291
2018-12-18 14:22:39 +00:00
Petr Vorel
55dc6b3e57 dhcpd: Support correct path for lease file on IPv6
/var/lib/dhcp/dhcpd6.leases path for lease file on IPv6 has been in
dhcp repository since 2008, now visible in commit 8dea7ba7 ("Add DHCPv6
files in configure").

Signed-off-by: Petr Vorel <pvorel@suse.cz>
2018-12-18 01:38:55 +01:00
Petr Vorel
bca66f5064 dhclient: Add path for Fedora/RHEL/CentOS/Oracle Linux
These distros use non-standard paths [1] since dhcp 4.0 in 2008
(commits in fedora pkg: 82186fd and c3b67cd)

[1] https://src.fedoraproject.org/cgit/rpms/dhcp.git/tree/dhcp.spec#n389

Signed-off-by: Petr Vorel <pvorel@suse.cz>
2018-12-18 01:38:43 +01:00
Petr Vorel
ce6c3c3505 dhclient: Support correct path for lease file on IPv6
/var/lib/dhcp/dhclient6.leases path for lease file on IPv6 has been in
dhcp repository since 2008, now visible in commit 8dea7ba7 ("Add DHCPv6
files in configure").
Adding it via extending dhclient-*.leases pattern.

Not sure whether /var/lib/dhcp6/dhclient.leases was ever used on Linux,
but keep in for backward compatibility.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
2018-12-18 00:45:54 +01:00
Eric Chiang
ccb1b01da7 Merge branch 'cboltz-xattr-cleanprof' into 'master'
Add a test profile with xattrs=... to cleanprof tests

See merge request apparmor/apparmor!289
2018-12-17 18:31:40 +00:00
intrigeri
5865d01449 Remove dead code.
Since 04eb2fe3, __parse_profiles_dir can only return 0 or 1, so $STATUS can only
be 0 or 1, so trying to reset this variable to 0 when its value is 2 can only
cause confusion.
2018-12-16 21:05:06 +00:00
intrigeri
45bc0b8eb7 Merge remote-tracking branch 'origin/master' into prepare-rc.apparmor.functions-for-Debian-and-Ubuntu 2018-12-16 20:36:53 +00:00
Christian Boltz
274132ee6c Add a test profile with xattrs=... to cleanprof tests 2018-12-09 20:54:41 +01:00
Emerson Bernier
c7b8368216 profiles/apparmor.d/abstractions/X: make x11 socket read-only
Write access isn't needed for connecting to x11 socket. Also
clear some duplicate and redundant rules in other abstractions.
2018-12-08 13:52:03 +01:00
John Johansen
718744b122 Merge branch 'cboltz-re_flags' into 'master'
Split out RE_FLAGS

... instead of having it duplicated in RE_PROFILE_HAT_DEF and RE_PROFILE_START.

Note that the flags=... handling in RE_PROFILE_HAT_DEF was more/too
strict (for example it didn't allow whitespace around the "="), so this
change also qualifies as a little bugfix.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/287
Acked-by: John Johansen <john.johansen@canonical.com>
2018-12-08 08:37:18 +00:00
John Johansen
bf58767724 Merge branch 'cboltz-dovecot-dumpable' into 'master'
dovecot: allow reading /proc/sys/fs/suid_dumpable

This is needed if a dovecot child process segfaults - in this case, dovecot provides a helpful error message like

dovecot[6179]: auth-worker: Fatal: master: service(auth-worker): child 8103 killed with signal 11 (core not dumped - https://dovecot.or /bugreport.html#coredumps - set /proc/sys/fs/suid_dumpable to 2)

which involves reading the current value in suid_dumpable.

I propose this fix for 2.10..master.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/286
Acked-by: John Johansen <john.johansen@canonical.com>
2018-12-08 08:31:21 +00:00
John Johansen
dedf977d01 Merge branch 'cboltz-ignore-orig-rej' into 'master'
Ignore *.orig and *.rej files when loading profiles

This was "accidently" reported by Ralph on the opensuse-support
mailinglist.

I propose this for 2.10..master (I verified that 2.10 tools and libapparmor have *.orig and *.rej in the ignore list)

PR: https://gitlab.com/apparmor/apparmor/merge_requests/282
Acked-by: John Johansen <john.johansen@canonical.com>
2018-12-08 08:15:23 +00:00
John Johansen
99d1865462 Merge branch 'couple-more-for-private-files' into 'master'
deny ~/.mutt** in private-files and audit deny ~/.aws in private-files-strict

PR: https://gitlab.com/apparmor/apparmor/merge_requests/276
Acked-by: John Johansen <john.johansen@canonical.com>
2018-12-08 06:57:07 +00:00
John Johansen
8441a42c51 Merge branch 'cboltz-drop-activate_repo_profiles' into 'master'
Drop unused activate_repo_profiles()

PR: https://gitlab.com/apparmor/apparmor/merge_requests/274
Acked-by: John Johansen <john.johansen@canonical.com>
2018-12-08 06:55:49 +00:00
John Johansen
67d7cd0ab0 Merge branch 'cboltz-dnsmasq' into 'master'
dnsmasq profile updates by Petr Vorel

This merge request includes two dnsmasq profiles Petr Vorel sent to the mailinglist:

dnsmasq: Add pid file used by NetworkManager
dnsmasq: Adjust pattern for log files to comply SELinux

I propose these patches for 2.11..master.

I'm not against also backporting to 2.10, but the profile in 2.10 doesn't allow to write anything in /var/log/, so either we apply/backport the changes manually, or we rely on the fact that we didn't get any bugreports for it ;-) Oh, and since I'm only forwarding these patches, I'll already add

Acked-by: Christian Boltz apparmor@cboltz.de for 2.11..master
Acked-by: John Johansen <john.johansen@canonical.com>

PR: https://gitlab.com/apparmor/apparmor/merge_requests/288
2018-12-08 06:24:32 +00:00
Petr Vorel
49848b9081 dnsmasq: Add pid file used by NetworkManager
Signed-off-by: Petr Vorel <pvorel@suse.cz>
2018-12-07 23:42:53 +01:00
Petr Vorel
3ef8df6ac0 dnsmasq: Adjust pattern for log files to comply SELinux
i.e. move '*' from beginning to before suffix.

Commit 025c7dc6 ("dnsmasq: Add permission to open log files") added
pattern, which is not compatible with SELinux. As this pattern has been
in SELinux since 2011 (with recent change to accept '.log' suffix +
logrotate patterns which are not relevant to AppArmor) IMHO it's better
to adjust our profile.

Fixes: 025c7dc6 ("dnsmasq: Add permission to open log files")

Signed-off-by: Petr Vorel <pvorel@suse.cz>
2018-12-07 23:40:19 +01:00
Christian Boltz
0d830fae31 Split out RE_FLAGS
... instead of having it duplicated in RE_PROFILE_HAT_DEF and
RE_PROFILE_START.

Note that the flags=... handling in RE_PROFILE_HAT_DEF was more/too
strict (for example it didn't allow whitespace around the "="), so this
change also qualifies as a little bugfix.
2018-12-06 22:02:01 +01:00
Christian Boltz
2202a8a267 dovecot: allow reading /proc/sys/fs/suid_dumpable
This is needed if a dovecot child process segfaults - in this case,
dovecot provides a helpful error message like

dovecot[6179]: auth-worker: Fatal: master: service(auth-worker): child 8103 killed with signal 11 (core not dumped - https://dovecot.org/bugreport.html#coredumps - set /proc/sys/fs/suid_dumpable to 2)

which involves reading the current value in suid_dumpable.
2018-12-06 18:12:25 +01:00
Christian Boltz
aa1e8bd55d Merge branch 'utils-xattrs' into 'master'
utils: add support to tools for profiles with xattrs

See merge request apparmor/apparmor!285

Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-12-06 13:15:49 +00:00
Eric Chiang
fde015435a utils: add support to tools for profiles with xattrs
Signed-off-by: Eric Chiang <ericchiang@google.com>
2018-12-05 19:22:32 -08:00
Steve Beattie
40449fdd27 Make coverity: do all compiles as one scan-build run
In fed101920b, the coverity build process
was modified to split out the build logs into separate files, instead of
having one log file that gets overwritten repeatedly, making failures
hard to debug.

However, the coverity service gets upset if there is no file named with
the expected build log name. Therefore, instead, we'll capture the
python bits first, and then capture all the compilation bits in one
cov-build command.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/273
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-11-30 12:23:39 -08:00
Christian Boltz
0a666b8e48 Merge branch 'certbot' into 'master'
Add /etc/letsencrypt/archive to ssl_key abstraction

See merge request apparmor/apparmor!283

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.10..master
2018-11-30 15:44:13 +00:00
Christian Boltz
869f98a2a4 Merge branch 'postfix-profiles' into 'master'
Postfix profile updates

See merge request apparmor/apparmor!284

Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-11-30 14:20:51 +00:00
Julian Andres Klode
4c85a7ec9e profiles/postfix-smtpd: Include ssl_certs, ssl_keys
This is needed for serving TLS.
2018-11-30 14:43:29 +01:00
Julian Andres Klode
b858428dd1 profiles/postdrop: Allow reading from pickup socket 2018-11-30 14:38:57 +01:00
Julian Andres Klode
d1ab0a021e profiles/postfix-pickup: Allow reading from cleanup socket 2018-11-30 14:33:45 +01:00
Julian Andres Klode
60d203b622 postfix.local: Minor adjustments to make it work
This connects queue manager to local.
2018-11-30 14:30:13 +01:00
Julian Andres Klode
02528133d2 postfix.*: Adapt for new queue names, and extra locking and r/w communication
This gets us to the local process now, which comes next.
2018-11-30 14:24:43 +01:00
Julian Andres Klode
3d842ddb82 postifx-common: Allow access to dynamicmaps, most seems to use it 2018-11-30 14:23:56 +01:00
Julian Andres Klode
e8841a0953 postfix.tlsmgr: Connect to urandom and prng exchange 2018-11-30 14:23:34 +01:00
Julian Andres Klode
f4bfd78164 postfix.master: Change path of child processes 2018-11-30 14:22:58 +01:00
Julian Andres Klode
cb46878644 Add /etc/letsencrypt stuff to ssl_keys/ssl_certs abstraction
`/etc/letsencrypt/live/` contains symlinks to
`/etc/letsencrypt/archive/` which contains the keys. Add the
certs to ssl_certs and the private keys to ssl_keys.
2018-11-30 14:02:16 +01:00
Steve Beattie
9943da2f52 profiles/postfix: add locking perm to pid files
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2018-11-29 15:14:55 -08:00
Steve Beattie
dd4903efc6 profiles/postfix: eliminate some redundant rules
Remove rules covered by the postfix-common or other abstractions.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2018-11-29 15:14:55 -08:00
Steve Beattie
889503f623 profiles: add a postfix dnsblog profile
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2018-11-29 15:14:55 -08:00
Steve Beattie
1c9459825a profiles: add a postfix postscreen profile
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2018-11-29 15:14:55 -08:00
Steve Beattie
35d84895fe profiles/postfix-master: grant signal+unix communication with children
Grant the ability to communicate with the postfix named child profiles
via signals and unix sockets. Include the path-based match names as
a fallback on upgrades.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2018-11-29 15:14:55 -08:00
Steve Beattie
39ca2adff6 profiles/postfix: use named profiles
Convert all the postfix subprocesses to using named profiles instead of
path match profiles, and adjust exec paths for newer debian/ubuntu
releses. Rename profiles to match profile names.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2018-11-29 15:14:55 -08:00
Steve Beattie
01648c6a61 profiles/postfix-master: use profile name instead of match pattern
Convert postfix's master profile to use a named profile
(postfix-master) rather than the exec path match pattern. Adjust
postfix-common abstraction to take this into account. Rename profile
name in the profiles/apparmor/profiles/extras/ directory to match
the profile name.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2018-11-29 15:14:52 -08:00
Christian Boltz
228b92ce5a Ignore *.orig and *.rej files when loading profiles
or: get rc.apparmor.functions in sync with the tools and libapparmor.

This was "accidently" reported by Ralph on the opensuse-support
mailinglist.
2018-11-28 22:50:09 +01:00
Christian Boltz
6fd0990bca Merge branch 'cboltz-fix-view-extra' into 'master'
Fix viewing a local inactive profile in aa-genprof

See merge request apparmor/apparmor!275

Acked-by: John Johansen <john.johansen@canonical.com>
2018-11-21 21:15:14 +00:00
Jamie Strandboge
170e8d6ac8 deny ~/.mutt** in private-files and audit deny ~/.aws in private-files-strict
Signed-Off-By: Jamie Strandboge <jamie@canonical.com>
2018-11-19 16:13:57 -06:00
Christian Boltz
8b4e76a7d5 Fix viewing a local inactive profile in aa-genprof
aa-genprof checks if one of the profiles in the extra profile dir
matches the binary, and proposes to use that profile as a starting
point.

Since 4d722f1839 the "(V)iew profile"
option to display the proposed profile was broken.

The easiest fix is to remember the filename in the extras directory, and
display the file from there.

Sidenote: when choosing to use the extra profile, it gets written to
disk without any problems, so this bug really only affected "(V)iew
profile" to preview the proposed extra profile.
2018-11-18 21:35:07 +01:00
Christian Boltz
04c91d5256 Drop unused activate_repo_profiles() 2018-11-18 17:20:30 +01:00
Christian Boltz
739b5d6cd3 Merge branch 'fix-make-clean-stress-tests' into 'master'
tests: fix make clean target

See merge request apparmor/apparmor!272

Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-11-17 18:44:57 +00:00
Steve Beattie
2e3fa8b830 Drop APPARMOR_ENABLE_AAEVENTD
Merge branch 'cboltz-eventd' into 'master'

PR: https://gitlab.com/apparmor/apparmor/merge_requests/269
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2018-11-16 23:15:36 +00:00
Steve Beattie
7496fad27f tests: fix make clean target
Make the tests/stress 'make clean' target cope with the rename from
subdomain to apparmor.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2018-11-16 14:16:07 -08:00
John Johansen
9db669a0ef Merge branch 'cboltz-parse-remainder' into 'master'
parse_profile_data(): Ensure last line in a profile is valid

'lastline' gets merged into 'line' (and reset to None) when reading the
next line. If 'lastline' isn't empty after reading the whole profile,
this means there's something unparseable at the end of the profile,
therefore parse_profile_data() should error out.

Also remove some simple_tests testcases from the 'exception_not_raised'
list - they only didn't raise the exception because the invalid rule was
the last line in the affected profile.

Thanks to Eric Chiang for accidently (and maybe even unnoticedly ;-)
discovering this bug while adding some xattr testcases that surprisingly
didn't fail in the tools.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/271
Acked-by: John Johansen <john.johansen@canonical.com>
2018-11-13 23:58:54 +00:00
Christian Boltz
4efff35bf8 parse_profile_data(): Ensure last line in a profile is valid
'lastline' gets merged into 'line' (and reset to None) when reading the
next line. If 'lastline' isn't empty after reading the whole profile,
this means there's something unparseable at the end of the profile,
therefore parse_profile_data() should error out.

Also remove some simple_tests testcases from the 'exception_not_raised'
list - they only didn't raise the exception because the invalid rule was
the last line in the affected profile.

Thanks to Eric Chiang for accidently (and maybe even unnoticedly ;-)
discovering this bug while adding some xattr testcases that surprisingly
didn't fail in the tools.
2018-11-13 17:59:40 +01:00
Christian Boltz
7ba8dc7e2e Drop APPARMOR_ENABLE_AAEVENTD
This is another trace of aa-eventd which is deprecated since years.
2018-11-12 15:51:15 +01:00
Christian Boltz
273e45a4af Merge branch 'cboltz-profile-list' into 'master'
Replace "existing_profiles" & fix minitools for named profiles

See merge request apparmor/apparmor!249

Acked-by: John Johansen <john.johansen@canonical.com>
2018-11-11 13:17:00 +00:00
John Johansen
2809060bec parser: limit the number of passes expr tree simplification does
Expr tree simplification makes multiple passes at simplifying the
expression tree trying to use fatoring rules and heuristics to achieve
the minimum tree, so that dfa construction has fewer nodes to deal
with.

Unfortunately expr tree simplification can slow some policy compiles,
dependent on the type of expressions generated, down, and even worse
is currently subject to never terminating on some expressions as the
left and right passes keep undoing each others work.

Limiting the number of passes that expr tree simplification does can
provide most of its benefits (later passes generally have diminishing
returns), reduces the overhead it has on simple policy where it is of
little benefit, and insures that simplifications can not get stuck in
an infinite loop due to the left and right passes ping-ponging on each
others factoring.

Note: This also results in a performance improvement in evince
compiles, and general policy compiles because it achieves a better
balance between time spent on simplifying the tree to remove nodes and
time the dfa build requires to build with extra nodes and then
eliminate with minimization.

$ time apparmor_parser -QT /etc/apparmor.d/usr.bin.evince
real	0m2.744s
user	0m2.714s
sys	0m0.028s

vs.

$ time apparmor_parser -QT /etc/apparmor.d/usr.bin.evince
real	0m2.992s
user	0m2.979s
sys	0m0.012s

and

$ time apparmor_parser -QT /etc/apparmor.d/
real	0m3.568s
user	0m14.529s
sys	0m0.152s

vs.

$ time apparmor_parser -QT /etc/apparmor.d/
real	0m3.741s
user	0m15.400s
sys	0m0.179s

PR: https://gitlab.com/apparmor/apparmor/merge_requests/246
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2018-11-09 13:01:01 -08:00
John Johansen
3318f660e3 Merge branch 'cboltz-eventd' into 'master'
Remove traces of aa-eventd

aa-eventd and its initscripts have been moved to deprecated/ in 2014 and didn't get any serious updates for several more years, so it's most probably useless and/or broken nowadays.

This also means we don't need to keep the AA_EV_BIN and AA_EV_PIDFILE variables in rc.apparmor.functions anymore.

(In theory I could move these variables to deprecated/rc.aaeventd.* - but in practise that sounds more than superfluous ;-)

PR: https://gitlab.com/apparmor/apparmor/merge_requests/263
Acked-by: John Johansen <john.johansen@canonical.com>
2018-11-09 17:02:22 +00:00
Christian Boltz
3a89e9811f Remove traces of aa-eventd
aa-eventd and its initscripts have been moved to deprecated/ in 2014 and
didn't get any serious updates for several more years, so it's most
probably useless and/or broken nowadays.

This also means we don't need to keep the AA_EV_BIN and AA_EV_PIDFILE
variables in rc.apparmor.functions anymore.
2018-11-09 17:22:17 +01:00
John Johansen
94ff870f78 remove subdomainfs support
It has been over 10 years since transition from subdomainfs to
using securityfs. Lets drop this deprecated code.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/258
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: seth.arnold@canonical.com
2018-11-08 18:23:21 -08:00
John Johansen
0d5ab43d59 rc.apparmor.functions: drop module loading support
The apparmor kernel "module" has not been a loadable module for more
than a decade, it must be built into the kernel and due configuration
requirements it will never go back to being a loadable module.

Remove the long unfunctioning load_module support from the init script.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/257
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: seth.arnold@canonical.com
2018-11-08 18:22:09 -08:00
John Johansen
e657ca67d7 Merge branch 'use-sys' into 'master'
Use @{sys} tunable in profiles and abstractions

Commit aa065287 made @{sys} tunable available by default.

Update profiles and abstractions to actually use @{sys} tunable for better confinement in the future (when @{sys} becomes kernel var).

Closes LP#1728551

PR: https://gitlab.com/apparmor/apparmor/merge_requests/262
Acked-by: John Johansen <john.johansen@canonical.com>
2018-11-09 01:45:18 +00:00
Vincas Dargis
2438179b76 Use @{sys} tunable in profiles and abstractions
Commit aa06528790 made @{sys} tunable
available by default.

Update profiles and abstractions to actually use @{sys} tunable for
better confinement in the future (when @{sys} becomes kernel var).

Closes LP#1728551
2018-11-08 20:04:46 +02:00
Steve Beattie
5888a50a0f parser/libapparmor_re: expand comment of firstpos, lastpos, followpos
Merge branch 'regex-dragon-book' into 'master'

PR: https://gitlab.com/apparmor/apparmor/merge_requests/261
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2018-11-07 21:36:32 +00:00
Eric Chiang
197b5d63fe parser/libapparmor_re: expand comment of firstpos, lastpos, followpos
Elaborate in class comment of firstpos, lastpos, followpos, and nullable
fields beyond just referencing the Dragon book. Also add the section of
the book these are explained in.
2018-11-06 19:08:28 -08:00
Christian Boltz
39a2031487 Merge branch 'cboltz-strict-todo-check' into 'master'
error out on superfluous TODOs

See merge request apparmor/apparmor!197

Acked-by: John Johansen <john.johansen@canonical.com>
2018-11-06 21:14:40 +00:00
Christian Boltz
4b26850e14 error out on superfluous TODOs
If a test is marked as TODO, but matches its EXRESULT, this means the
TODO is superfluous and (probably) a change fixed what the TODO was for.

Instead of more or less ignoring such superfluous TODOs, error out to
make the change visible instantly.
2018-11-06 21:44:40 +01:00
Christian Boltz
608af94dff Merge branch 'cboltz-disable-some-abi-tests' into 'master'
disable abi/ok_10 and abi/ok_12 tests

See merge request apparmor/apparmor!259
2018-11-06 20:43:04 +00:00
Christian Boltz
a3305b512d disable abi/ok_10 and abi/ok_12 tests
Both result in "superfluous TODO" (for unknown reason), but fail after
removing the TODO.

Disable the tests until we find out why they have this strange
behaviour, to unblock merging the "error out on superfluous TODO" patch.
2018-11-06 21:33:12 +01:00
Christian Boltz
c98d8570ee Merge branch 'cboltz-fixed-todos' into 'master'
Remove TODO notes from no-longer-failing tests

See merge request apparmor/apparmor!180

Acked-by: John Johansen <john.johansen@canonical.com>
Acked-by: intrigeri <intrigeri@debian.org>
2018-11-06 17:33:49 +00:00
intrigeri
7416138b43 Merge remote-tracking branch 'origin/merge-requests/251'
apparmor(7): Document various debugging options.

Bug-Debian: https://bugs.debian.org/826218
PR: https://gitlab.com/apparmor/apparmor/merge_requests/251
2018-11-04 12:01:38 +00:00
intrigeri
b95f9bdd3b apparmor(7): Document various debugging options.
Credits go to John Johansen <john@jjmx.net> for most of the information
and the initial phrasing.

Bug-Debian: https://bugs.debian.org/826218
2018-11-04 11:43:04 +00:00
John Johansen
607e185d0c Merge branch 'cboltz-minus-one' into 'master'
replace -1 return codes with 255

Technically "return -1" returns 255, so we should write it that way.
(found by shellcheck)

PR: https://gitlab.com/apparmor/apparmor/merge_requests/256
Acked-by: John Johansen <john.johansen@canonical.com>
2018-11-03 14:08:25 +00:00
Christian Boltz
29da17310e replace -1 return codes with 255
Technically "return -1" returns 255, so we should write it that way.

(found by shellcheck)
2018-11-02 17:00:33 +01:00
intrigeri
73e124d4fb rc.apparmor.functions: add is_container_with_internal_policy() function.
Imported from the Debian/Ubuntu packaging. We need this function so that
Debian/Ubuntu can switch to using this shell library instead of their own code.
2018-10-30 16:37:02 +00:00
intrigeri
f58c96699a rc.apparmor.functions: add support for an additional profiles directory, defaulting to /var/lib/snapd/apparmor/profiles.
We need this support so that Debian/Ubuntu can switch to using this shell
library instead of their own code.
2018-10-30 16:36:55 +00:00
intrigeri
13d9512287 rc.apparmor.functions: warn when the profiles directory cannot be found.
We do this for apparmor.conf so let's be consistent.
2018-10-30 15:30:01 +00:00
intrigeri
ff617819aa rc.apparmor.functions: delete disabled profile handling code.
It duplicates the parser's default behaviour.
2018-10-30 15:30:01 +00:00
intrigeri
222943eb3b rc.apparmor.functions: suppress warnings when booting in quiet mode. 2018-10-30 15:30:01 +00:00
intrigeri
04eb2fe345 rc.apparmor.functions: take benefit from the parser's automatic parallelization. 2018-10-30 13:37:05 +00:00
intrigeri
9385d00ea6 rc.apparmor.functions: stop passing -I explicitly to the parser.
A correctly configured/compiled parser adds $PROFILE_DIR to the search
path itself.
2018-10-30 13:13:04 +00:00
intrigeri
7c396bcd3e rc.apparmor.functions: drop force-complain handling code, that now duplicates parser's functionality. 2018-10-30 13:11:43 +00:00
Christian Boltz
473d1f5daa Merge branch 'cboltz-postalias' into 'master'
allow locking /etc/aliases.db

See merge request apparmor/apparmor!250

Acked-by: intrigeri <intrigeri@debian.org>
2018-10-26 14:39:31 +00:00
Christian Boltz
f74edd5d5a allow locking /etc/aliases.db
This is needed for "newaliases" on current openSUSE Tumbleweed / postfix 3.3.1
2018-10-25 20:59:25 +02:00
Christian Boltz
4d722f1839 Replace existing_profiles & fix minitools for named profiles
Technical stuff first:

Replace existing_profiles (a dict with the filenames for both active and
inactive profiles) with active_profiles and extra_profiles which are
ProfileList()s and store the active profiles and those in the extra
directory separately. Thanks to ProfileList, now also the relation
between attachments and filenames is easily available.

Also replace all usage of existing_profiles with active_profiles and
extra_profiles, and adjust it to the ProfileList syntax everywhere.

With this change, several bugs in aa-complain and the other minitools
get fixed:
- aa-complain etc. never found profiles that have a profile name
  (the attachment wasn't checked)
- even if the profile name was given as parameter to aa-complain, it
  first did "which $parameter" so it never matched on named profiles
- profile names with alternations (without attachment specification)
  also never matched because the old code didn't use AARE.

References: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=882047#92
(search for "As usual" ;-)

Just for completeness - the matching still doesn't honor/expand
variables in the profile name.
2018-10-23 00:28:37 +02:00
Christian Boltz
789c4658e2 add ProfileList class to store list of profiles
ProfileList is meant to store the list of profiles (both name and
attachment) and in which files they live.

Also add unittests to make sure everything works as expected.
2018-10-23 00:28:37 +02:00
Christian Boltz
8809218ac8 Move updating existing_profiles out of parse_profile_data()
parse_profile_data() returns the parsed profiles, but writes to
existing_profiles directly.

read_profiles() calls parse_profile_data() and already handles adding
the parsed profiles to aa, original_aa or extras, which means updating
existing_profiles there is a much better place.

This commit also includes a hidden change: Previously, when parsing
include files, they were also added to existing_profiles. This is
superfluous, only real profiles need to be stored there.
2018-10-23 00:28:37 +02:00
Christian Boltz
a6b8d14908 split off get_new_profile_filename()
... and call it from get_profile_filename_* if get_new is True
(= always with the current code)
2018-10-23 00:28:37 +02:00
Christian Boltz
ec741424f8 split get_profile_filename into .._from_profile_name and .._from_attachment
Split get_profile_filename() into
- get_profile_filename_from_profile_name() (parameter: a profile name)
- get_profile_filename_from_attachment() (parameter: an attachment)

Currently both functions call get_profile_filename_orig() (formerly
get_profile_filename()) so the behaviour doesn't change yet.

The most important part of this commit is changing all
get_profile_filename() calls to use one of the new functions to make
clear if they specify a profile or an attachment/executable as
parameter.

As promised, the is_attachment parameter starts to get used in this
patch ;-)

Note: The get_new parameter (which I'll explain in the patch actually
using it) is set to True in all calls to the new functions.
The long term plan is to get rid of it in most cases (hence defaulting
to False), but that will need more testing.
2018-10-23 00:28:37 +02:00
Christian Boltz
bc783372b8 Add is_attachment parameter to write_profile
The minitools call write_profile(), write_profile_feedback_ui() and
serialize_profile() with the _attachment_ as parameter.

However, aa-logprof etc. call them with the _profile name_ as parameter.

This patch adds an is_attachment parameter to write_profile() and
write_profile_feedback_ui(). It also passes it through to
serialize_profile() via the options parameter.

If is_attachment is True, the parameter will be handled as attachment,
otherwise it is expected to be a profile name.

tools.py gets changed to set is_attachment to True when calling the
functions listed above to make clear that the parameter is an attachment.

Note: This patch only adds the is_attachment parameter/option, but
doesn't change any behaviour. That will happen in the next patch.
2018-10-23 00:18:04 +02:00
Christian Boltz
fd68a5eb64 Merge branch 'cboltz-profile-names' into 'master'
Add profile names to all profiles with {bin,sbin} attachment

See merge request apparmor/apparmor!242

Acked-by: intrigeri <intrigeri@debian.org>
2018-10-21 10:34:59 +00:00
John Johansen
d87b6a5f6e Merge branch 'dont-hard-code-libc-header-location' into 'master'
Don't hard code the location of netinet/in.h.

This "will break with non-glibc libcs on Debian and with glibc headers moved to
multiarch locations" (https://bugs.debian.org/798955). Patch based on the one
proposed by Helmut Grohne helmut@subdivi.de, amended to replace hard coded
"gcc" with "$(CC)".

Bug-Debian: https://bugs.debian.org/909966

nominated for 2.13.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/245
Acked-by: John Johansen <john.johansen@canonical.com>
2018-10-21 06:29:05 +00:00
intrigeri
2d91211842 Don't hard code the location of netinet/in.h.
This "will break with non-glibc libcs on Debian and with glibc headers moved to
multiarch locations" (https://bugs.debian.org/798955). Patch based on the one
proposed by Helmut Grohne <helmut@subdivi.de>, amended to replace hard coded
"gcc" with "$(CC)".

Bug-Debian: https://bugs.debian.org/909966
2018-10-20 20:49:26 +00:00
intrigeri
f0dfb3cd74 Merge branch 'cboltz-rc-syntax-fix' into 'master'
Fix syntax error in rc.apparmor.functions

See merge request apparmor/apparmor!240
2018-10-20 16:00:07 +00:00
Christian Boltz
2863e20f37 Merge branch 'test-includes' into 'master'
profiles/Makefile: test abstractions against apparmor_parser

See merge request apparmor/apparmor!237

Acked-by: Christian Boltz <apparmor@cboltz.de> for trunk and 2.13.

Pre-acked for 2.10..2.12 after removing the --config-file option which is not supported in these branches.
2018-10-17 22:20:51 +00:00
Vincas Dargis
dc7ae28de0 profiles/Makefile: test abstractions against apparmor_parser
Update Makefile to test abstractions by generating temporary profile, to
check for missing (not backported) abstractions or other issues.
2018-10-17 20:05:51 +03:00
Christian Boltz
f920915dd3 Merge branch 'aa-notify-manpage' into 'master'
aa-notify man page: update user's configuration file path

See merge request apparmor/apparmor!239

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.10..master
2018-10-16 15:55:44 +00:00
Christian Boltz
b77116e6af Add profile names to all profiles with {bin,sbin} attachment
Also adjust the signal rules in the dovecot-common and apache2-common
abstractions to match the profile names, and to really do that
(peer=...{bin,sbin}... didn't work, the correct syntax would have been
peer=...\{bin,sbin\}...)

This fixes the regression introduced by !149 / commit
4200932d8f
2018-10-15 20:57:33 +02:00
nl6720
2209e09aef aa-notify man page: update user's configuration file path
Signed-off-by: nl6720 <nl6720@gmail.com>
2018-10-15 16:44:00 +03:00
Christian Boltz
3bf11cee3e Fix syntax error in rc.apparmor.functions
This bug was introduced in
- https://gitlab.com/apparmor/apparmor/merge_requests/230
- commit c974dd0d07 (master)
- commit 9987a7ec9c (2.13 branch)
2018-10-14 18:10:46 +02:00
John Johansen
4a2dad336a library: bump library version to keep it in sync with 2.13.1 release
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-10-13 16:40:05 -07:00
John Johansen
6242051a1c Merge branch 'cboltz-abi-exceptions' into 'master'
Add most abi/bad_*.sd tests to "exception not raised" list

Interestingly, abi/bad_6.sd is detected as invalid, and therefore not
added to the list.

I propose this for all branches that g[eo]t support for abi rules and the abi testcases.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/238
Acked-by: John Johansen <john.johansen@canonical.com>
2018-10-13 21:31:31 +00:00
Christian Boltz
5c54f66279 Add most abi/bad_*.sd tests to "exception not raised" list
Interestingly, abi/bad_6.sd is detected as invalid, and therefore not
added to the list.
2018-10-13 20:23:57 +02:00
John Johansen
83df7c4747 parser: ignore feature abi rules
AppArmor 3.0 requires policy to use a feature abi rule for access to
new features. However some policy may start using abi rules even if
they don't have rules that require new features.  This is especially
true for out of tree policy being shipped in other packages.

Add enough support to older releases that the parser will ignore the
abi rule and warn that it is falling back to the apparmor 2.x
technique of using the system abi.

If the profile contains rules that the older parser does not
understand it will fail policy compilation at the unknown rule instead
of the abi rule.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/196
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2018-10-12 22:14:38 -07:00
John Johansen
4153663c42 parser: fix: ensure that a quotedid actually has both quotes
The handling for quotedid checked for the first quote but failed
to ensure the trailing quote was present.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/196
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2018-10-12 22:14:38 -07:00
John Johansen
04beee7633 parser: combine INCLUDE cases together and support escape sequences
We can reduce the INCLUDE/INCLUDE_EXISTS code dup by using a
variable for whether the name was enclosed by '<' and using
processid() to handle the whether the id is quoted or not.

In addition using processid allows include names to contain
escaoe sequences like \n and have them handled correctly.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/196
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2018-10-12 22:14:38 -07:00
John Johansen
eff672b2eb parser: refactor INCLUDE and INCLUDE_EXISTS to share a start condition
We can reduce code duplication by checking the current state to
determine the single parameter difference between include and
include if exists

PR: https://gitlab.com/apparmor/apparmor/merge_requests/196
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2018-10-12 22:14:38 -07:00
John Johansen
924d4e87ad Merge branch 'cboltz-nmbd-systemd' into 'master'
References: https://bugs.launchpad.net/ubuntu/+source/samba/+bug/1719354
(comment 8)

PR: https://gitlab.com/apparmor/apparmor/merge_requests/236
Acked-by: John Johansen <john.johansen@canonical.com>
2018-10-12 22:00:11 +00:00
Christian Boltz
d4afbccb6a nmbd profile: allow writing to /run/systemd/notify
References: https://bugs.launchpad.net/ubuntu/+source/samba/+bug/1719354
(comment 8)
2018-10-12 23:48:13 +02:00
John Johansen
c421a29c61 parser: do not output cache warning for stdin if not using cache
Currently if stdin is used the warning
  apparmor_parser: cannot use or update cache, disable, or force-complain via stdin

is always displayed but if caching has been disabled there is no need for
this message.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-10-11 22:11:39 -07:00
Christian Boltz
93445ca02d Merge branch 'cboltz-mergeprof-hasher-fun' into 'master'
Fix aa-mergeprof crash caused by accidentially initialzed hat

See merge request apparmor/apparmor!234

Acked-by: John Johansen <john.johansen@canonical.com>
2018-10-11 19:49:24 +00:00
Christian Boltz
bc492533cc Fix aa-mergeprof crash caused by accidentially initialzed hat
Hasher causes some fun in aa-mergeprof: If the profile in
/etc/apparmor.d/ has a hat or subprofile that doesn't exist in the
to-be-merged profile, aa-mergeprof crashes. This is caused by reading
self.other.aa[program][hat]['include'] which accidently "creates" that
profile inside the aa hasher as empty hasher (instead of ProfileStorage).

Later, the code loops over self.other.aa[profile].keys(), expects
everything to be ProfileStorage, and explodes [1] when for example
trying to run .delete_duplicates on the hasher (which obviously doesn't
provide this method).

This patch adds checks to all self.other.aa accesses in
CleanProf.remove_duplicate_rules() to avoid accidently creating new keys
in the hasher.

Interestingly this bug survived unnoticed for years (at least since
2.11).

[1] last lines of the backtrace:
  File ".../utils/apparmor/cleanprofile.py", line 42, in compare_profiles
    deleted += self.remove_duplicate_rules(profile)
  File ".../utils/apparmor/cleanprofile.py", line 65, in remove_duplicate_rules
    deleted += apparmor.delete_duplicates(self.other.aa[program][hat], inc)
  File ".../utils/apparmor/aa.py", line 1680, in delete_duplicates
    deleted += profile[rule_type].delete_duplicates(include[incname][incname][rule_type])
AttributeError: 'collections.defaultdict' object has no attribute 'delete_duplicates'
2018-10-11 19:49:26 +02:00
John Johansen
fbb1a1735d Merge branch 'cboltz-gitignore' into 'master'
.gitignore profiles/apparmor.d/local/* except README

The old patter . doesn't match lsb_release and nvidia_modprobe, and
the only file we ship in local is a README. This patch adjusts the
pattern to ignore everything except README.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/227

Acked-by: John Johansen <john.johansen@canonical.com>
2018-10-11 17:20:30 +00:00
Christian Boltz
aeee9a1aab .gitignore profiles/apparmor.d/local/* except README
The old patter *.* doesn't match lsb_release and nvidia_modprobe, and
the only file we ship in local is a README. This patch adjusts the
pattern to ignore everything except README.
2018-10-11 12:59:16 +02:00
Christian Boltz
999263c831 Merge branch 'cboltz-extra-profiles-samba' into 'master'
delete smbd and nmbd from extra profiles

See merge request apparmor/apparmor!229

Acked-by: John Johansen <john.johansen@canonical.com>
2018-10-11 10:23:30 +00:00
John Johansen
a992a22668 Merge branch 'cboltz-dovecot-ssl-params' into 'master'
add new location for ssl-params file

(probably Ubuntu-only? The ssl-params file doesn't exist on my openSUSE
installation)

References: https://bugs.launchpad.net/apparmor-profiles/+bug/1796966
I propose this patch for 2.10..master

PR: https://gitlab.com/apparmor/apparmor/merge_requests/231
Acked-by: John Johansen <john.johansen@canonical.com>
2018-10-09 23:52:53 +00:00
John Johansen
958cc28876 libapparmor: Finish removing LD_RUN_PATH from Makefile.perl
commit 94dfe15b28 attempted to remove
LD_RUN_PATH unfortunately

   But all it actually does is cause the Makefile.perl to embed the rpath
    "" instead. Which is still an rpath, only I guess an even worse one.

    --
    Eli Schwartz
    Arch Linux Bug Wrangler and Trusted User

This is because it cleared the setting of the variable LD_RUN_PATH
which was expanded in the command

$(INST_DYNAMIC) : $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)$(DFSEP).exists $(EXPORT_LIST) $(PERL_ARCHIVEDEP) $(PERL_ARCHIVE_AFTER) $(INST_DYNAMIC_DEP)
	$(RM_F) $@
	 LD_RUN_PATH="$(LD_RUN_PATH)" $(LD)  $(LDDLFLAGS) $(LDFROM) $(OTHERLDFLAGS) -o $@ $(MYEXTLIB) \
	  $(PERL_ARCHIVE) $(LDLOADLIBS) $(PERL_ARCHIVE_AFTER) $(EXPORT_LIST) \
	  $(INST_DYNAMIC_FIX)
	$(CHMOD) $(PERM_RWX) $@

resulting in LD_RUN_PATH="" being passed to the command.

Finish removing LD_RUN_PATH from Makefile.perl by removing it from
the command invocation if it is present.

Note: we use \x24 instead of $ in the regex as there seems to be a bug
and no level of escaping $ would allow it to be used.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-10-09 16:42:17 -07:00
Christian Boltz
772a8702e0 Merge branch 'sys-by-default' into 'master'
Make @{sys} available by default

See merge request apparmor/apparmor!228

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.10..master
2018-10-09 22:30:10 +00:00
Christian Boltz
16a98d26d0 add new location for ssl-params file
(probably Ubuntu-only? The ssl-params file doesn't exist on my openSUSE
installation)

References: https://bugs.launchpad.net/apparmor-profiles/+bug/1796966
2018-10-09 23:24:51 +02:00
John Johansen
c974dd0d07 Merge branch 'void' into 'master'
rc.apparmor.functions: skip XBPS conffile artifacts

PR: https://gitlab.com/apparmor/apparmor/merge_requests/230

Acked-by: John Johansen <john.johansen@canonical.com>
2018-10-09 20:33:32 +00:00
Cameron Nemo
918e19238a rc.apparmor.functions: skip XBPS conffile artifacts 2018-10-09 12:39:24 -07:00
Vincas Dargis
aa06528790 Make @{sys} available by default
Move @{sys} into tunables/kernelvars to make it readily available for
all profiles by default. In order to avoid duplicate variable
declaration, other tunable includes where modified accordingly.
Additionally, apparmor_api/is_enable has updated comment with regards to
@{sys} availability. tunables/sys is now marked as deprecated and should
not be used as it is noop, left only for backwards compatibility.

This is preparation for fixing bug:
https://bugs.launchpad.net/apparmor/+bug/1728551

Thanks to Christian Boltz for original idea to implement this in
non-breaking manner.
2018-10-09 19:27:55 +03:00
Petr Vorel
025c7dc6a1 dnsmasq: Add permission to open log files
--log-facility option needs to have permission to open files.
Use '*' to allow using more files (for using more dnsmasq instances).

Signed-off-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Jamie Strandboge <jamie@canonical.com>
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2018-10-09 09:02:25 -07:00
Christian Boltz
516bc47495 delete smbd and nmbd from extra profiles
We ship newer versions of these profiles in apparmor.d, so there's no
reason to keep the outdated ones (no serious change since > 10 years) in
the extra directory.
2018-10-08 21:06:03 +02:00
Christian Boltz
34cf085036 Merge branch 'fix-bison' into 'master'
parser: fix Makefile hardcoded paths to flex and bison

Closes #4

See merge request apparmor/apparmor!224

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.10..master
2018-10-05 19:03:34 +00:00
John Johansen
17e059a253 parser: fix Makefile hardcoded paths to flex and bison
The hardcoded paths for flex and python can break builds on systems
where those tools are stored in an alternate location. Use which
to lookup where flex and bison are available.

This fixes issue #4

Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-10-05 11:48:11 -07:00
John Johansen
5718aa04ed Merge branch 'opencl-nvidia-update' into 'master'
Use nvidia_modprobe named profile inside opencl-nvidia abstraction

Commit 8f9bd5b0 rightfully removed PUx
transition into nvidia-modprobe executable due to security concerns. To
overcome this, commit 327420b1 added
named nvidia_modprobe profile, which allows to use this abstraction
without requiring additional rules to make OpenCL work with NVIDIA
drivers.

Add rule to allow Px transition into nvidia_modprobe profile for
nvidia-modprobe executable.

I propose this for 2.13..master (opencl* are only available in 2.13...). Please check if nvidia_modprobe is already backported.

https://gitlab.com/apparmor/apparmor/merge_requests/219

Acked-by: John Johansen <john.johansen@canonical.com>
2018-10-05 06:46:43 +00:00
John Johansen
97c1591f0e Merge branch 'aa-notify' into 'master'
aa-notify: Read user's configuration file from XDG_CONFIG_HOME

Legacy path ~/.apparmor/notify.conf is preferred if it exists, otherwise $XDG_CONFIG_HOME/apparmor/notify.conf, with fallback to ~/.config/apparmor/notify.conf, is used.

See merge request https://gitlab.com/apparmor/apparmor/merge_requests/215

Signed-off-by: nl6720 nl6720@gmail.com
Acked-by: John Johansen <john.johansen@canonical.com>
2018-10-05 06:34:39 +00:00
Christian Boltz
f76a718f28 Merge branch 'profile-usr.sbin.smbd' into 'master'
Add missing paths to usr.sbin.nmbd, usr.sbin.smbd and abstractions/samba

See merge request apparmor/apparmor!210

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.10..master
2018-10-04 20:34:06 +00:00
Vincas Dargis
e4b1cadf63 Use nvidia_modprobe named profile inside opencl-nvidia abstraction
Commit 8f9bd5b0e3 rightfully removed PUx
transition into nvidia-modprobe executable due to security concerns. To
overcome this, commit 327420b151 added
named nvidia_modprobe profile, which allows to use this abstraction
without requiring additional rules to make OpenCL work with NVIDIA
drivers.

Add rule to allow Px transition into nvidia_modprobe profile for
nvidia-modprobe executable.
2018-10-03 19:59:21 +03:00
nl6720
1fb9acc59e aa-notify: Read user's configuration file from XDG_CONFIG_HOME
Legacy path ~/.apparmor/notify.conf is preferred if it exists, otherwise
$XDG_CONFIG_HOME/apparmor/notify.conf, with fallback to
~/.config/apparmor/notify.conf, is used.

Signed-off-by: nl6720 <nl6720@gmail.com>
2018-10-03 12:38:28 +03:00
John Johansen
22fca3c217 Merge branch 'cboltz-log-to-profile-empty' into 'master'
test-libapparmor-test_multi.py: test for known-empty log

Add a check to logfile_to_profile() that checks the parsed log against a
list of input logs (log_to_profile_known_empty_log) that produce an
empty output.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/214

Acked-by: John Johansen <john.johansen@canonical.com>
2018-10-03 06:47:21 +00:00
John Johansen
e7133731cf Merge branch 'nvidia-modprobe' into 'master'
Add nvidia_modprobe named profile

nvidia-modprobe is setuid executable is used to create various device
files and load the the NVIDIA kernel module
(https://github.com/NVIDIA/nvidia-modprobe).
Add named profile to be used in application profiles for confining
potentially risky setuid application.
I propose this to 2.10..master.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/213

Acked-by: Christian Boltz <apparmor@cboltz.de>
Acked-by: John Johansen <john.johansen@canonical.com>
2018-10-03 06:45:16 +00:00
John Johansen
dada29a50c Merge branch 'profile-usr.sbin.dnsmasq' into 'master'
usr.sbin.dnsmasq: add /srv/tftp

See merge request apparmor/apparmor!211

Acked-by: John Johansen <john.johansen@canonical.com>
2018-10-03 06:40:51 +00:00
John Johansen
05e620903a Merge branch 'cboltz-abi' into 'master'
Add basic support for abi rules to the tools

 Add basic support for abi rules to the tools

Add basic "understand and keep" support for abi rules, where "understand" means to not error out when seeing an abi rule, and "keep" simply means to keep the original abi rule when serializing a profile.

On the long term, abi rules should be parsed (similar to include rules), but for now, this patch is the smallest possible changeset and easy to backport.

Note that the only added test is via cleanprof_test.* which is used by minitools_test.py - and does not run if you do a 'make check'. Oh, and of course the simple_tests/abi/ files also get parsed by test-parser-simple-tests.py.

Also note that serialize_profile_from_old_profile() (which no longer exists in master, "only" in <= 2.13) would in theory also need support for abi rules. In practise, making this another case of "serialize_profile_from_old_profile() has known issues" is probably fine, but we should at least test that "(V)iew changes" doesn't break if an abi rule is present.

I propose this patch for 2.10..master.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/202
Acked-by: John Johansen <john.johansen@canonical.com>
2018-10-03 06:35:05 +00:00
Vincas Dargis
327420b151 Add nvidia_modprobe named profile
nvidia-modprobe is setuid executable is used to create various device
files and load the the NVIDIA kernel module
(https://github.com/NVIDIA/nvidia-modprobe).

Add named profile to be used in application profiles for confining
potentially risky setuid application.
2018-10-02 20:29:10 +03:00
nl6720
80e98f2d93 Update usr.sbin.nmbd & usr.sbin.smbd
Add missing paths.
2018-10-02 11:58:57 +03:00
Christian Boltz
cf33ec99fc test-libapparmor-test_multi.py: test for known-empty log
Add a check to logfile_to_profile() that checks the parsed log against a
list of input logs (log_to_profile_known_empty_log) that produce an
empty output.
2018-10-01 20:55:03 +02:00
John Johansen
63cb46d20a library: fix dirat_for_each2() fd handling
The function was messing up its use of fds, it could get away with
it because the cb_dirfd passed to fdopendir was still valid until
closedir was called but if code was moved around, or fdopendir
code changed behavior it could easily break.

Also the check for dup failing was wrong fix it.

Reference: coverity #187003

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Time-out
2018-10-01 09:16:32 -07:00
Christian Boltz
a03badd822 Merge branch 'kde-qt5' into 'master'
Include qt5 into kde abstraction

See merge request apparmor/apparmor!209

Acked-by: Christian Boltz <apparmor@cboltz.de> for master and backporting to 2.10..2.13 (as soon as the qt5 abstraction is backported)
2018-09-30 17:43:04 +00:00
nl6720
6d670a3ca9 usr.sbin.dnsmasq: add /srv/tftp 2018-09-30 13:55:44 +03:00
Vincas Dargis
bd33cdd19a Include qt5 into kde abstraction
Currently, kde abstraction has rules relevant to Qt 3 and Qt 4
libraries, but are missing rules against latest Qt 5.

Include read-only Qt 5 abstraction to fix styling and similar issues for
software running on KDE 5 desktop.

Fixes https://bugs.launchpad.net/apparmor/+bug/1787201
2018-09-30 13:03:59 +03:00
John Johansen
395aed7259 Merge branch 'uid' into 'master'
Add uid and uids kernel var placeholders

Add @{uid} and @{uids} variables to allow migrating profiles in advance while awaiting path mediation implementation, based on current user id, in kernel side.

See merge request apparmor/apparmor!208

Acked-by: John Johansen <john.johansen@canonical.com>
2018-09-29 18:08:17 +00:00
Vincas Dargis
cba10db7e7 Add uid and uids kernel var placeholders
Add @{uid} and @{uids} variables to allow migrating profiles in advance
while awaiting path mediation implementation, based on current user id,
in kernel side.
2018-09-29 17:43:13 +03:00
Jamie Strandboge
141c2c1c47 Merge branch 'harden-abstractions-part-ii' into 'master'
Harden abstractions part ii

See merge request apparmor/apparmor!206
2018-09-27 20:25:57 +00:00
Jamie Strandboge
6e014ab8a9 similar change for user-files 2018-09-27 15:11:54 -05:00
Jamie Strandboge
bbe0f9af78 private-files{,-strict}: disallow writes to parent dirs too 2018-09-27 14:42:14 -05:00
Emerson Bernier
afdd4f2189 abstractions/private-files: disallow access to the dirs of private files
Reference:
https://launchpad.net/bugs/1794820
2018-09-27 19:07:21 +00:00
John Johansen
495c4ff30e Merge branch 'ubuntu-email-thunderbird' into 'master'
ubuntu-email: allow running Thunderbird wrapper script

See merge request apparmor/apparmor!204
2018-09-27 18:54:03 +00:00
Vincas Dargis
cee9527fa8 ubuntu-email: allow running Thunderbird wrapper script
gio-launch-desktop helper tries to execute /usr/bin/thunderbird wrapper
script, not the /usr/lib/thunderbird... directly.

Add rule allowing to execute /usr/bin/thunderbird.
2018-09-27 21:04:32 +03:00
John Johansen
63ffb8ea64 Merge branch 'harden-abstractions' into 'master'
Harden abstractions

 Harden abstractions

    remove antiquated abstractions/launchpad-integration
    abstractions/opencl-nvidia: don't allow PUx on nvidia-modprobe
    abstractions/private-files-strict: disallow access to the dirs of private files
    abstractions/private-files: disallow writes to thumbnailer dir (LP: #1788929)
    ubuntu-browsers.d/user-files: disallow access to the dirs of private files

Nominating launchpad-integration and opencl-nvidia for 2.13. Nominating private-files-strict, private-files and user-files for 2.10 and higher

See merge request apparmor/apparmor!203

Acked-by: John Johansen <john.johansen@canonical.com>
2018-09-27 17:32:47 +00:00
Jamie Strandboge
5efd257585 we don't need to adjust keyring**. Thanks cboltz 2018-09-27 12:13:04 -05:00
Jamie Strandboge
ea2429dab5 ubuntu-browsers.d/user-files: disallow access to the dirs of private files 2018-09-27 12:09:09 -05:00
Jamie Strandboge
503d2904dc abstractions/private-files: disallow writes to thumbnailer dir (LP: #1788929) 2018-09-27 11:56:09 -05:00
Jamie Strandboge
d1937093f7 abstractions/private-files-strict: disallow access to the dirs of private files
Reference:
https://launchpad.net/bugs/1794820
2018-09-27 11:55:37 -05:00
Jamie Strandboge
8f9bd5b0e3 abstractions/opencl-nvidia: don't allow PUx on nvidia-modprobe 2018-09-27 11:38:51 -05:00
Jamie Strandboge
ae771b475a remove antiquated abstractions/launchpad-integration 2018-09-27 11:29:11 -05:00
Christian Boltz
072d3e0451 Add basic support for abi rules to the tools
Add basic "understand and keep" support for abi rules, where
"understand" means to not error out when seeing an abi rule, and "keep"
simply means to keep the original abi rule when serializing a profile.

On the long term, abi rules should be parsed (similar to include rules),
but for now, this patch is the smallest possible changeset and easy to
backport.

Note that the only added test is via cleanprof_test.* which is used by
minitools_test.py - and does _not_ run if you do a 'make check'.
Oh, and of course the simple_tests/abi/ files also get parsed by
test-parser-simple-tests.py.

Also note that serialize_profile_from_old_profile() (which no longer
exists in master, "only" in <= 2.13) would in theory also need support
for abi rules. In practise, making this another case of
"serialize_profile_from_old_profile() has known issues" is probably
fine, but we should at least test that "(V)iew changes" doesn't break if
an abi rule is present.
2018-09-26 22:09:17 +02:00
Christian Boltz
7e22b0a894 Merge branch 'zsh' into 'master'
add zsh to logprof.conf

See merge request apparmor/apparmor!201

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.10..master
2018-09-24 17:34:56 +00:00
Emerson Bernier
00871696f1 add zsh to logprof.conf 2018-09-24 16:51:11 +00:00
John Johansen
bfd5445870 Revert "Update ubuntu-email for launching Thunderbird wrapper script"
This reverts commit ab7459ed40.

This commit was meant to go to a branch to setup a merge request in
gitlab. Revert until the commit has gone through the regular review
process.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-09-24 03:01:46 -07:00
Vincas Dargis
ab7459ed40 Update ubuntu-email for launching Thunderbird wrapper script 2018-09-21 16:46:48 +00:00
John Johansen
cac5a5d293 Merge branch 'cboltz-more-useful-simple-test-output' into 'master'
make simple.pl / parser make check output more useful

Instead of printing the (useless) numbers of no-longer-failing tests
marked as TODO, let prove print out the actual test names.

A side effect is that really unfixed TODOs and disabled tests get
printed (lists about 10 tests), but that's much better than having to
hunt down the no-longer-failing TODOs.

This change will print out lines like (the first one is still a TODO,
the second one got fixed at some time)

not ok 71447 - TODO: ./simple_tests//vars/vars_profile_name_13.sd: reference variables that are the profile name and attachment # TODO Unfixed testcase.

ok 71448 - TODO: ./simple_tests//vars/vars_profile_name_14.sd: reference variables in rules that also have alternations # TODO Unfixed testcase.
before printing the test summary.

I propose this patch for master and (optionally) the maintained branches.

See merge request apparmor/apparmor!194

Acked-by: John Johansen <john.johansen@canonical.com>
2018-09-19 06:42:37 +00:00
Christian Boltz
e9b25c4969 make simple.pl / parser make check output more useful
Instead of printing the (useless) numbers of no-longer-failing tests
marked as TODO, let `prove` print out the actual test names.

A side effect is that really unfixed TODOs and disabled tests get
printed (lists about 10 tests), but that's much better than having to
hunt down the no-longer-failing TODOs.

This change will print out lines like (the first one is still a TODO,
the second one got fixed at some time)

```
not ok 71447 - TODO: ./simple_tests//vars/vars_profile_name_13.sd: reference variables that are the profile name and attachment # TODO Unfixed testcase.
ok 71448 - TODO: ./simple_tests//vars/vars_profile_name_14.sd: reference variables in rules that also have alternations # TODO Unfixed testcase.
```

before printing the test summary.
2018-09-18 21:42:14 +02:00
John Johansen
884041605c Merge branch 'profile-usr.sbin.ntpd' into 'master'
usr.sbin.ntpd: add openntpd drift and socket files

See merge request apparmor/apparmor!192

Acked-by: John Johansen <john.johansen@canonical.com>
2018-09-18 11:35:28 +00:00
John Johansen
50c9901d62 Merge branch 'profile-usr.sbin.dnsmasq' into 'master'
usr.sbin.dnsmasq: add paths for NetworkManager connection sharing

dnsmasq needs to access additional paths when used for connection sharing by NetworkManager.
Additionally it needs read permissions to /usr/share/dnsmasq/trust-anchors.conf which contains the DNSSEC trust anchors.

See merge request apparmor/apparmor!193

Acked-by: John Johansen <john.johansen@canonical.com>
2018-09-18 11:34:13 +00:00
John Johansen
20de92c5d6 Merge branch 'qt-settings-write' into 'master'
Add qt5 writing abstractions

Qt-based applications stores QFileDialog (latest browsed directory) and
other shared user settings inside ~/.config/QtProject.conf. Currently
available qt abstraction only allows to read it (by design), so this
patch introduces abstraction that grants permissions for writing.
Relevant denies discovered with KDE Dragon Player:
/var/log/audit/audit.log.1:type=AVC msg=audit(1533485161.999:981): apparmor="DENIED" operation="mknod" profile="/usr/bin/dragon" name="/home/vincas/.config/QtProject.conf.lock" pid=29911 comm="dragon" requested_mask="c" denied_mask="c" fsuid=1000 ouid=1000
type=AVC msg=audit(1533486419.266:1141): apparmor="DENIED" operation="file_lock" profile="/usr/bin/dragon" name="/home/vincas/.config/QtProject.conf.lock" pid=30406 comm="dragon" requested_mask="k" denied_mask="k" fsuid=1000 ouid=1000
/var/log/audit/audit.log.1:type=AVC msg=audit(1533485206.575:1006): apparmor="DENIED" operation="link" profile="/usr/bin/dragon" name="/home/vincas/.config/QtProject.conf.Gflpds" pid=29946 comm="dragon" requested_mask="l" denied_mask="l" fsuid=1000 ouid=1000 target="/home/vincas/.config/#12982163"
In addition, added new qt-compose-cache-write abstraction as some applications wants to write compose cache. qt5 abstraction is appended with read-only rule (that's enough for LibreOffice using KDE file dialog).

See merge request apparmor/apparmor!159

Acked-by: John Johansen <john.johansen@canonical.com>
2018-09-18 10:03:08 +00:00
nl6720
5bc7a9fbd6 usr.sbin.dnsmasq: add paths for NetworkManager connection sharing
Also add /usr/share/dnsmasq/, DNSSEC trust anchors are kept there.
2018-09-18 12:57:22 +03:00
nl6720
b3c4a73e2f usr.sbin.ntpd: add openntpd drift and socket files 2018-09-18 11:53:36 +03:00
John Johansen
50658a9409 Merge branch 'cboltz-parser-tests-configfile' into 'master'
use empty parser/tst/parser.conf in all parser and profile tests

See merge request apparmor/apparmor!191

Without this, the system-wide parser.conf gets used, which causes test
failures if for example caching is enabled and the cache dir isn't
writeable for the user running the tests.

I propose this for all branches where the parser understands --config-file.

Acked-by: John Johansen <john.johansen@canonical.com>
2018-09-17 09:43:47 +00:00
Christian Boltz
fdfcd47baa Use parser/tst/parser.conf in profiles 'make check'
This avoids problems if the system-wide parser.conf has caching enabled,
and the cache location is not writeable for the user running 'make check'.
2018-09-16 22:06:46 +02:00
Christian Boltz
5a18fd7c89 use empty parser/tst/parser.conf in all parser tests
Without this, the system-wide parser.conf gets used, which causes test
failures if for example caching is enabled and the cache dir isn't
writeable for the user running the tests.
2018-09-16 21:58:28 +02:00
John Johansen
b4f6711f4e Merge branch 'cboltz-logprof-python3.7' into 'master'
add python3.7 to logprof.conf

See merge request apparmor/apparmor!190

 add python3.7 to logprof.conf

I propose this patch for at least 2.12..master, maybe also 2.10 and 2.11 (even if it's unlikely that someone uses the latest python3 on a distro with old AppArmor)

Acked-by: John Johansen <john.johansen@canonical.com>
2018-09-14 23:51:52 +00:00
Christian Boltz
db096135eb add python3.7 to logprof.conf 2018-09-15 00:32:48 +02:00
Tyler Hicks
be29aac40c Merge branch 'doc-improvements' into 'master'
Doc improvements

See merge request apparmor/apparmor!188

Acked-by: Christian Boltz <apparmor@cboltz.de>
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2018-09-13 17:49:22 +00:00
Tyler Hicks
f26afb5b55 README: Point to the security vuln section of the wiki
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2018-09-13 17:01:32 +00:00
Tyler Hicks
35e59af532 README: Point to the new email address for security bug reports
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2018-09-13 17:00:22 +00:00
Tyler Hicks
1f935c4145 README: Improve the bug reporting instructions
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2018-09-13 16:59:29 +00:00
Tyler Hicks
f91235ca6a README: Move project contact info into the main README
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2018-09-13 16:54:09 +00:00
Tyler Hicks
a97fe6337a parser: Remove mention of wiretrip vulnerability handling policy
It looks as if the wiretrip domain has changed hands. The linked policy
page no longer exists.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2018-09-13 16:48:49 +00:00
Tyler Hicks
2f0a773506 utils: Point to the correct Profiles wiki page
The URL redirect ends up at a page in the new wiki that doesn't exist.
We have to link directly to the gitlab URL here since the current URL
redirect doesn't let us use a wiki.apparmor.net URL and still reach the
expected Profiles page.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2018-09-13 16:46:10 +00:00
Tyler Hicks
eb8975e0cc all: Use HTTPS links for apparmor.net
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2018-09-13 16:41:32 +00:00
John Johansen
25f98537db libapparmor: fix readdirfd to memory checks and cleanup on failure
The open-coded readdirfd fn used to replace scandirat skipped
checks for memory allocation failures and cleaning on faulures,
fix this.

Acked-by: Tyler Hicks <tyhicks@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-09-12 16:20:03 -07:00
Patrick Steinhardt
259a4bad50 libapparmor: replace scandirat with open-coded variant
The `scandirat` function is a nonstandard GNU extension, which opens a
directory relative to a file descriptor. musl libc does not implement
that function and thus cannot be used to compile libapparmor.

All our uses of `scandirat` directly scan the directory the file
descriptor is referring to, not any directory beneath the FD. Implement
a function `readdirfd()`, which gets as arguments the directory FD, the
location where to put the list of directory entries as well as a
function pointer to a comparing function. `readdirfd` will then scan all
directory entries except "." and ".." and return them via an allocated
array. The array is sorted in case the comparing function is set.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/107
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-09-12 10:45:58 -07:00
John Johansen
474be603c4 parser: fix cache write message when stdin is used
Using stdin with --write-cache set results in

  # apparmor_parser --show-cache --write-cache
  Cache: added primary location '/var/cache/apparmor'
  Warnung aus stdin (Zeile 1): Cache: added readonly location '/usr/share/apparmor/cache'
  Warnung aus stdin (Zeile 1): apparmor_parser: cannot use or update cache, disable, or force-complain via stdin
  Cache miss: stdin
  Wrote cache: /var/cache/apparmor/9b2cd0d0.0/(null)

The "Wrote cache:" message is referencing a null value and should not
be displayed.

BugLink: http://bugs.launchpad.net/bugs/1787717
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Timeout
2018-09-11 18:31:06 -07:00
John Johansen
c6e704529d Merge branch 'cboltz-php-icu' into 'master'
abstractions/php: allow ICU (unicode support) data tables

See merge request apparmor/apparmor!184

  abstractions/php: allow ICU (unicode support) data tables

  Reported by darix on IRC, and also something I noticed in my own usage of PHP.

  I propose this addition for 2.10..master.

Acked-by: John Johansen <john.johansen@canonical.com>
2018-09-12 00:19:06 +00:00
John Johansen
a75d5503cf Merge branch 'cboltz-pyflakes2' into 'master'
remove unused exception binding in sandbox.py

See merge request apparmor/apparmor!178

Acked-by: John Johansen <john.johansen@canonical.com>
2018-09-12 00:16:30 +00:00
Christian Boltz
ce8038f602 Merge branch 'void' into 'master'
profiles: support void-specific binary names for openntp and traceroute

See merge request apparmor/apparmor!183

Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-09-11 18:41:03 +00:00
Cameron Nemo
6e28a94ace profiles: support void-specific binary names for openntpd, traceroute, and ping 2018-09-11 09:54:33 -07:00
Christian Boltz
e396f9dae9 abstractions/php: allow ICU (unicode support) data tables
Reported by darix on IRC, and also something I noticed in my own usage
of PHP.
2018-09-02 15:46:43 +02:00
John Johansen
770b100102 Merge branch 'cboltz-readme' into 'master'
README: another <pre> fix

See merge request apparmor/apparmor!182

Acked-by: John Johansen <john.johansen@canonical.com>
2018-08-27 21:59:35 +00:00
Christian Boltz
9c539ac3b9 README: another <pre> fix 2018-08-27 23:40:38 +02:00
Christian Boltz
edd9d7e049 Merge branch 'patch-1' into 'master'
README: Fix markup for preformatted text

See merge request apparmor/apparmor!181


Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-08-27 21:32:18 +00:00
林博仁(Buo-ren, Lin)
f9582a1cff README: Fix markup for Preformatted text
Fix concatenated-multiple-lines due to lacking Markdown's linebreak markup
by wrapping it with <pre>.

Signed-off-by: 林博仁(Buo-ren, Lin) <Buo.Ren.Lin@gmail.com>
2018-08-26 10:47:17 +00:00
Christian Boltz
d15bdabaef Remove TODO notes from no-longer-failing tests
simple.pl reported
    TODO passed:   71448, 71459-71460, 71494, 71577

This commit removes the TODO note from the tests that now work as
expected.
2018-08-22 22:24:43 +02:00
Christian Boltz
51482c33f5 remove unused exception binding in sandbox.py
pyflakes 2.0 is more strict and found that 'e' is never used.

References: https://build.opensuse.org/request/show/629206 (comment
section)
2018-08-22 21:23:25 +02:00
John Johansen
657495fa55 parser: add empty config file for parser caching tests
The caching tests will fail if a warning is thrown. Some setups may
not have a parser config file in the default location which results
in the warning
  config file '/etc/apparmor/parser.conf' not found

which causes the tests to fail.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/175
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-21 23:14:52 -07:00
John Johansen
af1818c053 parser: update option parsing so --config-file does not have to be first
Requiring --config-file to be first in the option list is not user
friendly fix the option parsing so that --config-file can be specified
anywhere in the option list.

This also fixes a bug where even when the --config-file option is
first the option parsing fails because the detection logic is broken
for some option cases.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/175
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-21 23:14:52 -07:00
John Johansen
9a8e7e58d2 parser: group parser number of config options together
To help avoid the duplicate option problem in the future sort and group
the config options using numbers at the end of the option table.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/173
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-21 23:14:52 -07:00
John Johansen
3da52f7515 parser: fix collision of --config-file and --compile-features options
Unfortunately both --config-file and --compile-features are using
139 to indicate the feature which breaks one or the other depending
on how the switch state that processes the options is compiled.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/173
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-21 23:14:52 -07:00
John Johansen
49cf515d3c documentation: Add the new AppArmor logo
Add the new AppArmor logo designed by Noah Davis.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/168
Acked-by: Christian Boltz <apparmor@cboltz.de>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-21 21:35:01 -07:00
John Johansen
2c0d7e608c parser: Add fixes to --config-file option
After the config file patch was committed to 2.13 a couple of
improvements were suggested by intrigeri and cboltz. These have
been done as a separate patch so they can be applied to both
dev and 2.13.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/170
Acked-by: Christian Boltz <apparmor@cboltz.de>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-17 08:19:39 -07:00
intrigeri
c052706e0f Merge branch 'fix-cacheloc' into 'master'
parser: fix build warning for assigning default cache location

See merge request apparmor/apparmor!172
2018-08-17 08:31:18 +00:00
John Johansen
e7949d09fa parser: fix build warning for assigning default cache location
The compiler is spitting out the warning

parser_main.c:1291:16: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
    char *tmp = "/var/cache/apparmor";

fix this by constifying the cacheloc array.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-15 13:21:37 -07:00
intrigeri
debf1b28f3 Merge branch 'allow-usr-local-lib-python3' into 'master'
abstractions/python: allow /usr/local/lib/python3

See merge request apparmor/apparmor!171
2018-08-15 14:03:40 +00:00
segfault
548de2f3b8 abstractions/python: allow /usr/local/lib/python3 2018-08-15 15:06:10 +02:00
Vincas Dargis
67816c42cf Add qt5-compose-cache-write abstraction
Qt GUI applications that uses "platforminputcontexts"-class of plugins
might need reading and/or writing compose cache. Add read-only rule in
qt5 abstraction and create new writing dedicated for compose cache
writing.
2018-08-15 13:25:19 +03:00
Vincas Dargis
69c4cabb93 Add qt5-write abstraction
Qt-based applications stores QFileDialog (latest browsed directory) and
other shared user settings inside ~/.config/QtProject.conf. Currently
available qt abstraction only allows to read it (by design), so this
patch introduces abstraction that grants permissions for writing.
2018-08-15 13:02:21 +03:00
John Johansen
b1967c892a parser: allow specifying the parser config file
The parser config file can affect the parsers behavior during tests.
Allow overriding the default location with the option

  --config-file=

the option must be the first option in the commands argument list.

Also provile a
  --print-config-file

option to display what the parser is using for a config file.

BugLink: http://bugs.launchpad.net/bugs/1277711
Acked-by: Christian Boltz <apparmor@cboltz.de>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-14 18:31:10 -07:00
John Johansen
533b4ab5b6 Merge branch 'drg-mods-1' into 'master'
Abstractions need write access to create/update some common config dirs

See merge request apparmor/apparmor!165

Acked-by: John Johansen <john.johansen@canonical.com>
2018-08-14 23:58:25 +00:00
Vincas Dargis
94014c09f0 Add kde-icon-cache-write abstraction
KIconLoader uses ~/.cache/icon-cache.kcache, and it is opened in
read-write mode. Because access to it does not seem to be critical, and
read-only mode is not used, rules for accessing this cache is added to
it's own new "write" abstraction, instead of making kde abstraction more
permissive by default.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-14 16:49:30 -07:00
Vincas Dargis
7345f61e9c Add kde-language-write abstraction
Currently, kde abstraction only allows reading
~/.config/klanguageoverridesrc file (by design). Some KDE applications
has option to change language for it's interface, and this needs write
access. This is fixed by introducing new abstraction.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-14 16:49:16 -07:00
Vincas Dargis
fae93f1b6c Add kde-globals-write abstraction
Currently, kde abstraction only allows reading ~/.config/kdeglobals (by
design), though some applications might need to update it's contents
such as KFileDialog settings. This patch fixes it by introducing new
abstraction.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-14 16:49:07 -07:00
John Johansen
ec86a15322 Merge branch 'recent-documents-write' into 'master'
Add recent-documents-write abstraction

See merge request apparmor/apparmor!163

Acked-by: John Johansen <john.johansen@canonical.com>
2018-08-14 23:26:02 +00:00
Daniel Richard G
7972c038d7 Updated abstractions to allow writing to some common config dirs 2018-08-14 16:38:18 -04:00
Daniel Richard G
094dc741ee Updated abstractions to allow creating some common config dirs 2018-08-14 16:38:18 -04:00
Daniel Richard G
f2c5401ebe sbin.rpc.statd: updated comment to reflect use of prctl()
Acked-by: Christian Boltz <apparmor@cboltz.de>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-13 10:23:28 -07:00
John Johansen
085e2fc1a4 Merge branch 'kde-settings' into 'master'
Update kde abstraction for common settings

See merge request apparmor/apparmor!162

Acked-by: John Johansen <john.johansen@canonical.com>
2018-08-08 05:33:00 +00:00
John Johansen
e76181c4d9 Merge branch 'cboltz-ssl-dehydrated' into 'master'
add dehydrated certificate location to ssl_* abstractions

See merge request apparmor/apparmor!161

Acked-by: John Johansen <john.johansen@canonical.com>
2018-08-08 05:31:39 +00:00
Vincas Dargis
4fe8ae97c4 Add recent-documents-write abstraction
Add abstraction for updating recent documents list.
2018-08-07 23:27:23 +03:00
Vincas Dargis
867442e962 Update kde abstraction for common settings
Add rules to allow reading common KDE-specific settings, used mostly by
native KDE file dialog.
2018-08-07 20:20:08 +03:00
John Johansen
86053c9e38 Merge branch 'cboltz-genprof-readonly-ratelimit' into 'master'
aa-genprof: don't crash if setting printk_ratelimit fails

See merge request apparmor/apparmor!157

Acked-by: John Johansen <john.johansen@canonical.com>
2018-08-07 10:02:25 +00:00
John Johansen
c66a1a972c Merge branch 'cboltz-fix-complain-named-profiles' into 'master'
set_profile_flags(): allow named profiles without attachment

See merge request apparmor/apparmor!142

Acked-by: John Johansen <john.johansen@canonical.com>
2018-08-07 10:00:49 +00:00
John Johansen
9dab5f07f4 Merge branch 'cboltz-change-flags' into 'master'
prevent that aa-complain etc. overwrites flags in child profiles if they differ from the main profile

See merge request apparmor/apparmor!150

Acked-by: John Johansen <john.johansen@canonical.com>
2018-08-07 09:59:39 +00:00
John Johansen
b38e646630 Merge branch 'move-the-binary-cache-to-var-cache' into 'master'
Move the cache to /var/cache

See merge request apparmor/apparmor!156

Acked-by: John Johansen <john.johansen@canonical.com>
2018-08-07 09:57:28 +00:00
John Johansen
4200932d8f Merge branch 'binmerge' into 'master'
profiles: support distributions which merge sbin into bin

Closes #8

See merge request apparmor/apparmor!149

Acked-by: John Johansen <john.johansen@canonical.com>
2018-08-07 09:53:17 +00:00
John Johansen
9c66fa09cb Merge branch 'build-fix_libapparmor_coverity_scan' into 'master'
coverity build: capture separate log files for each coverity invocation

See merge request apparmor/apparmor!145
2018-08-07 09:36:46 +00:00
John Johansen
e4e73e3dc0 Merge branch 'cboltz-notify-pkg' into 'master'
make message about notify-send package cross-distro compatible

See merge request apparmor/apparmor!144

Acked-by: John Johansen <john.johansen@canonical.com>
2018-08-07 09:24:58 +00:00
John Johansen
bc4aa43d64 Merge branch 'cboltz-abstractions-opencl-pocl' into 'master'
Fix typo (double /) in opencl-pocl abstraction

See merge request apparmor/apparmor!158

Acked-by: John Johansen <john.johansen@canonical.com>
2018-08-07 09:16:56 +00:00
Christian Boltz
2e8b902248 add dehydrated certificate location to ssl_* abstractions
I don't use dehydrated myself, therefore this is based on the comments
on https://build.opensuse.org/request/show/533380
2018-08-06 23:15:06 +02:00
Christian Boltz
763a6787d8 Merge branch 'add-path-to-abstractions-python' into 'master'
Allow /usr/local/lib/python3/dist-packages in abstractions/python

See merge request apparmor/apparmor!160

Acked-by: John Johansen <john.johansen@canonical.com>

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.10..master
2018-08-06 18:11:37 +00:00
segfault
6a10f07650 Allow /usr/local/lib/python3/dist-packages in abstractions/python 2018-08-06 19:53:16 +02:00
John Johansen
4011c421db Merge branch 'cboltz-fix-get-profile' into 'master'
Fix unsetting filename in get_profile()

See merge request apparmor/apparmor!140

Acked-by: John Johansen <john.johansen@canonical.com>
2018-08-06 17:34:23 +00:00
Christian Boltz
a054855433 Fix typo (double /) in opencl-pocl abstraction 2018-08-05 17:03:34 +02:00
Christian Boltz
961e69afe5 aa-genprof: don't crash if setting printk_ratelimit fails
When running aa-genprof in a lxd instance, printk_ratelimit is readonly
and writing to it fails. Instead of crashing with a backtrace, only
print a warning.

References: https://bugs.launchpad.net/apparmor/+bug/1785391
2018-08-05 14:46:13 +02:00
Christian Boltz
b4c848c81e Merge branch 'drg-mods-1' into 'master'
Various profile/abstraction updates

See merge request apparmor/apparmor!153

Acked-by: intrigeri <intrigeri@debian.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-08-02 17:17:30 +00:00
intrigeri
ddb256076b Consistently point to the current (Launchpad) issue tracker. 2018-08-02 14:46:14 +00:00
intrigeri
2233818325 Merge branch 'drg-mods-3' into 'master'
Updated README to direct users to the GitLab issue tracker.

See merge request apparmor/apparmor!155
2018-08-02 04:20:59 +00:00
intrigeri
47e38944f3 Merge branch 'drg-mods-2' into 'master'
New abstraction: lsb_release (sub-profile).

See merge request apparmor/apparmor!154
2018-08-02 04:12:13 +00:00
Daniel Richard G
cffaa7a035 Updated README with links to the GitLab AppArmor project. 2018-08-01 23:56:59 -04:00
intrigeri
3d21cf0e32 Move the cache to /var/cache
Let's not store a bunch of automatically generated binary files in /etc.
AppArmor 3.0 will store the cache in /var/cache and most distros
(openSUSE, Debian, and soon Ubuntu) moved it there already.

Bug-Debian: https://bugs.debian.org/904637
2018-08-02 01:18:04 +00:00
Daniel Richard G
99e45b59d3 lsb_release: added permissions needed by openSUSE implementation. 2018-08-01 19:13:26 -04:00
Daniel Richard G
f73514052d New profile: lsb_release (no attachment path)
This will allow removal of the lsb_release sub-profile from the
chromium, firefox and murmurd profiles, and consolidation of the rules
for /usr/bin/lsb_release in a single file.
2018-08-01 19:13:18 -04:00
Daniel Richard G
67728c4f91 usr.sbin.sshd: need write access to Kerberos ticket cache. 2018-08-01 17:39:30 -04:00
Daniel Richard G
0de3d5e14b usr.sbin.lighttpd: minor updates, added Debian/Ubuntu integration.
The integration changes are taken from the patch at
apparmor-2.12/debian/patches/debian/add-debian-integration-to-lighttpd.patch
and are necessary so that lighttpd doesn't serve everything as
application/octet-stream.
2018-08-01 17:39:17 -04:00
Daniel Richard G
e43468c94a usr.sbin.in.fingerd: needs lock access on /run/utmp. 2018-08-01 17:37:11 -04:00
Daniel Richard G
c047abcaf3 sbin.rpc.statd: updated so that it actually works. 2018-08-01 17:36:54 -04:00
Daniel Richard G
ac1d0545f4 ldapclient abstraction: allow rw access to the nslcd socket.
This addresses https://launchpad.net/bugs/1575438 and also the case of
applications accessing the socket directly (due to NSS config).
2018-07-30 22:49:24 -04:00
intrigeri
f30544f185 Merge branch 'flatpak-exports' into 'master'
abstractions/freedesktop.org: treat Flatpak exports the same way as bits shipped by the distro

See merge request apparmor/apparmor!71
2018-07-29 23:39:41 +00:00
intrigeri
aa3022208f tunables/share: make variables value more readable by avoiding the use of too many alternations.
Thanks to Christian Boltz for the suggestion and the patch!
2018-07-29 01:31:39 +00:00
Steve Beattie
4ee50ae1c4 Profiles: Patch usr.sbin.useradd to support usr-merge.
Merge branch 'xnox/apparmor-master'

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/152
2018-07-27 10:25:56 -07:00
Dimitri John Ledkov
e99fa6c605 Patch usr.sbin.useradd to support usr-merge. 2018-07-27 17:05:00 +01:00
intrigeri
34dbe372c5 Rename @{usr_share} → @{system_share_dirs} and @{home_local_share} → @{user_share_dirs}.
Thanks a lot to Simon McVittie for the much better names suggestion.
2018-07-27 06:33:42 +00:00
intrigeri
51f2259c08 freedesktop.org abstraction: refactor (factorize) for consistency.
This change makes the @{home_local_share} rules similar to the
@{usr_share} ones.
2018-07-27 06:28:22 +00:00
intrigeri
aed447aca2 freedesktop.org abstraction: simplify by not attempting to guess the exhaustive list of files that can exist in {~/.local/share,/usr/share}/applications/.
As Simon McVittie wrote, "if a specification or library creates extra caches, or
has .desktop files in a subdirectory, or anything like that, then I don't see
why we wouldn't want to allow reading those too".
2018-07-27 06:26:57 +00:00
intrigeri
9d843b90fe kde abstraction: drop redundant rules for icons access.
These rules are already in abstractions/freedesktop.org that's included
by the abstractions/kde.
2018-07-27 06:22:29 +00:00
intrigeri
0ba94f5a04 freedesktop.org abstraction: treat Flatpak exports the same way as bits shipped by the distro.
As Simon McVittie <smcv@collabora.com> wrote on
https://bugs.debian.org/865206 and on the AppArmor mailing list:

"Anything in /var/lib/flatpak/exports/share or
~/.local/share/flatpak/exports/share is essentially equivalent to
the corresponding path in /usr/{local/,}share, and is something
that has deliberately been "exported" to the rest of the system by a
Flatpak-confined app.

The only reason to prevent reading those directories would be if you do
not want the AppArmor-confined app to be able to enumerate the other
software you have installed on your system, as an anti-fingerprinting
mechanism.".

Bug-Debian: https://bugs.debian.org/865206
2018-07-27 06:22:22 +00:00
intrigeri
160f1027e4 freedesktop.org abstraction: DRY by factorizing duplicated path components with variables.
These alternations will need to grow quite a bit in order to support Flatpak
exports. Let's avoid repeating ourselves too much.
2018-07-27 06:21:40 +00:00
Steve Beattie
b75d19ea79 common/Version: update to show master is deveoping towards 2.14
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2018-07-25 16:10:12 -07:00
Christian Boltz
b00aab0843 let change_profile_flags() change flags in child profiles
... instead of overwriting them with the flags of the main profile.

This fixes a longstanding issue with aa-complain, aa-enforce and
aa-audit which broke the flags of child profiles and hats if they
differed from the main profile.

It also fixes several issues documented in the tests (which obviously
need adjustment to match the fixed behaviour).

Also change the "no profile found" cases to AppArmorException - errors
in a profile are not worth triggering AppArmorBug ;-)
2018-07-25 23:22:33 +02:00
Christian Boltz
d26ffbdd29 change_profile_flags: raise AppArmorBug on empty new flag 2018-07-25 23:21:28 +02:00
Cameron Nemo
9ab45d811e profiles: support distributions which merge sbin into bin
Closes #8
2018-07-25 14:07:35 -07:00
Christian Boltz
c016fc6656 merge set_profile_flags() into change_profile_flags()
(and adjust a few comments in profile_storage.py)
2018-07-25 22:25:38 +02:00
Christian Boltz
abd124c00d rewrite set_profile_flags() tests to use change_profile_flags()
All callers call change_profile_flags(), so it makes sense to test this
function instead of set_profile_flags().

Besides that, set_profile_flags() will be merged into
change_profile_flags() in the next commit ;-)

Note that this commit adds some '# XXX' notes to the tests. These will
be addressed in later commits.
2018-07-25 22:20:48 +02:00
Christian Boltz
4a021ec203 change_profile_flags: use ', ' as flags delimiter
This looks better than a comma without whitespace.

Also adjust minitools_test.py to follow this change.
2018-07-25 21:33:22 +02:00
Christian Boltz
e80caa130a extend add_or_remove_flag() to handle str for old flags
If the old flags are given as str (or None), call split_flags() to
convert them to a list.

This allows to simplify change_profile_flags() which now doesn't need to
call split_flags() on its own.

Also add some tests with a str for the old flags
2018-07-25 20:59:34 +02:00
Christian Boltz
604004c2b6 split off add_or_remove_flag() from change_profile_flags()
Also add some tests for add_or_remove_flag()
2018-07-25 20:44:39 +02:00
Christian Boltz
ce7ea062c5 move splitting flags into profile_storage split_flags() function
... and change change_profile_flags() to use it instead of doing it
itsself

Also add some tests for split_flags()
2018-07-25 20:36:45 +02:00
Christian Boltz
9d78694b00 activate_repo_profiles(): use change_profile_flags
... instead of set_profile_flags() to keep possibly existing flags like
attach_disconnected.

Note that this function is unused (meant to be used with the
no-longer-existing profile repo), therefore nobody noticed that
set_profile_flags() was called with the wrong number of parameters ;-)
2018-07-25 17:41:42 +02:00
intrigeri
d5e72d2ef2 Merge branch 'mesa-shader-lock' into 'master'
mesa abstraction: allow locking .cache/mesa_shader_cache/??/*.

See merge request apparmor/apparmor!148
2018-07-25 07:43:58 +00:00
intrigeri
59865e54c5 mesa abstraction: allow locking .cache/mesa_shader_cache/??/*.
At least Totem needs it on current Debian sid.
2018-07-24 07:21:51 +00:00
Christian Boltz
04e5b9fb8a Merge branch 'wireshark-refresh' into 'master'
Wireshark refresh

See merge request apparmor/apparmor!143

Acked-by: Vincas Dargis <vindrg@gmail.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-07-23 15:17:04 +00:00
Steve Beattie
e162461f9d parser: add missing break in load_profile()
Merge branch 'cboltz-parser-break' into 'master'

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/146
2018-07-17 22:33:50 -07:00
Simon Deziel
8684282a1b usr.bin.wireshark: allow saving pcaps with optional gzip compression 2018-07-17 17:26:34 -04:00
Simon Deziel
b077fccaef usr.bin.wireshark: allow creating QT compose cache 2018-07-17 17:15:15 -04:00
Simon Deziel
70a40566f5 usr.bin.wireshark: restrict hidden file creation under ~/.config/ 2018-07-17 17:14:17 -04:00
Simon Deziel
fa30238293 usr.bin.dumpcap: drop useless/redundant rules 2018-07-17 17:12:44 -04:00
Simon Deziel
e0ba7a4609 usr.bin.wireshark: fix access to configuration profiles 2018-07-17 17:02:28 -04:00
Simon Deziel
bf8222a361 usr.bin.wireshark: add a comment for QtProject.conf rules 2018-07-17 06:15:51 -04:00
Steve Beattie
fed101920b coverity build: capture separate log files for each coverity invocation
Each coverity command writes its debugging output to
cov-int/build-log.txt, which means that multiple runs of cov-build
overwrite previous logs, resulting in only the last invocation's output
remaining at the end of the build, making debugging why failures to
capture coverity output difficult. Fix this by renaming the build-log to
per-directory log files.

(This would still be an issue even if we had a single build command
for the entire tree, as capturing python and other interpreted
files requires a second invocation of cov-build to scan for those
file types.)

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/145
2018-07-13 11:35:45 -07:00
Christian Boltz
c437e9d4a5 add missing 'break' in load_profile()
'case OPTION_OFILE' missed the 'break', which means if did fallthrough
to the default case.

Adding the 'break' means no longer executing another PERROR, and no
longer executing the 'exit(1)' in the default branch.

References: coverity #55994
2018-07-13 15:21:24 +02:00
Simon Deziel
0e38f51aad usr.bin.wireshark: mention that dri rules were backported from abstraction/dri-enumerate 2018-07-13 04:56:42 -04:00
Christian Boltz
44ee1d5090 make message about notify-send package cross-distro compatible
References: https://bugzilla.opensuse.org/show_bug.cgi?id=1100779
2018-07-12 22:00:41 +02:00
Simon Deziel
5a8453fbe0 usr.bin.dumpcap: incorporate feedback from Talkless an cboltz 2018-07-12 05:13:55 -04:00
Simon Deziel
0c0a90be0b usr.bin.wireshark: refresh for 18.04 2018-07-11 12:29:36 -04:00
Simon Deziel
b765dab52e usr.bin.dumpcap: new profile 2018-07-11 12:29:12 -04:00
John Johansen
aa42e33860 kernel-patches: add v4.17-out-of-tree net compatibility patches
Add kernel patches that will NEVER be sent upstream. These provide abi
compatibility with the v2.x network and af_unix rules.

The 4.17 network mediation pull request deliberately broke abi
compatibility with the v2.x rules, and these are provided so that
distros who shipped the v2.x compatible patches can provide new
kernels on older releases that require v2.x network support.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-07-10 22:18:48 -07:00
Christian Boltz
0dca959c6b set_profile_flags(): allow named profiles without attachment
Named profiles can come without an attachment path specified, for
example
    profile foo {...}

This patch fixes set_profile_flags() to actually allow that instead of
erroring out.

References:
- https://bugzilla.opensuse.org/show_bug.cgi?id=1096269 comment #3 and #4
- https://bugs.launchpad.net/apparmor/+bug/1775591
2018-07-10 01:00:00 +02:00
Christian Boltz
73b33bdf36 Fix unsetting filename in get_profile()
When creating a new profile with aa-genprof, get_profile() searches for
an inactive ("extra") profile and, if it finds one, removes the filename
from that profile so that it gets stored in /etc/apparmor.d/ later.

However, it used .pop() to remove the filename, which explodes since
ProfileStorage is a class now.

This patch fixes this (tested manually).
2018-07-03 18:34:23 +02:00
Steve Beattie
8fc0ff7ffc utils: cleanup serialize_profile() and its callers
Merge branch 'cboltz-cleanup-serialize-profile'

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/138
2018-06-29 15:21:24 -07:00
Steve Beattie
640556637f adjust abstractions/python for python 3.7
Merge branch 'cboltz-python-version' into 'master'

Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/139/
2018-06-29 18:15:47 +00:00
Christian Boltz
01f41fbff8 adjust abstractions/python for python 3.7
Python 3.7 was released yesterday - and to make the abstraction
future-proof, also cover 3.8 and 3.9 in advance ;-)
2018-06-28 13:34:08 +02:00
Christian Boltz
e5ffa6815c Merge branch 'mesa' into 'master'
Add mesa abstraction

See merge request apparmor/apparmor!137


Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-06-27 19:11:06 +00:00
Christian Boltz
b613860f14 serialize_profile: simplify setting of include_flags
Note that NO_FLAGS was an inverse option, therefore
- NO_FLAGS was changed to FLAGS (also in sync_profile() which is the
  only caller that sets FLAGS)
- the default for include_flags (if FLAGS is not set) is True
2018-06-25 22:55:26 +02:00
Christian Boltz
9865e112f7 serialize_profile(): simplify setting include_metadata 2018-06-25 22:47:30 +02:00
Christian Boltz
5ef95fff4f serialize_profile(): add type check for options
This makes the "if options:" check superfluous, therefore remove it and
change the whitespace of the following lines
2018-06-25 22:43:39 +02:00
Christian Boltz
7e42135010 fix serialize_profile() calls to always use a dict for options 2018-06-25 21:42:29 +02:00
Christian Boltz
db7983aee5 simplify setting serialize_options 2018-06-25 21:39:47 +02:00
Vincas Dargis
a0c719df73 Add mesa abstraction
Add mesa abstraction to allow writing to the Mesa-specific cache
locations and listing devices. Abstraction is needed for applications
utilizing OpenGL API with Mesa implementation available on the system.
2018-06-23 17:07:05 +03:00
Christian Boltz
b7a4f37cbb Merge branch 'cboltz-nested-child-error' into 'master'
parse_profile_start(): Error out on nested child profiles

See merge request apparmor/apparmor!136

Acked-by: John Johansen <john.johansen@canonical.com> for 2.10..master
2018-06-21 10:20:03 +00:00
Christian Boltz
82eb749b6f Merge branch 'cboltz-view-changes' into 'master'
use serialize_profile() for the new profile in (V)iew Changes

See merge request apparmor/apparmor!131

Acked-by: John Johansen <john.johansen@canonical.com>
2018-06-21 10:19:12 +00:00
Christian Boltz
f7ed8257c3 Merge branch 'cboltz-gitignore' into 'master'
add utils/test/common_test.pyc to gitignore

See merge request apparmor/apparmor!135

Acked-by: John Johansen <john.johansen@canonical.com>
2018-06-20 20:55:30 +00:00
Christian Boltz
48d7692c05 Merge branch 'cboltz-systemd-cache-loc' into 'master'
Adjust cache paths in apparmor.service

See merge request apparmor/apparmor!134

Acked-by: John Johansen <john.johansen@canonical.com>
2018-06-20 20:54:51 +00:00
Christian Boltz
6c8fff099f Merge branch 'cboltz-simplify-write-vars' into 'master'
simplify write_list_vars()

See merge request apparmor/apparmor!130

Acked-by: John Johansen <john.johansen@canonical.com>
2018-06-20 15:52:02 +00:00
Christian Boltz
50aa8204c9 Merge branch 'cboltz-ruleset-tests' into 'master'
add some tests for BaseRule/BaseRuleset

See merge request apparmor/apparmor!132

Acked-by: John Johansen <john.johansen@canonical.com>
2018-06-20 15:51:13 +00:00
Christian Boltz
e5eff3bbee Merge branch 'cboltz-apache-stapling' into 'master'
fix path for apache2 stapling-cache

See merge request apparmor/apparmor!133

Acked-by: John Johansen <john.johansen@canonical.com>
2018-06-20 15:50:28 +00:00
Christian Boltz
8462c39b14 parse_profile_start(): Error out on nested child profiles
The tools can't handle nested child profiles yet. Instead of failing
in funny[tm] ways (parse_profile_start() only returned the first two
segments of the profile name) better error out with a clear message.
2018-06-20 14:43:48 +02:00
Christian Boltz
63d17ecf16 add utils/test/common_test.pyc to gitignore
(cache file that gets created when running the tests with python2)
2018-06-19 15:27:16 +02:00
Christian Boltz
1185df3c65 fix path for apache2 stapling-cache
... to match the default apache settings

See also the discussion on the mailinglist:
https://lists.ubuntu.com/archives/apparmor/2018-June/011688.html
2018-06-17 16:16:22 +02:00
Christian Boltz
3a9b0fd74a Adjust cache paths in apparmor.service
The initial apparmor.service assumed the profile cache is in
/var/lib/apparmor/ which was an openSUSE-specific path that was chosen
for historical reasons, but was far from perfect.

In the meantime, the profile cache moved to /var/cache/apparmor/ and the
read-only/packaged version was added in /usr/share/apparmor/cache/

This commit adjusts apparmor.service to use these paths.
2018-06-16 23:14:19 +02:00
Christian Boltz
2312873406 add some tests for BaseRule/BaseRuleset
These tests verify that
- _is_equal_aare() really raises an exception when it sees an invalid
  combination of other_value and other_all
- BaseRuleset.__repr__() works as expected

As a side effect, this commit pushes the test coverage of
apparmor/rule/__init__.py to 100% ;-)
2018-06-09 20:53:53 +02:00
Christian Boltz
82fc0b8239 delete now unused serialize_parse_profile_start()
(another function that was only used by
serialize_profile_from_old_profile())

Also delete the tests we had for that function.
2018-06-09 15:27:26 +02:00
Christian Boltz
0eb12a8cbd delete serialize_profile_from_old_profile()
... which is unused since the last commit.

Also delete several functions that were only used by this function:
- write_change_profile()
- write_rlimits()
- write_capabilities()
- write_netdomain()
- write_dbus()
- write_signal()
- write_ptrace()
- write_file()

Finally, no longer import some functions from profile_storage:
- write_links
- write_mount
- write_pivot_root
- write_unix

BTW: Deleting these 460 lines improves test coverage of aa.py from
38% to 44%, and total test coverage from 63% to 66% :-)
2018-06-09 15:13:50 +02:00
Christian Boltz
469eb444de use serialize_profile() for the new profile in (V)iew Changes
... instead of serialize_profile_from_old_profile()

This will give a realistic preview of the changes (serialize_profile()
is also used when actually writing the profile) and replaces the
known-buggy serialize_profile_from_old_profile() with known-working
code.

It also fixes the issue reported in
    https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1528139
which means we no longer need the workaround of catching AttributeError
(verified in manual before/after test)

References:
- https://bugs.launchpad.net/apparmor/+bug/1394788
- https://bugs.launchpad.net/bugs/1528139
- https://bugs.launchpad.net/apparmor/+bug/1404893
2018-06-09 15:10:07 +02:00
Christian Boltz
af9490556d get rid of superfluous variables in write_list_vars()
- rename prof_data parameter to ref
- drop empty allow, prefix and tail, and their usage in the format
  string
- inline sep into the format string
- replace usage of fn with the actual function name (var_transform)
2018-05-31 22:09:26 +02:00
Christian Boltz
5ae94391c5 inline set_ref_allow() into write_list_vars()
set_ref_allow() is only used by write_list_vars(). Inline it (actually
only the used, boring if branch) to simplify the code.
2018-05-31 22:00:50 +02:00
Christian Boltz
06eb65eb50 inline write_pair() into write_list_vars()
write_pair() is only used by write_list_vars(), so there's no need to
keep it as a separate function
2018-05-31 22:00:50 +02:00
Christian Boltz
c2a420d32b let var_transform() sort variable content
This is needed to get a reproducible output.

Also adjust the tests in test-profile-storage.py and add some example
variable to cleanprof.in and cleanprof.out
2018-05-31 22:00:36 +02:00
John Johansen
288ae9049a opensuse 2018 conference presentation
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-05-31 11:03:01 -07:00
Tyler Hicks
d038eea1be Merge branch 'aa-exec-fixups' into 'master'
aa-exec fixups

See merge request apparmor/apparmor!129
2018-05-31 17:51:36 +00:00
Tyler Hicks
379239b024 Merge branch 'aa-exec-pid' into 'master'
aa-exec: Prepend [PID] to all error, debug, and verbose messages

See merge request apparmor/apparmor!128
2018-05-31 17:44:42 +00:00
Tyler Hicks
95286bb9e7 aa-exec: Clarify ENOENT and EACCES errors when changing profiles
The aa-exec tool was indicating, in an error message, that a profile
didn't exist in cases where aa_change_profile() failed with errno set to
ENOENT or EACCES. However, the EACCES error means that changing to the
target profile is not allowed. This patch fixes the error message in the
cause of EACCES:

 $ ./aa-exec -p dne -- true
 aa-exec: ERROR: profile 'dne' does not exist

 $ ./aa-exec -p /usr/sbin/tcpdump -- ./aa-exec -p unconfined -- true
 aa-exec: ERROR: insufficient permissions to change to the profile 'unconfined'

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2018-05-31 17:37:55 +00:00
Tyler Hicks
652dac0cec aa-exec: Remove extra newline when profile changes fail
An extra newline was being printed when aa_change_profile() failed and
errno was ENOENT or EACCES.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2018-05-31 17:27:00 +00:00
Tyler Hicks
00800cb905 aa-exec: Prepend [PID] to all error, debug, and verbose messages
Add the pid of the process to the error, debug, and verbose output. This
is useful for debugging.

For example,

 $ aa-exec -v -- whoami
 [30389] exec whoami
 tyhicks

 $ aa-exec -p dne -- true
 [30390] aa-exec: ERROR: profile 'dne' does not exist

 $ aa-exec -d -p unconfined -- true
 [30409] aa-exec: DEBUG: 0 = aa_change_onexec("unconfined")

It can also help when multiple aa-exec invocations are used across a
fork and exec. Here's a contrived example:

 $ aa-exec -v -- \
   sh -c 'aa-exec -vp /usr/sbin/tcpdump -- aa-exec -p unconfined -- true'
 [3424] exec sh -c aa-exec -vp /usr/sbin/tcpdump -- aa-exec -p unconfined -- true
 [3425] aa_change_onexec("/usr/sbin/tcpdump")
 [3425] exec aa-exec -p unconfined -- true
 [3425] aa-exec: ERROR: profile 'unconfined' does not exist

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2018-05-31 17:04:20 +00:00
John Johansen
c9d341782e Merge branch 'cboltz-move-write-methods' into 'master'
Cboltz move write methods

See merge request apparmor/apparmor!122
2018-05-25 12:38:12 +00:00
John Johansen
097ff0fa6b Merge branch 'cboltz-drop-safety-nets' into 'master'
Drop some safety nets in aa.py

See merge request apparmor/apparmor!113
2018-05-25 12:34:28 +00:00
Jamie Strandboge
0c7c34c6f1 Merge branch 'vulkan' into 'master'
Add Vulkan abstraction

See merge request apparmor/apparmor!126
2018-05-22 21:45:31 +00:00
Vincas Dargis
47520931be Add Vulkan abstraction
Add abstraction for Vulkan API specific file paths.
2018-05-22 21:48:13 +03:00
Jamie Strandboge
c1431bc2de Merge branch 'nvidia-app-profiles' into 'master'
Update nvidia for reading application profiles

See merge request apparmor/apparmor!125
2018-05-22 18:24:19 +00:00
Vincas Dargis
f2e0fdc72b Update nvidia for reading application profiles
Add file rule to allow reading application profiles for NVIDIA
Linux graphics driver.
2018-05-22 20:43:56 +03:00
John Johansen
8e4ee696c3 Merge branch 'opencl' into 'master'
Add OpenCL abstractions

See merge request apparmor/apparmor!124
2018-05-13 20:14:15 +00:00
Vincas Dargis
8237d6e776 Add OpenCL abstractions 2018-05-13 20:14:15 +00:00
Steve Beattie
ab94074887 misc: add initial gitlab-ci.yml for running build/tests
This commit adds an initial gitlab-ci.yml file to perform test builds
and run tests on each commit.

v2: add liblocale-gettext-perl dependency for parser simple test
v3:
  - set noninteractive prompt to avoid debconf queries when installing
    packages
  - disable profiles test against aa-logprof; even if library and python
    path issues are resolved, aa-logprof early aborts due to being
    unable to find /sbin/apparmor_parser

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Tyler Hicks <tyler.hicks@canonical.com>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/101
2018-05-11 19:02:36 -07:00
Christian Boltz
79d9ee5c3b test-libapparmor-test_multi: initialize parent profiles
If a log line contains a denial for a child profile, log_dict will
(obviously) only contain the child profile. However, serialize_profile()
expects that the parent profile is also initialized as ProfileStorage.

This patch makes sure the parent profile gets initialized.

It also removes 26 of the 37 reasons in the TODO note in aa.py :-)
2018-05-10 12:44:04 +02:00
Steve Beattie
3b7c08e2b9 gitignore: add libapparmor/src/PMurHash.{o,lo}
Merge remote-tracking branch 'cboltz/cboltz-libapparmor-gitignore' from
Christian Boltz.

Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/123/
2018-05-09 14:43:00 -07:00
Christian Boltz
db92d96e68 add libapparmor/src/PMurHash.{o,lo} to gitignore 2018-05-09 23:03:03 +02:00
Jamie Strandboge
d1984706c8 Merge branch 'cboltz-samba-profiles-boo1092099' into 'master'
Update samba profiles

See merge request apparmor/apparmor!121
2018-05-09 20:48:35 +00:00
Christian Boltz
fbfeed0b65 Add get_rules_clean to ProfileStorage, and change write_rules to use it
ProfileStorage.get_rules_clean() returns all rules in a profile
(withouth the profile header or the closing '}')

Also change aa.py write_rules() to use get_rules_clean()
2018-05-09 22:36:38 +02:00
Christian Boltz
66620f3e19 move several write_* functions to apparmor.profile_storage
ProfileStorage() stores the content of a profile, so it makes sense to
also have the functions to write those rules (including helper functions
used by these functions) in the same file.

Note that I only moved the functions for rule types that are not handled
by *Ruleset classes.

The functions for writing rules stored in a *Ruleset class will
hopefully be superfluous sooner or later (probably later because
serialize_parse_profile_start() depends on them, and rewriting it won't
be easy)

Also move the test for var_transform() to test-profile-storage.py.
2018-05-09 22:23:34 +02:00
Patrick Steinhardt
655d3e7826 parser: provide typedefs for comparison_fn_t and __free_fn_t
The POSIX standard never defines the typedefs `comparison_fn_t` and
`__free_fn_t`, but they are provided by glibc and user in the parsing
code. Provide the typedefs ourselves to fix compiling on musl based
systems.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2018-05-09 13:15:42 -07:00
Patrick Steinhardt
778176b9d8 libapparmor: do not honor $LIBAPPARMOR_DEBUG when secure_getenv is undefined
The `secure_getenv` function is a non-POSIX compliant extension of
glibc. In contrast to the POSIX `getenv`, `secure_getenv` will return
`NULL` for all environment variables when the program is run with
escalated privileges due to an SUID or SGID bit. Some strictly
POSIX-compliant libc libraries, most notably musl libc, do not have this
function and do not wish to implement it. Thus, AppArmor cannot be
compiled on such systems.

In libapparmor, `secure_getenv` is only used to determine whether the
environment variable DEBUG_ENV_VAR has been set to enable debugging. In
case an unprivileged user runs a SUID/SGID executable linked against
libapparmor, we do not want that user to be able to get additional
information via debug output.

The fix here is to produce an error only in case where debug output is
enabled by defining ENABLE_DEBUG_OUTPUT. Otherwise, we simply define
`secure_getenv` to `NULL` to completely disable the debug output.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2018-05-09 13:15:42 -07:00
Patrick Steinhardt
1506f2cf0e libapparmor: make aa_policy_cache_add_ro_dir function visible
While the parser makes use of the `aa_policy_cache_add_ro_dir` function,
it is not being declared as a global function in the libapparmor.map
file. Due to this, dynamic linking of apparmor_parser with
libapparmor.so is not possible.

[Fixed up to use 2.13.1 symbol section as when the
 `aa_policy_cache_add_ro_dir` was introduced -- @smb]

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>

PR: https://gitlab.com/apparmor/apparmor/merge_requests/107
2018-05-09 13:14:21 -07:00
Christian Boltz
c47ed1d2e5 add more rule types to test/cleanprof.* profile 2018-05-09 22:04:04 +02:00
Christian Boltz
23b5f29b80 Update samba profiles
- allow smbd to load new shared libraries
- allow winbindd to read and write new kerberos cache location

Based on a patch by "Samuel Cabrero" <scabrero@suse.com>

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1092099
2018-05-09 21:00:30 +02:00
Rasmus Thomsen
7c86a2acaf parser: allow using a custom sbin & usr/sbin dir
This is especially handy if your distro doesn't split sbin and bin
and only wants to install into bin (so that the sbin directory doesn't
clash with the sbin -> bin symlink)

[Per feedback, added USR_SBINDIR as a toggle for the install location
 of aa-teardown -- @smb]

Signed-off-by: Rasmus Thomsen <cogitri@exherbo.org>
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/111/
2018-05-08 09:09:24 -07:00
Steve Beattie
6a2b90ba56 utils: rewrite write_alias()
Merge remote-tracking branch 'cboltz/cboltz-rewrite-write_alias' from
Christian Boltz

Acked-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/120/
2018-05-08 08:26:20 -07:00
Steve Beattie
0b259753b8 utils: fix writing alias rules
Merge remote-tracking branch 'cboltz/cboltz-fix-write-alias' from
Christian Boltz.

Acked-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/119
2018-05-08 07:46:20 -07:00
Steve Beattie
c639836d1a utils: test-libapparmor-test_multi.py: allow to parse a specific logfile
Merge branch cboltz-test-libapparmor-allow-single from Christian Boltz

Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/118
2018-05-06 23:55:27 -07:00
Steve Beattie
3f92d285f9 utils: fix writing "link subset" rules
Merge branch 'cboltz-utils-fix-link-subset' from Christian Boltz

Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/117
2018-05-06 22:26:23 -07:00
Steve Beattie
434c3f2264 utils: parse_profile_data(): error out on alias inside profile
Merge branch 'cboltz-strict-parse-alias' frim Christian Boltz
 
Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/116
2018-05-06 22:10:53 -07:00
Steve Beattie
f29eb7d9d4 utils: simplify write_piece in aa.py
Merge branch cboltz-simplify-write-piece from Christian Boltz.

Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/114/
2018-05-06 12:26:16 -07:00
Christian Boltz
3ee6058050 rewrite write_alias()
Instead of calling write_pair() (which is quite complex because it needs
to handle multiple rule types), write the alias rules directly in
write_alias().

This comes with minor code duplication, but makes the code much more
readable (3 instead of 7 %s)
2018-05-06 20:07:28 +02:00
Christian Boltz
ae4ab62855 Fix writing alias rules
write_pair() ignored the 'tail' parameter, which resulted in writing
invalid alias rules (without the trailing comma).

Also add an alias to test/cleanprof.* to ensure it doesn't break again.
2018-05-06 19:38:38 +02:00
Christian Boltz
0bc6078cfd test-libapparmor-test_multi.py: allow to parse a specific logfile
test-libapparmor-test_multi.py converts the libapparmor test_multi log
examples to profiles.

This patch allows to call test-libapparmor-test-multi.py with a logfile
(containing a single log line) as parameter. It will then print the
resulting profile.

Example:

  # python3 test-libapparmor-test_multi.py /path/to/libraries/libapparmor/testsuite/test_multi/testcase_dbus_01.in
  /tmp/apparmor-2.8.0/tests/regression/apparmor/dbus_service {
    dbus send bus=session path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=Hello peer=(label=unconfined),

  }
2018-05-06 17:59:18 +02:00
Christian Boltz
514535608f Fix writing "link subset" rules
Writing a "link subset" rule missed a space, which resulted in something
like
  link subset/foo -> /bar,

Also add a test rule to tests/cleanprof.* to ensure this doesn't break
again.
2018-05-06 14:56:45 +02:00
Christian Boltz
f910cb5559 parse_profile_data(): error out on alias inside profile
Defining an alias is only allowed outside of a profile.

Also add a parser test with an alias inside a profile.
2018-05-06 14:27:32 +02:00
Steve Beattie
eca16ae6cf aa-teardown: Replace /bin/bash with /bin/sh
Merge branch 'remove-unnecessary-bash' from Robert Joslyn

Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/115
2018-05-05 23:25:54 -07:00
Robert Joslyn
dbd6591e2f aa-teardown: Replace /bin/bash with /bin/sh
The script does not require bash, a POSIX shell is sufficient. This
removes bash as a runtime dependency of the parser.
2018-05-05 17:46:19 -07:00
Christian Boltz
2b7920ffec simplify write_piece
write_piece() has some funny code that converts the result of
write_header() and write_rules() (which is a list) to... a list.

Needless to say that this is superfluous ;-)
2018-05-05 21:22:10 +02:00
Christian Boltz
62e429bc4b Drop some safety nets in aa.py
match_includes() and is_known_rule() have safety nets to avoid troube if
include[incname][incname] is not a valid ProfileStorage object.
However, this situation shouldn't happen in practise anymore, so let's
drop these now superfluous safety nets.

I use this patch locally since months without problems.
2018-05-05 20:58:34 +02:00
Steve Beattie
9f2959482f libapparmor: do not purge PMurHash.h on maintainerclean
Commit 63b7cb0660 (libapparmor: convert
multicache from using djb2 hashing to murmur3 hash) mistakenly added
PmurHash.h to the list of files generated by the build process and thus
should be removed when the 'maintainerclean' make target is invoked.
This fixes the issue by removing PmurHash.h from the list of generated
files.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>

PR: https://gitlab.com/apparmor/apparmor/merge_requests/112
2018-05-03 14:09:17 -07:00
Steve Beattie
e87a662efc swap regression test: fix swap permissions warning
When running the swap regression tests, the swapon command would issue
a warning about insecure permissions on the swapfile being used as
part of the test:

  mkswap: /tmp/sdtest.9698-822-2BL034/swapfile: insecure permissions 0644, 0600 suggested.

Fix this by setting the permissions after the swapfile is created.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>

PR: https://gitlab.com/apparmor/apparmor/merge_requests/108
2018-04-30 13:48:13 -07:00
Steve Beattie
49ba6af2bf mount regression test: convert mount test to use MS_NODEV
The mount regression test passes MS_MANDLOCK to the mount(2) syscall in
the test program. When the kernel is configured without
CONFIG_MANDATORY_FILE_LOCKING set, attempting to mount a filesystem with
this option always fails with EPERM. To fix, convert the test program to
use the MS_NODEV option instead.

Bug: https://bugs.launchpad.net/apparmor/+bug/1765025
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>

PR: https://gitlab.com/apparmor/apparmor/merge_requests/109
2018-04-30 13:25:44 -07:00
Jamie Strandboge
7bd3029f25 Merge branch 'update-fonts' into 'master'
Update fonts for Debian and openSUSE

See merge request apparmor/apparmor!96
2018-04-30 10:03:22 +00:00
John Johansen
67d84c8959 Merge branch 'cboltz-utils-exclude-cache-d' into 'master'
is_skippable_dir(): add 'cache.d' to exclude list

See merge request apparmor/apparmor!110

Acked-by: John Johansen <john.johansen@canonical.com>
2018-04-30 05:07:07 +00:00
Christian Boltz
5b9497a8c6 is_skippable_dir(): add 'cache.d' to exclude list
This excludes the /etc/apparmor.d/cache.d/ directory from aa-logprof
parsing because parsing the binary cache, well, takes a while :-/

Reported on the opensuse-factory mailinglist by Frank Krüger and
confirmed by others.
2018-04-30 00:57:52 +02:00
John Johansen
e83fa67edf parser: fix failures due to -M only setting compile-features
Split the features file into compile features and kernel features
which is needed for policy versioning and the new caching scheme.

A new flag --kernel-features was added to set the kernel features but
unfortunately -M, --features-file was setup to only specify the
compile features, when it used to effectively specify both the
compile and kernel features.

This broke existing uses of -M.

Fix this by having -M specify both the compile and kernel features,
and a new flag --compile-features that can be used to specify the
compile fature set separate from the kernel feature set.

sbeattie> fixed up error message to refer to compile features when
--compile-features argument fails.

Fixes: 9e48a5da5e ("parser: split kernel features from compile features.")
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>

PR: https://gitlab.com/apparmor/apparmor/merge_requests/104
2018-04-25 22:16:57 -07:00
John Johansen
b08b327922 libapparmor: fix failure to create missing cache dir
The refactor unfortunately changed dirfd to fd on one mkdirat, but
fd is always invalid at this point resulting in the parser reporting

Failed setting up policy cache (../profiles/cache/): Bad file descriptor

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/103
2018-04-25 20:09:05 -07:00
John Johansen
c82fcd227d libapparmor: Fix build failure when enable-debug-output=yes
The code refactoring didn't update some debug messages. Update to
keep the debug messages and add a few extra while we are at it.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/103
2018-04-25 20:08:44 -07:00
Steve Beattie
987cc4af3a parser: fix permissions of apparmor.systemd helper script
Merge branch 'cboltz-fix-apparmor-systemd-perms'

Acked-by: Steve Beattie <steve@nxnw.org>

Bug: https://bugzilla.opensuse.org/show_bug.cgi?id=1090545
PR: https://gitlab.com/apparmor/apparmor/merge_requests/106
2018-04-25 15:41:52 -07:00
John Johansen
48a32b78b1 parser: Add the ability to turn off jobs to ease with debugging
The parser currently uses a fork model to do job processing. For
consistency even when the number of jobs is set to 1 a single
work process is forked. However this makes using gdb more difficult
and can be even worse for other debugging tools.

Make -j 0 disable all job spawning so all processing happens in the
main process.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/105

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2018-04-25 15:26:11 -07:00
Christian Boltz
f179612abe fix permissions of apparmor.systemd helper script
References: https://bugzilla.opensuse.org/show_bug.cgi?id=1090545
2018-04-23 18:01:52 +02:00
Steve Beattie
06d9a8eff0 libapparmor: fix reallocarray FTBFS w/older glibc
The recently added overlay cache directory support added to libapparmor
makes use of reallocarray(3) to resize memory allocations; however,
reallocarray() was only included in glibc 2.26. This commit adds a
configure check for reallocarray() and if it's not available, provides
it as a wrapper around realloc(3).

PR: https://gitlab.com/apparmor/apparmor/merge_requests/100
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2018-04-18 21:08:03 -07:00
Christian Boltz
3009b22aec Merge branch 'qt5' into 'master'
Add qt5 abstraction

See merge request apparmor/apparmor!99

Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-04-18 22:18:30 +00:00
Vincas Dargis
b902d2505d Update fonts for Debian and openSUSE
* Allow to read conf-avail dir itself.
* Add various openSUSE-specific font config directories.
2018-04-18 19:16:29 +03:00
Vincas Dargis
6a85ffe00e Add qt5 abstraction
Create abtractions/qt5 with common rules needed for Qt5-based
applications.
2018-04-18 19:12:28 +03:00
John Johansen
ae20ee6036 Merge branch 'cboltz-teardown-path' into 'master'
install aa-teardown to /usr/sbin, not /sbin

See merge request apparmor/apparmor!97

Acked-by: John Johansen <john.johansen@canonical.com>
2018-04-15 21:36:57 +00:00
Christian Boltz
62ecc2b574 install aa-teardown to /usr/sbin, not /sbin
Looks like I used a wrong path when upstreaming aa-teardown :-(
(openSUSE always used /usr/sbin/aa-teardown)
2018-04-15 23:28:41 +02:00
1090 changed files with 51003 additions and 34647 deletions

46
.gitignore vendored
View File

@@ -4,10 +4,17 @@ binutils/aa-enabled
binutils/aa-enabled.1
binutils/aa-exec
binutils/aa-exec.1
binutils/aa-features-abi
binutils/aa-features-abi.1
binutils/aa-status
binutils/aa-status.8
binutils/cJSON.o
binutils/po/*.mo
parser/po/*.mo
parser/af_names.h
parser/cap_names.h
parser/generated_cap_names.h
parser/generated_af_names.h
parser/tst_lib
parser/tst_misc
parser/tst_regex
@@ -23,6 +30,7 @@ parser/af_rule.o
parser/af_unix.o
parser/common_optarg.o
parser/dbus.o
parser/default_features.o
parser/lib.o
parser/libapparmor_re/aare_rules.o
parser/libapparmor_re/chfa.o
@@ -63,7 +71,8 @@ parser/techdoc.aux
parser/techdoc.log
parser/techdoc.pdf
parser/techdoc.toc
profiles/apparmor.d/local/*.*
profiles/apparmor.d/local/*
!profiles/apparmor.d/local/README
libraries/libapparmor/Makefile
libraries/libapparmor/Makefile.in
libraries/libapparmor/aclocal.m4
@@ -94,6 +103,8 @@ libraries/libapparmor/src/.deps
libraries/libapparmor/src/.libs
libraries/libapparmor/src/Makefile
libraries/libapparmor/src/Makefile.in
libraries/libapparmor/src/PMurHash.lo
libraries/libapparmor/src/PMurHash.o
libraries/libapparmor/src/af_protos.h
libraries/libapparmor/src/change_hat.lo
libraries/libapparmor/src/features.lo
@@ -149,6 +160,7 @@ libraries/libapparmor/swig/perl/libapparmor_wrap.c
libraries/libapparmor/swig/perl/libapparmor_wrap.o
libraries/libapparmor/swig/perl/pm_to_blib
libraries/libapparmor/swig/python/LibAppArmor.py
libraries/libapparmor/swig/python/LibAppArmor.egg-info/
libraries/libapparmor/swig/python/build/
libraries/libapparmor/swig/python/libapparmor_wrap.c
libraries/libapparmor/swig/python/Makefile
@@ -160,8 +172,14 @@ libraries/libapparmor/swig/python/test/test-suite.log
libraries/libapparmor/swig/python/test/test_python.py
libraries/libapparmor/swig/python/test/test_python.py.log
libraries/libapparmor/swig/python/test/test_python.py.trs
libraries/libapparmor/swig/ruby/LibAppArmor.so
libraries/libapparmor/swig/ruby/LibAppArmor_wrap.c
libraries/libapparmor/swig/ruby/LibAppArmor_wrap.o
libraries/libapparmor/swig/ruby/Makefile
libraries/libapparmor/swig/ruby/Makefile.in
libraries/libapparmor/swig/ruby/Makefile.bak
libraries/libapparmor/swig/ruby/Makefile.ruby
libraries/libapparmor/swig/ruby/mkmf.log
libraries/libapparmor/testsuite/.deps
libraries/libapparmor/testsuite/.libs
libraries/libapparmor/testsuite/Makefile
@@ -187,13 +205,22 @@ utils/*.tmp
utils/po/*.mo
utils/apparmor/*.pyc
utils/apparmor/rule/*.pyc
utils/apparmor.egg-info/
utils/build/
utils/htmlcov/
utils/test/common_test.pyc
utils/test/.coverage
utils/test/coverage-report.txt
utils/test/htmlcov/
utils/vim/apparmor.vim
utils/vim/apparmor.vim.5
utils/vim/apparmor.vim.5.html
utils/vim/pod2htmd.tmp
tests/regression/apparmor/*.o
tests/regression/apparmor/aa_policy_cache
tests/regression/apparmor/access
tests/regression/apparmor/at_secure
tests/regression/apparmor/attach_disconnected
tests/regression/apparmor/changehat
tests/regression/apparmor/changehat_fail
tests/regression/apparmor/changehat_fork
@@ -208,6 +235,10 @@ tests/regression/apparmor/chgrp
tests/regression/apparmor/chmod
tests/regression/apparmor/chown
tests/regression/apparmor/clone
tests/regression/apparmor/dbus_eavesdrop
tests/regression/apparmor/dbus_message
tests/regression/apparmor/dbus_service
tests/regression/apparmor/dbus_unrequested_reply
tests/regression/apparmor/deleted
tests/regression/apparmor/env_check
tests/regression/apparmor/environ
@@ -218,7 +249,10 @@ tests/regression/apparmor/fchdir
tests/regression/apparmor/fchgrp
tests/regression/apparmor/fchmod
tests/regression/apparmor/fchown
tests/regression/apparmor/fd_inheritance
tests/regression/apparmor/fd_inheritor
tests/regression/apparmor/fork
tests/regression/apparmor/introspect
tests/regression/apparmor/link
tests/regression/apparmor/link_subset
tests/regression/apparmor/mkdir
@@ -229,15 +263,20 @@ tests/regression/apparmor/net_raw
tests/regression/apparmor/open
tests/regression/apparmor/openat
tests/regression/apparmor/pipe
tests/regression/apparmor/pivot_root
tests/regression/apparmor/ptrace
tests/regression/apparmor/ptrace_helper
tests/regression/apparmor/pwrite
tests/regression/apparmor/query_label
tests/regression/apparmor/readdir
tests/regression/apparmor/rename
tests/regression/apparmor/rw
tests/regression/apparmor/socketpair
tests/regression/apparmor/swap
tests/regression/apparmor/symlink
tests/regression/apparmor/syscall_chroot
tests/regression/apparmor/syscall_ioperm
tests/regression/apparmor/syscall_iopl
tests/regression/apparmor/syscall_mknod
tests/regression/apparmor/syscall_mlockall
tests/regression/apparmor/syscall_ptrace
@@ -249,10 +288,15 @@ tests/regression/apparmor/syscall_setscheduler
tests/regression/apparmor/syscall_sysctl
tests/regression/apparmor/sysctl_proc
tests/regression/apparmor/tcp
tests/regression/apparmor/transition
tests/regression/apparmor/unix_fd_client
tests/regression/apparmor/unix_fd_server
tests/regression/apparmor/unix_socket
tests/regression/apparmor/unix_socket_client
tests/regression/apparmor/unlink
tests/regression/apparmor/uservars.inc
tests/regression/apparmor/xattrs
tests/regression/apparmor/xattrs_profile
tests/regression/apparmor/coredump
**/__pycache__/
*.orig

139
.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,139 @@
---
image: ubuntu:latest
# XXX - add a deploy stage to publish man pages, docs, and coverage
# reports
stages:
- build
- test
.ubuntu-before_script:
before_script:
- export DEBIAN_FRONTEND=noninteractive
- apt-get update -qq
- apt-get install --no-install-recommends -y gcc perl liblocale-gettext-perl linux-libc-dev lsb-release make
- lsb_release -a
- uname -a
.install-c-build-deps: &install-c-build-deps
- apt-get install --no-install-recommends -y build-essential apache2-dev autoconf automake bison dejagnu flex libpam-dev libtool pkg-config python3-all-dev python3-setuptools ruby-dev swig zlib1g-dev
build-all:
stage: build
extends:
- .ubuntu-before_script
artifacts:
name: ${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}
expire_in: 30 days
untracked: true
paths:
- libraries/libapparmor/
- parser/
- binutils/
- utils/
- changehat/mod_apparmor/
- changehat/pam_apparmor/
- profiles/
script:
- *install-c-build-deps
- cd libraries/libapparmor && ./autogen.sh && ./configure --with-perl --with-python --prefix=/usr && make && cd ../.. || { cat config.log ; exit 1 ; }
- make -C parser
- make -C binutils
- make -C utils
- make -C changehat/mod_apparmor
- make -C changehat/pam_apparmor
- make -C profiles
test-libapparmor:
stage: test
needs: ["build-all"]
extends:
- .ubuntu-before_script
script:
- *install-c-build-deps
- make -C libraries/libapparmor check
test-parser:
stage: test
needs: ["build-all"]
extends:
- .ubuntu-before_script
script:
- *install-c-build-deps
- make -C parser check
test-binutils:
stage: test
needs: ["build-all"]
extends:
- .ubuntu-before_script
script:
- make -C binutils check
test-utils:
stage: test
needs: ["build-all"]
extends:
- .ubuntu-before_script
script:
- apt-get install --no-install-recommends -y libc6-dev libjs-jquery libjs-jquery-throttle-debounce libjs-jquery-isonscreen libjs-jquery-tablesorter pyflakes3 python3-coverage python3-notify2 python3-psutil python3-setuptools
# See apparmor/apparmor#221
- make -C parser/tst gen_dbus
- make -C parser/tst gen_xtrans
- make -C utils check
- make -C utils/test coverage-regression
artifacts:
paths:
- utils/test/htmlcov/
when: always
test-mod-apparmor:
stage: test
needs: ["build-all"]
extends:
- .ubuntu-before_script
script:
- make -C changehat/mod_apparmor check
test-profiles:
stage: test
needs: ["build-all"]
extends:
- .ubuntu-before_script
script:
- make -C profiles check-parser
- make -C profiles check-abstractions.d
- make -C profiles check-extras
shellcheck:
stage: test
needs: []
extends:
- .ubuntu-before_script
script:
- apt-get install --no-install-recommends -y file shellcheck xmlstarlet
- shellcheck --version
- './tests/bin/shellcheck-tree --format=checkstyle
| xmlstarlet tr tests/checkstyle2junit.xslt
> shellcheck.xml'
artifacts:
when: always
reports:
junit: shellcheck.xml
# Disabled due to aa-logprof dependency on /sbin/apparmor_parser existing
# - make -C profiles check-profiles
# test-pam_apparmor:
# - stage: test
# - script:
# - cd changehat/pam_apparmor && make check
include:
- template: SAST.gitlab-ci.yml
- template: Secret-Detection.gitlab-ci.yml
variables:
SAST_EXCLUDED_ANALYZERS: "eslint,flawfinder,semgrep,spotbugs"
SAST_BANDIT_EXCLUDED_PATHS: "*/tst/*, */test/*"

10
.shellcheckrc Normal file
View File

@@ -0,0 +1,10 @@
# Don't follow source'd scripts
disable=SC1090
disable=SC1091
# dash supports 'local'
disable=SC2039
disable=SC3043
# dash supports 'echo -n'
disable=SC3037

View File

@@ -54,10 +54,12 @@ snapshot: clean
.PHONY: coverity
coverity: snapshot
cd $(SNAPSHOT_NAME)/libraries/libapparmor && ./configure --with-python
$(foreach dir, $(filter-out utils profiles tests, $(DIRS)), \
cov-build --dir $(COVERITY_DIR) -- $(MAKE) -C $(SNAPSHOT_NAME)/$(dir);)
$(foreach dir, libraries/libapparmor utils, \
cov-build --dir $(COVERITY_DIR) --no-command --fs-capture-search $(SNAPSHOT_NAME)/$(dir);)
cov-build --dir $(COVERITY_DIR) --no-command --fs-capture-search $(SNAPSHOT_NAME)/$(dir); \
mv $(COVERITY_DIR)/build-log.txt $(COVERITY_DIR)/build-log-python-$(subst /,.,$(dir)).txt ;)
cov-build --dir $(COVERITY_DIR) -- sh -c \
"$(foreach dir, $(filter-out utils profiles tests, $(DIRS)), \
$(MAKE) -C $(SNAPSHOT_NAME)/$(dir);) "
tar -cvzf $(SNAPSHOT_NAME)-$(COVERITY_DIR).tar.gz $(COVERITY_DIR)
.PHONY: export_dir

135
README.md
View File

@@ -23,9 +23,44 @@ library, available under the LGPL license, which allows change_hat(2)
and change_profile(2) to be used by non-GPL binaries).
For more information, you can read the techdoc.pdf (available after
building the parser) and by visiting the http://apparmor.net/ web
building the parser) and by visiting the https://apparmor.net/ web
site.
----------------
Getting in Touch
----------------
Please send all complaints, feature requests, rants about the software,
and questions to the
[AppArmor mailing list](https://lists.ubuntu.com/mailman/listinfo/apparmor).
Bug reports can be filed against the AppArmor project on
[GitLab](https://gitlab.com/apparmor/apparmor/-/issues) or reported to the mailing
list directly for those who wish not to register for an account on
GitLab. See the
[wiki page](https://gitlab.com/apparmor/apparmor/wikis/home#reporting-bugs)
for more information.
Security issues can be filed in GitLab by opening up a new [issue](https://gitlab.com/apparmor/apparmor/-/issues) and selecting the tick box ```This issue is confidential and should only be visible to team members with at least Reporter access.``` or directed to `security@apparmor.net`. Additional details can be found
in the [wiki](https://gitlab.com/apparmor/apparmor/wikis/home#reporting-security-vulnerabilities).
--------------
Privacy Policy
--------------
The AppArmor security project respects users privacy and data and does not collect data from or on its users beyond what is required for a given component to function.
The AppArmor kernel security module will log violations to the audit subsystem, and those will be logged/forwarded/recorded on the user's system(s) according to how the administrator has logging configured. Again this is not forwarded to or collected by the AppArmor project.
The AppArmor userspace tools do not collect information on the system user beyond the logs and information needed to interact with the user. This is not forwarded to, nor collected by the AppArmor project.
Users may submit information as part of an email, bug report or merge request, etc. and that will be recorded as part of the mailing list, bug/issue tracker, or code repository but only as part of a user initiated action.
The AppArmor project does not collect information from contributors beyond their interactions with the AppArmor project, code, and community. However contributors are subject to the terms and conditions and privacy policy of the individual platforms (currently GitLab) should they choose to contribute through those platforms. And those platforms may collect data on the user that the AppArmor project does not.
Currently GitLab requires a user account to submit patches or report bugs and issues. If a contributor does not wish to create an account for these platforms the mailing list is available. Membership in the list is not required. Content from non-list members will be sent to moderation, to ensure that it is on topic, so there may be a delay in choosing to interact in this way.
-------------
Source Layout
@@ -33,6 +68,7 @@ Source Layout
AppArmor consists of several different parts:
```
binutils/ source for basic utilities written in compiled languages
changehat/ source for using changehat with Apache, PAM and Tomcat
common/ common makefile rules
@@ -43,6 +79,7 @@ parser/ source for parser/loader and corresponding documentation
profiles/ configuration files, reference profiles and abstractions
tests/ regression and stress testsuites
utils/ high-level utilities for working with AppArmor
```
--------------------------------------
Important note on AppArmor kernel code
@@ -67,63 +104,82 @@ the following order. Some systems may need to export various python-related
environment variables to complete the build. For example, before building
anything on these systems, use something along the lines of:
```
$ export PYTHONPATH=$(realpath libraries/libapparmor/swig/python)
$ export PYTHON=/usr/bin/python3
$ export PYTHON_VERSION=3
$ export PYTHON_VERSIONS=python3
```
### libapparmor:
libapparmor:
```
$ cd ./libraries/libapparmor
$ sh ./autogen.sh
$ sh ./configure --prefix=/usr --with-perl --with-python # see below
$ make
$ make check
$ make install
```
[an additional optional argument to libapparmor's configure is --with-ruby, to
generate Ruby bindings to libapparmor.]
Binary Utilities:
### Binary Utilities:
```
$ cd binutils
$ make
$ make check
$ make install
```
### Parser:
parser:
```
$ cd parser
$ make # depends on libapparmor having been built first
$ make check
$ make install
```
Utilities:
### Utilities:
```
$ cd utils
$ make
$ make check
$ make check PYFLAKES=/usr/bin/pyflakes3
$ make install
```
### Apache mod_apparmor:
Apache mod_apparmor:
```
$ cd changehat/mod_apparmor
$ make # depends on libapparmor having been built first
$ make install
```
PAM AppArmor:
### PAM AppArmor:
```
$ cd changehat/pam_apparmor
$ make # depends on libapparmor having been built first
$ make install
```
Profiles:
### Profiles:
```
$ cd profiles
$ make
$ make check # depends on the parser having been built first
$ make install
```
[Note that for the parser, binutils, and utils, if you only wish to build/use
some of the locale languages, you can override the default by passing
@@ -144,38 +200,64 @@ For details on structure and adding tests, see
tests/regression/apparmor/README.
To run:
### Regression tests - using apparmor userspace installed on host
```
$ cd tests/regression/apparmor (requires root)
$ make USE_SYSTEM=1
$ sudo make tests USE_SYSTEM=1
$ sudo bash open.sh -r # runs and saves the last testcase from open.sh
```
### Regression tests - using apparmor userspace from the tree.
- [build libapparmor](#libapparmor)
- [build binutils](#binary-utilities)
- [build apparmor parser](#parser)
- [build Pam apparmor](#pam-apparmor)
```
$ cd tests/regression/apparmor (requires root)
$ make
$ sudo make tests
$ sudo bash open.sh -r # runs and saves the last testcase from open.sh
```
Parser tests
------------
For details on structure and adding tests, see parser/tst/README.
To run:
```
$ cd parser/tst
$ make
$ make tests
```
Libapparmor
-----------
For details on structure and adding tests, see libraries/libapparmor/README.
```
$ cd libraries/libapparmor
$ make check
```
Utils
-----
Tests for the Python utilities exist in the test/ subdirectory.
```
$ cd utils
$ make check
```
The aa-decode utility to be tested can be overridden by
setting up environment variable APPARMOR_DECODE; e.g.:
```
$ APPARMOR_DECODE=/usr/bin/aa-decode make check
```
Profile checks
--------------
@@ -183,29 +265,44 @@ A basic consistency check to ensure that the parser and aa-logprof parse
successfully the current set of shipped profiles. The system or other
parser and logprof can be passed in by overriding the PARSER and LOGPROF
variables.
```
$ cd profiles
$ make && make check
```
Stress Tests
------------
To run AppArmor stress tests:
```
$ make all
```
Use these:
```
$ ./change_hat
$ ./child
$ ./kill.sh
$ ./open
$ ./s.sh
```
Or run all at once:
```
$ ./stress.sh
```
Please note that the above will stress the system so much it may end up
invoking the OOM killer.
To run parser stress tests (requires /usr/bin/ruby):
```
$ ./stress.sh
```
(see stress.sh -h for options)
@@ -220,7 +317,10 @@ https://scan.coverity.com/download?tab=cxx to obtain a pre-built copy of
cov-build.
To generate a compressed tarball of an intermediate Coverity directory:
```
$ make coverity
```
The compressed tarball is written to
apparmor-<SNAPSHOT_VERSION>-cov-int.tar.gz, where <SNAPSHOT_VERSION>
@@ -245,10 +345,15 @@ The AppArmor userspace utilities are written with some assumptions about
installed and available versions of other tools. This is a (possibly
incomplete) list of known version dependencies:
The Python utilities require a minimum of Python 2.7 (deprecated) or Python 3.3.
Python 3.x is recommended. Python 2.x support is deprecated since AppArmor 2.11.
The Python utilities require a minimum of Python 3.3.
Some utilities (aa-exec, aa-notify and aa-decode) require Perl 5.10.1 or newer.
The aa-notify tool's Python dependencies can be satisfied by installing the
following packages (Debian package names, other distros may vary):
* python3-notify2
* python3-psutil
Perl is no longer needed since none of the utilities shipped to end users depend
on it anymore.
Most shell scripts are written for POSIX-compatible sh. aa-decode expects
bash, probably version 3.2 and higher.

View File

@@ -19,11 +19,11 @@ include $(COMMONDIR)/Make.rules
DESTDIR=/
BINDIR=${DESTDIR}/usr/bin
SBINDIR=${DESTDIR}/usr/sbin
LOCALEDIR=/usr/share/locale
MANPAGES=aa-enabled.1 aa-exec.1
MANPAGES=aa-enabled.1 aa-exec.1 aa-features-abi.1 aa-status.8
WARNINGS = -Wall
EXTRA_WARNINGS = -Wsign-compare -Wmissing-field-initializers -Wformat-security -Wunused-parameter
CPP_WARNINGS =
ifndef CFLAGS
CFLAGS = -g -O2 -pipe
@@ -36,7 +36,7 @@ CFLAGS = -g -pg -fprofile-arcs -ftest-coverage
endif
endif #CFLAGS
EXTRA_CFLAGS = ${CFLAGS} ${CPPFLAGS} ${EXTRA_CXXFLAGS} ${CPP_WARNINGS}
EXTRA_CFLAGS = ${CFLAGS} ${CPPFLAGS} ${EXTRA_CXXFLAGS} ${CPP_WARNINGS} $(EXTRA_WARNINGS)
#INCLUDEDIR = /usr/src/linux/include
INCLUDEDIR =
@@ -50,10 +50,15 @@ EXTRA_CFLAGS+=-DPACKAGE=\"${NAME}\" -DLOCALEDIR=\"${LOCALEDIR}\"
SRCS = aa_enabled.c
HDRS =
TOOLS = aa-enabled aa-exec
BINTOOLS = aa-enabled aa-exec aa-features-abi
SBINTOOLS = aa-status
AALIB = -Wl,-Bstatic -lapparmor -Wl,-Bdynamic -lpthread
ifdef WITH_LIBINTL
AALIB += -lintl
endif
ifdef USE_SYSTEM
# Using the system libapparmor so Makefile dependencies can't be used
LIBAPPARMOR_A =
@@ -93,7 +98,7 @@ po/%.pot: %.c
# targets arranged this way so that people who don't want full docs can
# pick specific targets they want.
arch: $(TOOLS)
arch: $(BINTOOLS) $(SBINTOOLS)
manpages: $(MANPAGES)
@@ -106,7 +111,7 @@ all: arch indep
.PHONY: coverage
coverage:
$(MAKE) clean $(TOOLS) COVERAGE=1
$(MAKE) clean $(BINTOOLS) $(SBINTOOLS) COVERAGE=1
ifndef USE_SYSTEM
$(LIBAPPARMOR_A):
@@ -118,18 +123,27 @@ $(LIBAPPARMOR_A):
fi
endif
aa-features-abi: aa_features_abi.c $(LIBAPPARMOR_A)
$(CC) $(LDFLAGS) $(EXTRA_CFLAGS) -o $@ $< $(LIBS) $(AALIB)
aa-enabled: aa_enabled.c $(LIBAPPARMOR_A)
$(CC) $(LDFLAGS) $(EXTRA_CFLAGS) -o $@ $< $(LIBS) $(AALIB)
aa-exec: aa_exec.c $(LIBAPPARMOR_A)
$(CC) $(LDFLAGS) $(EXTRA_CFLAGS) -o $@ $< $(LIBS) $(AALIB)
aa-status: aa_status.c cJSON.o $(LIBAPPARMOR_A)
$(CC) $(LDFLAGS) $(EXTRA_CFLAGS) -o $@ $< $(LIBS) $(AALIB) cJSON.o
cJSON.o: cJSON.c cJSON.h
$(CC) $(EXTRA_CFLAGS) -c -o $@ $<
.SILENT: check
.PHONY: check
check: check_pod_files tests
.SILENT: tests
tests: $(TOOLS) $(TESTS)
tests: $(BINTOOLS) $(SBINTOOLS) $(TESTS)
echo "no tests atm"
.PHONY: install
@@ -138,12 +152,16 @@ install: install-indep install-arch
.PHONY: install-arch
install-arch: arch
install -m 755 -d ${BINDIR}
install -m 755 ${TOOLS} ${BINDIR}
install -m 755 ${BINTOOLS} ${BINDIR}
install -m 755 -d ${SBINDIR}
ln -sf aa-status ${SBINDIR}/apparmor_status
install -m 755 ${SBINTOOLS} ${SBINDIR}
.PHONY: install-indep
install-indep: indep
$(MAKE) -C po install NAME=${NAME} DESTDIR=${DESTDIR}
$(MAKE) install_manpages DESTDIR=${DESTDIR}
ln -sf aa-status.8 ${DESTDIR}/${MANDIR}/man8/apparmor_status.8
ifndef VERBOSE
.SILENT: clean
@@ -152,6 +170,6 @@ endif
clean: pod_clean
rm -f core core.* *.o *.s *.a *~ *.gcda *.gcno
rm -f gmon.out
rm -f $(TOOLS) $(TESTS)
rm -f $(BINTOOLS) $(SBINTOOLS) $(TESTS)
$(MAKE) -s -C po clean

View File

@@ -48,6 +48,11 @@ Do not output anything to stdout. This option is intended to be used by
scripts that simply want to use the exit code to determine if AppArmor is
enabled.
=item -x, --exclusive
Require AppArmor to have exclusive access to shared LSM interfaces to
be considered enabled.
=back
=head1 EXIT STATUS
@@ -76,6 +81,10 @@ if the AppArmor control files aren't available under /sys/kernel/security/.
if B<aa-enabled> doesn't have enough privileges to read the apparmor control files.
=item B<10>
AppArmor is enabled but does not have access to shared LSM interfaces.
=item B<64>
if any unexpected error or condition is encountered.
@@ -85,10 +94,10 @@ if any unexpected error or condition is encountered.
=head1 BUGS
If you find any bugs, please report them at
L<https://bugs.launchpad.net/apparmor/+filebug>.
L<https://gitlab.com/apparmor/apparmor/-/issues>.
=head1 SEE ALSO
apparmor(7), apparmor.d(5), aa_is_enabled(2), and L<http://wiki.apparmor.net>.
apparmor(7), apparmor.d(5), aa_is_enabled(2), and L<https://wiki.apparmor.net>.
=cut

View File

@@ -83,11 +83,11 @@ aa-exec.
=head1 BUGS
If you find any bugs, please report them at
L<https://bugs.launchpad.net/apparmor/+filebug>.
L<https://gitlab.com/apparmor/apparmor/-/issues>
=head1 SEE ALSO
aa-stack(8), aa-namespace(8), apparmor(7), apparmor.d(5), aa_change_profile(3),
aa_change_onexec(3) and L<http://wiki.apparmor.net>.
aa_change_onexec(3) and L<https://wiki.apparmor.net>.
=cut

View File

@@ -0,0 +1,97 @@
# This publication is intellectual property of Canonical Ltd. Its contents
# can be duplicated, either in part or in whole, provided that a copyright
# label is visibly located on each copy.
#
# All information found in this book has been compiled with utmost
# attention to detail. However, this does not guarantee complete accuracy.
# Neither Canonical Ltd, the authors, nor the translators shall be held
# liable for possible errors or the consequences thereof.
#
# Many of the software and hardware descriptions cited in this book
# are registered trademarks. All trade names are subject to copyright
# restrictions and may be registered trade marks. Canonical Ltd
# essentially adheres to the manufacturer's spelling.
#
# Names of products and trademarks appearing in this book (with or without
# specific notation) are likewise subject to trademark and trade protection
# laws and may thus fall under copyright restrictions.
#
=pod
=head1 NAME
aa-features-abi - Extract, validate and manipulate AppArmor feature abis
=head1 SYNOPSIS
B<aa-features-abi> [OPTIONS] <SOURCE> [OUTPUT OPTIONS]
=head1 DESCRIPTION
B<aa-features-abi> is used to extract a features abi and output to
either stdout or a specified file. A SOURCE_OPTION must be specified.
If an output option is not specified the features abi is written to
stdout.
=head1 OPTIONS
B<aa-features-abi> accepts the following arguments:
=over 4
=item -h, --help
Display a brief usage guide.
=item -d, --debug
show messages with debugging information
=item -v, --verbose
show messages with stats
=back
=head1 SOURCE
=over 4
=item -x, --extract
Extract the features abi for the kernel
=item -f FILE, --file=FILE
Load the features abi from FILE and send it to OUTPUT OPTIONS.
=back
=head1 OUTPUT OPTIONS
=over 4
=item --stdout
Write the features abi to I<stdout>, this is the default if no output option
is specified.
=item -w FILE, --write FILE
Write the features abi to I<FILE>.
=back
=head1 BUGS
If you find any bugs, please report them at
L<https://gitlab.com/apparmor/apparmor/-/issues>.
=head1 SEE ALSO
apparmor(7), apparmor.d(5), aa_features(3), and L<https://wiki.apparmor.net>.
=cut

View File

@@ -70,6 +70,18 @@ displays the number of loaded enforcing AppArmor policies.
displays the number of loaded non-enforcing AppArmor policies.
=item --kill
displays the number of loaded enforcing AppArmor policies that will kill tasks on policy violations.
=item --special-unconfined
displays the number of loaded non-enforcing AppArmor policies that are in the special unconfined mode.
=item --process-mixed
displays the number of processes confined by profile stacks with
profiles in different modes.
=item --verbose
displays multiple data points about loaded AppArmor policy
@@ -119,6 +131,10 @@ if the apparmor control files aren't available under /sys/kernel/security/.
if the user running the script doesn't have enough privileges to read
the apparmor control files.
=item B<42>
if an internal error occurred.
=back
=head1 BUGS
@@ -128,11 +144,11 @@ policy from the apparmor module. It uses the /proc filesystem to determine
which processes are confined and so is susceptible to race conditions.
If you find any additional bugs, please report them at
L<https://bugs.launchpad.net/apparmor/+filebug>.
L<https://gitlab.com/apparmor/apparmor/-/issues>.
=head1 SEE ALSO
apparmor(7), apparmor.d(5), and
L<http://wiki.apparmor.net>.
L<https://wiki.apparmor.net>.
=cut

View File

@@ -20,6 +20,7 @@ void print_help(const char *command)
{
printf(_("%s: [options]\n"
" options:\n"
" -x | --exclusive Shared interfaces must be available\n"
" -q | --quiet Don't print out any messages\n"
" -h | --help Print help\n"),
command);
@@ -30,8 +31,6 @@ void print_help(const char *command)
/* Exit statuses and meanings are documented in the aa-enabled.pod file */
static void exit_with_error(int saved_errno, int quiet)
{
int err;
switch(saved_errno) {
case ENOSYS:
if (!quiet)
@@ -50,8 +49,11 @@ static void exit_with_error(int saved_errno, int quiet)
if (!quiet)
printf(_("Maybe - insufficient permissions to determine availability.\n"));
exit(4);
case EBUSY:
if (!quiet)
printf(_("Partially - public shared interfaces are not available.\n"));
exit(10);
}
if (!quiet)
printf(_("Error - %s\n"), strerror(saved_errno));
exit(64);
@@ -59,22 +61,27 @@ static void exit_with_error(int saved_errno, int quiet)
int main(int argc, char **argv)
{
int enabled;
int i, enabled;
int quiet = 0;
int require_shared = 0;
setlocale(LC_MESSAGES, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
if (argc > 2) {
if (argc > 3) {
printf(_("unknown or incompatible options\n"));
print_help(argv[0]);
} else if (argc == 2) {
if (strcmp(argv[1], "--quiet") == 0 ||
strcmp(argv[1], "-q") == 0) {
}
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "--quiet") == 0 ||
strcmp(argv[i], "-q") == 0) {
quiet = 1;
} else if (strcmp(argv[1], "--help") == 0 ||
strcmp(argv[1], "-h") == 0) {
} else if (strcmp(argv[i], "--exclusive") == 0 ||
strcmp(argv[i], "-x") == 0) {
require_shared = 1;
} else if (strcmp(argv[i], "--help") == 0 ||
strcmp(argv[i], "-h") == 0) {
print_help(argv[0]);
} else {
printf(_("unknown option '%s'\n"), argv[1]);
@@ -83,9 +90,10 @@ int main(int argc, char **argv)
}
enabled = aa_is_enabled();
if (!enabled)
exit_with_error(errno, quiet);
if (!enabled) {
if (require_shared || errno != EBUSY)
exit_with_error(errno, quiet);
}
if (!quiet)
printf(_("Yes\n"));
exit(0);

View File

@@ -25,6 +25,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/apparmor.h>
#include <sys/types.h>
#include <unistd.h>
#define _(s) gettext(s)
@@ -33,6 +34,7 @@ static const char *opt_namespace = NULL;
static bool opt_debug = false;
static bool opt_immediate = false;
static bool opt_verbose = false;
static pid_t pid = 0;
static void usage(const char *name, bool error)
{
@@ -60,7 +62,7 @@ static void usage(const char *name, bool error)
exit(status);
}
#define error(fmt, args...) _error(_("aa-exec: ERROR: " fmt "\n"), ## args)
#define error(fmt, args...) _error(_("[%ld] aa-exec: ERROR: " fmt "\n"), (long)pid, ## args)
static void _error(const char *fmt, ...)
{
va_list args;
@@ -71,7 +73,7 @@ static void _error(const char *fmt, ...)
exit(EXIT_FAILURE);
}
#define debug(fmt, args...) _debug(_("aa-exec: DEBUG: " fmt "\n"), ## args)
#define debug(fmt, args...) _debug(_("[%ld] aa-exec: DEBUG: " fmt "\n"), (long)pid, ## args)
static void _debug(const char *fmt, ...)
{
va_list args;
@@ -84,7 +86,7 @@ static void _debug(const char *fmt, ...)
va_end(args);
}
#define verbose(fmt, args...) _verbose(_(fmt "\n"), ## args)
#define verbose(fmt, args...) _verbose(_("[%ld] " fmt "\n"), (long)pid, ## args)
static void _verbose(const char *fmt, ...)
{
va_list args;
@@ -102,7 +104,7 @@ static void verbose_print_argv(char **argv)
if (!opt_verbose)
return;
fprintf(stderr, _("exec"));
fprintf(stderr, _("[%ld] exec"), (long)pid);
for (; *argv; argv++)
fprintf(stderr, " %s", *argv);
fprintf(stderr, "\n");
@@ -129,9 +131,13 @@ static char **parse_args(int argc, char **argv)
usage(argv[0], false);
break;
case 'p':
if (opt_profile)
error("Multiple -p/--profile parameters given");
opt_profile = optarg;
break;
case 'n':
if (opt_namespace)
error("Multiple -n/--namespace parameters given");
opt_namespace = optarg;
break;
case 'i':
@@ -183,6 +189,11 @@ int main(int argc, char **argv)
char name[PATH_MAX];
int rc = 0;
/* IMPORTANT: pid must be initialized before doing anything else since
* it is used in a global context when printing messages
*/
pid = getpid();
argv = parse_args(argc, argv);
if (opt_namespace || opt_profile)
@@ -201,8 +212,11 @@ int main(int argc, char **argv)
}
if (rc) {
if (errno == ENOENT || errno == EACCES) {
error("%s '%s' does not exist\n",
if (errno == ENOENT) {
error("%s '%s' does not exist",
opt_profile ? "profile" : "namespace", name);
} else if (errno == EACCES) {
error("insufficient permissions to change to the %s '%s'",
opt_profile ? "profile" : "namespace", name);
} else if (errno == EINVAL) {
error("AppArmor interface not available");

207
binutils/aa_features_abi.c Normal file
View File

@@ -0,0 +1,207 @@
/*
* Copyright (c) 2020
* Canonical, Ltd. (All rights reserved)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, contact Canonical Ltd.
*/
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <libintl.h>
#include <limits.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/apparmor.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#define _(s) gettext(s)
#include "../libraries/libapparmor/src/private.h"
static const char *progname = NULL;
static const char *opt_file = NULL;
static const char *opt_write = NULL;
static bool opt_debug = false;
static bool opt_verbose = false;
static bool opt_extract = false;
static void usage(const char *name, bool error)
{
FILE *stream = stdout;
int status = EXIT_SUCCESS;
if (error) {
stream = stderr;
status = EXIT_FAILURE;
}
fprintf(stream,
_("USAGE: %s [OPTIONS] <SOURCE> [OUTPUT OPTIONS]\n"
"\n"
"Output AppArmor feature abi from SOURCE to OUTPUT"
"\n"
"OPTIONS:\n"
#if 0
" -d, --debug show messages with debugging information\n"
" -v, --verbose show messages with stats\n"
#endif
" -h, --help display this help\n"
"SOURCE:\n"
" -f F, --file=F load features abi from file F\n"
" -x, --extract extract features abi from the kernel\n"
"OUTPUT OPTIONS:\n"
" --stdout default, write features to stdout\n"
" -w F, --write=F write features abi to the file F instead of stdout\n"
"\n"), name);
exit(status);
}
#define error(fmt, args...) _error(_("%s: ERROR: " fmt " - %m\n"), progname, ## args)
static void _error(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
exit(EXIT_FAILURE);
}
#if 0
#define debug(fmt, args...) _debug(_("%s: DEBUG: " fmt "\n"), progname, ## args)
static void _debug(const char *fmt, ...)
{
va_list args;
if (!opt_debug)
return;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
}
#define verbose(fmt, args...) _verbose(_(fmt "\n"), ## args)
static void _verbose(const char *fmt, ...)
{
va_list args;
if (!opt_verbose)
return;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
}
#endif
#define ARG_STDOUT 128
static char **parse_args(int argc, char **argv)
{
int opt;
struct option long_opts[] = {
{"debug", no_argument, 0, 'd'},
{"verbose", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
{"extract", no_argument, 0, 'x'},
{"file", required_argument, 0, 'f'},
{"write", required_argument, 0, 'w'},
{"stdout", no_argument, 0, ARG_STDOUT},
};
while ((opt = getopt_long(argc, argv, "+dvhxf:l:w:", long_opts, NULL)) != -1) {
switch (opt) {
case 'd':
opt_debug = true;
break;
case 'v':
opt_verbose = true;
break;
case 'h':
usage(argv[0], false);
break;
case 'x':
opt_extract = true;
break;
case 'f':
opt_file = optarg;
break;
case 'w':
opt_write = optarg;
break;
case ARG_STDOUT:
opt_write = NULL;
break;
default:
usage(argv[0], true);
break;
}
}
return argv + optind;
}
/* TODO: add features intersection and testing */
int main(int argc, char **argv)
{
struct aa_features *features;
autoclose int in = -1;
autoclose int out = -1;
int rc = 0;
progname = argv[0];
argv = parse_args(argc, argv);
if (!opt_extract && !opt_file)
usage(argv[0], true);
if (opt_extract && opt_file) {
error("options --extract and --file are mutually exclusive");
}
if (opt_extract) {
rc = aa_features_new_from_kernel(&features);
if (rc == -1)
error("failed to extract features abi from the kernel");
}
if (opt_file) {
in = open(opt_file, O_RDONLY);
if (in == -1)
error("failed to open file '%s'", opt_file);
rc = aa_features_new_from_file(&features, in);
if (rc == -1)
error("failed to load features abi from file '%s'", opt_file);
}
if (opt_write) {
out = open(opt_write, O_WRONLY | O_CREAT, 00600);
if (out == -1)
error("failed to open output file '%s'", opt_write);
} else {
out = fileno(stdout);
if (out == -1)
error("failed to get stdout");
}
rc = aa_features_write_to_fd(features, out);
if (rc == -1)
error("failed to write features abi");
return 0;
}

676
binutils/aa_status.c Normal file
View File

@@ -0,0 +1,676 @@
/*
* Copyright (C) 2020 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License published by the Free Software Foundation.
*/
#define _GNU_SOURCE /* for asprintf() */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
#include <dirent.h>
#include <sys/apparmor.h>
#include <sys/apparmor_private.h>
#include "cJSON.h"
#define autofree __attribute((cleanup(_aa_autofree)))
#define autofclose __attribute((cleanup(_aa_autofclose)))
#define AA_EXIT_ENABLED 0
#define AA_EXIT_DISABLED 1
#define AA_EXIT_NO_POLICY 2
#define AA_EXIT_NO_CONTROL 3
#define AA_EXIT_NO_PERM 4
#define AA_EXIT_INTERNAL_ERROR 42
/* NOTE: Increment this whenever the JSON format changes */
static const unsigned char aa_status_json_version[] = "2";
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
#define __unused __attribute__ ((__unused__))
struct profile {
char *name;
char *status;
};
static void free_profiles(struct profile *profiles, size_t n) {
while (n > 0) {
n--;
free(profiles[n].name);
free(profiles[n].status);
}
free(profiles);
}
struct process {
char *pid;
char *profile;
char *exe;
char *mode;
};
static void free_processes(struct process *processes, size_t n) {
while (n > 0) {
n--;
free(processes[n].pid);
free(processes[n].profile);
free(processes[n].exe);
free(processes[n].mode);
}
free(processes);
}
static int verbose = 0;
#define dprintf(...) \
do { \
if (verbose) \
printf(__VA_ARGS__); \
} while (0)
#define dfprintf(...) \
do { \
if (verbose) \
fprintf(__VA_ARGS__); \
} while (0)
static int get_profiles(struct profile **profiles, size_t *n) {
autofree char *apparmorfs = NULL;
autofree char *apparmor_profiles = NULL;
struct stat st;
autofclose FILE *fp = NULL;
autofree char *line = NULL;
size_t len = 0;
int ret;
*profiles = NULL;
*n = 0;
ret = stat("/sys/module/apparmor", &st);
if (ret != 0) {
dfprintf(stderr, "apparmor not present.\n");
ret = AA_EXIT_DISABLED;
goto exit;
}
dprintf("apparmor module is loaded.\n");
ret = aa_find_mountpoint(&apparmorfs);
if (ret == -1) {
dfprintf(stderr, "apparmor filesystem is not mounted.\n");
ret = AA_EXIT_NO_CONTROL;
goto exit;
}
apparmor_profiles = malloc(strlen(apparmorfs) + 10); // /profiles\0
if (apparmor_profiles == NULL) {
ret = AA_EXIT_INTERNAL_ERROR;
goto exit;
}
sprintf(apparmor_profiles, "%s/profiles", apparmorfs);
fp = fopen(apparmor_profiles, "r");
if (fp == NULL) {
if (errno == EACCES) {
dfprintf(stderr, "You do not have enough privilege to read the profile set.\n");
} else {
dfprintf(stderr, "Could not open %s: %s", apparmor_profiles, strerror(errno));
}
ret = AA_EXIT_NO_PERM;
goto exit;
}
while (getline(&line, &len, fp) != -1) {
struct profile *_profiles;
autofree char *status = NULL;
autofree char *name = NULL;
char *tmpname = aa_splitcon(line, &status);
if (!tmpname) {
dfprintf(stderr, "Error: failed profile name split of '%s'.\n", line);
ret = AA_EXIT_INTERNAL_ERROR;
// skip this entry and keep processing
continue;
}
name = strdup(tmpname);
if (status)
status = strdup(status);
// give up if out of memory
if (name == NULL || status == NULL) {
free_profiles(*profiles, *n);
*profiles = NULL;
*n = 0;
ret = AA_EXIT_INTERNAL_ERROR;
break;
}
_profiles = realloc(*profiles, (*n + 1) * sizeof(**profiles));
if (_profiles == NULL) {
free_profiles(*profiles, *n);
*profiles = NULL;
*n = 0;
ret = AA_EXIT_INTERNAL_ERROR;
break;
}
// steal name and status
_profiles[*n].name = name;
_profiles[*n].status = status;
name = NULL;
status = NULL;
*n = *n + 1;
*profiles = _profiles;
}
exit:
return ret == 0 ? (*n > 0 ? AA_EXIT_ENABLED : AA_EXIT_NO_POLICY) : ret;
}
static int compare_profiles(const void *a, const void *b) {
return strcmp(((struct profile *)a)->name,
((struct profile *)b)->name);
}
static int filter_profiles(struct profile *profiles,
size_t n,
const char *filter,
struct profile **filtered,
size_t *nfiltered)
{
int ret = 0;
size_t i;
*filtered = NULL;
*nfiltered = 0;
for (i = 0; i < n; i++) {
if (filter == NULL || strcmp(profiles[i].status, filter) == 0) {
struct profile *_filtered = realloc(*filtered, (*nfiltered + 1) * sizeof(**filtered));
if (_filtered == NULL) {
free_profiles(*filtered, *nfiltered);
*filtered = NULL;
*nfiltered = 0;
ret = AA_EXIT_INTERNAL_ERROR;
break;
}
_filtered[*nfiltered].name = strdup(profiles[i].name);
_filtered[*nfiltered].status = strdup(profiles[i].status);
*filtered = _filtered;
*nfiltered = *nfiltered + 1;
}
}
if (*nfiltered != 0) {
qsort(*filtered, *nfiltered, sizeof(*profiles), compare_profiles);
}
return ret;
}
static int get_processes(struct profile *profiles,
size_t n,
struct process **processes,
size_t *nprocesses)
{
DIR *dir = NULL;
struct dirent *entry = NULL;
int ret = 0;
*processes = NULL;
*nprocesses = 0;
dir = opendir("/proc");
if (dir == NULL) {
ret = AA_EXIT_INTERNAL_ERROR;
goto exit;
}
while ((entry = readdir(dir)) != NULL) {
size_t i;
int rc;
int ispid = 1;
autofree char *profile = NULL;
autofree char *mode = NULL; /* be careful */
autofree char *exe = NULL;
autofree char *real_exe = NULL;
autofclose FILE *fp = NULL;
autofree char *line = NULL;
// ignore non-pid entries
for (i = 0; ispid && i < strlen(entry->d_name); i++) {
ispid = (isdigit(entry->d_name[i]) ? 1 : 0);
}
if (!ispid) {
continue;
}
rc = aa_getprocattr(atoi(entry->d_name), "current", &profile, &mode);
if (rc == -1 && errno != ENOMEM) {
/* fail to access */
continue;
} else if (rc == -1 ||
asprintf(&exe, "/proc/%s/exe", entry->d_name) == -1) {
fprintf(stderr, "ERROR: Failed to allocate memory\n");
ret = AA_EXIT_INTERNAL_ERROR;
goto exit;
} else if (mode) {
/* TODO: make this not needed. Mode can now be autofreed */
mode = strdup(mode);
}
// get executable - readpath can allocate for us but seems
// to fail in some cases with errno 2 - no such file or
// directory - whereas readlink() can succeed in these
// cases - and readpath() seems to have the same behaviour
// as in python with better canonicalized results so try it
// first and fallack to readlink if it fails
// coverity[toctou]
real_exe = realpath(exe, NULL);
if (real_exe == NULL) {
int res;
// ensure enough space for NUL terminator
real_exe = calloc(PATH_MAX + 1, sizeof(char));
if (real_exe == NULL) {
fprintf(stderr, "ERROR: Failed to allocate memory\n");
ret = AA_EXIT_INTERNAL_ERROR;
goto exit;
}
res = readlink(exe, real_exe, PATH_MAX);
if (res == -1) {
continue;
}
real_exe[res] = '\0';
}
if (mode == NULL) {
// is unconfined so keep only if this has a
// matching profile. TODO: fix to use attachment
for (i = 0; i < n; i++) {
if (strcmp(profiles[i].name, real_exe) == 0) {
profile = strdup(real_exe);
mode = strdup("unconfined");
break;
}
}
}
if (profile != NULL && mode != NULL) {
struct process *_processes = realloc(*processes,
(*nprocesses + 1) * sizeof(**processes));
if (_processes == NULL) {
free_processes(*processes, *nprocesses);
*processes = NULL;
*nprocesses = 0;
ret = AA_EXIT_INTERNAL_ERROR;
goto exit;
}
_processes[*nprocesses].pid = strdup(entry->d_name);
_processes[*nprocesses].profile = profile;
_processes[*nprocesses].exe = strdup(real_exe);
_processes[*nprocesses].mode = mode;
*processes = _processes;
*nprocesses = *nprocesses + 1;
profile = NULL;
mode = NULL;
ret = AA_EXIT_ENABLED;
}
}
exit:
if (dir != NULL) {
closedir(dir);
}
return ret;
}
static int filter_processes(struct process *processes,
size_t n,
const char *filter,
struct process **filtered,
size_t *nfiltered)
{
size_t i;
int ret = 0;
*filtered = NULL;
*nfiltered = 0;
for (i = 0; i < n; i++) {
if (filter == NULL || strcmp(processes[i].mode, filter) == 0) {
struct process *_filtered = realloc(*filtered, (*nfiltered + 1) * sizeof(**filtered));
if (_filtered == NULL) {
free_processes(*filtered, *nfiltered);
*filtered = NULL;
*nfiltered = 0;
ret = AA_EXIT_INTERNAL_ERROR;
break;
}
_filtered[*nfiltered].pid = strdup(processes[i].pid);
_filtered[*nfiltered].profile = strdup(processes[i].profile);
_filtered[*nfiltered].exe = strdup(processes[i].exe);
_filtered[*nfiltered].mode = strdup(processes[i].mode);
*filtered = _filtered;
*nfiltered = *nfiltered + 1;
}
}
return ret;
}
/**
* Returns error code if AppArmor is not enabled
*/
static int simple_filtered_count(const char *filter) {
size_t n;
struct profile *profiles;
int ret;
ret = get_profiles(&profiles, &n);
if (ret == 0) {
size_t nfiltered;
struct profile *filtered = NULL;
ret = filter_profiles(profiles, n, filter, &filtered, &nfiltered);
printf("%zd\n", nfiltered);
free_profiles(filtered, nfiltered);
}
free_profiles(profiles, n);
return ret;
}
static int simple_filtered_process_count(const char *filter) {
size_t nprocesses, nprofiles;
struct profile *profiles = NULL;
struct process *processes = NULL;
int ret;
ret = get_profiles(&profiles, &nprofiles);
if (ret != 0)
return ret;
ret = get_processes(profiles, nprofiles, &processes, &nprocesses);
if (ret == 0) {
size_t nfiltered;
struct process *filtered = NULL;
ret = filter_processes(processes, nprocesses, filter, &filtered, &nfiltered);
printf("%zd\n", nfiltered);
free_processes(filtered, nfiltered);
}
free_profiles(profiles, nprofiles);
free_processes(processes, nprocesses);
return ret;
}
static int cmd_enabled(__unused const char *command) {
int res = aa_is_enabled();
return res == 1 ? 0 : 1;
}
static int cmd_profiled(__unused const char *command) {
return simple_filtered_count(NULL);
}
static int cmd_enforced(__unused const char *command) {
return simple_filtered_count("enforce");
}
static int cmd_complaining(__unused const char *command) {
return simple_filtered_count("complain");
}
static int cmd_kill(__unused const char *command) {
return simple_filtered_count("kill");
}
static int cmd_unconfined(__unused const char *command) {
return simple_filtered_count("unconfined");
}
static int cmd_process_mixed(__unused const char *command) {
return simple_filtered_process_count("mixed");
}
static int compare_processes_by_profile(const void *a, const void *b) {
return strcmp(((struct process *)a)->profile,
((struct process *)b)->profile);
}
static int compare_processes_by_executable(const void *a, const void *b) {
return strcmp(((struct process *)a)->exe,
((struct process *)b)->exe);
}
static int detailed_output(FILE *json) {
size_t nprofiles = 0, nprocesses = 0;
struct profile *profiles = NULL;
struct process *processes = NULL;
const char *profile_statuses[] = {"enforce", "complain", "kill", "unconfined"};
const char *process_statuses[] = {"enforce", "complain", "unconfined", "mixed", "kill"};
int ret;
size_t i;
int need_finish = 0;
ret = get_profiles(&profiles, &nprofiles);
if (ret != 0) {
goto exit;
}
ret = get_processes(profiles, nprofiles, &processes, &nprocesses);
if (ret != 0) {
dfprintf(stderr, "Failed to get processes: %d....\n", ret);
goto exit;
}
if (json) {
fprintf(json, "{\"version\": \"%s\", \"profiles\": {", aa_status_json_version);
} else {
dprintf("%zd profiles are loaded.\n", nprofiles);
}
for (i = 0; i < ARRAY_SIZE(profile_statuses); i++) {
size_t nfiltered = 0, j;
struct profile *filtered = NULL;
ret = filter_profiles(profiles, nprofiles, profile_statuses[i], &filtered, &nfiltered);
if (ret != 0) {
goto exit;
}
if (!json) {
dprintf("%zd profiles are in %s mode.\n", nfiltered, profile_statuses[i]);
}
for (j = 0; j < nfiltered; j++) {
if (json) {
fprintf(json, "%s\"%s\": \"%s\"",
i == 0 && j == 0 ? "" : ", ", filtered[j].name, profile_statuses[i]);
} else {
dprintf(" %s\n", filtered[j].name);
}
}
free_profiles(filtered, nfiltered);
}
if (json) {
fprintf(json, "}, \"processes\": {");
} else {
dprintf("%zd processes have profiles defined.\n", nprocesses);
}
for (i = 0; i < ARRAY_SIZE(process_statuses); i++) {
size_t nfiltered = 0, j;
struct process *filtered = NULL;
ret = filter_processes(processes, nprocesses, process_statuses[i], &filtered, &nfiltered);
if (ret != 0) {
goto exit;
}
if (!json) {
if (strcmp(process_statuses[i], "unconfined") == 0) {
dprintf("%zd processes are unconfined but have a profile defined.\n", nfiltered);
} else {
dprintf("%zd processes are in %s mode.\n", nfiltered, process_statuses[i]);
}
}
if (!json) {
qsort(filtered, nfiltered, sizeof(*filtered), compare_processes_by_profile);
for (j = 0; j < nfiltered; j++) {
dprintf(" %s (%s) %s\n", filtered[j].exe, filtered[j].pid,
// hide profile name if matches executable
(strcmp(filtered[j].profile, filtered[j].exe) == 0 ?
"" :
filtered[j].profile));
}
} else {
// json output requires processes to be grouped per executable
qsort(filtered, nfiltered, sizeof(*filtered), compare_processes_by_executable);
for (j = 0; j < nfiltered; j++) {
if (j > 0 && strcmp(filtered[j].exe, filtered[j - 1].exe) == 0) {
// same executable
fprintf(json, ", {\"profile\": \"%s\", \"pid\": \"%s\", \"status\": \"%s\"}",
filtered[j].profile, filtered[j].pid, filtered[j].mode);
} else {
fprintf(json, "%s\"%s\": [{\"profile\": \"%s\", \"pid\": \"%s\", \"status\": \"%s\"}",
// first element will be a unique executable
j == 0 && !need_finish ? "" : "], ",
filtered[j].exe, filtered[j].profile, filtered[j].pid, filtered[j].mode);
}
need_finish = 1;
}
}
free_processes(filtered, nfiltered);
}
if (json) {
if (need_finish > 0) {
fprintf(json, "]");
}
fprintf(json, "}}\n");
}
exit:
free_processes(processes, nprocesses);
free_profiles(profiles, nprofiles);
return ret == 0 ? (nprofiles > 0 ? AA_EXIT_ENABLED : AA_EXIT_NO_POLICY) : ret;
}
static int cmd_json(__unused const char *command) {
detailed_output(stdout);
return 0;
}
static int cmd_pretty_json(__unused const char *command) {
autofree char *buffer = NULL;
autofree char *pretty = NULL;
cJSON *json;
FILE *f; /* no autofclose - want explicit close to sync */
size_t size;
int ret;
f = open_memstream(&buffer, &size);
if (!f) {
dfprintf(stderr, "Failed to open memstream: %m\n");
return AA_EXIT_INTERNAL_ERROR;
}
ret = detailed_output(f);
fclose(f);
if (ret)
return ret;
json = cJSON_Parse(buffer);
if (!json) {
dfprintf(stderr, "Failed to parse json output");
return AA_EXIT_INTERNAL_ERROR;
}
pretty = cJSON_Print(json);
if (!pretty) {
dfprintf(stderr, "Failed to print pretty json");
return AA_EXIT_INTERNAL_ERROR;
}
fprintf(stdout, "%s\n", pretty);
return AA_EXIT_ENABLED;
}
static int cmd_verbose(__unused const char *command) {
verbose = 1;
return detailed_output(NULL);
}
static int print_usage(const char *command)
{
printf("Usage: %s [OPTIONS]\n"
"Displays various information about the currently loaded AppArmor policy.\n"
"OPTIONS (one only):\n"
" --enabled returns error code if AppArmor not enabled\n"
" --profiled prints the number of loaded policies\n"
" --enforced prints the number of loaded enforcing policies\n"
" --complaining prints the number of loaded non-enforcing policies\n"
" --kill prints the number of loaded enforcing policies that kill tasks on policy violations\n"
" --special-unconfined prints the number of loaded non-enforcing policies in the special unconfined mode\n"
" --process-mixed prints the number processes with mixed profile modes\n"
" --json displays multiple data points in machine-readable JSON format\n"
" --pretty-json same data as --json, formatted for human consumption as well\n"
" --verbose (default) displays multiple data points about loaded policy set\n"
" --help this message\n",
command);
return 0;
}
struct command {
const char * const name;
int (*cmd)(const char *command);
};
static struct command commands[] = {
{"--enabled", cmd_enabled},
{"--profiled", cmd_profiled},
{"--enforced", cmd_enforced},
{"--complaining", cmd_complaining},
{"--kill", cmd_kill},
{"--special-unconfined", cmd_unconfined},
{"--process-mixed", cmd_process_mixed},
{"--json", cmd_json},
{"--pretty-json", cmd_pretty_json},
{"--verbose", cmd_verbose},
{"-v", cmd_verbose},
{"--help", print_usage},
{"-h", print_usage},
};
int main(int argc, char **argv)
{
int ret = EXIT_SUCCESS;
int _ret;
int (*cmd)(const char*) = cmd_verbose;
if (argc > 2) {
dfprintf(stderr, "Error: Too many options.\n");
cmd = print_usage;
ret = EXIT_FAILURE;
} else if (argc == 2) {
int (*_cmd)(const char*) = NULL;
size_t i;
for (i = 0; i < ARRAY_SIZE(commands); i++) {
if (strcmp(argv[1], commands[i].name) == 0) {
_cmd = commands[i].cmd;
break;
}
}
if (_cmd == NULL) {
dfprintf(stderr, "Error: Invalid command.\n");
cmd = print_usage;
ret = EXIT_FAILURE;
} else {
cmd = _cmd;
}
}
_ret = cmd(argv[0]);
exit(ret == EXIT_FAILURE ? ret : _ret);
}

3074
binutils/cJSON.c Normal file

File diff suppressed because it is too large Load Diff

293
binutils/cJSON.h Normal file
View File

@@ -0,0 +1,293 @@
/*
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef cJSON__h
#define cJSON__h
#ifdef __cplusplus
extern "C"
{
#endif
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
#define __WINDOWS__
#endif
#ifdef __WINDOWS__
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
For *nix builds that support visibility attribute, you can define similar behavior by
setting default visibility to hidden by adding
-fvisibility=hidden (for gcc)
or
-xldscope=hidden (for sun cc)
to CFLAGS
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
*/
#define CJSON_CDECL __cdecl
#define CJSON_STDCALL __stdcall
/* export symbols by default, this is necessary for copy pasting the C and header file */
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_EXPORT_SYMBOLS
#endif
#if defined(CJSON_HIDE_SYMBOLS)
#define CJSON_PUBLIC(type) type CJSON_STDCALL
#elif defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
#elif defined(CJSON_IMPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
#endif
#else /* !__WINDOWS__ */
#define CJSON_CDECL
#define CJSON_STDCALL
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
#else
#define CJSON_PUBLIC(type) type
#endif
#endif
/* project version */
#define CJSON_VERSION_MAJOR 1
#define CJSON_VERSION_MINOR 7
#define CJSON_VERSION_PATCH 13
#include <stddef.h>
/* cJSON Types: */
#define cJSON_Invalid (0)
#define cJSON_False (1 << 0)
#define cJSON_True (1 << 1)
#define cJSON_NULL (1 << 2)
#define cJSON_Number (1 << 3)
#define cJSON_String (1 << 4)
#define cJSON_Array (1 << 5)
#define cJSON_Object (1 << 6)
#define cJSON_Raw (1 << 7) /* raw json */
#define cJSON_IsReference 256
#define cJSON_StringIsConst 512
/* The cJSON structure: */
typedef struct cJSON
{
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
struct cJSON *next;
struct cJSON *prev;
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
struct cJSON *child;
/* The type of the item, as above. */
int type;
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
char *valuestring;
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
int valueint;
/* The item's number, if type==cJSON_Number */
double valuedouble;
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
char *string;
} cJSON;
typedef struct cJSON_Hooks
{
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
void *(CJSON_CDECL *malloc_fn)(size_t sz);
void (CJSON_CDECL *free_fn)(void *ptr);
} cJSON_Hooks;
typedef int cJSON_bool;
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
* This is to prevent stack overflows. */
#ifndef CJSON_NESTING_LIMIT
#define CJSON_NESTING_LIMIT 1000
#endif
/* returns the version of cJSON as a string */
CJSON_PUBLIC(const char*) cJSON_Version(void);
/* Supply malloc, realloc and free functions to cJSON */
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
/* Render a cJSON entity to text for transfer/storage. */
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting. */
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
/* Delete a cJSON entity and all subentities. */
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
/* Returns the number of items in an array (or object). */
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
/* Get item "string" from object. Case insensitive. */
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
/* Check item type and return its value */
CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item);
CJSON_PUBLIC(double) cJSON_GetNumberValue(cJSON *item);
/* These functions check the type of an item */
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);
/* These calls create a cJSON item of the appropriate type. */
CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
/* raw json */
CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
/* Create a string where valuestring references a string so
* it will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
/* Create an object/array that only references it's elements so
* they will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
/* These utilities create an Array of count items.
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
/* Append item to the specified array/object. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
* writing to `item->string` */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
/* Remove/Detach items from Arrays/Objects. */
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
/* Update array items. */
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
/* Duplicate a cJSON item */
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
* The item->next and ->prev pointers are always zero on return from Duplicate. */
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
* The input pointer json cannot point to a read-only address area, such as a string constant,
* but should point to a readable and writable adress area. */
CJSON_PUBLIC(void) cJSON_Minify(char *json);
/* Helper functions for creating and adding items to an object at the same time.
* They return the added item or NULL on failure. */
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
/* helper for the cJSON_SetNumberValue macro */
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
/* Macro for iterating over an array or object */
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
CJSON_PUBLIC(void) cJSON_free(void *object);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,73 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR Canonical Ltd
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: apparmor@lists.ubuntu.com\n"
"POT-Creation-Date: 2020-10-14 03:52-0700\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: ../aa_enabled.c:21
#, c-format
msgid ""
"%s: [options]\n"
" options:\n"
" -x | --exclusive Shared interfaces must be available\n"
" -q | --quiet Don't print out any messages\n"
" -h | --help Print help\n"
msgstr ""
#: ../aa_enabled.c:37
#, c-format
msgid "No - not available on this system.\n"
msgstr ""
#: ../aa_enabled.c:41
#, c-format
msgid "No - disabled at boot.\n"
msgstr ""
#: ../aa_enabled.c:45
#, c-format
msgid "Maybe - policy interface not available.\n"
msgstr ""
#: ../aa_enabled.c:50
#, c-format
msgid "Maybe - insufficient permissions to determine availability.\n"
msgstr ""
#: ../aa_enabled.c:54
#, c-format
msgid "Partially - public shared interfaces are not available.\n"
msgstr ""
#: ../aa_enabled.c:58
#, c-format
msgid "Error - %s\n"
msgstr ""
#: ../aa_enabled.c:73
#, c-format
msgid "unknown or incompatible options\n"
msgstr ""
#: ../aa_enabled.c:87
#, c-format
msgid "unknown option '%s'\n"
msgstr ""
#: ../aa_enabled.c:98
#, c-format
msgid "Yes\n"
msgstr ""

55
binutils/po/aa_exec.pot Normal file
View File

@@ -0,0 +1,55 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR Canonical Ltd
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: apparmor@lists.ubuntu.com\n"
"POT-Creation-Date: 2020-10-14 03:52-0700\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: ../aa_exec.c:50
#, c-format
msgid ""
"USAGE: %s [OPTIONS] <prog> <args>\n"
"\n"
"Confine <prog> with the specified PROFILE.\n"
"\n"
"OPTIONS:\n"
" -p PROFILE, --profile=PROFILE\t\tPROFILE to confine <prog> with\n"
" -n NAMESPACE, --namespace=NAMESPACE\tNAMESPACE to confine <prog> in\n"
" -d, --debug\t\t\t\tshow messages with debugging information\n"
" -i, --immediate\t\t\tchange profile immediately instead of at exec\n"
" -v, --verbose\t\t\t\tshow messages with stats\n"
" -h, --help\t\t\t\tdisplay this help\n"
"\n"
msgstr ""
#: ../aa_exec.c:65
#, c-format
msgid "[%ld] aa-exec: ERROR: "
msgstr ""
#: ../aa_exec.c:76
#, c-format
msgid "[%ld] aa-exec: DEBUG: "
msgstr ""
#: ../aa_exec.c:89
#, c-format
msgid "[%ld] "
msgstr ""
#: ../aa_exec.c:107
#, c-format
msgid "[%ld] exec"
msgstr ""

View File

@@ -0,0 +1,51 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR Canonical Ltd
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: apparmor@lists.ubuntu.com\n"
"POT-Creation-Date: 2020-10-14 03:52-0700\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: ../aa_features_abi.c:53
#, c-format
msgid ""
"USAGE: %s [OPTIONS] <SOURCE> [OUTPUT OPTIONS]\n"
"\n"
"Output AppArmor feature abi from SOURCE to OUTPUT\n"
"OPTIONS:\n"
" -d, --debug show messages with debugging information\n"
" -v, --verbose show messages with stats\n"
" -h, --help display this help\n"
"SOURCE:\n"
" -f F, --file=F load features abi from file F\n"
" -x, --extract extract features abi from the kernel\n"
"OUTPUT OPTIONS:\n"
" --stdout default, write features to stdout\n"
" -w F, --write=F write features abi to the file F instead of stdout\n"
"\n"
msgstr ""
#: ../aa_features_abi.c:73
#, c-format
msgid "%s: ERROR: "
msgstr ""
#: ../aa_features_abi.c:85
#, c-format
msgid "%s: DEBUG: "
msgstr ""
#: ../aa_features_abi.c:98
msgid "\n"
msgstr ""

71
binutils/po/af.po Normal file
View File

@@ -0,0 +1,71 @@
# Afrikaans translation for apparmor
# Copyright (c) 2020 Rosetta Contributors and Canonical Ltd 2020
# This file is distributed under the same license as the apparmor package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2020.
#
msgid ""
msgstr ""
"Project-Id-Version: apparmor\n"
"Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n"
"POT-Creation-Date: 2015-11-28 10:23-0800\n"
"PO-Revision-Date: 2020-03-04 17:55+0000\n"
"Last-Translator: bernard stafford <Unknown>\n"
"Language-Team: Afrikaans <af@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Launchpad-Export-Date: 2020-03-05 05:40+0000\n"
"X-Generator: Launchpad (build e0878392dc799b267dea80578fa65500a5d74155)\n"
#: ../aa_enabled.c:26
#, c-format
msgid ""
"%s: [options]\n"
" options:\n"
" -q | --quiet Don't print out any messages\n"
" -h | --help Print help\n"
msgstr ""
"%s: [opsies]\n"
" opsies:\n"
" -q | --quiet Moenie druk uit enige boodskappe\n"
" -h | --help Afdruk hulp\n"
#: ../aa_enabled.c:45
#, c-format
msgid "unknown or incompatible options\n"
msgstr "onbekende of onversoenbare opsies\n"
#: ../aa_enabled.c:55
#, c-format
msgid "unknown option '%s'\n"
msgstr "onbekende opsie '%s'\n"
#: ../aa_enabled.c:64
#, c-format
msgid "Yes\n"
msgstr "Ja\n"
#: ../aa_enabled.c:71
#, c-format
msgid "No - not available on this system.\n"
msgstr "Geen - nie beskikbaar op hierdie stelsel.\n"
#: ../aa_enabled.c:74
#, c-format
msgid "No - disabled at boot.\n"
msgstr "Nee - gestremde by stewel.\n"
#: ../aa_enabled.c:77
#, c-format
msgid "Maybe - policy interface not available.\n"
msgstr "Miskien - beleid koppelvlak nie beskikbaar.\n"
#: ../aa_enabled.c:81
#, c-format
msgid "Maybe - insufficient permissions to determine availability.\n"
msgstr "Miskien - onvoldoende toestemmings om beskikbaarheid te bepaal.\n"
#: ../aa_enabled.c:84
#, c-format
msgid "Error - '%s'\n"
msgstr "Fout - '%s'\n"

View File

@@ -14,8 +14,8 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Launchpad-Export-Date: 2018-02-11 05:14+0000\n"
"X-Generator: Launchpad (build 18544)\n"
"X-Launchpad-Export-Date: 2019-04-18 05:33+0000\n"
"X-Generator: Launchpad (build 18928)\n"
"Language: de\n"
#: ../aa_enabled.c:26

View File

@@ -14,8 +14,8 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Launchpad-Export-Date: 2016-06-01 05:15+0000\n"
"X-Generator: Launchpad (build 18053)\n"
"X-Launchpad-Export-Date: 2019-04-18 05:33+0000\n"
"X-Generator: Launchpad (build 18928)\n"
"Language: en_GB\n"
#: ../aa_enabled.c:26

71
binutils/po/es.po Normal file
View File

@@ -0,0 +1,71 @@
# Spanish translation for apparmor
# Copyright (c) 2019 Rosetta Contributors and Canonical Ltd 2019
# This file is distributed under the same license as the apparmor package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2019.
#
msgid ""
msgstr ""
"Project-Id-Version: apparmor\n"
"Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n"
"POT-Creation-Date: 2015-11-28 10:23-0800\n"
"PO-Revision-Date: 2019-06-09 14:01+0000\n"
"Last-Translator: Adolfo Jayme <fitoschido@gmail.com>\n"
"Language-Team: Spanish <es@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Launchpad-Export-Date: 2019-06-10 04:32+0000\n"
"X-Generator: Launchpad (build 18978)\n"
#: ../aa_enabled.c:26
#, c-format
msgid ""
"%s: [options]\n"
" options:\n"
" -q | --quiet Don't print out any messages\n"
" -h | --help Print help\n"
msgstr ""
"%s: [opciones]\n"
" opciones:\n"
" -q | --quiet No emitir ningún mensaje\n"
" -h | --help Mostrar la ayuda\n"
#: ../aa_enabled.c:45
#, c-format
msgid "unknown or incompatible options\n"
msgstr "opciones desconocidas o incompatibles\n"
#: ../aa_enabled.c:55
#, c-format
msgid "unknown option '%s'\n"
msgstr "se desconoce la opción «%s»\n"
#: ../aa_enabled.c:64
#, c-format
msgid "Yes\n"
msgstr "Sí\n"
#: ../aa_enabled.c:71
#, c-format
msgid "No - not available on this system.\n"
msgstr "No; no disponible en este sistema.\n"
#: ../aa_enabled.c:74
#, c-format
msgid "No - disabled at boot.\n"
msgstr "No; desactivado durante el arranque.\n"
#: ../aa_enabled.c:77
#, c-format
msgid "Maybe - policy interface not available.\n"
msgstr "Quizá; interfaz de directiva no disponible.\n"
#: ../aa_enabled.c:81
#, c-format
msgid "Maybe - insufficient permissions to determine availability.\n"
msgstr "Quizá; permisos insuficientes para determinar disponibilidad.\n"
#: ../aa_enabled.c:84
#, c-format
msgid "Error - '%s'\n"
msgstr "Error: «%s»\n"

67
binutils/po/fa.po Normal file
View File

@@ -0,0 +1,67 @@
# Persian translation for apparmor
# Copyright (c) 2019 Rosetta Contributors and Canonical Ltd 2019
# This file is distributed under the same license as the apparmor package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2019.
#
msgid ""
msgstr ""
"Project-Id-Version: apparmor\n"
"Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n"
"POT-Creation-Date: 2015-11-28 10:23-0800\n"
"PO-Revision-Date: 2019-12-27 08:16+0000\n"
"Last-Translator: VahidNameni <Unknown>\n"
"Language-Team: Persian <fa@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Launchpad-Export-Date: 2019-12-28 05:38+0000\n"
"X-Generator: Launchpad (build bceb5ef013b87ef7aafe0755545ceb689ca7ac60)\n"
#: ../aa_enabled.c:26
#, c-format
msgid ""
"%s: [options]\n"
" options:\n"
" -q | --quiet Don't print out any messages\n"
" -h | --help Print help\n"
msgstr ""
#: ../aa_enabled.c:45
#, c-format
msgid "unknown or incompatible options\n"
msgstr "تنظیم نامعلوم یا ناسازگار\n"
#: ../aa_enabled.c:55
#, c-format
msgid "unknown option '%s'\n"
msgstr "تنظیم '%s' ناشناخته است\n"
#: ../aa_enabled.c:64
#, c-format
msgid "Yes\n"
msgstr "بله\n"
#: ../aa_enabled.c:71
#, c-format
msgid "No - not available on this system.\n"
msgstr "خیر- در این سیستم موجود نیست.\n"
#: ../aa_enabled.c:74
#, c-format
msgid "No - disabled at boot.\n"
msgstr "خیر - غیرفعال در زمان boot.\n"
#: ../aa_enabled.c:77
#, c-format
msgid "Maybe - policy interface not available.\n"
msgstr "شاید - رابط سیاست گذاری در دسترس نیست.\n"
#: ../aa_enabled.c:81
#, c-format
msgid "Maybe - insufficient permissions to determine availability.\n"
msgstr "شاید - دسترسی ناکافی جهت شناسایی در دسترس پذیری.\n"
#: ../aa_enabled.c:84
#, c-format
msgid "Error - '%s'\n"
msgstr "خطا - '%s'\n"

67
binutils/po/fi.po Normal file
View File

@@ -0,0 +1,67 @@
# Finnish translation for apparmor
# Copyright (c) 2020 Rosetta Contributors and Canonical Ltd 2020
# This file is distributed under the same license as the apparmor package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2020.
#
msgid ""
msgstr ""
"Project-Id-Version: apparmor\n"
"Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n"
"POT-Creation-Date: 2015-11-28 10:23-0800\n"
"PO-Revision-Date: 2020-01-29 07:44+0000\n"
"Last-Translator: Jiri Grönroos <Unknown>\n"
"Language-Team: Finnish <fi@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Launchpad-Export-Date: 2020-01-30 05:40+0000\n"
"X-Generator: Launchpad (build b8d1327fd820d6bf500589d6da587d5037c7d88e)\n"
#: ../aa_enabled.c:26
#, c-format
msgid ""
"%s: [options]\n"
" options:\n"
" -q | --quiet Don't print out any messages\n"
" -h | --help Print help\n"
msgstr ""
#: ../aa_enabled.c:45
#, c-format
msgid "unknown or incompatible options\n"
msgstr "tuntemattomat tai yhteensopimattomat valinnat\n"
#: ../aa_enabled.c:55
#, c-format
msgid "unknown option '%s'\n"
msgstr "tuntematon valinta '%s'\n"
#: ../aa_enabled.c:64
#, c-format
msgid "Yes\n"
msgstr "Kyllä\n"
#: ../aa_enabled.c:71
#, c-format
msgid "No - not available on this system.\n"
msgstr "Ei - ei käytettävissä tässä järjestelmässä.\n"
#: ../aa_enabled.c:74
#, c-format
msgid "No - disabled at boot.\n"
msgstr "Ei - poistettu käytöstä käynnistyksen yhteydessä.\n"
#: ../aa_enabled.c:77
#, c-format
msgid "Maybe - policy interface not available.\n"
msgstr ""
#: ../aa_enabled.c:81
#, c-format
msgid "Maybe - insufficient permissions to determine availability.\n"
msgstr ""
#: ../aa_enabled.c:84
#, c-format
msgid "Error - '%s'\n"
msgstr "Virhe - '%s'\n"

View File

@@ -14,8 +14,8 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Launchpad-Export-Date: 2016-06-01 05:15+0000\n"
"X-Generator: Launchpad (build 18053)\n"
"X-Launchpad-Export-Date: 2019-04-18 05:33+0000\n"
"X-Generator: Launchpad (build 18928)\n"
"Language: id\n"
#: ../aa_enabled.c:26

View File

@@ -9,13 +9,13 @@ msgstr ""
"Report-Msgid-Bugs-To: AppArmor list <apparmor@lists.ubuntu.com>\n"
"POT-Creation-Date: 2015-11-28 10:23-0800\n"
"PO-Revision-Date: 2016-03-03 08:34+0000\n"
"Last-Translator: Ivo Xavier <ivoxavier.8@gmail.com>\n"
"Last-Translator: Ivo Xavier <ivofernandes12@gmail.com>\n"
"Language-Team: Portuguese <pt@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Launchpad-Export-Date: 2016-06-01 05:15+0000\n"
"X-Generator: Launchpad (build 18053)\n"
"X-Launchpad-Export-Date: 2019-04-18 05:33+0000\n"
"X-Generator: Launchpad (build 18928)\n"
"Language: pt\n"
#: ../aa_enabled.c:26

72
binutils/po/ro.po Normal file
View File

@@ -0,0 +1,72 @@
# Romanian translation for apparmor
# Copyright (c) 2020 Rosetta Contributors and Canonical Ltd 2020
# This file is distributed under the same license as the apparmor package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2020.
#
msgid ""
msgstr ""
"Project-Id-Version: apparmor\n"
"Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n"
"POT-Creation-Date: 2015-11-28 10:23-0800\n"
"PO-Revision-Date: 2020-02-20 21:47+0000\n"
"Last-Translator: Daniel Slavu <Unknown>\n"
"Language-Team: Romanian <ro@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Launchpad-Export-Date: 2020-02-21 05:39+0000\n"
"X-Generator: Launchpad (build 19413b719a8df7423ab1390528edadce9e0e4aca)\n"
#: ../aa_enabled.c:26
#, c-format
msgid ""
"%s: [options]\n"
" options:\n"
" -q | --quiet Don't print out any messages\n"
" -h | --help Print help\n"
msgstr ""
"%s: [opțiuni]\n"
" opțiuni:\n"
" -q | --calm Nu imprima niciun mesaj\n"
" -h | - ajutor Imprimare ajutor\n"
#: ../aa_enabled.c:45
#, c-format
msgid "unknown or incompatible options\n"
msgstr "opțiuni necunoscute sau incompatibile\n"
#: ../aa_enabled.c:55
#, c-format
msgid "unknown option '%s'\n"
msgstr "opțiune necunoscută '%s'\n"
#: ../aa_enabled.c:64
#, c-format
msgid "Yes\n"
msgstr "Da\n"
#: ../aa_enabled.c:71
#, c-format
msgid "No - not available on this system.\n"
msgstr "Nu - nu este disponibil pe acest sistem.\n"
#: ../aa_enabled.c:74
#, c-format
msgid "No - disabled at boot.\n"
msgstr "Nu - dezactivat la pornire.\n"
#: ../aa_enabled.c:77
#, c-format
msgid "Maybe - policy interface not available.\n"
msgstr "Poate - interfața politică nu este disponibilă.\n"
#: ../aa_enabled.c:81
#, c-format
msgid "Maybe - insufficient permissions to determine availability.\n"
msgstr ""
"Poate - permisiuni insuficiente pentru a determina disponibilitatea.\n"
#: ../aa_enabled.c:84
#, c-format
msgid "Error - '%s'\n"
msgstr "Eroare - '%s'\n"

View File

@@ -9,13 +9,13 @@ msgstr ""
"Report-Msgid-Bugs-To: AppArmor list <apparmor@lists.ubuntu.com>\n"
"POT-Creation-Date: 2015-11-28 10:23-0800\n"
"PO-Revision-Date: 2016-03-29 14:46+0000\n"
"Last-Translator: Eugene Marshal <Unknown>\n"
"Last-Translator: Eugene Roskin <Unknown>\n"
"Language-Team: Russian <ru@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Launchpad-Export-Date: 2016-06-01 05:15+0000\n"
"X-Generator: Launchpad (build 18053)\n"
"X-Launchpad-Export-Date: 2019-04-18 05:33+0000\n"
"X-Generator: Launchpad (build 18928)\n"
"Language: ru\n"
#: ../aa_enabled.c:26

72
binutils/po/sv.po Normal file
View File

@@ -0,0 +1,72 @@
# Swedish translation for apparmor
# Copyright (c) 2018 Rosetta Contributors and Canonical Ltd 2018
# This file is distributed under the same license as the apparmor package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2018.
#
msgid ""
msgstr ""
"Project-Id-Version: apparmor\n"
"Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n"
"POT-Creation-Date: 2015-11-28 10:23-0800\n"
"PO-Revision-Date: 2018-09-08 03:51+0000\n"
"Last-Translator: Jonatan Nyberg <Unknown>\n"
"Language-Team: Swedish <sv@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Launchpad-Export-Date: 2019-04-18 05:33+0000\n"
"X-Generator: Launchpad (build 18928)\n"
#: ../aa_enabled.c:26
#, c-format
msgid ""
"%s: [options]\n"
" options:\n"
" -q | --quiet Don't print out any messages\n"
" -h | --help Print help\n"
msgstr ""
"%s: [options]\n"
" flaggor:\n"
" -q | --quiet Skriv inte ut några meddelanden\n"
" -h | --help Skriv ut hjälp\n"
#: ../aa_enabled.c:45
#, c-format
msgid "unknown or incompatible options\n"
msgstr "okända eller inkompatibla flaggor\n"
#: ../aa_enabled.c:55
#, c-format
msgid "unknown option '%s'\n"
msgstr "okänd flagga '%s'\n"
#: ../aa_enabled.c:64
#, c-format
msgid "Yes\n"
msgstr "Ja\n"
#: ../aa_enabled.c:71
#, c-format
msgid "No - not available on this system.\n"
msgstr "Nej - inte tillgänglig på detta system.\n"
#: ../aa_enabled.c:74
#, c-format
msgid "No - disabled at boot.\n"
msgstr "Nej - inaktiverad vid uppstart.\n"
#: ../aa_enabled.c:77
#, c-format
msgid "Maybe - policy interface not available.\n"
msgstr "Kanske - policy gränssnitt inte tillgängliga.\n"
#: ../aa_enabled.c:81
#, c-format
msgid "Maybe - insufficient permissions to determine availability.\n"
msgstr ""
"Kanske - otillräckliga behörigheter för att bestämma tillgängligheten.\n"
#: ../aa_enabled.c:84
#, c-format
msgid "Error - '%s'\n"
msgstr "Fel - '%s'\n"

71
binutils/po/sw.po Normal file
View File

@@ -0,0 +1,71 @@
# Swahili translation for apparmor
# Copyright (c) 2019 Rosetta Contributors and Canonical Ltd 2019
# This file is distributed under the same license as the apparmor package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2019.
#
msgid ""
msgstr ""
"Project-Id-Version: apparmor\n"
"Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n"
"POT-Creation-Date: 2015-11-28 10:23-0800\n"
"PO-Revision-Date: 2019-11-14 12:33+0000\n"
"Last-Translator: Swahilinux Administration <admin@swahilinux.org>\n"
"Language-Team: Swahili <sw@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Launchpad-Export-Date: 2019-11-15 04:30+0000\n"
"X-Generator: Launchpad (build c597c3229eb023b1e626162d5947141bf7befb13)\n"
#: ../aa_enabled.c:26
#, c-format
msgid ""
"%s: [options]\n"
" options:\n"
" -q | --quiet Don't print out any messages\n"
" -h | --help Print help\n"
msgstr ""
"%s: [chaguzi]\n"
" chaguzi:\n"
" -q | --quiet Usichapishe jumbe yoyote\n"
" -h | --help Chapisha msaada\n"
#: ../aa_enabled.c:45
#, c-format
msgid "unknown or incompatible options\n"
msgstr "chaguo lisilojulikana au lisilofaa\n"
#: ../aa_enabled.c:55
#, c-format
msgid "unknown option '%s'\n"
msgstr "chaguo lisilojulikana '%s'\n"
#: ../aa_enabled.c:64
#, c-format
msgid "Yes\n"
msgstr "Ndio\n"
#: ../aa_enabled.c:71
#, c-format
msgid "No - not available on this system.\n"
msgstr "La - haipo kwenye mfumo huu.\n"
#: ../aa_enabled.c:74
#, c-format
msgid "No - disabled at boot.\n"
msgstr "La - ilizimwa kwenye washi.\n"
#: ../aa_enabled.c:77
#, c-format
msgid "Maybe - policy interface not available.\n"
msgstr "Labda - kiolesura cha faragha hakipo.\n"
#: ../aa_enabled.c:81
#, c-format
msgid "Maybe - insufficient permissions to determine availability.\n"
msgstr "Labda - hamna ruhusa ya kutosha ili kuamua kama ipo.\n"
#: ../aa_enabled.c:84
#, c-format
msgid "Error - '%s'\n"
msgstr "Dosari - '%s'\n"

72
binutils/po/tr.po Normal file
View File

@@ -0,0 +1,72 @@
# Turkish translation for apparmor
# Copyright (c) 2018 Rosetta Contributors and Canonical Ltd 2018
# This file is distributed under the same license as the apparmor package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2018.
#
msgid ""
msgstr ""
"Project-Id-Version: apparmor\n"
"Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n"
"POT-Creation-Date: 2015-11-28 10:23-0800\n"
"PO-Revision-Date: 2018-05-19 23:10+0000\n"
"Last-Translator: Kudret EMRE <kudretemre@hotmail.com>\n"
"Language-Team: Turkish <tr@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Launchpad-Export-Date: 2019-04-18 05:33+0000\n"
"X-Generator: Launchpad (build 18928)\n"
#: ../aa_enabled.c:26
#, c-format
msgid ""
"%s: [options]\n"
" options:\n"
" -q | --quiet Don't print out any messages\n"
" -h | --help Print help\n"
msgstr ""
"%s: [seçenekler]\n"
" seçenekler:\n"
" -q | --quiet Hiçbir mesajı gösterme\n"
" -h | --help Yardımı görüntüler\n"
#: ../aa_enabled.c:45
#, c-format
msgid "unknown or incompatible options\n"
msgstr "bilinmeyen veya uyumsuz seçenekler\n"
#: ../aa_enabled.c:55
#, c-format
msgid "unknown option '%s'\n"
msgstr "bilinmeyen seçenek '%s'\n"
#: ../aa_enabled.c:64
#, c-format
msgid "Yes\n"
msgstr "Evet\n"
#: ../aa_enabled.c:71
#, c-format
msgid "No - not available on this system.\n"
msgstr "Hayır - Bu sistemde kullanılabilir değil.\n"
#: ../aa_enabled.c:74
#, c-format
msgid "No - disabled at boot.\n"
msgstr "Hayır - önyüklemede devredışı bırakıldı.\n"
#: ../aa_enabled.c:77
#, c-format
msgid "Maybe - policy interface not available.\n"
msgstr "Belki - policy arayüzü kullanılabilir değil.\n"
#: ../aa_enabled.c:81
#, c-format
msgid "Maybe - insufficient permissions to determine availability.\n"
msgstr ""
"Belki - kullanılabilir olup olmadığını denetlemek için yetersiz yetki.\n"
#: ../aa_enabled.c:84
#, c-format
msgid "Error - '%s'\n"
msgstr "Hata - '%s'\n"

View File

@@ -70,6 +70,8 @@ libapparmor by adding USE_SYSTEM=1 to your make command.${nl}\
LDLIBS = -lapparmor
endif
APXS_CFLAGS="-Wc,$(EXTRA_WARNINGS)"
.PHONY: libapparmor_check
.SILENT: libapparmor_check
libapparmor_check: ; $(ERROR_MESSAGE)
@@ -80,7 +82,7 @@ all: libapparmor_check $(TARGET) docs
docs: ${MANPAGES} ${HTMLMANPAGES}
%.so: %.c
${APXS} ${LIBAPPARMOR_FLAGS} -c $< ${LDLIBS}
${APXS} ${LIBAPPARMOR_FLAGS} ${APXS_CFLAGS} -c $< ${LDLIBS}
mv .libs/$@ .
.PHONY: install

View File

@@ -30,6 +30,10 @@
/* #define DEBUG */
#ifndef unused_
#define unused_ __attribute__ ((unused))
#endif
/* should the following be configurable? */
#define DEFAULT_HAT "HANDLING_UNTRUSTED_INPUT"
#define DEFAULT_URI_HAT "DEFAULT_URI"
@@ -65,7 +69,7 @@ typedef struct {
* memory will be wiped out, and the magic_token will be lost, so apache
* wouldn't be able to change_hat back out. */
static int
aa_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
aa_init(apr_pool_t *p, unused_ apr_pool_t *plog, unused_ apr_pool_t *ptemp, unused_ server_rec *s)
{
apr_file_t *file;
apr_size_t size = sizeof(magic_token);
@@ -89,7 +93,7 @@ aa_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
* to protect ourselves from bugs in parsing network input, but before
* we change_hat to the uri specific hat. */
static void
aa_child_init(apr_pool_t *p, server_rec *s)
aa_child_init(unused_ apr_pool_t *p, unused_ server_rec *s)
{
int ret;
@@ -260,7 +264,7 @@ aa_exit_hat(request_rec *r)
}
static const char *
aa_cmd_ch_path(cmd_parms *cmd, void *mconfig, const char *parm1)
aa_cmd_ch_path(unused_ cmd_parms *cmd, unused_ void *mconfig, const char *parm1)
{
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, "directory config change hat %s",
parm1 ? parm1 : "DEFAULT");
@@ -287,7 +291,7 @@ immunix_cmd_ch_path(cmd_parms *cmd, void *mconfig, const char *parm1)
}
static const char *
aa_cmd_ch_srv(cmd_parms *cmd, void *mconfig, const char *parm1)
aa_cmd_ch_srv(cmd_parms *cmd, unused_ void *mconfig, const char *parm1)
{
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, "server config change hat %s",
parm1 ? parm1 : "DEFAULT");
@@ -347,7 +351,7 @@ aa_merge_dir_config(apr_pool_t *p, void *parent, void *child)
*/
static void *
aa_create_srv_config(apr_pool_t *p, server_rec *srv)
aa_create_srv_config(apr_pool_t *p, unused_ server_rec *srv)
{
apparmor_srv_cfg *newcfg = (apparmor_srv_cfg *) apr_pcalloc(p, sizeof(*newcfg));
@@ -397,7 +401,7 @@ static const command_rec mod_apparmor_cmds[] = {
};
static void
register_hooks(apr_pool_t *p)
register_hooks(unused_ apr_pool_t *p)
{
ap_hook_post_config(aa_init, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_child_init(aa_child_init, NULL, NULL, APR_HOOK_MIDDLE);
@@ -408,7 +412,7 @@ register_hooks(apr_pool_t *p)
module AP_MODULE_DECLARE_DATA apparmor_module = {
STANDARD20_MODULE_STUFF,
aa_create_dir_config, /* dir config creater */
aa_create_dir_config, /* dir config creator */
NULL, /* dir merger --- default is to override */
/* immunix_merge_dir_config, */ /* dir merger --- default is to override */
aa_create_srv_config, /* server config */

View File

@@ -135,11 +135,11 @@ may not work correctly. For Apache 2.4 users, you should enable the mpm_prefork
module.
There are likely other bugs lurking about; if you find any, please report
them at L<https://bugs.launchpad.net/apparmor/+filebug>.
them at L<https://gitlab.com/apparmor/apparmor/-/issues>.
=head1 SEE ALSO
apparmor(7), subdomain.conf(5), apparmor_parser(8), aa_change_hat(2) and
L<http://wiki.apparmor.net>.
apparmor(7), apparmor_parser(8), aa_change_hat(2) and
L<https://wiki.apparmor.net>.
=cut

View File

@@ -54,7 +54,7 @@ libapparmor by adding USE_SYSTEM=1 to your make command.${nl}\
AA_LINK_FLAGS = -L$(LIBAPPARMOR_PATH)
AA_LDLIBS = -lapparmor
endif
EXTRA_CFLAGS=$(CFLAGS) $(CPPFLAGS) -fPIC -shared -Wall $(LIBAPPARMOR_INCLUDE)
EXTRA_CFLAGS=$(CFLAGS) $(CPPFLAGS) -fPIC -shared -Wall $(EXTRA_WARNINGS) $(LIBAPPARMOR_INCLUDE)
LINK_FLAGS=-Xlinker -x $(AA_LINK_FLAGS) $(LDFLAGS)
LIBS=-lpam $(AA_LDLIBS)
OBJECTS=${NAME}.o get_options.o

View File

@@ -45,6 +45,10 @@
int debug_flag = 0;
#ifndef unused_
#define unused_ __attribute__ ((unused))
#endif
static struct config default_config = {
.hat_type[0] = eGroupname,
.hat_type[1] = eDefault,
@@ -54,14 +58,14 @@ static struct config default_config = {
/* --- session management functions (only) --- */
PAM_EXTERN int
pam_sm_close_session (pam_handle_t *pamh, int flags,
int argc, const char **argv)
pam_sm_close_session (unused_ pam_handle_t *pamh, unused_ int flags,
unused_ int argc, unused_ const char **argv)
{
return PAM_IGNORE;
}
PAM_EXTERN
int pam_sm_open_session(pam_handle_t *pamh, int flags,
int pam_sm_open_session(pam_handle_t *pamh, unused_ int flags,
int argc, const char **argv)
{
int fd, retval, pam_retval = PAM_SUCCESS;

View File

@@ -66,8 +66,8 @@ under src/jni_src.
cp dist/libJNIChangeHat.so /usr/lib
[Note: you must ensure that the target directory is passed to tomcat via the
java.library.path propert. This can be accomplished by setting the JAVA_OPTS
enviroment variable, export JAVA_OPTS=-Djava.library.path, or set via the
java.library.path property. This can be accomplished by setting the JAVA_OPTS
environment variable, export JAVA_OPTS=-Djava.library.path, or set via the
env variable LD_LIBRARY_PATH to include this directory so that tomcat can
find this library at startup]
@@ -108,13 +108,13 @@ under src/jni_src.
Once the installation steps above have been started you are ready to begin
creating a profile for your application. The profile creation tool genprof will
guide you through generating a profile and its support for change_hat will
prompt you create discrete hats as requested byt the changeHatValve during
prompt you create discrete hats as requested by the changeHatValve during
tomcat execution.
1. Create a basic profile for the tomcat server.
- Run the command "genprof PATH_TO_CATALINA.SH"
- In a seperate window start tomcat and then stop tomcat
- In a separate window start tomcat and then stop tomcat
- In the genprof window press "S" to scan for events
- Answer the questions about the initial profile for tomcat
@@ -124,7 +124,7 @@ tomcat execution.
- Stop the tomcat server
- Deploy your WAR file or equivalent files under the container.
- execute "genprof PATH_TO_CATALINA.SH"
- In a seperate window start tomcat and then exercise your web application
- In a separate window start tomcat and then exercise your web application
- In the genprof window press "S" to scan for events
During the prompting you will be asked questions similar to:
@@ -180,7 +180,7 @@ all subsequent resource requests will be mediated in this hew hat (or security
context).
If you choose to use the default hat: genprof will mediate all resource
requests in the default hat for the duration of processing this request.
When the request processng is complete the valve will change_hat back to the
When the request processing is complete the valve will change_hat back to the
parent context.

View File

@@ -66,8 +66,8 @@ under src/jni_src.
cp dist/libJNIChangeHat.so /usr/lib
[Note: you must ensure that the target directory is passed to tomcat via the
java.library.path propert. This can be accomplished by setting the JAVA_OPTS
enviroment variable, export JAVA_OPTS=-Djava.library.path, or set via the
java.library.path property. This can be accomplished by setting the JAVA_OPTS
environment variable, export JAVA_OPTS=-Djava.library.path, or set via the
env variable LD_LIBRARY_PATH to include this directory so that tomcat can
find this library at startup]
@@ -108,13 +108,13 @@ under src/jni_src.
Once the installation steps above have been started you are ready to begin
creating a profile for your application. The profile creation tool genprof will
guide you through generating a profile and its support for change_hat will
prompt you create discrete hats as requested byt the changeHatValve during
prompt you create discrete hats as requested by the changeHatValve during
tomcat execution.
1. Create a basic profile for the tomcat server.
- Run the command "genprof PATH_TO_CATALINA.SH"
- In a seperate window start tomcat and then stop tomcat
- In a separate window start tomcat and then stop tomcat
- In the genprof window press "S" to scan for events
- Answer the questions about the initial profile for tomcat
@@ -124,7 +124,7 @@ tomcat execution.
- Stop the tomcat server
- Deploy your WAR file or equivalent files under the container.
- execute "genprof PATH_TO_CATALINA.SH"
- In a seperate window start tomcat and then exercise your web application
- In a separate window start tomcat and then exercise your web application
- In the genprof window press "S" to scan for events
During the prompting you will be asked questions similar to:
@@ -180,7 +180,7 @@ all subsequent resource requests will be mediated in this hew hat (or security
context).
If you choose to use the default hat: genprof will mediate all resource
requests in the default hat for the duration of processing this request.
When the request processng is complete the valve will change_hat back to the
When the request processing is complete the valve will change_hat back to the
parent context.

View File

@@ -47,7 +47,7 @@ endef
REPO_VERSION_CMD=[ -x /usr/bin/git ] && /usr/bin/git describe --tags --long --abbrev=16 --match 'v*' 2> /dev/null || awk '{ print $2 }' common/.stamp_rev
ifndef PYTHON_VERSIONS
PYTHON_VERSIONS = $(call map, pathsearch, python2 python3)
PYTHON_VERSIONS = $(call map, pathsearch, python3)
endif
ifndef PYTHON
@@ -57,6 +57,18 @@ endif
#Helper function to be used with $(call pyalldo, run_test_with_all.py)
pyalldo=set -e; $(foreach py, $(PYTHON_VERSIONS), $(py) $(1);)
# Common set of compiler warnings
_EXTRA_WARNINGS = -Wall -Wsign-compare -Wmissing-field-initializers -Wformat -Wformat-security -Wunused-parameter -Wimplicit-fallthrough
EXTRA_WARNINGS := $(shell for warning in ${_EXTRA_WARNINGS} ; do \
if ${CC} $${warning} -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then \
echo "$${warning}"; \
else \
echo "***" >&2 ; \
echo "WARNING: unable to use $${warning} with ${CC}, dropping" >&2 ; \
echo "***" >&2 ; \
fi ; \
done)
.PHONY: version
.SILENT: version
version:
@@ -74,40 +86,6 @@ endif
pod_clean:
-rm -f ${MANPAGES} *.[0-9].gz ${HTMLMANPAGES} pod2htm*.tmp
# =====================
# generate list of capabilities based on
# /usr/include/linux/capabilities.h for use in multiple locations in
# the source tree
# =====================
# emits defined capabilities in a simple list, e.g. "CAP_NAME CAP_NAME2"
CAPABILITIES=$(shell echo "\#include <linux/capability.h>" | cpp -dM | LC_ALL=C sed -n -e '/CAP_EMPTY_SET/d' -e 's/^\#define[ \t]\+CAP_\([A-Z0-9_]\+\)[ \t]\+\([0-9xa-f]\+\)\(.*\)$$/CAP_\1/p' | LC_ALL=C sort)
.PHONY: list_capabilities
list_capabilities: /usr/include/linux/capability.h
@echo "$(CAPABILITIES)"
# =====================
# generate list of network protocols based on
# sys/socket.h for use in multiple locations in
# the source tree
# =====================
# These are the families that it doesn't make sense for apparmor
# to mediate. We use PF_ here since that is what is required in
# bits/socket.h, but we will rewrite these as AF_.
FILTER_FAMILIES=PF_UNIX
__FILTER=$(shell echo $(strip $(FILTER_FAMILIES)) | sed -e 's/ /\\\|/g')
# emits the AF names in a "AF_NAME NUMBER," pattern
AF_NAMES=$(shell echo "\#include <sys/socket.h>" | cpp -dM | LC_ALL=C sed -n -e '/$(__FILTER)/d' -e 's/PF_LOCAL/PF_UNIX/' -e 's/^\#define[ \t]\+PF_\([A-Z0-9_]\+\)[ \t]\+\([0-9]\+\).*$$/AF_\1 \2,/p' | sort -n -k2)
.PHONY: list_af_names
list_af_names:
@echo "$(AF_NAMES)"
# =====================
# manpages
# =====================

View File

@@ -1 +1 @@
2.13
3.1.6

19
common/list_af_names.sh Executable file
View File

@@ -0,0 +1,19 @@
#!/bin/bash -e
# =====================
# generate list of network protocols based on
# sys/socket.h for use in multiple locations in
# the source tree
# =====================
# It doesn't make sense for AppArmor to mediate PF_UNIX, filter it out. Search
# for "PF_" constants since that is what is required in bits/socket.h, but
# rewrite as "AF_".
echo "#include <sys/socket.h>" | \
cpp -dM | \
LC_ALL=C sed -n \
-e '/PF_UNIX/d' \
-e 's/PF_LOCAL/PF_UNIX/' \
-e 's/^#define[ \t]\+PF_\([A-Z0-9_]\+\)[ \t]\+\([0-9]\+\).*$/AF_\1 \2,/p' | \
sort -n -k2

14
common/list_capabilities.sh Executable file
View File

@@ -0,0 +1,14 @@
#!/bin/bash -e
# =====================
# generate list of capabilities based on
# /usr/include/linux/capabilities.h for use in multiple locations in
# the source tree
# =====================
echo "#include <linux/capability.h>" | \
cpp -dM | \
LC_ALL=C sed -n \
-e '/CAP_EMPTY_SET/d' \
-e 's/^\#define[ \t]\+CAP_\([A-Z0-9_]\+\)[ \t]\+\([0-9xa-f]\+\)\(.*\)$/CAP_\1/p' | \
LC_ALL=C sort

View File

@@ -1,137 +0,0 @@
#!/bin/sh
# ----------------------------------------------------------------------
# Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
# NOVELL (All rights reserved)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
# ----------------------------------------------------------------------
# rc.apparmor by Steve Beattie
#
# /etc/init.d/aaeventd
# and its symbolic link
# /sbin/rcaaeventd
#
# chkconfig: 2345 01 99
# description: AppArmor Notification and Reporting daemon
#
### BEGIN INIT INFO
# Provides: aaeventd
# Required-Start: apparmor
# Required-Stop:
# Default-Start: 2 3 5
# Default-Stop:
# Short-Description: AppArmor Notification and Reporting
# Description: AppArmor Notification and Reporting daemon
### END INIT INFO
APPARMOR_FUNCTIONS=/lib/apparmor/rc.apparmor.functions
# source function library
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
elif [ -f /lib/lsb/init-functions ]; then
. /lib/lsb/init-functions
else
exit 0
fi
sd_log_success_msg() {
echo -n "$*"
success
echo
}
sd_log_warning_msg() {
echo -n "$*"
warning
echo
}
sd_log_skipped_msg() {
echo -n "$*"
warning
echo
}
sd_log_failure_msg() {
echo -n "$*"
failure
echo
}
sd_action() {
STRING=$1
shift
action "${STRING} " "$@"
return $?
}
start_aa_event() {
if [ -x "$AA_EV_BIN" -a "${APPARMOR_ENABLE_AAEVENTD}" = "yes" ] ; then
sd_action "Starting AppArmor Event daemon" daemon --pidfile $AA_EV_PIDFILE $AA_EV_BIN -p $AA_EV_PIDFILE
elif [ -x "$SD_EV_BIN" -a "${APPARMOR_ENABLE_AAEVENTD}" = "yes" ] ; then
sd_action "Starting AppArmor Event daemon" daemon --pidfile $SD_EV_PIDFILE $SD_EV_BIN -p $SD_EV_PIDFILE
fi
}
stop_aa_event() {
if [ -x "$AA_EV_BIN" -a -f "$AA_EV_PIDFILE" ] ; then
sd_action "Shutting down AppArmor Event daemon" killproc -p $AA_EV_PIDFILE -INT $AA_EV_BIN
fi
if [ -f "$SD_EV_PIDFILE" ] ; then
sd_action "Shutting down AppArmor Event daemon" killproc -p $SD_EV_PIDFILE -INT $SD_EV_BIN
fi
}
usage() {
echo "Usage: $0 {start|stop|restart|try-restart|reload|force-reload|status}"
}
# source apparmor function library
if [ -f "${APPARMOR_FUNCTIONS}" ]; then
. ${APPARMOR_FUNCTIONS}
else
sd_log_failure_msg "Unable to find AppArmor initscript functions"
exit 1
fi
case "$1" in
start)
start_aa_event
rc=$?
;;
stop)
stop_aa_event
rc=$?
;;
restart|reload|force-reload|try-restart)
stop_aa_event
start_aa_event
rc=$?
;;
status)
echo -n "Checking for service AppArmor Event daemon:"
if [ "${APPARMOR_ENABLE_AAEVENTD}" = "yes" ]; then
/sbin/checkproc -p $AA_EV_PIDFILE $AA_EV_BIN
rc_status -v
else
rc_status -u
fi
;;
*)
usage
exit 1
;;
esac
exit $rc

View File

@@ -1,133 +0,0 @@
#!/bin/sh
# ----------------------------------------------------------------------
# Copyright (c) 1999, 2000, 2001, 2002, 2003 2004, 2005, 2006, 2007
# NOVELL (All rights reserved)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
# ----------------------------------------------------------------------
# rc.apparmor by Steve Beattie
#
# /etc/init.d/aaeventd
# and its symbolic link
# /sbin/rcaaeventd
#
# chkconfig: 2345 01 99
# description: AppArmor Notification and Reporting daemon
#
### BEGIN INIT INFO
# Provides: aaeventd
# Required-Start: apparmor
# Required-Stop: $null
# Default-Start: 2 3 5
# Default-Stop:
# Short-Description: AppArmor Notification and Reporting
# Description: AppArmor Notification and Reporting daemon
### END INIT INFO
APPARMOR_FUNCTIONS=/lib/apparmor/rc.apparmor.functions
# source function library
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
elif [ -f /lib/lsb/init-functions ]; then
. /lib/lsb/init-functions
else
exit 0
fi
# Ugh, SUSE doesn't implement action
sd_action() {
STRING=$1
shift
"$@"
rc=$?
if [ $rc -eq 0 ] ; then
log_success_msg $"$STRING "
else
log_failure_msg $"$STRING "
fi
return $rc
}
sd_log_success_msg() {
log_success_msg $*
}
sd_log_warning_msg() {
log_warning_msg $*
}
sd_log_failure_msg() {
log_failure_msg $*
}
usage() {
echo "Usage: $0 {start|stop|restart|try-restart|reload|force-reload|status}"
}
start_aa_event() {
if [ -x "$AA_EV_BIN" -a "${APPARMOR_ENABLE_AAEVENTD}" = "yes" ] ; then
sd_action "Starting AppArmor Event daemon" startproc -p $AA_EV_PIDFILE $AA_EV_BIN -p $AA_EV_PIDFILE
elif [ -x "$SD_EV_BIN" -a "${APPARMOR_ENABLE_AAEVENTD}" = "yes" ] ; then
sd_action "Starting AppArmor Event daemon" startproc -p $SD_EV_PIDFILE $SD_EV_BIN -p $SD_EV_PIDFILE
fi
}
stop_aa_event() {
if [ -x "$AA_EV_BIN" -a -f "$AA_EV_PIDFILE" ] ; then
sd_action "Shutting down AppArmor Event daemon" killproc -G -p $AA_EV_PIDFILE -INT $AA_EV_BIN
fi
if [ -f "$SD_EV_PIDFILE" ] ; then
sd_action "Shutting down AppArmor Event daemon" killproc -G -p $SD_EV_PIDFILE -INT $SD_EV_BIN
fi
}
# source apparmor function library
if [ -f "${APPARMOR_FUNCTIONS}" ]; then
. ${APPARMOR_FUNCTIONS}
else
sd_log_failure_msg "Unable to find AppArmor initscript functions"
exit 1
fi
case "$1" in
start)
start_aa_event
rc=$?
;;
stop)
stop_aa_event
rc=$?
;;
restart|reload|force-reload|try-restart)
stop_aa_event
start_aa_event
rc=$?
;;
status)
echo -n "Checking for service AppArmor Event daemon:"
if [ "${APPARMOR_ENABLE_AAEVENTD}" = "yes" ]; then
/sbin/checkproc -p $AA_EV_PIDFILE $AA_EV_BIN
rc_status -v
else
rc_status -u
fi
;;
*)
usage
exit 1
;;
esac
exit $rc

File diff suppressed because it is too large Load Diff

View File

@@ -1,124 +0,0 @@
# ----------------------------------------------------------------------
# Copyright (c) 2006 Novell, Inc. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com.
# ----------------------------------------------------------------------
package Immunix::Config;
use strict;
use warnings;
use Carp;
use Cwd qw(cwd realpath);
use File::Basename;
use File::Temp qw/ tempfile tempdir /;
use Data::Dumper;
use Locale::gettext;
use POSIX;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(
read_config
write_config
find_first_file
find_first_dir
);
our $confdir = "/etc/apparmor";
# config vars
our $cfg;
our $repo_cfg;
sub read_config {
my $filename = shift;
my $config;
if (open(CONF, "$confdir/$filename")) {
my $which;
while (<CONF>) {
chomp;
# ignore comments
next if /^\s*#/;
if (m/^\[(\S+)\]/) {
$which = $1;
} elsif (m/^\s*(\S+)\s*=\s*(.*)\s*$/) {
my ($key, $value) = ($1, $2);
$config->{$which}{$key} = $value;
}
}
close(CONF);
}
# LP: #692406
# Explicitly disable the repository until there is an alternative, since
# the OpenSUSE site went away
if ($filename eq "repository.conf") {
$config->{repository}{enabled} = "no";
}
return $config;
}
sub write_config {
my ($filename, $config) = @_;
if (open(my $CONF, ">$confdir/$filename")) {
for my $section (sort keys %$config) {
print $CONF "[$section]\n";
for my $key (sort keys %{$config->{$section}}) {
print $CONF " $key = $config->{$section}{$key}\n"
if ($config->{$section}{$key});
}
}
chmod(0600, $CONF);
close($CONF);
} else {
die "Can't write config file $filename: $!";
}
}
sub find_first_file {
my $list = shift;
return if ( not defined $list );
my $filename;
for my $f (split(/\s+/, $list)) {
if (-f $f) {
$filename = $f;
last;
}
}
return $filename;
}
sub find_first_dir {
my $list = shift;
return if ( not defined $list );
my $dirname;
for my $f (split(/\s+/, $list)) {
if (-d $f) {
$dirname = $f;
last;
}
}
return $dirname;
}
1;

File diff suppressed because it is too large Load Diff

View File

@@ -1,354 +0,0 @@
# ----------------------------------------------------------------------
# Copyright (c) 2008 Dominic Reynolds
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# ----------------------------------------------------------------------
package Immunix::Repository;
use strict;
use warnings;
use Carp;
use Cwd qw(cwd realpath);
use Data::Dumper;
use File::Basename;
use File::Temp qw/ tempfile tempdir /;
use Immunix::Config;
use Locale::gettext;
use POSIX;
use RPC::XML;
use RPC::XML::Client;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(
get_repo_client
did_result_succeed
get_result_error
user_login
user_register
upload_profile
fetch_profile_by_id
fetch_profiles_by_user
fetch_profiles_by_name
fetch_profiles_by_name_and_user
fetch_newer_profile
get_repo_config
set_repo_config
);
our %clients;
our %uid2login;
our $DEBUGGING = 0;
our $repo_cfg;
our $aa_cfg;
sub get_repo_client ($) {
my $repo_url = shift;
unless ( $clients{$repo_url} ) {
$clients{$repo_url} = new RPC::XML::Client $repo_url;
}
return $clients{$repo_url};
}
sub did_result_succeed {
my $result = shift;
my $ref = ref $result;
return ($ref && $ref ne "RPC::XML::fault") ? 1 : 0;
}
sub get_result_error {
my $result = shift;
if (ref $result) {
if (ref $result eq "RPC::XML::fault") {
$result = $result->string;
} else {
$result = $$result;
}
}
return $result;
}
sub user_login ($$$) {
my ($repo_url,$user,$pass) = @_;
my ($status,$detail);
my $repo_client = get_repo_client( $repo_url );
if ( $repo_client ) {
my $res = $repo_client->send_request('LoginConfirm', $user, $pass);
if (did_result_succeed($res)) {
$status = 1;
$detail = "";
} else {
$status = 0;
$detail = get_result_error($res);
}
}
return $status,$detail;
}
sub user_register ($$$$) {
my ($repo_url,$user,$pass,$email) = @_;
my $repo_client = get_repo_client( $repo_url );
my ($status,$detail);
if ( $repo_client ) {
my $res = $repo_client->send_request('Signup', $user, $pass, $email);
if (did_result_succeed($res)) {
$status = 1;
$detail = "";
} else {
$status = 0;
$detail = get_result_error($res);
}
}
return $status,$detail;
}
sub upload_profile ($$$$$$$) {
my ($repo_url,$user,$pass,$distro,$pname,$profile,$changelog) = @_;
my ($status,$detail);
my $repo_client = get_repo_client( $repo_url );
my $res = $repo_client->send_request( 'Create', $user, $pass, $distro,
$pname, $profile, $changelog);
if (did_result_succeed($res)) {
$detail = $res->value;
$status = 1;
} else {
$detail = get_result_error($res);
$status = 0;
}
return $status,$detail;
}
sub fetch_profile_by_id ($$) {
my ($repo_url,$id) = @_;
my $repo_client = get_repo_client( $repo_url );
my $repo_profile;
my ($status,$detail);
my $res = $repo_client->send_request('Show', $id);
if (did_result_succeed($res)) {
$status = 1;
$detail = $res->value();
} else {
$status = 0;
$detail = get_result_error($res);
}
return $status, $detail;
}
sub fetch_profiles ($$$$) {
my ($repo_url,$distro,$username,$fqdn) = @_;
my $p_hash = {};
my ($status,$detail);
my $repo_client = get_repo_client( $repo_url );
my $res =
$repo_client->send_request('FindProfiles', $distro, $fqdn, $username);
if (did_result_succeed($res)) {
$status = 1;
for my $p ( @$res ) {
my $p_repo = $p->{profile}->value();
$p_repo =~ s/flags=\(complain\)// if ( $p_repo ); #strip complain flag
$p->{profile} = $p_repo;
$p->{user_id} = $p->{user_id}->value();
$p->{id} = $p->{id}->value();
$p->{name} = $p->{name}->value();
$p->{created_at} = $p->{created_at}->value();
$p->{downloaded_count} = $p->{downloaded_count}->value();
}
$detail = $res;
} else {
$status = 0;
$detail = get_result_error($res);
}
return $status,$detail;
}
sub fetch_profiles_by_user ($$$) {
my ($repo_url,$distro,$username) = @_;
my $p_hash = {};
my ($status,$detail) = fetch_profiles( $repo_url, $distro, $username, "" );
if ( $status ) {
for my $p ( @$detail ) {
my $p_repo = $p->{profile};
if ($p_repo ne "") {
$p->{username} = $username;
$p_hash->{$p->{name}} = $p;
}
}
} else {
return ($status,$detail);
}
return($status,$p_hash);
}
sub fetch_profiles_by_name_and_user ($$$$) {
my ($repo_url,$distro,$fqdbin, $username) = @_;
my $p_hash = {};
my ($status,$detail) = fetch_profiles( $repo_url, $distro, $username, $fqdbin );
if ( $status ) {
for my $p ( @$detail ) {
my $p_repo = $p->{profile}?$p->{profile}:"";
$p_hash->{$p->{name}} = $p if ($p_repo ne "");
}
} else {
return ($status,$detail);
}
return($status,$p_hash);
}
sub fetch_profiles_by_name ($$$) {
my ($repo_url,$distro,$fqdbin) = @_;
my ($status,$detail,$data);
$detail = {};
($status,$data) = fetch_profiles( $repo_url, $distro, "", $fqdbin);
if ($status) {
my @uids;
for my $p (@$data) {
push @uids, $p->{user_id};
}
my ($status_unames,$unames) = fetch_usernames_from_uids($repo_url, @uids);
if ( $status_unames ) {
for my $p (@$data) {
if ( $unames->{$p->{user_id}} ) {
$p->{username} = $unames->{$p->{user_id}};
} else {
$p->{username} = "unkown-" . $p->{user_id};
}
}
} else {
print STDOUT "ERROR UID\n";
}
for my $p (@$data) {
$p->{profile_type} = "REPOSITORY";
$detail->{$p->{username}} = $p;
}
} else {
$detail = $data;
}
return $status,$detail;
}
sub fetch_newer_profile ($$$$$) {
my ($repo_url,$distro,$user,$id,$profile) = @_;
my $repo_client = get_repo_client( $repo_url );
my $p;
my ($status,$detail);
if ($repo_client) {
my $res =
$repo_client->send_request('FindProfiles', $distro, $profile, $user);
if (did_result_succeed($res)) {
my @profiles;
my @profile_list = @{$res->value};
$status = 1;
if (@profile_list) {
if ($profile_list[0]->{id} > $id) {
$p = $profile_list[0];
}
}
$detail = $p;
} else {
$status = 0;
$detail = get_result_error($res);
}
}
return $status,$detail;
}
sub fetch_usernames_from_uids ($) {
my ($repo_url,@searchuids) = @_;
my ($status,$result) = (1,{});
my @uids;
for my $uid ( @searchuids ) {
if ( $uid2login{$uid} ) {
$result->{$uid} = $uid2login{$uid};
} else {
push @uids, $uid;
}
}
if (@uids) {
my $repo_client = get_repo_client( $repo_url );
#RPC::XML will serialize the array into XML with the is_utf8 flag set
#which causes, HTTP:Message to fail. Looping on the array elements
#stops this from happening, and since these are all numbers it
#will not cause problems.
for my $foo (@uids) {
Encode::_utf8_off($foo);
}
my $res = $repo_client->send_request('LoginNamesFromUserIds', [@uids]);
if (did_result_succeed($res)) {
my @usernames = @{ $res->value };
for my $uid (@uids) {
my $username = shift @usernames;
$uid2login{$uid} = $username;
$result->{$uid} = $uid2login{$uid};
}
} else {
$status = 0;
$result = get_result_error($res);
}
}
return $status,$result;
}
sub get_repo_config {
unless ( $repo_cfg ) {
$repo_cfg = Immunix::Config::read_config("repository.conf");
}
unless ( $aa_cfg ) {
$aa_cfg = Immunix::Config::read_config("logprof.conf");
}
return {
"url" => $aa_cfg->{repository}{url},
"distro" => $aa_cfg->{repository}{distro},
"enabled" => $repo_cfg->{repository}{enabled},
"upload" => $repo_cfg->{repository}{upload},
"user" => $repo_cfg->{repository}{user},
"password" => $repo_cfg->{repository}{pass},
"email" => $repo_cfg->{repository}{email}
};
}
sub set_repo_config ($) {
my $cfg = shift;
my ($url,$distro,$enabled,$upload,$user,$pass);
unless ( $repo_cfg ) {
$repo_cfg = Immunix::Config::read_config("repository.conf");
}
unless ( $aa_cfg ) {
$aa_cfg = Immunix::Config::read_config("logprof.conf");
}
$repo_cfg->{repository}{enabled} = $cfg->{enabled} if ( $cfg->{enabled} );
$repo_cfg->{repository}{upload} = $cfg->{upload} if ( $cfg->{upload} );
$repo_cfg->{repository}{user} = $cfg->{user} if ( $cfg->{user} );
$repo_cfg->{repository}{pass} = $cfg->{password}if ( $cfg->{password} );
$repo_cfg->{repository}{email} = $cfg->{email} if ( $cfg->{email} );
$aa_cfg->{repository}{distro} = $cfg->{distro} if ( $cfg->{distro} );
$aa_cfg->{repository}{url} = $cfg->{url} if ( $cfg->{url} );
write_config("repository.conf", $repo_cfg);
write_config("logprof.conf", $aa_cfg);
}
1;

View File

@@ -1,221 +0,0 @@
# ------------------------------------------------------------------
#
# Copyright (C) 2005-2006 Novell/SUSE
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License published by the Free Software Foundation.
#
# ------------------------------------------------------------------
package Immunix::Severity;
use strict;
use Data::Dumper;
my ($debug) = 0;
sub debug {
print @_ if $debug;
}
sub new {
my $self = {};
$self->{DATABASENAME} = undef;
$self->{CAPABILITIES} = {};
$self->{FILES} = {};
$self->{REGEXPS} = {};
$self->{DEFAULT_RANK} = 10;
bless($self);
shift;
$self->init(@_) if @_;
return $self;
}
sub init ($;$) {
my ($self, $resource, $read, $write, $execute, $severity);
$self = shift;
$self->{DATABASENAME} = shift;
$self->{DEFAULT_RANK} = shift if defined $_[0];
open(DATABASE, $self->{DATABASENAME})
or die "Could not open severity db $self->{DATABASENAME}: $!\n";
while (<DATABASE>) {
chomp();
next if m/^\s*#/;
next if m/^\s*$/;
# leading whitespace is fine; maybe it shouldn't be?
if (/^\s*\/(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s*$/) {
my ($path, $read, $write, $execute) = ($1, $2, $3, $4);
if (index($path, "*") == -1) {
$self->{FILES}{$path} = {
r => $read,
w => $write,
x => $execute
};
} else {
my $ptr = $self->{REGEXPS};
my @pieces = split(/\//, $path);
while (my $piece = shift @pieces) {
if (index($piece, "*") != -1) {
my $path = join("/", $piece, @pieces);
my $regexp = convert_regexp($path);
$ptr->{$regexp}{SD_RANK} = {
r => $read,
w => $write,
x => $execute
};
last;
} else {
$ptr->{$piece} = {} unless exists $ptr->{$piece};
$ptr = $ptr->{$piece};
}
}
}
} elsif (m|^\s*CAP|) {
($resource, $severity) = split;
$self->{CAPABILITIES}{$resource} = $severity;
} else {
print "unexpected database line: $_\n";
}
}
close(DATABASE);
debug Dumper($self);
return $self;
}
#rank:
# handle capability
# handle file
#
# handle capability
# if the name is in the database, return it
# otherwise, send a diagnostic message to stderr and return the default
#
# handle file
# initialize the current return value to 0
# loop over each entry in the database;
# find the max() value for each mode that matches and set a 'found' flag
# if the found flag has not been set, return the default;
# otherwise, return the maximum from the database
sub handle_capability ($) {
my ($self, $resource) = @_;
my $ret = $self->{CAPABILITIES}{$resource};
if (!defined($ret)) {
return "unexpected capability rank input: $resource\n";
}
return $ret;
}
sub check_subtree {
my ($tree, $mode, $sev, $first, @rest) = @_;
# reassemble the remaining path from this directory level
my $path = join("/", $first, @rest);
# first check if we have a literal directory match to descend into
if ($tree->{$first}) {
$sev = check_subtree($tree->{$first}, $mode, $sev, @rest);
}
# if we didn't get a severity already, check for matching globs
unless ($sev) {
# check each glob at this directory level
for my $chunk (grep { index($_, "*") != -1 } keys %{$tree}) {
# does it match the rest of our path?
if ($path =~ /^$chunk$/) {
# if we've got a ranking, check if it's higher than
# current one, if any
if ($tree->{$chunk}->{SD_RANK}) {
for my $m (split(//, $mode)) {
if ((!defined $sev)
|| $tree->{$chunk}->{SD_RANK}->{$m} > $sev)
{
$sev = $tree->{$chunk}->{SD_RANK}->{$m};
}
}
}
}
}
}
return $sev;
}
sub handle_file ($$) {
my ($self, $resource, $mode) = @_;
# strip off the initial / from the path we're checking
$resource = substr($resource, 1);
# break the path into directory-level chunks
my @pieces = split(/\//, $resource);
my $sev;
# if there's a exact match for this path in the db, use that instead of
# checking the globs
if ($self->{FILES}{$resource}) {
# check each piece of the passed mode against the db entry
for my $m (split(//, $mode)) {
if ((!defined $sev) || $self->{FILES}{$resource}{$m} > $sev) {
$sev = $self->{FILES}{$resource}{$m};
}
}
} else {
# descend into the regexp tree looking for matches
$sev = check_subtree($self->{REGEXPS}, $mode, $sev, @pieces);
}
return (defined $sev) ? $sev : $self->{DEFAULT_RANK};
}
sub rank ($;$) {
my ($self, $resource, $mode) = @_;
if (substr($resource, 0, 1) eq "/") {
return $self->handle_file($resource, $mode);
} elsif (substr($resource, 0, 3) eq "CAP") {
return $self->handle_capability($resource);
} else {
return "unexpected rank input: $resource\n";
}
}
sub convert_regexp ($) {
my ($input) = shift;
# we need to convert subdomain regexps to perl regexps
my $regexp = $input;
# escape + . [ and ] characters
$regexp =~ s/(\+|\.|\[|\])/\\$1/g;
# convert ** globs to match anything
$regexp =~ s/\*\*/.SDPROF_INTERNAL_GLOB/g;
# convert * globs to match anything at current path level
$regexp =~ s/\*/[^\/]SDPROF_INTERNAL_GLOB/g;
# convert {foo,baz} to (foo|baz)
$regexp =~ y/\{\}\,/\(\)\|/ if $regexp =~ /\{.*\,.*\}/;
# twiddle the escaped * chars back
$regexp =~ s/SDPROF_INTERNAL_GLOB/\*/g;
return $regexp;
}
1; # so the require or use succeeds

View File

@@ -1,62 +0,0 @@
# ----------------------------------------------------------------------
# Copyright (c) 1999, 2004-2009 NOVELL (All rights reserved)
# Copyright (c) 2010-2011, 2014 Canonical Ltd.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
# ----------------------------------------------------------------------
# NOTE: this Makefile has been adjusted from the original to assist in
# the installation of the Immunix perl modules, if they're still needed
# by users. Because the utilities conflict with their replacments, make
# install *will* *not* install them.
NAME = apparmor-utils
all:
COMMONDIR=../../common/
include $(COMMONDIR)/Make.rules
MODDIR = Immunix
PERLTOOLS = aa-genprof aa-logprof aa-autodep aa-audit aa-complain aa-enforce \
aa-unconfined aa-disable
MODULES = ${MODDIR}/AppArmor.pm ${MODDIR}/Repository.pm \
${MODDIR}/Config.pm ${MODDIR}/Severity.pm
all:
# need some better way of determining this
DESTDIR=/
BINDIR=${DESTDIR}/usr/sbin
CONFDIR=${DESTDIR}/etc/apparmor
VENDOR_PERL=$(shell perl -e 'use Config; print $$Config{"vendorlib"};')
PERLDIR=${DESTDIR}${VENDOR_PERL}/${MODDIR}
.PHONY: install
install:
install -d ${PERLDIR}
install -m 644 ${MODULES} ${PERLDIR}
.PHONY: clean
ifndef VERBOSE
.SILENT: clean
endif
clean: pod_clean
rm -f core core.* *.o *.s *.a *~
rm -rf staging/ build/
.PHONY: check
.SILENT: check
check:
for i in ${MODULES} ${PERLTOOLS} ; do \
perl -c $$i || exit 1; \
done

View File

@@ -1,132 +0,0 @@
#!/usr/bin/perl
# ----------------------------------------------------------------------
# Copyright (c) 2005 Novell, Inc. All Rights Reserved.
# Copyright (c) 2011 Canonical, Ltd.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com.
# ----------------------------------------------------------------------
use strict;
use FindBin;
use Getopt::Long;
use Immunix::AppArmor;
use Data::Dumper;
use Locale::gettext;
use POSIX;
# initialize the local poo
setlocale(LC_MESSAGES, "");
textdomain("apparmor-utils");
$UI_Mode = "text";
# options variables
my $help = '';
GetOptions(
'dir|d=s' => \$profiledir,
'help|h' => \$help,
);
# tell 'em how to use it...
&usage && exit if $help;
# let's convert it to full path...
$profiledir = get_full_path($profiledir);
unless (-d $profiledir) {
UI_Important("Can't find AppArmor profiles in $profiledir.");
exit 1;
}
# what are we profiling?
my @profiling = @ARGV;
unless (@profiling) {
@profiling = (UI_GetString("Please enter the program to switch to audit mode: ", ""));
}
for my $profiling (@profiling) {
next unless $profiling;
my $fqdbin;
if (-e $profiling) {
$fqdbin = get_full_path($profiling);
chomp($fqdbin);
} else {
if ($profiling !~ /\//) {
opendir(DIR,$profiledir);
my @tmp_fqdbin = grep ( /$profiling/, readdir(DIR));
closedir(DIR);
if (scalar @tmp_fqdbin eq 1) {
$fqdbin = "$profiledir/$tmp_fqdbin[0]";
} else {
my $which = which($profiling);
if ($which) {
$fqdbin = get_full_path($which);
}
}
}
}
if (-e $fqdbin) {
my $filename;
if ($fqdbin =~ /^$profiledir\//) {
$filename = $fqdbin;
} else {
$filename = getprofilefilename($fqdbin);
}
# argh, skip directories
next unless -f $filename;
# skip rpm backup files
next if isSkippableFile($filename);
printf(gettext('Setting %s to audit mode.'), $fqdbin);
print "\n";
setprofileflags($filename, "audit");
my $cmd_info = qx(cat $filename | $parser -I$profiledir -r 2>&1 1>/dev/null);
if ($? != 0) {
UI_Info($cmd_info);
exit $?;
}
# if check_for_subdomain();
} else {
if ($profiling =~ /^[^\/]+$/) {
UI_Info(sprintf(gettext('Can\'t find %s in the system path list. If the name of the application is correct, please run \'which %s\' as a user with the correct PATH environment set up in order to find the fully-qualified path.'), $profiling, $profiling));
exit 1;
} else {
UI_Info(sprintf(gettext('%s does not exist, please double-check the path.'), $profiling));
exit 1;
}
}
}
exit 0;
sub usage {
UI_Info(sprintf(gettext("usage: \%s [ -d /path/to/profiles ] [ program to switch to audit mode ]"), $0));
exit 0;
}

View File

@@ -1,122 +0,0 @@
#!/usr/bin/perl
# ----------------------------------------------------------------------
# Copyright (c) 2005 Novell, Inc. All Rights Reserved.
# Copyright (c) 2011 Canonical, Ltd.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com.
# ----------------------------------------------------------------------
use strict;
use FindBin;
use Getopt::Long;
use Immunix::AppArmor;
use Data::Dumper;
use Locale::gettext;
use POSIX;
# force $PATH to be sane
$ENV{PATH} = "/bin:/sbin:/usr/bin:/usr/sbin";
# initialize the local poo
setlocale(LC_MESSAGES, "");
textdomain("apparmor-utils");
$UI_Mode = "text";
# options variables
my $help = '';
my $force = undef;
GetOptions(
'force' => \$force,
'dir|d=s' => \$profiledir,
'help|h' => \$help,
);
# tell 'em how to use it...
&usage && exit if $help;
my $sd_mountpoint = check_for_subdomain();
# let's convert it to full path...
$profiledir = get_full_path($profiledir);
unless (-d $profiledir) {
UI_Important(sprintf(gettext('Can\'t find AppArmor profiles in %s.'), $profiledir));
exit 1;
}
# what are we profiling?
my @profiling = @ARGV;
unless (@profiling) {
@profiling = (UI_GetString(gettext("Please enter the program to create a profile for: "), ""));
}
for my $profiling (@profiling) {
next unless $profiling;
my $fqdbin;
if (-e $profiling) {
$fqdbin = get_full_path($profiling);
chomp($fqdbin);
} else {
if ($profiling !~ /\//) {
my $which = which($profiling);
if ($which) {
$fqdbin = get_full_path($which);
}
}
}
# make sure that the app they're requesting to profile is not marked as
# not allowed to have it's own profile
if ($qualifiers{$fqdbin}) {
unless ($qualifiers{$fqdbin} =~ /p/) {
UI_Info(sprintf(gettext('%s is currently marked as a program that should not have it\'s own profile. Usually, programs are marked this way if creating a profile for them is likely to break the rest of the system. If you know what you\'re doing and are certain you want to create a profile for this program, edit the corresponding entry in the [qualifiers] section in /etc/apparmor/logprof.conf.'), $fqdbin));
exit 1;
}
}
if (-e $fqdbin) {
if (-e getprofilefilename($fqdbin) && !$force) {
UI_Info(sprintf(gettext('Profile for %s already exists - skipping.'), $fqdbin));
} else {
autodep($fqdbin);
reload($fqdbin) if $sd_mountpoint;
}
} else {
if ($profiling =~ /^[^\/]+$/) {
UI_Info(sprintf(gettext('Can\'t find %s in the system path list. If the name of the application is correct, please run \'which %s\' as a user with the correct PATH environment set up in order to find the fully-qualified path.'), $profiling, $profiling));
exit 1;
} else {
UI_Info(sprintf(gettext('%s does not exist, please double-check the path.'), $profiling));
exit 1;
}
}
}
exit 0;
sub usage {
UI_Info("usage: $0 [ --force ] [ -d /path/to/profiles ]");
exit 0;
}

View File

@@ -1,131 +0,0 @@
#!/usr/bin/perl
# ----------------------------------------------------------------------
# Copyright (c) 2005 Novell, Inc. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com.
# ----------------------------------------------------------------------
use strict;
use FindBin;
use Getopt::Long;
use Immunix::AppArmor;
use Data::Dumper;
use Locale::gettext;
use POSIX;
# initialize the local poo
setlocale(LC_MESSAGES, "");
textdomain("apparmor-utils");
$UI_Mode = "text";
# options variables
my $help = '';
GetOptions(
'dir|d=s' => \$profiledir,
'help|h' => \$help,
);
# tell 'em how to use it...
&usage && exit if $help;
# let's convert it to full path...
$profiledir = get_full_path($profiledir);
unless (-d $profiledir) {
UI_Important("Can't find AppArmor profiles in $profiledir.");
exit 1;
}
# what are we profiling?
my @profiling = @ARGV;
unless (@profiling) {
@profiling = (UI_GetString(gettext("Please enter the program to switch to complain mode: "), ""));
}
for my $profiling (@profiling) {
next unless $profiling;
my $fqdbin;
if (-e $profiling) {
$fqdbin = get_full_path($profiling);
chomp($fqdbin);
} else {
if ($profiling !~ /\//) {
opendir(DIR,$profiledir);
my @tmp_fqdbin = grep ( /$profiling/, readdir(DIR));
closedir(DIR);
if (scalar @tmp_fqdbin eq 1) {
$fqdbin = "$profiledir/$tmp_fqdbin[0]";
} else {
my $which = which($profiling);
if ($which) {
$fqdbin = get_full_path($which);
}
}
}
}
if (-e $fqdbin) {
my $filename;
if ($fqdbin =~ /^$profiledir\//) {
$filename = $fqdbin;
} else {
$filename = getprofilefilename($fqdbin);
}
# argh, skip directories
next unless -f $filename;
# skip rpm backup files
next if isSkippableFile($filename);
printf(gettext('Setting %s to complain mode.'), $fqdbin);
print "\n";
setprofileflags($filename, "complain");
my $cmd_info = qx(cat $filename | $parser -I$profiledir -r 2>&1 1>/dev/null);
if ($? != 0) {
UI_Info($cmd_info);
exit $?;
}
# if check_for_subdomain();
} else {
if ($profiling =~ /^[^\/]+$/) {
UI_Info(sprintf(gettext('Can\'t find %s in the system path list. If the name of the application is correct, please run \'which %s\' as a user with the correct PATH environment set up in order to find the fully-qualified path.'), $profiling, $profiling));
exit 1;
} else {
UI_Info(sprintf(gettext('%s does not exist, please double-check the path.'), $profiling));
exit 1;
}
}
}
exit 0;
sub usage {
UI_Info(sprintf(gettext("usage: \%s [ -d /path/to/profiles ] [ program to switch to complain mode ]"), $0));
exit 0;
}

View File

@@ -1,152 +0,0 @@
#!/usr/bin/perl
# ----------------------------------------------------------------------
# Copyright (c) 2005-2010 Novell, Inc. All Rights Reserved.
# Copyright (c) 2011 Canonical, Inc. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Canonical, Inc.
#
# To contact Canonical about this file by physical or electronic mail,
# you may find current contact information at www.canonical.com.
# ----------------------------------------------------------------------
use strict;
use FindBin;
use Getopt::Long;
use Immunix::AppArmor;
use Data::Dumper;
use Locale::gettext;
use POSIX;
use File::Basename;
# initialize the local poo
setlocale(LC_MESSAGES, "");
textdomain("apparmor-utils");
$UI_Mode = "text";
# options variables
my $help = '';
GetOptions(
'dir|d=s' => \$profiledir,
'help|h' => \$help,
);
# tell 'em how to use it...
&usage && exit if $help;
# let's convert it to full path...
$profiledir = get_full_path($profiledir);
unless (-d $profiledir) {
UI_Important("Can't find AppArmor profiles in $profiledir.");
exit 1;
}
my $disabledir = "$profiledir/disable";
unless (-d $disabledir) {
UI_Important("Can't find AppArmor disable directory '$disabledir'.");
exit 1;
}
# what are we profiling?
my @profiling = @ARGV;
unless (@profiling) {
@profiling = (UI_GetString(gettext("Please enter the program whose profile should be disabled: "), ""));
}
for my $profiling (@profiling) {
next unless $profiling;
my $fqdbin;
if (-e $profiling) {
$fqdbin = get_full_path($profiling);
chomp($fqdbin);
} else {
if ($profiling !~ /\//) {
opendir(DIR,$profiledir);
my @tmp_fqdbin = grep ( /$profiling/, readdir(DIR));
closedir(DIR);
if (scalar @tmp_fqdbin eq 1) {
$fqdbin = "$profiledir/$tmp_fqdbin[0]";
} else {
my $which = which($profiling);
if ($which) {
$fqdbin = get_full_path($which);
}
}
}
}
if (-e $fqdbin) {
my $filename;
if ($fqdbin =~ /^$profiledir\//) {
$filename = $fqdbin;
} else {
$filename = getprofilefilename($fqdbin);
}
# argh, skip directories
next unless -f $filename;
# skip package manager backup files
next if isSkippableFile($filename);
my ($bname, $dname, $suffix) = File::Basename::fileparse($filename);
if ($bname eq "") {
UI_Info(sprintf(gettext('Could not find basename for %s.'), $filename));
exit 1;
}
printf(gettext('Disabling %s.'), $fqdbin);
print "\n";
my $link = "$disabledir/$bname";
if (! -e $link) {
if (symlink($filename, $link) != 1) {
UI_Info(sprintf(gettext('Could not create %s symlink.'), $link));
exit 1;
}
}
my $cmd_info = qx(cat $filename | $parser -I$profiledir -R 2>&1 1>/dev/null);
if ($? != 0) {
UI_Info($cmd_info);
exit $?;
}
# if check_for_subdomain();
} else {
if ($profiling =~ /^[^\/]+$/) {
UI_Info(sprintf(gettext('Can\'t find %s in the system path list. If the name of the application is correct, please run \'which %s\' as a user with the correct PATH environment set up in order to find the fully-qualified path.'), $profiling, $profiling));
exit 1;
} else {
UI_Info(sprintf(gettext('%s does not exist, please double-check the path.'), $profiling));
exit 1;
}
}
}
exit 0;
sub usage {
UI_Info(sprintf(gettext("usage: \%s [ -d /path/to/profiles ] [ program to have profile disabled ]"), $0));
exit 0;
}

View File

@@ -1,142 +0,0 @@
#!/usr/bin/perl
# ----------------------------------------------------------------------
# Copyright (c) 2005 Novell, Inc. All Rights Reserved.
# Copyright (c) 2011 Canonical, Ltd.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com.
# ----------------------------------------------------------------------
use strict;
use FindBin;
use Getopt::Long;
use Immunix::AppArmor;
use Data::Dumper;
use Locale::gettext;
use POSIX;
# initialize the local poo
setlocale(LC_MESSAGES, "");
textdomain("apparmor-utils");
$UI_Mode = "text";
# options variables
my $help = '';
GetOptions(
'dir|d=s' => \$profiledir,
'help|h' => \$help,
);
# tell 'em how to use it...
&usage && exit if $help;
# let's convert it to full path...
$profiledir = get_full_path($profiledir);
unless (-d $profiledir) {
UI_Important("Can't find AppArmor profiles in $profiledir.");
exit 1;
}
# what are we profiling?
my @profiling = @ARGV;
unless (@profiling) {
@profiling = (UI_GetString(gettext("Please enter the program to switch to enforce mode: "), ""));
}
for my $profiling (@profiling) {
next unless $profiling;
my $fqdbin;
if (-e $profiling) {
$fqdbin = get_full_path($profiling);
chomp($fqdbin);
} else {
if ($profiling !~ /\//) {
opendir(DIR,$profiledir);
my @tmp_fqdbin = grep ( /$profiling/, readdir(DIR));
closedir(DIR);
if (scalar @tmp_fqdbin eq 1) {
$fqdbin = "$profiledir/$tmp_fqdbin[0]";
} else {
my $which = which($profiling);
if ($which) {
$fqdbin = get_full_path($which);
}
}
}
}
if (-e $fqdbin) {
my $filename;
if ($fqdbin =~ /^$profiledir\//) {
$filename = $fqdbin;
} else {
$filename = getprofilefilename($fqdbin);
}
# argh, skip directories
next unless -f $filename;
# skip rpm backup files
next if isSkippableFile($filename);
printf(gettext('Setting %s to enforce mode.'), $fqdbin);
print "\n";
setprofileflags($filename, "");
# remove symlink in $profiledir/force-complain as well
my $complainlink = $filename;
$complainlink =~ s/^$profiledir/$profiledir\/force-complain/;
-e $complainlink and unlink($complainlink);
# remove symlink in $profiledir/disable as well
my $disablelink = $filename;
$disablelink =~ s/^$profiledir/$profiledir\/disable/;
-e $disablelink and unlink($disablelink);
my $cmd_info = qx(cat $filename | $parser -I$profiledir -r 2>&1 1>/dev/null);
if ($? != 0) {
UI_Info($cmd_info);
exit $?;
}
# if check_for_subdomain();
} else {
if ($profiling =~ /^[^\/]+$/) {
UI_Info(sprintf(gettext('Can\'t find %s in the system path list. If the name of the application is correct, please run \'which %s\' as a user with the correct PATH environment set up in order to find the fully-qualified path.'), $profiling, $profiling));
exit 1;
} else {
UI_Info(sprintf(gettext('%s does not exist, please double-check the path.'), $profiling));
exit 1;
}
}
}
exit 0;
sub usage {
UI_Info(sprintf(gettext("usage: \%s [ -d /path/to/profiles ] [ program to switch to enforce mode ]"), $0));
exit 0;
}

View File

@@ -1,940 +0,0 @@
#!/usr/bin/perl -w
# ----------------------------------------------------------------------
# Copyright (c) 2005 Novell, Inc. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com.
# ----------------------------------------------------------------------
use strict;
use Data::Dumper;
use DBI;
use Fcntl;
use File::Temp qw(tempfile);
use Getopt::Long;
use POSIX 'setsid';
use Time::Local;
use File::Tail;
use Immunix::Severity;
require LibAppArmor;
##########################################################################
# locations
my $productname = "apparmor";
my $cfgdir = "/etc/$productname";
my $dbdir = "/var/log/$productname";
my $cfgfile = "$cfgdir/notify.cfg";
my $errlog = "$dbdir/event-dispatch.log";
my $logfile = "/var/log/audit/audit.log";
my $syslogfile = "/var/log/messages";
##########################################################################
# options variables
my $pidfile = '';
GetOptions('pidfile|p=s' => \$pidfile);
my $DEBUG = 0;
my $config;
my $verbose = { last_notify => 0 };
my $summary = { last_notify => 0 };
my $terse = { last_notify => 0 };
# we don't want to call str2time on every line and also batch up event dbs
# a month at a time, so we need to keep track of a few extra things
my $timestamp = 0;
my $lasttime = "";
my $counter = 0;
my $thismonth = 0;
my $nextmonth = 0;
# pop open a connection to the severity database
my $sevdb = new Immunix::Severity("$cfgdir/severity.db", -1);
my $REdate = '\w{3}\s+\d+\s+\d{2}:\d{2}:\d{2}';
my $last_inserted_time;
my $last_inserted_counter;
##########################################################################
# commit how often?
my $timeout = 5;
# keep track of when we commited last
my $last_flush_time = 0;
# keep track of some statistics
my $max = 0;
my $inserts = 0;
my $total = 0;
my @commit_buffer;
my @debug_buffer;
my @verbose_buffer;
my @summary_buffer;
my @terse_buffer;
my $date_module = "None";
my %templates = (
"path" => "(time,counter,type,op,profile,sdmode,mode_req,mode_deny,resource,prog,pid,severity) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)",
"link" => "(time,counter,type,op,profile,sdmode,resource,target,prog,pid,severity) VALUES(?,?,?,?,?,?,?,?,?,?,?)",
"chattr" => "(time,counter,type,op,profile,sdmode,resource,mode_req,mode_deny,prog,pid,severity) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)",
"capability" => "(time,counter,type,op,profile,sdmode,resource,prog,pid,severity) VALUES(?,?,?,?,?,?,?,?,?,?)",
"capable" => "(time,counter,type,op,prog,pid,profile) VALUES(?,?,?,?,?,?,?)",
"unknown_hat" => "(time,counter,type,op,profile,sdmode,resource,pid) VALUES(?,?,?,?,?,?,?,?)",
"fork" => "(time,counter,type,op,profile,sdmode,pid,resource) VALUES(?,?,?,?,?,?,?,?)",
"changing_profile" => "(time,counter,type,op,profile,sdmode,pid) VALUES(?,?,?,?,?,?,?)",
"profile_replacement" => "(time,counter,type,op,profile,sdmode,prog,pid,severity) VALUES(?,?,?,?,?,?,?,?,?)",
"net" => "(time,counter,type,op,net_family,net_socktype,net_proto,pid,profile) VALUES(?,?,?,?,?,?,?,?,?)",
"removed" => "(time,counter,type,op,severity) VALUES(?,?,?,?,?)",
"initialized" => "(time,counter,type,op,resource,severity) VALUES(?,?,?,?,?,?)",
"ctrl_var" => "(time,counter,type,op,resource,mode_req,mode_deny,severity) VALUES(?,?,?,?,?,?,?,?)",
"profile_load" => "(time,counter,type,op,resource,prog,pid) VALUES(?,?,?,?,?,?,?)",
);
##########################################################################
# generic functions
sub errlog ($) {
my $mesg = shift;
my $localtime = localtime(time);
print ERRLOG "[$localtime] $mesg\n";
}
sub readconfig () {
my $cfg = {};
# record when we read the config file
$cfg->{load_time} = time;
if (open(CFG, $cfgfile)) {
# yank in the values we need
while (<CFG>) {
$cfg->{$1} = $2 if /^(\S+)\s+(.+)\s*$/;
}
close(CFG);
}
return $cfg;
}
sub daemonize {
chdir '/' or die "Can't chdir to /: $!";
open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!";
defined(my $pid = fork) or die "Can't fork: $!";
exit if $pid;
setsid or die "Can't start a new session: $!";
open STDERR, '>&STDOUT' or die "Can't dup stdout: $!";
}
sub parsedate ($) {
my $time = shift;
my $timestamp = 0;
if ($date_module eq 'TimeDate') {
$timestamp = Date::Parse::str2time($time);
} elsif ($date_module eq 'DateManip') {
$timestamp = Date::Manip::UnixDate(Date::Manip::ParseDateString($time), '%s');
} else {
errlog "No date module found, exiing";
kill HUP => -$$;
}
return $timestamp;
}
##########################################################################
# database handling functions
sub connect_database ($) {
my $dbdir = shift;
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbdir/events.db", "", "", {RaiseError=>1});
# we'll do the commits ourselves so performance doesn't suck
$dbh->{AutoCommit} = 0;
# bump up our cache size a little
$dbh->do("PRAGMA cache_size = 20000;");
# figure out if the tables already exist or not
my %existing_tables;
my $sth = $dbh->prepare("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;");
$sth->execute;
while (my @row = $sth->fetchrow_array) {
$existing_tables{ $row[0] } = 1;
}
$sth->finish;
# create the info table and fill in the appropriate values for this db
unless ($existing_tables{info}) {
my $host = `hostname -f`;
chomp $host;
$dbh->do("CREATE TABLE info (name,value)");
$sth = $dbh->prepare("INSERT INTO info(name,value) VALUES(?,?)");
$sth->execute("version", "0.2");
$sth->execute("host", "$host");
}
# create the events table
unless ($existing_tables{events}) {
$dbh->do(
"CREATE TABLE events (
id INTEGER PRIMARY KEY AUTOINCREMENT,
time INTEGER NOT NULL,
counter INTEGER NOT NULL,
op,
pid,
sdmode,
type,
mode_deny,
mode_req,
resource,
target,
profile,
prog,
name_alt,
attr,
parent,
active_hat,
net_family,
net_proto,
net_socktype,
severity INTEGER
)"
);
# set up the indexes we want
#my @indexes = qw(time type sdmode mode resource profile prog severity);
my @indexes = qw(time type op sdmode mode_req mode_deny resource profile prog severity);
for my $index (@indexes) {
$dbh->do("CREATE INDEX " . $index . "_idx ON events($index)");
}
}
# make sure our changes actually get saved
$dbh->commit || errlog "Error commiting changes: $!";
# mark the db as up to date as of now
$last_flush_time = time;
return $dbh;
}
##########################################################################
sub verbose_notify_handler {
my ($email, $file, $last, $level, $unknown) = @_;
$last = localtime($last);
my $now = time;
my $host = `hostname -f`;
chomp $host;
my $subj = "Verbose Security Report for $host.";
my $mesg = "The following security events occured since $last:\n\n";
my @events;
if (open(V, $file)) {
while (<V>) {
chomp;
if (/^(\d+) (\d+) (.+)$/) {
my ($timestamp, $counter, $logmsg) = ($1, $2, $3);
push @events, [ $timestamp, $counter ];
$mesg .= "$logmsg\n";
}
}
close(V);
if (@events) {
if ($DEBUG) {
my $count = scalar @events;
errlog "[$count events] sending verbose notification to $email.";
}
# actually send out the notification...
open(MAIL, "| sendmail -F 'AppArmor Security Notification' $email");
print MAIL "To: $email\n";
print MAIL "Subject: $subj\n\n";
print MAIL "$mesg\n";
print MAIL ".\n";
close(MAIL);
}
# delete the verbose notification logfile once we've processed it
unlink($file);
}
}
sub summary_notify_handler {
my ($email, $file, $last, $level, $unknown) = @_;
$last = localtime($last);
my $now = time;
my $host = `hostname -f`;
chomp $host;
my $subj = "Summary Security Report for $host.";
my $mesg = "The following security events occured since $last:\n\n";
my @events;
if (open(V, $file)) {
while (<V>) {
chomp;
if (/^(\d+) (\d+) (.+)$/) {
my ($timestamp, $counter, $logmsg) = ($1, $2, $3);
push @events, [ $timestamp, $counter ];
$mesg .= "$logmsg\n";
}
}
close(V);
if (@events) {
if ($DEBUG) {
my $count = scalar @events;
errlog "[$count events] sending summary notification to $email.";
}
# actually send out the notification...
open(MAIL, "| sendmail -F 'AppArmor Security Notification' $email");
print MAIL "To: $email\n";
print MAIL "Subject: $subj\n\n";
print MAIL "$mesg\n";
print MAIL ".\n";
close(MAIL);
}
# delete the verbose notification logfile once we've processed it
unlink($file);
}
}
sub terse_notify_handler {
my ($email, $file, $last, $level, $unknown) = @_;
$last = localtime($last);
my $now = time;
my $host = `hostname -f`;
chomp $host;
my @events;
my $count = 0;
if (open(V, $file)) {
while (<V>) {
chomp;
if (/^(\d+) (\d+) (.+)$/) {
my ($timestamp, $counter, $logmsg) = ($1, $2, $3);
push @events, [ $timestamp, $counter ];
$count++;
}
}
close(V);
if ($count) {
if ($DEBUG) {
errlog "[$count events] sending terse notification to $email.";
}
my $subj = "Security Report for $host.";
my $mesg = "$host has had $count security events since $last.";
# actually send out the notification...
open(MAIL, "| sendmail -F 'AppArmor Security Notification' $email");
print MAIL "To: $email\n";
print MAIL "Subject: $subj\n\n";
print MAIL "$mesg\n";
print MAIL ".\n";
close(MAIL);
}
# delete the terse notification logfile once we've processed it
unlink($file);
}
}
sub fork_into_background {
my ($name, $func, @args) = @_;
my $pid = fork;
if (not defined $pid) {
# something bad happened, just log it...
errlog "couldn't fork for \"$name\": $!"
} elsif ($pid == 0) {
# we're in the child process now...
# set our process name
$0 = $name;
# call our subroutine
my $ret = &$func(@args);
exit($ret);
}
return $pid;
}
##########################################################################
# Parse event record into key-value pairs
sub parseEvent($) {
my %ev = ();
my $msg = shift;
chomp($msg);
my $event = LibAppArmor::parse_record($msg);
# resource is an alternate term for 'name1' below
# mode is an alternate term for 'mode_deny' below
$ev{'time'} = LibAppArmor::aa_log_record::swig_epoch_get($event);
$ev{'op'} = LibAppArmor::aa_log_record::swig_operation_get($event);
$ev{'pid'} = LibAppArmor::aa_log_record::swig_pid_get($event);
$ev{'mode_deny'} = LibAppArmor::aa_log_record::swig_denied_mask_get($event);
$ev{'mode_req'} = LibAppArmor::aa_log_record::swig_requested_mask_get($event);
$ev{'profile'}= LibAppArmor::aa_log_record::swig_profile_get($event);
$ev{'prog'} = LibAppArmor::aa_log_record::swig_name_get($event);
$ev{'name2'} = LibAppArmor::aa_log_record::swig_name2_get($event);
$ev{'attr'} = LibAppArmor::aa_log_record::swig_attribute_get($event);
$ev{'parent'} = LibAppArmor::aa_log_record::swig_parent_get($event);
$ev{'magic_token'} = LibAppArmor::aa_log_record::swig_magic_token_get($event);
$ev{'resource'} = LibAppArmor::aa_log_record::swig_info_get($event);
$ev{'active_hat'} = LibAppArmor::aa_log_record::swig_active_hat_get($event);
$ev{'sdmode'} = LibAppArmor::aa_log_record::swig_event_get($event);
# NetDomain
if ( $ev{'op'} && $ev{'op'} =~ /socket/ ) {
next if $ev{'op'} =~ /create/;
$ev{'net_family'} = LibAppArmor::aa_log_record::swig_net_family_get($event);
$ev{'net_proto'} = LibAppArmor::aa_log_record::swig_net_protocol_get($event);
$ev{'net_socktype'} = LibAppArmor::aa_log_record::swig_net_sock_type_get($event);
}
LibAppArmor::free_record($event);
if ( ! $ev{'time'} ) { $ev{'time'} = time; }
# remove null responses
for (keys(%ev)) {
if ( ! $ev{$_} || $ev{$_} !~ /\w+/) {delete($ev{$_}); }
#errlog "EVENT: $_ is $ev{$_}";
}
if ( $ev{'sdmode'} ) {
#0 = invalid, 1 = error, 2 = AUDIT, 3 = ALLOW/PERMIT,
#4 = DENIED/REJECTED, 5 = HINT, 6 = STATUS/config change
if ( $ev{'sdmode'} == 2 ) { $ev{'sdmode'} = "AUDITING"; }
elsif ( $ev{'sdmode'} == 3 ) { $ev{'sdmode'} = "PERMITING"; }
elsif ( $ev{'sdmode'} == 4 ) { $ev{'sdmode'} = "REJECTING"; }
else { delete($ev{'sdmode'}); }
}
return \%ev;
}
sub process_event ($$) {
my $dbh = shift;
my $logmsg = shift;
my $sth;
my $severity = "";
my @eventList = ();
my $type = undef;
my $time = undef;
return unless $logmsg && $logmsg =~ /APPARMOR/;
my $ev = parseEvent($logmsg);
# skip logprof hints
if ( ! $ev->{'op'} || $ev->{'op'} eq 'clone') { return; }
$time = time; # XXX - do we want current time or $ev->{'time'}?
if ($time ne $lasttime) {
$counter = 0;
$timestamp = $time;
$lasttime = $time;
}
$counter++;
# some statistics...
$max = $counter if $counter > $max;
# if we already have events in the db, make sure we don't try to re-enter
# duplicates if we start up again and parse the same logfile over again
if ($last_inserted_time) {
return if $timestamp < $last_inserted_time;
if ($timestamp == $last_inserted_time) {
return if $counter <= $last_inserted_counter;
}
$last_inserted_time = undef;
}
if ( $ev->{'sdmode'} && $ev->{'sdmode'} eq "REJECTING") {
$severity = $sevdb->rank($ev->{'prog'}, $ev->{'mode_req'});
if ( ! $severity ) { $severity = "-1"; }
# we only do notification for enforce mode events
if ($config->{verbose_freq}) {
if ( ($severity >= $config->{verbose_level})
|| (($severity == -1) && $config->{verbose_unknown}))
{
push @verbose_buffer, [ $timestamp, $counter, $logmsg ];
}
}
if ($config->{summary_freq}) {
if ( ($severity >= $config->{summary_level})
|| (($severity == -1) && $config->{summary_unknown}))
{
push @summary_buffer, [ $timestamp, $counter, "path",
$ev->{'prog'}, $ev->{'mode_req'}, $ev->{'resource'} ];
}
}
if ($config->{terse_freq}) {
if ( ($severity >= $config->{terse_level})
|| (($severity == -1) && $config->{terse_unknown}))
{
push @terse_buffer, [ $timestamp, $counter, "dummy" ];
}
}
}
unless ( $ev->{'op'} ) {
my $errmsg = "ERROR: No operation found: ";
for my $k (sort keys(%$ev)) {
$errmsg .= "$k is $ev->{$k}, ";
}
errlog("$errmsg\n");
return;
}
# Format the message to match the db template
if ($ev->{'op'} eq 'link' ) {
$type = 'link';
push(@eventList, [$time,$counter,$type,$ev->{'profile'},$ev->{'sdmode'},
$ev->{'resource'},$ev->{'target'},$ev->{'prog'},$ev->{'pid'},$severity]);
} elsif ($ev->{'op'} eq 'attribute') {
$type = 'chattr';
push(@eventList, []);
push(@eventList, [$time,$counter,$type,$ev->{'op'},$ev->{'profile'},$ev->{'sdmode'},
$ev->{'resource'},$ev->{'mode_req'},$ev->{'mode_deny'},$ev->{'prog'},
$ev->{'pid'},$severity]);
} elsif ($ev->{'op'} eq 'capability') {
$type = 'capability';
push(@eventList, [$time,$counter,$type,$ev->{'op'},$ev->{'profile'},$ev->{'sdmode'},
$ev->{'resource'},$ev->{'prog'},$ev->{'pid'},$severity]);
} elsif ($ev->{'op'} eq 'capable') {
$type = 'capable';
push(@eventList, [$time,$counter,$type,$ev->{'op'},$ev->{'prog'},
$ev->{'profile'},$ev->{'pid'}]);
} elsif ($ev->{'op'} =~ /ontrol variable/ ) {
$type = 'ctrl_var';
push(@eventList, [$time,$counter,$type,$ev->{'op'},$ev->{'resource'},
$ev->{'mode_req'},$ev->{'mode_deny'},$severity]);
} elsif ($ev->{'op'} eq 'unknown_hat') {
$type = 'unknown_hat';
push(@eventList, [$time,$counter,$type,$ev->{'op'},$ev->{'profile'},$ev->{'sdmode'},
$ev->{'resource'},$ev->{'pid'},$severity]);
} elsif ($ev->{'op'} eq 'fork') {
$type = 'fork';
push(@eventList, [$time,$counter,$type,$ev->{'op'},$ev->{'profile'},$ev->{'sdmode'},
$ev->{'pid'},$ev->{'resource'}]);
} elsif ($ev->{'op'} eq 'changing_profile') {
$type = 'changing_profile';
push(@eventList, [$time,$counter,$type,$ev->{'op'},$ev->{'profile'},$ev->{'sdmode'},
$ev->{'pid'}]);
} elsif ($ev->{'op'} eq 'profile_load') {
$type = 'profile_load';
push(@eventList, [$time,$counter,$type,$ev->{'op'},$ev->{'resource'},
$ev->{'prog'},$ev->{'pid'}]);
} elsif ($ev->{'op'} eq 'profile_replace') {
$type = 'profile_replacement';
push(@eventList, [$time,$counter,$type,$ev->{'op'},$ev->{'profile'},$ev->{'sdmode'},
$ev->{'prog'},$ev->{'pid'},$severity]);
} elsif ($ev->{'op'} eq 'removed') {
$type = 'removed';
push(@eventList, [$time,$counter,$type,$ev->{'op'},$severity]);
} elsif ($ev->{'op'} eq 'initialized') {
$type = 'initialized';
push(@eventList, [$time,$counter,$type,$ev->{'op'},$ev->{'resource'},$severity]);
} elsif ( $ev->{'op'} =~ /socket/) {
$type = 'net';
push(@eventList, [$time,$counter,$type,$ev->{'op'},$ev->{'net_family'},
$ev->{'net_sock_type'},$ev->{'net_proto'},$ev->{'pid'},$ev->{'profile'}]);
} else {
$type = 'path';
if ( ! $ev->{'prog'} ) { $ev->{'prog'} = "NIL"; }
push(@eventList, [$time,$counter,$type,$ev->{'op'},$ev->{'profile'},
$ev->{'sdmode'},$ev->{'mode_req'},$ev->{'mode_deny'},$ev->{'resource'},
$ev->{'prog'},$ev->{'pid'},$severity]);
}
push(@commit_buffer, @eventList);
$inserts++;
}
sub dump_events {
my ($which, @events) = @_;
if ($DEBUG) {
my $count = scalar @events;
errlog "dumping $count events to $which db.";
}
if (open(F, ">>$dbdir/$which.db")) {
for my $event (@events) {
my @event = @$event;
print F "@event\n";
}
close(F);
} else {
errlog "can't write to $dbdir/$which.db: $!";
}
}
sub check_timers ($) {
my $dbh = shift;
# what time is it right... NOW
my $now = time;
# make sure we commit periodically
if (($inserts > 10000) || ($now >= ($last_flush_time + $timeout))) {
my $last_prepare = "";
my $sth;
for my $event (sort { $a->[0] cmp $b->[0] } @commit_buffer) {
my @event = @{$event};
#my $type = shift @event;
my $type = $event[2];
eval {
if ($type ne $last_prepare) {
$sth = $dbh->prepare("INSERT INTO events $templates{$type}");
$last_prepare = $type;
}
$sth->execute(@event);
};
if ($@) {
print ERRLOG "DBI Execution failed: $DBI::errstr\n";
}
#$sth->execute(@event);
}
$dbh->commit || errlog "Error commiting changes: $!";
# need to get the time again to include how much time it takes to
# actually write all this crap to the db
$now = time;
if ($DEBUG && $inserts) {
$total += $inserts;
my $delta = $now - $last_flush_time;
my $rate = int($inserts / $delta);
errlog "$rate/s $inserts in ${delta}s total=$total max=$max";
}
$last_flush_time = $now;
@commit_buffer = ();
$max = 0;
$inserts = 0;
if (@verbose_buffer) {
# if we've got verbose events, dump them
dump_events("verbose", @verbose_buffer);
# and clear out our buffer
@verbose_buffer = ();
}
if (@terse_buffer) {
# if we've got terse events, dump them
dump_events("terse", @terse_buffer);
# and clear out our buffer
@terse_buffer = ();
}
# bail out if we don't have notification configured
return unless -f $cfgfile;
# what time did we last read the config file?
my $load_time = $config->{load_time};
# check when the config file was last modified...
my $mtime = (stat($cfgfile))[9];
# if it's been changed since we last read the config file, we need to
# load the new settings
if ($load_time < $mtime) {
errlog "Reloading changed config file.";
$config = readconfig();
}
}
# bail out if we don't have notification configured
return unless -f $cfgfile;
if ($config->{terse_freq}) {
if (($terse->{last_notify} + $config->{terse_freq}) <= $now) {
if (-f "$dbdir/terse.db") {
$DEBUG && errlog "doing terse notification...";
# get a temporary filename...
my ($fh, $filename) = tempfile("terseXXXXXX", DIR => $dbdir);
# overwrite the temp file we just created...
rename("$dbdir/terse.db", $filename);
if ($DEBUG) {
errlog "terse file is $filename";
}
# do the actual notification in the background
fork_into_background("terse-notification",
\&terse_notify_handler,
$config->{terse_email},
$filename,
$terse->{last_notify},
$config->{terse_level},
$config->{terse_unknown});
# ...keep track of when we last sent out a notify
$terse->{last_notify} = $now;
}
}
}
if ($config->{summary_freq}) {
if (($summary->{last_notify} + $config->{summary_freq}) <= $now) {
if (-f "$dbdir/summary.db") {
$DEBUG && errlog "doing summary notification...";
# get a temporary filename...
my ($fh, $filename) = tempfile("summaryXXXXXX", DIR => $dbdir);
# overwrite the temp file we just created...
rename("$dbdir/summary.db", $filename);
# do the actual notification in the background
fork_into_background("summary-notification",
\&summary_notify_handler,
$config->{summary_email},
$filename,
$summary->{last_notify},
$config->{summary_level},
$config->{summary_unknown});
# ...keep track of when we last sent out a notify
$summary->{last_notify} = $now;
}
}
}
if ($config->{verbose_freq}) {
if (($verbose->{last_notify} + $config->{verbose_freq}) <= $now) {
if (-f "$dbdir/verbose.db") {
$DEBUG && errlog "doing verbose notification...";
# get a temporary filename...
my ($fh, $filename) = tempfile("verboseXXXXXX", DIR => $dbdir);
# overwrite the temp file we just created...
rename("$dbdir/verbose.db", $filename);
if ($DEBUG) {
errlog "verbose file is $filename";
}
# do the actual notification in the background
fork_into_background("verbose-notification",
\&verbose_notify_handler,
$config->{verbose_email},
$filename,
$verbose->{last_notify},
$config->{verbose_level},
$config->{verbose_unknown});
# ...keep track of when we last sent out a notify
$verbose->{last_notify} = $now;
}
}
}
}
sub get_last_event {
my $dbh = shift;
my ($time, $counter);
# get the oldest timestamp...
my $sth = $dbh->prepare('SELECT MAX(time) FROM events');
$sth->execute;
my @row = $sth->fetchrow_array || (0);
$time = $row[0];
if ($time) {
# get the highest counter for this timestamp...
$sth = $dbh->prepare("SELECT MAX(counter) FROM events WHERE time = $time");
$sth->execute;
@row = $sth->fetchrow_array || (0);
$counter = $row[0];
}
return ($time, $counter);
}
##########################################################################
# start the real magic...
my $finished;
# make sure we exit if someone sends us the right signal
sub sig_handler {
my $signame = shift;
errlog("Caught signal '$signame'. Exiting...");
$finished = 1;
}
# set up our error log without buffering
open(ERRLOG, ">>$dbdir/event-dispatch.log");
my $oldfd = select(ERRLOG);
$| = 1;
select($oldfd);
$config = readconfig();
# fork off into the background. we need to do this before we connect to
# the db, otherwise, we'll get an ugly error about rolling back a
# connection that's being destroyed
daemonize;
# automagically reap child processes
$SIG{INT} = \&sig_handler;
$SIG{TERM} = \&sig_handler;
$SIG{CHLD} = 'IGNORE';
# Sigh, portable dates in perl sucks
eval "use Date::Parse";
if (!$@) {
$date_module = 'TimeDate';
} else {
eval "use Date::Manip";
if (!$@) {
$date_module = 'DateManip';
} else {
errlog "Unable to load Date module; use either TimeDate or Date::Manip";
$finished = 1;
}
}
# if they want us to write a pid, do it
if ($pidfile) {
if (open(PIDFILE, ">$pidfile")) {
print PIDFILE "$$\n";
close(PIDFILE);
}
}
my $dbh = connect_database($dbdir);
($last_inserted_time, $last_inserted_counter) = get_last_event($dbh);
my $auditlog = File::Tail->new(
name => $logfile,
debug => 1,
tail => -1,
interval => 1,
maxinterval => 5,
adjustafter => 20,
errmode => "return",
ignore_noexistant => 1
);
my $syslog = File::Tail->new(
name => $syslogfile,
debug => 1,
tail => -1,
interval => 1,
maxinterval => 5,
adjustafter => 20,
errmode => "return",
ignore_noexistant => 1
);
my $line = '';
# process complete lines from the buffer...
while (not $finished) {
my ($nfound, $timeleft, @pending) = File::Tail::select(undef, undef, undef, $timeout, ($auditlog, $syslog));
foreach (@pending) {
process_event($dbh, $_->read);
}
# see if we should flush pending entries to disk and/or do notification
check_timers($dbh);
}
# make sure we don't exit with any pending events not written to the db
$dbh->commit || errlog "Error commiting changes: $!";
$dbh->disconnect || errlog "Error disconnecting from db: $!";
# close our error/debugging log file
close(ERRLOG);
unlink($pidfile) if $pidfile;
exit 0;

View File

@@ -1,216 +0,0 @@
#!/usr/bin/perl
# ----------------------------------------------------------------------
# Copyright (c) 2005 Novell, Inc. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com.
# ----------------------------------------------------------------------
use strict;
use Getopt::Long;
use Immunix::AppArmor;
use Data::Dumper;
use Locale::gettext;
use POSIX;
sub sysctl_read($) {
my $path = shift;
my $value = undef;
if (open(SYSCTL, "<$path")) {
$value = int(<SYSCTL>);
}
close(SYSCTL);
return $value;
}
sub sysctl_write($$) {
my $path = shift;
my $value = shift;
return if (!defined($value));
if (open(SYSCTL, ">$path")) {
print SYSCTL $value;
close(SYSCTl);
}
}
# force $PATH to be sane
$ENV{PATH} = "/bin:/sbin:/usr/bin:/usr/sbin";
# initialize the local poo
setlocale(LC_MESSAGES, "");
textdomain("apparmor-utils");
# options variables
my $help = '';
GetOptions(
'file|f=s' => \$filename,
'dir|d=s' => \$profiledir,
'help|h' => \$help,
);
# tell 'em how to use it...
&usage && exit if $help;
my $sd_mountpoint = check_for_subdomain();
unless ($sd_mountpoint) {
fatal_error(gettext("AppArmor does not appear to be started. Please enable AppArmor and try again."));
}
# let's convert it to full path...
$profiledir = get_full_path($profiledir);
unless (-d $profiledir) {
fatal_error "Can't find AppArmor profiles in $profiledir.";
}
# what are we profiling?
my $profiling = shift;
unless ($profiling) {
$profiling = UI_GetString(gettext("Please enter the program to profile: "), "")
|| exit 0;
}
my $fqdbin;
if (-e $profiling) {
$fqdbin = get_full_path($profiling);
chomp($fqdbin);
} else {
if ($profiling !~ /\//) {
my $which = which($profiling);
if ($which) {
$fqdbin = get_full_path($which);
}
}
}
unless ($fqdbin && -e $fqdbin) {
if ($profiling =~ /^[^\/]+$/) {
fatal_error(sprintf(gettext('Can\'t find %s in the system path list. If the name of the application is correct, please run \'which %s\' in the other window in order to find the fully-qualified path.'), $profiling, $profiling));
} else {
fatal_error(sprintf(gettext('%s does not exist, please double-check the path.'), $profiling));
}
}
# make sure that the app they're requesting to profile is not marked as
# not allowed to have it's own profile
check_qualifiers($fqdbin);
# load all the include files
loadincludes();
my $profilefilename = getprofilefilename($fqdbin);
if (-e $profilefilename) {
$helpers{$fqdbin} = getprofileflags($profilefilename) || "enforce";
} else {
autodep($fqdbin);
$helpers{$fqdbin} = "enforce";
}
if ($helpers{$fqdbin} eq "enforce") {
complain($fqdbin);
reload($fqdbin);
}
# When reading from syslog, it is possible to hit the default kernel
# printk ratelimit. This will result in audit entries getting skipped,
# making profile generation inaccurate. When using genprof, disable
# the printk ratelimit, and restore it on exit.
my $ratelimit_sysctl = "/proc/sys/kernel/printk_ratelimit";
my $ratelimit_saved = sysctl_read($ratelimit_sysctl);
END { sysctl_write($ratelimit_sysctl, $ratelimit_saved); }
sysctl_write($ratelimit_sysctl, 0);
UI_Info(gettext("\nBefore you begin, you may wish to check if a\nprofile already exists for the application you\nwish to confine. See the following wiki page for\nmore information:\nhttp://wiki.apparmor.net/index.php/Profiles"));
UI_Important(gettext("Please start the application to be profiled in \nanother window and exercise its functionality now.\n\nOnce completed, select the \"Scan\" button below in \norder to scan the system logs for AppArmor events. \n\nFor each AppArmor event, you will be given the \nopportunity to choose whether the access should be \nallowed or denied."));
my $syslog = 1;
my $logmark = "";
my $done_profiling = 0;
$syslog = 0 if (-e "/var/log/audit/audit.log");
while (not $done_profiling) {
if ($syslog) {
$logmark = `date | md5sum`;
chomp $logmark;
$logmark = $1 if $logmark =~ /^([0-9a-f]+)/;
system("$logger -p kern.warn 'GenProf: $logmark'");
} else {
$logmark = last_audit_entry_time();
}
eval {
my $q = {};
$q->{headers} = [ gettext("Profiling"), $fqdbin ];
$q->{functions} = [ "CMD_SCAN", "CMD_FINISHED" ];
$q->{default} = "CMD_SCAN";
my ($ans, $arg) = UI_PromptUser($q);
if ($ans eq "CMD_SCAN") {
my $lp_ret = do_logprof_pass($logmark);
$done_profiling = 1 if $lp_ret eq "FINISHED";
} else {
$done_profiling = 1;
}
};
if ($@) {
if ($@ =~ /FINISHING/) {
$done_profiling = 1;
} else {
die $@;
}
}
}
for my $p (sort keys %helpers) {
if ($helpers{$p} eq "enforce") {
enforce($p);
reload($p);
}
}
UI_Info(gettext("Reloaded AppArmor profiles in enforce mode."));
UI_Info(gettext("\nPlease consider contributing your new profile! See\nthe following wiki page for more information:\nhttp://wiki.apparmor.net/index.php/Profiles\n"));
UI_Info(sprintf(gettext('Finished generating profile for %s.'), $fqdbin));
exit 0;
sub usage {
UI_Info(sprintf(gettext("usage: \%s [ -d /path/to/profiles ] [ -f /path/to/logfile ] [ program to profile ]"), $0));
exit 0;
}
sub last_audit_entry_time {
local $_ = `tail -1 /var/log/audit/audit.log`;
my $logmark;
if (/^*msg\=audit\((\d+\.\d+\:\d+).*\).*$/) {
$logmark = $1;
} else {
$logmark = "";
}
return $logmark;
}

View File

@@ -1,72 +0,0 @@
#!/usr/bin/perl
# ----------------------------------------------------------------------
# Copyright (c) 2005 Novell, Inc. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com.
# ----------------------------------------------------------------------
use strict;
use Data::Dumper;
use Getopt::Long;
use Locale::gettext;
use POSIX;
use Immunix::AppArmor;
# force $PATH to be sane
$ENV{PATH} = "/bin:/sbin:/usr/bin:/usr/sbin";
# initialize the local poo
setlocale(LC_MESSAGES, "");
textdomain("apparmor-utils");
setup_yast();
# options variables
my $help = '';
my $logmark;
GetOptions(
'file|f=s' => \$filename,
'dir|d=s' => \$profiledir,
'logmark|m=s' => \$logmark,
'help|h' => \$help,
);
# tell 'em how to use it...
&usage && exit if $help;
# let's convert it to full path...
$profiledir = get_full_path($profiledir);
unless (-d $profiledir) {
fatal_error "Can't find AppArmor profiles in $profiledir.";
}
# load all the include files
loadincludes();
do_logprof_pass($logmark);
shutdown_yast();
exit 0;
sub usage {
UI_Info(sprintf(gettext("usage: \%s [ -d /path/to/profiles ] [ -f /path/to/logfile ] [ -m \"mark in log to start processing after\""), $0));
exit 0;
}

View File

@@ -1,821 +0,0 @@
#!/usr/bin/perl
# ----------------------------------------------------------------------
# Copyright (c) 2008 Dominic Reynolds. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
#
my $usage =
"aa-repo.pl --command args\n";
my $usage_search =
" --search [author=XXX] [prog=XXX] [id=XXX]
Search the repository for profiles matching the search criteria
and return the results.
NOTE: One --search switch per option
--verbose|v
Verbosity level. Supply either one or two switches. Two switches
adds full profile text in returned search results.\n";
my $usage_push =
" --push [--profile=XXX|all] [--changelog=XXX]
Push local profiles to repository, uses configured user and upon
overwrite of an existing profile in the repository then prompt
user with a diff for confirmation XXX the name of the application
whose profile should be uploaded or \"all\" to upload all
profiles. Multiple --profile switches may be passed to supply
multiple profile names
e.g. --push --profile /usr/sbin/mdnsd --profile /usr/sbin/ftp
e.g. --push --profile all\n";
my $usage_pull =
" --pull [--author=XXX] [--profile=XXX] or [--id=XXX] [--mode=complain]
pull remote profiles and install on local system
If operation will change local profiles then prompt user with
diff for confirmation
NOTE: One --pull switch per option and there are three acceptable
combinations
--pull --author=XXX
* pull all profiles in the repo for the author
--pull --author=XXX --profile=XXXX
* pull the profile for prog owned by author
--pull --id=XXXX
* pull the profile with id
--pull --mode=complain
* set the profile(s) to complain mode when installed
Profiles are checked for conflicts with currently installed
profiles and presented as a list to the user to confirm and view.\n";
my $usage_sync =
" --sync [--up] [--down] [--noconfirm]
Synchronize local profile set with the repository - showing
changes and allowing prompting the user with the diffs and
suggest the newest version to be activated. If the --all option
is passed then treat profiles not marked as remote as new
profiles that will be uploaded to the repository.\n";
my $usage_stat =
" --status
Show the current status of the local profile set. This operation
is similar to sync but does not prompt the user to up|down load
changes\n";
my $usage_getconfig =
" --getconfig|c
Print the current configuration for the repsository\n";
my $usage_setconfig =
" --setconfig [url=xxx] [username=xxxx] [password=xxxx] [enabled=(yes|no)]
[upload=(yes|no)]
Set the configuration options for the repository.
NOTE: One --setconfig switch per option\n";
my $usage_bottom =
" --quiet|q Don't prompt user - assume that all changes should be made.
ISSUES:
o Should changes made to the system be recorded somehow? An audit event?
o Should the tool allow a repo/distro to be passed for each operation?
";
use strict;
use Getopt::Long;
use Immunix::AppArmor;
use Immunix::Repository;
use Data::Dumper;
use Locale::gettext;
use POSIX;
# force $PATH to be sane
$ENV{PATH} = "/bin:/sbin:/usr/bin:/usr/sbin";
# initialize the local poo
setlocale(LC_MESSAGES, "");
textdomain("apparmor-utils");
# options variables
my $help = '';
my $verbose = '';
my ( $id, $author, $mode, %search, $sync, $getconfig, $push,
$pull, %setconfig, @profiles, $all, $changelog, $stat );
GetOptions(
'search=s%' => \%search,
'sync=s' => \$sync,
'status' => \$stat,
'getconfig|c' => \$getconfig,
'setconfig=s%' => \%setconfig,
'push' => \$push,
'id=s' => \$id,
'author=s' => \$author,
'profile=s' => \@profiles,
'changelog=s' => \$changelog,
'pull' => \$pull,
'all|a' => \$all,
'help|h' => \$help,
'verbose|v+' => \$verbose
);
#
# Root privs required to run the repo tool
#
if ( geteuid() != 0 ) {
print STDERR gettext(
"You must be logged in with root user privileges to use this program.\n"
);
exit;
}
# --help
# tell 'em how to use it...
&usage && exit if $help;
my $config = get_repo_config();
#
# --getconfig operation
#
&config && exit if $getconfig;
my $sd_mountpoint = check_for_subdomain();
unless ($sd_mountpoint) {
fatal_error(gettext(
"AppArmor does not appear to be started. Please enable AppArmor and try again."
)
);
}
#
# --setconfig operation
#
if ( keys %setconfig ) {
$config->{url} = $setconfig{url} if ( $setconfig{url} );
$config->{distro} = $setconfig{distro} if ( $setconfig{distro} );
$config->{enabled} = $setconfig{enabled} if ( $setconfig{enabled} );
$config->{email} = $setconfig{email} if ( $setconfig{email} );
$config->{user} = $setconfig{username} if ( $setconfig{username} );
$config->{password} = $setconfig{password} if ( $setconfig{password} );
$config->{upload} = $setconfig{upload} if ( $setconfig{upload} );
set_repo_config( $config );
}
#
# --push operation
#
if ( $push ) {
my ($conflicts, $repo_profiles, $local_profiles, @overrides);
if ( ! @profiles ) {
print STDERR gettext(
"Must supply at least one profile using \"--profile XXX\" to --push\n"
);
exit 1;
} else {
print STDERR Data::Dumper->Dump([@profiles], [qw(*profiles)]);
}
my $changelog = $changelog?$changelog:"none";
push_profiles( \@profiles, $changelog, 1 );
}
#
# --pull operation
#
if ( $pull ) {
my $type = "";
if ( $id ) {
if ( $author || @profiles ) {
print STDERR gettext(
"Option --id=XX is only allowed by itself and not in combination to
other options for the --pull command.\n"
);
exit 1;
}
$type = "id";
}
if ( @profiles && ! $author ) {
print STDERR gettext(
"Option --profile=XX requires that the --author=XX option be supplied
to distinguish a specific profile.\n"
);
exit 1;
} else {
$type = "profile";
}
my $mode = $mode eq "complain"?1:0;
pull_profiles( \@profiles, $type, $mode, 1 );
}
#
# --search operation
#
if ( keys %search ) {
if ( $search{id} ) {
my($status,$result) = fetch_profile_by_id( $config->{url},
$search{id} );
if ($status) {
my $title = sprintf(gettext( "Profile ID %s\n"), $search{id});
console_print_search_results( $title,
"profile",
{ $result->{name} => $result }
);
} else {
print STDERR "ERROR $result\n";
}
} elsif ( $search{author} && $search{prog} ) {
my($status,$result) =
fetch_profiles_by_name_and_user( $config->{url},
$config->{distro},
$search{prog},
$search{author}
);
if ( $status ) {
my $title =
sprintf(gettext("Profiles matching user: %s and program: %s\n"),
$search{author},
$search{prog}
);
console_print_search_results( $title, "profile", $result );
} else {
print STDERR "ERROR $result\n";
}
} elsif ( $search{author} ) {
my($status,$result) = fetch_profiles_by_user( $config->{url},
$config->{distro},
$search{author}
);
if ( $status ) {
my $title = sprintf(gettext( "Profiles for %s\n"), $search{author});
console_print_search_results( $title, "profile", $result );
} else {
print STDERR "ERROR $result\n";
}
} elsif ( $search{prog} ) {
my($status,$result) = fetch_profiles_by_name( $config->{url},
$config->{distro},
$search{prog},
);
if ( $status ) {
my $title = sprintf(gettext("Profiles matching program: %s\n"),
$search{prog});
console_print_search_results( $title, "user", $result );
} else {
print STDERR "ERROR $result\n";
}
} else {
print STDERR
"Unsupported search criteria. Please specify at least one of
author=XXX prog=XXX id=XXX\n";
}
}
if ( $stat ) {
my ( $local_profiles, $remote_profiles );
my $msg =
" The following profiles are stored in the repository but
are not synchronized with the copy in the repository\n";
my ($status, $result) = fetch_profiles_by_user( $config->{url},
$config->{distro},
$config->{user}
);
if ( $status ) {
$remote_profiles = $result;
} else {
print STDERR sprintf(gettext("ERROR connecting to repository: %s\n"),
$result);
exit;
}
readprofiles();
$local_profiles = serialize_local_profiles( \%sd );
my ($local_only,$unsynched,$synched,$conflicts) = ({}, {}, {});
$unsynched = find_profile_conflicts($remote_profiles, $local_profiles);
for my $p ( keys %$local_profiles ) {
if ( ! $remote_profiles->{$p} ) {
$local_only->{$p} = $local_profiles->{$p};
}
}
for my $p ( keys %$remote_profiles ) {
$synched->{$p} =
$remote_profiles->{$p}->{profile} if ( ! %$unsynched->{$p} );
}
UI_status($synched, $unsynched, $local_only);
}
######################
# Helper functions
######################
#
# Compare the local profile set with the remote profile set.
# Return a list of the conflicting profiles as a list
# { PROFILE_NAME => [LOCAL_PROFILE, REMOTE_PROFILE] ]
#
#
# remote_profiles = repository profiles as returned by one of the
# Immunix::Repository::fetch... functions
# local_profiles = hash ref containing
# { name => serialized local profile }
#
#
sub find_profile_conflicts ($$) {
my ($remote_profiles,$local_profiles) = @_;
my $conflicts = {};
for my $p ( keys(%$local_profiles) ) {
if ( $local_profiles->{$p} and $remote_profiles->{$p} ) {
my $p_local = $local_profiles->{$p};
my $p_remote = $remote_profiles->{$p}->{profile};
chomp($p_local);
chomp($p_remote);
if ( $p_remote ne $p_local ) {
$conflicts->{$p} = [ $p_local, $p_remote ];
}
}
}
return( $conflicts );
}
sub serialize_local_profiles ($) {
my $profiles = shift;
my $local_profiles = {};
for my $p ( keys %$profiles ) {
my $serialize_opts = {};
$serialize_opts->{NO_FLAGS} = 1;
my $p_local = serialize_profile( $profiles->{$p},
$p,
$serialize_opts );
$local_profiles->{$p} = $p_local;
}
return $local_profiles;
}
sub console_print_search_results ($$$) {
my ($title, $type,$result) = @_;
open(PAGER, "| less") or die "Can't open pager";
print PAGER $title;
print PAGER "Found " . values(%$result) . " profiles \n";
for my $p ( values(%$result) ) {
if ( $verbose ) {
if ( $type eq "user" ) {
print PAGER " Author [ " . $p->{username} . " ]\n";
} elsif ( $type eq "profile" ) {
print PAGER " Name [ " . $p->{name} . " ]\n";
}
print PAGER " Created [ " . $p->{created_at} . " ]\n";
print PAGER " Downloads [ " . $p->{downloaded_count} . " ]\n";
print PAGER " ID [ " . $p->{id} . " ]\n";
if ( $verbose > 1 ) {
print PAGER " Profile [ \n" . $p->{profile} . " ]\n\n";
} else {
print PAGER "\n";
}
} else {
my $data = $type eq "user"?$p->{username}:$p->{name};
print PAGER " " . $data . "\n";
}
}
close PAGER;
}
sub UI_resolve_profile_conflicts {
my ($explanation, $conflict_hash) = @_;
my $url = $config->{url};
my @conflicts = map { [ $_,
$conflict_hash->{$_}->[0],
$conflict_hash->{$_}->[1]
] }
keys %$conflict_hash;
my @commits = [];
my $title = "Profile conflicts";
my %resolution = ();
my $q = {};
$q->{title} = $title;
$q->{headers} = [ "Repository", $url, ];
$q->{explanation} = $explanation;
$q->{functions} = [ "CMD_OVERWRITE",
"CMD_KEEP",
"CMD_VIEW_CHANGES",
"CMD_ABORT",
"CMD_CONTINUE", ];
$q->{default} = "CMD_OVERWRITE";
$q->{options} = [ map { $_->[0] } @conflicts ];
$q->{selected} = 0;
my ($ans, $arg);
do {
($ans, $arg) = UI_PromptUser($q);
if ($ans eq "CMD_VIEW_CHANGES") {
display_changes($conflicts[$arg]->[2], $conflicts[$arg]->[1]);
}
if ( $ans eq "CMD_OVERWRITE") {
$q->{options} =
[ map { $_ =~ /$conflicts[$arg]->[0]( K| O)?$/?
$conflicts[$arg]->[0] . " O":
$_ }
@{$q->{options}}
];
$resolution{$conflicts[$arg]->[0]} = "O";
}
if ( $ans eq "CMD_KEEP") {
$q->{options} =
[ map { $_ =~ /$conflicts[$arg]->[0]( K| O)?$/?
$conflicts[$arg]->[0] . " K":
$_ }
@{$q->{options}}
];
$resolution{$conflicts[$arg]->[0]} = "K";
}
$q->{selected} = ($arg+1) % @conflicts;
} until $ans =~ /^CMD_CONTINUE/;
if ($ans eq "CMD_CONTINUE") {
my @results = ();
for my $p ( keys %resolution ) {
if ( $resolution{$p} eq "O" ) {
push @results, $p;
}
}
return @results;
}
}
sub UI_display_profiles {
my ($explanation, $profile_hash) = @_;
my $url = $config->{url};
my @profiles = map { [ $_, $profile_hash->{$_} ] } keys %$profile_hash;
my $title = gettext("Profiles");
my $q = {};
$q->{title} = $title;
$q->{headers} = [ "Repository", $url, ];
$q->{explanation} = $explanation;
$q->{functions} = [ "CMD_VIEW",
"CMD_CONTINUE", ];
$q->{default} = "CMD_CONTINUE";
$q->{options} = [ map { $_->[0] } @profiles ];
$q->{selected} = 0;
my ($ans, $arg);
do {
($ans, $arg) = UI_PromptUser($q);
if ($ans eq "CMD_VIEW") {
my $pager = get_pager();
open ( PAGER, "| $pager" ) or die "Can't open $pager";
print PAGER gettext("Profile: ") . $profiles[$arg]->[0] . "\n";
print PAGER $profiles[$arg]->[1];
close PAGER;
}
$q->{selected} = ($arg+1) % @profiles;
} until $ans =~ /^CMD_CONTINUE/;
return;
}
sub UI_display_profile_conflicts {
my ($explanation, $conflict_hash) = @_;
my $url = $config->{url};
my @conflicts = map { [ $_,
$conflict_hash->{$_}->[0],
$conflict_hash->{$_}->[1]
] }
keys %$conflict_hash;
my @commits = [];
my $title = gettext("Profile conflicts");
my $q = {};
$q->{title} = $title;
$q->{headers} = [ "Repository", $url, ];
$q->{explanation} = $explanation;
$q->{functions} = [ "CMD_VIEW_CHANGES",
"CMD_CONTINUE", ];
$q->{default} = "CMD_CONTINUE";
$q->{options} = [ map { $_->[0] } @conflicts ];
$q->{selected} = 0;
my ($ans, $arg);
do {
($ans, $arg) = UI_PromptUser($q);
if ($ans eq "CMD_VIEW_CHANGES") {
display_changes($conflicts[$arg]->[2], $conflicts[$arg]->[1]);
}
$q->{selected} = ($arg+1) % @conflicts;
} until $ans =~ /^CMD_CONTINUE/;
return;
}
sub usage {
if ( $help eq "push" ) {
print STDERR $usage . $usage_push ."\n";
} elsif ( $help eq "pull" ) {
print STDERR $usage . $usage_pull ."\n";
} elsif ( $help eq "sync" ) {
print STDERR $usage . $usage_sync ."\n";
} elsif ( $help eq "getconfig" ) {
print STDERR $usage . $usage_getconfig ."\n";
} elsif ( $help eq "setconfig" ) {
print STDERR $usage . $usage_setconfig ."\n";
} elsif ( $help eq "status" ) {
print STDERR $usage . $usage_stat ."\n";
} elsif ( $help eq "search" ) {
print STDERR $usage . $usage_search ."\n";
} else {
open(PAGER, "| less") or die "Can't open pager";
print PAGER $usage .
$usage_search .
$usage_push .
$usage_pull .
$usage_sync .
$usage_stat .
$usage_setconfig .
$usage_getconfig .
$usage_bottom . "\n";
close PAGER;
}
}
#
# --getconfig helper function
#
sub config {
my $configstr = gettext("Current config\n");
my $config = get_repo_config();
$configstr .= "\turl:\t\t$config->{url}\n";
$configstr .= "\tdistro:\t\t$config->{distro}\n";
$configstr .= "\tenabled:\t$config->{enabled}\n";
$configstr .= "\temail:\t\t$config->{email}\n";
$configstr .= "\tusername:\t$config->{user}\n";
$configstr .= "\tpassword:\t$config->{password}\n";
$configstr .= "\tupload:\t\t$config->{upload}\n";
print STDERR $configstr . "\n";
}
#
# helper function to push profiles to the repository
# used by --push and --sync options
#
sub push_profiles($$$) {
my ( $p_ref, $changelog, $confirm ) = @_;
my ( $conflicts, $remote_profiles, $local_profiles, @overrides );
my @profiles = @$p_ref;
my $conflict_msg =
" The following profile(s) selected for upload conflicts with a profile already
stored in the repository for your account. Please choose whether to keep the
current version or overwrite it.\n";
$all = 0;
readprofiles();
my ($status, $result) = fetch_profiles_by_user( $config->{url},
$config->{distro},
$config->{user}
);
if ( $status ) {
$remote_profiles = $result;
} else {
print STDERR sprintf(gettext("ERROR connecting to repository: %s\n"),
$result);
exit;
}
$all = 1 if ( grep(/^all$/, @profiles) );
if ( $all ) {
$local_profiles = serialize_local_profiles( \%sd );
} else {
my $local_sd = {};
for my $p ( @profiles ) {
if ( !$sd{$p} ) {
print STDERR
sprintf(gettext("Profile for [%s] does not exist\n"), $p);
exit;
}
$local_sd->{$p} = $sd{$p};
}
$local_profiles = serialize_local_profiles( $local_sd );
}
$conflicts = find_profile_conflicts($remote_profiles, $local_profiles);
if ( keys %$conflicts ) {
@overrides = UI_resolve_profile_conflicts( $conflict_msg, $conflicts );
}
if ( $local_profiles ) {
my @uploads;
for my $p ( keys %$local_profiles ) {
unless ( $conflicts->{$p} and !grep(/^$p$/, @overrides) ) {
print STDERR gettext("Uploading ") . $p . "... ";
my ($status,$result) = upload_profile( $config->{url},
$config->{user},
$config->{password},
$config->{distro},
$p,
$local_profiles->{$p},
$changelog
);
print STDERR gettext("done") . "\n";
}
if ( $status ) {
push @uploads, $p;
} else {
print STDERR gettext("Error uploading") . "$p: $result\n";
}
}
if ( @uploads ) {
#
# Currently the upload API with the repository returns the
# the current users profile set before the update so we have
# to refetch to obtain the metadata to update the local profiles
#
my $repo_p = [];
print STDERR gettext("Updating local profile metedata....\n");
my ($status,$result) = fetch_profiles_by_user( $config->{url},
$config->{distro},
$config->{user} );
if ( $status ) {
for my $p ( @uploads ) {
push( @$repo_p, [$p, $result->{$p}] ) if ( $result->{$p} );
}
activate_repo_profiles( $config->{url}, $repo_p, 0 );
print STDERR gettext(" done\n");
} else {
print STDERR gettext(
"Failed to retrieve updated profiles from the repository. Error: "
) . $result . "\n";
}
}
}
}
#
# Helper function for pulling profiles from the repository
# used by --pull and --sync options
#
sub pull_profiles($$$$) {
my ( $p_ref, $mode, $confirm, $opts ) = @_;
my @profiles = @$p_ref;
my ( $conflicts, $commit_list, $remote_profiles,
$local_profiles, @overrides );
my $conflict_msg =
" The following profiles selected for download conflict with profiles
already deployed on the system. Please choose whether to keep the local
version or overwrite with the version from the repository\n";
readprofiles();
if ( $opts->{id} ) {
my ($status,$newp) = fetch_profile_by_id( $config->{url}, $opts->{id} );
if ( ! $status ) {
print STDERR gettext(
sprintf("Error occured during operation\n\t[%s]\n",
$newp
)
);
exit 1;
} else {
$remote_profiles = { $newp->{name} => $newp->{profile} };
}
} elsif ( @profiles && $opts->{author} ) {
$remote_profiles = {};
for my $p ( @profiles ) {
my ($status,$profiles) =
fetch_profiles_by_name_and_user( $config->{url},
$config->{distro},
$p,
$opts->{author} );
if ( ! $status ) {
print STDERR gettext(sprintf(
"Error occured during operation\n\t[%s]\n",
$profiles
)
);
exit 1;
} else {
$remote_profiles->{$p} = $profiles->{$p};
}
}
} elsif ( $opts->{author} ) {
my ($status,$profiles) = fetch_profiles_by_user( $config->{url},
$config->{distro},
$opts->{author} );
if ( ! $status ) {
print STDERR gettext(sprintf(
"Error occured during operation\n\t[%s]\n",
$profiles
)
);
exit 1;
} else {
$remote_profiles = $profiles;
}
}
$local_profiles = serialize_local_profiles( \%sd );
$conflicts = find_profile_conflicts( $remote_profiles, $local_profiles );
if ( keys %$conflicts ) {
@overrides = UI_resolve_profile_conflicts( $conflict_msg, $conflicts );
}
for my $p ( keys %$remote_profiles ) {
unless ( $conflicts->{$p} and !grep(/^$p$/, @overrides) ) {
$remote_profiles->{$p}->{username} = $opts->{author};
push @$commit_list, [$p, $remote_profiles->{$p}];
}
}
if ( $commit_list and @$commit_list ) {
activate_repo_profiles( $config->{url}, $commit_list, $mode );
system("rcapparmor reload");
} else {
UI_Info(gettext("No changes to make"));
}
}
sub UI_status {
my ($synched, $unsynched, $local) = @_;
my $url = $config->{url};
my $synched_text = gettext("Synchronized repository profiles:\t\t") .
keys %$synched;
my $unsynched_text = gettext("Unsynchronized repository profiles:\t") .
keys %$unsynched;
my $local_text = gettext("Local only profiles :\t\t\t") . keys %$local;
my $options = [ $synched_text, $unsynched_text, $local_text ];
my $title = gettext("Profile Status");
my $explanation = gettext(
" This is the current status of active profiles on the system.
To view the profiles or unsyncronized changes select VIEW\n"
);
my $q = {};
$q->{title} = $title;
$q->{headers} = [ "Repository", $url, ];
$q->{explanation} = $explanation;
$q->{functions} = [ "CMD_VIEW", "CMD_FINISHED", ];
$q->{default} = "CMD_FINISHED";
$q->{options} = $options;
$q->{selected} = 0;
my ($ans, $arg);
do {
($ans, $arg) = UI_PromptUser($q);
if ($ans eq "CMD_VIEW") {
if ( $arg == 0 ) {
UI_display_profiles(
gettext("Profiles stored in the repository"),
$synched
);
} elsif ( $arg == 1 ) {
UI_display_profile_conflicts(
gettext("Unsyncronised profile changes"),
$unsynched
);
} elsif ( $arg == 2 ) {
UI_display_profiles(
gettext("Profiles stored in the repository"),
$local
);
}
}
} until $ans =~ /^CMD_FINSHED/;
}

View File

@@ -1,218 +0,0 @@
#!/usr/bin/perl -w
# ------------------------------------------------------------------
#
# Copyright (C) 2005-2006 Novell/SUSE
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License published by the Free Software Foundation.
#
# ------------------------------------------------------------------
use strict;
use Getopt::Long;
use Cwd 'abs_path';
my $confdir = "/etc/apparmor";
my $sd_mountpoint;
my $check_enabled = 0;
my $count_enforced = 0;
my $count_profiled = 0;
my $count_complain = 0;
my $verbose = 0;
my $help;
GetOptions(
'complaining' => \$count_complain,
'enabled' => \$check_enabled,
'enforced' => \$count_enforced,
'profiled' => \$count_profiled,
'verbose|v' => \$verbose,
'help|h' => \$help,
) or usage();
sub usage {
print "Usage: $0 [OPTIONS]\n";
print "Displays various information about the currently loaded AppArmor policy.\n";
print "OPTIONS (one only):\n";
print " --enabled returns error code if subdomain not enabled\n";
print " --profiled prints the number of loaded policies\n";
print " --enforced prints the number of loaded enforcing policies\n";
print " --complaining prints the number of loaded non-enforcing policies\n";
print " --verbose (default) displays multiple data points about loaded policy set\n";
print " --help this message\n";
exit;
}
$verbose = 1 if ($count_complain + $check_enabled + $count_enforced + $count_profiled == 0);
usage() if $help or ($count_complain + $check_enabled + $count_enforced + $count_profiled + $verbose > 1);
sub is_subdomain_loaded() {
return 1 if (-d "/sys/module/apparmor");
if(open(MODULES, "/proc/modules")) {
while(<MODULES>) {
return 1 if m/^(subdomain|apparmor)\s+/;
}
}
return 0;
}
sub find_subdomainfs() {
my $sd_mountpoint;
if(open(MOUNTS, "/proc/mounts")) {
while(<MOUNTS>) {
$sd_mountpoint = "$1/apparmor" if m/^\S+\s+(\S+)\s+securityfs\s/ && -e "$1/apparmor";
$sd_mountpoint = "$1/subdomain" if m/^\S+\s+(\S+)\s+securityfs\s/ && -e "$1/subdomain";
$sd_mountpoint = $1 if m/^\S+\s+(\S+)\s+subdomainfs\s/ && -e "$1";
}
close(MOUNTS);
}
return $sd_mountpoint;
}
sub get_profiles {
my $mountpoint = shift;
my %profiles = ();
if (open(PROFILES, "$mountpoint/profiles")) {
while(<PROFILES>) {
$profiles{$1} = $2 if m/^([^\(]+)\s+\((\w+)\)$/;
}
close(PROFILES);
}
return (%profiles);
}
sub get_processes {
my %profiles = @_;
my %processes = ();
if (opendir(PROC, "/proc")) {
my $file;
while (defined($file = readdir(PROC))) {
if ($file =~ m/^\d+/) {
if (open(CURRENT, "/proc/$file/attr/current")) {
while (<CURRENT>) {
if (m/^([^\(]+)\s+\((\w+)\)$/) {
$processes{$file}{'profile'} = $1;
$processes{$file}{'mode'} = $2;
} elsif (grep(abs_path("/proc/$file/exe") eq $_ , keys(%profiles))) {
# keep only unconfined processes that have a profile defined
$processes{$file}{'profile'} = abs_path("/proc/$file/exe");
$processes{$file}{'mode'} = 'unconfined';
}
}
close(CURRENT);
}
}
}
closedir(PROC);
}
return (%processes);
}
my $is_loaded = is_subdomain_loaded();
if (!$is_loaded) {
print STDERR "apparmor module is not loaded.\n" if $verbose;
exit 1;
}
print "apparmor module is loaded.\n" if $verbose;
$sd_mountpoint = find_subdomainfs();
if (!$sd_mountpoint) {
print STDERR "apparmor filesystem is not mounted.\n" if $verbose;
exit 3;
}
if (! -r "$sd_mountpoint/profiles") {
print STDERR "You do not have enough privilege to read the profile set.\n" if $verbose;
exit 4;
}
#print "subdomainfs is at $sd_mountpoint.\n" if $verbose;
# processes is a hash table :
# * keys : processes pid
# * values : hash containing information about the running process:
# * 'profile' : name of the profile applied to the running process
# * 'mode' : mode of the profile applied to the running process
my %processes = ();
my %enforced_processes = ();
my %complain_processes = ();
my %unconfined_processes = ();
# profiles is a hash table :
# * keys : profile name
# * value : profile mode
my %profiles;
my @enforced_profiles = ();
my @complain_profiles = ();
%profiles = get_profiles($sd_mountpoint);
@enforced_profiles = grep { $profiles{$_} eq 'enforce' } keys %profiles;
@complain_profiles = grep { $profiles{$_} eq 'complain' } keys %profiles;
# we consider the case where no profiles are loaded to be "disabled" as well
my $rc = (keys(%profiles) == 0) ? 2 : 0;
if ($check_enabled) {
exit $rc;
}
if ($count_profiled) {
print scalar(keys(%profiles)). "\n";
exit $rc;
}
if ($count_enforced) {
print $#enforced_profiles + 1 . "\n";
exit $rc;
}
if ($count_complain) {
print $#complain_profiles + 1 . "\n";
exit $rc;
}
if ($verbose) {
print keys(%profiles) . " profiles are loaded.\n";
print $#enforced_profiles + 1 . " profiles are in enforce mode.\n";
for (sort(@enforced_profiles)) {
print " " . $_ . "\n";
}
print $#complain_profiles + 1 . " profiles are in complain mode.\n";
for (sort(@complain_profiles)) {
print " " . $_ . "\n";
}
}
%processes = get_processes(%profiles);
if ($verbose) {
for (keys(%processes)) {
$enforced_processes{$_} = $processes{$_} if $processes{$_}{'mode'} eq 'enforce';
$complain_processes{$_} = $processes{$_} if $processes{$_}{'mode'} eq 'complain';
# some early code uses unconfined instead of unconfined.
$unconfined_processes{$_} = $processes{$_} if $processes{$_}{'mode'} =~ /uncon(fi|strai)ned/;
}
print keys(%processes) . " processes have profiles defined.\n";
print keys(%enforced_processes) . " processes are in enforce mode :\n";
for (sort { $enforced_processes{$a}{'profile'} cmp $enforced_processes{$b}{'profile'} } keys(%enforced_processes)) {
print " " . $enforced_processes{$_}{'profile'} . " ($_) \n";
}
print keys(%complain_processes) . " processes are in complain mode.\n";
for (sort { $complain_processes{$a}{'profile'} cmp $complain_processes{$b}{'profile'} } keys(%complain_processes)) {
print " " . $complain_processes{$_}{'profile'} . " ($_) \n";
}
print keys(%unconfined_processes) . " processes are unconfined but have a profile defined.\n";
for (sort { $unconfined_processes{$a}{'profile'} cmp $unconfined_processes{$b}{'profile'} } keys(%unconfined_processes)) {
print " " . $unconfined_processes{$_}{'profile'} . " ($_) \n";
}
}
exit $rc;

View File

@@ -1,113 +0,0 @@
#!/usr/bin/perl -w
# ----------------------------------------------------------------------
# Copyright (c) 2005 Novell, Inc. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com.
# ----------------------------------------------------------------------
#
# unconfined -
# audit local system for processes listening on network connections
# that are not currently running with a profile.
use strict;
use Getopt::Long;
use Immunix::AppArmor;
use Locale::gettext;
use POSIX;
setlocale(LC_MESSAGES, "");
textdomain("apparmor-utils");
# options variables
my $paranoid = '';
my $help = '';
GetOptions(
'paranoid' => \$paranoid,
'help|h' => \$help,
);
# tell 'em how to use it...
&usage && exit if $help;
sub usage {
printf(gettext("Usage: %s [ --paranoid ]\n"), $0);
exit 0;
}
my $subdomainfs = check_for_subdomain();
die gettext("AppArmor does not appear to be started. Please enable AppArmor and try again.") . "\n"
unless $subdomainfs;
my @pids;
if ($paranoid) {
opendir(PROC, "/proc") or die gettext("Can't read /proc\n");
@pids = grep { /^\d+$/ } readdir(PROC);
closedir(PROC);
} else {
if (open(NETSTAT, "LANG=C /bin/netstat -nlp |")) {
while (<NETSTAT>) {
chomp;
push @pids, $5
if /^(tcp|udp)\s+\d+\s+\d+\s+\S+\:(\d+)\s+\S+\:(\*|\d+)\s+(LISTEN|\s+)\s+(\d+)\/(\S+)/;
}
close(NETSTAT);
}
}
for my $pid (sort { $a <=> $b } @pids) {
my $prog = readlink "/proc/$pid/exe" or next;
my $attr;
if (open(CURRENT, "/proc/$pid/attr/current")) {
while (<CURRENT>) {
chomp;
$attr = $_ if (/^\// || /^null/);
}
close(CURRENT);
}
my $cmdline = `cat /proc/$pid/cmdline`;
my $pname = (split(/\0/, $cmdline))[0];
if ($pname =~ /\// && !($pname eq $prog)) {
$pname = "($pname) ";
} else {
$pname = "";
}
if (not $attr) {
if ($prog =~ m/^(\/usr\/bin\/python|\/usr\/bin\/perl|\/bin\/bash)$/) {
#my $scriptname = (split(/\0/, `cat /proc/$pid/cmdline`))[1];
$cmdline =~ s/\0/ /g;
$cmdline =~ s/\s+$//;
chomp $cmdline;
print "$pid $prog ($cmdline) " . gettext("not confined\n");
} else {
print "$pid $prog $pname" . gettext("not confined\n");
}
} else {
if ($prog =~ m/^(\/usr\/bin\/python|\/usr\/bin\/perl|\/bin\/bash)$/) {
#my $scriptname = (split(/\0/, `cat /proc/$pid/cmdline`))[1];
$cmdline =~ s/\0/ /g;
$cmdline =~ s/\s+$//;
chomp $cmdline;
print "$pid $prog ($cmdline) " . gettext("confined by") . " '$attr'\n";
} else {
print "$pid $prog $pname" . gettext("confined by") . " '$attr'\n";
}
}
}

View File

@@ -1,135 +0,0 @@
#! /usr/bin/perl -w
# Very simple script to try converting AppArmor profiles to the new
# profile syntax as of April 2007.
#
# Copyright (C) 2007 Andreas Gruenbacher <agruen@suse.de>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
use FileHandle;
use File::Temp;
use Getopt::Std;
use strict;
sub match($) {
my ($str) = @_;
my @fields;
@fields = ($str =~ /^(\s*)([@\/]\S*)(\s.*,)$/);
if (!@fields) {
@fields = ($str =~ /^(\s*")((?:[^"]|\\")*)("\s.*,)$/);
}
return @fields;
}
sub alterations($) {
my ($str) = @_;
if ($str =~ /^([^{]*){([^}]*,[^}]*)}(.*)$/) {
my @strs = map { "$1$_$3" } split(/,/, $2);
return map { alterations($_) } @strs;
} else {
return ($str);
}
}
my %known_dirs;
sub remember_pathname($) {
my ($str) = @_;
my $pathname;
for (split /(\/)/, $str) {
if ($_ eq '/' && $pathname ne '') {
#print "<<>> $pathname\n";
$known_dirs{$pathname} = 1;
}
$pathname .= $_;
}
}
sub add_slash($$) {
my ($str, $perms) = @_;
return exists $known_dirs{$str} || -d $str;
}
sub never_add_slash($$) {
my ($str, $perms) = @_;
return $perms =~ /[lmx]/ || $str =~ /\.(so|cf|db|conf|config|log|pid|so\*)$/ ||
$str =~ /(\*\*|\/)$/ || (-e $str && ! -d $str);
}
our($opt_i);
getopts('i');
foreach my $filename (@ARGV) {
my $fh_in;
$fh_in = new FileHandle("< $filename")
or die "$filename: $!\n";
while (<$fh_in>) {
if (my @fields = match($_)) {
for my $x (alterations($fields[1])) {
remember_pathname($x);
}
}
}
}
if (@ARGV == 0) {
print "Usage: $0 profile ...\n";
print "Tries to convert the profile to the new profile syntax, and\n" .
"prints the result to standard output. The result may need" .
"further review.\n";
exit 0;
}
foreach my $filename (@ARGV) {
my ($fh_in, $fh_out, $tmpname);
$fh_in = new FileHandle("< $filename")
or die "$filename: $!\n";
if ($opt_i) {
($fh_out, $tmpname) = mkstemp("$filename.XXXXXX")
or die "$!\n";
*STDOUT = $fh_out;
}
while (<$fh_in>) {
if (my @fields = match($_)) {
for my $x (alterations($fields[1])) {
if (never_add_slash($x, $fields[2])) {
print $_;
} elsif (add_slash($x, $fields[2])) {
print "$fields[0]$x/$fields[2] # (dir)\n";
} else {
print "$fields[0]$x/$fields[2] # (maybe-dir)\n";
print $_;
}
}
} else {
print $_;
}
}
if ($opt_i) {
rename $tmpname, $filename
or die "$filename: $!\n";
}
}
# vim: smartindent softtabstop=4 shiftwidth=4

View File

@@ -1,201 +0,0 @@
#!/usr/bin/perl -wi
# automatically repair apparmor profiles that have had their supporting
# infrastructure refactored out from underneath them
# note -i in shebang line -- this program will modify in-place
# profiles or #include chunks specified on the command line without
# backups. Please make some yourself and inspect the changes made by
# this tool to ensure they look correct.
# It'll try to fix up #include files (supplied by SUSE/Immunix) that have
# moved; it will also inspect many #include files that exist solely
# for netdomain rule separation, and either remove the #include line
# from profiles/includes or suck in the contents of the specific file,
# depending if there was any non-netdomain content.
# If you haven't modified any of the files listed in the @useless array,
# you probably don't have to concern yourself with the complicated part
# of the previous paragraph. If you did modify any of those files, this
# tool will inspect those for changes, try to update any lines in those
# files for correctness, and insert those lines directly into the
# referencing profiles.
our %count_cache;
# count the number of 'interesting' lines in the file
sub numlines ($) {
my $name = $_[0];
return $count_cache{$name} if $count_cache{$name};
open FH, $name or return 1; # can't tell -> not empty
my $linecount=0;
while(<FH>) {
if (m/^[^#]*#include/) {
$linecount++;
} elsif (m/^\s*#/) {
# just a comment, skip it
} elsif (m/\s*tcp_/) {
# netdomain rules are unenforced, skip it
} elsif (m/\s*udp_/) {
# netdomain rules are unenforced, skip it
} elsif (m/\S+/) {
$linecount++;
}
}
close FH;
$count_cache{$name} = $linecount;
return $linecount;
}
# given a single line from a profile, perform some search/replace
# operations to reflect new locations for old files.
#
# change #include lines that reference files in the @useless array:
# don't print the #include any more, and either suck in the contents of
# the referenced file (calling itself recursively to fix up _those_
# files) or just leave well enough alone, if the file had no
# 'interesting' lines as defined above.
%transforms = (
# renamed around SuSE 9.3
"abstractions/kde3" => "abstractions/kde",
"abstractions/user-GTK" => "abstractions/gnome",
"abstractions/user-Xauthority" => "abstractions/X",
# user-custom -> program-chunks around SHASS 1.1, but these changed dirs
"user-custom/fonts" => "abstractions/fonts",
"user-custom/kde3" => "abstractions/kde",
"user-custom/user-GTK" => "abstractions/gnome",
"user-custom/user-mail" => "abstractions/user-mail",
"user-custom/user-manpages" => "abstractions/user-manpages",
"user-custom/user-Xauthority" => "abstractions/X",
"user-custom/user-tmp" => "abstractions/user-tmp",
# try to forget the -files
"program-chunks/base-files" => "abstractions/base",
"program-chunks/nameservice-files" => "abstractions/nameservice",
"immunix-standard/base-files" => "abstractions/base",
"immunix-standard/nameservice-files" => "abstractions/nameservice",
# immunix-standard -> program-chunks
"immunix-standard/postfix-bounce" => "program-chunks/postfix-bounce",
"immunix-standard/postfix-cleanup" => "program-chunks/postfix-cleanup",
"immunix-standard/postfix-common" => "program-chunks/postfix-common",
"immunix-standard/postfix-flush" => "program-chunks/postfix-flush",
"immunix-standard/postfix-local" => "program-chunks/postfix-local",
"immunix-standard/postfix-master" => "program-chunks/postfix-master",
"immunix-standard/postfix-nqmgr" => "program-chunks/postfix-nqmgr",
"immunix-standard/postfix-pickup" => "program-chunks/postfix-pickup",
"immunix-standard/postfix-proxymap" => "program-chunks/postfix-proxymap",
"immunix-standard/postfix-qmgr" => "program-chunks/postfix-qmgr",
"immunix-standard/postfix-showq" => "program-chunks/postfix-showq",
"immunix-standard/postfix-smtp" => "program-chunks/postfix-smtp",
"immunix-standard/postfix-smtpd" => "program-chunks/postfix-smtpd",
"immunix-standard/postfix-trivial-rewrite" => "program-chunks/postfix-trivial-rewrite",
"immunix-standard/apache-default-uri" => "program-chunks/apache-default-uri",
"immunix-standard/at" => "program-chunks/at",
);
# chunks that immunix tools never populated -- lets remove the ones that
# don't have any useful information
my @useless = qw{
program-chunks/base-nd
program-chunks/portmap-nd
program-chunks/postfix-local-nd
program-chunks/postfix-master-nd
program-chunks/postfix-proxymap-nd
program-chunks/postfix-smtpd-nd
program-chunks/postfix-smtp-nd
user-custom/base-nd
user-custom/portmap-nd
user-custom/postfix-local-nd
user-custom/postfix-master-nd
user-custom/postfix-proxymap-nd
user-custom/postfix-smtpd-nd
user-custom/postfix-smtp-nd
immunix-standard/base-nd
immunix-standard/portmap-nd
immunix-standard/postfix-local-nd
immunix-standard/postfix-master-nd
immunix-standard/postfix-proxymap-nd
immunix-standard/postfix-smtpd-nd
immunix-standard/postfix-smtp-nd
program-chunks/at
program-chunks/fam
program-chunks/httpd
program-chunks/identd
program-chunks/imapd
program-chunks/ipop2d
program-chunks/ipop3d
program-chunks/lpd
program-chunks/mutt
program-chunks/named
program-chunks/nmbd
program-chunks/ntalkd
program-chunks/ntpd
program-chunks/postgres
program-chunks/rpc.lockd
program-chunks/rpc.nfsd
program-chunks/rpc.statd
program-chunks/samba
program-chunks/sendmail.sendmail
program-chunks/shells
program-chunks/slocate
program-chunks/snmpd
program-chunks/spamc
program-chunks/sshd
program-chunks/swat
program-chunks/syslogd
program-chunks/talk
program-chunks/xfs
};
# create an alternation to speed up the regexp below
my $useless = join('|', @useless);
sub fixup ($) {
$line = $_[0];
$line =~ s/#include\s+<([^>]+)>/$i = (exists $transforms{$1}) ? $transforms{$1} : "$1"; "#include <$i>"/e;
if ($line =~ m/\s*#include\s+<($useless)>/) {
my $file = $1;
if (numlines("/etc/subdomain.d/$file") > 0) {
my $succ = open INC, "/etc/subdomain.d/$file";
if (not $succ) {
print STDERR "Error opening /etc/subdomain.d/$file\n";
} else {
while(my $included_line = <INC>) {
print fixup_loop($included_line);
}
close INC;
}
}
$line = ""; # this line has been handled by the file
}
return $line;
}
# call fixup on a single entry repeatedly -- this way, we can encode
# 'small' changes in the fixup routine when they are made, rather than
# encoding all possible starting points and which specific end point
# they should go to.
sub fixup_loop ($) {
my $line = $_[0];
my $saved;
do {
$saved = $line;
$line = fixup($saved);
} until ($line eq $saved);
return $line;
}
# main entry point; fix each line in every file in argv.
while(<>) {
print fixup_loop($_);
}

25
documentation/logo/README Normal file
View File

@@ -0,0 +1,25 @@
The apparmor logo (logo-default-red.svg) was created by Noah Davis and
released under the LGPL (licence included below).
Logo variants and uses:
logo-default-red.svg - default logo and coloration used for the apparmor
project. Created for larger (64x64) uses.
Not optimized for small 16x16 tiles.
License
* Copyright (c) 2018 Noah Davis <noahadvs@gmail.com>
*
* The appaprmor logo is licensed under the terms of the GNU
* Lesser General Public License, version 2.1. Please see the file
* COPYING.LGPL.
*
* This logo file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.

View File

@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg height="64" width="64" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><linearGradient id="a" gradientUnits="userSpaceOnUse" x1="55" x2="55" xlink:href="#j" y1="54" y2="9"/><linearGradient id="b"><stop offset="0" stop-color="#bf4231"/><stop offset="1" stop-color="#e05e4c"/></linearGradient><linearGradient id="c" gradientUnits="userSpaceOnUse" x1="32" x2="32" y1="58" y2="6"><stop offset="0" stop-color="#173f4f"/><stop offset="1" stop-color="#2f5361"/></linearGradient><linearGradient id="d" gradientUnits="userSpaceOnUse" x1="55" x2="55" xlink:href="#b" y1="54" y2="9"/><linearGradient id="e" gradientUnits="userSpaceOnUse" x1="20" x2="45" xlink:href="#k" y1="22" y2="47"/><linearGradient id="f" gradientUnits="userSpaceOnUse" x1="37" x2="37" y1="46" y2="38"><stop offset="0" stop-color="#be4434"/><stop offset=".25" stop-color="#c44837"/><stop offset="1" stop-color="#cb4c3b"/></linearGradient><linearGradient id="g" gradientUnits="userSpaceOnUse" x1="26" x2="50" xlink:href="#k" y1="16" y2="40"/><linearGradient id="h" gradientUnits="userSpaceOnUse" x1="40" x2="47" xlink:href="#k" y1="38" y2="45"/><linearGradient id="i" gradientUnits="userSpaceOnUse" x1="43" x2="46" xlink:href="#k" y1="44" y2="47"/><linearGradient id="j"><stop offset="0" stop-color="#eff0f1"/><stop offset="1" stop-color="#fcfcfc"/></linearGradient><linearGradient id="k"><stop offset="0" stop-color="#292c2f"/><stop offset="1" stop-opacity="0"/></linearGradient><linearGradient id="l" gradientUnits="userSpaceOnUse" x1="32" x2="32" xlink:href="#j" y1="54" y2="9"/><linearGradient id="m" gradientUnits="userSpaceOnUse" x1="32" x2="32" xlink:href="#b" y1="54" y2="9"/><path d="m32 6c-6.33333 3.35447-12.66667 4.72491-19 6v25.001953c0 7 10.26331 16.561337 19 20.998047 8.73669-4.43671 19-13.998047 19-20.998047v-25.001953c-6.33333-1.27509-12.66667-2.64553-19-6z" fill="url(#c)" stroke-linecap="square" stroke-width="2"/><path d="m13 36.001953v1c0 7 10.26331 16.561337 19 20.998047 8.73669-4.43671 19-13.998047 19-20.998047v-1c0 7-10.26331 16.561337-19 20.998047-8.73669-4.43671-19-13.998047-19-20.998047z" fill="#292c2f" opacity=".2" stroke-linecap="square" stroke-width="2"/><path d="m48 14-26.304688 32.304688 11.208985 11.208984c8.525508-4.614773 18.095703-13.751033 18.095703-20.511719v-20.001953z" fill="url(#i)" opacity=".2"/><path d="m40.824219 12.349609-17.617188 35.238282c2.735569 2.548653 5.806349 4.895376 8.792969 6.412109 7.392765-3.754157 16-12.076982 16-18v-22c-2.403402-.483885-4.789398-1.006952-7.175781-1.650391z" fill="url(#d)"/><path d="m32 9c-5.358808 2.838395-10.64102 3.921074-16 5v22c0 3.530034 3.17163 7.828219 7.207031 11.587891l17.617188-35.238282c-2.934573-.791246-5.868718-1.784199-8.824219-3.349609z" fill="url(#a)"/><path d="m24 14-8 16 20.935547 20.935547c1.522034-1.10756 3.001377-2.336903 4.361328-3.638672l-1.296875-1.296875-7-14z" fill="url(#e)" opacity=".2"/><path d="m28 14 12 32 8-16h-4z" fill="url(#g)" opacity=".2"/><g stroke-width="1.857143"><path d="m24 14 16 32 8-16h-4l-1 2h-6l-9-18zm14 20h4l-2 4z" fill="url(#l)"/><path d="m24 14-8 16h4l1-2h6l8.5 17.000001h4zm0 8 2 4h-4z" fill="url(#m)"/><path d="m32 38 4 8h4l-4-8z" fill="url(#f)"/></g><path d="m48 30-8 16 3.617188 3.617188c4.013144-3.887728 7.018045-8.222958 7.351562-11.9375.019301-.229864.03125-.456776.03125-.677735v-4.001953z" fill="url(#h)" opacity=".2"/></svg>

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@@ -0,0 +1,249 @@
From 02e2bc1b330f7e15dba671547a256a6f900f6e5d Mon Sep 17 00:00:00 2001
From: John Johansen <john.johansen@canonical.com>
Date: Sun, 17 Jun 2018 03:56:25 -0700
Subject: [PATCH 1/3] apparmor: patch to provide compatibility with v2.x net
rules
The networking rules upstreamed in 4.17 have a deliberate abi break
with the older 2.x network rules.
This patch provides compatibility with the older rules for those
still using an apparmor 2.x userspace and still want network rules
to work on a newer kernel.
Signed-off-by: John Johansen <john.johansen@canonical.com>
---
security/apparmor/apparmorfs.c | 1 +
security/apparmor/include/apparmor.h | 2 +-
security/apparmor/include/net.h | 11 ++++++++
security/apparmor/include/policy.h | 2 ++
security/apparmor/net.c | 31 ++++++++++++++++-----
security/apparmor/policy.c | 1 +
security/apparmor/policy_unpack.c | 54 ++++++++++++++++++++++++++++++++++--
7 files changed, 92 insertions(+), 10 deletions(-)
diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
index 1fdcc7d5a977..32f0e660ffd0 100644
--- a/security/apparmor/apparmorfs.c
+++ b/security/apparmor/apparmorfs.c
@@ -2272,6 +2272,7 @@ static struct aa_sfs_entry aa_sfs_entry_features[] = {
AA_SFS_DIR("domain", aa_sfs_entry_domain),
AA_SFS_DIR("file", aa_sfs_entry_file),
AA_SFS_DIR("network_v8", aa_sfs_entry_network),
+ AA_SFS_DIR("network", aa_sfs_entry_network_compat),
AA_SFS_DIR("mount", aa_sfs_entry_mount),
AA_SFS_DIR("namespaces", aa_sfs_entry_ns),
AA_SFS_FILE_U64("capability", VFS_CAP_FLAGS_MASK),
diff --git a/security/apparmor/include/apparmor.h b/security/apparmor/include/apparmor.h
index 73d63b58d875..17d89f3badc6 100644
--- a/security/apparmor/include/apparmor.h
+++ b/security/apparmor/include/apparmor.h
@@ -24,7 +24,7 @@
#define AA_CLASS_UNKNOWN 1
#define AA_CLASS_FILE 2
#define AA_CLASS_CAP 3
-#define AA_CLASS_DEPRECATED 4
+#define AA_CLASS_NET_COMPAT 4
#define AA_CLASS_RLIMITS 5
#define AA_CLASS_DOMAIN 6
#define AA_CLASS_MOUNT 7
diff --git a/security/apparmor/include/net.h b/security/apparmor/include/net.h
index ec7228e857a9..579b59a40ea4 100644
--- a/security/apparmor/include/net.h
+++ b/security/apparmor/include/net.h
@@ -72,6 +72,16 @@ struct aa_sk_ctx {
DEFINE_AUDIT_NET(NAME, OP, SK, (SK)->sk_family, (SK)->sk_type, \
(SK)->sk_protocol)
+/* struct aa_net - network confinement data
+ * @allow: basic network families permissions
+ * @audit: which network permissions to force audit
+ * @quiet: which network permissions to quiet rejects
+ */
+struct aa_net_compat {
+ u16 allow[AF_MAX];
+ u16 audit[AF_MAX];
+ u16 quiet[AF_MAX];
+};
#define af_select(FAMILY, FN, DEF_FN) \
({ \
@@ -84,6 +94,7 @@ struct aa_sk_ctx {
})
extern struct aa_sfs_entry aa_sfs_entry_network[];
+extern struct aa_sfs_entry aa_sfs_entry_network_compat[];
void audit_net_cb(struct audit_buffer *ab, void *va);
int aa_profile_af_perm(struct aa_profile *profile, struct common_audit_data *sa,
diff --git a/security/apparmor/include/policy.h b/security/apparmor/include/policy.h
index 6c93e62383e6..4006fa9fc9f1 100644
--- a/security/apparmor/include/policy.h
+++ b/security/apparmor/include/policy.h
@@ -112,6 +112,7 @@ struct aa_data {
* @policy: general match rules governing policy
* @file: The set of rules governing basic file access and domain transitions
* @caps: capabilities for the profile
+ * @net_compat: v2 compat network controls for the profile
* @rlimits: rlimits for the profile
*
* @dents: dentries for the profiles file entries in apparmorfs
@@ -149,6 +150,7 @@ struct aa_profile {
struct aa_policydb policy;
struct aa_file_rules file;
struct aa_caps caps;
+ struct aa_net_compat *net_compat;
int xattr_count;
char **xattrs;
diff --git a/security/apparmor/net.c b/security/apparmor/net.c
index bb24cfa0a164..bf6aaefc3a5f 100644
--- a/security/apparmor/net.c
+++ b/security/apparmor/net.c
@@ -27,6 +27,11 @@ struct aa_sfs_entry aa_sfs_entry_network[] = {
{ }
};
+struct aa_sfs_entry aa_sfs_entry_network_compat[] = {
+ AA_SFS_FILE_STRING("af_mask", AA_SFS_AF_MASK),
+ { }
+};
+
static const char * const net_mask_names[] = {
"unknown",
"send",
@@ -119,14 +124,26 @@ int aa_profile_af_perm(struct aa_profile *profile, struct common_audit_data *sa,
if (profile_unconfined(profile))
return 0;
state = PROFILE_MEDIATES(profile, AA_CLASS_NET);
- if (!state)
+ if (state) {
+ if (!state)
+ return 0;
+ buffer[0] = cpu_to_be16(family);
+ buffer[1] = cpu_to_be16((u16) type);
+ state = aa_dfa_match_len(profile->policy.dfa, state,
+ (char *) &buffer, 4);
+ aa_compute_perms(profile->policy.dfa, state, &perms);
+ } else if (profile->net_compat) {
+ /* 2.x socket mediation compat */
+ perms.allow = (profile->net_compat->allow[family] & (1 << type)) ?
+ ALL_PERMS_MASK : 0;
+ perms.audit = (profile->net_compat->audit[family] & (1 << type)) ?
+ ALL_PERMS_MASK : 0;
+ perms.quiet = (profile->net_compat->quiet[family] & (1 << type)) ?
+ ALL_PERMS_MASK : 0;
+
+ } else {
return 0;
-
- buffer[0] = cpu_to_be16(family);
- buffer[1] = cpu_to_be16((u16) type);
- state = aa_dfa_match_len(profile->policy.dfa, state, (char *) &buffer,
- 4);
- aa_compute_perms(profile->policy.dfa, state, &perms);
+ }
aa_apply_modes_to_perms(profile, &perms);
return aa_check_perms(profile, &perms, request, sa, audit_net_cb);
diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
index c07493ce2376..d1a869699040 100644
--- a/security/apparmor/policy.c
+++ b/security/apparmor/policy.c
@@ -227,6 +227,7 @@ void aa_free_profile(struct aa_profile *profile)
aa_free_file_rules(&profile->file);
aa_free_cap_rules(&profile->caps);
aa_free_rlimit_rules(&profile->rlimits);
+ kzfree(profile->net_compat);
for (i = 0; i < profile->xattr_count; i++)
kzfree(profile->xattrs[i]);
diff --git a/security/apparmor/policy_unpack.c b/security/apparmor/policy_unpack.c
index b9e6b2cafa69..a1b07e6c163d 100644
--- a/security/apparmor/policy_unpack.c
+++ b/security/apparmor/policy_unpack.c
@@ -37,7 +37,7 @@
#define v5 5 /* base version */
#define v6 6 /* per entry policydb mediation check */
-#define v7 7
+#define v7 7 /* v2 compat networking */
#define v8 8 /* full network masking */
/*
@@ -292,6 +292,19 @@ static bool unpack_nameX(struct aa_ext *e, enum aa_code code, const char *name)
return 0;
}
+static bool unpack_u16(struct aa_ext *e, u16 *data, const char *name)
+{
+ if (unpack_nameX(e, AA_U16, name)) {
+ if (!inbounds(e, sizeof(u16)))
+ return 0;
+ if (data)
+ *data = le16_to_cpu(get_unaligned((__le16 *) e->pos));
+ e->pos += sizeof(u16);
+ return 1;
+ }
+ return 0;
+}
+
static bool unpack_u32(struct aa_ext *e, u32 *data, const char *name)
{
if (unpack_nameX(e, AA_U32, name)) {
@@ -621,7 +634,7 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
struct aa_profile *profile = NULL;
const char *tmpname, *tmpns = NULL, *name = NULL;
const char *info = "failed to unpack profile";
- size_t ns_len;
+ size_t size = 0, ns_len;
struct rhashtable_params params = { 0 };
char *key = NULL;
struct aa_data *data;
@@ -759,6 +772,43 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
goto fail;
}
+ size = unpack_array(e, "net_allowed_af");
+ if (size || VERSION_LT(e->version, v8)) {
+ profile->net_compat = kzalloc(sizeof(struct aa_net_compat), GFP_KERNEL);
+ if (!profile->net_compat) {
+ info = "out of memory";
+ goto fail;
+ }
+ for (i = 0; i < size; i++) {
+ /* discard extraneous rules that this kernel will
+ * never request
+ */
+ if (i >= AF_MAX) {
+ u16 tmp;
+
+ if (!unpack_u16(e, &tmp, NULL) ||
+ !unpack_u16(e, &tmp, NULL) ||
+ !unpack_u16(e, &tmp, NULL))
+ goto fail;
+ continue;
+ }
+ if (!unpack_u16(e, &profile->net_compat->allow[i], NULL))
+ goto fail;
+ if (!unpack_u16(e, &profile->net_compat->audit[i], NULL))
+ goto fail;
+ if (!unpack_u16(e, &profile->net_compat->quiet[i], NULL))
+ goto fail;
+ }
+ if (size && !unpack_nameX(e, AA_ARRAYEND, NULL))
+ goto fail;
+ if (VERSION_LT(e->version, v7)) {
+ /* pre v7 policy always allowed these */
+ profile->net_compat->allow[AF_UNIX] = 0xffff;
+ profile->net_compat->allow[AF_NETLINK] = 0xffff;
+ }
+ }
+
+
if (unpack_nameX(e, AA_STRUCT, "policydb")) {
/* generic policy dfa - optional and may be NULL */
info = "failed to unpack policydb";
--
2.14.1

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,57 @@
From 45ff74bd5a009ab8f9648531fa11fce55b9a67fd Mon Sep 17 00:00:00 2001
From: John Johansen <john.johansen@canonical.com>
Date: Tue, 26 Jun 2018 20:19:19 -0700
Subject: [PATCH 3/3] apparmor: fix use after free in sk_peer_label
BugLink: http://bugs.launchpad.net/bugs/1778646
Signed-off-by: John Johansen <john.johansen@canonical.com>
---
security/apparmor/lsm.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index 7a6b1bd8e046..0d2925389947 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -1125,9 +1125,10 @@ static struct aa_label *sk_peer_label(struct sock *sk)
{
struct sock *peer_sk;
struct aa_sk_ctx *ctx = SK_CTX(sk);
+ struct aa_label *label = ERR_PTR(-ENOPROTOOPT);
if (ctx->peer)
- return ctx->peer;
+ return aa_get_label(ctx->peer);
if (sk->sk_family != PF_UNIX)
return ERR_PTR(-ENOPROTOOPT);
@@ -1135,14 +1136,15 @@ static struct aa_label *sk_peer_label(struct sock *sk)
/* check for sockpair peering which does not go through
* security_unix_stream_connect
*/
- peer_sk = unix_peer(sk);
+ peer_sk = unix_peer_get(sk);
if (peer_sk) {
ctx = SK_CTX(peer_sk);
if (ctx->label)
- return ctx->label;
+ label = aa_get_label(ctx->label);
+ sock_put(peer_sk);
}
- return ERR_PTR(-ENOPROTOOPT);
+ return label;
}
/**
@@ -1186,6 +1188,7 @@ static int apparmor_socket_getpeersec_stream(struct socket *sock,
}
+ aa_put_label(peer);
done:
end_current_label_crit_section(label);
--
2.14.1

View File

@@ -1,3 +1,3 @@
What little documentation exists is in src/aalogparse.h.
What little documentation exists is in include/aalogparse.h.
Please file bugs using https://bugs.launchpad.net/apparmor/+filebug
Please file bugs using https://gitlab.com/apparmor/apparmor/-/issues

View File

@@ -42,11 +42,11 @@ AC_ARG_WITH(python,
[AC_MSG_RESULT($withval)], [AC_MSG_RESULT(no)])
if test "$with_python" = "yes"; then
test -z "$SWIG" && AC_MSG_ERROR([swig is required when enabling python bindings])
AC_PATH_PROG(PYTHON, python)
AC_PATH_PROG(PYTHON, python3)
test -z "$PYTHON" && AC_MSG_ERROR([python is required when enabling python bindings])
sinclude(m4/ac_python_devel.m4)
AC_PYTHON_DEVEL
AM_PATH_PYTHON
AM_PATH_PYTHON([3.0])
fi
AC_MSG_CHECKING([whether perl bindings are enabled])
@@ -58,7 +58,7 @@ if test "$with_perl" = "yes"; then
AC_PATH_PROG(PERL, perl)
test -z "$PERL" && AC_MSG_ERROR([perl is required when enabling perl bindings])
perl_includedir="`$PERL -e 'use Config; print $Config{archlib}'`/CORE"
AC_CHECK_FILE($perl_includedir/perl.h, enable_perl=yes, enable_perl=no)
AS_IF([test -e "$perl_includedir/perl.h"], enable_perl=yes, enable_perl=no)
fi
@@ -81,7 +81,7 @@ AM_CONDITIONAL(HAVE_RUBY, test x$with_ruby = xyes)
AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h stdint.h syslog.h)
AC_CHECK_FUNCS([asprintf __secure_getenv secure_getenv])
AC_CHECK_FUNCS([asprintf __secure_getenv secure_getenv reallocarray])
AM_PROG_CC_C_O
AC_C_CONST

View File

@@ -137,11 +137,11 @@ First, a simple high-level overview of aa_change_hat() use:
void foo (void) {
unsigned long magic_token;
/* get a random magic token value
from our huge entropy pool */
magic_token = random_function();
/* change into the subprofile while
* we do stuff we don't trust */
aa_change_hat("stuff_we_dont_trust", magic_token);
@@ -166,20 +166,20 @@ aren't accessible after an aa_change_hat() call:
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
int fd;
unsigned long tok;
char buf[10];
/* random() is a poor choice */
tok = random();
/* open /etc/passwd outside of any hat */
if ((fd=open("/etc/passwd", O_RDONLY)) < 0)
perror("Failure opening /etc/passwd");
/* confirm for ourselves that we can really read /etc/passwd */
memset(&buf, 0, 10);
if (read(fd, &buf, 10) == -1) {
@@ -188,7 +188,7 @@ aren't accessible after an aa_change_hat() call:
}
buf[9] = '\0';
printf("/etc/passwd: %s\n", buf);
/* change hat to the "hat" subprofile, which should not have
* read access to /etc/passwd -- even though we have a valid
* file descriptor at the time of the aa_change_hat() call. */
@@ -196,7 +196,7 @@ aren't accessible after an aa_change_hat() call:
perror("Failure changing hat -- aborting");
_exit(1);
}
/* confirm that we cannot read /etc/passwd */
lseek(fd,0,SEEK_SET);
memset(&buf, 0, 10);
@@ -204,7 +204,7 @@ aren't accessible after an aa_change_hat() call:
perror("Failure reading /etc/passwd post-hat");
buf[9] = '\0';
printf("/etc/passwd: %s\n", buf);
return 0;
}
@@ -248,7 +248,7 @@ The output when run:
=head1 BUGS
None known. If you find any, please report them at
L<https://bugs.launchpad.net/apparmor/+filebug>. Note that
L<https://gitlab.com/apparmor/apparmor/-/issues>. Note that
aa_change_hat(2) provides no memory barriers between different areas of a
program; if address space separation is required, then separate processes
should be used.
@@ -257,6 +257,6 @@ should be used.
apparmor(7), apparmor.d(5), apparmor_parser(8), aa_change_profile(2),
aa_getcon(2) and
L<http://wiki.apparmor.net>.
L<https://wiki.apparmor.net>.
=cut

View File

@@ -196,7 +196,7 @@ used (in addition to the one for 'i_cant_be_trusted_anymore', above):
=head1 BUGS
None known. If you find any, please report them at
L<https://bugs.launchpad.net/apparmor/+filebug>. Note that using
L<https://gitlab.com/apparmor/apparmor/-/issues>. Note that using
aa_change_profile(2) without execve(2) provides no memory barriers between
different areas of a program; if address space separation is required, then
separate processes should be used.
@@ -204,6 +204,6 @@ separate processes should be used.
=head1 SEE ALSO
apparmor(7), apparmor.d(5), apparmor_parser(8), aa_change_hat(2) and
L<http://wiki.apparmor.net>.
L<https://wiki.apparmor.net>.
=cut

View File

@@ -34,6 +34,8 @@ aa_features_ref - increments the ref count of an aa_features object
aa_features_unref - decrements the ref count and frees the aa_features object when 0
aa_features_write_to_fd - write a string representation of an aa_features object to a file descriptor
aa_features_write_to_file - write a string representation of an aa_features object to a file
aa_features_is_equal - equality test for two aa_features objects
@@ -42,6 +44,8 @@ aa_features_supports - provides aa_features object support status
aa_features_id - provides unique identifier for an aa_features object
aa_features_value - the value associated with a given feature.
=head1 SYNOPSIS
B<#include E<lt>sys/apparmor.hE<gt>>
@@ -50,6 +54,8 @@ B<typedef struct aa_features aa_features;>
B<int aa_features_new(aa_features **features, int dirfd, const char *path);>
B<int aa_features_new_from_file(aa_features **features, int fd);>
B<int aa_features_new_from_string(aa_features **features, const char *string, size_t size);>
B<int aa_features_new_from_kernel(aa_features **features);>
@@ -58,6 +64,8 @@ B<aa_features *aa_features_ref(aa_features *features);>
B<void aa_features_unref(aa_features *features);>
B<int aa_features_write_to_fd(aa_features *features, int fd);>
B<int aa_features_write_to_file(aa_features *features, int dirfd, const char *path);>
B<bool aa_features_is_equal(aa_features *features1, aa_features *features2);>
@@ -66,6 +74,8 @@ B<bool aa_features_supports(aa_features *features, const char *str);>
B<char *aa_features_id(aa_features *features);>
B<char *aa_features_value(aa_features *features, const char *str, size_t *len);>
Link with B<-lapparmor> when compiling.
=head1 DESCRIPTION
@@ -82,6 +92,10 @@ directory file descriptor and path. The I<path> can point to a file or
directory. See the openat(2) man page for examples of I<dirfd> and I<path>. The
allocated I<features> object must be freed using aa_features_unref().
The aa_features_new_from_file() function is similar except that it
accepts an open file as the argument. The allocated I<features> object
must be freed using aa_features_unref().
The aa_features_new_from_string() function is similar except that it accepts a
NUL-terminated string representation of the AppArmor features as the I<string>
argument. The length of the features string, not counting the NUL-terminator,
@@ -97,6 +111,9 @@ aa_features_ref() increments the reference count on the I<features> object.
aa_features_unref() decrements the reference count on the I<features> object
and releases all corresponding resources when the reference count reaches zero.
The aa_features_write_to_fd() function writes a string representation of the
I<features> object to the file descriptor specified by the I<fd>.
The aa_features_write_to_file() function writes a string representation of the
I<features> object to the file specified by the I<dirfd> and I<path>
combination.
@@ -140,6 +157,11 @@ aa_features_id() returns a string identifying I<features> which must be
freed by the caller. NULL is returned on error, with errno set
appropriately.
aa_features_value() returns a null terminated string with is
associated length which must be freed by the caller. NULL is returned
on error, with errno set to ENOENT if the feature was not found,
ENODIR if the specified feature does not resolve to a leaf feature.
=head1 ERRORS
The errno value will be set according to the underlying error in the
@@ -157,10 +179,10 @@ before exiting in libapparmor version 2.12 and newer.
=head1 BUGS
None known. If you find any, please report them at
L<https://bugs.launchpad.net/apparmor/+filebug>.
L<https://gitlab.com/apparmor/apparmor/-/issues>.
=head1 SEE ALSO
openat(2) and L<http://wiki.apparmor.net>.
openat(2), aa-features-abi(1) and L<https://wiki.apparmor.net>.
=cut

View File

@@ -70,6 +70,10 @@ AppArmor extensions to the system are not available.
AppArmor is available on the system but has been disabled at boot.
=item B<EBUSY>
AppArmor is available but only via private interfaces.
=item B<ENOENT>
AppArmor is available (and maybe even enforcing policy) but the interface is
@@ -87,6 +91,11 @@ Did not have sufficient permissions to determine if AppArmor is enabled.
Did not have sufficient permissions to determine if AppArmor is enabled.
=item B<EBUSY>
AppArmor is enabled but does not have access to shared interfaces, and
only private interfaces are available.
=back
B<aa_find_mountpoint>
@@ -110,11 +119,11 @@ The apparmor filesystem mount could not be found
=head1 BUGS
None known. If you find any, please report them at
L<https://bugs.launchpad.net/apparmor/+filebug>.
L<https://gitlab.com/apparmor/apparmor/-/issues>.
=head1 SEE ALSO
apparmor(7), apparmor.d(5), apparmor_parser(8), and
L<http://wiki.apparmor.net>.
L<https://wiki.apparmor.net>.
=cut

View File

@@ -127,11 +127,11 @@ confinement data.
=head1 BUGS
None known. If you find any, please report them at
L<https://bugs.launchpad.net/apparmor/+filebug>.
L<https://gitlab.com/apparmor/apparmor/-/issues>.
=head1 SEE ALSO
apparmor(7), apparmor.d(5), apparmor_parser(8), aa_change_profile(2),
aa_splitcon(3) and L<http://wiki.apparmor.net>.
aa_splitcon(3) and L<https://wiki.apparmor.net>.
=cut

View File

@@ -156,10 +156,10 @@ errno before exiting in libapparmor version 2.12 and newer.
=head1 BUGS
None known. If you find any, please report them at
L<https://bugs.launchpad.net/apparmor/+filebug>.
L<https://gitlab.com/apparmor/apparmor/-/issues>.
=head1 SEE ALSO
aa_features(3), openat(2) and L<http://wiki.apparmor.net>.
aa_features(3), openat(2) and L<https://wiki.apparmor.net>.
=cut

View File

@@ -125,7 +125,7 @@ layer. Binary policy cache files will be located in the directory
returned by this function.
The aa_policy_cache_dir_levels() function provides access to the number
of directories that are being overlayed to create the policy cache.
of directories that are being overlaid to create the policy cache.
=head1 RETURN VALUE
@@ -170,11 +170,11 @@ before exiting in libapparmor version 2.12 and newer.
=head1 BUGS
None known. If you find any, please report them at
L<https://bugs.launchpad.net/apparmor/+filebug>.
L<https://gitlab.com/apparmor/apparmor/-/issues>.
=head1 SEE ALSO
aa_features(3), aa_kernel_interface(3), openat(2) and
L<http://wiki.apparmor.net>.
L<https://wiki.apparmor.net>.
=cut

View File

@@ -123,11 +123,11 @@ query and can change at any point in the future.
=head1 BUGS
None known. If you find any, please report them at
L<https://bugs.launchpad.net/apparmor/+filebug>.
L<https://gitlab.com/apparmor/apparmor/-/issues>.
=head1 SEE ALSO
apparmor(7), apparmor.d(5), apparmor_parser(8), aa_getcon(2), aa_splitcon(3)
and L<http://wiki.apparmor.net>.
and L<https://wiki.apparmor.net>.
=cut

View File

@@ -63,10 +63,10 @@ on error.
=head1 BUGS
None known. If you find any, please report them at
L<https://bugs.launchpad.net/apparmor/+filebug>.
L<https://gitlab.com/apparmor/apparmor/-/issues>.
=head1 SEE ALSO
aa_getcon(2) and L<http://wiki.apparmor.net>.
aa_getcon(2) and L<https://wiki.apparmor.net>.
=cut

View File

@@ -137,12 +137,12 @@ aa_stack_profile().
{
int fd;
char buf[10];
if ((fd=open("/etc/passwd", O_RDONLY)) < 0) {
perror("Failure opening /etc/passwd");
_exit(1);
}
/* Verify that we can read /etc/passwd */
memset(&buf, 0, 10);
if (read(fd, &buf, 10) == -1) {
@@ -153,19 +153,19 @@ aa_stack_profile().
printf("/etc/passwd: %s\n", buf);
close(fd);
}
int main(int argc, char * argv[])
{
printf("Before aa_stack_profile():\n");
read_passwd();
/* stack the "i_cant_be_trusted_anymore" profile, which
* should not have read access to /etc/passwd. */
if (aa_stack_profile("i_cant_be_trusted_anymore") < 0) {
perror("Failure changing profile -- aborting");
_exit(1);
}
printf("After aa_stack_profile():\n");
read_passwd();
_exit(0);
@@ -208,7 +208,7 @@ The output when run:
=head1 BUGS
None known. If you find any, please report them at
L<https://bugs.launchpad.net/apparmor/+filebug>. Note that using
L<https://gitlab.com/apparmor/apparmor/-/issues>. Note that using
aa_stack_profile(2) without execve(2) provides no memory barriers between
different areas of a program; if address space separation is required, then
separate processes should be used.
@@ -216,6 +216,6 @@ separate processes should be used.
=head1 SEE ALSO
apparmor(7), apparmor.d(5), apparmor_parser(8), aa_change_profile(2),
aa_getcon(2) and L<http://wiki.apparmor.net>.
aa_getcon(2) and L<https://wiki.apparmor.net>.
=cut

View File

@@ -159,6 +159,8 @@ typedef struct
char *fs_type;
char *flags;
char *src_name;
char *class;
} aa_log_record;
/**

View File

@@ -20,6 +20,8 @@
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#ifdef __cplusplus
@@ -68,7 +70,7 @@ extern int aa_is_enabled(void);
extern int aa_find_mountpoint(char **mnt);
/* Prototypes for self directed domain transitions
* see <http://apparmor.net>
* see <https://apparmor.net>
* Please see the change_hat(2) manpage for information.
*/
@@ -93,7 +95,7 @@ extern int aa_getprocattr(pid_t tid, const char *attr, char **label,
char **mode);
extern int aa_gettaskcon(pid_t target, char **label, char **mode);
extern int aa_getcon(char **label, char **mode);
extern int aa_getpeercon_raw(int fd, char *buf, int *len, char **mode);
extern int aa_getpeercon_raw(int fd, char *buf, socklen_t *len, char **mode);
extern int aa_getpeercon(int fd, char **label, char **mode);
/* A NUL character is used to separate the query command prefix string from the
@@ -143,18 +145,21 @@ extern int aa_query_link_path(const char *label, const char *target,
typedef struct aa_features aa_features;
extern int aa_features_new(aa_features **features, int dirfd, const char *path);
extern int aa_features_new_from_file(aa_features **features, int file);
extern int aa_features_new_from_string(aa_features **features,
const char *string, size_t size);
extern int aa_features_new_from_kernel(aa_features **features);
extern aa_features *aa_features_ref(aa_features *features);
extern void aa_features_unref(aa_features *features);
extern int aa_features_write_to_fd(aa_features *features, int fd);
extern int aa_features_write_to_file(aa_features *features,
int dirfd, const char *path);
extern bool aa_features_is_equal(aa_features *features1,
aa_features *features2);
extern bool aa_features_supports(aa_features *features, const char *str);
extern char *aa_features_id(aa_features *features);
extern char *aa_features_value(aa_features *features, const char *str, size_t *len);
typedef struct aa_kernel_interface aa_kernel_interface;
extern int aa_kernel_interface_new(aa_kernel_interface **kernel_interface,

View File

@@ -13,6 +13,11 @@ AC_DEFUN([AC_PYTHON_DEVEL],[
PYTHON_VERSION=""
fi
AC_PATH_TOOL([PYTHON_CONFIG],[`basename [$PYTHON]-config`])
if test -z "$PYTHON_CONFIG"; then
AC_MSG_ERROR([Cannot find python$PYTHON_VERSION-config in your system path])
fi
#
# Check for a version of Python >= 2.1.0
#
@@ -61,17 +66,17 @@ variable to configure. See ``configure --help'' for reference.
fi
#
# Check if you have distutils, else fail
# Check if you have setuptools, else fail
#
AC_MSG_CHECKING([for the distutils Python package])
ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`
if test -z "$ac_distutils_result"; then
AC_MSG_CHECKING([for the setuptools Python package])
ac_setuptools_result=`$PYTHON -c "import setuptools" 2>&1`
if test -z "$ac_setuptools_result"; then
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
AC_MSG_ERROR([cannot import Python module "distutils".
AC_MSG_ERROR([cannot import Python module "setuptools".
Please check your Python installation. The error was:
$ac_distutils_result])
$ac_setuptools_result])
PYTHON_VERSION=""
fi
@@ -79,12 +84,12 @@ $ac_distutils_result])
# Check for Python include path
#
AC_MSG_CHECKING([for Python include path])
if type $PYTHON-config; then
PYTHON_CPPFLAGS=`$PYTHON-config --includes`
if type $PYTHON_CONFIG; then
PYTHON_CPPFLAGS=`$PYTHON_CONFIG --includes`
fi
if test -z "$PYTHON_CPPFLAGS"; then
python_path=`$PYTHON -c "import sys; import distutils.sysconfig;\
sys.stdout.write('%s\n' % distutils.sysconfig.get_python_inc());"`
python_path=`$PYTHON -c "import sys; import sysconfig;\
sys.stdout.write('%s\n' % sysconfig.get_path('include'));"`
if test -n "${python_path}"; then
python_path="-I$python_path"
fi
@@ -97,14 +102,14 @@ sys.stdout.write('%s\n' % distutils.sysconfig.get_python_inc());"`
# Check for Python library path
#
AC_MSG_CHECKING([for Python library path])
if type $PYTHON-config; then
PYTHON_LDFLAGS=`$PYTHON-config --ldflags`
if type $PYTHON_CONFIG; then
PYTHON_LDFLAGS=`$PYTHON_CONFIG --ldflags`
fi
if test -z "$PYTHON_LDFLAGS"; then
# (makes two attempts to ensure we've got a version number
# from the interpreter)
py_version=`$PYTHON -c "import sys; from distutils.sysconfig import *; \
sys.stdout.write('%s\n' % ''.join(get_config_vars('VERSION')))"`
py_version=`$PYTHON -c "import sys; import sysconfig; \
sys.stdout.write('%s\n' % ''.join(sysconfig.get_config_vars('VERSION')))"`
if test "$py_version" == "[None]"; then
if test -n "$PYTHON_VERSION"; then
py_version=$PYTHON_VERSION
@@ -114,8 +119,8 @@ sys.stdout.write("%s\n" % sys.version[[:3]])"`
fi
fi
PYTHON_LDFLAGS=`$PYTHON -c "import sys; from distutils.sysconfig import *; \
sys.stdout.write('-L' + get_python_lib(0,1) + ' -lpython\n')"`$py_version`$PYTHON -c \
PYTHON_LDFLAGS=`$PYTHON -c "import sys; import sysconfig; \
sys.stdout.write('-L' + sysconfig.get_path('stdlib') + ' -lpython\n')"`$py_version`$PYTHON -c \
"import sys; sys.stdout.write('%s' % getattr(sys,'abiflags',''))"`
fi
AC_MSG_RESULT([$PYTHON_LDFLAGS])
@@ -126,8 +131,8 @@ sys.stdout.write('-L' + get_python_lib(0,1) + ' -lpython\n')"`$py_version`$PYTHO
#
AC_MSG_CHECKING([for Python site-packages path])
if test -z "$PYTHON_SITE_PKG"; then
PYTHON_SITE_PKG=`$PYTHON -c "import sys; import distutils.sysconfig; \
sys.stdout.write('%s\n' % distutils.sysconfig.get_python_lib(0,0));"`
PYTHON_SITE_PKG=`$PYTHON -c "import sys; import sysconfig; \
sys.stdout.write('%s\n' % sysconfig.get_path('purelib'));"`
fi
AC_MSG_RESULT([$PYTHON_SITE_PKG])
AC_SUBST([PYTHON_SITE_PKG])
@@ -136,10 +141,14 @@ sys.stdout.write('%s\n' % distutils.sysconfig.get_python_lib(0,0));"`
# libraries which must be linked in when embedding
#
AC_MSG_CHECKING(python extra libraries)
if type $PYTHON_CONFIG; then
PYTHON_EXTRA_LIBS=`$PYTHON_CONFIG --libs --embed` || \
PYTHON_EXTRA_LIBS=''
fi
if test -z "$PYTHON_EXTRA_LIBS"; then
PYTHON_EXTRA_LIBS=`$PYTHON -c "import sys; import distutils.sysconfig; \
conf = distutils.sysconfig.get_config_var; \
sys.stdout.write('%s %s\n' % (conf('LOCALMODLIBS'), conf('LIBS')))"`
PYTHON_EXTRA_LIBS=`$PYTHON -c "import sys; import sysconfig; \
conf = sysconfig.get_config_var; \
sys.stdout.write('%s %s %s\n' % (conf('BLDLIBRARY'), conf('LOCALMODLIBS'), conf('LIBS')))"`
fi
AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
AC_SUBST(PYTHON_EXTRA_LIBS)
@@ -148,9 +157,13 @@ sys.stdout.write('%s %s\n' % (conf('LOCALMODLIBS'), conf('LIBS')))"`
# linking flags needed when embedding
#
AC_MSG_CHECKING(python extra linking flags)
if type $PYTHON_CONFIG; then
PYTHON_EXTRA_LDFLAGS=`$PYTHON_CONFIG --ldflags --embed` || \
PYTHON_EXTRA_LDFLAGS=''
fi
if test -z "$PYTHON_EXTRA_LDFLAGS"; then
PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import sys; import distutils.sysconfig; \
conf = distutils.sysconfig.get_config_var; \
PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import sys; import sysconfig; \
conf = sysconfig.get_config_var; \
sys.stdout.write('%s\n' % conf('LINKFORSHARED'))"`
fi
AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
@@ -164,7 +177,7 @@ sys.stdout.write('%s\n' % conf('LINKFORSHARED'))"`
# save current global flags
ac_save_LIBS="$LIBS"
ac_save_CPPFLAGS="$CPPFLAGS"
LIBS="$ac_save_LIBS $PYTHON_LDFLAGS"
LIBS="$ac_save_LIBS $PYTHON_EXTRA_LIBS $PYTHON_LDFLAGS"
CPPFLAGS="$ac_save_CPPFLAGS $PYTHON_CPPFLAGS"
AC_TRY_LINK([
#include <Python.h>

View File

@@ -11,9 +11,13 @@ INCLUDES = $(all_includes)
# 3. If any interfaces have been added, removed, or changed since the last
# update,
# - increment AA_LIB_CURRENT
# - by 1 if bugfix release
# - by 5 on larger releases. This gives room to fix library interface
# problems in the unlikely event where an interface has to break.
# - set AA_LIB_REVISION to 0.
# 4. If any interfaces have been added since the last public release, then
# - increment AA_LIB_AGE.
# - increment AA_LIB_AGE by the same amount that AA_LIB_CURRENT was
# incremented.
# 5. If any interfaces have been removed or changed since the last public
# release, then
# - set AA_LIB_AGE to 0.
@@ -26,24 +30,30 @@ INCLUDES = $(all_includes)
# For more information, see:
# http://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
#
AA_LIB_CURRENT = 6
AA_LIB_REVISION = 0
AA_LIB_AGE = 5
# After changing the AA_LIB_* variables, also update EXPECTED_SO_NAME.
AA_LIB_CURRENT = 13
AA_LIB_REVISION = 3
AA_LIB_AGE = 12
EXPECTED_SO_NAME = libapparmor.so.1.12.3
SUFFIXES = .pc.in .pc
BUILT_SOURCES = grammar.h scanner.h af_protos.h PMurHash.h
COMMONDIR=$(top_srcdir)/../../common/
include $(COMMONDIR)/Make.rules
BUILT_SOURCES = grammar.h scanner.h af_protos.h
AM_LFLAGS = -v
AM_YFLAGS = -d -p aalogparse_
AM_CFLAGS = -Wall
AM_CFLAGS = -Wall $(EXTRA_WARNINGS) -fPIC -flto-partition=none
AM_CPPFLAGS = -D_GNU_SOURCE -I$(top_srcdir)/include/
scanner.h: scanner.l
$(LEX) -v $<
scanner.c: scanner.l
af_protos.h: /usr/include/netinet/in.h
LC_ALL=C sed -n -e "/IPPROTO_MAX/d" -e "s/^\#define[ \\t]\\+IPPROTO_\\([A-Z0-9_]\\+\\)\\(.*\\)$$/AA_GEN_PROTO_ENT(\\UIPPROTO_\\1, \"\\L\\1\")/p" $< > $@
af_protos.h:
echo '#include <netinet/in.h>' | $(CC) $(CPPFLAGS) -E -dM - | LC_ALL=C sed -n -e "/IPPROTO_MAX/d" -e "s/^\#define[ \\t]\\+IPPROTO_\\([A-Z0-9_]\\+\\)\\(.*\\)$$/AA_GEN_PROTO_ENT(\\UIPPROTO_\\1, \"\\L\\1\")/p" > $@
lib_LTLIBRARIES = libapparmor.la
noinst_HEADERS = grammar.h parser.h scanner.h af_protos.h private.h PMurHash.h
@@ -74,4 +84,8 @@ tst_kernel_LDFLAGS = -pthread
check_PROGRAMS = tst_aalogmisc tst_features tst_kernel
TESTS = $(check_PROGRAMS)
.PHONY: check-local
check-local:
test -f ./.libs/$(EXPECTED_SO_NAME) || { echo '*** unexpected .so name/number for libapparmor (expected $(EXPECTED_SO_NAME), the actual filename is shown below) ***' ; ls -l ./.libs/libapparmor.so.*.* ; exit 1; }
EXTRA_DIST = grammar.y scanner.l libapparmor.map libapparmor.pc

View File

@@ -98,9 +98,8 @@ static int features_snprintf(struct features_struct *fst, const char *fmt, ...)
return 0;
}
/* load_features_file - opens and reads a file into @buffer and then NUL-terminates @buffer
* @dirfd: a directory file descriptory or AT_FDCWD (see openat(2))
* @path: name of the file
/* load_features_file - reads a file into @buffer and then NUL-terminates @buffer
* @file: file to read the features from
* @buffer: the buffer to read the features file into (will be NUL-terminated on success)
* @size: the size of @buffer
*
@@ -110,25 +109,11 @@ static int features_snprintf(struct features_struct *fst, const char *fmt, ...)
* ENOBUFS indicating that @buffer was not large enough to contain all of the
* file contents.
*/
static ssize_t load_features_file(int dirfd, const char *path,
char *buffer, size_t size)
static ssize_t load_features_file(int file, char *buffer, size_t size)
{
autoclose int file = -1;
char *pos = buffer;
ssize_t len;
file = openat(dirfd, path, O_RDONLY);
if (file < 0) {
PDEBUG("Could not open '%s'\n", path);
return -1;
}
PDEBUG("Opened features \"%s\"\n", path);
if (!size) {
errno = ENOBUFS;
return -1;
}
/* Save room for a NUL-terminator at the end of @buffer */
size--;
@@ -151,7 +136,7 @@ static ssize_t load_features_file(int dirfd, const char *path,
if (len > 0)
errno = ENOBUFS;
PDEBUG("Error reading features file '%s': %m\n", path);
PDEBUG("Error reading features file: %m\n");
return -1;
}
@@ -161,6 +146,42 @@ static ssize_t load_features_file(int dirfd, const char *path,
return pos - buffer;
}
/* open_and_load_features_file - opens and reads a file into @buffer and then NUL-terminates @buffer
* @dirfd: a directory file descriptory or AT_FDCWD (see openat(2))
* @path: name of the file
* @buffer: the buffer to read the features file into (will be NUL-terminated on success)
* @size: the size of @buffer
*
* Returns: The number of bytes copied into @buffer on success (not counting
* the NUL-terminator), else -1 and errno is set. Note that @size must be
* larger than the size of the file or -1 will be returned with errno set to
* ENOBUFS indicating that @buffer was not large enough to contain all of the
* file contents.
*/
static ssize_t open_and_load_features_file(int dirfd, const char *path,
char *buffer, size_t size)
{
autoclose int file = -1;
ssize_t rc;
file = openat(dirfd, path, O_RDONLY);
if (file < 0) {
PDEBUG("Could not open '%s': %m\n", path);
return -1;
}
PDEBUG("Opened features '%s': %m\n", path);
if (!size) {
errno = ENOBUFS;
return -1;
}
rc = load_features_file(file, buffer, size);
if (rc == -1)
PDEBUG("Error failed to load features file '%s': %m\n", path);
return rc;
}
static int features_dir_cb(int dirfd, const char *name, struct stat *st,
void *data)
{
@@ -173,6 +194,8 @@ static int features_dir_cb(int dirfd, const char *name, struct stat *st,
if (features_snprintf(fst, "%s {", name) == -1)
return -1;
/* Handle symlink here. See _aa_dirat_for_each in private.c */
if (S_ISREG(st->st_mode)) {
ssize_t len;
size_t remaining;
@@ -180,7 +203,7 @@ static int features_dir_cb(int dirfd, const char *name, struct stat *st,
if (features_buffer_remaining(fst, &remaining) == -1)
return -1;
len = load_features_file(dirfd, name, fst->pos, remaining);
len = open_and_load_features_file(dirfd, name, fst->pos, remaining);
if (len < 0)
return -1;
@@ -219,7 +242,7 @@ static int init_features_hash(aa_features *features)
/* portable murmur3 hash
* https://github.com/aappleby/smhasher/wiki/MurmurHash3
*/
PMurHash32_Process(&hash, &carry, features, len);
PMurHash32_Process(&hash, &carry, string, len);
hash = PMurHash32_Result(hash, carry, len);
if (snprintf(features->hash, HASH_SIZE,
@@ -429,7 +452,7 @@ int aa_features_new(aa_features **features, int dirfd, const char *path)
retval = S_ISDIR(stat_file.st_mode) ?
load_features_dir(dirfd, path, f->string, STRING_SIZE) :
load_features_file(dirfd, path, f->string, STRING_SIZE);
open_and_load_features_file(dirfd, path, f->string, STRING_SIZE);
if (retval == -1) {
aa_features_unref(f);
return -1;
@@ -492,6 +515,48 @@ int aa_features_new_from_string(aa_features **features,
return 0;
}
/**
* aa_features_new_from_file - create a new aa_features object based on an open file
* @features: will point to the address of an allocated and initialized
* aa_features object upon success
* @file: file to load features from
*
* Returns: 0 on success, -1 on error with errno set and *@features pointing to
* NULL
*/
int aa_features_new_from_file(aa_features **features, int file)
{
aa_features *f;
ssize_t retval;
*features = NULL;
f = calloc(1, sizeof(*f));
if (!f) {
errno = ENOMEM;
return -1;
}
aa_features_ref(f);
retval = load_features_file(file, f->string, STRING_SIZE);
if (retval == -1) {
aa_features_unref(f);
return -1;
}
if (init_features_hash(f) == -1) {
int save = errno;
aa_features_unref(f);
errno = save;
return -1;
}
*features = f;
return 0;
}
/**
* aa_features_new_from_kernel - create a new aa_features object based on the current kernel
* @features: will point to the address of an allocated and initialized
@@ -532,27 +597,18 @@ void aa_features_unref(aa_features *features)
}
/**
* aa_features_write_to_file - write a string representation of an aa_features object to a file
* aa_features_write_to_fd - write a string representation of an aa_features object to an @fd
* @features: the features
* @dirfd: directory file descriptor or AT_FDCWD (see openat(2))
* @path: the path to write to
* @fd: the file descriptor to write to
*
* Returns: 0 on success, -1 on error with errno set
*/
int aa_features_write_to_file(aa_features *features,
int dirfd, const char *path)
int aa_features_write_to_fd(aa_features *features, int fd)
{
autoclose int fd = -1;
size_t size;
ssize_t retval;
char *string;
fd = openat(dirfd, path,
O_WRONLY | O_CREAT | O_TRUNC | O_SYNC | O_CLOEXEC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd == -1)
return -1;
string = features->string;
size = strlen(string);
do {
@@ -567,6 +623,28 @@ int aa_features_write_to_file(aa_features *features,
return 0;
}
/**
* aa_features_write_to_file - write a string representation of an aa_features object to a file
* @features: the features
* @dirfd: directory file descriptor or AT_FDCWD (see openat(2))
* @path: the path to write to
*
* Returns: 0 on success, -1 on error with errno set
*/
int aa_features_write_to_file(aa_features *features,
int dirfd, const char *path)
{
autoclose int fd = -1;
fd = openat(dirfd, path,
O_WRONLY | O_CREAT | O_TRUNC | O_SYNC | O_CLOEXEC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd == -1)
return -1;
return aa_features_write_to_fd(features, fd);
}
/**
* aa_features_is_equal - equality test for two aa_features objects
* @features1: the first features (can be NULL)
@@ -580,6 +658,38 @@ bool aa_features_is_equal(aa_features *features1, aa_features *features2)
strcmp(features1->string, features2->string) == 0;
}
static const char *features_lookup(aa_features *features, const char *str)
{
const char *features_string = features->string;
struct component components[32];
size_t i, num_components;
/* Empty strings are not accepted. Neither are leading '/' chars. */
if (!str || str[0] == '/')
return NULL;
/**
* Break @str into an array of components. For example,
* "mount/mask/mount" would turn into { "mount", 5 } as the first
* component, { "mask", 4 } as the second, and { "mount", 5 } as the
* third
*/
num_components = tokenize_path_components(str, components,
sizeof(components) / sizeof(*components));
/* At least one valid token is required */
if (!num_components)
return NULL;
/* Ensure that all components are valid and found */
for (i = 0; i < num_components; i++) {
if (!walk_one(&features_string, &components[i], i == 0))
return NULL;
}
return features_string;
}
/**
* aa_features_supports - provides aa_features object support status
* @features: the features
@@ -592,36 +702,55 @@ bool aa_features_is_equal(aa_features *features1, aa_features *features2)
*/
bool aa_features_supports(aa_features *features, const char *str)
{
const char *features_string = features->string;
struct component components[32];
size_t i, num_components;
const char *value = features_lookup(features, str);
/* Empty strings are not accepted. Neither are leading '/' chars. */
if (!str || str[0] == '/')
if (!value)
return false;
/**
* Break @str into an array of components. For example,
* "mount/mask/mount" would turn into { "mount", 5 } as the first
* component, { "mask", 4 } as the second, and { "mount", 5 } as the
* third
*/
num_components = tokenize_path_components(str, components,
sizeof(components) / sizeof(*components));
/* At least one valid token is required */
if (!num_components)
return false;
/* Ensure that all components are valid and found */
for (i = 0; i < num_components; i++) {
if (!walk_one(&features_string, &components[i], i == 0))
return false;
}
return true;
}
/**
* aa_features_value - lookup the value for a give feature
* @features: the features
* @str: the feature to look up the value for
* @len: return: if set length of returned str on success
*
* Returns: null terminated string or NULL on error with errno set to
* ENOENT - @str not found
* EISDIR - @str is not a leaf node in the feature tree
*/
char *aa_features_value(aa_features *features, const char *str, size_t *len)
{
const char *start, *cur = features_lookup(features, str);
errno = ENOENT;
if (!cur)
return NULL;
if (!islbrace(*cur))
return NULL;
cur++;
start = cur;
while (!isbrace_or_nul(*cur)) {
if (!isascii(*cur))
return NULL;
if (islbrace(*cur)) {
/* component is not leaf */
errno = EISDIR;
return NULL;
}
cur++;
}
errno = 0;
if (len)
*len = cur - start;
return strndup(start, cur - start);
}
/**
* aa_features_id - provides unique identifier for an aa_features object
* @features: the features

View File

@@ -19,7 +19,12 @@
%{
/* set the following to non-zero to get bison to emit debugging
* information about tokens given and rules matched. */
* information about tokens given and rules matched.
* Also:
* Uncomment the %defines
* parse.error
* parse.trace
*/
#define YYDEBUG 0
#include <string.h>
#include <aalogparse.h>
@@ -27,14 +32,25 @@
#include "grammar.h"
#include "scanner.h"
#ifndef unused_
#define unused_ __attribute__ ((unused))
#endif
#if (YYDEBUG != 0)
#define debug_unused_ /* nothing */
#else
#define debug_unused_ unused_
#endif
aa_log_record *ret_record;
/* Since we're a library, on any errors we don't want to print out any
* error messages. We should probably add a debug interface that does
* emit messages when asked for. */
void aalogparse_error(void *scanner, char const *s)
void aalogparse_error(unused_ void *scanner, debug_unused_ char const *s)
{
//printf("ERROR: %s\n", s);
#if (YYDEBUG != 0)
printf("ERROR: %s\n", s);
#endif
ret_record->event = AA_RECORD_INVALID;
}
@@ -68,6 +84,11 @@ aa_record_event_type lookup_aa_event(unsigned int type)
%}
%defines
/* uncomment for debugging
%define parse.error verbose
%define parse.trace
*/
%define api.pure
%lex-param{void *scanner}
%parse-param{void *scanner}
@@ -128,6 +149,8 @@ aa_record_event_type lookup_aa_event(unsigned int type)
%token TOK_KEY_PEER_PID
%token TOK_KEY_PROFILE
%token TOK_KEY_PEER_PROFILE
%token TOK_KEY_LABEL
%token TOK_KEY_PEER_LABEL
%token TOK_KEY_PEER
%token TOK_AUDIT
%token TOK_KEY_FAMILY
@@ -136,7 +159,9 @@ aa_record_event_type lookup_aa_event(unsigned int type)
%token TOK_KEY_NAMESPACE
%token TOK_KEY_ERROR
%token TOK_KEY_FSUID
%token TOK_KEY_FSUID_UPPER
%token TOK_KEY_OUID
%token TOK_KEY_OUID_UPPER
%token TOK_KEY_UID
%token TOK_KEY_AUID
%token TOK_KEY_SAUID
@@ -162,7 +187,9 @@ aa_record_event_type lookup_aa_event(unsigned int type)
%token TOK_KEY_FSTYPE
%token TOK_KEY_FLAGS
%token TOK_KEY_SRCNAME
%token TOK_KEY_CLASS
%token TOK_SOCKLOGD_KERNEL
%token TOK_SYSLOG_KERNEL
%token TOK_SYSLOG_USER
@@ -194,7 +221,7 @@ new_syntax:
| TOK_TYPE_AA_ERROR audit_msg key_list { ret_record->event = AA_RECORD_ERROR; }
| TOK_TYPE_UNKNOWN audit_msg key_list { ret_record->event = lookup_aa_event($1); }
| TOK_TYPE_LSM_AVC audit_msg key_list
| TOK_TYPE_USER_AVC audit_user_msg TOK_SINGLE_QUOTE key_list TOK_SINGLE_QUOTE
| TOK_TYPE_USER_AVC audit_user_msg
;
other_audit: TOK_TYPE_OTHER audit_msg TOK_MSG_REST
@@ -209,19 +236,28 @@ dmesg_type: TOK_DMESG_STAMP TOK_AUDIT TOK_COLON key_type audit_id key_list
{ ret_record->version = AA_RECORD_SYNTAX_V2; free($1); }
;
syslog_id: TOK_ID TOK_SYSLOG_KERNEL { free($1); }
| TOK_SOCKLOGD_KERNEL { }
;
syslog_type:
syslog_date TOK_ID TOK_SYSLOG_KERNEL audit_id key_list
{ ret_record->version = AA_RECORD_SYNTAX_V2; free($2); }
| syslog_date TOK_ID TOK_SYSLOG_KERNEL key_type audit_id key_list
{ ret_record->version = AA_RECORD_SYNTAX_V2; free($2); }
| syslog_date TOK_ID TOK_SYSLOG_KERNEL TOK_DMESG_STAMP audit_id key_list
{ ret_record->version = AA_RECORD_SYNTAX_V2; free($2); free($4); }
| syslog_date TOK_ID TOK_SYSLOG_KERNEL TOK_DMESG_STAMP key_type audit_id key_list
{ ret_record->version = AA_RECORD_SYNTAX_V2; free($2); free($4); }
| syslog_date TOK_ID TOK_SYSLOG_KERNEL TOK_DMESG_STAMP TOK_AUDIT TOK_COLON key_type audit_id key_list
{ ret_record->version = AA_RECORD_SYNTAX_V2; free($2); free($4); }
| syslog_date TOK_ID TOK_SYSLOG_KERNEL TOK_AUDIT TOK_COLON key_type audit_id key_list
{ ret_record->version = AA_RECORD_SYNTAX_V2; free($2); }
syslog_date syslog_id audit_id key_list
{ ret_record->version = AA_RECORD_SYNTAX_V2; }
| syslog_date syslog_id key_type audit_id key_list
{ ret_record->version = AA_RECORD_SYNTAX_V2; }
| syslog_date syslog_id TOK_DMESG_STAMP audit_id key_list
{ ret_record->version = AA_RECORD_SYNTAX_V2; free($3); }
| syslog_date syslog_id TOK_DMESG_STAMP key_type audit_id key_list
{ ret_record->version = AA_RECORD_SYNTAX_V2; free($3); }
/* needs update: hard newline in handling mutiline log messages */
| syslog_date syslog_id TOK_DMESG_STAMP TOK_AUDIT TOK_COLON key_type audit_id audit_user_msg_partial_tail
{ ret_record->version = AA_RECORD_SYNTAX_V2; free($3); }
| syslog_date syslog_id TOK_DMESG_STAMP TOK_AUDIT TOK_COLON key_type audit_id audit_user_msg_tail
{ ret_record->version = AA_RECORD_SYNTAX_V2; free($3); }
| syslog_date syslog_id TOK_DMESG_STAMP TOK_AUDIT TOK_COLON key_type audit_id key_list
{ ret_record->version = AA_RECORD_SYNTAX_V2; free($3); }
| syslog_date syslog_id TOK_AUDIT TOK_COLON key_type audit_id key_list
{ ret_record->version = AA_RECORD_SYNTAX_V2; }
| syslog_date TOK_ID TOK_SYSLOG_USER key_list
{ ret_record->version = AA_RECORD_SYNTAX_V2; free($2); }
;
@@ -234,7 +270,13 @@ audit_dispatch:
audit_msg: TOK_KEY_MSG TOK_EQUALS audit_id
;
audit_user_msg: TOK_KEY_MSG TOK_EQUALS audit_id ignored_pid ignored_uid ignored_auid ignored_ses TOK_KEY_MSG TOK_EQUALS
audit_user_msg_partial_tail: ignored_pid ignored_uid ignored_auid ignored_ses TOK_KEY_MSG TOK_EQUALS TOK_SINGLE_QUOTE key_list
;
audit_user_msg_tail: audit_user_msg_partial_tail TOK_SINGLE_QUOTE
;
audit_user_msg: TOK_KEY_MSG TOK_EQUALS audit_id audit_user_msg_tail
;
audit_id: TOK_AUDIT TOK_OPEN_PAREN TOK_AUDIT_DIGITS TOK_PERIOD TOK_AUDIT_DIGITS TOK_COLON TOK_AUDIT_DIGITS TOK_CLOSE_PAREN TOK_COLON
@@ -292,6 +334,10 @@ key: TOK_KEY_OPERATION TOK_EQUALS TOK_QUOTED_STRING
{ ret_record->profile = $3;}
| TOK_KEY_PEER_PROFILE TOK_EQUALS safe_string
{ ret_record->peer_profile = $3;}
| TOK_KEY_LABEL TOK_EQUALS safe_string
{ ret_record->profile = $3;}
| TOK_KEY_PEER_LABEL TOK_EQUALS safe_string
{ ret_record->peer_profile = $3;}
| TOK_KEY_FAMILY TOK_EQUALS TOK_QUOTED_STRING
{ ret_record->net_family = $3;}
| TOK_KEY_SOCK_TYPE TOK_EQUALS TOK_QUOTED_STRING
@@ -308,6 +354,10 @@ key: TOK_KEY_OPERATION TOK_EQUALS TOK_QUOTED_STRING
{ ret_record->fsuid = $3;}
| TOK_KEY_OUID TOK_EQUALS TOK_DIGITS
{ ret_record->ouid = $3;}
| TOK_KEY_FSUID_UPPER TOK_EQUALS TOK_QUOTED_STRING
{ free($3);} /* Ignore - fsuid username */
| TOK_KEY_OUID_UPPER TOK_EQUALS TOK_QUOTED_STRING
{ free($3);} /* Ignore - ouid username */
| TOK_KEY_SAUID TOK_EQUALS TOK_DIGITS
{ /* Ignore - Source audit ID from user AVC messages */ }
| TOK_KEY_HOSTNAME TOK_EQUALS safe_string
@@ -335,7 +385,7 @@ key: TOK_KEY_OPERATION TOK_EQUALS TOK_QUOTED_STRING
| TOK_KEY_CAPABILITY TOK_EQUALS TOK_DIGITS
{ /* need to reverse map number to string, need to figure out
* how to get auto generation of reverse mapping table into
* autotools Makefile. For now just drop assumming capname is
* autotools Makefile. For now just drop assuming capname is
* present which it should be with current kernels */
}
| TOK_KEY_CAPNAME TOK_EQUALS TOK_QUOTED_STRING
@@ -343,7 +393,7 @@ key: TOK_KEY_OPERATION TOK_EQUALS TOK_QUOTED_STRING
ret_record->name = $3;
}
| TOK_KEY_OFFSET TOK_EQUALS TOK_DIGITS
{ /* offset is used for reporting where an error occured unpacking
{ /* offset is used for reporting where an error occurred unpacking
* loaded policy. We can just drop this currently
*/
}
@@ -382,6 +432,8 @@ key: TOK_KEY_OPERATION TOK_EQUALS TOK_QUOTED_STRING
ret_record->event = AA_RECORD_INVALID;
ret_record->info = $1;
}
| TOK_KEY_CLASS TOK_EQUALS TOK_QUOTED_STRING
{ ret_record->class = $3; }
;
apparmor_event:

View File

@@ -43,10 +43,137 @@
__asm__ (".symver " #real "," #name "@" #version)
#define default_symbol_version(real, name, version) \
__asm__ (".symver " #real "," #name "@@" #version)
#define DLLEXPORT __attribute__((visibility("default"),externally_visible))
#define UNCONFINED "unconfined"
#define UNCONFINED_SIZE strlen(UNCONFINED)
/*
* AppArmor kernel interfaces. Potentially used by this code to
* implement the various library functions.
*
*
* /sys/module/apparmor/parameters/ *
*
* Available on all kernels, some options may not be available and policy
* may block access.
* audit - normal,quiet_denied,quiet,noquiet,all
* debug (bool) - turn on debug messages if enabled during compile
* hash_policy (bool) - provide a hash of loaded policy
* logsyscall (bool) - ignored
* paranoid_load (bool) - whether full policy checks are done. Should only
* be disabled for embedded device kernels
* audit_header (bool) - include "apparmor=<mode> in messages"
* enabled (bool) - whether apparmor is enabled. This can be
* different than whether apparmor is available.
* See virtualization and LSM stacking.
* lock_policy (bool) - one way trigger. Once set policy can not be
* loaded, replace, removed.
* mode - global policy namespace control of whether
* apparmor is in "enforce", "complain"
* path_max - maximum path size. Can always be read but
* can only be set on some kernels.
*
* securityfs/apparmor - usually mounted at /sys/kernel/security/apparmor/ *
* .access - transactional interface used to query kernel
* .ns_level - RO policy namespace level of current task
* .ns_name - RO current policy namespace of current task
* .ns_stacked - RO boolean if stacking is in use with the namespace
* .null - special device file used to redirect closed fds to
* profiles - RO virtualized text list of visible loaded profiles
* .remove - WO names of profiles to remove
* .replace - WO binary policy to replace (will load if not present)
* .load - WO binary policy to load (will fail if already present)
* revision - RO unique incrementing revision number for policy
* .stacked - RO boolean if label is currently stacked
* features/ - RO feature set supported by kernel
* policy/ - RO policy loaded into kernel
*
*
* /proc/<tid>/attr/apparmor/ *
* New proc attr interface compatible with LSM stacking. Available even
* when LSM stacking is not in use.
* current - see /proc/<tid>/attr/current
* exec - see /proc/<tid>/attr/exec
* prev - see /proc/<tid>/attr/prev
*
* /proc/<tid>/attr/ * Old proc attr interface shared between LSMs goes
* to first registered LSM that wants the proc interface, but can be
* virtualized by setting the display LSM. So if LSM stacking is in
* use this interface may belong to another LSM. Use
* /proc/<tid>/attr/apparmor/ *
* first if possible, and do NOT use if
* /sys/module/apparmor/parameters/enabled=N.
* Note: older version of the library only used this interface and did not
* check if it was available. Which could lead to weird failures if
* another LSM has claimed it. This version of the library tries to
* fix this problem, but unfortunately it is impossible to completely
* address, because access to interfaces required to determine
* whether apparmor owns the interface may be restricted, either
* by existing apparmor policy that has not been updated to use the
* new interface or by another LSM.
* current - current confinement
* display - LSM stacking. Which LSM currently owns the interface.
* exec - label to switch to at exec
* fscreate - unused by apparmor
* keycreate - unused by apparmor
* prev - when in HAT set to parent label
* sockcreate - unused by apparmor
*
*
* Below /proc/ interface combinations are documented on how the library
* currently behaves and how it used to behave. This serves to document
* known failure points as we can not entirely fix this mess.
* Note: userspace applications using the interface directly have all
* the issues/failures of AppArmor 2.x unless they have specifically
* been updated to deal with this mess.
*
*
* AppArmor 2.x Lib
*
* LSM AA sys sys proc/ proc/ user
* Stk | Blt | LSM | enabl | avail | aa/ | * | space |
* ----+-----+-------+-------+-------+-------+-------+-------+--------+
* N | N | - | - | - | - | N | AA2.x | - |
* N | N | other | - | - | - | N | AA2.x | FAIL |
* N | N | other |denied | - | - | N | AA2.x | FAIL |
* N | Y | - | N | - | - | N | AA2.x | - |
* N | Y | other | - | - | - | N | AA2.x | FAIL |
* N | Y | AA | - | - | - | Y | AA2.x | PASS |
* Y | N | - | - | - | - | N | AA2.x | - |
* Y | N | other | - | - | - | N | AA2.x | FAIL |
* Y | Y | - | N | - | - | N | AA2.x | - |
* Y | Y | other | - | - | - | N | AA2.x | FAIL |
* Y | Y | AA | - | - | - | Y | AA2.x | PASS |
* Y | Y | major | - | - | - | Y | AA2.x | PASS |
* Y | Y | minor | - | - | - | N | AA2.x | FAIL |
*
*
* AppArmor 3.x Lib - adds stacking support.
*
* Will FAIL in a few cases because it can not determine if apparmor
* is enabled and has control of the old interface. Not failing in these
* cases where AppArmor is available will result in regressions where
* the library will not work correctly with old kernels. In these
* cases its better that apparmor userspace is not used.
*
* AppArmor 3.x will avoid the failure cases if any of enabled, avail
* or the new proc interfaces are available to the task. AppArmor 3.x
* will also automatically add permissions to access the new proc
* interfaces so change_hat and change_profile won't experience these
* failures, it will only happen for confined applications hitting the
* interfaces and not using change_hat or change_profile.
*
* LSM AA sys sys proc/ proc/
* Stk | Blt | LSM | enabl | avail | aa/ | * |
* ----+-----+-------+-------+-------+-------+-------+-----------------
* Y/N | N | other | denied| NA | NA | Y | old interface avail
* Y/N | Y | other | denied| NA | NA | Y | old interface avail
* Y | Y | minor | denied| NA | NA | Y | old interface avail
* Y | Y | minor | denied| NA | denied| Y | old interface avail
* Y/N | Y | minor | denied| denied| denied| Y | old interface avail
*/
/**
* aa_find_mountpoint - find where the apparmor interface filesystem is mounted
* @mnt: returns buffer with the mountpoint string
@@ -93,6 +220,85 @@ int aa_find_mountpoint(char **mnt)
return rc;
}
/**
* pararm_check_base - return boolean value for PARAM
* PARAM: parameter to check
*
* Returns: 1 == Y
* 0 == N
* <0 == error
*
* done as a macro so we can paste the param
*/
#define param_check_base(PARAM) \
({ \
int rc, fd; \
fd = open("/sys/module/apparmor/parameters/" PARAM, O_RDONLY); \
if (fd == -1) { \
rc = -errno; \
} else { \
char buffer[2]; \
int size = read(fd, &buffer, 2); \
rc = -errno; \
close(fd); \
errno = -rc; \
if (size > 0) { \
if (buffer[0] == 'Y') \
rc = 1; \
else \
rc = 0; \
} \
} \
(rc); \
})
static pthread_once_t param_enabled_ctl = PTHREAD_ONCE_INIT;
static int param_enabled = 0;
static pthread_once_t param_private_enabled_ctl = PTHREAD_ONCE_INIT;
static int param_private_enabled = 0;
static void param_check_enabled_init_once(void)
{
param_enabled = param_check_base("enabled");
}
static int param_check_enabled()
{
if (pthread_once(&param_enabled_ctl, param_check_enabled_init_once) == 0 && param_enabled >= 0)
return param_enabled;
/* fallback if not initialized OR we recorded an error when
* initializing.
*/
return param_check_base("enabled");
}
static int is_enabled(void)
{
return param_check_enabled() == 1;
}
static void param_check_private_enabled_init_once(void)
{
param_private_enabled = param_check_base("available");
}
static int param_check_private_enabled()
{
if (pthread_once(&param_private_enabled_ctl, param_check_private_enabled_init_once) == 0 && param_private_enabled >= 0)
return param_private_enabled;
/* fallback if not initialized OR we recorded an error when
* initializing.
*/
return param_check_base("available");
}
static int is_private_enabled(void)
{
return param_check_private_enabled() == 1;
}
/**
* aa_is_enabled - determine if apparmor is enabled
*
@@ -105,36 +311,47 @@ int aa_find_mountpoint(char **mnt)
*/
int aa_is_enabled(void)
{
int serrno, fd, rc, size;
char buffer[2];
int rc;
char *mnt;
bool private = false;
/* if the interface mountpoint is available apparmor is enabled */
rc = param_check_enabled();
if (rc < 1) {
if (!is_private_enabled()) {
if (rc == 0)
errno = ECANCELED;
else if (rc == -ENOENT)
errno = ENOSYS;
else
errno = -rc;
return 0;
}
/* actually available but only on private interfaces */
private = true;
}
/* if the interface mountpoint is available apparmor may not
* be locally enabled for older interfaces but still present
* so make sure to check after, checking available status
* also we don't cache the enabled status like available
* because the mount status can change.
*/
rc = aa_find_mountpoint(&mnt);
if (rc == 0) {
free(mnt);
return 1;
if (!private)
return 1;
/* provide an error code to indicate apparmor is available
* on private interfaces, but we can note that apparmor
* is enabled because some applications hit the low level
* interfaces directly and don't know about the new
* private interfaces
*/
errno = EBUSY;
/* fall through to return 0 */
}
/* determine why the interface mountpoint isn't available */
fd = open("/sys/module/apparmor/parameters/enabled", O_RDONLY);
if (fd == -1) {
if (errno == ENOENT)
errno = ENOSYS;
return 0;
}
size = read(fd, &buffer, 2);
serrno = errno;
close(fd);
errno = serrno;
if (size > 0) {
if (buffer[0] == 'Y')
errno = ENOENT;
else
errno = ECANCELED;
}
return 0;
}
@@ -147,14 +364,135 @@ static inline pid_t aa_gettid(void)
#endif
}
/*
* Check for the new apparmor proc interface once on the first api call
* and then reuse the result on all subsequent api calls. This avoids
* a double syscall overhead on each api call if the interface is not
* present.
*/
static pthread_once_t proc_attr_base_ctl = PTHREAD_ONCE_INIT;
static const char *proc_attr_base_old = "/proc/%d/attr/%s";
static const char *proc_attr_new_dir = "/proc/%d/attr/apparmor/";
static const char *proc_attr_base_stacking = "/proc/%d/attr/apparmor/%s";
static const char *proc_attr_base_unavailable = "/proc/%d/attr/apparmor/unavailable/%s";
static const char *proc_attr_base = NULL;
static int proc_stacking_present = -1; /* unknown */
static void proc_attr_base_init_once(void)
{
autofree char *tmp;
/* if we fail we just fall back to the default value */
if (asprintf(&tmp, proc_attr_new_dir, aa_gettid()) > 0) {
struct stat sb;
if (stat(tmp, &sb) == 0) {
proc_attr_base = proc_attr_base_stacking;
proc_stacking_present = 1;
return;
} else if (errno == ENOENT) {
/* no stacking - try falling back */
proc_stacking_present = 0;
} else if (errno == EACCES) {
/* the dir exists, but access is denied */
proc_stacking_present = 1;
proc_attr_base = proc_attr_base_stacking;
} /* else
denied by policy, or other error try falling back */
} else {
/* failed allocation - proc_attr_base stays NULL */
return;
}
/* check for new interface failed, see if we can fallback */
if (param_check_enabled() == 0) {
/* definate NO (not just an error) on enabled. Do not fall
* back to old shared proc interface
*
* First try an alternate check for private proc interface
*/
int enabled = param_check_private_enabled();
if (enabled == 1) {
/* the private interface exists and we can't
* fallback so just keep trying on the new
* interface.
*/
proc_attr_base = proc_attr_base_stacking;
} else if (enabled == 0) {
/* definite NO - no interface available */
proc_attr_base = proc_attr_base_unavailable;
} else {
/* error can't determine, proc_attr_base stays NULL */
}
} else if (param_check_enabled() == 1) {
/* apparmor is enabled, we can use the old interface */
proc_attr_base = proc_attr_base_old;
} else if (errno != EACCES) {
/* this shouldn't happen unless apparmor is not builtin
* or proc isn't mounted
*/
proc_attr_base = proc_attr_base_unavailable;
} /* else
denied by policy - proc_attr_base stays NULL */
return;
}
static char *procattr_path(pid_t pid, const char *attr)
{
char *path = NULL;
if (asprintf(&path, "/proc/%d/attr/%s", pid, attr) > 0)
const char *tmp;
/* TODO: rework this with futex or userspace RCU so we can update
* the base value instead of continually using the same base
* after we have hit an error
*/
/* ignore failure, we just fallback to the default value */
(void) pthread_once(&proc_attr_base_ctl, proc_attr_base_init_once);
if (proc_attr_base)
tmp = proc_attr_base;
else if (proc_stacking_present)
/* couldn't determine during init */
tmp = proc_attr_base_stacking;
else
/* couldn't determine during init and no stacking */
tmp = proc_attr_base_old;
if (asprintf(&path, tmp, pid, attr) > 0)
return path;
return NULL;
}
static int procattr_open(pid_t tid, const char *attr, int flags)
{
char *tmp;
int fd;
tmp = procattr_path(tid, attr);
if (!tmp) {
return -1;
}
fd = open(tmp, flags);
free(tmp);
/* Test is we can fallback to the old interface (this is ugly).
* If we haven't tried the old interface already
* proc_attr_base == proc_attr_base_old - no fallback
* else if is_enabled()
* apparmor is available on the old interface
* we do NOT use is_private_enabled() as
* 1. the new private interface would have been tried first above
* 2. that can be true even when another LSM is using the
* old interface where is_enabled() is only successful if
* the old interface is available to apparmor.
*/
if (fd == -1 && tmp != proc_attr_base_old && param_check_enabled() != 0) {
if (asprintf(&tmp, proc_attr_base_old, tid, attr) < 0)
return -1;
fd = open(tmp, flags);
free(tmp);
}
return fd;
}
/**
* parse_unconfined - check for the unconfined label
* @con: the confinement context
@@ -264,12 +602,7 @@ int aa_getprocattr_raw(pid_t tid, const char *attr, char *buf, int len,
goto out;
}
tmp = procattr_path(tid, attr);
if (!tmp)
goto out;
fd = open(tmp, O_RDONLY);
free(tmp);
fd = procattr_open(tid, attr, O_RDONLY);
if (fd == -1) {
goto out;
}
@@ -380,18 +713,13 @@ static int setprocattr(pid_t tid, const char *attr, const char *buf, int len)
{
int rc = -1;
int fd, ret;
char *ctl = NULL;
if (!buf) {
errno = EINVAL;
goto out;
}
ctl = procattr_path(tid, attr);
if (!ctl)
goto out;
fd = open(ctl, O_WRONLY);
fd = procattr_open(tid, attr, O_WRONLY);
if (fd == -1) {
goto out;
}
@@ -412,9 +740,6 @@ static int setprocattr(pid_t tid, const char *attr, const char *buf, int len)
(void)close(fd);
out:
if (ctl) {
free(ctl);
}
return rc;
}
@@ -500,7 +825,7 @@ int aa_change_onexec(const char *profile)
}
/* create an alias for the old change_hat@IMMUNIX_1.0 symbol */
extern typeof((__change_hat)) __old_change_hat __attribute__((alias ("__change_hat")));
DLLEXPORT extern typeof((__change_hat)) __old_change_hat __attribute__((alias ("__change_hat")));
symbol_version(__old_change_hat, change_hat, IMMUNIX_1.0);
default_symbol_version(__change_hat, change_hat, APPARMOR_1.0);
@@ -690,16 +1015,24 @@ int aa_getcon(char **label, char **mode)
* Returns: length of confinement context including null termination or -1 on
* error if errno == ERANGE then @len will hold the size needed
*/
int aa_getpeercon_raw(int fd, char *buf, int *len, char **mode)
int aa_getpeercon_raw(int fd, char *buf, socklen_t *len, char **mode)
{
socklen_t optlen = *len;
socklen_t optlen;
int rc;
if (optlen <= 0 || buf == NULL) {
if (*len <= 0 || buf == NULL) {
errno = EINVAL;
return -1;
}
optlen = *len;
if (!is_enabled()) {
errno = EINVAL;
return -1;
}
/* TODO: add check for private_enabled when alternate interface
* is approved
*/
rc = getsockopt(fd, SOL_SOCKET, SO_PEERSEC, buf, &optlen);
if (rc == -1 || optlen <= 0)
goto out;
@@ -747,7 +1080,8 @@ out:
*/
int aa_getpeercon(int fd, char **label, char **mode)
{
int rc, last_size, size = INITIAL_GUESS_SIZE;
socklen_t last_size, size = INITIAL_GUESS_SIZE;
int rc;
char *buffer = NULL;
if (!label) {
@@ -849,7 +1183,7 @@ int query_label(uint32_t mask, char *query, size_t size, int *allowed,
memcpy(query, AA_QUERY_CMD_LABEL, AA_QUERY_CMD_LABEL_SIZE);
errno = 0;
ret = write(fd, query, size);
if (ret != size) {
if (ret < 0 || ((size_t) ret != size)) {
if (ret >= 0)
errno = EPROTO;
/* IMPORTANT: This is the only valid error path that can have
@@ -889,7 +1223,7 @@ int query_label(uint32_t mask, char *query, size_t size, int *allowed,
/* export multiple aa_query_label symbols to compensate for downstream
* releases with differing symbol versions. */
extern typeof((query_label)) __aa_query_label __attribute__((alias ("query_label")));
DLLEXPORT extern typeof((query_label)) __aa_query_label __attribute__((alias ("query_label")));
symbol_version(__aa_query_label, aa_query_label, APPARMOR_1.1);
default_symbol_version(query_label, aa_query_label, APPARMOR_2.9);
@@ -985,9 +1319,9 @@ int aa_query_link_path_len(const char *label, size_t label_len,
query[pos] = 0;
query[++pos] = AA_CLASS_FILE;
memcpy(query + pos + 1, link, link_len);
/* The kernel does the query in two parts we could similate this
/* The kernel does the query in two parts; we could simulate this
* doing the following, however as long as policy is compiled
* correctly this isn't requied, and it requires and extra round
* correctly this isn't required, and it requires an extra round
* trip to the kernel and adds a race on policy replacement between
* the two queries.
*

View File

@@ -90,7 +90,7 @@ static int write_buffer(int fd, const char *buffer, int size)
/**
* write_policy_buffer - load compiled policy into the kernel
* @fd: kernel iterface to write to
* @fd: kernel interface to write to
* @atomic: whether to load all policy in buffer atomically (true)
* @buffer: buffer of policy to load
* @size: the size of the data in the buffer
@@ -205,7 +205,7 @@ static int write_policy_file_to_iface(aa_kernel_interface *kernel_interface,
* @apparmorfs: path to the apparmor directory of the mounted securityfs (can
* be NULL and the path will be auto discovered)
*
* Returns: 0 on success, -1 on error with errnot set and *@kernel_interface
* Returns: 0 on success, -1 on error with errno set and *@kernel_interface
* pointing to NULL
*/
int aa_kernel_interface_new(aa_kernel_interface **kernel_interface,

View File

@@ -103,6 +103,8 @@ void free_record(aa_log_record *record)
free(record->flags);
if (record->src_name != NULL)
free(record->src_name);
if (record->class != NULL)
free(record->class);
free(record);
}
@@ -131,7 +133,7 @@ char *hex_to_string(char *hexstring)
char *ret = NULL;
char buf[3], *endptr;
size_t len;
int i;
size_t i;
if (!hexstring)
goto out;

View File

@@ -6,14 +6,14 @@
IMMUNIX_1.0 {
global:
change_hat;
change_hat; __old_change_hat;
local:
*;
};
APPARMOR_1.0 {
global:
change_hat;
change_hat; __change_hat;
parse_record;
free_record;
local:
@@ -24,7 +24,7 @@ APPARMOR_1.1 {
global:
aa_is_enabled;
aa_find_mountpoint;
aa_change_hat;
aa_change_hat; __old_change_hat;
aa_change_hatv;
aa_change_hat_vargs;
aa_change_profile;
@@ -37,7 +37,7 @@ APPARMOR_1.1 {
free_record;
aa_getprocattr_raw;
aa_getprocattr;
aa_query_label;
aa_query_label; __aa_query_label;
# no more symbols here, please
@@ -47,7 +47,7 @@ APPARMOR_1.1 {
APPARMOR_2.9 {
global:
aa_query_label;
aa_query_label; query_label;
local:
*;
} APPARMOR_1.1;
@@ -108,9 +108,26 @@ APPARMOR_2.13 {
*;
} APPARMOR_2.11;
APPARMOR_2.13.1 {
global:
aa_policy_cache_add_ro_dir;
local:
*;
} APPARMOR_2.13;
APPARMOR_3.0 {
global:
aa_features_new_from_file;
aa_features_write_to_fd;
aa_features_value;
local:
*;
} APPARMOR_2.13.1;
PRIVATE {
global:
_aa_is_blacklisted;
_aa_asprintf;
_aa_autofree;
_aa_autoclose;
_aa_autofclose;

View File

@@ -45,6 +45,8 @@ struct aa_policy_cache {
static int clear_cache_cb(int dirfd, const char *path, struct stat *st,
void *data unused)
{
/* Handle symlink here. See _aa_dirat_for_each in private.c */
if (S_ISREG(st->st_mode)) {
/* remove regular files */
return unlinkat(dirfd, path, 0);
@@ -260,7 +262,7 @@ static int cache_dir_from_path_and_features(char **cache_path,
{
autofree const char *features_id = NULL;
char *cache_dir;
size_t len;
ssize_t len;
int rc;
features_id = aa_features_id(features);
@@ -301,8 +303,10 @@ static int cache_dir_from_path_and_features(char **cache_path,
PDEBUG("cache_dir_from_path_and_features() callback found '%s'\n", data.cache_name);
*cache_path = data.cache_name;
return 0;
} else if (rc)
} else if (rc) {
PDEBUG("cache_dir_from_path_and_features() callback returned an error'%m'\n");
return -1;
}
/* no dir found use 1 higher than highest dir n searched */
len = asprintf(&cache_dir, "%s/%s.%d", path, features_id, data.n + 1);
if (len == -1)
@@ -313,18 +317,20 @@ static int cache_dir_from_path_and_features(char **cache_path,
return 0;
}
/* will return the cache_dir or NULL */
static int open_or_create_cache_dir(aa_features *features, int dirfd,
const char *path, bool create)
const char *path, bool create,
char **cache_dir)
{
autofree char *cache_dir = NULL;
int fd;
if (cache_dir_from_path_and_features(&cache_dir, dirfd, path,
*cache_dir = NULL;
if (cache_dir_from_path_and_features(cache_dir, dirfd, path,
features))
return -1;
open:
fd = openat(dirfd, cache_dir, O_RDONLY | O_CLOEXEC | O_DIRECTORY);
fd = openat(dirfd, *cache_dir, O_RDONLY | O_CLOEXEC | O_DIRECTORY);
if (fd < 0) {
/* does the dir exist? */
if (create && errno == ENOENT) {
@@ -336,23 +342,24 @@ open:
* /etc/apparmor.d/cache.d/<features_id>/
* 3) Try to reopen the cache directory
*/
if (mkdirat(fd, path, 0700) == -1 &&
if (mkdirat(dirfd, path, 0700) == -1 &&
errno != EEXIST) {
PERROR("Can't create cache location '%s': %m\n",
path);
} else if (mkdirat(dirfd, cache_dir, 0700) == -1 &&
} else if (mkdirat(dirfd, *cache_dir, 0700) == -1 &&
errno != EEXIST) {
PERROR("Can't create cache directory '%s': %m\n",
cache_dir);
*cache_dir);
} else {
goto open;
}
} else if (create) {
PERROR("Can't update cache directory '%s': %m\n", cache_dir);
PERROR("Can't update cache directory '%s': %m\n", *cache_dir);
} else {
PDEBUG("Cache directory '%s' does not exist\n", cache_dir);
PDEBUG("Cache directory '%s' does not exist\n", *cache_dir);
}
PDEBUG("Could not open cache_dir: %m");
return -1;
}
@@ -380,6 +387,7 @@ int aa_policy_cache_new(aa_policy_cache **policy_cache,
aa_features *kernel_features,
int dirfd, const char *path, uint16_t max_caches)
{
autofree char *cache_dir = NULL;
aa_policy_cache *pc;
bool create = max_caches > 0;
autofree const char *features_id = NULL;
@@ -407,13 +415,16 @@ int aa_policy_cache_new(aa_policy_cache **policy_cache,
aa_features_ref(kernel_features);
} else if (aa_features_new_from_kernel(&kernel_features) == -1) {
aa_policy_cache_unref(pc);
PDEBUG("%s: Failed to obtain features %m\n", __FUNCTION__);
return -1;
}
pc->features = kernel_features;
fd = open_or_create_cache_dir(kernel_features, dirfd, path, create);
fd = open_or_create_cache_dir(kernel_features, dirfd, path, create,
&cache_dir);
if (fd == -1) {
aa_policy_cache_unref(pc);
PDEBUG("%s: Failed to open_or_create_dir %m\n", __FUNCTION__);
return -1;
}
pc->dirfd[0] = fd;
@@ -443,16 +454,20 @@ int aa_policy_cache_new(aa_policy_cache **policy_cache,
int aa_policy_cache_add_ro_dir(aa_policy_cache *policy_cache, int dirfd,
const char *path)
{
autofree char *cache_dir = NULL;
int fd;
if (policy_cache->n >= MAX_POLICY_CACHE_OVERLAY_DIRS) {
errno = ENOSPC;
PDEBUG("%s: exceeded number of supported cache overlays\n", __FUNCTION__);
return -1;
}
fd = open_or_create_cache_dir(policy_cache->features, dirfd, path,
false);
if (fd == -1)
false, &cache_dir);
if (fd == -1) {
PDEBUG("%s: failed to open_or_create_cache_dir %m\n", __FUNCTION__);
return -1;
}
policy_cache->dirfd[policy_cache->n++] = fd;
return 0;
@@ -675,8 +690,8 @@ char *aa_policy_cache_dir_path_preview(aa_features *kernel_features,
aa_features_unref(kernel_features);
if (asprintf(&dir_path, "%s%s%s",
cache_loc ? : "", cache_loc ? "/" : "", cache_dir) == -1) {
if (asprintf(&dir_path, "%s%s%s", cache_loc ? cache_loc : "",
cache_loc ? "/" : "", cache_dir) == -1) {
errno = ENOMEM;
return NULL;
}

View File

@@ -38,11 +38,24 @@
#ifndef HAVE_SECURE_GETENV
#ifdef HAVE___SECURE_GETENV
#define secure_getenv __secure_getenv
#elif ENABLE_DEBUG_OUTPUT
#error Debug output is not possible without a secure_getenv() implementation.
#else
#error neither secure_getenv nor __secure_getenv is available
#define secure_getenv(env) NULL
#endif
#endif
/**
* Allow libapparmor to build on older glibcs and other libcs that do
* not support reallocarray.
*/
#ifndef HAVE_REALLOCARRAY
void *reallocarray(void *ptr, size_t nmemb, size_t size)
{
return realloc(ptr, nmemb * size);
}
#endif
struct ignored_suffix_t {
const char * text;
int len;
@@ -50,7 +63,7 @@ struct ignored_suffix_t {
};
static struct ignored_suffix_t ignored_suffixes[] = {
/* Debian packging files, which are in flux during install
/* Debian packaging files, which are in flux during install
should be silently ignored. */
{ ".dpkg-new", 9, 1 },
{ ".dpkg-old", 9, 1 },
@@ -113,7 +126,7 @@ bool atomic_dec_and_test(unsigned int *v)
int _aa_is_blacklisted(const char *name)
{
size_t name_len = strlen(name);
ssize_t name_len = strlen(name);
struct ignored_suffix_t *suffix;
/* skip dot files and files with no name */
@@ -134,7 +147,7 @@ int _aa_is_blacklisted(const char *name)
return 0;
}
/* automaticly free allocated variables tagged with autofree on fn exit */
/* automatically free allocated variables tagged with autofree on fn exit */
void _aa_autofree(void *p)
{
void **_p = (void**)p;
@@ -173,16 +186,6 @@ int _aa_asprintf(char **strp, const char *fmt, ...)
return rc;
}
static int dot_or_dot_dot_filter(const struct dirent *ent)
{
if (strcmp(ent->d_name, ".") == 0 ||
strcmp(ent->d_name, "..") == 0)
return 0;
return 1;
}
/* stops on first error, can use errno or return value to communicate
* the goal is to use this to replace _aa_dirat_for_each, but that will
* be a different patch.
@@ -191,6 +194,7 @@ int _aa_dirat_for_each2(int dirfd, const char *name, void *data,
int (* cb)(int, const struct dirent *, void *))
{
autoclose int cb_dirfd = -1;
int fd_for_dir = -1;
const struct dirent *ent;
DIR *dir;
int save, rc;
@@ -206,15 +210,16 @@ int _aa_dirat_for_each2(int dirfd, const char *name, void *data,
PDEBUG("could not open directory fd '%d' '%s': %m\n", dirfd, name);
return -1;
}
dir = fdopendir(cb_dirfd);
if (!dir) {
PDEBUG("could not open directory '%s' from fd '%d': %m\n", name, cb_dirfd);
/* dup cd_dirfd because fdopendir has claimed the fd passed to it */
fd_for_dir = dup(cb_dirfd);
if (fd_for_dir == -1) {
PDEBUG("could not dup directory fd '%s': %m\n", name);
return -1;
}
/* dup cd_dirfd because fdopendir has claimed the fd passed to it */
cb_dirfd = dup(cb_dirfd);
dir = fdopendir(fd_for_dir);
if (!dir) {
PDEBUG("could not dup directory fd '%s': %m\n", name);
PDEBUG("could not open directory '%s' from fd '%d': %m\n", name, fd_for_dir);
close(fd_for_dir);
return -1;
}
@@ -273,60 +278,131 @@ static int insert(struct overlaydir **overlayptr, int *max_size, int *size,
#define merge(overlay, n_overlay, max_size, list, n_list, dirfd) \
({ \
int i, j; \
int y, z; \
int rc = 0; \
\
for (i = 0, j = 0; i < n_overlay && j < n_list; ) { \
int res = strcmp(overlay[i].dent->d_name, list[j]->d_name);\
for (y = 0, z = 0; y < n_overlay && z < n_list; ) { \
int res = strcmp(overlay[y].dent->d_name, list[z]->d_name);\
if (res < 0) { \
i++; \
y++; \
continue; \
} else if (res == 0) { \
free(list[j]); \
list[j] = NULL; \
i++; \
j++; \
free(list[z]); \
list[z] = NULL; \
y++; \
z++; \
} else { \
if ((rc = insert(&overlay, &max_size, &n_overlay, i,\
n_list - j, dirfd, list[j]))) \
if ((rc = insert(&overlay, &max_size, &n_overlay, y,\
n_list - z, dirfd, list[z]))) \
goto fail; \
i++; \
list[j++] = NULL; \
y++; \
list[z++] = NULL; \
} \
} \
while (j < n_list) { \
if ((rc = insert(&overlay, &max_size, &n_overlay, i, \
n_list - j, dirfd,list[j]))) \
while (z < n_list) { \
if ((rc = insert(&overlay, &max_size, &n_overlay, y, \
n_list - z, dirfd,list[z]))) \
goto fail; \
i++; \
list[j++] = NULL; \
y++; \
list[z++] = NULL; \
} \
\
fail: \
rc; \
})
static ssize_t readdirfd(int dirfd, struct dirent ***out,
int (*dircmp)(const struct dirent **, const struct dirent **))
{
struct dirent **dents = NULL, *dent;
ssize_t n = 0, i;
int save;
DIR *dir;
*out = NULL;
/*
* closedir(dir) will close the underlying fd, so we need
* to dup first
*/
if ((dirfd = dup(dirfd)) < 0) {
PDEBUG("dup of dirfd failed: %m\n");
return -1;
}
if ((dir = fdopendir(dirfd)) == NULL) {
PDEBUG("fdopendir of dirfd failed: %m\n");
close(dirfd);
return -1;
}
/* Get number of directory entries */
while ((dent = readdir(dir)) != NULL) {
if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
continue;
n++;
}
rewinddir(dir);
dents = calloc(n, sizeof(struct dirent *));
if (!dents)
goto fail;
for (i = 0; i < n; ) {
if ((dent = readdir(dir)) == NULL) {
PDEBUG("readdir of entry[%d] failed: %m\n", i);
goto fail;
}
if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
continue;
dents[i] = malloc(sizeof(*dents[i]));
if (!dents[i])
goto fail;
memcpy(dents[i], dent, sizeof(*dent));
i++;
}
if (dircmp)
qsort(dents, n, sizeof(struct dirent *), (int (*)(const void *, const void *))dircmp);
*out = dents;
closedir(dir);
return n;
fail:
save = errno;
if (dents) {
for (i = 0; i < n; i++)
free(dents[i]);
}
free(dents);
closedir(dir);
errno = save;
return -1;
}
int _aa_overlaydirat_for_each(int dirfd[], int n, void *data,
int (* cb)(int, const char *, struct stat *, void *))
{
autofree struct dirent **list = NULL;
autofree struct overlaydir *overlay = NULL;
int i, k;
int i;
int n_list, size = 0, max_size = 0;
int rc = 0;
for (i = 0; i < n; i++) {
n_list = scandirat(dirfd[i], ".", &list, dot_or_dot_dot_filter,
alphasort);
n_list = readdirfd(dirfd[i], &list, alphasort);
if (n_list == -1) {
PDEBUG("scandirat of dirfd[%d] failed: %m\n", i);
return -1;
}
if (merge(overlay, size, max_size, list, n_list, dirfd[i])) {
for (k = 0; k < n_list; k++)
for (i = 0; i < n_list; i++)
free(list[i]);
for (k = 0; k < size; k++)
free(overlay[k].dent);
for (i = 0; i < size; i++)
free(overlay[i].dent);
return -1;
}
}
@@ -376,7 +452,8 @@ int _aa_overlaydirat_for_each(int dirfd[], int n, void *data,
*
* The cb function is called with the DIR in use and the name of the
* file in that directory. If the file is to be opened it should
* use the openat, fstatat, and related fns.
* use the openat, fstatat, and related fns. If the file is a symlink
* _aa_dirat_for_each currently tries to traverse it for the caller
*
* Returns: 0 on success, else -1 and errno is set to the error code
*/
@@ -398,8 +475,7 @@ int _aa_dirat_for_each(int dirfd, const char *name, void *data,
return -1;
}
num_dirs = scandirat(cb_dirfd, ".", &namelist,
dot_or_dot_dot_filter, NULL);
num_dirs = readdirfd(cb_dirfd, &namelist, alphasort);
if (num_dirs == -1) {
PDEBUG("scandirat of directory '%s' failed: %m\n", name);
return -1;
@@ -410,14 +486,34 @@ int _aa_dirat_for_each(int dirfd, const char *name, void *data,
autofree struct dirent *dir = namelist[i];
struct stat my_stat;
if (rc)
continue;
if (fstatat(cb_dirfd, dir->d_name, &my_stat, 0)) {
if (fstatat(cb_dirfd, dir->d_name, &my_stat, AT_SYMLINK_NOFOLLOW)) {
PDEBUG("stat failed for '%s': %m\n", dir->d_name);
rc = -1;
continue;
}
/* currently none of the callers handle symlinks, and this
* same basic code was applied to each. So for this patch
* just drop it here.
*
* Going forward we need to start handling symlinks as
* they have meaning.
* In the case of
* cache: they act as a place holder for files that have been
* combined into a single binary. This enables the
* file based cache lookup time find that relation
* and dedup, so multiple loads aren't done.
* profiles: just a profile in an alternate location, but
* should do dedup detection when doing dir reads
* so we don't double process.
*/
if (S_ISLNK(my_stat.st_mode)) {
/* just traverse the symlink */
if (fstatat(cb_dirfd, dir->d_name, &my_stat, 0)) {
PDEBUG("symlink target stat failed for '%s': %m\n", dir->d_name);
rc = -1;
continue;
}
}
if (cb(cb_dirfd, dir->d_name, &my_stat, data)) {
PDEBUG("dir_for_each callback failed for '%s'\n",

View File

@@ -72,7 +72,7 @@ void string_buf_append(unsigned int length, char *text)
%}
ws [ \t\r\n]
ws [ \t\r\n\x1d]
equals "="
digit [[:digit:]]
@@ -121,6 +121,8 @@ key_namespace "namespace"
key_mask "mask"
key_denied_mask "denied_mask"
key_requested_mask "requested_mask"
key_denied "denied"
key_requested "requested"
key_attribute "attribute"
key_task "task"
key_parent "parent"
@@ -131,12 +133,16 @@ key_pid "pid"
key_peer_pid "peer_pid"
key_profile "profile"
key_peer_profile "peer_profile"
key_label "label"
key_peer_label "peer_label"
key_family "family"
key_sock_type "sock_type"
key_protocol "protocol"
key_error "error"
key_fsuid "fsuid"
key_fsuid_upper "FSUID"
key_ouid "ouid"
key_ouid_upper "OUID"
key_uid "uid"
key_auid "auid"
key_sauid "sauid"
@@ -159,17 +165,20 @@ key_dest "dest"
key_path "path"
key_interface "interface"
key_member "member"
key_method "method"
key_signal "signal"
key_peer "peer"
key_fstype "fstype"
key_flags "flags"
key_srcname "srcname"
key_class "class"
audit "audit"
/* network addrs */
ip_addr [a-f[:digit:].:]{3,}
/* syslog tokens */
socklogd_kernel kern.notice{colon}
syslog_kernel kernel{colon}
syslog_user [[:alnum:]_-]+\[[[:digit:]]+\]{colon}
syslog_yyyymmdd {digit}{4}{minus}{digit}{2}{minus}{digit}{2}
@@ -304,6 +313,8 @@ yy_flex_debug = 0;
{key_mask} { return(TOK_KEY_MASK); }
{key_denied_mask} { return(TOK_KEY_DENIED_MASK); }
{key_requested_mask} { return(TOK_KEY_REQUESTED_MASK); }
{key_denied} { return(TOK_KEY_DENIED_MASK); }
{key_requested} { return(TOK_KEY_REQUESTED_MASK); }
{key_attribute} { BEGIN(sub_id); return(TOK_KEY_ATTRIBUTE); }
{key_task} { return(TOK_KEY_TASK); }
{key_parent} { return(TOK_KEY_PARENT); }
@@ -314,12 +325,16 @@ yy_flex_debug = 0;
{key_peer_pid} { return(TOK_KEY_PEER_PID); }
{key_profile} { BEGIN(safe_string); return(TOK_KEY_PROFILE); }
{key_peer_profile} { BEGIN(safe_string); return(TOK_KEY_PEER_PROFILE); }
{key_label} { BEGIN(safe_string); return(TOK_KEY_LABEL); }
{key_peer_label} { BEGIN(safe_string); return(TOK_KEY_PEER_LABEL); }
{key_family} { return(TOK_KEY_FAMILY); }
{key_sock_type} { return(TOK_KEY_SOCK_TYPE); }
{key_protocol} { return(TOK_KEY_PROTOCOL); }
{key_error} { return(TOK_KEY_ERROR); }
{key_fsuid} { return(TOK_KEY_FSUID); }
{key_fsuid_upper} { return(TOK_KEY_FSUID_UPPER); }
{key_ouid} { return(TOK_KEY_OUID); }
{key_ouid_upper} { return(TOK_KEY_OUID_UPPER); }
{key_uid} { return(TOK_KEY_UID); }
{key_auid} { return(TOK_KEY_AUID); }
{key_sauid} { return(TOK_KEY_SAUID); }
@@ -341,12 +356,15 @@ yy_flex_debug = 0;
{key_path} { return(TOK_KEY_PATH); }
{key_interface} { return(TOK_KEY_INTERFACE); }
{key_member} { return(TOK_KEY_MEMBER); }
{key_method} { return(TOK_KEY_MEMBER); }
{key_signal} { BEGIN(sub_id); return(TOK_KEY_SIGNAL); }
{key_peer} { BEGIN(safe_string); return(TOK_KEY_PEER); }
{key_fstype} { return(TOK_KEY_FSTYPE); }
{key_flags} { BEGIN(safe_string); return(TOK_KEY_FLAGS); }
{key_srcname} { BEGIN(safe_string); return(TOK_KEY_SRCNAME); }
{key_class} { BEGIN(safe_string); return(TOK_KEY_CLASS); }
{socklogd_kernel} { BEGIN(dmesg_timestamp); return(TOK_SOCKLOGD_KERNEL); }
{syslog_kernel} { BEGIN(dmesg_timestamp); return(TOK_SYSLOG_KERNEL); }
{syslog_user} { return(TOK_SYSLOG_USER); }
{syslog_month} { yylval->t_str = strdup(yytext); return(TOK_DATE_MONTH); }
@@ -361,6 +379,7 @@ yy_flex_debug = 0;
<hostname>{
{ws}+ { /* eat whitespace */ }
{socklogd_kernel} { BEGIN(dmesg_timestamp); return(TOK_SOCKLOGD_KERNEL); }
{syslog_hostname} { yylval->t_str = strdup(yytext); BEGIN(INITIAL); return(TOK_ID); }
}

View File

@@ -12,6 +12,7 @@ LibAppArmor.pm: libapparmor_wrap.c
Makefile.perl: Makefile.PL LibAppArmor.pm
$(PERL) $< PREFIX=$(prefix) MAKEFILE=$@
sed -ie 's/LD_RUN_PATH="\x24(LD_RUN_PATH)"//g' Makefile.perl
sed -ie 's/^LD_RUN_PATH.*//g' Makefile.perl
LibAppArmor.so: libapparmor_wrap.c Makefile.perl

View File

@@ -1,5 +1,8 @@
if HAVE_PYTHON
COMMONDIR = $(top_srcdir)/../../common/
include $(COMMONDIR)/Make.rules
EXTRA_DIST = libapparmor_wrap.c
SUBDIRS = test
@@ -11,14 +14,14 @@ MOSTLYCLEANFILES=libapparmor_wrap.c LibAppArmor.py
all-local: libapparmor_wrap.c setup.py
if test ! -f libapparmor_wrap.c; then cp $(srcdir)/libapparmor_wrap.c . ; fi
$(PYTHON) setup.py build
CC="$(CC)" CFLAGS="$(PYTHON_CPPFLAGS) $(EXTRA_WARNINGS)" LDSHARED="$(CC) -shared" LDFLAGS="$(PYTHON_LDFLAGS) $(LDFLAGS)" $(PYTHON) setup.py build
install-exec-local:
$(PYTHON) setup.py install --root="/$(DESTDIR)" --prefix="$(prefix)"
clean-local:
if test -x "$(PYTHON)"; then $(PYTHON) setup.py clean; fi
rm -rf build
rm -rf build LibAppArmor.egg-info
if test $(top_srcdir) != $(top_builddir) ; then rm -f libapparmor_wrap.c ; fi
endif

View File

@@ -1,6 +1 @@
import sys
if sys.version_info[0] >= 3:
from LibAppArmor.LibAppArmor import *
else:
from .LibAppArmor import *
from LibAppArmor.LibAppArmor import *

View File

@@ -1,11 +1,11 @@
from distutils.core import setup, Extension
from setuptools import setup, Extension
import string
setup(name = 'LibAppArmor',
version = '@VERSION@',
author = 'AppArmor Dev Team',
author_email = 'apparmor@lists.ubuntu.com',
url = 'http://wiki.apparmor.net',
url = 'https://wiki.apparmor.net',
description = 'AppArmor python bindings',
download_url = 'https://launchpad.net/apparmor/+download',
package_dir = {'LibAppArmor': '@srcdir@'},

Some files were not shown because too many files have changed in this diff Show More