Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp588035pxb; Fri, 22 Apr 2022 07:24:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5wazKvjW8jvO6ER1DoCgycw3SR0Ji/bpXSYesJPZ29RQdiHdeDhLZXOr/EXQHEST5P0yL X-Received: by 2002:a17:906:3fd1:b0:6ef:606f:e5c5 with SMTP id k17-20020a1709063fd100b006ef606fe5c5mr4330780ejj.441.1650637442818; Fri, 22 Apr 2022 07:24:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650637442; cv=none; d=google.com; s=arc-20160816; b=HJaqVAQJdBXE3KLFzAYkL1iWFLRi2kdySkK7RsUIRGTrpunAfW89qBzmE4/WiiRCqA vmYu3X93g3HjXPYiSxmwxeBczxguK3r0HExiEtG1umyq7pKlnlhe03TKnsv5OijKbaYV k8meLVvzYjIflizHYhQq7BYHzP9NJwWNfRTAayzjHXUrzyh12xRbCjdZlBQcHDwawklp b5WDlmcHlDUyP/Xt2U0F4WnOBycsdbjkmj7Y6r7gBCl6SMrxpj91l2ECF/onjZLN6rmC O/7MDBbU6V7jGQcjKDiDI5MM/lZBTWwKoaRctnzrK6kbiS1KaExCTuURcJIMYGmJltlr XI5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=p4QO0moKpEkXz+ulrvSLQo0T9lC8TOEa3gAblMHHWcg=; b=gw/OrGZLKAyQQ7mftc/UgrIoF1jvMdsbSPNcapGyB+dqcoxpxAD+GsTR3iZ5tgfRIh +XoJoYmS9XM/mWoHZdgNHrVhP+eD4vVYhxOB7IHj0zQGEf/UyFTIhdec0nxTwpfJvT3U GWsGrHGCn2YNzoLzGgPNNA/H8LPrNdOAIrH/kTymJNd7fM8jxdXHX1LwhTI6mmTYz2b6 XLtzuZenfQoT13nNo/uUOnsS110VylyWybhgHCmgSsLpWVZ35Mvd1PRGIHldp8dDeadp DdmK6vk79Tcie7FVDL49haASRwkL1nhH4G0KmPiK5+8w/1799dNetamuQqhxBRTWSUJy UMgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=W5tjJw+u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z7-20020a50f147000000b00425c6ad47edsi266440edl.291.2022.04.22.07.23.38; Fri, 22 Apr 2022 07:24:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=W5tjJw+u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1385847AbiDUHid (ORCPT + 99 others); Thu, 21 Apr 2022 03:38:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385887AbiDUHiY (ORCPT ); Thu, 21 Apr 2022 03:38:24 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B847D13DD3; Thu, 21 Apr 2022 00:35:31 -0700 (PDT) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 55E7A1C000F; Thu, 21 Apr 2022 07:35:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1650526529; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p4QO0moKpEkXz+ulrvSLQo0T9lC8TOEa3gAblMHHWcg=; b=W5tjJw+uF9lptPqXryNnTwotnKABgq9Ic3j79bCDlyH4iFgliXcsv9VSd7n99CplsWqHCq okVua35NKDn/cOEwdtfhzT3+mokU0WhN1lah0wBVHe3nqb6em5PDNp5vJtLwKz6yXV+Zgw vrf9KgFxLeQlocnMMpzXJHdG54xIiL887VIpXmBbT5sw8omtoMXb0CzImEZkf7fQPOs8iz HmgZr3qiTBbVnufIUcXIru9Cy+I0hPCyWbZa4qVPZbVclAW+xG73nDp16a9J9YYzuyj0j3 Rd/slS5Gex4c2ycFMo2uZ3M9C51cMLv3LXCpbG7V+b7WX2aJimX71A4eDWNpwQ== From: Miquel Raynal To: Md Sadre Alam , mani@kernel.org, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, linux-mtd@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: konrad.dybcio@somainline.org, quic_srichara@quicinc.com, stable@vger.kernel.org Subject: Re: [PATCH V5] mtd: rawnand: qcom: fix memory corruption that causes panic Date: Thu, 21 Apr 2022 09:35:27 +0200 Message-Id: <20220421073527.71690-1-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <1650268107-5363-1-git-send-email-quic_mdalam@quicinc.com> References: MIME-Version: 1.0 X-linux-mtd-patch-notification: thanks X-linux-mtd-patch-commit: b'ba7542eb2dd5dfc75c457198b88986642e602065' Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2022-04-18 at 07:48:27 UTC, Md Sadre Alam wrote: > This patch fixes a memory corruption that occurred in the > nand_scan() path for Hynix nand device. > > On boot, for Hynix nand device will panic at a weird place: > | Unable to handle kernel NULL pointer dereference at virtual > address 00000070 > | [00000070] *pgd=00000000 > | Internal error: Oops: 5 [#1] PREEMPT SMP ARM > | Modules linked in: > | CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.17.0-01473-g13ae1769cfb0 > #38 > | Hardware name: Generic DT based system > | PC is at nandc_set_reg+0x8/0x1c > | LR is at qcom_nandc_command+0x20c/0x5d0 > | pc : [] lr : [] psr: 00000113 > | sp : c14adc50 ip : c14ee208 fp : c0cc970c > | r10: 000000a3 r9 : 00000000 r8 : 00000040 > | r7 : c16f6a00 r6 : 00000090 r5 : 00000004 r4 :c14ee040 > | r3 : 00000000 r2 : 0000000b r1 : 00000000 r0 :c14ee040 > | Flags: nzcv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none > | Control: 10c5387d Table: 8020406a DAC: 00000051 > | Register r0 information: slab kmalloc-2k start c14ee000 pointer offset > 64 size 2048 > | Process swapper/0 (pid: 1, stack limit = 0x(ptrval)) > | nandc_set_reg from qcom_nandc_command+0x20c/0x5d0 > | qcom_nandc_command from nand_readid_op+0x198/0x1e8 > | nand_readid_op from hynix_nand_has_valid_jedecid+0x30/0x78 > | hynix_nand_has_valid_jedecid from hynix_nand_init+0xb8/0x454 > | hynix_nand_init from nand_scan_with_ids+0xa30/0x14a8 > | nand_scan_with_ids from qcom_nandc_probe+0x648/0x7b0 > | qcom_nandc_probe from platform_probe+0x58/0xac > > The problem is that the nand_scan()'s qcom_nand_attach_chip callback > is updating the nandc->max_cwperpage from 1 to 4 or 8 based on page size. > This causes the sg_init_table of clear_bam_transaction() in the driver's > qcom_nandc_command() to memset much more than what was initially > allocated by alloc_bam_transaction(). > > This patch will update nandc->max_cwperpage 1 to 4 or 8 based on page > size in qcom_nand_attach_chip call back after freeing the previously > allocated memory for bam txn as per nandc->max_cwperpage = 1 and then > again allocating bam txn as per nandc->max_cwperpage = 4 or 8 based on > page size in qcom_nand_attach_chip call back itself. > > Cc: stable@vger.kernel.org > Fixes: 6a3cec64f18c ("mtd: rawnand: qcom: convert driver to nand_scan()") > Reported-by: Konrad Dybcio > Reviewed-by: Manivannan Sadhasivam > Co-developed-by: Sricharan R > Signed-off-by: Sricharan R > Signed-off-by: Md Sadre Alam Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/fixes, thanks. Miquel