From patchwork Tue Mar 14 17:55:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9624101 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 395A6604CC for ; Tue, 14 Mar 2017 17:56:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E083285DC for ; Tue, 14 Mar 2017 17:56:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22BE2285DE; Tue, 14 Mar 2017 17:56:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF80A285DC for ; Tue, 14 Mar 2017 17:56:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751102AbdCNR4D (ORCPT ); Tue, 14 Mar 2017 13:56:03 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35109 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750996AbdCNR4B (ORCPT ); Tue, 14 Mar 2017 13:56:01 -0400 Received: by mail-pf0-f193.google.com with SMTP id 67so20049151pfg.2 for ; Tue, 14 Mar 2017 10:56:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=8J9s+EjJ1AHU7AH5PtKolHL0c6n3CIAM54tJa2RNHWs=; b=pxkw3/6XHMKQl9TKPKjPLSV3m9Losq38TVqzcB48OVpxF5RbFFRaIloo31Jf0qR6Ap tI+Vj6FN9LtEySeRdPM83NFJjb+LTPdpHGcGDdfPxPPSaclaGxx1tfgxyDDR3zGTE2aY GOYlzxtU/5LczgWdcT2itgp7G9bEK2v2201HJb+HqbNz75M2+me8BZtDh57d6IHXnov7 CK3c3fnw4mm4If099jpAnZ4zhEVDtqdLQVUz2Ou9b8+eAI7XwA24MPr6c+8u+vn2Ee9w 4bCA9wPPbA0+ktaXQ7dvs+NvDMrtH9b5Fx2XahYg+DChpDwYQ/r53eysXrtzH+TDt6J/ lmVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=8J9s+EjJ1AHU7AH5PtKolHL0c6n3CIAM54tJa2RNHWs=; b=ahlOau1wMa3anjEJn7s2mpK3z480G6wZB2hJz4r5hhi0qnN3Cz/S1QuRQLj0e1vgaf rLiW4+MYGphSxCTIwVMNKwW2OIFL0w2g7MmdRZev67xbIflyq2gLJtYoFlNlGjOFH4Xc PPCgxv5QjNs3lH0RXrrPId8mZy4W/mkGz8oH+wbqlPfW6B5067ew8alytMUJd+IiP9ST C5cKsU7+brz+0IJOKQJGQBcvZ0tZ+y6oo5dwZkuyrtVbhp8KIyk/sUBqfirM6RPD2+zO d7sz6//xYnZO9ihtU2xnFMscYqxlCXtptRbS5AlNpTcz+Ilh6LtnTVGkIP85oADK9Zjq R9gg== X-Gm-Message-State: AMke39k7QzCibt71cSx8ng6D3rcYYR9pZsUSCI4CRosB9B6DuxRfdJxagyP5DRiE7aJfhA== X-Received: by 10.84.231.200 with SMTP id g8mr58421865pln.100.1489514160653; Tue, 14 Mar 2017 10:56:00 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.119.30.131]) by smtp.gmail.com with ESMTPSA id d1sm39821001pfk.20.2017.03.14.10.55.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 14 Mar 2017 10:56:00 -0700 (PDT) From: Eric Biggers To: fstests@vger.kernel.org Cc: Gwendal Grignou , Theodore Ts'o , Eric Biggers Subject: [PATCH v2] common/config: don't hard-code SELinux context Date: Tue, 14 Mar 2017 10:55:46 -0700 Message-Id: <20170314175546.62834-1-ebiggers3@gmail.com> X-Mailer: git-send-email 2.12.0.367.g23dc2f6d3c-goog Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers If SELinux is enabled, by default xfstests mounts its filesystems with "-o context=system_u:object_r:nfs_t:s0" so that no SELinux xattrs get created and interfere with tests. However, this particular context is not guaranteed to be available because the context names are a detail of the SELinux policy. The SELinux policy on Android systems, for example, does not have a context with this name. To fix this without having to manually override SELINUX_MOUNT_OPTIONS, just grab the SELinux context of the root directory. This is arbitrary, but it should always provide a valid context. And if for some reason someone is actually running xfstests in a specific SELinux context that needs files labeled with a particular context, then they may still override SELINUX_MOUNT_OPTIONS. Signed-off-by: Eric Biggers --- common/config | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/common/config b/common/config index 0c7335ad..5bcf114d 100644 --- a/common/config +++ b/common/config @@ -260,11 +260,18 @@ case "$HOSTOS" in esac # SELinux adds extra xattrs which can mess up our expected output. -# So, mount with a context, and they won't be created -# # nfs_t is a "liberal" context so we can use it. +# So, mount with a context, and they won't be created. +# +# Since the context= option only accepts contexts defined in the SELinux +# policy, and different systems may have different policies with +# different context names, use the context of an existing directory. +# Assume that any valid context is fine, since xfstests should really +# only be run from an "unconfined" process, or with SELinux in permissive +# mode. But if not, just specify your own SELINUX_MOUNT_OPTIONS. if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then - : ${SELINUX_MOUNT_OPTIONS:="-o context=system_u:object_r:nfs_t:s0"} + : ${SELINUX_MOUNT_OPTIONS:="-o context=$(stat -c %C /)"} export SELINUX_MOUNT_OPTIONS + fi # check if mkfs.xfs supports v5 xfs