From patchwork Fri Apr 5 16:52:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 1078553 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44bQq44G8Kz9sPR for ; Sat, 6 Apr 2019 03:52:45 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id F1D373EAEBC for ; Fri, 5 Apr 2019 18:52:40 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) by picard.linux.it (Postfix) with ESMTP id 472AB3EAEA6 for ; Fri, 5 Apr 2019 18:52:37 +0200 (CEST) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id A6E136013CD for ; Fri, 5 Apr 2019 18:52:38 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 67593B112; Fri, 5 Apr 2019 16:52:36 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Fri, 5 Apr 2019 18:52:23 +0200 Message-Id: <20190405165225.27216-2-pvorel@suse.cz> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190405165225.27216-1-pvorel@suse.cz> References: <20190405165225.27216-1-pvorel@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Cc: Ignaz Forster , Marcus Meissner , Fabian Vogt , linux-integrity@vger.kernel.org, Mimi Zohar Subject: [LTP] [PATCH v2 1/3] ima: Call test's cleanup inside ima_setup.sh cleanup X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" to work the same way as setup Signed-off-by: Petr Vorel --- testcases/kernel/security/integrity/ima/tests/ima_setup.sh | 6 +++++- .../kernel/security/integrity/ima/tests/ima_violations.sh | 2 -- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh index 52551190a..cbded42c2 100644 --- a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh +++ b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh @@ -20,7 +20,8 @@ TST_TESTFUNC="test" TST_SETUP_CALLER="$TST_SETUP" TST_SETUP="ima_setup" -TST_CLEANUP="${TST_CLEANUP:-ima_cleanup}" +TST_CLEANUP_CALLER="$TST_CLEANUP" +TST_CLEANUP="ima_cleanup" TST_NEEDS_TMPDIR=1 TST_NEEDS_ROOT=1 @@ -95,6 +96,9 @@ ima_setup() ima_cleanup() { local dir + + [ -n "$TST_CLEANUP_CALLER" ] && $TST_CLEANUP_CALLER + for dir in $UMOUNT; do umount $dir done diff --git a/testcases/kernel/security/integrity/ima/tests/ima_violations.sh b/testcases/kernel/security/integrity/ima/tests/ima_violations.sh index 74223c221..a44bd1230 100755 --- a/testcases/kernel/security/integrity/ima/tests/ima_violations.sh +++ b/testcases/kernel/security/integrity/ima/tests/ima_violations.sh @@ -51,8 +51,6 @@ cleanup() { [ "$PRINTK_RATE_LIMIT" != "0" ] && \ sysctl -wq kernel.printk_ratelimit=$PRINTK_RATE_LIMIT - - ima_cleanup } open_file_read() From patchwork Fri Apr 5 16:52:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 1078554 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44bQq81phXz9sPR for ; Sat, 6 Apr 2019 03:52:52 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B1EF33EAEC3 for ; Fri, 5 Apr 2019 18:52:49 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) by picard.linux.it (Postfix) with ESMTP id DDB373EAEA6 for ; Fri, 5 Apr 2019 18:52:38 +0200 (CEST) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id CC239100174D for ; Fri, 5 Apr 2019 18:52:35 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 682DCB141; Fri, 5 Apr 2019 16:52:37 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Fri, 5 Apr 2019 18:52:24 +0200 Message-Id: <20190405165225.27216-3-pvorel@suse.cz> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190405165225.27216-1-pvorel@suse.cz> References: <20190405165225.27216-1-pvorel@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Cc: Ignaz Forster , Marcus Meissner , Fabian Vogt , linux-integrity@vger.kernel.org, Mimi Zohar Subject: [LTP] [PATCH v2 2/3] shell: Add $TST_DEVICE as default parameter to tst_umount X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" + use it directly as a cleanup function in df01.sh Signed-off-by: Petr Vorel --- doc/test-writing-guidelines.txt | 4 ++-- testcases/commands/df/df01.sh | 7 +------ testcases/commands/mkfs/mkfs01.sh | 2 +- testcases/kernel/security/integrity/ima/tests/ima_setup.sh | 2 +- testcases/lib/tst_test.sh | 2 +- 5 files changed, 6 insertions(+), 11 deletions(-) diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt index f1912dc12..fc64b418b 100644 --- a/doc/test-writing-guidelines.txt +++ b/doc/test-writing-guidelines.txt @@ -2115,8 +2115,8 @@ The 'tst_mount' mounts '$TST_DEVICE' of '$TST_FS_TYPE' (optional) to '$TST_MNT_PARAMS'. The '$TST_MNTPOINT' directory is created if it didn't exist prior to the function call. -If the path passed to the 'tst_umount' is not mounted (present in '/proc/mounts') -it's noop. +If the path passed (optional, defaults to '$TST_DEVICE') to the 'tst_umount' is +not mounted (present in '/proc/mounts') it's noop. Otherwise it retries to umount the filesystem a few times on a failure, which is a workaround since there are a daemons dumb enough to probe all newly mounted filesystems, which prevents them from umounting shortly after they diff --git a/testcases/commands/df/df01.sh b/testcases/commands/df/df01.sh index 9b0be76fe..3876816dc 100755 --- a/testcases/commands/df/df01.sh +++ b/testcases/commands/df/df01.sh @@ -18,7 +18,7 @@ TST_CNT=12 TST_SETUP=setup -TST_CLEANUP=cleanup +TST_CLEANUP=tst_umount TST_TESTFUNC=test TST_OPTS="f:" TST_USAGE=usage @@ -54,11 +54,6 @@ setup() DF_FS_TYPE=$(mount | grep "$TST_DEVICE" | awk '{print $5}') } -cleanup() -{ - tst_umount $TST_DEVICE -} - df_test() { local cmd="$1 -P" diff --git a/testcases/commands/mkfs/mkfs01.sh b/testcases/commands/mkfs/mkfs01.sh index 88f7f0baa..28af890b3 100755 --- a/testcases/commands/mkfs/mkfs01.sh +++ b/testcases/commands/mkfs/mkfs01.sh @@ -71,7 +71,7 @@ mkfs_verify_size() { tst_mount local blocknum=`df -P -B 1k mntpoint | tail -n1 | awk '{print $2}'` - tst_umount "$TST_DEVICE" + tst_umount if [ $blocknum -gt "$2" ]; then return 1 diff --git a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh index cbded42c2..da49eb1b2 100644 --- a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh +++ b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh @@ -105,7 +105,7 @@ ima_cleanup() if [ "$TST_NEEDS_DEVICE" = 1 ]; then cd $TST_TMPDIR - tst_umount $TST_DEVICE + tst_umount fi } diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh index 512732315..740253df1 100644 --- a/testcases/lib/tst_test.sh +++ b/testcases/lib/tst_test.sh @@ -259,7 +259,7 @@ tst_mount() tst_umount() { - local device="$1" + local device="${1:-$TST_DEVICE}" local i=0 if ! grep -q "$device" /proc/mounts; then From patchwork Fri Apr 5 16:52:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 1078556 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44bQqD70Wyz9sPR for ; Sat, 6 Apr 2019 03:52:56 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 27A9E3EB044 for ; Fri, 5 Apr 2019 18:52:54 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id D123B3EAEA6 for ; Fri, 5 Apr 2019 18:52:39 +0200 (CEST) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 0E4E56013CB for ; Fri, 5 Apr 2019 18:52:40 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 69F56B143; Fri, 5 Apr 2019 16:52:38 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Fri, 5 Apr 2019 18:52:25 +0200 Message-Id: <20190405165225.27216-4-pvorel@suse.cz> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190405165225.27216-1-pvorel@suse.cz> References: <20190405165225.27216-1-pvorel@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Cc: Ignaz Forster , Marcus Meissner , Fabian Vogt , linux-integrity@vger.kernel.org, Mimi Zohar Subject: [LTP] [PATCH v2 3/3] ima: Add overlay test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" test demonstrate a bug on overlayfs on current mainline kernel when combining IMA with EVM. Based on reproducer made by Ignaz Forster used for not upstreamed patchset [1] and previous report [2]. IMA only behavior has already been fixed [3]. NOTE: backup variables are needed because ima_setup.sh calling tst_mount as well when TMPDIR is on tmpfs device. [1] https://www.spinics.net/lists/linux-integrity/msg05926.html [2] https://www.spinics.net/lists/linux-integrity/msg03593.html [3] https://patchwork.kernel.org/patch/10776231/ Tested-by: Ignaz Forster Signed-off-by: Petr Vorel --- Changes v1->v2: * Added 2 more tests (suggested by Ignaz): append file and create a new file. Tests has been further split to 4 tests (previously was only 1). * Fixed testing on tmpfs (reported by Mimi) by adding TST_NEEDS_DEVICE=1. * Renamed file to evm_overlay.sh (from ima_overlay.sh; suggested by Ignaz). Obviously it's about IMA + EVM, but IMHO 'ima' can be left from filename. * Changed pattern for kernel parameters check (suggested by Mimi). TODO/questions: Still not sure what is a proper setup. Should I check EVM enabled? /sys/kernel/security/evm should be 1? I suppose different behaviour between ima_policy=appraise_tcb and ima_appraise_tcb is just my wrong setup. Thanks a lot for your comments. Kind regards, Petr --- runtest/ima | 1 + .../integrity/ima/tests/evm_overlay.sh | 86 +++++++++++++++++++ .../security/integrity/ima/tests/ima_setup.sh | 4 +- 3 files changed, 89 insertions(+), 2 deletions(-) create mode 100755 testcases/kernel/security/integrity/ima/tests/evm_overlay.sh diff --git a/runtest/ima b/runtest/ima index bcae16bb7..f3ea88cf0 100644 --- a/runtest/ima +++ b/runtest/ima @@ -3,3 +3,4 @@ ima_measurements ima_measurements.sh ima_policy ima_policy.sh ima_tpm ima_tpm.sh ima_violations ima_violations.sh +evm_overlay evm_overlay.sh diff --git a/testcases/kernel/security/integrity/ima/tests/evm_overlay.sh b/testcases/kernel/security/integrity/ima/tests/evm_overlay.sh new file mode 100755 index 000000000..08ec1ea37 --- /dev/null +++ b/testcases/kernel/security/integrity/ima/tests/evm_overlay.sh @@ -0,0 +1,86 @@ +#!/bin/sh +# Copyright (c) 2019 Petr Vorel +# Based on reproducer and further discussion with Ignaz Forster + +TST_SETUP="setup" +TST_CLEANUP="cleanup" +TST_NEEDS_DEVICE=1 +TST_CNT=4 +. ima_setup.sh + +setup() +{ + lower="$TST_MNTPOINT/lower" + upper="$TST_MNTPOINT/upper" + work="$TST_MNTPOINT/work" + merged="$TST_MNTPOINT/merged" + mkdir -p $lower $upper $work $merged + + device_backup="$TST_DEVICE" + TST_DEVICE="overlay" + + fs_type_backup="$TST_FS_TYPE" + TST_FS_TYPE="overlay" + + mntpoint_backup="$TST_MNTPOINT" + TST_MNTPOINT="$merged" + + params_backup="$TST_MNT_PARAMS" + TST_MNT_PARAMS="-o lowerdir=$lower,upperdir=$upper,workdir=$work" + + grep -q -e ima_policy= -e ima_appraise_tcb /proc/cmdline || \ + tst_brk TCONF "Test requires specify IMA policy as kernel parameter" + + tst_mount + mounted=1 +} + +test1() +{ + local file="foo1.txt" + + tst_res TINFO "overwrite file in overlay" + ROD echo lower \> $lower/$file + EXPECT_PASS echo overlay \> $merged/$file +} + +test2() +{ + local file="foo2.txt" + + tst_res TINFO "append file in overlay" + ROD echo lower \> $lower/$file + EXPECT_PASS echo overlay \>\> $merged/$file +} + +test3() +{ + local file="foo3.txt" + + tst_res TINFO "create a new file in overlay" + EXPECT_PASS echo overlay \> $merged/$file +} + +test4() +{ + local f + + tst_res TINFO "read all created files" + for f in $(find $TST_MNTPOINT -type f); do + EXPECT_PASS cat $f \> /dev/null 2\> /dev/null + done +} + +cleanup() +{ + [ -n "$mounted" ] || return 0 + + tst_umount $TST_DEVICE + + TST_DEVICE="$device_backup" + TST_FS_TYPE="$fs_type_backup" + TST_MNTPOINT="$mntpoint_backup" + TST_MNT_PARAMS="$params_backup" +} + +tst_run diff --git a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh index da49eb1b2..08aa5300a 100644 --- a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh +++ b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh @@ -64,14 +64,14 @@ print_ima_config() local config="/boot/config-$(uname -r)" local i - tst_res TINFO "/proc/cmdline: $(cat /proc/cmdline)" - if [ -r "$config" ]; then tst_res TINFO "IMA kernel config:" for i in $(grep ^CONFIG_IMA $config); do tst_res TINFO "$i" done fi + + tst_res TINFO "/proc/cmdline: $(cat /proc/cmdline)" } ima_setup()