Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[patch] kcore: fix test for end of list

3 views
Skip to first unread message

Dan Carpenter

unread,
Mar 22, 2010, 8:10:03 AM3/22/10
to
"m" is never NULL here. We need a different test for the end of list
condition.

Signed-off-by: Dan Carpenter <err...@gmail.com>
---
Found with a static checker and compile tested only. Please review
carefully.

diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index a44a789..b442dac 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -490,7 +490,7 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
}
read_unlock(&kclist_lock);

- if (m == NULL) {
+ if (&m->list == &kclist_head) {
if (clear_user(buffer, tsz))
return -EFAULT;
} else if (is_vmalloc_or_module_addr((void *)start)) {
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

KAMEZAWA Hiroyuki

unread,
Mar 22, 2010, 8:30:02 PM3/22/10
to
On Mon, 22 Mar 2010 15:05:09 +0300
Dan Carpenter <err...@gmail.com> wrote:

> "m" is never NULL here. We need a different test for the end of list
> condition.
>
> Signed-off-by: Dan Carpenter <err...@gmail.com>

yes, thank you.
Acked-by: KAMEZAWA Hiroyuki <kamezaw...@jp.fujitsu.com>

Américo Wang

unread,
Mar 22, 2010, 10:50:01 PM3/22/10
to
On Tue, Mar 23, 2010 at 8:18 AM, KAMEZAWA Hiroyuki
<kamezaw...@jp.fujitsu.com> wrote:
> On Mon, 22 Mar 2010 15:05:09 +0300
> Dan Carpenter <err...@gmail.com> wrote:
>
>> "m" is never NULL here.  We need a different test for the end of list
>> condition.
>>
>> Signed-off-by: Dan Carpenter <err...@gmail.com>
>
> yes, thank you.
> Acked-by: KAMEZAWA Hiroyuki <kamezaw...@jp.fujitsu.com>

Yeah, this is a good catch for me too!

Acked-by: WANG Cong <xiyou.w...@gmail.com>

Andrew Morton

unread,
Mar 23, 2010, 2:40:01 AM3/23/10
to
On Mon, 22 Mar 2010 15:05:09 +0300 Dan Carpenter <err...@gmail.com> wrote:

> "m" is never NULL here. We need a different test for the end of list
> condition.
>
> Signed-off-by: Dan Carpenter <err...@gmail.com>
> ---
> Found with a static checker and compile tested only. Please review
> carefully.
>
> diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
> index a44a789..b442dac 100644
> --- a/fs/proc/kcore.c
> +++ b/fs/proc/kcore.c
> @@ -490,7 +490,7 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
> }
> read_unlock(&kclist_lock);
>
> - if (m == NULL) {
> + if (&m->list == &kclist_head) {
> if (clear_user(buffer, tsz))
> return -EFAULT;
> } else if (is_vmalloc_or_module_addr((void *)start)) {

hm, that code's been there for five years. I wonder if it's actually necessary.

KAMEZAWA Hiroyuki

unread,
Mar 23, 2010, 3:00:01 AM3/23/10
to
On Mon, 22 Mar 2010 23:31:13 -0400
Andrew Morton <ak...@linux-foundation.org> wrote:

> On Mon, 22 Mar 2010 15:05:09 +0300 Dan Carpenter <err...@gmail.com> wrote:
>
> > "m" is never NULL here. We need a different test for the end of list
> > condition.
> >
> > Signed-off-by: Dan Carpenter <err...@gmail.com>
> > ---
> > Found with a static checker and compile tested only. Please review
> > carefully.
> >
> > diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
> > index a44a789..b442dac 100644
> > --- a/fs/proc/kcore.c
> > +++ b/fs/proc/kcore.c
> > @@ -490,7 +490,7 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
> > }
> > read_unlock(&kclist_lock);
> >
> > - if (m == NULL) {
> > + if (&m->list == &kclist_head) {
> > if (clear_user(buffer, tsz))
> > return -EFAULT;
> > } else if (is_vmalloc_or_module_addr((void *)start)) {
>
> hm, that code's been there for five years. I wonder if it's actually necessary.
>

Hmm..on x86 and others, finally,
(kern_addr_valid(start))
will catch bad access. But some architectures seems to define kern_addr_valid() as

#define kern_addr_valid(addr) (1) (from arch/ia64/include/asm/pgtable.h)

Then, we should check "start" is valid address by ourselves (for now). We have
a complete list of registered address in kclist_head.

Regards,
-Kame

Américo Wang

unread,
Mar 23, 2010, 3:10:02 AM3/23/10
to
On Tue, Mar 23, 2010 at 11:31 AM, Andrew Morton
<ak...@linux-foundation.org> wrote:
> On Mon, 22 Mar 2010 15:05:09 +0300 Dan Carpenter <err...@gmail.com> wrote:
>
>> "m" is never NULL here.  We need a different test for the end of list
>> condition.
>>
>> Signed-off-by: Dan Carpenter <err...@gmail.com>
>> ---
>> Found with a static checker and compile tested only.  Please review
>> carefully.
>>
>> diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
>> index a44a789..b442dac 100644
>> --- a/fs/proc/kcore.c
>> +++ b/fs/proc/kcore.c
>> @@ -490,7 +490,7 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
>>               }
>>               read_unlock(&kclist_lock);
>>
>> -             if (m == NULL) {
>> +             if (&m->list == &kclist_head) {
>>                       if (clear_user(buffer, tsz))
>>                               return -EFAULT;
>>               } else if (is_vmalloc_or_module_addr((void *)start)) {
>
> hm, that code's been there for five years.  I wonder if it's actually necessary.

Nope, not that long, please see commit 2ef43ec7. :)

0 new messages