Commit graph

5872 commits

Author SHA1 Message Date
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