From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from imap1.codethink.co.uk ([176.9.8.82]:60030 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752960AbeENPQE (ORCPT ); Mon, 14 May 2018 11:16:04 -0400 Message-ID: <1526310960.9159.3.camel@codethink.co.uk> Subject: Re: [PATCH 4.4 01/72] mtd: jedec_probe: Fix crash in jedec_read_mfr() From: Ben Hutchings To: Linus Walleij , Boris Brezillon Cc: stable@vger.kernel.org, Greg Kroah-Hartman , LKML Date: Mon, 14 May 2018 16:16:00 +0100 In-Reply-To: <20180406084305.298690833@linuxfoundation.org> References: <20180406084305.210085169@linuxfoundation.org> <20180406084305.298690833@linuxfoundation.org> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org List-ID: On Fri, 2018-04-06 at 15:23 +0200, Greg Kroah-Hartman wrote: > 4.4-stable review patch.  If anyone has any objections, please let me know. > > ------------------ > > From: Linus Walleij > > commit 87a73eb5b56fd6e07c8e499fe8608ef2d8912b82 upstream. [...] > --- a/drivers/mtd/chips/jedec_probe.c > +++ b/drivers/mtd/chips/jedec_probe.c > @@ -1889,6 +1889,8 @@ static inline u32 jedec_read_mfr(struct >   do { >   uint32_t ofs = cfi_build_cmd_addr(0 + (bank << 8), map, cfi); >   mask = (1 << (cfi->device_type * 8)) - 1; > + if (ofs >= map->size) > + return 0; >   result = map_read(map, base + ofs); >   bank++; >   } while ((result.x[0] & mask) == CFI_MFR_CONTINUATION); Looking at the calling code several levels up, in genprobe_ident_chips(): max_chips = map->size >> cfi.chipshift; [...] for (i = 1; i < max_chips; i++) { cp->probe_chip(map, i << cfi.chipshift, chip_map, &cfi); } The expression i << cfi.chipshift becomes the base parameter here, so we have base < map->size. That implies to me that map->size is the size of the complete mapping, and we need to compare it with the complete address. So shouldn't the test be ofs >= (map->size - base)? Or even ofs >= (1 << cfi->chipshift)? Ben. -- Ben Hutchings Software Developer, Codethink Ltd.