Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5253595imu; Tue, 15 Jan 2019 14:09:06 -0800 (PST) X-Google-Smtp-Source: ALg8bN7eBw5fOJZKhki9xJVvWk+AA0Pys54w+zLBkeuq1w6k97C70SSfXJIi3+lyzSO0PX/eaY+/ X-Received: by 2002:a62:d701:: with SMTP id b1mr6237893pfh.34.1547590146894; Tue, 15 Jan 2019 14:09:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547590146; cv=none; d=google.com; s=arc-20160816; b=AGt5O2zgYu5hkcWLt80BLIOwYkkBxJThq5coIRLDSN8OtzhcVAPHHklM98BJOat8x9 vjZ0adyEVm5BZ1Yva08aScBpaL03bL6PC1EiEx8sIFYIzEFtQJ4VLTqyVutrQLMXnFiy sK+WG0UJrg2frWhIbRM7ouO3s6DNNwC+45Op/zuzOwr3JBzgRPpthWu1f18YJqegrlcr 6KHZh7SYzwWcL5V+LwU5wDp0IT7hwYhaQroU4wr74UpV6cvwYVoD5l9sQZOr0bqmaood j6MAJihr87tWUS+m69E2D1yfPUXMo1ZfvFmypUneLw/nnbmoRdN5GmimeJpi5ePjQV/p kMAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LRQ7bpQ6Z/XjgTjMin2NjpYy7MVTgSvcr6BVeoDZwP8=; b=AL6uXOs4xH3YE6KEMABysOYxO+jApukuoOtGUP/Zzc9iZGATw5Yt+XNiw89FXTQKaG m7joZhmQJoLq6eMpCWKcoH1YbGe6Q8fTpMneK4GgcnRuHLt+796L01rQ+7YRdxYE4kq2 mfec58u4YT8Sxv15B+IpWd/2MX8c6oh8MZhX7/BwbfkgL5qXzEi0ZhmQj7W+EPdA9sYH 5LMH77yANU5QkrM7I07n4z4Wvxwyg12rtyOrQaVGePoQ3Oa0lUDuRjW66WA92FfR4CgY D0P40+KUl45gpmas3hSDMov1H1DUHTMN6ukFFeb5x3JqabUhvsYlP5HkgEeeAe1U5chA mU6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WYappuWO; 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 d125si3900794pgc.418.2019.01.15.14.08.50; Tue, 15 Jan 2019 14:09:06 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=WYappuWO; 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 S2387905AbfAOQqD (ORCPT + 99 others); Tue, 15 Jan 2019 11:46:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:35690 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387895AbfAOQp7 (ORCPT ); Tue, 15 Jan 2019 11:45:59 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3D0DE20645; Tue, 15 Jan 2019 16:45:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547570758; bh=2AurtfLU9c9DqVU4P6QxN5P79UYwh7Nmfxy8F5jBp3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WYappuWOoCP6MxBx69CG3YPcx/f6CfovB9y5vC9MwlBMIU73Zv2uZspXA5NKuTu/I BlbvUUO/2m2Igz9oNcf7IYpnlW1PDmq4Ws4DFPLPvFmxCpPoe3FVy1b7vf0/B9gs7M 9xbRQZF2F0Qz3f1KkovmscQk90kpVKBIkUCJukw4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christian Lamparter , Miquel Raynal , Boris Brezillon Subject: [PATCH 4.20 35/57] mtd: rawnand: qcom: fix memory corruption that causes panic Date: Tue, 15 Jan 2019 17:36:16 +0100 Message-Id: <20190115154912.721001003@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190115154910.734892368@linuxfoundation.org> References: <20190115154910.734892368@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christian Lamparter commit 81d9bdf59092e4755fc4307c93c4589ef0fe2e0f upstream. This patch fixes a memory corruption that occurred in the qcom-nandc driver since it was converted to nand_scan(). On boot, an affected device will panic from a NPE at a weird place: | Unable to handle kernel NULL pointer dereference at virtual address 0 | pgd = (ptrval) | [00000000] *pgd=00000000 | Internal error: Oops: 80000005 [#1] SMP ARM | CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.19.9 #0 | Hardware name: Generic DT based system | PC is at (null) | LR is at nand_block_isbad+0x90/0xa4 | pc : [<00000000>] lr : [] psr: 80000013 | sp : cf839d40 ip : 00000000 fp : cfae9e20 | r10: cf815810 r9 : 00000000 r8 : 00000000 | r7 : 00000000 r6 : 00000000 r5 : 00000001 r4 : cf815810 | r3 : 00000000 r2 : cfae9810 r1 : ffffffff r0 : cf815810 | Flags: Nzcv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none | Control: 10c5387d Table: 8020406a DAC: 00000051 | Process swapper/0 (pid: 1, stack limit = 0x(ptrval)) | [] (nand_block_isbad) from [] | [] (allocate_partition) from [] | [] (add_mtd_partitions) from [] | [] (parse_mtd_partitions) from [] | [] (mtd_device_parse_register) from [] | [] (qcom_nandc_probe) from [] The problem is that the nand_scan()'s qcom_nand_attach_chip callback is updating the nandc->max_cwperpage from 1 to 4. This causes the sg_init_table of clear_bam_transaction() in the driver's qcom_nandc_block_bad() to memset much more than what was initially allocated by alloc_bam_transaction(). This patch restores the old behavior by reallocating the shared bam transaction alloc_bam_transaction() after the chip was identified, but before mtd_device_parse_register() (which is an alias for mtd_device_register() - see panic) gets called. This fixes the corruption and the driver is working again. Cc: stable@vger.kernel.org Fixes: 6a3cec64f18c ("mtd: rawnand: qcom: convert driver to nand_scan()") Signed-off-by: Christian Lamparter Acked-by: Miquel Raynal Signed-off-by: Boris Brezillon Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/nand/raw/qcom_nandc.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) --- a/drivers/mtd/nand/raw/qcom_nandc.c +++ b/drivers/mtd/nand/raw/qcom_nandc.c @@ -2833,6 +2833,16 @@ static int qcom_nand_host_init_and_regis if (ret) return ret; + if (nandc->props->is_bam) { + free_bam_transaction(nandc); + nandc->bam_txn = alloc_bam_transaction(nandc); + if (!nandc->bam_txn) { + dev_err(nandc->dev, + "failed to allocate bam transaction\n"); + return -ENOMEM; + } + } + ret = mtd_device_register(mtd, NULL, 0); if (ret) nand_cleanup(chip); @@ -2847,16 +2857,6 @@ static int qcom_probe_nand_devices(struc struct qcom_nand_host *host; int ret; - if (nandc->props->is_bam) { - free_bam_transaction(nandc); - nandc->bam_txn = alloc_bam_transaction(nandc); - if (!nandc->bam_txn) { - dev_err(nandc->dev, - "failed to allocate bam transaction\n"); - return -ENOMEM; - } - } - for_each_available_child_of_node(dn, child) { host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); if (!host) {