From: "J. Bruce Fields" <bfields@fieldses.org>
To: Sasha Levin <levinsasha928@gmail.com>
Cc: Trond.Myklebust@netapp.com, davem@davemloft.net,
davej@redhat.com, linux-nfs@vger.kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] SUNRPC: Prevent kernel stack corruption on long values of flush
Date: Wed, 18 Jul 2012 13:39:13 -0400 [thread overview]
Message-ID: <20120718173913.GA1298@fieldses.org> (raw)
In-Reply-To: <1342476086-21638-1-git-send-email-levinsasha928@gmail.com>
On Tue, Jul 17, 2012 at 12:01:26AM +0200, Sasha Levin wrote:
> The buffer size in read_flush() is too small for the longest possible values
> for it. This can lead to a kernel stack corruption:
Thanks!
>
> diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
> index 2afd2a8..f86d95e 100644
> --- a/net/sunrpc/cache.c
> +++ b/net/sunrpc/cache.c
> @@ -1409,11 +1409,11 @@ static ssize_t read_flush(struct file *file, char __user *buf,
> size_t count, loff_t *ppos,
> struct cache_detail *cd)
> {
> - char tbuf[20];
> + char tbuf[22];
I wonder how common this sort of calculation is in the kernel? It might
provide some peace of mind to be able to write this something like
char tbuf[MAXLEN_BASE10_UL + 2] /* + 2 for final "\n\0" */
--b.
> unsigned long p = *ppos;
> size_t len;
>
> - sprintf(tbuf, "%lu\n", convert_to_wallclock(cd->flush_time));
> + snprintf(tbuf, sizeof(tbuf), "%lu\n", convert_to_wallclock(cd->flush_time));
> len = strlen(tbuf);
> if (p >= len)
> return 0;
> --
> 1.7.8.6
>
next prev parent reply other threads:[~2012-07-18 17:39 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-16 22:01 [PATCH] SUNRPC: Prevent kernel stack corruption on long values of flush Sasha Levin
2012-07-18 17:39 ` J. Bruce Fields [this message]
2012-07-18 20:00 ` Jim Rees
2012-07-18 20:33 ` Dave Jones
2012-07-18 20:33 ` Dave Jones
2012-07-18 20:55 ` Jim Rees
2012-07-18 20:55 ` Jim Rees
2012-10-17 18:29 ` Boaz Harrosh
2012-10-17 18:29 ` Boaz Harrosh
2012-10-18 8:34 ` David Laight
2012-10-18 8:34 ` David Laight
2012-10-18 8:34 ` David Laight
2012-07-18 21:08 ` J. Bruce Fields
2012-07-18 21:08 ` J. Bruce Fields
[not found] ` <50072BA7.6070205@gmail.com>
2012-07-18 21:43 ` Sasha Levin
2012-07-18 21:43 ` Sasha Levin
2012-07-18 23:04 ` Jim Rees
2012-07-18 23:04 ` Jim Rees
2012-10-17 17:59 ` Sasha Levin
2012-10-17 17:59 ` Sasha Levin
2012-10-17 19:02 ` J. Bruce Fields
2012-10-17 19:02 ` J. Bruce Fields
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=20120718173913.GA1298@fieldses.org \
--to=bfields@fieldses.org \
--cc=Trond.Myklebust@netapp.com \
--cc=davej@redhat.com \
--cc=davem@davemloft.net \
--cc=levinsasha928@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/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.