Received: by 10.213.65.68 with SMTP id h4csp688339imn; Fri, 6 Apr 2018 07:20:15 -0700 (PDT) X-Google-Smtp-Source: AIpwx49IwOGx1uwMz+itzLEkSFd+5pwkMMcHU29qiPl2szNVQ/O7nYwIu2+gvrw8oHxNiF/xDdzf X-Received: by 2002:a17:902:7049:: with SMTP id h9-v6mr27306390plt.386.1523024414972; Fri, 06 Apr 2018 07:20:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523024414; cv=none; d=google.com; s=arc-20160816; b=LRPr2YiTH5DJM3cotDK9KoedMUS+FkF90cAzZpwBwInaZxwL0IxPkZ5hpTnMsGooX2 OFmu3NOKIGOqmGPUMc2O26Xnrh3vKr+Rd5L1MpnJg+88jR0D4p5+kOfPSj4JfhQsBO2q ZjBNxSYiXW1DymEGVI/mlh3H4U9VT3sondNUfG/t8yb5xvkUoewDq+z8tXG67YEtuMbt DhTEpz+3YgkGUk55gTeDnlAce0xR2eutbpIcpIJdQGss85WfoGqhIQp3GGZoqIyXBnZj /156YZJzYM8pZEZpNyqne87axumxabAU+C4Ov6MEUrmgaUZxfTxvB/CO8WDTyjQAAjaT MP5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=KZNgMbAdIvK/t8eqh/xw2EEcdqDtKTdAAO43yoZe4IE=; b=rnshrkRtSupUwL83hsv8hm4Y4ruIxJFUVlwwDhKXgHMuBPODiOWDo/OjH8DOMkpys9 /v+n22xE0GS8cdGsw/PRamhb2NA8zMkaSta2mXQmTBPTd+dUy1pTzbi2z1OkRP77KFj/ UU5y/nQGLRXTunuNIWKd0xOEy9awiRBXFqJJSZSHZZas0nPKhJOCD3zh2GwsotWroSTG 6bCklp2fj2iSGXWh/L1XyyKn2tbIiv+B31RM9AIleGP1Yp2dXeUnpdvQ+4wvuOopCwb/ cPBs7JQ+1ORIqTDxPeBKssy82ikrbn4f0sm4g0BbFecFajDIbMww3ctnc4urCLEH41nK NxGw== 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 u184si7166902pgc.699.2018.04.06.07.20.00; Fri, 06 Apr 2018 07:20:14 -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 S1756510AbeDFOS7 (ORCPT + 99 others); Fri, 6 Apr 2018 10:18:59 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33566 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932487AbeDFNin (ORCPT ); Fri, 6 Apr 2018 09:38:43 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C5B22D1F; Fri, 6 Apr 2018 13:38:42 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linus Walleij , Boris Brezillon Subject: [PATCH 4.14 05/67] mtd: jedec_probe: Fix crash in jedec_read_mfr() Date: Fri, 6 Apr 2018 15:23:35 +0200 Message-Id: <20180406084341.973252108@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084341.225558262@linuxfoundation.org> References: <20180406084341.225558262@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable 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") Cc: Signed-off-by: Linus Walleij Signed-off-by: Boris Brezillon Signed-off-by: Greg Kroah-Hartman --- 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);