From patchwork Thu Aug 31 16:05:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magali Lemes X-Patchwork-Id: 1828650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=ojv+rBMx; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RcSB44KF2z1ygF for ; Fri, 1 Sep 2023 16:02:51 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qbxEr-00042Y-UL; Fri, 01 Sep 2023 06:02:37 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qbkBI-0004Oo-TT for kernel-team@lists.ubuntu.com; Thu, 31 Aug 2023 16:06:05 +0000 Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) (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 8395141D2F for ; Thu, 31 Aug 2023 16:06:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1693497963; bh=x5nvKxEwswZxwG9e0lONHrHaFudZGSWunAsa7aCEQVs=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ojv+rBMx6Sh5Tsf6bftZFeOlC6Fkpj6bXecbpCldJyrV0A9s/57lT46Rn9PPPfIbo HuccyKOyJkG+P/9jXRGuC9RJeEoj5vQ4sMvm2K0ysaVolI5tAjoyGXVyEWc2JQIzYz RAOXjaLhZluV2kL7RbHOr8bRzSI199n34Pqeg5fDcm8FR+RK0VDRUIfNDdratfe85o 9uZd9zHlphMCSSSWSiYYDZSMJGpt0k8CBRRHMWrNuNiNfAHW3Sf+13mLqTdFGNKNSy EvN7kDckVvligd7j24REQYIQJn/0ej5ujXUGRpwM7YJwdcIzn4LsqczM6hHLhMPZbS JuxTE8kUXqBJg== Received: by mail-ot1-f69.google.com with SMTP id 46e09a7af769-6bf0d513257so1187532a34.1 for ; Thu, 31 Aug 2023 09:06:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693497962; x=1694102762; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x5nvKxEwswZxwG9e0lONHrHaFudZGSWunAsa7aCEQVs=; b=fSu8Oq+lUK3QTFZfmt+vIi/qQgSEIJWK0I+osi3cQ+RXTLAuyf99egoPbf/TNX/oCE CXiZkTZcecXXmWpttKdJA6+KCW8vCs6enFgPzTx/fT985kieNQksniDy7vGtegkVw8bh YlCpKVhFBrJC/B26OScbSx/tjZ9+MZqQH3aSIFFRyI+zHpvvAOjb6hv4Fw+lqa4Qr4Yi c5rWwtGeMX8BBUZV8QwJAkFr3VcIzpm5TAbSto0pWMx9FEYD+kqA3mGC3LROfa3H6KzV 0qAefQppj4b5wcjKDl3o9d7qlChfCkx9QDXaeqSbS5XQcnZ1HsBs20Jo5F2tw5+ldzxM uNjA== X-Gm-Message-State: AOJu0YxTL0e0KA9B3+SZrX7WRGlzet5QCPLG/7kOP9hBThz86mbmjQGu oHF5Jzi8ogk9RfyBOMCcZTlAcgOLaQOHzEmd5hbQBo0VgtG3e36zZ6fulN/3i5lRI2AYzYK1+Aw Ys6SJIfHb4x4xdRs0XcFFhQKaQ4qwtObutzsos6TLt/03qGchVA== X-Received: by 2002:a05:6870:e2cb:b0:1b7:60a3:4104 with SMTP id w11-20020a056870e2cb00b001b760a34104mr6794782oad.13.1693497961840; Thu, 31 Aug 2023 09:06:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGWfKRkGGOvPEuVg5Rv/4C/b3pJfKHwVG5D9dM4Q1zg/cweNNZo9i/MeVTFQM+BbAz7pgkPgA== X-Received: by 2002:a05:6870:e2cb:b0:1b7:60a3:4104 with SMTP id w11-20020a056870e2cb00b001b760a34104mr6794720oad.13.1693497960959; Thu, 31 Aug 2023 09:06:00 -0700 (PDT) Received: from localhost.localdomain ([2804:7f0:b441:ef12:18f8:5cad:a1c5:a2f1]) by smtp.gmail.com with ESMTPSA id c19-20020a9d4813000000b006b8af3a2599sm823827otf.73.2023.08.31.09.05.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Aug 2023 09:06:00 -0700 (PDT) From: Magali Lemes To: kernel-team@lists.ubuntu.com Subject: [SRU][M][PATCH 1/1] UBUNTU: [Packaging] Add a new fips-checks script Date: Thu, 31 Aug 2023 13:05:11 -0300 Message-Id: <20230831160511.495067-3-magali.lemes@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230831160511.495067-1-magali.lemes@canonical.com> References: <20230831160511.495067-1-magali.lemes@canonical.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 01 Sep 2023 06:02:32 +0000 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" From: Marcelo Henrique Cerri BugLink: https://bugs.launchpad.net/bugs/1945989 Add a new script responsible for checking if any FIPS relevant commit was added since the last version. If a new change is found, a corresponding entry should exist in the justifications file otherwise the check will fail. The justifications file is located at "${DEBIAN}/fips.justifications" and should follow the following format for each commit justification: Signed-off-by: Marcelo Henrique Cerri Acked-by: Tim Gardner Acked-by: Stefan Bader Signed-off-by: Kelsey Skunberg (ported from commit 68d02506ae6b236d7df155cdcaa64456e9153d5e focal) [magalilemes: added arch/arm64/crypto and lib/crypto/{sha1,aes}.c to crypto_files] Signed-off-by: Magali Lemes --- debian/scripts/misc/fips-checks | 138 ++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100755 debian/scripts/misc/fips-checks diff --git a/debian/scripts/misc/fips-checks b/debian/scripts/misc/fips-checks new file mode 100755 index 000000000000..400d56d643e1 --- /dev/null +++ b/debian/scripts/misc/fips-checks @@ -0,0 +1,138 @@ +#!/bin/bash -eu +export LC_ALL=C.UTF-8 + +usage() { + cat << EOF +Usage: ${P:-$(basename "$0")} [-h|--help] + +Check if there are any FIPS relevant changes since the last +release. Any change that is identified should have a justification in +the justifications file or the check will fail. + +Optional arguments: + -h, --help Show this help message and exit. + -p, --previous Version to use as the previous base version. + -c, --current Version to use as the current base version. + +EOF +} + +prev_base_version= +curr_base_version= +crypto_files=( crypto arch/x86/crypto drivers/char/random.c arch/s390/crypto arch/arm64/crypto lib/crypto/sha1.c lib/crypto/aes.c ) + +c_red='\033[0;31m' +c_green='\033[0;32m' +c_off='\033[0m' + +# Parse arguments +while [ "$#" -gt 0 ]; do + case "$1" in + -h|--help) + usage + exit 0 + ;; + -p|--previous) + shift + prev_base_version="$1" + ;; + -c|--current) + shift + curr_base_version="$1" + ;; + *) + usage + exit 1 + ;; + esac + shift +done + +DEBIAN= +# shellcheck disable=SC1091 +. debian/debian.env + +# Check if the "$DEBIAN" directory exists. +if [ ! -d "$DEBIAN" ]; then + echo "You must run this script from the top directory of this repository." + exit 1 +fi + +CONF="$DEBIAN/etc/update.conf" +if [ ! -f "$CONF" ]; then + echo "Missing file: $CONF" + exit 1 +fi +# shellcheck disable=SC1090 +. "$CONF" + +if [ "$DEBIAN_MASTER" = "" ]; then + echo "DEBIAN_MASTER should be defined either in $DEBIAN/etc/update.conf or the environment" + exit 1 +fi + +# Find the base kernel version used by the previous version +if [ -z "$prev_base_version" ]; then + offset=1 + # Loop through each entry of the current changelog, searching for an + # entry that refers to the master version used as base (ie a line + # containing "[ Ubuntu: 4.15.0-39.42 ]"): + while true; do + changes=$(dpkg-parsechangelog -l"$DEBIAN/changelog" -SChanges -c1 -o"$offset") + if ! [ "$changes" ]; then + echo "Failed to retrieve base master version from changelog file: $DEBIAN/changelog" + exit 1 + fi + prev_base_version=$(echo "$changes" | sed -n -r -e '/^\s.*\[ Ubuntu: ([~0-9.-]*) \]$/{s//\1/p;q}') + [ "$prev_base_version" ] && break + offset=$(( offset + 1 )) + done + if [ -z "${prev_base_version}" ]; then + echo "Failed to retrieve base version from previous version from changelog: $DEBIAN/changelog" + exit 1 + fi +fi + +# Find the current base kernel version +if [ -z "$curr_base_version" ]; then + curr_base_version=$(dpkg-parsechangelog -l"${DEBIAN_MASTER}/changelog" -SVersion) + if ! [ "$curr_base_version" ]; then + echo "Failed to retrieve current master version from changelog: $DEBIAN_MASTER/changelog" + exit 1 + fi +fi + +# Check base kernel tags +tag_prefix="Ubuntu-${DEBIAN_MASTER#debian.}-" +prev_tag="${tag_prefix}${prev_base_version}" +curr_tag="${tag_prefix}${curr_base_version}" +for tag in "$prev_tag" "$curr_tag"; do + if ! git rev-parse --verify "$tag" &> /dev/null; then + echo "Missing tag \"$tag\". Please fetch tags from base kernel." + exit 1 + fi +done + +# Check all the changes +fails=0 +justifications_file="$DEBIAN/fips.justifications" +justifications=$(grep -P '^[^#\s]' "$justifications_file" 2> /dev/null || true) +while read -r id; do + short_msg=$(git log --format=%s --max-count=1 "$id") + if echo "$justifications" | grep -q -x -F "$short_msg"; then + echo -e "${c_green}OK${c_off} | ${id::12} ${short_msg}" + continue + fi + echo -e "${c_red}FAIL${c_off} | ${id::12} ${short_msg}" + fails=$(( fails + 1 )) +done < <(git rev-list "${prev_tag}..${curr_tag}" -- "${crypto_files[@]}") + +echo +if [ "$fails" -gt 0 ]; then + echo "FIPS relevant changes were found without justification: ${fails} change(s)." + echo "Please, check the commits above and update the file \"${justifications_file}\"." + exit 1 +fi + +echo "Check completed without errors." +exit 0