* [PATCH] kobject: Read buffer overflow
@ 2009-08-02 8:02 Roel Kluin
2009-08-02 10:06 ` Thibaut VARENE
2009-08-02 23:33 ` James Bottomley
0 siblings, 2 replies; 5+ messages in thread
From: Roel Kluin @ 2009-08-02 8:02 UTC (permalink / raw)
To: kyle, deller, linux-parisc, Andrew Morton
Check whether index is within bounds before testing the element.
Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
This also removes the likely, should it be kept?
diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
index f9f9a5f..13a64bc 100644
--- a/drivers/parisc/pdc_stable.c
+++ b/drivers/parisc/pdc_stable.c
@@ -370,7 +370,7 @@ pdcspath_layer_read(struct pdcspath_entry *entry, char *buf)
if (!i) /* entry is not ready */
return -ENODATA;
- for (i = 0; devpath->layers[i] && (likely(i < 6)); i++)
+ for (i = 0; i < 6 && devpath->layers[i]; i++)
out += sprintf(out, "%u ", devpath->layers[i]);
out += sprintf(out, "\n");
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] kobject: Read buffer overflow
2009-08-02 8:02 [PATCH] kobject: Read buffer overflow Roel Kluin
@ 2009-08-02 10:06 ` Thibaut VARENE
2009-08-02 10:16 ` Matthew Wilcox
2009-08-02 23:33 ` James Bottomley
1 sibling, 1 reply; 5+ messages in thread
From: Thibaut VARENE @ 2009-08-02 10:06 UTC (permalink / raw)
To: Roel Kluin; +Cc: kyle, deller, linux-parisc, Andrew Morton
On Sun, Aug 2, 2009 at 10:02 AM, Roel Kluin<roel.kluin@gmail.com> wrote=
:
> Check whether index is within bounds before testing the element.
The change is correct but:
- There are other places in the code with that construct. Even though
they wouldn't trigger an overflow, why not fixing them too?
- Keep the likely: we are more likely to run out of data in the layers
than to exhaust the counter (which is why no overflow was ever
triggered, I believe ;-)
HTH
T-Bone
> diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.=
c
> index f9f9a5f..13a64bc 100644
> --- a/drivers/parisc/pdc_stable.c
> +++ b/drivers/parisc/pdc_stable.c
> @@ -370,7 +370,7 @@ pdcspath_layer_read(struct pdcspath_entry *entry,=
char *buf)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!i) /* entry is not ready */
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -ENODAT=
A;
>
> - =C2=A0 =C2=A0 =C2=A0 for (i =3D 0; devpath->layers[i] && (likely(i =
< 6)); i++)
> + =C2=A0 =C2=A0 =C2=A0 for (i =3D 0; i < 6 && devpath->layers[i]; i++=
)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0out +=3D sprin=
tf(out, "%u ", devpath->layers[i]);
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0out +=3D sprintf(out, "\n");
> --
> To unsubscribe from this list: send the line "unsubscribe linux-paris=
c" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at =C2=A0http://vger.kernel.org/majordomo-info.ht=
ml
>
--=20
Thibaut VARENE
http://www.parisc-linux.org/~varenet/
--
To unsubscribe from this list: send the line "unsubscribe linux-parisc"=
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] kobject: Read buffer overflow
2009-08-02 10:06 ` Thibaut VARENE
@ 2009-08-02 10:16 ` Matthew Wilcox
2009-08-02 10:24 ` Thibaut VARENE
0 siblings, 1 reply; 5+ messages in thread
From: Matthew Wilcox @ 2009-08-02 10:16 UTC (permalink / raw)
To: Thibaut VARENE; +Cc: Roel Kluin, kyle, deller, linux-parisc, Andrew Morton
On Sun, Aug 02, 2009 at 12:06:59PM +0200, Thibaut VARENE wrote:
> On Sun, Aug 2, 2009 at 10:02 AM, Roel Kluin<roel.kluin@gmail.com> wrote:
> > Check whether index is within bounds before testing the element.
>
> The change is correct but:
> - There are other places in the code with that construct. Even though
> they wouldn't trigger an overflow, why not fixing them too?
> - Keep the likely: we are more likely to run out of data in the layers
> than to exhaust the counter (which is why no overflow was ever
> triggered, I believe ;-)
No, lose the likely. It's a for-loop; gcc will do the right thing.
(If you think I'm wrong, convince me by showing the disassembly of the
compiled code with and without the likely).
--
Matthew Wilcox Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours. We can't possibly take such
a retrograde step."
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] kobject: Read buffer overflow
2009-08-02 10:16 ` Matthew Wilcox
@ 2009-08-02 10:24 ` Thibaut VARENE
0 siblings, 0 replies; 5+ messages in thread
From: Thibaut VARENE @ 2009-08-02 10:24 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: Roel Kluin, kyle, deller, linux-parisc, Andrew Morton
On Sun, Aug 2, 2009 at 12:16 PM, Matthew Wilcox<matthew@wil.cx> wrote:
> On Sun, Aug 02, 2009 at 12:06:59PM +0200, Thibaut VARENE wrote:
>> On Sun, Aug 2, 2009 at 10:02 AM, Roel Kluin<roel.kluin@gmail.com> wr=
ote:
>> > Check whether index is within bounds before testing the element.
>>
>> The change is correct but:
>> - There are other places in the code with that construct. Even thoug=
h
>> they wouldn't trigger an overflow, why not fixing them too?
>> - Keep the likely: we are more likely to run out of data in the laye=
rs
>> than to exhaust the counter (which is why no overflow was ever
>> triggered, I believe ;-)
>
> No, lose the likely. =C2=A0It's a for-loop; gcc will do the right thi=
ng.
I stand corrected then. ;-)
Thanks willy.
T-Bone
--=20
Thibaut VARENE
http://www.parisc-linux.org/~varenet/
--
To unsubscribe from this list: send the line "unsubscribe linux-parisc"=
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] kobject: Read buffer overflow
2009-08-02 8:02 [PATCH] kobject: Read buffer overflow Roel Kluin
2009-08-02 10:06 ` Thibaut VARENE
@ 2009-08-02 23:33 ` James Bottomley
1 sibling, 0 replies; 5+ messages in thread
From: James Bottomley @ 2009-08-02 23:33 UTC (permalink / raw)
To: Roel Kluin; +Cc: kyle, deller, linux-parisc, Andrew Morton
On Sun, 2009-08-02 at 10:02 +0200, Roel Kluin wrote:
> Check whether index is within bounds before testing the element.
>
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
> This also removes the likely, should it be kept?
>
> diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
> index f9f9a5f..13a64bc 100644
> --- a/drivers/parisc/pdc_stable.c
> +++ b/drivers/parisc/pdc_stable.c
> @@ -370,7 +370,7 @@ pdcspath_layer_read(struct pdcspath_entry *entry, char *buf)
> if (!i) /* entry is not ready */
> return -ENODATA;
>
> - for (i = 0; devpath->layers[i] && (likely(i < 6)); i++)
> + for (i = 0; i < 6 && devpath->layers[i]; i++)
Since all patterns like this (swapping the order of conditions with no
side effects in a for loop condition) are basically trivial, shouldn't
they be going via Jiri Kosina (trivial tree)?
James
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-08-02 23:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-02 8:02 [PATCH] kobject: Read buffer overflow Roel Kluin
2009-08-02 10:06 ` Thibaut VARENE
2009-08-02 10:16 ` Matthew Wilcox
2009-08-02 10:24 ` Thibaut VARENE
2009-08-02 23:33 ` James Bottomley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox