mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: Joe Perches <joe@perches.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Jiri Kosina <jkosina@suse.cz>, Al Viro <viro@zeniv.linux.org.uk>,
	"David S. Miller" <davem@davemloft.net>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] lib/vsprintf: add %pT[C012] format specifier
Date: Fri, 3 Jan 2014 09:08:25 -0800	[thread overview]
Message-ID: <CAGXu5jL7RunQuAw1MjnUMgWeYMX35+YcGeaZYCx6dhND3YUmsQ@mail.gmail.com> (raw)
In-Reply-To: <201401021349.JGJ78109.OOFtFFHJMLSOQV@I-love.SAKURA.ne.jp>

On Wed, Jan 1, 2014 at 8:49 PM, Tetsuo Handa
<penguin-kernel@i-love.sakura.ne.jp> wrote:
> From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> Date: Thu, 2 Jan 2014 13:37:14 +0900
> Subject: [PATCH v3] lib/vsprintf: support built-in tokens
>
> The vast majority of ->comm accesses are accessing current->comm, for
> debug reasons. I'm counting 350-odd sites. At all these sites it's
> pointless passing `current' to the printk function at all!
>
> This patch introduces a set of vsprintf tokens for embedding globally visible
> arguments into the format string, so that we can reduce text size a bit (and
> in the future make reading of task_struct->comm consistent) by stop generating
> the code to pass an argument which the callee already has access to, with an
> assumption that currently we are not using the 0x1A byte within the format
> string.
>
> Some examples are shown below.
>
>   pr_info("comm=%s\n", current->comm);
>           => pr_info("comm=" EMBED_CURRENT_COMM "\n");
>
>   pr_info("pid=%d\n", current->pid);
>           => pr_info("pid=" EMBED_CURRENT_PID "\n");
>
>   pr_info("%s(%d)\n", current->comm, current->pid);
>           => pr_info(EMBED_CURRENT_COMM "(" EMBED_CURRENT_PID ")\n");
>
>   pr_info("[%-6.6s]\n", current->comm);
>           => pr_info(EMBED_FORMAT "-6.6" EMBED_CURRENT_COMM "\n");
>
> Since this patch does not use get_task_comm(), you should not convert from
> get_task_comm(current) to built-in tokens if you want constsistent reading.
>
> Suggested-by: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> ---
>  include/linux/kernel.h |   17 ++++++++
>  lib/vsprintf.c         |  101 +++++++++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 116 insertions(+), 2 deletions(-)
> [...]
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 10909c5..b05217d 100644
> @@ -1423,7 +1512,7 @@ int format_decode(const char *fmt, struct printf_spec *spec)
>         spec->type = FORMAT_TYPE_NONE;
>
>         for (; *fmt ; ++fmt) {
> -               if (*fmt == '%')
> +               if (*fmt == '%' || *fmt == 0x1A)
>                         break;
>         }
>

I'm on board with the idea of embedding comm/pid/whatever, but I
either missed or do not understand why a second format-start character
is being added. I think this will complicate audits and maybe trigger
weird info leaks (imagine printing a string that was %-escaped, but
not 0x1A-escaped?)

Why not use % followed by 0x1A to be the start code, instead of just 0x1A?

-Kees

-- 
Kees Cook
Chrome OS Security

  reply	other threads:[~2014-01-03 17:08 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-25 12:37 Tetsuo Handa
2013-12-26  8:43 ` Joe Perches
2013-12-27 23:02 ` Andrew Morton
2013-12-28  3:43   ` Tetsuo Handa
2013-12-28 18:57     ` Geert Uytterhoeven
2013-12-28 19:25       ` Andrew Morton
2013-12-28 19:25         ` Geert Uytterhoeven
2013-12-28 19:53           ` Joe Perches
2013-12-28 20:08             ` Andrew Morton
2013-12-28 20:24               ` Joe Perches
2013-12-29  0:32                 ` Tetsuo Handa
2013-12-29  2:07                   ` Joe Perches
2013-12-29 12:13                     ` Tetsuo Handa
2013-12-30 16:55                       ` Joe Perches
2013-12-31  6:53                         ` Tetsuo Handa
2013-12-31 16:24                           ` Joe Perches
2014-01-01  5:34                             ` Tetsuo Handa
2014-01-01  5:49                               ` Joe Perches
2014-01-01 10:02                                 ` Tetsuo Handa
2014-01-02  1:33                                   ` Joe Perches
2014-01-02  4:49                                     ` Tetsuo Handa
2014-01-03 17:08                                       ` Kees Cook [this message]
2014-01-03 17:39                                         ` Joe Perches
2014-01-03 17:49                                           ` Kees Cook
2014-01-04  2:26                                             ` Tetsuo Handa
2014-01-05  3:15                                               ` Tetsuo Handa
2014-01-05 18:09                                                 ` Joe Perches
2014-01-06 14:00                                                   ` Tetsuo Handa
2014-01-06 17:34                                                     ` Joe Perches
2014-01-06 21:41                                                       ` Tetsuo Handa
2014-01-06 22:25                                                         ` Joe Perches
2014-01-07  0:16                                                           ` Pavel Machek
2014-01-07  1:03                                                             ` Joe Perches
2014-01-07  8:37                                                               ` Pavel Machek
2014-01-07 17:34                                                                 ` Joe Perches
2014-01-07 17:56                                                                   ` Pavel Machek
2014-01-07 18:28                                                                     ` Geert Uytterhoeven
2014-01-08 14:19                                                                     ` Tetsuo Handa
2014-01-08 14:46                                                                       ` Pavel Machek
2014-01-06 21:34                                                     ` Pavel Machek
2014-01-05 22:27                                                 ` Pavel Machek
2014-01-06 14:02                                                   ` Tetsuo Handa
2014-01-10 13:15                                                     ` Tetsuo Handa
2014-01-02  1:38                                   ` Joe Perches
2014-01-02 11:51               ` Pavel Machek

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=CAGXu5jL7RunQuAw1MjnUMgWeYMX35+YcGeaZYCx6dhND3YUmsQ@mail.gmail.com \
    --to=keescook@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=geert@linux-m68k.org \
    --cc=jkosina@suse.cz \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®