Linux Security Modules development
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: Kentaro Takeda <takedakn@nttdata.co.jp>,
	linux-security-module@vger.kernel.org
Subject: Re: [PATCH] tomoyo: Use scnprintf() for avoiding potential buffer overflow
Date: Wed, 11 Mar 2020 12:06:28 +0100	[thread overview]
Message-ID: <s5hwo7rnoaz.wl-tiwai@suse.de> (raw)
In-Reply-To: <fbe60125-091d-c536-36a0-5cfab2eff707@i-love.sakura.ne.jp>

On Wed, 11 Mar 2020 11:20:44 +0100,
Tetsuo Handa wrote:
> 
> On 2020/03/11 18:36, Takashi Iwai wrote:
> > Since snprintf() returns the would-be-output size instead of the
> > actual output size, the succeeding calls may go beyond the given
> > buffer limit.  Fix it by replacing with scnprintf().
> > 
> > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > ---
> >  security/tomoyo/audit.c | 18 +++++++++---------
> >  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> Thanks for a patch. But current code will simply hit WARN_ON_ONCE() in vsnprintf()
> if the would-be-output size went beyond the given buffer limit, and we have never
> hit that warning from this function. That is, the buffer limit is large enough,
> and the last byte is guaranteed to be '\0'.

Right, I don't think this actually hitting the overflow, either.
If the code is intended to rely on the sanity check in vsnprintf(),
it's fine.  But I find it a bit fragile and would prefer more explicit
check in the caller side instead.


thanks,

Takashi

      reply	other threads:[~2020-03-11 11:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-11  9:36 [PATCH] tomoyo: Use scnprintf() for avoiding potential buffer overflow Takashi Iwai
2020-03-11 10:20 ` Tetsuo Handa
2020-03-11 11:06   ` Takashi Iwai [this message]

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=s5hwo7rnoaz.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=linux-security-module@vger.kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=takedakn@nttdata.co.jp \
    /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