From: Petr Mladek <pmladek@suse.com>
To: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Cc: Nathan Chancellor <natechancellor@gmail.com>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>,
linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com
Subject: Re: [PATCH] printk: Convert a use of sprintf to snprintf in console_unlock
Date: Tue, 11 Feb 2020 14:05:05 +0100 [thread overview]
Message-ID: <20200211130505.2lj2fm6nslbwgmg6@pathway.suse.cz> (raw)
In-Reply-To: <20200131070237.GB240941@google.com>
On Fri 2020-01-31 16:02:37, Sergey Senozhatsky wrote:
> On (20/01/30 15:16), Nathan Chancellor wrote:
> > When CONFIG_PRINTK is disabled (e.g. when building allnoconfig), clang
> > warns:
> >
> > ../kernel/printk/printk.c:2416:10: warning: 'sprintf' will always
> > overflow; destination buffer has size 0, but format string expands to at
> > least 33 [-Wfortify-source]
> > len = sprintf(text,
> > ^
> > 1 warning generated.
> >
> > It is not wrong; text has a zero size when CONFIG_PRINTK is disabled
> > because LOG_LINE_MAX and PREFIX_MAX are both zero. Change to snprintf so
> > that this case is explicitly handled without any risk of overflow.
>
> We probably can add a note here that for !CONFIG_PRINTK builds
> logbuf overflow is very unlikely.
Good point. Well, the sprintf() was used for a well defined string:
"** %llu printk messages dropped **\n" ""
It could overflow only when anyone modified LOG_LINE_MAX to
something really small. It was not the case upstream, definitely.
> Otherwise,
> Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
The patch has been committed into printk.git, branch for-5.7.
I did not add any extra comment to keep it simple. I hope
that it is ok.
Best Regards,
Petr
prev parent reply other threads:[~2020-02-11 13:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-30 22:16 [PATCH] printk: Convert a use of sprintf to snprintf in console_unlock Nathan Chancellor
2020-01-31 7:02 ` Sergey Senozhatsky
2020-02-11 13:05 ` Petr Mladek [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=20200211130505.2lj2fm6nslbwgmg6@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=clang-built-linux@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=natechancellor@gmail.com \
--cc=rostedt@goodmis.org \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=sergey.senozhatsky@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).