From: Joe Perches <joe@perches.com>
To: william.c.roberts@intel.com, linux-kernel@vger.kernel.org,
apw@canonical.com
Cc: keescook@chromium.org, kernel-hardening@lists.openwall.com
Subject: [kernel-hardening] Re: [PATCH v2] checkpatch: add warning on invalid %p extensions
Date: Fri, 10 Feb 2017 14:49:10 -0800 [thread overview]
Message-ID: <1486766950.2192.29.camel@perches.com> (raw)
In-Reply-To: <1486766608-8791-1-git-send-email-william.c.roberts@intel.com>
On Fri, 2017-02-10 at 14:43 -0800, william.c.roberts@intel.com wrote:
> From: William Roberts <william.c.roberts@intel.com>
>
> The kernel supports %p extensions as documented in
> Documentation/printk-formats.txt. Warn on possibly
> improper use of non-extension characters.
>
> One issue would be the usage of %pk when %pK should have
> been used. This has a side-effect of appearing to work
> alright, but does not respect the kptr_restrict setting
> as %pK does.
>
> Sample output:
> WARNING: Invalid vsprintf pointer extension '%pk'
> + printk(KERN_INFO "Could not allocate IRQ %d for PCI Applicom device. %pk\n", dev->irq, pci_get_class); // NOT OK
>
> WARNING: Invalid vsprintf pointer extension '%pn'
> + sprintf(buf, "%pn", x); // NOT OK
>
> Signed-off-by: William Roberts <william.c.roberts@intel.com>
> ---
> scripts/checkpatch.pl | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 982c52c..fa22751 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -6096,6 +6096,12 @@ sub process {
> "recursive locking is bad, do not use this ever.\n" . $herecurr);
> }
>
> +# check for vsprintf extension %p<foo> misuses
> + if (get_quoted_string($line, $rawline) =~ /(\%[\*\d\.]*p(?![\WFfSsBKRraEhMmIiUDdgVCbGN]).)/) {
> + WARN("VSPRINTF_POINTER_EXTENSION",
> + "Invalid vsprintf pointer extension '$1'\n" . $herecurr);
> + }
> +
nack.
You can't just use get_quoted_string.
You have to verify that the thing being scanned is
actually a format. There are many quoted uses of
%p like %%pil and %%pstate used by inline assembly.
WARNING: multiple messages have this Message-ID (diff)
From: Joe Perches <joe@perches.com>
To: william.c.roberts@intel.com, linux-kernel@vger.kernel.org,
apw@canonical.com
Cc: keescook@chromium.org, kernel-hardening@lists.openwall.com
Subject: Re: [PATCH v2] checkpatch: add warning on invalid %p extensions
Date: Fri, 10 Feb 2017 14:49:10 -0800 [thread overview]
Message-ID: <1486766950.2192.29.camel@perches.com> (raw)
In-Reply-To: <1486766608-8791-1-git-send-email-william.c.roberts@intel.com>
On Fri, 2017-02-10 at 14:43 -0800, william.c.roberts@intel.com wrote:
> From: William Roberts <william.c.roberts@intel.com>
>
> The kernel supports %p extensions as documented in
> Documentation/printk-formats.txt. Warn on possibly
> improper use of non-extension characters.
>
> One issue would be the usage of %pk when %pK should have
> been used. This has a side-effect of appearing to work
> alright, but does not respect the kptr_restrict setting
> as %pK does.
>
> Sample output:
> WARNING: Invalid vsprintf pointer extension '%pk'
> + printk(KERN_INFO "Could not allocate IRQ %d for PCI Applicom device. %pk\n", dev->irq, pci_get_class); // NOT OK
>
> WARNING: Invalid vsprintf pointer extension '%pn'
> + sprintf(buf, "%pn", x); // NOT OK
>
> Signed-off-by: William Roberts <william.c.roberts@intel.com>
> ---
> scripts/checkpatch.pl | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 982c52c..fa22751 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -6096,6 +6096,12 @@ sub process {
> "recursive locking is bad, do not use this ever.\n" . $herecurr);
> }
>
> +# check for vsprintf extension %p<foo> misuses
> + if (get_quoted_string($line, $rawline) =~ /(\%[\*\d\.]*p(?![\WFfSsBKRraEhMmIiUDdgVCbGN]).)/) {
> + WARN("VSPRINTF_POINTER_EXTENSION",
> + "Invalid vsprintf pointer extension '$1'\n" . $herecurr);
> + }
> +
nack.
You can't just use get_quoted_string.
You have to verify that the thing being scanned is
actually a format. There are many quoted uses of
%p like %%pil and %%pstate used by inline assembly.
next prev parent reply other threads:[~2017-02-10 22:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-10 22:43 [kernel-hardening] [PATCH v2] checkpatch: add warning on invalid %p extensions william.c.roberts
2017-02-10 22:43 ` william.c.roberts
2017-02-10 22:49 ` Joe Perches [this message]
2017-02-10 22:49 ` Joe Perches
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=1486766950.2192.29.camel@perches.com \
--to=joe@perches.com \
--cc=apw@canonical.com \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-kernel@vger.kernel.org \
--cc=william.c.roberts@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.