From patchwork Tue Dec 1 14:39:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: KP Singh X-Patchwork-Id: 11943081 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, URIBL_BLOCKED,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 B1EF7C64E7B for ; Tue, 1 Dec 2020 14:40:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 48D2820757 for ; Tue, 1 Dec 2020 14:40:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="d8sGd9/Q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389478AbgLAOkS (ORCPT ); Tue, 1 Dec 2020 09:40:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389462AbgLAOkR (ORCPT ); Tue, 1 Dec 2020 09:40:17 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23F9DC0613D4 for ; Tue, 1 Dec 2020 06:39:37 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id v14so3336876wml.1 for ; Tue, 01 Dec 2020 06:39:37 -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=Gil/YkV/qEojPCDRG+9N2VK29191DcVOXW+Q/DLuqGs=; b=d8sGd9/QHyX9OItvcKoZ8vDuw0MJDRFNvdvYkfsjk4U4cfAHtOWgwuJSuphCHnuOaN vCK9Hvf4iMZXfUpRjzAHXO7lJ+tkLRMIMlxzlyAlB1XREYzPej/IO907KmM0Tinz/Lb2 aGsFAKhDDeGsdtJrnMljya2+kcOS+Iuq+BrFI= 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=Gil/YkV/qEojPCDRG+9N2VK29191DcVOXW+Q/DLuqGs=; b=XsQDkVm1J3OGXObGyI7pGTBvw4CciGMGatKfNA5a/wPhlJJJ3lXgnqIPbF6ZFOjX1x jEVdgrfUYVxBEsEoidiMKd3pF6hoZCnHxge4L57yMf77GBV/HtY7QxIkKhri32csRX9Z PBeE6gmwCJTp/AJHwHzFXHaP6iLWpvXk0oyUeivN61HINJghvedZ+h0c73vGWHo/nb83 byTHcSzdukf2lYXpldw8aD6nmkPAh+YikHMWqyg0LD+ARSOirp5n+zZM75j502nkGiyL rrx83Rw+EQM3C66rBPfZq04u55lkH3D15uD8Sw/lJ3AU5e+0dGkyJ4GxVWRx/Qe+Watn EuFw== X-Gm-Message-State: AOAM532nk/CgUcj4ALPaLWMLFGq6VB+PKY0YJj5e+BV5/TWeEZnZqxqZ DjJSxU1fA1tIwOjE5yxH3UcdjCWBR9DXwyFn X-Google-Smtp-Source: ABdhPJyiu5JpvttgROO+HOisz1TOAbEhfOyT9DkLkLzjkgaV9ZqRjbD/75twaWv03Utwykfwq6GGCw== X-Received: by 2002:a1c:2c4:: with SMTP id 187mr1505666wmc.187.1606833575464; Tue, 01 Dec 2020 06:39:35 -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 i8sm61199wma.32.2020.12.01.06.39.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2020 06:39:34 -0800 (PST) From: KP Singh To: bpf@vger.kernel.org Cc: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann Subject: [PATCH bpf-next 1/2] selftests/bpf: Update ima test helper's losetup commands Date: Tue, 1 Dec 2020 14:39:23 +0000 Message-Id: <20201201143924.2908241-1-kpsingh@chromium.org> X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-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 Update the commands to use the bare minimum options so that it works in busybox environments. 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 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/bpf/ima_setup.sh b/tools/testing/selftests/bpf/ima_setup.sh index 15490ccc5e55..ed29bde26a12 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,9 +24,10 @@ 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.ext4 "${loop_device:?}" mount "${loop_device}" "${mount_dir}" cp "${TEST_BINARY}" "${mount_dir}" @@ -38,7 +40,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 Tue Dec 1 14:39:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: KP Singh X-Patchwork-Id: 11943083 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, URIBL_BLOCKED,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 2DB1BC64E90 for ; Tue, 1 Dec 2020 14:40:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D1CF820757 for ; Tue, 1 Dec 2020 14:40:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Al6iKh6u" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391641AbgLAOkY (ORCPT ); Tue, 1 Dec 2020 09:40:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389462AbgLAOkX (ORCPT ); Tue, 1 Dec 2020 09:40:23 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C9C7C0613D6 for ; Tue, 1 Dec 2020 06:39:38 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id h21so5552905wmb.2 for ; Tue, 01 Dec 2020 06:39:38 -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=y2pihj4lnPlLWrJE5+RYdsoHnnsm23fjjkLBO9yU9Fo=; b=Al6iKh6uP0Pe8eNjwDhk4hryCPw1FLnBFWVuI3WUdlK3zN8V0Ogi1jlJg/IIwdkxOV hnN1rjkuuU9cNfN5CYfJjiBF76j1RtBcGLOSN3bTg7CK1HJysrYnMQXCx+lkAW9/BnOc 3M5iqCAgTsTfrOxiaLat9gzNjgHHxYy9Hq8Cc= 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=y2pihj4lnPlLWrJE5+RYdsoHnnsm23fjjkLBO9yU9Fo=; b=cf34ZSA0Kb75ygK436BNd7fTAk+E0QDNhkG9Aqe/yqKDKT8DNsbGGjtkEfLjaDU7JV 2n5+MAGxDL+nC3liyJ0VJ0ZXBZLJ6clPg143AGR4fOuV1pff8GBDUQNEp2za2b7gAPVT 8OdOs+KoxknpjDEKgoKGrorPun4hAhAmRSMPFEsuSTWFJQK/m0iORou54jC/OCkJQViM SeX5ijFLLndF8fHZlWeUvphwDDF9iTWUq7JOlap8j0na59EE84J5Awp+MV/fNi8hPhJP D7XeAvm4q8YgqaRoLlJJ0yJztRIYXGyfNpS9pyZR/fsdXSnA5XnQXdIj9Uj1jhIJ8y08 ab9A== X-Gm-Message-State: AOAM533FRSvj3wyz1W5MCzPszPIJars+KD42O4cuXwrRF8s8smwJZxX8 PkDlTBolyqUX+GP2xKBl9YUSOwmVXyoVWewF X-Google-Smtp-Source: ABdhPJzN9O0n66gPhgWlirpIKBrIKkjNBZUxj4csnV5zOjlArWgfs1FpMNMQdX0mWFLnpTFKy9ToQg== X-Received: by 2002:a1c:4e10:: with SMTP id g16mr3098890wmh.48.1606833576193; Tue, 01 Dec 2020 06:39:36 -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 i8sm61199wma.32.2020.12.01.06.39.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2020 06:39:35 -0800 (PST) From: KP Singh To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Subject: [PATCH bpf-next 2/2] selftests/bpf: Update ima test helper's mount uuid logic Date: Tue, 1 Dec 2020 14:39:24 +0000 Message-Id: <20201201143924.2908241-2-kpsingh@chromium.org> X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog In-Reply-To: <20201201143924.2908241-1-kpsingh@chromium.org> References: <20201201143924.2908241-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 test uses blkid to determine the uuid which may not be available on every system. Switch the logic to a good-old for loop iterating over /dev/disk/by-uuid and reading the symlinks to find the correct UUID for a given loop device Fixes: 34b82d3ac105 ("bpf: Add a selftest for bpf_ima_inode_hash") Signed-off-by: KP Singh --- tools/testing/selftests/bpf/ima_setup.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/ima_setup.sh b/tools/testing/selftests/bpf/ima_setup.sh index ed29bde26a12..7b8615c30c09 100755 --- a/tools/testing/selftests/bpf/ima_setup.sh +++ b/tools/testing/selftests/bpf/ima_setup.sh @@ -31,8 +31,24 @@ setup() mount "${loop_device}" "${mount_dir}" cp "${TEST_BINARY}" "${mount_dir}" - local mount_uuid="$(blkid -s UUID -o value ${loop_device})" - echo "measure func=BPRM_CHECK fsuuid=${mount_uuid}" > ${IMA_POLICY_FILE} + local mount_uuid="" + # This can be done with blkid -s UUID -o value ${loop_device} but + # blkid might not be available everywhere, especially in busybox + # environments. + for uuid in $(ls /dev/disk/by-uuid); do + local link_target="$(readlink -f /dev/disk/by-uuid/${uuid})" + if [[ "${loop_device}" == "${link_target}" ]]; then + mount_uuid="${uuid}" + break; + fi + done + + if [[ -z "${mount_uuid}" ]]; then + echo "Could not find mount_uuid for ${loop_device}" + exit 1; + fi + + echo "measure func=BPRM_CHECK fsuuid=${mount_uuid:?}" > ${IMA_POLICY_FILE} } cleanup() {