Received: by 10.213.65.68 with SMTP id h4csp722229imn; Fri, 6 Apr 2018 07:51:56 -0700 (PDT) X-Google-Smtp-Source: AIpwx48L2lMa3A9Nwu9XfV1XxHETe2Ndtyrl9AULCzs9y8kfuTXLVeUSfSc+s6DeetwXLgw61bAq X-Received: by 2002:a17:902:1c1:: with SMTP id b59-v6mr27586094plb.325.1523026316207; Fri, 06 Apr 2018 07:51:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523026316; cv=none; d=google.com; s=arc-20160816; b=SatdMy77CalUuuHsGwo6dSkYPCt6YxMwbN8p6sj09cfBSuUFxtyAzdSwEv1hz5JC0P 6WFySMVSvzU2lTjHYhyNkFw1un9/sBp/VY6U0PrVru3T5FWSttG42Ey9J84AxdgW2HMz DBQ/ex1jXmBAPmvYDfkth4YZ+roNtCOb/RrMSkZhXWdR11Tutc+5ECfwk9FEb3u6KHaQ KQA5v0qdrSLfABnCS8CrBbQ8g1m0ghHtYQ72yEq60LhTsHItYrHP8ItuqMXSKAKCOrdQ wY5OLU9MKNeVuHIQPrrblTvLx9xAEd+pgrM7MXd5RQtTbc4L2IWoC7tyEgvzD04BKrt4 2NsA== 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=ORpX67BtVal0nCgjEgRFoO1j+CS8LmUHxSaq6J5vgoI=; b=xm4iL61Kc8gGaPuXgtO6XiLNpIqSMgqfFirXcktdMXgi3hUZRzL7l8shbTqCj7ho8K 2/ZQ8X1jE1JBLmpMpGzUT7thOiLrPdxj85Yg5v0rMspXNt/r73piyK2DSfXOZa9WIAmd l9ZnTRwiS9Km4GP+i+8zfNat8lE9sNhqyRdbjoEjcfDKcMiNmr0w61YAIglHlnqxJUQ+ ZZepdmfMeOuMtR0veV7U8yKRUq5DztfvKoPnuRrSbO0SUdfNDyxTQITkJG79WMtDml/z 6W+sRR0teX3P8cAZ3Mxes5K6LkbDehEjN4971mYReH44N9TKdpIWR2hYmsr1zNy7t8Pf iPfQ== 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 t15si8012950pfa.170.2018.04.06.07.51.42; Fri, 06 Apr 2018 07:51:56 -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 S1755539AbeDFNdP (ORCPT + 99 others); Fri, 6 Apr 2018 09:33:15 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:57798 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755527AbeDFNdM (ORCPT ); Fri, 6 Apr 2018 09:33:12 -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 79304CD0; Fri, 6 Apr 2018 13:33:11 +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.9 002/102] mtd: jedec_probe: Fix crash in jedec_read_mfr() Date: Fri, 6 Apr 2018 15:22:43 +0200 Message-Id: <20180406084331.842625333@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084331.507038179@linuxfoundation.org> References: <20180406084331.507038179@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.9-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);