linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marco Elver <elver@google.com>
To: Joe Perches <joe@perches.com>
Cc: "Eric W . Biederman" <ebiederm@xmission.com>,
	Dwaipayan Ray <dwaipayanray1@gmail.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Andy Whitcroft <apw@canonical.com>,
	Lukas Bulwahn <lukas.bulwahn@gmail.com>
Subject: Re: [PATCH v2] checkpatch: warn about direct use of send_sig_info and force_sig_info
Date: Fri, 7 May 2021 13:47:17 +0200	[thread overview]
Message-ID: <CANpmjNPXJUWhO6sVcXcqXjf6_0ud9L1Q3TJchmB_=Ov1QZOngg@mail.gmail.com> (raw)
In-Reply-To: <2bea96ba2525c31b18185f51fffea2d2052aa8a0.camel@perches.com>

On Thu, 6 May 2021 at 23:41, Joe Perches <joe@perches.com> wrote:
> On Thu, 2021-05-06 at 17:22 +0200, Marco Elver wrote:
> > Setting up siginfo and using send_sig_info() or force_sig_info()
> > directly is discouraged. Instead, new code wanting to generate signals
> > should use the appropriate helper specific to the signal.
> >
> > Eric mentioned that he'd like to make these static at some point, but
> > until that can happen, let's try to avoid introducing new users of them.
> []
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> []
> > @@ -7153,6 +7153,12 @@ sub process {
> >                            "Where possible, use lockdep_assert_held instead of assertions based on spin_is_locked\n" . $herecurr);
> >               }
> >
> >
> > +# check for direct use of send_sig_info(), force_sig_info()
> > +             if ($line =~ /\b((?:force|send)_sig_info)\(/) {
>
> You want to be able to find uses like 'force_sig_info (<foo>...'
> so you should add a \s* after the capture group.
> And it's probably simpler and more readable to use
>                 if ($sline =~ /\b(force_sig_info|send_sig_info)\s*\(/) {
> instead of the more complex regex
>
> (sline is stripped of comments, $line is not)

Done for v3.

> > +                     WARN("USE_SIGINFO_HELPER",
> > +                          "Where possible, avoid using '$1' directly and use a signal-specific helper setting required siginfo fields (see include/linux/sched/signal.h).\n" . $herecurr);
>
> A rather long and complex sentence.
> How about
>         "Prefer signal-specific helpers over use of '$1' (see: include/linux/sched/signal.h)\n"

Sounds good.

> And in that signal.h file, there's no obvious reference to
> these signal-specific helpers.  Is there a better reference
> in the Documentation/ tree?

Yeah, signal.h has their declarations, the definitions live in
kernel/signal.c. But otherwise, there's no better reference anywhere
AFAIK. The main thing here is to alert someone to double-check their
use of {send,force}_sig_info() -- when thinking what would have helped
me identify the problem earlier, I came to the conclusion that a
checkpatch.pl warning would have done exactly that. Like Eric said,
eventually these might become static, but it doesn't look trivial to
do this right now. When that happens, this check can then be removed
again. But since it might be a while, we can at least try to automate
this "trivial" review around siginfo.

I'll send v3 shortly.

Thanks,
-- Marco

  reply	other threads:[~2021-05-07 11:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-06 13:28 [PATCH] checkpatch: warn about direct use of send_sig_info and force_sig_info Marco Elver
2021-05-06 15:02 ` Dwaipayan Ray
2021-05-06 15:22   ` [PATCH v2] " Marco Elver
2021-05-06 21:41     ` Joe Perches
2021-05-07 11:47       ` Marco Elver [this message]
2021-05-06 16:02   ` [PATCH] " Lukas Bulwahn
2021-05-06 16:11     ` Marco Elver
2021-05-06 17:51       ` Eric W. Biederman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CANpmjNPXJUWhO6sVcXcqXjf6_0ud9L1Q3TJchmB_=Ov1QZOngg@mail.gmail.com' \
    --to=elver@google.com \
    --cc=apw@canonical.com \
    --cc=dwaipayanray1@gmail.com \
    --cc=ebiederm@xmission.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).