From: Mimi Zohar <zohar@linux.ibm.com>
To: Roberto Sassu <roberto.sassu@huaweicloud.com>, dmitry.kasatkin@gmail.com
Cc: linux-integrity@vger.kernel.org, vt@altlinux.org, pvorel@suse.cz,
stefanb@linux.ibm.com, Roberto Sassu <roberto.sassu@huawei.com>
Subject: Re: [PATCH ima-evm-utils v2] Add ima_policy_check.awk and ima_policy_check.test
Date: Wed, 15 Feb 2023 22:22:21 -0500 [thread overview]
Message-ID: <f00d6ea8df825b38f1df62cd2487fb4467c7ab48.camel@linux.ibm.com> (raw)
In-Reply-To: <20230214152258.3553294-1-roberto.sassu@huaweicloud.com>
Hi Roberto,
> diff --git a/tests/ima_policy_check.awk b/tests/ima_policy_check.awk
> new file mode 100755
> index 00000000000..73107d01083
> --- /dev/null
> +++ b/tests/ima_policy_check.awk
> @@ -0,0 +1,176 @@
> +#! /usr/bin/gawk -f
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# Copyright (C) 2023 Roberto Sassu <roberto.sassu@huawei.com>
> +#
> +# Check a new rule against the loaded IMA policy.
> +#
> +# Documentation/ABI/testing/ima_policy (Linux kernel)
> +# base: [[func=] [mask=] [fsmagic=] [fsuuid=] [fsname=]
> +# [uid=] [euid=] [gid=] [egid=]
> +# [fowner=] [fgroup=]]
> +# lsm: [[subj_user=] [subj_role=] [subj_type=]
> +# [obj_user=] [obj_role=] [obj_type=]]
> +# option: [digest_type=] [template=] [permit_directio]
> +# [appraise_type=] [appraise_flag=]
> +# [appraise_algos=] [keyrings=]
> +#
> +# Rules don't overlap if there is at least one policy keyword (in base or lsm)
> +# providing a different value.
The above comment needs to be updated to reflect the overlapping tests.
> Currently, the < > operators and the ^ modifier
> +# are not supported and overlap is asserted even if intervals are disjoint.
> +# Also, despite the MMAP_CHECK and MMAP_CHECK_REQPROT hooks have different
> +# names, they are basically the same hook but with different behavior depending
> +# on external factors, so also in this case overlap has to be asserted. Finally,
> +# the existing aliases PATH_CHECK and FILE_MMAP are converted to the current
> +# hook names, respectively FILE_CHECK and MMAP_CHECK.
> +#
> +# Rule equivalence is determined by checking each key/value pair, regardless of
> +# their order. However, the action must always be at the beginning of the rules.
> +# Rules with aliases are considered equivalent.
> +#
> +# Return a bit mask with the following values:
> +# - 1: invalid new rule;
> +# - 2: overlap of the new rule with an existing rule in the IMA policy;
> +# - 4: new rule exists in the IMA policy.
>
> diff --git a/tests/ima_policy_check.test b/tests/ima_policy_check.test
> new file mode 100755
> index 00000000000..ba8747a74b1
> --- /dev/null
> +++ b/tests/ima_policy_check.test
> @@ -0,0 +1,225 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# Copyright (C) 2023 Roberto Sassu <roberto.sassu@huawei.com>
> +#
> +# Test for ima_policy_check.awk
> +
> +trap '_report_exit_and_cleanup' SIGINT SIGTERM EXIT
> +
> +cd "$(dirname "$0")" || exit 1
> +. ./functions.sh
> +
> +export PATH=$PWD:$PATH
> +
> +check_result() {
> + local result
> +
> + echo -e "\nTest: $1"
> + echo "New rule: $2"
> + echo "IMA policy: $3"
> +
> + echo -n "Result (expect $4): "
> +
> + echo -e "$2\n$3" | ima_policy_check.awk
> + result=$?
> +
> + if [ "$result" -ne "$4" ]; then
> + echo "${RED}$result${NORM}"
> + return "$FAIL"
> + fi
> +
> + echo "${GREEN}$result${NORM}"
> + return "$OK"
> +}
> +
> +# Basic checks.
> +desc="empty IMA policy"
> +rule="measure func=FILE_CHECK"
> +ima_policy=""
> +expect_pass check_result "$desc" "$rule" "$ima_policy" 0
Include the comment, before the tests, as to what the expected return
values mean:
# Return a bit mask with the following values:
# - 1: invalid new rule;
# - 2: overlap of the new rule with an existing rule in the IMA policy;
# - 4: new rule exists in the IMA policy.
> +desc="Empty new rule"
> +rule=""
> +ima_policy=""
> +expect_pass check_result "$desc" "$rule" "$ima_policy" 1
> +
> +desc="Wrong func"
"FILE_CHECK" is actually fine, but the condition keyword "fun" is
invalid.
> +rule="measure fun=FILE_CHECK"
> +ima_policy=""
> +expect_pass check_result "$desc" "$rule" "$ima_policy" 1
> +
> +desc="Missing action"
> +rule="func=FILE_CHECK"
> +ima_policy=""
> +expect_pass check_result "$desc" "$rule" "$ima_policy" 1
> +
> +# Non-overlapping rules.
> +desc="Non-overlapping by func"
> +rule="measure func=FILE_CHECK"
> +ima_policy="appraise func=MMAP_CHECK"
> +expect_pass check_result "$desc" "$rule" "$ima_policy" 0
All of the non-overlapping tests are non-overlapping by action as well.
Is this intentional?
> +
> +desc="Non-overlapping by uid, func is equal"
> +rule="measure func=FILE_CHECK uid=0"
> +ima_policy="appraise uid=1 func=FILE_CHECK"
> +expect_pass check_result "$desc" "$rule" "$ima_policy" 0
> +desc="Non-overlapping by uid, func is equal, same policy options"
> +rule="measure func=FILE_CHECK uid=0 permit_directio"
> +ima_policy="appraise uid=1 func=FILE_CHECK permit_directio"
> +expect_pass check_result "$desc" "$rule" "$ima_policy" 0
> +
> +desc="Non-overlapping by mask, func and uid are equal, same policy options"
> +rule="measure func=FILE_CHECK uid=0 permit_directio mask=MAY_READ"
> +ima_policy="appraise uid=0 mask=MAY_EXEC func=FILE_CHECK permit_directio"
> +expect_pass check_result "$desc" "$rule" "$ima_policy" 0
> +
> +desc="Non-overlapping by mask, func and uid are equal, different policy options"
> +rule="measure func=FILE_CHECK uid=0 permit_directio mask=MAY_READ"
> +ima_policy="appraise uid=0 mask=MAY_EXEC func=FILE_CHECK"
> +expect_pass check_result "$desc" "$rule" "$ima_policy" 0
> +
> +# Overlapping and different rules.
> +desc="same actions, different keywords"
> +rule="appraise func=FILE_CHECK"
> +ima_policy="appraise uid=0"
> +expect_pass check_result "$desc" "$rule" "$ima_policy" 2
> +
> +desc="different actions, same func"
> +rule="appraise func=FILE_CHECK"
> +ima_policy="measure func=FILE_CHECK"
> +expect_pass check_result "$desc" "$rule" "$ima_policy" 2
Ok, a "measure" rule overlapping with an existing "appraise" rule could
impact a test, but the reverse an "appraise" rule overlapping with an
existing "measure" rule should not impact tests. So overlapping rules
are not necessarily interferring.
> +desc="different actions, same func"
> +rule="appraise func=FILE_CHECK"
> +ima_policy="dont_measure func=FILE_CHECK"
> +expect_pass check_result "$desc" "$rule" "$ima_policy" 2
Similarly, an "appraise" rule should not be impacted by an existing
"dont_measure" rule.
> +desc="different actions, same func"
> +rule="measure func=FILE_CHECK"
> +ima_policy="dont_measure func=FILE_CHECK"
> +expect_pass check_result "$desc" "$rule" "$ima_policy" 2
Right, measure/dont_measure rules for the same func hook overlap.
> +
> +desc="different actions, same func, different policy options"
> +rule="measure func=FILE_CHECK"
> +ima_policy="dont_measure func=FILE_CHECK permit_directio"
> +expect_pass check_result "$desc" "$rule" "$ima_policy" 2
Right, any combination of measure rules or measure/dont_measure rules
for the same func hook should overlap, if one rule is more restrictive
than the other.
> +desc="different actions, same func, different policy options"
> +rule="measure func=FILE_CHECK permit_directio"
> +ima_policy="dont_measure func=FILE_CHECK"
> +expect_pass check_result "$desc" "$rule" "$ima_policy" 2
> +
> +desc="same actions, same func, same mask with different modifier"
> +rule="measure func=FILE_CHECK mask=MAY_EXEC"
> +ima_policy="measure func=FILE_CHECK mask=^MAY_EXEC"
> +expect_pass check_result "$desc" "$rule" "$ima_policy" 2
> +
> +desc="same actions, same func, different mask with same modifier"
> +rule="measure func=FILE_CHECK mask=^MAY_READ"
> +ima_policy="measure func=FILE_CHECK mask=^MAY_EXEC"
> +expect_pass check_result "$desc" "$rule" "$ima_policy" 2
Right, these rules are equally restrictive, but would overlap when a
file is opened RW.
--
thanks,
Mimi
next prev parent reply other threads:[~2023-02-16 3:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-14 15:22 [PATCH ima-evm-utils v2] Add ima_policy_check.awk and ima_policy_check.test Roberto Sassu
2023-02-15 23:39 ` Mimi Zohar
2023-02-16 8:18 ` Roberto Sassu
2023-02-16 3:22 ` Mimi Zohar [this message]
2023-02-16 8:39 ` Roberto Sassu
2023-02-16 13:13 ` Mimi Zohar
2023-02-16 13:30 ` Roberto Sassu
2023-02-16 13:40 ` Mimi Zohar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f00d6ea8df825b38f1df62cd2487fb4467c7ab48.camel@linux.ibm.com \
--to=zohar@linux.ibm.com \
--cc=dmitry.kasatkin@gmail.com \
--cc=linux-integrity@vger.kernel.org \
--cc=pvorel@suse.cz \
--cc=roberto.sassu@huawei.com \
--cc=roberto.sassu@huaweicloud.com \
--cc=stefanb@linux.ibm.com \
--cc=vt@altlinux.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox