mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 08:24:42 +01:00
parser: add equality tests for network port range
To run the network port range equality tests, we need to check if the kernel supports the network_v8/af_inet feature. Also, a new file features.af_inet is needed containing the af_inet feature. Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
This commit is contained in:
parent
f9621054d7
commit
93f3a0fa99
2 changed files with 186 additions and 1 deletions
|
@ -28,10 +28,12 @@ APPARMOR_PARSER="${APPARMOR_PARSER:-${_SCRIPTDIR}/../apparmor_parser}"
|
|||
fails=0
|
||||
errors=0
|
||||
verbose="${VERBOSE:-}"
|
||||
default_features_file="features.all"
|
||||
features_file=$default_features_file
|
||||
|
||||
hash_binary_policy()
|
||||
{
|
||||
printf %s "$1" | ${APPARMOR_PARSER} --features-file "${_SCRIPTDIR}/features_files/features.all" -qS 2>/dev/null| md5sum | cut -d ' ' -f 1
|
||||
printf %s "$1" | ${APPARMOR_PARSER} --features-file "${_SCRIPTDIR}/features_files/$features_file" -qS 2>/dev/null| md5sum | cut -d ' ' -f 1
|
||||
return $?
|
||||
}
|
||||
|
||||
|
@ -122,6 +124,39 @@ verify_binary_inequality()
|
|||
verify_binary "inequality" "$@"
|
||||
}
|
||||
|
||||
# kernel_features - test whether path(s) are present
|
||||
# $@: feature path(s) to test
|
||||
# Returns: 0 and outputs "true" if all paths exist
|
||||
# 1 and error message if features dir is not available
|
||||
# 2 and error message if path does not exist
|
||||
kernel_features()
|
||||
{
|
||||
features_dir="/sys/kernel/security/apparmor/features/"
|
||||
if [ ! -e "$features_dir" ] ; then
|
||||
echo "Kernel feature masks not supported."
|
||||
return 1;
|
||||
fi
|
||||
|
||||
for f in $@ ; do
|
||||
if [ ! -e "$features_dir/$f" ] ; then
|
||||
# check if feature is in file
|
||||
feature=$(basename "$features_dir/$f")
|
||||
file=$(dirname "$features_dir/$f")
|
||||
if [ -f $file ]; then
|
||||
if ! grep -q $feature $file; then
|
||||
echo "Required feature '$f' not available."
|
||||
return 2;
|
||||
fi
|
||||
else
|
||||
echo "Required feature '$f' not available."
|
||||
return 3;
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
echo "true"
|
||||
return 0;
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
### wrapper fn, should be indented but isn't to reduce wrap
|
||||
|
@ -787,6 +822,39 @@ verify_binary_equality "set rlimit memlock <= 2GB" \
|
|||
"/t { set rlimit memlock <= $((2 * 1024 * 1024)) KB, }" \
|
||||
"/t { set rlimit memlock <= $((2 * 1024 * 1024 * 1024)) , }"
|
||||
|
||||
run_port_range=$(kernel_features network_v8/af_inet)
|
||||
if [ "$run_port_range" != "true" ]; then
|
||||
echo -e "\nSkipping network af_inet tests. $run_port_range\n"
|
||||
else
|
||||
# network port range
|
||||
# select features file that contains netv8 af_inet
|
||||
features_file="features.af_inet"
|
||||
verify_binary_equality "network port range" \
|
||||
"/t { network port=3456-3460, }" \
|
||||
"/t { network port=3456, \
|
||||
network port=3457, \
|
||||
network port=3458, \
|
||||
network port=3459, \
|
||||
network port=3460, }"
|
||||
|
||||
verify_binary_equality "network peer port range" \
|
||||
"/t { network peer=(port=3456-3460), }" \
|
||||
"/t { network peer=(port=3456), \
|
||||
network peer=(port=3457), \
|
||||
network peer=(port=3458), \
|
||||
network peer=(port=3459), \
|
||||
network peer=(port=3460), }"
|
||||
|
||||
verify_binary_inequality "network port range allows more than single port" \
|
||||
"/t { network port=3456-3460, }" \
|
||||
"/t { network port=3456, }"
|
||||
|
||||
verify_binary_inequality "network peer port range allows more than single port" \
|
||||
"/t { network peer=(port=3456-3460), }" \
|
||||
"/t { network peer=(port=3456), }"
|
||||
# return to default
|
||||
features_file=$default_features_file
|
||||
fi
|
||||
|
||||
# verify combinations of different priority levels
|
||||
# for single rule comparisons, rules should keep same expected result
|
||||
|
|
117
parser/tst/features_files/features.af_inet
Normal file
117
parser/tst/features_files/features.af_inet
Normal file
|
@ -0,0 +1,117 @@
|
|||
capability {0xffffff
|
||||
}
|
||||
caps {extended {yes
|
||||
}
|
||||
mask {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 setfcap mac_override mac_admin syslog wake_alarm block_suspend audit_read perfmon bpf checkpoint_restore
|
||||
}
|
||||
}
|
||||
dbus {mask {acquire send receive
|
||||
}
|
||||
}
|
||||
domain {attach_conditions {xattr {yes
|
||||
}
|
||||
}
|
||||
change_hat {yes
|
||||
}
|
||||
change_hatv {yes
|
||||
}
|
||||
change_onexec {yes
|
||||
}
|
||||
change_profile {yes
|
||||
}
|
||||
computed_longest_left {yes
|
||||
}
|
||||
disconnected.path {yes
|
||||
}
|
||||
fix_binfmt_elf_mmap {yes
|
||||
}
|
||||
interruptible {yes
|
||||
}
|
||||
kill.signal {yes
|
||||
}
|
||||
post_nnp_subset {yes
|
||||
}
|
||||
stack {yes
|
||||
}
|
||||
unconfined_allowed_children {yes
|
||||
}
|
||||
version {1.2
|
||||
}
|
||||
}
|
||||
file {mask {create read write exec append mmap_exec link lock
|
||||
}
|
||||
}
|
||||
io_uring {mask {sqpoll override_creds
|
||||
}
|
||||
}
|
||||
ipc {posix_mqueue {create read write open delete setattr getattr
|
||||
}
|
||||
}
|
||||
mount {mask {mount umount pivot_root
|
||||
}
|
||||
move_mount {detached
|
||||
}
|
||||
}
|
||||
namespaces {mask {userns_create
|
||||
}
|
||||
pivot_root {no
|
||||
}
|
||||
profile {yes
|
||||
}
|
||||
userns_create {pciu&
|
||||
}
|
||||
}
|
||||
network {af_mask {unspec unix inet ax25 ipx appletalk netrom bridge atmpvc x25 inet6 rose netbeui security key netlink packet ash econet atmsvc rds sna irda pppox wanpipe llc ib mpls can tipc bluetooth iucv rxrpc isdn phonet ieee802154 caif alg nfc vsock kcm qipcrtr smc xdp mctp
|
||||
}
|
||||
af_unix {yes
|
||||
}
|
||||
}
|
||||
network_v8 {af_inet {yes
|
||||
}
|
||||
af_mask {unspec unix inet ax25 ipx appletalk netrom bridge atmpvc x25 inet6 rose netbeui security key netlink packet ash econet atmsvc rds sna irda pppox wanpipe llc ib mpls can tipc bluetooth iucv rxrpc isdn phonet ieee802154 caif alg nfc vsock kcm qipcrtr smc xdp mctp
|
||||
}
|
||||
}
|
||||
policy {outofband {0x000001
|
||||
}
|
||||
permstable32 {allow deny subtree cond kill complain prompt audit quiet hide xindex tag label
|
||||
}
|
||||
permstable32_version {0x000003
|
||||
}
|
||||
set_load {yes
|
||||
}
|
||||
unconfined_restrictions {change_profile {yes
|
||||
}
|
||||
io_uring {0
|
||||
}
|
||||
userns {1
|
||||
}
|
||||
}
|
||||
versions {v5 {yes
|
||||
}
|
||||
v6 {yes
|
||||
}
|
||||
v7 {yes
|
||||
}
|
||||
v8 {yes
|
||||
}
|
||||
v9 {yes
|
||||
}
|
||||
}
|
||||
}
|
||||
ptrace {mask {read trace
|
||||
}
|
||||
}
|
||||
query {label {data {yes
|
||||
}
|
||||
multi_transaction {yes
|
||||
}
|
||||
perms {allow deny audit quiet
|
||||
}
|
||||
}
|
||||
}
|
||||
rlimit {mask {cpu fsize data stack core rss nproc nofile memlock as locks sigpending msgqueue nice rtprio rttime
|
||||
}
|
||||
}
|
||||
signal {mask {hup int quit ill trap abrt bus fpe kill usr1 segv usr2 pipe alrm term stkflt chld cont stop stp ttin ttou urg xcpu xfsz vtalrm prof winch io pwr sys emt lost
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue