From nobody Mon Sep 28 02:05:45 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1785134532; cv=none; d=zohomail.com; s=zohoarc; b=R95It/QWRy/XLfAGrUlH7lV30DCTVrn9SORlD7d9OwveBcTlICihvLtwg4AEoR6LLi6axFuEGB+IN6903r5o9M8yIjBhT48FeK+0VIauiLJ+9Dpv68EaeDmgCARgq1dcgbDCKzA3ft/1UOZPAbxtvNlIorIveG5fociqKcpFago= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785134532; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=z1vkUhFf1Ayr3m8Q/cKW2P6QHRBwZl0jJeSWAQ2RN/I=; b=e4T5bmd1QFO7F6fugZgHginxhB+Nb7MkuXc8Kf/1sBoU7DYkkHxPgHs1CmbNNud0sqLIP/93BvegSDHNxYXQgJhh0RrZ4+lnvVm+wU3DDXR+VZRKZ51XeM1q2N9VAzlnSDsL3ZnRCACs3mexzF19YEA5I1tLPudic94YHIgL6fk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1785134532227912.7050414652084; Sun, 26 Jul 2026 23:42:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1woF2H-0008Gy-MK; Mon, 27 Jul 2026 02:42:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1woF2G-0008GS-50 for qemu-devel@nongnu.org; Mon, 27 Jul 2026 02:42:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1woF2E-0001Uy-9s for qemu-devel@nongnu.org; Mon, 27 Jul 2026 02:41:59 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-462-9K6fiMioPUSUT271KIMs6Q-1; Mon, 27 Jul 2026 02:41:55 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 218191801358; Mon, 27 Jul 2026 06:41:54 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.30]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F0ACE180034F; Mon, 27 Jul 2026 06:41:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785134517; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=z1vkUhFf1Ayr3m8Q/cKW2P6QHRBwZl0jJeSWAQ2RN/I=; b=Zo99U+KD6NWdZeg7SDFkF9OMp56qrcOIWWnbajX6w+rWquVHX7XPWUDN6Vy1G4ZO9oUx45 T16fBVE9yFI6i7+d4k4hLh6bFjoWuJ41lSZsmZ83z2oWyFsFCNfHVUFRmidligxCnlNGYZ 7s4tBK7vAaXTvtgvBVb6hL0twC0gvaA= X-MC-Unique: 9K6fiMioPUSUT271KIMs6Q-1 X-Mimecast-MFC-AGG-ID: 9K6fiMioPUSUT271KIMs6Q_1785134514 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Michael Tokarev , Chao Liu , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v2] scripts/checkpatch: validate Fixes: tag format and commit ancestry Date: Mon, 27 Jul 2026 08:41:49 +0200 Message-ID: <20260727064149.1469828-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -36 X-Spam_score: -3.7 X-Spam_bar: --- X-Spam_report: (-3.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.58, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1785134534015158500 Adapt the kernel's checkpatch Fixes: tag validation for QEMU. Add a git_commit_info() helper to resolve commit hashes and validate the Fixes: tag in commit messages. The canonical form is: Fixes: <12+ chars of sha1> ("") The check validates capitalization, spacing, hash length, lowercase hex, and quoted title. When the format is wrong and the commit can be resolved, suggest the corrected Fixes: line. When running inside a git repository, also verify that the referenced commit is an ancestor of master. Lines matching "Fixes: CVE-*" are skipped. The check can be disabled with --no-fixes-tag. Signed-off-by: C=C3=A9dric Le Goater <clg@redhat.com> --- Changes in v2: - Introduced $git_command scripts/checkpatch.pl | 71 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 03f35e75012c8c7a00b67f036e4befb2ea162d4a..59ae3532d012f49122ea097cec1= eeb2b95354f99 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -21,6 +21,7 @@ use Getopt::Long qw(:config no_auto_abbrev); my $quiet =3D 0; my $tree =3D 1; my $chk_signoff =3D 1; +my $chk_fixes_tag =3D 1; my $chk_patch =3D undef; my $chk_branch =3D undef; my $tst_only; @@ -54,6 +55,7 @@ Options: -q, --quiet quiet --no-tree run without a qemu tree --no-signoff do not check for 'Signed-off-by' line + --no-fixes-tag do not check for 'Fixes:' tag --patch treat FILE as patchfile --branch treat args as GIT revision list --emacs emacs compile window format @@ -94,6 +96,7 @@ GetOptions( 'q|quiet+' =3D> \$quiet, 'tree!' =3D> \$tree, 'signoff!' =3D> \$chk_signoff, + 'fixes-tag!' =3D> \$chk_fixes_tag, 'patch!' =3D> \$chk_patch, 'branch!' =3D> \$chk_branch, 'emacs!' =3D> \$emacs, @@ -441,6 +444,11 @@ sub build_types { build_types(); =20 $chk_signoff =3D 0 if ($file); +$chk_fixes_tag =3D 0 if ($file); + +my $git_command =3D'export LANGUAGE=3Den_US.UTF-8; git'; +my $gitroot =3D $ENV{'GIT_DIR'}; +$gitroot =3D ".git" if !defined($gitroot); =20 my @rawlines =3D (); my @lines =3D (); @@ -561,6 +569,28 @@ sub which { return ""; } =20 +sub git_commit_info { + my ($commit, $id, $desc) =3D @_; + + return ($id, $desc) if ((which("git") eq "") || !(-e "$gitroot")); + + my $output =3D `${git_command} log --no-color --format=3D'%H %s' -1 $comm= it 2>&1`; + $output =3D~ s/^\s*//gm; + my @lines =3D split("\n", $output); + + return ($id, $desc) if ($#lines < 0); + + if ($lines[0] =3D~ /^fatal: ambiguous argument '$commit': unknown revisio= n or path not in the working tree\./ || + $lines[0] =3D~ /^fatal: bad object $commit/) { + $id =3D undef; + } else { + $id =3D substr($lines[0], 0, 12); + $desc =3D substr($lines[0], 41); + } + + return ($id, $desc); +} + sub expand_tabs { my ($str) =3D @_; =20 @@ -1811,6 +1841,47 @@ sub process { } } =20 +# Check Fixes: tag format and commit validity + if ($chk_fixes_tag && + $line =3D~ /^\s*(fixes:?)\s*(?:commit\s*)?([0-9a-f]{5,40})\s*(.*)?/i= ) { + my $tag =3D $1; + my $orig_commit =3D $2; + my $title =3D $3; + + if ($line !~ /^\s*Fixes:\s+CVE/i) { + my $tag_case =3D not ($tag eq "Fixes:"); + my $tag_space =3D not ($line =3D~ /^fixes:? [0-9a-f]{5,40}/i); + my $id_length =3D not ($orig_commit =3D~ /^[0-9a-f]{12,40}$/); + my $id_case =3D not ($orig_commit !~ /[A-F]/); + + my $id =3D "0123456789ab"; + my $description =3D "commit title"; + my $has_quotes =3D 0; + + if (defined $title && $title =3D~ /^\("(.*?)"\)$/) { + $description =3D $1 if ($1); + $has_quotes =3D 1; + } elsif (defined $title && $title =3D~ /^\(?(.*?)\)?$/) { + $description =3D $1 if ($1); + } + + my ($cid, $ctitle) =3D git_commit_info($orig_commit, $id, $description= ); + + if (defined($cid) && ($ctitle ne $description || $tag_case || $tag_spa= ce || $id_length || $id_case || !$has_quotes)) { + my $fixed =3D "Fixes: $cid (\"$ctitle\")"; + WARN("Please use correct Fixes: style 'Fixes: <12+ chars of sha1> (\"= <title line>\")'" . + " - ie: '$fixed'\n" . $herecurr); + } + if (which("git") ne "" && -e "$gitroot") { + my $hash =3D defined($cid) ? $cid : $orig_commit; + `git merge-base --is-ancestor $hash master 2>/dev/null`; + if ($? !=3D 0) { + WARN("Fixes: commit $hash is not an ancestor of master\n" . $herecur= r); + } + } + } + } + # Check SPDX-License-Identifier references a permitted license if (($rawline =3D~ m,SPDX-License-Identifier: (.*?)(\*/)?\s*$,) && $rawline !~ /^-/) { --=20 2.55.0