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
J. Bruce Fields wrote:
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" */
You could use something like:
char tbuf[sizeof (unsigned long) * 24 / 10 + 1 + 2]; /* + 2 for final "\n\0" */
since there are roughly 10 bits for every 3 decimal digits.
But I'm obviously confused, because I don't understand why tbuf needs to be
any more than 10 + 2.
From: Dave Jones <hidden> Date: 2012-07-18 20:33:35
On Wed, Jul 18, 2012 at 04:00:49PM -0400, Jim Rees wrote:
> You could use something like:
>
> char tbuf[sizeof (unsigned long) * 24 / 10 + 1 + 2]; /* + 2 for final "\n\0" */
>
> since there are roughly 10 bits for every 3 decimal digits.
>
> But I'm obviously confused, because I don't understand why tbuf needs to be
> any more than 10 + 2.
Unsigned long isn't necessarily 32 bits.
On 64-bit systems %lu can be up to 18446744073709551615
Dave
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Dave Jones wrote:
On Wed, Jul 18, 2012 at 04:00:49PM -0400, Jim Rees wrote:
> You could use something like:
>
> char tbuf[sizeof (unsigned long) * 24 / 10 + 1 + 2]; /* + 2 for final "\n\0" */
>
> since there are roughly 10 bits for every 3 decimal digits.
>
> But I'm obviously confused, because I don't understand why tbuf needs to be
> any more than 10 + 2.
Unsigned long isn't necessarily 32 bits.
On 64-bit systems %lu can be up to 18446744073709551615
Thanks. You caught me thinking "Intel." How embarrassing.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: J. Bruce Fields <hidden> Date: 2012-07-18 21:08:33
On Wed, Jul 18, 2012 at 04:00:49PM -0400, Jim Rees wrote:
J. Bruce Fields wrote:
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" */
You could use something like:
char tbuf[sizeof (unsigned long) * 24 / 10 + 1 + 2]; /* + 2 for final "\n\0" */
since there are roughly 10 bits for every 3 decimal digits.
So we could do something like this. OK, I'm not sure I care enough.
--b.
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, Jul 18, 2012 at 1:39 PM, J. Bruce Fields [off-list ref] wrote:
On Tue, Jul 17, 2012 at 12:01:26AM +0200, Sasha Levin wrote:
quoted
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!
I've just stumbled on this crash again, and noticed that this patch
never made it in.
Was it just a mixup, or is something still missing?
Thanks,
Sasha
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Dave Jones wrote:
Unsigned long isn't necessarily 32 bits.
On 64-bit systems %lu can be up to 18446744073709551615
Thanks. You caught me thinking "Intel." How embarrassing.
What? why even on Intel-64 long is 64bit. long is always the
same or bigger then a pointer (A pointer must always fit
in a long)
On the other hand int is 32bit in Intel-64 unlike some
other CPUs where int(s) may get to be 64bit as well.
Cheers
Boaz
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: J. Bruce Fields <hidden> Date: 2012-10-17 19:02:43
On Wed, Oct 17, 2012 at 01:59:39PM -0400, Sasha Levin wrote:
On Wed, Jul 18, 2012 at 1:39 PM, J. Bruce Fields [off-list ref] wrote:
quoted
On Tue, Jul 17, 2012 at 12:01:26AM +0200, Sasha Levin wrote:
quoted
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!
I've just stumbled on this crash again, and noticed that this patch
never made it in.
Was it just a mixup, or is something still missing?
Oh, man, I guess I got distracted by the subsequent base10len()
discussion.
Added to my for-3.7 branch, I'll push that out after some tests and
hopefully send in a pull request tomorrow.
Thanks for noticing the ommission.
--b.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: David Laight <hidden> Date: 2012-10-18 08:38:42
...
long is always the same or bigger then a pointer
(A pointer must always fit in a long)
...
Linux may make that assumption, but it doesn't have
to be true. 64bit windows still has 32bit long.
C99 inttypes.h defines [u]intptr_t to be an integral type
that is large enough to hold a pointer to any data item.
(That in itself is problematic for implementations that
encode multiple characters into a machine word and need
to use 'fat' pointers in order to encode the offset.)
David
��칻
�&�~�&���+-��ݶ��w��˛���m�b��g~ȧ���ܨ}���Ơz�&j:+v����n�r��6;靫3��\
nnX��f�z��2�ޙ���&�)ߡ�a����
�G���h��j:+v���w�٥