From patchwork Wed Dec 2 22:39:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: KP Singh X-Patchwork-Id: 11947293 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4220EC64E7B for ; Wed, 2 Dec 2020 22:40:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA55A221FD for ; Wed, 2 Dec 2020 22:40:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726518AbgLBWkg (ORCPT ); Wed, 2 Dec 2020 17:40:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726055AbgLBWkg (ORCPT ); Wed, 2 Dec 2020 17:40:36 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDC88C0613D6 for ; Wed, 2 Dec 2020 14:39:49 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id u12so5839870wrt.0 for ; Wed, 02 Dec 2020 14:39:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=56zwlFn3s580XsICf7QuJIey5v9E28+9gH7x/gZVe/A=; b=QYbejiIHYR+hdUzcL/MiTLNvsm2o5i3z8/ZpXeiqfJixdvzAYwbijDk6OgVtSZbxkc +rl+rzq6iTr5NpCsvuxba8gaYnPrf3N1hPT0cfOsr8mH3NMx9zp/o9XWkXLRFSNe+9mb 7jMqWiG6rAc9Lt4SEmAR3OOW0DIIqWLQl0o5I= 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:mime-version :content-transfer-encoding; bh=56zwlFn3s580XsICf7QuJIey5v9E28+9gH7x/gZVe/A=; b=sk1G6ZsGRLK66SLO4D79T8qdvGo0MRPjOr6VjtwytuVmn24Uw7atWH7BMvtg7jdQxl 4iAF5s3oQVx8gGGJTpgazPFy9T5lW/fgytSNIe5sO7VfcARlxud/P41kBAbeOuDawnJI C4XcZXU4Nx/iLde8fDK4WNy6MQzg3U4TpTiKjq7IcPT2F8Dgqi7O6e7qwI2egSmywgtC KCuKAfj64g1R+d/BMKZo6y9xm8yUfT1g5wd0pkZWNffZ0WoFR4m5Xwb/PLXXMSxwvW6y Xiyy/vLDF2SvbtBLKHH3p7x96Ao1V2DP47MXYTA2UrnEH4cJySEfTLcvwNnC2gh1NMnN aUSQ== X-Gm-Message-State: AOAM5309Eu+FZYlBRcGVtrUjBsvNNftCyU3ED6uY5GdeZrTptM7rap02 F+cd3H4joQhz47fdfx2LDO7EWsu3mFPii5Pc X-Google-Smtp-Source: ABdhPJxoZ5KaYsNMoFxD8AKpYG+rUXTwzKMNCgtGlTILKdTTcM1NQRL/ZDBq2sAgBlop9zZpVZwU/w== X-Received: by 2002:adf:f98a:: with SMTP id f10mr331939wrr.154.1606948788081; Wed, 02 Dec 2020 14:39:48 -0800 (PST) Received: from kpsingh.c.googlers.com.com (203.75.199.104.bc.googleusercontent.com. [104.199.75.203]) by smtp.gmail.com with ESMTPSA id c2sm113068wrv.41.2020.12.02.14.39.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 14:39:47 -0800 (PST) From: KP Singh To: bpf@vger.kernel.org Cc: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann Subject: [PATCH bpf-next v2 1/3] selftests/bpf: Update ima_setup.sh for busybox Date: Wed, 2 Dec 2020 22:39:42 +0000 Message-Id: <20201202223944.456903-1-kpsingh@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: KP Singh * losetup on busybox does not output the name of loop device on using -f with --show. It also dosn't support -j to find the loop devices for a given backing file. losetup is updated to use "-a" which is available on busybox. * blkid does not support options (-s and -o) to only display the uuid. * Not all environments have mkfs.ext4, the test requires a loop device with a backing image file which could formatted with any filesystem. Update to using mkfs.ext2 which is available on busybox. Fixes: 34b82d3ac105 ("bpf: Add a selftest for bpf_ima_inode_hash") Reported-by: Andrii Nakryiko Signed-off-by: KP Singh --- tools/testing/selftests/bpf/ima_setup.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/bpf/ima_setup.sh b/tools/testing/selftests/bpf/ima_setup.sh index 15490ccc5e55..d864c62c1207 100755 --- a/tools/testing/selftests/bpf/ima_setup.sh +++ b/tools/testing/selftests/bpf/ima_setup.sh @@ -3,6 +3,7 @@ set -e set -u +set -o pipefail IMA_POLICY_FILE="/sys/kernel/security/ima/policy" TEST_BINARY="/bin/true" @@ -23,13 +24,15 @@ setup() dd if=/dev/zero of="${mount_img}" bs=1M count=10 - local loop_device="$(losetup --find --show ${mount_img})" + losetup -f "${mount_img}" + local loop_device=$(losetup -a | grep ${mount_img:?} | cut -d ":" -f1) - mkfs.ext4 "${loop_device}" + mkfs.ext2 "${loop_device:?}" mount "${loop_device}" "${mount_dir}" cp "${TEST_BINARY}" "${mount_dir}" - local mount_uuid="$(blkid -s UUID -o value ${loop_device})" + local mount_uuid="$(blkid ${loop_device} | sed 's/.*UUID="\([^"]*\)".*/\1/')" + echo "measure func=BPRM_CHECK fsuuid=${mount_uuid}" > ${IMA_POLICY_FILE} } @@ -38,7 +41,8 @@ cleanup() { local mount_img="${tmp_dir}/test.img" local mount_dir="${tmp_dir}/mnt" - local loop_devices=$(losetup -j ${mount_img} -O NAME --noheadings) + local loop_devices=$(losetup -a | grep ${mount_img:?} | cut -d ":" -f1) + for loop_dev in "${loop_devices}"; do losetup -d $loop_dev done From patchwork Wed Dec 2 22:39:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: KP Singh X-Patchwork-Id: 11947291 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1757CC6369E for ; Wed, 2 Dec 2020 22:40:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B7AD4221F7 for ; Wed, 2 Dec 2020 22:40:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727646AbgLBWkb (ORCPT ); Wed, 2 Dec 2020 17:40:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727071AbgLBWka (ORCPT ); Wed, 2 Dec 2020 17:40:30 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38492C0617A6 for ; Wed, 2 Dec 2020 14:39:50 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id l1so5781603wrb.9 for ; Wed, 02 Dec 2020 14:39:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=q8/10OyIjlZ3CbHmV7X/BEUAsasCZ5FCOwzYE2LIh5A=; b=KDIxplTdKW8VBJOyPepd2QrTPr9KsdOGrtHWEs4/WGLDL3Osjr6kZ0TB1ITOw07k+K wgp/vXOB3PX1yLQ6WscnxoHHZAxKnLnTGvY3VD/5vYMDhGSuDrgEULxlQMvj3fjBoMLF IIPE/qJbSo+K8hKB7ahY+wUiYlgsKjqd2IFkM= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=q8/10OyIjlZ3CbHmV7X/BEUAsasCZ5FCOwzYE2LIh5A=; b=Oo2ERfGufPnOO4IvUkH/798CeLSFWXbHxiQ06MUlQncL6EnSa74TH25jhBftjy3aN+ W2apu6qcJO1HgMxyWjBISCk4GYiIoyGsMv39IQdfBe4kn+J3dQnKWmFUiGTMruEmDa+k 7s52mr0Ah5KGDn//x5OBhe2ZtRXU4Z6Fj3ux+w8RB1Qqby6MBeh1WWG1j3DHD4MqETt4 ysSvCGDmAvmBBySm7Ki5oXlvukr7BGARiIXEht1huVXV4qgqS6ptPsrn21PnDBfO0jKG Btqe711slPSswac6o1GMAK13++5LvLA5C88Bu1UbmL+h2tmNq04uI3YIarmn1j5jmovn BTjg== X-Gm-Message-State: AOAM531KuJFZpxe+anJ1dEtRCcF/poNhtoRVdtW54zvJxqUJHJqw8xhl M7gQGrjQyW5/44sAyh5mP+kZWRNIcuF6rhgz X-Google-Smtp-Source: ABdhPJw5IzQcR9ji3BP2fr/i3O7xGFyF4MnVGfGrGh7Z7Yy6U7g8/P5oJQfEL+32pxmQ5H8ovc97iw== X-Received: by 2002:adf:e5c4:: with SMTP id a4mr344590wrn.56.1606948788670; Wed, 02 Dec 2020 14:39:48 -0800 (PST) Received: from kpsingh.c.googlers.com.com (203.75.199.104.bc.googleusercontent.com. [104.199.75.203]) by smtp.gmail.com with ESMTPSA id c2sm113068wrv.41.2020.12.02.14.39.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 14:39:48 -0800 (PST) From: KP Singh To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Subject: [PATCH bpf-next v2 2/3] selftests/bpf: Ensure securityfs mount before writing ima policy Date: Wed, 2 Dec 2020 22:39:43 +0000 Message-Id: <20201202223944.456903-2-kpsingh@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog In-Reply-To: <20201202223944.456903-1-kpsingh@chromium.org> References: <20201202223944.456903-1-kpsingh@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: KP Singh SecurityFS may not be mounted even if it is enabled in the kernel config. Signed-off-by: KP Singh Reported-by: Andrii Nakryiko --- tools/testing/selftests/bpf/ima_setup.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/testing/selftests/bpf/ima_setup.sh b/tools/testing/selftests/bpf/ima_setup.sh index d864c62c1207..1da2d97a0e72 100755 --- a/tools/testing/selftests/bpf/ima_setup.sh +++ b/tools/testing/selftests/bpf/ima_setup.sh @@ -14,6 +14,20 @@ usage() exit 1 } +ensure_mount_securityfs() +{ + local securityfs_dir=$(grep "securityfs" /proc/mounts | awk '{print $2}') + + if [ -z "${securityfs_dir}" ]; then + securityfs_dir=/sys/kernel/security + mount -t securityfs security "${securityfs_dir}" + fi + + if [ ! -d "${securityfs_dir}" ]; then + echo "${securityfs_dir} :securityfs is not mounted" && exit 1 + fi +} + setup() { local tmp_dir="$1" @@ -33,6 +47,7 @@ setup() cp "${TEST_BINARY}" "${mount_dir}" local mount_uuid="$(blkid ${loop_device} | sed 's/.*UUID="\([^"]*\)".*/\1/')" + ensure_mount_securityfs echo "measure func=BPRM_CHECK fsuuid=${mount_uuid}" > ${IMA_POLICY_FILE} } From patchwork Wed Dec 2 22:39:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: KP Singh X-Patchwork-Id: 11947295 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CF95C64E7C for ; Wed, 2 Dec 2020 22:40:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2AC8722201 for ; Wed, 2 Dec 2020 22:40:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726955AbgLBWkh (ORCPT ); Wed, 2 Dec 2020 17:40:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726055AbgLBWkh (ORCPT ); Wed, 2 Dec 2020 17:40:37 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF00FC0617A7 for ; Wed, 2 Dec 2020 14:39:50 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id p8so5808520wrx.5 for ; Wed, 02 Dec 2020 14:39:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SZbL9ltkMDSrTa8UWNt4NTT0pJi1szO3pVPjHCV0axM=; b=DflXLPk2F3Au8ExOKLpAAgtZmdgDHKDzyBu+Kmly2DFprdCaPFoLK5+JX7oX75cM3e PGXmTriXBuq8bibuYHPO8vwmlmToT5QDqFcrTZR/fiP0RURxAyT08B79Knv4WG6mWu6L eggOj3aoIHMQtcHbxHOAIvDz6rDClf6d5aIU0= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=SZbL9ltkMDSrTa8UWNt4NTT0pJi1szO3pVPjHCV0axM=; b=r1tGN6NX09sSTK4bf+vNJKpexUhCZz0DQo/qBSxAxMIF74CPnhe6y7vlDm3+6of4Ce HqXFEwaznd2eODa503EspzUPihH6iihOO6g4wHVph8Zy4u0Otn81DUJV5qnG7X/4yZoP c95NPaRE1/lWEG6jIUFroMyz+0uJqixB+m3cOX4Q19AQBz3m/6FSXVOoQFxkj+ITgm9u yZgPqyJ8ryk/A33TTyE9O+6QIJ8ddTZsB+tFm+u2d0jQzNtW1Kxk/Mx66UclZW9G7dRK lMIvhhnPQttA95x9NgXfVVNk8t+afdiN4OfhWuTLV0EXRqHGROMkdane84N9yQ9GYiSw jWnw== X-Gm-Message-State: AOAM5315GZHuohxR69Ceevf0J+HnSqkhvvUxOrjvdGzAym8LSyBxFnEs YgvR8sxSIeRnG0Se3jcC4DkzvdgC7NkyCBZA X-Google-Smtp-Source: ABdhPJwa8DTZPR4e9yM/sVPi0bBojDRVVXrEwCVi5/FcJbsFVSSaEQgs05SIjVbnaZvU7hXpXBKL4w== X-Received: by 2002:adf:f882:: with SMTP id u2mr283922wrp.271.1606948789250; Wed, 02 Dec 2020 14:39:49 -0800 (PST) Received: from kpsingh.c.googlers.com.com (203.75.199.104.bc.googleusercontent.com. [104.199.75.203]) by smtp.gmail.com with ESMTPSA id c2sm113068wrv.41.2020.12.02.14.39.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 14:39:48 -0800 (PST) From: KP Singh To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Subject: [PATCH bpf-next v2 3/3] selftests/bpf: Add config dependency on BLK_DEV_LOOP Date: Wed, 2 Dec 2020 22:39:44 +0000 Message-Id: <20201202223944.456903-3-kpsingh@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog In-Reply-To: <20201202223944.456903-1-kpsingh@chromium.org> References: <20201202223944.456903-1-kpsingh@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: KP Singh The ima selftest restricts its scope to a test filesystem image mounted on a loop device and prevents permanent ima policy changes for the whole system. Signed-off-by: KP Singh Reported-by: Andrii Nakryiko --- tools/testing/selftests/bpf/config | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/bpf/config b/tools/testing/selftests/bpf/config index 365bf9771b07..37e1f303fc11 100644 --- a/tools/testing/selftests/bpf/config +++ b/tools/testing/selftests/bpf/config @@ -43,3 +43,4 @@ CONFIG_IMA=y CONFIG_SECURITYFS=y CONFIG_IMA_WRITE_POLICY=y CONFIG_IMA_READ_POLICY=y +CONFIG_BLK_DEV_LOOP=y