Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2259456imm; Thu, 7 Jun 2018 07:51:12 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIXIcT8buM7r5P7aWqQYv98pckDKlO8GwyQ/RxurfFAxd6xzdd1p7njkuWwISgDfV1wy65W X-Received: by 2002:a62:830e:: with SMTP id h14-v6mr2127849pfe.64.1528383072909; Thu, 07 Jun 2018 07:51:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528383072; cv=none; d=google.com; s=arc-20160816; b=h9iwdWYxbTKGMEwzqwKi05xBpE0I+LJ4RRlwdICVsJoNVQDq0hoDZya3KopyKK9HeA uoCH2N1hjJL0hRpce01WPYKIfjQhw/bdGrcsEPpHmv+5mWgI2CUTBlGbFUGjGwV/sbA/ NmX+TOwPE7xmORMFsRlMolqP5yrcsjjZS2Cijy7vlh4PlVlT2yGniknvLF0frh3wJSvX czKcfNpNElINIy7r4XgKCW6VLG1D8hcsgx2+Qstp5FL5EhAd7lWxzP3TktSAwOgqy2ne JSObVePxTupLklsDWGDrWBx4N9G7k3yDwvdTBPPF9XXsoGzQ74YzdGeix0uE1GF/uIqx yTAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=UdUDxCwymxYL8516dBG6/HkrrUgL25bo3qKpebWgKGQ=; b=OdP+6mbl8tYvmFwkcIAONV9ImdmnIuHskkqcTdReZ2r3sui0Zz+U/B2Q8nB9MlK1Cl oYFaapD2EKGXP8zazH/U/x+0t2AFWBb9RcvmIdvbFBm2VswDE+3QKLFFYlYALohU/mEh nL1j10Nulv6f30aEkQ/UVC5JD0YcXtrCcL3XH7ynawOOCM8Gublhzf5zMcyRNl91ILAH tsumJcGgmyJhr0I4aGa1bDaCTSCFuyQeflgqQctGsEwCtJWHgby8on82QTXtNooGLg+J P5qhMwCMr5yoPYpZJL7njVoyJfg45TIhIJmtnT10T7eAVQU2ZAtXRk9nLPw0FPerEyGl IUJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m11-v6si41469851plt.284.2018.06.07.07.50.58; Thu, 07 Jun 2018 07:51:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935154AbeFGOti (ORCPT + 99 others); Thu, 7 Jun 2018 10:49:38 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:40877 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933249AbeFGOth (ORCPT ); Thu, 7 Jun 2018 10:49:37 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbI-0005Zm-K0; Thu, 07 Jun 2018 15:09:16 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvbF-0003Kd-Mx; Thu, 07 Jun 2018 15:09:13 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Linus Walleij" , "Boris Brezillon" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 409/410] mtd: jedec_probe: Fix crash in jedec_read_mfr() In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Linus Walleij commit 87a73eb5b56fd6e07c8e499fe8608ef2d8912b82 upstream. It turns out that the loop where we read manufacturer jedec_read_mfd() can under some circumstances get a CFI_MFR_CONTINUATION repeatedly, making the loop go over all banks and eventually hit the end of the map and crash because of an access violation: Unable to handle kernel paging request at virtual address c4980000 pgd = (ptrval) [c4980000] *pgd=03808811, *pte=00000000, *ppte=00000000 Internal error: Oops: 7 [#1] PREEMPT ARM CPU: 0 PID: 1 Comm: swapper Not tainted 4.16.0-rc1+ #150 Hardware name: Gemini (Device Tree) PC is at jedec_probe_chip+0x6ec/0xcd0 LR is at 0x4 pc : [] lr : [<00000004>] psr: 60000013 sp : c382dd18 ip : 0000ffff fp : 00000000 r10: c0626388 r9 : 00020000 r8 : c0626340 r7 : 00000000 r6 : 00000001 r5 : c3a71afc r4 : c382dd70 r3 : 00000001 r2 : c4900000 r1 : 00000002 r0 : 00080000 Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none Control: 0000397f Table: 00004000 DAC: 00000053 Process swapper (pid: 1, stack limit = 0x(ptrval)) Fix this by breaking the loop with a return 0 if the offset exceeds the map size. Fixes: 5c9c11e1c47c ("[MTD] [NOR] Add support for flash chips with ID in bank other than 0") Signed-off-by: Linus Walleij Signed-off-by: Boris Brezillon Signed-off-by: Ben Hutchings --- drivers/mtd/chips/jedec_probe.c | 2 ++ 1 file changed, 2 insertions(+) --- 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);