[prev in list] [next in list] [prev in thread] [next in thread]
List: kernel-janitors
Subject: Re: [patch] tlb_uv: handle large snprintf() returns
From: Andrew Morton <akpm () linux-foundation ! org>
Date: 2010-09-27 23:12:03
Message-ID: 20100927161203.732833b0.akpm () linux-foundation ! org
[Download RAW message or body]
On Mon, 16 Aug 2010 12:55:02 +0200
Dan Carpenter <error27@gmail.com> wrote:
> snprintf() returns the number of bytes that *would* have been copied if
> the buffer was large enough, so it can be larger than the size of the
> buffer. In this case it's ok, but let's put a cap on it anyway so it's
> easier to audit.
>
> Signed-off-by: Dan Carpenter <error27@gmail.com>
>
> diff --git a/arch/x86/kernel/tlb_uv.c b/arch/x86/kernel/tlb_uv.c
> index 312ef02..5e88b3a 100644
> --- a/arch/x86/kernel/tlb_uv.c
> +++ b/arch/x86/kernel/tlb_uv.c
> @@ -1012,6 +1012,9 @@ static ssize_t tunables_read(struct file *file, char __user *userbuf,
> timeoutsb4reset, ipi_reset_limit, complete_threshold,
> congested_response_us, congested_reps, congested_period);
>
> + if (ret > 300)
> + ret = 300;
> +
> return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
> }
That 300-byte local array is yuk.
Duplicating the "300" later in the function (instead of using sizeof)
is also yuk.
The code can be deyukked by using sprintf_to_user(), only we don't have
one. But we do have kasprintf().
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic