From patchwork Wed Jul 19 21:55:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 122851 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2739667vqt; Wed, 19 Jul 2023 15:16:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlGr7j4/RJ84p5poh/1T/9j9uJ0bdheRPbhNsFugPpjlsBP4YbM+e1N1cFcEO8WPEVDDbfCE X-Received: by 2002:a5d:4482:0:b0:315:8f4f:81b2 with SMTP id j2-20020a5d4482000000b003158f4f81b2mr776215wrq.64.1689805016551; Wed, 19 Jul 2023 15:16:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689805016; cv=none; d=google.com; s=arc-20160816; b=rj00hLqzXj5wLx2uKb60mU+FjVQQbws19o1hkuz8IlFhAqkBCXhAtXlIrOXJt0nJFb St3I+8ui0cfjdUTO4CGLIVvsj4zJEqCFdzy/oQ9HeKe3OMxfqas/Uf0+ECT+W3NhO/8W a7aHiFNgaH6OpfFUgWPT8ap2tUtOOUbXdO56gPJ0ylkhwoYdHqcr5MkLjwxzm4xL3T7H 3oCajxtorJbERfl1DTHMXW6ocOFkFSgaN/oAT6zQW+CovxNggzy3NMFPtdWWWFpyV7Ng 1TnhLRoFjy/MWUVuSh88B1ugw/qi9IgZ9hIrEbkV0alIxQtvcSFO/hWHMoLufzWctg12 2lQQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=HzYBbxpYE3IX2TCrR04zl6ewdpf4XKvAL64ilNVr08Q=; fh=Jog91roCXfYk7BVYIdbdF1DXbB4WVZTOrDh/CND0B2k=; b=rxASF9nPj2xUyfSQ2g0Ue10GxpAzielRSQkWjnzUY1Q+mZAfH7iap5ilSvhgO6mX5u 7sQDMGzDaNbONypzVS5orOxFQzEdZ0gpW9MHetsgrTOP9gJlEM2aXmdEotOjCdbV/MVX Fu+FxQDfwlaTjLR5jodlPL1/PtF2WxYmTnnyh7Xpzwwa2300UmpZRiPLAbOYP9YrWYW7 vMSnj/mP5Yy2u4Fsv3pOt3GLMvRMdcny9O3ht94nJGHTKmjMEA0lZ62cC/c9gyOwdqx7 g04ylG244c5P+sWz6ArpN0Li5AXcZzLk+KSMd11odwFALRPZ1XDGmYZ8HNbP5lfe8AwW K6vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=W1NWYKvS; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y4-20020a056402134400b0051dd300b37bsi3703646edw.76.2023.07.19.15.16.32; Wed, 19 Jul 2023 15:16:56 -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=@wanadoo.fr header.s=t20230301 header.b=W1NWYKvS; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229680AbjGSVz2 (ORCPT + 99 others); Wed, 19 Jul 2023 17:55:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229706AbjGSVz0 (ORCPT ); Wed, 19 Jul 2023 17:55:26 -0400 Received: from smtp.smtpout.orange.fr (smtp-22.smtpout.orange.fr [80.12.242.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A2681FE2 for ; Wed, 19 Jul 2023 14:55:23 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id MF8dq7PjtT4RdMF8dqgUPy; Wed, 19 Jul 2023 23:55:20 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1689803720; bh=HzYBbxpYE3IX2TCrR04zl6ewdpf4XKvAL64ilNVr08Q=; h=From:To:Cc:Subject:Date; b=W1NWYKvSI/IzA7HjoHwC98Y8+GYqVdCL4/63SaTE73QP5Tg/gmXrjVOb2UzIVucqK 8kirPYqzz8TCyTkAtxGHAzDl47IEL+CzjI52G8Oms5gj3loRQVbGTGE7lfJlF1Lu2Y +uL94r2Li4n6CHv1cgQX/Ca8F9guUE/gCpQayQta9w0n65amj58int/64YPOZdkddz Qwq8YRpSE1FmGApi1LQcuMRCksXOwW31Ge2Ys14pHP/f4q07yN+lt3vq2gK/AkFGvL zHFqET3z6QgoEznR+fT8w90jfHYLXCQTiHjB6CasG3lG97yta0aCEWYSQnYg4TIF+B a/0WIDdo1ndBQ== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Wed, 19 Jul 2023 23:55:20 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Boris Brezillon Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-mtd@lists.infradead.org Subject: [PATCH] mtd: rawnand: fsl_upm: Fix an off-by one test in fun_exec_op() Date: Wed, 19 Jul 2023 23:55:01 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771888984555095822 X-GMAIL-MSGID: 1771888984555095822 'op-cs' is copied in 'fun->mchip_number' which is used to access the 'mchip_offsets' and the 'rnb_gpio' arrays. These arrays have NAND_MAX_CHIPS elements, so the index must be below this limit. Fix the sanity check in order to avoid the NAND_MAX_CHIPS value. This would lead to out-of-bound accesses. Fixes: 54309d657767 ("mtd: rawnand: fsl_upm: Implement exec_op()") Signed-off-by: Christophe JAILLET Reviewed-by: Dan Carpenter --- drivers/mtd/nand/raw/fsl_upm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/fsl_upm.c b/drivers/mtd/nand/raw/fsl_upm.c index f1810e2f2c07..0c67fd1347c4 100644 --- a/drivers/mtd/nand/raw/fsl_upm.c +++ b/drivers/mtd/nand/raw/fsl_upm.c @@ -135,7 +135,7 @@ static int fun_exec_op(struct nand_chip *chip, const struct nand_operation *op, unsigned int i; int ret; - if (op->cs > NAND_MAX_CHIPS) + if (op->cs >= NAND_MAX_CHIPS) return -EINVAL; if (check_only)