Commit 17f0565a authored by Steve Beattie's avatar Steve Beattie

add optional allow prefix to the language

From: John Johansen <john.johansen@canonical.com>

let allow be used as a prefix in place of deny.  Allow is the default
and is implicit so it is not needed but some user keep tripping over
it, and it makes the language more symmetric

   eg.
      /foo rw,
      allow /foo rw,
      deny /foo rw,

Patch history:
  v1: - initial revision

  v2: - rename yacc target rule from opt_deny to opt_perm_mode to
reflect
        that it can be either an allow or deny modifier
      - break apart tests into more digestible chunks and to clarify
        their purpose
      - fix some tests to exercise 'audit allow'
      - add negative tests for 'allow' and 'deny' in the same rule
      - add support for 'allow' keyword to apparmor.vim
      - fix a bug in apparmor.vim to let it recognize multiple
        capability entries in a single line.

  v3: - add support for optional keywords on capability rules in
        regression tests, as well as the bare capability keyword (via
        'cap:ALL')
      - add allow, deny, and conflicting capability behavioral
        regression tests
      - fix vim syntax modeline to refer to apparmor in parser tests
      - adjust FILE regex in vim syntax file creator script
Signed-off-by: default avatarJohn Johansen <john.johansen@canonical.com>
Signed-off-by: Steve Beattie's avatarSteve Beattie <steve@nxnw.org>
Acked-by: default avatarSeth Arnold <seth.arnold@canonical.com>
parent ec738148
......@@ -74,6 +74,7 @@ static struct keyword_table keyword_table[] = {
{"subset", TOK_SUBSET},
{"audit", TOK_AUDIT},
{"deny", TOK_DENY},
{"allow", TOK_ALLOW},
{"set", TOK_SET},
{"rlimit", TOK_RLIMIT},
{"alias", TOK_ALIAS},
......
......@@ -111,6 +111,7 @@ void add_local_entry(struct codomain *cod);
%token TOK_SUBSET
%token TOK_AUDIT
%token TOK_DENY
%token TOK_ALLOW
%token TOK_PROFILE
%token TOK_SET
%token TOK_ALIAS
......@@ -223,7 +224,7 @@ void add_local_entry(struct codomain *cod);
%type <boolean> opt_owner_flag
%type <boolean> opt_profile_flag
%type <boolean> opt_flags
%type <boolean> opt_deny
%type <boolean> opt_perm_mode
%type <id> opt_namespace
%type <id> opt_id
%type <prefix> opt_prefix
......@@ -518,10 +519,11 @@ opt_owner_flag: { /* nothing */ $$ = 0; }
| TOK_OWNER { $$ = 1; };
| TOK_OTHER { $$ = 2; };
opt_deny: { /* nothing */ $$ = 0; }
opt_perm_mode: { /* nothing */ $$ = 0; }
| TOK_ALLOW { $$ = 0; }
| TOK_DENY { $$ = 1; }
opt_prefix: opt_audit_flag opt_deny opt_owner_flag
opt_prefix: opt_audit_flag opt_perm_mode opt_owner_flag
{
$$.audit = $1;
$$.deny = $2;
......
#
#=DESCRIPTION fail conflicting perm mod same line
#=EXRESULT FAIL
# vim:syntax=apparmor
# Last Modified: Sun Apr 17 19:44:44 2005
#
/does/not/exist {
allow deny capability chown,
}
#
#=DESCRIPTION fail conflicting perm mod same line
#=EXRESULT FAIL
# vim:syntax=apparmor
# Last Modified: Sun Apr 17 19:44:44 2005
#
/does/not/exist {
audit allow deny capability chown,
}
#
#=DESCRIPTION validate uses of allow/capabilities.
#=EXRESULT PASS
# vim:syntax=apparmor
# Last Modified: Sun Apr 17 19:44:44 2005
#
/does/not/exist {
allow capability chown,
allow capability dac_override,
allow capability dac_read_search,
allow capability fowner,
allow capability fsetid,
allow capability kill,
allow capability setgid,
allow capability setuid,
allow capability setpcap,
allow capability linux_immutable,
allow capability net_bind_service,
allow capability net_broadcast,
allow capability net_admin,
allow capability net_raw,
allow capability ipc_lock,
allow capability ipc_owner,
allow capability sys_module,
allow capability sys_rawio,
allow capability sys_chroot,
allow capability sys_ptrace,
allow capability sys_pacct,
allow capability sys_admin,
allow capability sys_boot,
allow capability sys_nice,
allow capability sys_resource,
allow capability sys_time,
allow capability sys_tty_config,
allow capability mknod,
allow capability lease,
allow capability audit_write,
allow capability audit_control,
allow capability setfcap,
allow capability mac_override,
}
#
#=DESCRIPTION validate audit allow with bare capability in hat.
#=EXRESULT PASS
# vim:syntax=apparmor
# Last Modified: Sun Apr 17 19:44:44 2005
#
/does/not/exist {
^capability {
audit allow capability,
}
}
#
#=DESCRIPTION validate uses of allow/capabilities in hats
#=EXRESULT PASS
# vim:syntax=apparmor
# Last Modified: Sun Apr 17 19:44:44 2005
#
/does/not/exist2 {
^chown {
allow capability chown,
}
^dac_override {
allow capability dac_override,
}
^dac_read_search {
allow capability dac_read_search,
}
^fowner {
allow capability fowner,
}
^fsetid {
allow capability fsetid,
}
^kill {
allow capability kill,
}
^setgid {
allow capability setgid,
}
^setuid {
allow capability setuid,
}
^setpcap {
allow capability setpcap,
}
^linux_immutable {
allow capability linux_immutable,
}
^net_bind_service {
allow capability net_bind_service,
}
^net_broadcast {
allow capability net_broadcast,
}
^net_admin {
allow capability net_admin,
}
^net_raw {
allow capability net_raw,
}
^ipc_lock {
allow capability ipc_lock,
}
^ipc_owner {
allow capability ipc_owner,
}
^sys_module {
allow capability sys_module,
}
^sys_rawio {
allow capability sys_rawio,
}
^sys_chroot {
allow capability sys_chroot,
}
^sys_ptrace {
allow capability sys_ptrace,
}
^sys_pacct {
allow capability sys_pacct,
}
^sys_admin {
allow capability sys_admin,
}
^sys_boot {
allow capability sys_boot,
}
^sys_nice {
allow capability sys_nice,
}
^sys_resource {
allow capability sys_resource,
}
^sys_time {
allow capability sys_time,
}
^sys_tty_config {
allow capability sys_tty_config,
}
^mknod {
allow capability mknod,
}
^lease {
allow capability lease,
}
^audit_write {
allow capability audit_write,
}
^audit_control {
allow capability audit_control,
}
}
#
#=DESCRIPTION validate allow w/multiple capabilities in a line.
#=EXRESULT PASS
# vim:syntax=apparmor
# Last Modified: Sun Apr 17 19:44:44 2005
#
/does/not/exit101 {
allow capability chown dac_override dac_read_search fowner fsetid kill setgid setuid setpcap linux_immutable net_bind_service net_broadcast net_admin net_raw ipc_lock ipc_owner sys_module sys_rawio sys_chroot sys_ptrace sys_pacct sys_admin sys_boot sys_nice sys_resource sys_time sys_tty_config mknod lease audit_write audit_control,
}
#
#=DESCRIPTION validate audit allow w/capabilities.
#=EXRESULT PASS
# vim:syntax=apparmor
# Last Modified: Sun Apr 17 19:44:44 2005
#
/does/not/exist {
audit allow capability chown,
audit allow capability dac_override,
audit allow capability dac_read_search,
audit allow capability fowner,
audit allow capability fsetid,
audit allow capability kill,
audit allow capability setgid,
audit allow capability setuid,
audit allow capability setpcap,
audit allow capability linux_immutable,
audit allow capability net_bind_service,
audit allow capability net_broadcast,
audit allow capability net_admin,
audit allow capability net_raw,
audit allow capability ipc_lock,
audit allow capability ipc_owner,
audit allow capability sys_module,
audit allow capability sys_rawio,
audit allow capability sys_chroot,
audit allow capability sys_ptrace,
audit allow capability sys_pacct,
audit allow capability sys_admin,
audit allow capability sys_boot,
audit allow capability sys_nice,
audit allow capability sys_resource,
audit allow capability sys_time,
audit allow capability sys_tty_config,
audit allow capability mknod,
audit allow capability lease,
audit allow capability audit_write,
audit allow capability audit_control,
audit allow capability setfcap,
audit allow capability mac_override,
}
#
#=DESCRIPTION validate audit allow w/capabilities in hats.
#=EXRESULT PASS
# vim:syntax=apparmor
# Last Modified: Sun Apr 17 19:44:44 2005
#
/does/not/exist2 {
^chown {
audit allow capability chown,
}
^dac_override {
audit allow capability dac_override,
}
^dac_read_search {
audit allow capability dac_read_search,
}
^fowner {
audit allow capability fowner,
}
^fsetid {
audit allow capability fsetid,
}
^kill {
audit allow capability kill,
}
^setgid {
audit allow capability setgid,
}
^setuid {
audit allow capability setuid,
}
^setpcap {
audit allow capability setpcap,
}
^linux_immutable {
audit allow capability linux_immutable,
}
^net_bind_service {
audit allow capability net_bind_service,
}
^net_broadcast {
audit allow capability net_broadcast,
}
^net_admin {
audit allow capability net_admin,
}
^net_raw {
audit allow capability net_raw,
}
^ipc_lock {
audit allow capability ipc_lock,
}
^ipc_owner {
audit allow capability ipc_owner,
}
^sys_module {
audit allow capability sys_module,
}
^sys_rawio {
audit allow capability sys_rawio,
}
^sys_chroot {
audit allow capability sys_chroot,
}
^sys_ptrace {
audit allow capability sys_ptrace,
}
^sys_pacct {
audit allow capability sys_pacct,
}
^sys_admin {
audit allow capability sys_admin,
}
^sys_boot {
audit allow capability sys_boot,
}
^sys_nice {
audit allow capability sys_nice,
}
^sys_resource {
audit allow capability sys_resource,
}
^sys_time {
audit allow capability sys_time,
}
^sys_tty_config {
audit allow capability sys_tty_config,
}
^mknod {
audit allow capability mknod,
}
^lease {
audit allow capability lease,
}
^audit_write {
audit allow capability audit_write,
}
^audit_control {
audit allow capability audit_control,
}
}
#
#=DESCRIPTION validate audit allow w/multiple capabilities.
#=EXRESULT PASS
# vim:syntax=apparmor
# Last Modified: Sun Apr 17 19:44:44 2005
#
/does/not/exit101 {
audit allow capability chown dac_override dac_read_search fowner fsetid kill setgid setuid setpcap linux_immutable net_bind_service net_broadcast net_admin net_raw ipc_lock ipc_owner sys_module sys_rawio sys_chroot sys_ptrace sys_pacct sys_admin sys_boot sys_nice sys_resource sys_time sys_tty_config mknod lease audit_write audit_control,
}
#
#=DESCRIPTION validate allow with bare capability keyword.
#=EXRESULT PASS
# vim:syntax=apparmor
# Last Modified: Sun Apr 17 19:44:44 2005
#
/does/not/exist {
allow capability,
}
#
#=DESCRIPTION validate allow with bare capability in hat.
#=EXRESULT PASS
# vim:syntax=apparmor
# Last Modified: Sun Apr 17 19:44:44 2005
#
/does/not/exist {
^capability {
allow capability,
}
}
#
#=DESCRIPTION validate audit allow with bare capability keyword.
#=EXRESULT PASS
# vim:syntax=apparmor
# Last Modified: Sun Apr 17 19:44:44 2005
#
/does/not/exist {
audit allow capability,
}
#
#=DESCRIPTION validate allow of duplicate capabilities.
#=EXRESULT PASS
# vim:syntax=apparmor
# Last Modified: Sun Apr 17 19:44:44 2005
#
# Test for duplicates?
/does/not/exist3 {
allow capability mknod,
allow capability mknod,
}
#
#=DESCRIPTION validate audit allow of duplicate capabilities.
#=EXRESULT PASS
# vim:syntax=apparmor
# Last Modified: Sun Apr 17 19:44:44 2005
#
# Test for duplicates?
/does/not/exist3 {
audit allow capability mknod,
audit allow capability mknod,
}
#
#=DESCRIPTION validate allow of duplicate multiple capabilities.
#=EXRESULT PASS
# vim:syntax=apparmor
# Last Modified: Sun Apr 17 19:44:44 2005
#
/does/not/exit102 {
allow capability chown dac_override dac_read_search fowner fsetid kill setgid setuid setpcap linux_immutable net_bind_service net_broadcast net_admin net_raw ipc_lock ipc_owner sys_module sys_rawio sys_chroot sys_ptrace sys_pacct sys_admin sys_boot sys_nice sys_resource sys_time sys_tty_config mknod lease audit_write audit_control,
allow capability chown dac_override dac_read_search fowner fsetid kill setgid setuid setpcap linux_immutable net_bind_service net_broadcast net_admin net_raw ipc_lock ipc_owner sys_module sys_rawio sys_chroot sys_ptrace sys_pacct sys_admin sys_boot sys_nice sys_resource sys_time sys_tty_config mknod lease audit_write audit_control,
}
#
#=DESCRIPTION validate audit allow of duplicate multiple capabilities.
#=EXRESULT PASS
# vim:syntax=apparmor
# Last Modified: Sun Apr 17 19:44:44 2005
#
/does/not/exit102 {
audit allow capability chown dac_override dac_read_search fowner fsetid kill setgid setuid setpcap linux_immutable net_bind_service net_broadcast net_admin net_raw ipc_lock ipc_owner sys_module sys_rawio sys_chroot sys_ptrace sys_pacct sys_admin sys_boot sys_nice sys_resource sys_time sys_tty_config mknod lease audit_write audit_control,
audit allow capability chown dac_override dac_read_search fowner fsetid kill setgid setuid setpcap linux_immutable net_bind_service net_broadcast net_admin net_raw ipc_lock ipc_owner sys_module sys_rawio sys_chroot sys_ptrace sys_pacct sys_admin sys_boot sys_nice sys_resource sys_time sys_tty_config mknod lease audit_write audit_control,
}
#
#=DESCRIPTION validate duplicate multiple capabilities w/differing perm mods.
#=EXRESULT PASS
# vim:syntax=apparmor
# Last Modified: Sun Apr 17 19:44:44 2005
#
/does/not/exit102 {
allow capability chown dac_override dac_read_search fowner fsetid kill setgid setuid setpcap linux_immutable net_bind_service net_broadcast net_admin net_raw ipc_lock ipc_owner sys_module sys_rawio sys_chroot sys_ptrace sys_pacct sys_admin sys_boot sys_nice sys_resource sys_time sys_tty_config mknod lease audit_write audit_control,
audit allow capability chown dac_override dac_read_search fowner fsetid kill setgid setuid setpcap linux_immutable net_bind_service net_broadcast net_admin net_raw ipc_lock ipc_owner sys_module sys_rawio sys_chroot sys_ptrace sys_pacct sys_admin sys_boot sys_nice sys_resource sys_time sys_tty_config mknod lease audit_write audit_control,
audit deny capability chown dac_override dac_read_search fowner fsetid kill setgid setuid setpcap linux_immutable net_bind_service net_broadcast net_admin net_raw ipc_lock ipc_owner sys_module sys_rawio sys_chroot sys_ptrace sys_pacct sys_admin sys_boot sys_nice sys_resource sys_time sys_tty_config mknod lease audit_write audit_control,
deny capability chown dac_override dac_read_search fowner fsetid kill setgid setuid setpcap linux_immutable net_bind_service net_broadcast net_admin net_raw ipc_lock ipc_owner sys_module sys_rawio sys_chroot sys_ptrace sys_pacct sys_admin sys_boot sys_nice sys_resource sys_time sys_tty_config mknod lease audit_write audit_control,
}
#
#=DESCRIPTION validate duplicate capability entries.
#=EXRESULT PASS
# vim:syntax=apparmor
# Last Modified: Sun Apr 17 19:44:44 2005
#
# Test for duplicates?
/does/not/exist3 {
capability mknod,
audit allow capability mknod,
deny capability mknod,
audit allow capability mknod,
deny capability mknod,
allow capability mknod,
}
#
#=Description basic file rule
#=EXRESULT PASS
# vim:syntax=apparmor
#
/usr/bin/foo {
allow /usr/bin/foo r,
}
#
#=DESCRIPTION A simple successful profile
#=EXRESULT PASS
# vim:syntax=apparmor
#
/usr/bin/foo {
allow /usr/bin/foo r,
allow /usr/bin/blah rix,
}
#
#=DESCRIPTION test append
#=EXRESULT PASS
# vim:syntax=apparmor
#
/usr/bin/foo {
allow /bin/cat a,
allow /bin/true ra,
allow /bin/false ma,
allow /lib/libc.so la,
allow /bin/less ixa,
allow /bin/more pxa,
allow /a uxa,
}
#
#=DESCRIPTION carat in pathname
#=EXRESULT PASS
# vim:syntax=apparmor
#
/usr/bin/foo {
allow /foo^bar r,
}
#
#=DESCRIPTION trailing carat in pathname
#=EXRESULT PASS
# vim:syntax=apparmor
#
/usr/bin/foo {
allow /foo/bar^ r,
}
#
#=DESCRIPTION comma in pathname
#=EXRESULT PASS
# vim:syntax=apparmor
#
/usr/bin/foo {
allow /foo,bar r,
}
#
#=DESCRIPTION comma at end of pathname
#=EXRESULT PASS
# vim:syntax=apparmor
#
/usr/bin/foo {
allow "/foobar," r,
}
#=DESCRIPTION Simple test case for embedded spaces
#=EXRESULT PASS
# vim:syntax=apparmor
/bin/foo {
allow "/abc\ def" r,
}
#=DESCRIPTION Simple test case for embedded spaces
#=EXRESULT PASS
# vim:syntax=apparmor
/bin/foo {
allow "/abc def" r,
}
#=DESCRIPTION Simple test case for embedded spaces
#=EXRESULT PASS
# vim:syntax=apparmor
"/bin/fo o" {
allow "/abc def" r,
}
#
#=DESCRIPTION carat in pathname
#=EXRESULT PASS
# vim:syntax=apparmor
#
/usr/bin/foo {
allow /foo[^me]bar r,
}
#
#=DESCRIPTION k and other perms do not conflict
#=EXRESULT PASS
# vim:syntax=apparmor
#
/usr/bin/foo {
allow /bin/a k,
allow /bin/b rk,
allow /bin/c wk,
allow /bin/d ak,
allow /bin/e lk,
allow /bin/e mk,
allow /bin/f pxk,
allow /bin/g Pxk,
allow /bin/h ixk,
allow /bin/i uxk,
allow /bin/j Uxk,
}
#
#=DESCRIPTION m and [uUpPi]x do not conflict
#=EXRESULT PASS
# vim:syntax=apparmor
#
/usr/bin/foo {
allow /bin/cat mix,
allow /bin/true mpx,
allow /bin/false mux,
allow /lib/libc.so rwlm,
allow /bin/less mUx,
allow /bin/more mPx,
}
#
#=DESCRIPTION m and [upi]x do not conflict, seperate rules
#=EXRESULT PASS
# vim:syntax=apparmor
#
/usr/bin/foo {
allow /bin/cat rm,
allow /bin/cat ix,
allow /bin/true px,
allow /bin/true m,
allow /bin/false m,
allow /bin/false ux,
allow /lib/libc.so rwl,
allow /lib/libc.so m,
}
......@@ -91,10 +91,17 @@ for TEST in ${TESTS} ; do
my_entries=$(eval echo \${${TEST}_extra_entries})
settest ${TEST}
# base case, unconfined
runchecktest "${TEST} -- unconfined" pass ${my_arg}
# no capabilities allowed
genprofile ${my_entries}
runchecktest "${TEST} -- no caps" fail ${my_arg}
# all capabilities allowed
genprofile cap:ALL ${my_entries}
runchecktest "${TEST} -- all caps" pass ${my_arg}
# iterate through each of the capabilities
for cap in ${CAPABILITIES} ; do
if [ "X$(eval echo \${${TEST}_${cap}})" == "XTRUE" ] ; then
......@@ -111,6 +118,11 @@ for TEST in ${TESTS} ; do
settest ${testwrapper}
genprofile hat:$bin/${TEST} addimage:${bin}/${TEST} ${my_entries}
runchecktest "${TEST} changehat -- no caps" fail $bin/${TEST} ${my_arg}
# all capabilities allowed
genprofile hat:$bin/${TEST} addimage:${bin}/${TEST} cap:ALL ${my_entries}
runchecktest "${TEST} changehat -- all caps" pass $bin/${TEST} ${my_arg}
for cap in ${CAPABILITIES} ; do
if [ "X$(eval echo \${${TEST}_${cap}})" == "XTRUE" ] ; then
expected_result=pass
......@@ -123,3 +135,79 @@ for TEST in ${TESTS} ; do
done
cap=sys_chroot
settest syscall_chroot
# test deny keyword works
genprofile cap:${cap}:deny ${syscall_chroot_extra_entries}
runchecktest "syscall_chroot -- capability ${cap}, deny keyword" fail ${syscall_chroot_args}
# test allow keyword works
genprofile cap:${cap}:allow ${syscall_chroot_extra_entries}
runchecktest "syscall_chroot -- capability ${cap}, allow keyword" pass ${syscall_chroot_args}
### allow/deny overlap tests ###
# test allow & deny keyword behavior, allow first
genprofile cap:${cap}:allow cap:${cap}:deny ${syscall_chroot_extra_entries}
runchecktest "syscall_chroot -- capability ${cap}, allow & deny keyword, allow first" fail ${syscall_chroot_args}
# test implicit allow & deny keyword behavior, allow first
genprofile cap:${cap} cap:${cap}:deny ${syscall_chroot_extra_entries}
runchecktest "syscall_chroot -- capability ${cap}, implicit allow & deny keyword, allow first" fail ${syscall_chroot_args}
# test allow & deny keyword behavior, deny first
genprofile cap:${cap}:deny cap:${cap}:allow ${syscall_chroot_extra_entries}
runchecktest "syscall_chroot -- capability ${cap}, allow & deny keyword, deny first" fail ${syscall_chroot_args}
# test implicit allow & deny keyword behavior, deny first
genprofile cap:${cap}:deny cap:${cap} ${syscall_chroot_extra_entries}
runchecktest "syscall_chroot -- capability ${cap}, implicit allow & deny keyword, deny first" fail ${syscall_chroot_args}