2015-02-24 16:56:14

by Ameen

[permalink] [raw]
Subject: [PATCH] dcssblk.c : Array index 'i' is used before limits check.

avoid out-of-bounds-read by checking count before indexing.

Signed-off-by : Ameen Ali <[email protected]>
---
drivers/s390/block/dcssblk.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c
index 96128cb..da21281 100644
--- a/drivers/s390/block/dcssblk.c
+++ b/drivers/s390/block/dcssblk.c
@@ -547,7 +547,7 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
* parse input
*/
num_of_segments = 0;
- for (i = 0; ((buf[i] != '\0') && (buf[i] != '\n') && i < count); i++) {
+ for (i = 0; (i < count && (buf[i] != '\0') && (buf[i] != '\n')); i++) {
for (j = i; (buf[j] != ':') &&
(buf[j] != '\0') &&
(buf[j] != '\n') &&
--
2.1.0


2015-02-24 16:44:31

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH] dcssblk.c : Array index 'i' is used before limits check.

On Tue, Feb 24, 2015 at 8:41 AM, Ameen Ali <[email protected]> wrote:
> avoid out-of-bounds-read by checking count before indexing.
>
> Signed-off-by : Ameen Ali <[email protected]>

Reviewed-by: Kees Cook <[email protected]>

-Kees

> ---
> drivers/s390/block/dcssblk.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c
> index 96128cb..da21281 100644
> --- a/drivers/s390/block/dcssblk.c
> +++ b/drivers/s390/block/dcssblk.c
> @@ -547,7 +547,7 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
> * parse input
> */
> num_of_segments = 0;
> - for (i = 0; ((buf[i] != '\0') && (buf[i] != '\n') && i < count); i++) {
> + for (i = 0; (i < count && (buf[i] != '\0') && (buf[i] != '\n')); i++) {
> for (j = i; (buf[j] != ':') &&
> (buf[j] != '\0') &&
> (buf[j] != '\n') &&
> --
> 2.1.0
>



--
Kees Cook
Chrome OS Security

2015-02-25 09:26:41

by Heiko Carstens

[permalink] [raw]
Subject: Re: [PATCH] dcssblk.c : Array index 'i' is used before limits check.

On Tue, Feb 24, 2015 at 06:41:50PM +0200, Ameen Ali wrote:
> avoid out-of-bounds-read by checking count before indexing.
>
> Signed-off-by : Ameen Ali <[email protected]>
> ---
> drivers/s390/block/dcssblk.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c
> index 96128cb..da21281 100644
> --- a/drivers/s390/block/dcssblk.c
> +++ b/drivers/s390/block/dcssblk.c
> @@ -547,7 +547,7 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
> * parse input
> */
> num_of_segments = 0;
> - for (i = 0; ((buf[i] != '\0') && (buf[i] != '\n') && i < count); i++) {
> + for (i = 0; (i < count && (buf[i] != '\0') && (buf[i] != '\n')); i++) {

Applied, thanks!