2023-09-27 05:27:20

by Justin Stitt

[permalink] [raw]
Subject: [PATCH 3/3] get_maintainer: add patch-only pattern matching type

Add the "D:" type which behaves the same as "K:" but will only match
content present in a patch file.

To illustrate:

Imagine this entry in MAINTAINERS:

NEW REPUBLIC
M: Han Solo <[email protected]>
W: https://www.jointheresistance.org
D: \bstrncpy\b

Our maintainer, Han, will only be added to the recipients if a patch
file is passed to get_maintainer (like what b4 does):
$ ./scripts/get_maintainer.pl 0004-some-change.patch

If the above patch has a `strncpy` present in the subject, commit log or
diff then Han will be to/cc'd.

However, in the event of a file from the tree given like:
$ ./scripts/get_maintainer.pl ./lib/string.c

Han will not be noisily to/cc'd (like a K: type would in this
circumstance)

Note that folks really shouldn't be using get_maintainer on tree files
anyways [1].

[1]: https://lore.kernel.org/all/[email protected]/
---
scripts/get_maintainer.pl | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index e679eac96793..f290bf0948f1 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -309,6 +309,7 @@ if ( $tree && !top_of_kernel_tree($lk_path) ) {

my @typevalue = ();
my %keyword_hash;
+my %patch_keyword_hash;
my @mfiles = ();
my @self_test_info = ();

@@ -339,6 +340,9 @@ sub read_maintainer_file {
elsif ( $type eq "K" ) {
$keyword_hash{@typevalue} = $value;
}
+ elsif ( $type eq "D" ) {
+ $patch_keyword_hash{@typevalue} = $value;
+ }
push( @typevalue, "$type:$value" );
}
elsif ( !( /^\s*$/ || /^\s*\#/ ) ) {
@@ -591,6 +595,11 @@ foreach my $file (@ARGV) {
push( @keyword_tvi, $line );
}
}
+ foreach my $line ( keys %patch_keyword_hash ) {
+ if ($patch_line =~ m/${patch_prefix}$patch_keyword_hash{$line}/x ) {
+ push( @keyword_tvi, $line );
+ }
+ }
}
}
close($patch);

--
2.42.0.582.g8ccd20d70d-goog


2023-09-27 07:20:17

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 3/3] get_maintainer: add patch-only pattern matching type

On Wed, Sep 27, 2023 at 03:19:16AM +0000, Justin Stitt wrote:
> Note that folks really shouldn't be using get_maintainer on tree files
> anyways [1].

That's not true, Linus and I use it on a daily basis this way, it's part
of our normal workflow, AND the workflow of the kernel security team.

So please don't take that valid use-case away from us.

thanks,

greg k-h

2023-09-27 09:11:24

by Justin Stitt

[permalink] [raw]
Subject: Re: [PATCH 3/3] get_maintainer: add patch-only pattern matching type

On Wed, Sep 27, 2023 at 3:14 PM Greg KH <[email protected]> wrote:
>
> On Wed, Sep 27, 2023 at 03:19:16AM +0000, Justin Stitt wrote:
> > Note that folks really shouldn't be using get_maintainer on tree files
> > anyways [1].
>
> That's not true, Linus and I use it on a daily basis this way, it's part
> of our normal workflow, AND the workflow of the kernel security team.
>
> So please don't take that valid use-case away from us.

Fair. I'm on the side of keeping the "K:'' behavior the way it is and
that's why I'm proposing adding "D:" to provide a more granular
content matching type operating strictly on patches. It's purely
opt-in.

The patch I linked mentioned steering folks away from using
tree files but not necessarily removing the behavior.

>
> thanks,
>
> greg k-h

Thanks
Justin

2023-09-27 16:41:40

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 3/3] get_maintainer: add patch-only pattern matching type

On Wed, Sep 27, 2023 at 03:46:30PM +0900, Justin Stitt wrote:
> On Wed, Sep 27, 2023 at 3:14 PM Greg KH <[email protected]> wrote:
> >
> > On Wed, Sep 27, 2023 at 03:19:16AM +0000, Justin Stitt wrote:
> > > Note that folks really shouldn't be using get_maintainer on tree files
> > > anyways [1].
> >
> > That's not true, Linus and I use it on a daily basis this way, it's part
> > of our normal workflow, AND the workflow of the kernel security team.
> >
> > So please don't take that valid use-case away from us.
>
> Fair. I'm on the side of keeping the "K:'' behavior the way it is and
> that's why I'm proposing adding "D:" to provide a more granular
> content matching type operating strictly on patches. It's purely
> opt-in.
>
> The patch I linked mentioned steering folks away from using
> tree files but not necessarily removing the behavior.

Please don't steer folks away from it, it is a valid use case of the
tool, and I would argue, one of the most important ones given how often
I use it that way.

Hence my objection to this verbage in the changelog, it's not correct.

thanks,

greg k-h

2023-09-27 17:59:57

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH 3/3] get_maintainer: add patch-only pattern matching type

On Wed, Sep 27, 2023 at 03:19:16AM +0000, Justin Stitt wrote:
> Add the "D:" type which behaves the same as "K:" but will only match
> content present in a patch file.
>
> To illustrate:
>
> Imagine this entry in MAINTAINERS:
>
> NEW REPUBLIC
> M: Han Solo <[email protected]>
> W: https://www.jointheresistance.org
> D: \bstrncpy\b
>
> Our maintainer, Han, will only be added to the recipients if a patch
> file is passed to get_maintainer (like what b4 does):
> $ ./scripts/get_maintainer.pl 0004-some-change.patch
>
> If the above patch has a `strncpy` present in the subject, commit log or
> diff then Han will be to/cc'd.
>
> However, in the event of a file from the tree given like:
> $ ./scripts/get_maintainer.pl ./lib/string.c
>
> Han will not be noisily to/cc'd (like a K: type would in this
> circumstance)
>
> Note that folks really shouldn't be using get_maintainer on tree files
> anyways [1].
>
> [1]: https://lore.kernel.org/all/[email protected]/

