From patchwork Thu Jan 30 20:22:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Smalley X-Patchwork-Id: 11358623 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2290188B for ; Thu, 30 Jan 2020 20:27:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C565720708 for ; Thu, 30 Jan 2020 20:27:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=tycho.nsa.gov header.i=@tycho.nsa.gov header.b="hNH9FUzM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727686AbgA3U1W (ORCPT ); Thu, 30 Jan 2020 15:27:22 -0500 Received: from UPDC19PA22.eemsg.mail.mil ([214.24.27.197]:29193 "EHLO UPDC19PA22.eemsg.mail.mil" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726514AbgA3U1V (ORCPT ); Thu, 30 Jan 2020 15:27:21 -0500 X-EEMSG-check-017: 52191884|UPDC19PA22_ESA_OUT04.csd.disa.mil X-IronPort-AV: E=Sophos;i="5.70,382,1574121600"; d="scan'208";a="52191884" Received: from emsm-gh1-uea11.ncsc.mil ([214.29.60.3]) by UPDC19PA22.eemsg.mail.mil with ESMTP/TLS/DHE-RSA-AES256-SHA256; 30 Jan 2020 20:27:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho.nsa.gov; i=@tycho.nsa.gov; q=dns/txt; s=tycho.nsa.gov; t=1580416038; x=1611952038; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=/S5kUAK1PB+/s1cHbNYY0dHWf6nh9gNEWRHS0e6gsxM=; b=hNH9FUzMPZlXKECxyTNCCHuzmzm2LsMtx8eWjR60i1cadPp0RkZTz1Cn YposTWnKht836QwRnGPtoPQpRw7y7VPIoKsvaUr+iGRHNxEbj4Lp7uGjq fK6l13SGj3JX/1rIZKgFB0XmAX6qwdUloeMbgDcVifXSbUcBlKP2oii4H 5oh4khMi39bS55UcXjn0OhyzMPSXb/W64Ml5ae9a/rFQBjctCavYmjl9O rQmHwXclMbA6DEIX58zf0jFbgI8wFt6zNDW7iSlvqbKCapKGW6fOr9qvg MEez1avBsd6ffZotuf8Nk0ejwfBugtIL8IPU7QY3cGNentSMqtXh4vtIp w==; X-IronPort-AV: E=Sophos;i="5.70,382,1574121600"; d="scan'208";a="38485158" IronPort-PHdr: 9a23:UxnXpBNkkMBgeiL74+Yl6mtUPXoX/o7sNwtQ0KIMzox0K/z5psbcNUDSrc9gkEXOFd2Cra4d16yN4+u5AjdIoc7Y9ixbK9oUD15NoP5VtjRoONSCB0z/IayiRA0BN+MGamVY+WqmO1NeAsf0ag6aiHSz6TkPBke3blItdaz6FYHIksu4yf259YHNbAVUnjq9Zq55IAmroQnLucQanIRvJrw/xxbKrXdEZupbyG11Ll6Xgxrw+9288ZF+/yleof4t69JMXaDndKkkULJUCygrPXoo78PxrxnDSgWP5noYUmoIlxdDHhbI4hLnUJrvqyX2ruVy1jWUMs3wVrA0RC+t77x3Rx/yiScILCA2/WfKgcFtlq1boRahpxtiw47IZYyeKfRzcr/Bcd4cWGFOUNxRVyhcCY2iaYUBAfcKMeJBo4Tzo1YCqB2zDhSuCuzy0D9Fnn/407Mn3eovEg/I2wMvEd0VvXjIr9j4LrseXPqpwKXUyzjIcvNY2S366IjNah0vvO2MUqxoccrR10YvER7OgEiVqYP/OzOV0voCsmiG5OdnTuKglnUnphptojmv2sgsio7JipgTylDf7yp12ok1JdqmSENiZ9OvDZVetyafN4RsQ8MiRXlluCk7yr0auZ67YTMFxI47yB7YbvyKdZWD7BH7VOuJPDt1i31odKi/ihqv60Ss1OLxWteu3FpXqCdOj8PCuWoX1xPJ78iKUv59/kC81jmRzw3T8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000 Received: from moss-pluto.infosec.tycho.ncsc.mil (moss-pluto [192.168.25.131]) by tarius.infosec.tycho.ncsc.mil (8.14.7/8.14.4) with ESMTP id 00UKQRD9226332; Thu, 30 Jan 2020 15:26:29 -0500 From: Stephen Smalley To: paul@paul-moore.com Cc: selinux@vger.kernel.org, omosnace@redhat.com, richard_c_haines@btinternet.com, Stephen Smalley Subject: [PATCH v3 1/2] testsuite: provide support for testing labeled NFS Date: Thu, 30 Jan 2020 15:22:38 -0500 Message-Id: <20200130202239.11498-1-sds@tycho.nsa.gov> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Provide instructions in the README.md file, the required kernel config options in defconfig, and a nfs.sh script for running the testsuite within a labeled NFS mount. This depends on the previous change to enable running over labeled NFS without failures. This completes the first part of https://github.com/SELinuxProject/selinux-testsuite/issues/32. What remains unfinished is adding tests that context mounts are properly honored, with and without security_label in exports, for NFS, and default labeling of NFS when neither security_label nor context mounts are used (i.e. genfscon default of nfs_t). Signed-off-by: Stephen Smalley --- v3 moves nfs.sh under tools/, updates README.md, and fixes nfs.sh for the relocation. As before, these patches depend on the previous one ("testsuite: enable running over labeled NFS") in order to allow the testsuite to pass on NFS mounts. README.md | 41 +++++++++++++++++++++++++++++++++++++++++ defconfig | 10 ++++++++++ tools/nfs.sh | 13 +++++++++++++ 3 files changed, 64 insertions(+) create mode 100755 tools/nfs.sh diff --git a/README.md b/README.md index 4352796edb2d..e02ae9ac6d6f 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,47 @@ the tests: tests/infiniband_pkey/ibpkey_test.conf tests/infiniband_endport/ibendport_test.conf +#### NFS + +It is possible to run most of the tests within a labeled NFS mount in +order to exercise the NFS security labeling functionality. Certain +tests have been excluded from such testing due to differences between +NFS and local filesystems; these tests will be automatically skipped. + +You will need to install an additional package, the package below +is for Fedora/RHEL but other Linux distributions should have a similar +package: + +* nfs-utils _(for `nfsd', `exportfs', and other NFS-related programs)_ + +On a modern Fedora system you can install this dependency with the +following command: + + # dnf install nfs-utils + +If your distribution does not use systemd as its init system, you will +need to customize the nfs.sh script found in the tools directory to +correctly start and stop the nfs server. You may also choose to not +start/stop the nfs-server as part of the script by removing those lines +if you are already using NFS for other reasons. + +Before running the tests in a labeled NFS mount, first ensure that you +can run them successfully on a local filesystem following the standard +instructions further below. Any failures that occur on a local +filesystem should also typically be expected when running over NFS. + +To run the tests within a labeled NFS mount, you can run the +nfs.sh script while in the selinux-testsuite directory: + + # cd selinux-testsuite + # ./tools/nfs.sh + +The script will start the nfs-server, export the mount containing the +testsuite directory with the security_label option to localhost, mount +it via NFSv4.2 on /mnt/selinux-testsuite, switch to that directory, +and run the testsuite there. After completion, it will unmount and +unexport the mount and then stop the nfs-server. + ## Running the Tests Create a shell with the `unconfined_r` or `sysadm_r` role and the Linux diff --git a/defconfig b/defconfig index 7cb6a2ca7f71..8419e40b79dc 100644 --- a/defconfig +++ b/defconfig @@ -94,3 +94,13 @@ CONFIG_TRACEPOINTS=y CONFIG_BLK_DEV_LOOP=m CONFIG_BLK_DEV_LOOP_MIN_COUNT=0 CONFIG_QFMT_V2=y + +# Test labeled NFS. +# This is not required for SELinux operation itself. +CONFIG_NFS_FS=m +CONFIG_NFS_V4=m +CONFIG_NFS_V4_2=y +CONFIG_NFS_V4_SECURITY_LABEL=y +CONFIG_NFSD=m +CONFIG_NFSD_V4=y +CONFIG_NFSD_V4_SECURITY_LABEL=y diff --git a/tools/nfs.sh b/tools/nfs.sh new file mode 100755 index 000000000000..31c66c377cae --- /dev/null +++ b/tools/nfs.sh @@ -0,0 +1,13 @@ +#!/bin/sh -e +MOUNT=`stat --print %m .` +TESTDIR=`pwd` +systemctl start nfs-server +exportfs -orw,no_root_squash,security_label localhost:$MOUNT +mkdir -p /mnt/selinux-testsuite +mount -t nfs -o vers=4.2 localhost:$TESTDIR /mnt/selinux-testsuite +pushd /mnt/selinux-testsuite +make test +popd +umount /mnt/selinux-testsuite +exportfs -u localhost:$MOUNT +systemctl stop nfs-server