Received: by 10.192.165.156 with SMTP id m28csp1117765imm; Wed, 11 Apr 2018 12:46:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/96USP9aACR+1KrKE8SfBsZHYmzSr9XZ+/GUzlt81m6spo2B7wpFRkj9dJD1enI77Ga2Tv X-Received: by 10.101.97.205 with SMTP id j13mr4358983pgv.266.1523476000470; Wed, 11 Apr 2018 12:46:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523476000; cv=none; d=google.com; s=arc-20160816; b=fhpQPhZff6zjseChNI+tDXhBnq1+O8nDoYei1Zyj1ltuPfa3tLM/fCGbmZN3SEDTwo De8meEnmc0oRsVfqQzdWbLZgNVw+DH5z6OSv7C5nSIGNpZsQW2sWTSZPiM79X9RF/tLz qI3Sxg2l7vqtlP3lUUdJ9NT/HOdj+rXTgSQUiROGHX6yuNJ5ff9ieZQ1NyJtArvh8e9h KY0oDRgDZNjg1uMR75h1AGy00+bjtFXkCEubHQOEvmspFc2ilywTfBlcw+Olzfp1JL02 bpJ7Q4S5J74hMZ4QlmvQXv6vLPl44wnMmw155F5VV5DQV0RbC1QoQFZnppm+d+J1kf3A fXpw== 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=G5vhFIo8gl4thYffGEJx68KdFjQcbeaOLMI9SqxbZOQ=; b=lbHHJBFQrczC168qCoQGKWIiPAzwZBX1rVDKmicZvv6UAKOImlqZHTnxZWOiZk0a5i v/qZAt8SgddsxQES7OmBFaY5lGJahRs7fhOGOykMAkkgc1M/ydYSrKYjWp62p7rMnJCQ NC0wL4LDrIO3uZyhph+t6Thwyipbb6QmsVX5WvCR6QDZv+TcOKdAmgxBD5PWidG7KYKh vSYBRPOqs7HDmRM695fLbKrSLvDxOa1YxCzFApxneNRw22KX4U+v10Ufl9ONjmHdnKJ/ rKYrU00UlmIHttX+j6hqIF/DW9ixSmW9s1ymPxoXFiqqATGHEGItCHzwUNE33zpf2ReB VlSw== 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 s11si1120056pgp.680.2018.04.11.12.46.03; Wed, 11 Apr 2018 12:46:40 -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 S1756732AbeDKTAb (ORCPT + 99 others); Wed, 11 Apr 2018 15:00:31 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37774 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756704AbeDKTA2 (ORCPT ); Wed, 11 Apr 2018 15:00:28 -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 0B6FFD72; Wed, 11 Apr 2018 19:00:27 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masahiro Yamada , Boris Brezillon , Sasha Levin Subject: [PATCH 4.9 170/310] mtd: nand: check ecc->total sanity in nand_scan_tail Date: Wed, 11 Apr 2018 20:35:09 +0200 Message-Id: <20180411183629.954638344@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183622.305902791@linuxfoundation.org> References: <20180411183622.305902791@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: Masahiro Yamada [ Upstream commit 79e0348c4e24fd1affdcf055e0269755580e0fcc ] Drivers are supposed to set correct ecc->{size,strength,bytes} before calling nand_scan_tail(), but it does not complain about ecc->total bigger than oobsize. In this case, chip->scan_bbt() crashes due to memory corruption, but it is hard to debug. It would be kind to fail it earlier with a clear message. Signed-off-by: Masahiro Yamada Signed-off-by: Boris Brezillon Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/nand/nand_base.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -4785,6 +4785,11 @@ int nand_scan_tail(struct mtd_info *mtd) goto err_free; } ecc->total = ecc->steps * ecc->bytes; + if (ecc->total > mtd->oobsize) { + WARN(1, "Total number of ECC bytes exceeded oobsize\n"); + ret = -EINVAL; + goto err_free; + } /* * The number of bytes available for a client to place data into