From patchwork Mon May 9 14:25:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juerg Haefliger X-Patchwork-Id: 1628638 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=LXl4iXGY; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kxk3J6dSbz9sGV for ; Tue, 10 May 2022 00:25:16 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1no4Jz-0007AB-VM; Mon, 09 May 2022 14:25:11 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1no4Jx-00078u-R3 for kernel-team@lists.ubuntu.com; Mon, 09 May 2022 14:25:09 +0000 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id A69B73F1CC for ; Mon, 9 May 2022 14:25:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1652106309; bh=tiICoyad91mScyog/66DLraxTlCk4LRoKRaZliXoYTA=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LXl4iXGY7i/fOPExRLU0gz6Hwqt0LuoJ8mmmTPj7MBdU2uLHYUdu0VRl6jhNKk5aU W80ZKfRW1NRV7fKkXATIIAstWqsUjnGMWdxvorBO8bpKYt4mK4S1Hh/3M9FG3kFkfX axF0KzsfJhRSD8qoYsn8a4SAPmxTkWAYRJ3boGa69KlMXUZmu41yebzLMZeHxeCwt5 KQksVJUbljenlWp3Ltm8QES08gZOxx+qHyWBxN39gfb6jZwIKXSuUjiUv5jQrWkJCi nkd3P6zy7NTpVuC1MbkRRx5SSjBfYxHEUKECahSZBykLl3A+s9SBgAk7kTTo78I8Q1 kJzdxc/CSvmvg== Received: by mail-ed1-f70.google.com with SMTP id l24-20020a056402231800b00410f19a3103so8434743eda.5 for ; Mon, 09 May 2022 07:25:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tiICoyad91mScyog/66DLraxTlCk4LRoKRaZliXoYTA=; b=v+UIXGzxbxuL5X7FYJlRASCjqDvCWXAuNgMwkOcUwEzwGkRmCfBLxZ2sJu4GyYdsXL wNQtpZSCBYRrIfcNyMqLcRWuiQopaXDlsw/BIgzeNhCQUM88cj5Oxm4cHuLh+f03m9ba esLiRQj6euPp49BTDvimev1rR9o39SjeQ17PYcI53d049b7NrECF/EHyKIiT6jWUrHRX KGZ2niADvBWyUZVYajNCwW73WBuzJLRq9UosRmpXst1Y0886jhHU3RugCXYa2BOqDn5S U2vzfbkUFNOMOkbLwlUHI6rNPJiMDESWSXHgfsKV5HQiz7Moua4apY/cnsYgZdG1LRiI Ta+Q== X-Gm-Message-State: AOAM532q/hXEV7ASwkVBZtG9CyVU0ONGVWxZF3VoGUdtsWQ09xnV98Xq OktKlXTq9xpj7fpvzBzZir0U4kHIsYAFI8yRY4asQDYP4ByKvbNs0bn34Xulq3n6+EvE7iCDZv7 6yQjtJnJj2p+nPf7NFVFpwV3v1F3VvBakJbCOjI6V4g== X-Received: by 2002:a05:6402:4391:b0:427:f2f0:607b with SMTP id o17-20020a056402439100b00427f2f0607bmr17832839edc.45.1652106309340; Mon, 09 May 2022 07:25:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPgg83PsxZBI4uk5sFJjybUDGFKs68DoFEdmgoSB/thhPafcy5IPbyGCS+vhDpo2M6XkSH8Q== X-Received: by 2002:a05:6402:4391:b0:427:f2f0:607b with SMTP id o17-20020a056402439100b00427f2f0607bmr17832824edc.45.1652106309142; Mon, 09 May 2022 07:25:09 -0700 (PDT) Received: from gollum.fritz.box ([194.191.244.86]) by smtp.gmail.com with ESMTPSA id l15-20020a17090612cf00b006f3ef214df9sm5143736ejb.95.2022.05.09.07.25.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 07:25:08 -0700 (PDT) From: Juerg Haefliger X-Google-Original-From: Juerg Haefliger To: kernel-team@lists.ubuntu.com Subject: [Unstable][PATCH v2 3/3] UBUNTU: [Packaging] Add module-signature-check Date: Mon, 9 May 2022 16:25:04 +0200 Message-Id: <20220509142504.493925-4-juergh@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220509142504.493925-1-juergh@canonical.com> References: <20220509142504.493925-1-juergh@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/1642368 Check the signature of staging modules during package build. Signed-off-by: Juerg Haefliger --- debian/rules.d/4-checks.mk | 10 +++- debian/scripts/module-signature-check | 67 +++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100755 debian/scripts/module-signature-check diff --git a/debian/rules.d/4-checks.mk b/debian/rules.d/4-checks.mk index d85de43adffc..ecc6b82aeab5 100644 --- a/debian/rules.d/4-checks.mk +++ b/debian/rules.d/4-checks.mk @@ -10,13 +10,21 @@ module-check-%: $(stampdir)/stamp-install-% $(DROOT)/scripts/module-check "$*" \ "$(prev_abidir)" "$(abidir)" $(skipmodule) +# Check the signature of staging modules +module-signature-check-%: $(stampdir)/stamp-install-% + @echo Debug: $@ + $(DROOT)/scripts/module-signature-check "$*" \ + "$(DROOT)/$(mods_pkg_name)-$*" \ + "$(DROOT)/$(mods_extra_pkg_name)-$*" \ + "$(DROOT)/signature-inclusion" + # Check the reptoline jmp/call functions against the last release. retpoline-check-%: $(stampdir)/stamp-install-% @echo Debug: $@ $(SHELL) $(DROOT)/scripts/retpoline-check "$*" \ "$(prev_abidir)" "$(abidir)" "$(skipretpoline)" "$(builddir)/build-$*" -checks-%: module-check-% abi-check-% retpoline-check-% +checks-%: module-check-% module-signature-check-% abi-check-% retpoline-check-% @echo Debug: $@ # Check the config against the known options list. diff --git a/debian/scripts/module-signature-check b/debian/scripts/module-signature-check new file mode 100755 index 000000000000..f28f4a89c913 --- /dev/null +++ b/debian/scripts/module-signature-check @@ -0,0 +1,67 @@ +#!/bin/bash -eu + +flavor="${1}" +mods_dir="${2}" +mods_extra_dir="${3}" +sig_inc="${4}" + +echo "II: Checking signature of staging modules for ${flavor}..." + +if [ -f "${sig_inc}" ] ; then + echo "II: Use signature inclusion file:" + echo " ${sig_inc}" + sig_all=0 +else + echo "WW: Signature inclusion file missing:" + echo " ${sig_inc}" + echo "II: All modules must be signed" + sig_all=1 +fi + +if ! [ -d "${mods_dir}" ] ; then + echo "EE: Modules directory missing:" + echo " ${mods_dir}" + exit 1 +fi + +echo "II: Checking modules directory:" +echo " ${mods_dir}" +mods_dirs=("${mods_dir}") + +if [ -d "${mods_extra_dir}" ] ; then + echo " ${mods_extra_dir}" + mods_dirs+=("${mods_extra_dir}") +fi + +pass=0 +fail=0 +while IFS= read -r mod ; do + is=0 + if /sbin/modinfo "${mod}" | grep -q "^signature:" ; then + # Module is signed + is=1 + fi + + must=0 + if [ ${sig_all} -eq 1 ] || grep -qFx "${mod##*/}" "${sig_inc}" ; then + # Module must be signed + must=1 + fi + + case "${is}${must}" in + 00) echo " PASS (unsigned) : ${mod##*/}" ; pass=$((pass + 1)) ;; + 01) echo " FAIL (unsigned) : ${mod##*/}" ; fail=$((fail + 1)) ;; + 10) echo " FAIL (signed) : ${mod##*/}" ; fail=$((fail + 1)) ;; + 11) echo " PASS (signed) : ${mod##*/}" ; pass=$((pass + 1)) ;; + esac +done < <(find "${mods_dirs[@]}" -path '*/drivers/staging/*.ko' | sort) + +echo "II: Checked $((pass + fail)) modules : ${pass} PASS, ${fail} FAIL" + +if [ ${fail} -eq 0 ] ; then + echo "II: Done" + exit 0 +else + echo "EE: Modules signature failures" + exit 1 +fi