Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp514125rwl; Tue, 11 Apr 2023 23:28:33 -0700 (PDT) X-Google-Smtp-Source: AKy350Y2EMmLFHx5GR5RGJY6yKesoX5YMalrQOq27Hxa/jP2vsl96k0yls9IWgq6CuudzoZizzrQ X-Received: by 2002:aa7:c913:0:b0:504:a3ec:eacc with SMTP id b19-20020aa7c913000000b00504a3eceaccmr1661778edt.4.1681280913767; Tue, 11 Apr 2023 23:28:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681280913; cv=none; d=google.com; s=arc-20160816; b=fYdod5sP7xcE1KG3iuJ6NR1JlyU2QcZy4nitpeBf7lyYMHsHkdpz2NgET25q7lvyJR Nz2oGpEiQJZ0BXR3sFfTNU1hGqQrg1kPS7yk+7w+HRbR3QkDmqU0tB/0yKqXwAsmAmLg bwdI0YcVaj+2P+ILC3jgIleRvKpuT2qv+UAALZAm73DOEZi6OGffsTkT0yFU8DChp7jp djWwGjuR1soFBlPvft5c6evjY4Bf6iL4n2qvH8HPCHBDCNV/Oyx6BBWgaPU+ZTTuKuq0 g8AksauoQDmiX0onu6ZUam/ee19WtZkbT5O2/WV3Tlb4t8TiiRk30f6sfiMV6ExXmJC5 6tow== 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=ijR0GjfEvDOCR18/yaVWHDk9s/uQwtd45e8HbVoRBEQ=; b=lw5TcEdJui2jgr0nU0Itwk/V1LN7vZIzh+suAUtrWUnyAnlBIO6aH2XkeWGOkJM8WS LmG4dWZyKjiNX0Fl1ftByljsIOfLgN36Z6HrPOr4QgNEHIe8TeBfWzQt36tK/s805wP9 wnMVEnjNDjZYkLEYPasbSdDgo1/lG7pM06c0W7W1R2JOT8z7Us53TAmWIu4nDSqBEu7L lvEOuphI9l7adu3q1scGE0/J1MWBMvTqpeFV33uVyc9EFC23/3EcbiJC7yeRnDKb4CWO I6vg9qJLyM+DVhn2pAggPyCf1FwNOR+1DRYBuwK2LzLYq3Y190Rkah1soj8LuBjbhfu1 EmIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=PfZzkCq9; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j5-20020aa7de85000000b0050489897d31si10007708edv.151.2023.04.11.23.28.05; Tue, 11 Apr 2023 23:28:33 -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=@sberdevices.ru header.s=mail header.b=PfZzkCq9; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229700AbjDLGVb (ORCPT + 99 others); Wed, 12 Apr 2023 02:21:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229574AbjDLGV0 (ORCPT ); Wed, 12 Apr 2023 02:21:26 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9CB6E49 for ; Tue, 11 Apr 2023 23:21:22 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 0E3E35FD62; Wed, 12 Apr 2023 09:21:21 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1681280481; bh=ijR0GjfEvDOCR18/yaVWHDk9s/uQwtd45e8HbVoRBEQ=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=PfZzkCq9CfP69XL505bFICG6fQTHQzkN70Rkt6pEOLy6eMuNbijDMoHHDAOY49mQo q1cXnKYiwWKg2qrhAHi2oC4sHDDazFy2C7SO+2qlfiiuBMjh7uJqfRu1jI+84xxHF3 RF4PLF+/2LCXHbjA6gFaB408oiHijSXmao+vbdqEvGulBHdb/RSVLuv54sEjRLZ9Lv tw8a/fB/sM9YPQQbl/x2Q0HNBBDLq0gNraT/NUC8T+NVAmscMoSkGh/ZWaCsZurxau CQBrljvgymE+ZEguk0nVtlfO62vqMQIdoETUXJR+hQI4RahO7T1cBjLn0uwEbsp9Fu ix43OXeg9E9Wg== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Wed, 12 Apr 2023 09:21:21 +0300 (MSK) From: Arseniy Krasnov To: Liang Yang , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Yixun Lan , Jianxin Pan CC: , , Arseniy Krasnov , , , , Subject: [PATCH v1 3/5] mtd: rawnand: meson: check buffer length Date: Wed, 12 Apr 2023 09:16:57 +0300 Message-ID: <20230412061700.1492474-4-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230412061700.1492474-1-AVKrasnov@sberdevices.ru> References: <20230412061700.1492474-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/04/12 04:12:00 #21090163 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 With this chip, buffer length is limited by hardware, so check it before command execution to avoid length trim. Signed-off-by: Arseniy Krasnov --- drivers/mtd/nand/raw/meson_nand.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c index 45b53d420aed..f84a10238e4d 100644 --- a/drivers/mtd/nand/raw/meson_nand.c +++ b/drivers/mtd/nand/raw/meson_nand.c @@ -543,6 +543,9 @@ static int meson_nfc_read_buf(struct nand_chip *nand, u8 *buf, int len) u32 cmd; u8 *info; + if (len > NFC_CMD_RAW_LEN) + return -EINVAL; + info = kzalloc(PER_INFO_BYTE, GFP_KERNEL); if (!info) return -ENOMEM; @@ -571,6 +574,9 @@ static int meson_nfc_write_buf(struct nand_chip *nand, u8 *buf, int len) int ret = 0; u32 cmd; + if (len > NFC_CMD_RAW_LEN) + return -EINVAL; + ret = meson_nfc_dma_buffer_setup(nand, buf, len, NULL, 0, DMA_TO_DEVICE); if (ret) @@ -1269,6 +1275,7 @@ static int meson_nand_attach_chip(struct nand_chip *nand) struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); struct mtd_info *mtd = nand_to_mtd(nand); int nsectors = mtd->writesize / 1024; + int raw_writesize; int ret; if (!mtd->name) { @@ -1280,6 +1287,13 @@ static int meson_nand_attach_chip(struct nand_chip *nand) return -ENOMEM; } + raw_writesize = mtd->writesize + mtd->oobsize; + if (raw_writesize > NFC_CMD_RAW_LEN) { + dev_err(nfc->dev, "too big write size in raw mode: %d > %ld\n", + raw_writesize, NFC_CMD_RAW_LEN); + return -EINVAL; + } + if (nand->bbt_options & NAND_BBT_USE_FLASH) nand->bbt_options |= NAND_BBT_NO_OOB; -- 2.35.0