Commit graph

5658 commits

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