* [PATCH] Fix memory corruption in console selection
@ 2009-01-30 20:27 Mikulas Patocka
2009-02-02 23:54 ` Andrew Morton
0 siblings, 1 reply; 2+ messages in thread
From: Mikulas Patocka @ 2009-01-30 20:27 UTC (permalink / raw
To: Linus Torvalds; +Cc: linux-kernel
[ I don't know who is the console maintainer or if there is any, so I'm
posting this to Linus ]
Fix an off-by-two memory error in console selection.
The loop below goes from sel_start to sel_end (inclusive), so it writes
one more character. This one more character was added to the allocated
size (+1), but it was not multiplied by an UTF-8 multiplier.
This patch fixes a memory corruption when UTF-8 console is used and the
user selects a few characters, all of them 3-byte in UTF-8 (for example a
frame line).
When memory redzones are enabled, a redzone corruption is reported. When
they are not enabled, trashing of random memory occurs.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
---
drivers/char/selection.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Index: linux-2.6.29-rc3-devel/drivers/char/selection.c
===================================================================
--- linux-2.6.29-rc3-devel.orig/drivers/char/selection.c 2009-01-30 21:03:07.000000000 +0100
+++ linux-2.6.29-rc3-devel/drivers/char/selection.c 2009-01-30 21:03:38.000000000 +0100
@@ -268,7 +268,7 @@ int set_selection(const struct tiocl_sel
/* Allocate a new buffer before freeing the old one ... */
multiplier = use_unicode ? 3 : 1; /* chars can take up to 3 bytes */
- bp = kmalloc((sel_end-sel_start)/2*multiplier+1, GFP_KERNEL);
+ bp = kmalloc(((sel_end-sel_start)/2+1)*multiplier, GFP_KERNEL);
if (!bp) {
printk(KERN_WARNING "selection: kmalloc() failed\n");
clear_selection();
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix memory corruption in console selection
2009-01-30 20:27 [PATCH] Fix memory corruption in console selection Mikulas Patocka
@ 2009-02-02 23:54 ` Andrew Morton
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2009-02-02 23:54 UTC (permalink / raw
To: Mikulas Patocka; +Cc: torvalds, linux-kernel, stable
On Fri, 30 Jan 2009 15:27:14 -0500 (EST)
Mikulas Patocka <mpatocka@redhat.com> wrote:
> [ I don't know who is the console maintainer or if there is any, so I'm
> posting this to Linus ]
>
>
> Fix an off-by-two memory error in console selection.
>
> The loop below goes from sel_start to sel_end (inclusive), so it writes
> one more character. This one more character was added to the allocated
> size (+1), but it was not multiplied by an UTF-8 multiplier.
>
> This patch fixes a memory corruption when UTF-8 console is used and the
> user selects a few characters, all of them 3-byte in UTF-8 (for example a
> frame line).
>
> When memory redzones are enabled, a redzone corruption is reported. When
> they are not enabled, trashing of random memory occurs.
>
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
>
> ---
> drivers/char/selection.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> Index: linux-2.6.29-rc3-devel/drivers/char/selection.c
> ===================================================================
> --- linux-2.6.29-rc3-devel.orig/drivers/char/selection.c 2009-01-30 21:03:07.000000000 +0100
> +++ linux-2.6.29-rc3-devel/drivers/char/selection.c 2009-01-30 21:03:38.000000000 +0100
> @@ -268,7 +268,7 @@ int set_selection(const struct tiocl_sel
>
> /* Allocate a new buffer before freeing the old one ... */
> multiplier = use_unicode ? 3 : 1; /* chars can take up to 3 bytes */
> - bp = kmalloc((sel_end-sel_start)/2*multiplier+1, GFP_KERNEL);
> + bp = kmalloc(((sel_end-sel_start)/2+1)*multiplier, GFP_KERNEL);
> if (!bp) {
> printk(KERN_WARNING "selection: kmalloc() failed\n");
> clear_selection();
The patch is now in mainline for 2.6.29, as
878b8619f711280fd05845e21956434b5e588cc4.
It appears to be applicable to earlier kernels as far back as 2.6.25
(at least). But the -stable maintainers were not informed of this.
An appropriate way of flagging this is to add
Cc: <stable@kernel.org>
to the changelog.
Please, people - we all need to think about this, to prevent stuff from
falling through cracks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-02-02 23:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-30 20:27 [PATCH] Fix memory corruption in console selection Mikulas Patocka
2009-02-02 23:54 ` Andrew Morton
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 read-only IMAP folder(s) and NNTP newsgroup(s).