Message ID | 20230606231252.94838-5-william.zhang@broadcom.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3731182vqr; Tue, 6 Jun 2023 16:20:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5pQ1m5pfjwKZBeiY/LirafmnkakIUE0o0hO7J5tiAxX8grG/afpMrcthXHqNNrVq4ITVGo X-Received: by 2002:a05:6359:324:b0:129:c2dc:1bcb with SMTP id ef36-20020a056359032400b00129c2dc1bcbmr645245rwb.1.1686093639677; Tue, 06 Jun 2023 16:20:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686093639; cv=none; d=google.com; s=arc-20160816; b=kouk/prPTVIrFpMQrHdZIypG5J52TpH3xusSr96bsksL5oqL0eMEbwEtT5nANqjmSi fjvf3YqNjJJ7+4H5oGO/Kr1vUktQM5k990ZtLq4Ximvzj868hg93toYRaXg65iEfw6gC I2+TMXdh7FFPggq74QkiFXBLfJ8evftETp1Hq1D5ptqVxRl2pzfxJ0BFhl3g/fF5p8aD faIPN5e5CttmHj4CcBAhHK3jGSGUh100wfe3Z7wSYBzq0yItSUAOShML1zGXgrjaknVo 6bmnP0UxA9AxzLFA5PEYx3ua02ZUhMDYdgfOEdKK4IfaPXMB0yKpw9WMzi2TIIJEjWcA Ee/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Y/bt+LEczbR9ZUUhvtsOE3sTva/F2otJWZaeIMwxWEk=; b=gwiFTbLvrQvCImR9HpHaJRE7AXDrNXggSv4WBxh6syn75Onnfxm2k5mGC+xyhk9OlW EzxQwVKwUBNke2es/43SMVZ7lb7+T0S5o9Pb7PJ+7NBcuQYfM98ZQYRo6NzLeJFOEF5c 7YlhcQHXzSugWhKQ7Keib12PWrv7swPgu0JTkLe1J4uOd8A9qjSAYxfmD1Wx3Dicnmz3 M05ChTT1OCDJRR1JzgTem4FW5NTtvtafI9BDeVrf8tXGXqDXGTeXTwVrZhiAyq1PlWFe weLeYV+dxWiv5v54eWz3OEUaJ4jW7W9p5uKKE4NOMnzhn2Zs8p9jrs5ENXU72s7WXFgE j/jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=IcvpTxqz; 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=broadcom.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ca5-20020a17090af30500b00255d8dda719si106059pjb.148.2023.06.06.16.20.24; Tue, 06 Jun 2023 16:20:39 -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=@broadcom.com header.s=google header.b=IcvpTxqz; 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=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240234AbjFFXOq (ORCPT <rfc822;xxoosimple@gmail.com> + 99 others); Tue, 6 Jun 2023 19:14:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240217AbjFFXOe (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 6 Jun 2023 19:14:34 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7252C19A0 for <linux-kernel@vger.kernel.org>; Tue, 6 Jun 2023 16:14:27 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-75d5051fad3so459497985a.3 for <linux-kernel@vger.kernel.org>; Tue, 06 Jun 2023 16:14:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1686093266; x=1688685266; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=Y/bt+LEczbR9ZUUhvtsOE3sTva/F2otJWZaeIMwxWEk=; b=IcvpTxqz3X3uEzw7gAkqP2liMCfJ2uugzeIKp6t36GLVNCcdf6xV5178qrmEUAsyOX mLvx6qrqCfXcUN/hqyEGHOmAzXMv4b6GKoGR1aWaxPc9mrIvr9BAVVVv5Eis1QBj2qYb mif4GWt4gIjcabQYs+fXdHxksx8EP8zVHs2IY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686093266; x=1688685266; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Y/bt+LEczbR9ZUUhvtsOE3sTva/F2otJWZaeIMwxWEk=; b=MzsmuL2J3jqemKM0SllD1LOOEMn2sMsQfwD3+EGqOrpApQviNBL+w9QmnyKsVrdPZB uikCiwHSomFBbLDk7IEtDxbevqgi13bWT95QHg0EdffUUmJd+FfiRx4wXGcF+GBqZOG4 2von6T7PLvyL17fAC6yutTf/2516cPWiX8r0jDprmDouM+fVn8mTp/5HjPfQOEp+T1wG 2Vbtd5loOO4KSwUjrvNTgxuIoyYZ4DY3t6MZ+7n5jCsfaQkLrxBLPNELVNI+HRr7zqxL j98C/R7V84NhuS2KgngoICvzm8UA2iWWy/glgHZ49TgiPeRbQkcZlw5+ylsVXxnCPF4q wN7Q== X-Gm-Message-State: AC+VfDxjYSXE86BmjhEMPO0qT/3nS5zoJ8C6rF9B4/Ke2AuZkdvBiJIg gcT72sd/YkdbSILO/amTfKB1h2bJYK1DTvi2Oh4= X-Received: by 2002:a05:620a:6285:b0:75d:5446:3bff with SMTP id ov5-20020a05620a628500b0075d54463bffmr132327qkn.55.1686093266463; Tue, 06 Jun 2023 16:14:26 -0700 (PDT) Received: from ubuntu-22.localdomain ([192.19.222.250]) by smtp.gmail.com with ESMTPSA id x9-20020ae9e909000000b0075b23e55640sm5221519qkf.123.2023.06.06.16.14.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 16:14:25 -0700 (PDT) From: William Zhang <william.zhang@broadcom.com> To: Broadcom Kernel List <bcm-kernel-feedback-list@broadcom.com>, Linux MTD List <linux-mtd@lists.infradead.org> Cc: f.fainelli@gmail.com, rafal@milecki.pl, kursad.oney@broadcom.com, joel.peshkin@broadcom.com, computersforpeace@gmail.com, anand.gore@broadcom.com, dregan@mail.com, kamal.dasu@broadcom.com, tomer.yacoby@broadcom.com, dan.beygelman@broadcom.com, William Zhang <william.zhang@broadcom.com>, Florian Fainelli <florian.fainelli@broadcom.com>, Miquel Raynal <miquel.raynal@bootlin.com>, linux-kernel@vger.kernel.org, Vignesh Raghavendra <vigneshr@ti.com>, Richard Weinberger <richard@nod.at>, Kamal Dasu <kdasu.kdev@gmail.com> Subject: [PATCH 04/12] mtd: rawnand: brcmnand: Fix potential out-of-bounds access in oob write Date: Tue, 6 Jun 2023 16:12:44 -0700 Message-Id: <20230606231252.94838-5-william.zhang@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230606231252.94838-1-william.zhang@broadcom.com> References: <20230606231252.94838-1-william.zhang@broadcom.com> MIME-Version: 1.0 Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="0000000000003911eb05fd7e2e21" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767997324144368498?= X-GMAIL-MSGID: =?utf-8?q?1767997324144368498?= |
Series |
mtd: rawnand: brcmnand: driver and doc updates
|
|
Commit Message
William Zhang
June 6, 2023, 11:12 p.m. UTC
When the oob buffer length is not in multiple of words, the oob write function does out-of-bounds read on the oob source buffer at the last iteration. Fix that by always checking length limit on the oob buffer read and fill with 0xff when reaching the end of the buffer to the oob registers. Fixes: 27c5b17cd1b1 ("mtd: nand: add NAND driver "library" for Broadcom STB NAND controller") Signed-off-by: William Zhang <william.zhang@broadcom.com> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> --- drivers/mtd/nand/raw/brcmnand/brcmnand.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Comments
Hi William, william.zhang@broadcom.com wrote on Tue, 6 Jun 2023 16:12:44 -0700: > When the oob buffer length is not in multiple of words, the oob write > function does out-of-bounds read on the oob source buffer at the last > iteration. Fix that by always checking length limit on the oob buffer > read and fill with 0xff when reaching the end of the buffer to the oob > registers. > > Fixes: 27c5b17cd1b1 ("mtd: nand: add NAND driver "library" for Broadcom STB NAND controller") > Signed-off-by: William Zhang <william.zhang@broadcom.com> > Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> > --- > > drivers/mtd/nand/raw/brcmnand/brcmnand.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c > index 20832857c4aa..d920e88c7f5b 100644 > --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c > +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c > @@ -1486,10 +1486,10 @@ static int write_oob_to_regs(struct brcmnand_controller *ctrl, int i, > > for (j = 0; j < tbytes; j += 4) > oob_reg_write(ctrl, j, > - (oob[j + 0] << 24) | > - (oob[j + 1] << 16) | > - (oob[j + 2] << 8) | > - (oob[j + 3] << 0)); > + (((j < tbytes) ? oob[j] : 0xff) << 24) | > + (((j + 1 < tbytes) ? oob[j + 1] : 0xff) << 16) | > + (((j + 2 < tbytes) ? oob[j + 2] : 0xff) << 8) | > + ((j + 3 < tbytes) ? oob[j + 3] : 0xff)); This is a lot of additional operations which most of the time are not relevant. I would instead got for one less iteration in the for loop when there is unaligned data, and then dedicated if/else to fill the missing bytes. > return tbytes; > } > Thanks, Miquèl
diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index 20832857c4aa..d920e88c7f5b 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -1486,10 +1486,10 @@ static int write_oob_to_regs(struct brcmnand_controller *ctrl, int i, for (j = 0; j < tbytes; j += 4) oob_reg_write(ctrl, j, - (oob[j + 0] << 24) | - (oob[j + 1] << 16) | - (oob[j + 2] << 8) | - (oob[j + 3] << 0)); + (((j < tbytes) ? oob[j] : 0xff) << 24) | + (((j + 1 < tbytes) ? oob[j + 1] : 0xff) << 16) | + (((j + 2 < tbytes) ? oob[j + 2] : 0xff) << 8) | + ((j + 3 < tbytes) ? oob[j + 3] : 0xff)); return tbytes; }