Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752961AbbBXQob (ORCPT ); Tue, 24 Feb 2015 11:44:31 -0500 Received: from mail-ob0-f176.google.com ([209.85.214.176]:49545 "EHLO mail-ob0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752557AbbBXQo3 (ORCPT ); Tue, 24 Feb 2015 11:44:29 -0500 MIME-Version: 1.0 In-Reply-To: <1424796110-7736-1-git-send-email-ameenali023@gmail.com> References: <1424796110-7736-1-git-send-email-ameenali023@gmail.com> Date: Tue, 24 Feb 2015 08:44:28 -0800 X-Google-Sender-Auth: oHK1wFrvHq5QO5ErJ3cojkXgOPQ Message-ID: Subject: Re: [PATCH] dcssblk.c : Array index 'i' is used before limits check. From: Kees Cook To: Ameen Ali Cc: Martin Schwidefsky , Heiko Carstens , linux390@de.ibm.com, Wolfram Sang , linux-s390@vger.kernel.org, LKML Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1296 Lines: 40 On Tue, Feb 24, 2015 at 8:41 AM, Ameen Ali wrote: > avoid out-of-bounds-read by checking count before indexing. > > Signed-off-by : Ameen Ali Reviewed-by: Kees Cook -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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/