As Greg suggested, please drop the above paragraph and link. Then this
looks good to me.

I would immediately want to send this patch too, so please feel free to
add this to your series (and I bet many other hints on "git grep 'K:.\\b'"
would want to switch from K: to D: too):

diff --git a/MAINTAINERS b/MAINTAINERS
index 5f18c6ba3c3c..830e10866acf 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5057,7 +5057,7 @@ F: Documentation/kbuild/llvm.rst
F: include/linux/compiler-clang.h
F: scripts/Makefile.clang
F: scripts/clang-tools/
-K: \b(?i:clang|llvm)\b
+D: \b(?i:clang|llvm)\b

CLK API
M: Russell King <[email protected]>
@@ -8199,7 +8199,7 @@ F: lib/strcat_kunit.c
F: lib/strscpy_kunit.c
F: lib/test_fortify/*
F: scripts/test_fortify.sh
-K: \b__NO_FORTIFY\b
+D: \b__NO_FORTIFY\b

FPGA DFL DRIVERS
M: Wu Hao <[email protected]>
@@ -11457,9 +11457,9 @@ F: include/linux/overflow.h
F: include/linux/randomize_kstack.h
F: kernel/configs/hardening.config
F: mm/usercopy.c
-K: \b(add|choose)_random_kstack_offset\b
-K: \b__check_(object_size|heap_object)\b
-K: \b__counted_by\b
+D: \b(add|choose)_random_kstack_offset\b
+D: \b__check_(object_size|heap_object)\b
+D: \b__counted_by\b

KERNEL JANITORS
L: [email protected]
@@ -17354,7 +17354,7 @@ F: drivers/acpi/apei/erst.c
F: drivers/firmware/efi/efi-pstore.c
F: fs/pstore/
F: include/linux/pstore*
-K: \b(pstore|ramoops)
+D: \b(pstore|ramoops)

PTP HARDWARE CLOCK SUPPORT
M: Richard Cochran <[email protected]>
@@ -19302,8 +19302,8 @@ F: include/uapi/linux/seccomp.h
F: kernel/seccomp.c
F: tools/testing/selftests/kselftest_harness.h
F: tools/testing/selftests/seccomp/*
-K: \bsecure_computing
-K: \bTIF_SECCOMP\b
+D: \bsecure_computing
+D: \bTIF_SECCOMP\b

SECURE DIGITAL HOST CONTROLLER INTERFACE (SDHCI) Broadcom BRCMSTB DRIVER
M: Kamal Dasu <[email protected]>

--
Kees Cook

2023-09-27 19:11:29

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 3/3] get_maintainer: add patch-only pattern matching type

On Wed, 2023-09-27 at 03:19 +0000, Justin Stitt wrote:
> Add the "D:" type which behaves the same as "K:" but will only match
> content present in a patch file.

Likely it'd be less aggravating just to document
that K: is only for patches and add a !$file test.



2023-09-27 20:27:32

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 3/3] get_maintainer: add patch-only pattern matching type

On Wed, 2023-09-27 at 09:15 -0700, Kees Cook wrote:
> On Wed, Sep 27, 2023 at 03:19:16AM +0000, Justin Stitt wrote:
> > Add the "D:" type which behaves the same as "K:" but will only match
> > content present in a patch file.
> >
> > To illustrate:
> >
> > Imagine this entry in MAINTAINERS:
> >
> > NEW REPUBLIC
> > M: Han Solo <[email protected]>
> > W: https://www.jointheresistance.org
> > D: \bstrncpy\b
> >
> > Our maintainer, Han, will only be added to the recipients if a patch
> > file is passed to get_maintainer (like what b4 does):
> > $ ./scripts/get_maintainer.pl 0004-some-change.patch
> >
> > If the above patch has a `strncpy` present in the subject, commit log or
> > diff then Han will be to/cc'd.
> >
> > However, in the event of a file from the tree given like:
> > $ ./scripts/get_maintainer.pl ./lib/string.c
> >
> > Han will not be noisily to/cc'd (like a K: type would in this
> > circumstance)
> >
> > Note that folks really shouldn't be using get_maintainer on tree files
> > anyways [1].
> >
> > [1]: https://lore.kernel.org/all/[email protected]/
>
> As Greg suggested, please drop the above paragraph and link. Then this
> looks good to me.
>
> I would immediately want to send this patch too, so please feel free to
> add this to your series (and I bet many other hints on "git grep 'K:.\\b'"
> would want to switch from K: to D: too):
>
> diff --git a/MAINTAINERS b/MAINTAINERS
[]
> @@ -5057,7 +5057,7 @@ F: Documentation/kbuild/llvm.rst
> F: include/linux/compiler-clang.h
> F: scripts/Makefile.clang
> F: scripts/clang-tools/
> -K: \b(?i:clang|llvm)\b
> +D: \b(?i:clang|llvm)\b

etc...

My assumption is that the K: --file use is just unnecessary
and it'd be better to only use the K: lookup on patches.

(and I've somehow stuffed up the receiving side of my
email configuration so please ignore any emails to me
that bounce for a while)