mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sylvain Munaut <s.munaut@whatever-company.com>
Cc: Roland Dreier <roland@kernel.org>, Kay Sievers <kay@vrfy.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org,
	Roland Dreier <roland@purestorage.com>
Subject: Re: [PATCH] printk: Fix incorrect length from print_time() when seconds > 99999
Date: Sat, 29 Dec 2012 12:08:54 -0800	[thread overview]
Message-ID: <1356811734.16149.1.camel@joe-AO722> (raw)
In-Reply-To: <20121229175625.GA1963@kroah.com>

On Sat, 2012-12-29 at 09:56 -0800, Greg Kroah-Hartman wrote:
> On Fri, Dec 28, 2012 at 08:23:04PM -0800, Roland Dreier wrote:
> > From: Roland Dreier <roland@purestorage.com>
> > 
> > print_prefix() passes a NULL buf to print_time() to get the length of
> > the time prefix; when printk times are enabled, the current code just
> > returns the constant 15, which matches the format "[%5lu.%06lu] " used
> > to print the time value.  However, this is obviously incorrect when
> > the whole seconds part of the time gets beyond 5 digits (100000
> > seconds is a bit more than a day of uptime).
> > 
> > The simple fix is to use snprintf(NULL, 0, ...) to calculate the
> > actual length of the time prefix.  This could be micro-optimized but
> > it seems better to have simpler, more readable code here.
> > 
> > The bug leads to the syslog system call miscomputing which messages
> > fit into the userspace buffer.  If there are enough messages to fill
> > log_buf_len and some have a timestamp >= 100000, dmesg may fail with:
> > 
> >     # dmesg
> >     klogctl: Bad address
> > 
> > When this happens, strace shows that the failure is indeed EFAULT due
> > to the kernel mistakenly accessing past the end of dmesg's buffer,
> > since dmesg asks the kernel how big a buffer it needs, allocates a bit
> > more, and then gets an error when it asks the kernel to fill it:
> > 
> >     syslog(0xa, 0, 0)                       = 1048576
> >     mmap(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa4d25d2000
> >     syslog(0x3, 0x7fa4d25d2010, 0x100008)   = -1 EFAULT (Bad address)
> > 
> > Signed-off-by: Roland Dreier <roland@purestorage.com>
> 
> Nice work.  When did you start seeing this problem, 3.6 or so?  I ask as
> it's probably something that should go to stable as well if so.
> 
> Andrew seems to be keeping the printk patches these days, so I'll let
> him pick this up with:

Sylvan Munaut did something similar
https://lkml.org/lkml/2012/12/5/168

It's been around quite awhile.



  reply	other threads:[~2012-12-29 20:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-29  4:23 Roland Dreier
2012-12-29 17:56 ` Greg Kroah-Hartman
2012-12-29 20:08   ` Joe Perches [this message]
2012-12-29 22:27     ` Roland Dreier
2012-12-30  3:07       ` Joe Perches
2012-12-31 14:45       ` Sylvain Munaut
2012-12-29 22:24   ` Roland Dreier

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=1356811734.16149.1.camel@joe-AO722 \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kay@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roland@kernel.org \
    --cc=roland@purestorage.com \
    --cc=s.munaut@whatever-company.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

all inboxes | Powered by JetHome®