mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mimi Zohar <zohar@linux.ibm.com>
To: Coiby Xu <coxu@redhat.com>, kexec@lists.infradead.org
Cc: linux-integrity@vger.kernel.org, Shuah Khan <shuah@kernel.org>,
	"open list:KERNEL SELFTEST FRAMEWORK" 
	<linux-kselftest@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 2/2] selftests/kexec: enable lockdown tests
Date: Tue, 03 Jan 2023 08:48:20 -0500	[thread overview]
Message-ID: <f60b7949dd7c453821f99a25e243b715ac36c290.camel@linux.ibm.com> (raw)
In-Reply-To: <20221230065850.897967-2-coxu@redhat.com>

Hi Coiby,

On Fri, 2022-12-30 at 14:58 +0800, Coiby Xu wrote:
> When lockdown is enabled, kexec_load syscall should always fail.
> 
> For kexec_file_load, when lockdown is enabled, it should
>  - fail of missing PE signature when KEXEC_SIG is enabled
>  - fail of missing IMA signature when KEXEC_SIG is disabled

Appended kernel image signatures are supported, but differently on
powerpc and s390.  For s390, KEXEC_SIG is enabled.  For completeness
the above statements should reflect appended signatures.

> 
> Before this patch, test_kexec_load.sh fails (false positive) and
> test_kexec_file_load.sh fails without a reason when lockdown enabled and
> KEXEC_SIG disabled,
> 
>     # kexec_load failed [FAIL]
>     not ok 1 selftests: kexec: test_kexec_load.sh # exit=1
>     # kexec_file_load failed [PASS]
>     ok 2 selftests: kexec: test_kexec_file_load.sh
> 
> After this patch, test_kexec_load.sh succeeds and
> test_kexec_file_load.sh fails with the correct reason when lockdown
> enabled and KEXEC_SIG disabled,
> 
>     # kexec_load failed [PASS]
>     ok 1 selftests: kexec: test_kexec_load.sh
>     # kexec_file_load failed (missing IMA sig) [PASS]
>     ok 2 selftests: kexec: test_kexec_file_load.sh
> 
> Cc: kexec@lists.infradead.org
> Cc: linux-integrity@vger.kernel.org
> Suggested-by: Mimi Zohar <zohar@linux.ibm.com>
> Signed-off-by: Coiby Xu <coxu@redhat.com>
> ---
>  .../selftests/kexec/kexec_common_lib.sh       | 16 +++++++++++
>  .../selftests/kexec/test_kexec_file_load.sh   | 27 +++++++++++++++++++
>  .../selftests/kexec/test_kexec_load.sh        | 12 ++++++---
>  3 files changed, 52 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/kexec/kexec_common_lib.sh b/tools/testing/selftests/kexec/kexec_common_lib.sh
> index 641ef05863b2..06c298b46788 100755
> --- a/tools/testing/selftests/kexec/kexec_common_lib.sh
> +++ b/tools/testing/selftests/kexec/kexec_common_lib.sh
> @@ -110,6 +110,22 @@ get_secureboot_mode()
>  	return $secureboot_mode;
>  }
>  
> +is_lockdown_enabled()
> +{
> +	local ret=0
> +
> +	if [ -f /sys/kernel/security/lockdown ] \
> +	     && ! grep -qs "\[none\]" /sys/kernel/security/lockdown; then
> +		ret=1
> +	fi
> +
> +	if [ $ret -eq 0 ]; then
> +		log_info "lockdown not enabled"
> +	fi
> +
> +	return $ret
> +}
> +
>  require_root_privileges()
>  {
>  	if [ $(id -ru) -ne 0 ]; then
> diff --git a/tools/testing/selftests/kexec/test_kexec_file_load.sh b/tools/testing/selftests/kexec/test_kexec_file_load.sh
> index c9ccb3c93d72..790f96938083 100755
> --- a/tools/testing/selftests/kexec/test_kexec_file_load.sh
> +++ b/tools/testing/selftests/kexec/test_kexec_file_load.sh
> @@ -139,6 +139,16 @@ kexec_file_load_test()
>  			log_fail "$succeed_msg (missing IMA sig)"
>  		fi
>  
> +		if [ $lockdown -eq 1 ] && [ $kexec_sig_enabled -eq 1 ] \
> +		     && [ $pe_signed -eq 0 ]; then
> +			log_fail "$succeed_msg (missing PE sig)"
> +		fi

CONFIG_KEXEC_SIG being enabled does not require signature verification
to be enforced.  When the CONFIG_IMA_ARCH_POLICY is enabled, IMA
requires kexec signature verification.  Also on s390, CONFIG_KEXEC_SIG
verifies an appended signature, not a PE signature.  Instead of the
"missing PE sig" message, perhaps indicate lockdown requires kexec
signature verification. 

> +
> +		if [ $lockdown -eq 1 ] && [ $kexec_sig_enabled -eq 0 ] && [ $ima_signed -eq 0 ] \
> +		     && [ $ima_modsig -eq 0 ]; then
> +			log_fail "$succeed_msg (missing IMA sig)"
> +		fi
> +

Similarly, only if IMA is enabled and requires the kexec signature
verficiation should this message be emitted.  Perhaps a single generic
lockdown message would be sufficient for both.

>  		if [ $pe_sig_required -eq 0 ] && [ $ima_appraise -eq 1 ] \
>  		    && [ $ima_sig_required -eq 0 ] && [ $ima_signed -eq 0 ] \
>  	            && [ $ima_read_policy -eq 0 ]; then
> @@ -181,6 +191,16 @@ kexec_file_load_test()
>  		log_pass "$failed_msg (possibly missing IMA sig)"
>  	fi
>  
> +	if [ $lockdown -eq 1 ] && [ $kexec_sig_enabled -eq 1 ] \
> +	    && [ $pe_signed -eq 0 ]; then
> +		log_pass "$failed_msg (missing PE sig)"
> +	fi
> +
> +	if [ $lockdown -eq 1 ] && [ $kexec_sig_enabled -eq 0 ] \
> +	    && [ $ima_signed -eq 0 ] && [ $ima_modsig -eq 0 ]; then
> +		log_pass "$failed_msg (missing IMA sig)"
> +	fi
> +

Similar comments as above.

-- 
thanks,

Mimi


  reply	other threads:[~2023-01-03 13:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-30  6:58 [PATCH v3 1/2] lockdown: kexec_file: prevent unsigned kernel image when KEXEC_SIG not enabled Coiby Xu
2022-12-30  6:58 ` [PATCH v3 2/2] selftests/kexec: enable lockdown tests Coiby Xu
2023-01-03 13:48   ` Mimi Zohar [this message]
2023-01-03 14:42 ` [PATCH v3 1/2] lockdown: kexec_file: prevent unsigned kernel image when KEXEC_SIG not enabled 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=f60b7949dd7c453821f99a25e243b715ac36c290.camel@linux.ibm.com \
    --to=zohar@linux.ibm.com \
    --cc=coxu@redhat.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.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

all inboxes | Powered by JetHome®