2007-08-15 08:56:53

by Wu Fengguang

[permalink] [raw]
Subject: [PATCH] seqfile: fix uninitialized memory allocation in mounts_open()

proc_mounts.m.buf is not explicitly zeroed at allocation time, which
may later confuse the seqfile code and triggle an kfree(m->buf).

Signed-off-by: Fengguang Wu <[email protected]>
---

--- linux.orig/fs/proc/base.c
+++ linux/fs/proc/base.c
@@ -380,7 +380,7 @@ static int mounts_open(struct inode *ino

if (ns) {
ret = -ENOMEM;
- p = kmalloc(sizeof(struct proc_mounts), GFP_KERNEL);
+ p = kzalloc(sizeof(struct proc_mounts), GFP_KERNEL);
if (p) {
file->private_data = &p->m;
ret = seq_open(file, &mounts_op);


2007-08-15 09:01:27

by Wu Fengguang

[permalink] [raw]
Subject: Re: [PATCH] seqfile: fix uninitialized memory allocation in mounts_open()

On Wed, Aug 15, 2007 at 04:56:37PM +0800, Fengguang Wu wrote:
> proc_mounts.m.buf is not explicitly zeroed at allocation time, which
> may later confuse the seqfile code and triggle an kfree(m->buf).

It's weird it did not show up in real world. Could I be wrong?

> --- linux.orig/fs/proc/base.c
> +++ linux/fs/proc/base.c
> @@ -380,7 +380,7 @@ static int mounts_open(struct inode *ino
>
> if (ns) {
> ret = -ENOMEM;
> - p = kmalloc(sizeof(struct proc_mounts), GFP_KERNEL);
> + p = kzalloc(sizeof(struct proc_mounts), GFP_KERNEL);
> if (p) {
> file->private_data = &p->m;
> ret = seq_open(file, &mounts_op);
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/

2007-08-15 09:04:19

by Alexey Dobriyan

[permalink] [raw]
Subject: Re: [PATCH] seqfile: fix uninitialized memory allocation in mounts_open()

On 8/15/07, Fengguang Wu <[email protected]> wrote:
> proc_mounts.m.buf is not explicitly zeroed at allocation time, which
> may later confuse the seqfile code and triggle an kfree(m->buf).

It's cleared in seq_open().

> --- linux.orig/fs/proc/base.c
> +++ linux/fs/proc/base.c
> @@ -380,7 +380,7 @@ static int mounts_open(struct inode *ino
>
> if (ns) {
> ret = -ENOMEM;
> - p = kmalloc(sizeof(struct proc_mounts), GFP_KERNEL);
> + p = kzalloc(sizeof(struct proc_mounts), GFP_KERNEL);
> if (p) {
> file->private_data = &p->m;
> ret = seq_open(file, &mounts_op);

2007-08-15 09:09:17

by Wu Fengguang

[permalink] [raw]
Subject: Re: [PATCH] seqfile: fix uninitialized memory allocation in mounts_open()

On Wed, Aug 15, 2007 at 01:04:05PM +0400, Alexey Dobriyan wrote:
> On 8/15/07, Fengguang Wu <[email protected]> wrote:
> > proc_mounts.m.buf is not explicitly zeroed at allocation time, which
> > may later confuse the seqfile code and triggle an kfree(m->buf).
>
> It's cleared in seq_open().

So it is :)

> > --- linux.orig/fs/proc/base.c
> > +++ linux/fs/proc/base.c
> > @@ -380,7 +380,7 @@ static int mounts_open(struct inode *ino
> >
> > if (ns) {
> > ret = -ENOMEM;
> > - p = kmalloc(sizeof(struct proc_mounts), GFP_KERNEL);
> > + p = kzalloc(sizeof(struct proc_mounts), GFP_KERNEL);
> > if (p) {
> > file->private_data = &p->m;
> > ret = seq_open(file, &mounts_op);