All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Gerum <rpm@xenomai.org>
To: Jan Kiszka <jan.kiszka@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-core] [PATCH] Buffer over flow in /proc/xenomai/stat
Date: Wed, 13 Aug 2008 15:06:13 +0200	[thread overview]
Message-ID: <48A2DC45.9040900@domain.hid> (raw)
In-Reply-To: <48A2BD34.2020601@domain.hid>

Jan Kiszka wrote:
> Philippe Gerum wrote:
>> Philippe Gerum wrote:
>>> Atsushi-san,
>>>
>>> Atsushi Katagiri wrote:
>>>> Yes, I actually encountered this bug and my Linux was crashed by NULL pointer dereference.
>>>>
>>>> I think this is a very simple bug.
>>>> It happens "everytime" we open /proc/xenomai/stat,
>>>> because the last iter->nentries++; (line 466) surely reaches the value of the count,
>>>> and the next iteration, line 449, surely overwrites zero on out of the kmalloced area.
>>>>
>>> Please try this fix instead:
>>>
>> Actually, this one is better:
>>
>> --- ksrc/nucleus/module.c	(revision 4074)
>> +++ ksrc/nucleus/module.c	(working copy)
>> @@ -440,13 +440,13 @@
>>  	/* Iterate over all IRQ numbers, ... */
>>  	for (irq = 0; irq < XNARCH_NR_IRQS; irq++) {
>>  		xnintr_t *prev = NULL;
>> -		int cpu = 0;
>> +		int cpu = 0, _cpu;
>>  		int err;
>>
>>  		/* ...over all shared IRQs on all CPUs */
>>  		while (1) {
>>  			stat_info = &iter->stat_info[iter->nentries];
>> -			stat_info->cpu = cpu;
>> +			_cpu = cpu;
>>
>>  			err = xnintr_query(irq, &cpu, &prev, intr_rev,
>>  					   stat_info->name,
>> @@ -458,6 +458,7 @@
>>  			if (err)
>>  				break; /* line unused or end of chain */
>>
>> +			stat_info->cpu = _cpu;
>>  			stat_info->pid = 0;
>>  			stat_info->state =  0;
>>  			stat_info->ssw = 0;
>>
> 
> Good catch. But for the sake of telling variable names I would suggest:
> 
> Index: ksrc/nucleus/module.c
> ===================================================================
> --- ksrc/nucleus/module.c	(Revision 4094)
> +++ ksrc/nucleus/module.c	(Arbeitskopie)
> @@ -444,15 +444,15 @@ static int stat_seq_open(struct inode *i
>  	/* Iterate over all IRQ numbers, ... */
>  	for (irq = 0; irq < XNARCH_NR_IRQS; irq++) {
>  		xnintr_t *prev = NULL;
> -		int cpu = 0, _cpu;
> -		int err;
> +		int next_cpu = 0;
> +		int cpu, err;
>  
>  		/* ...over all shared IRQs on all CPUs */
>  		while (1) {
>  			stat_info = &iter->stat_info[iter->nentries];
> -			_cpu = cpu;
> +			cpu = next_cpu;
>  
> -			err = xnintr_query(irq, &cpu, &prev, intr_rev,
> +			err = xnintr_query(irq, &next_cpu, &prev, intr_rev,
>  					   stat_info->name,
>  					   &stat_info->csw,
>  					   &stat_info->exectime,
> @@ -462,7 +462,7 @@ static int stat_seq_open(struct inode *i
>  			if (err)
>  				break; /* line unused or end of chain */
>  
> -			stat_info->cpu = _cpu;
> +			stat_info->cpu = cpu;
>  			stat_info->pid = 0;
>  			stat_info->state =  0;
>  			stat_info->ssw = 0;
> 

This would be even better with a proper iterator construct.

-- 
Philippe.


  reply	other threads:[~2008-08-13 13:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-04  7:02 [Xenomai-core] [PATCH] Buffer over flow in /proc/xenomai/stat Atsushi Katagiri
2008-08-04  7:49 ` Philippe Gerum
2008-08-04  9:38   ` Atsushi Katagiri
2008-08-04 10:15     ` Philippe Gerum
2008-08-04 10:22       ` Philippe Gerum
2008-08-04 11:42         ` Atsushi Katagiri
2008-08-13 10:53         ` Jan Kiszka
2008-08-13 13:06           ` Philippe Gerum [this message]
2008-08-18 19:11             ` [Xenomai-core] [PATCH] rework xnintr_query (was: [PATCH] Buffer over flow in /proc/xenomai/stat) Jan Kiszka
2008-08-19  9:01               ` [Xenomai-core] [PATCH] rework xnintr_query Philippe Gerum
2008-08-19  9:06                 ` Gilles Chanteperdrix
2008-08-19 19:31                   ` Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48A2DC45.9040900@domain.hid \
    --to=rpm@xenomai.org \
    --cc=jan.kiszka@domain.hid \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.