From patchwork Fri Oct 6 20:17:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 149397 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp573903vqo; Fri, 6 Oct 2023 13:17:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQz8IzEbPufZD6eLVHvtI7gMYwYIFqwL4oVBJ55XooDThm3/YrxtoDej0a428d8ZloBGkX X-Received: by 2002:a17:90b:33c6:b0:279:19b7:9be7 with SMTP id lk6-20020a17090b33c600b0027919b79be7mr9449282pjb.5.1696623472224; Fri, 06 Oct 2023 13:17:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696623472; cv=none; d=google.com; s=arc-20160816; b=psIxkVfP4kKtgtqL67MQnGEXom8sa7ZNnNyApMmVv2fw+HzmGNjbRLLd8dreUzVWX7 ikRcyeSCqC16txdX3qJ9dK8AkSViBed3RvGh0lurTomQdZU/qtY8XR1s3amPxYXGe0zN Ev8C0KfuV/GUl+cuoO872lAJ63k3xCi4kksOJ7YwTNh+4iT2tJwRMERvZPl8mXfynzig NDoZ4WGHNmyXUHvoJZvA22QFHAKPzcoo4ErDEVBTR1vJXRG43prs6FZTI6/DQ5AKCfOb ZaKHoRzQHzGwwhw+vBjQ8w4kt69OSlxtm9185kQUxcDF2yiq6YWwCCWdx1oNgeQgeeww jtwg== 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=44cFvtKqMAZFN6/2W4HaH3hNmYSsLMnAgOIOpwVomfM=; fh=G+CPWTwETy6dSU5ZbCYAkW2vWooCN/RUD5FDrf0MrYo=; b=LO/Lgg1cimiiLWqyLeeI0X+/0mpj87UvvudrlPlC8sKlY8t3fFj6pTlL1ntusBVido ReF5QZvlC0D/hL5aOCdJ68wvIsNueU0qsNiemN2wFACqcPKz7ZySN7G/AJwEmJOyo6Uo IHRbfIfWhQbpwhF9Cd4gREzmDgsqLvm1OX5IQSo6dBRS8RgSUCsa1GTq+0IAK15wJXjL mwC5HSWq4TrY2+DAug9kTh5uwGDNuODhjIFhe+0DFMPPMpZUMzNIBwMaUUXUh+cNbnbL arHN0h3hckZuaEfeqnWU8R19tSgqWek0x0IEuhZPrJv0HCrf2X5QLmaXwO+lvIhy6bG0 Pf5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Ce2kSLvT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id ki13-20020a170903068d00b001b9f55d28a2si4067663plb.205.2023.10.06.13.17.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 13:17:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Ce2kSLvT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 0DB9F80B02B4; Fri, 6 Oct 2023 13:17:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233423AbjJFURo (ORCPT + 18 others); Fri, 6 Oct 2023 16:17:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233437AbjJFURm (ORCPT ); Fri, 6 Oct 2023 16:17:42 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7E79D8 for ; Fri, 6 Oct 2023 13:17:31 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-5855333fbadso1737760a12.1 for ; Fri, 06 Oct 2023 13:17:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696623451; x=1697228251; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=44cFvtKqMAZFN6/2W4HaH3hNmYSsLMnAgOIOpwVomfM=; b=Ce2kSLvTFnCAoxEyE+73FFor074Illg7hBYKvjSCBx5BsA4SPxRHzXNfZEscBFObB7 8CnkQkQTGQ74zGxOL6xzZzzSQvqotpH/8iSyVSP7A3udZjmTBv6+RgkpYQUy1BVTQNwV KLSRVd7WCTFHmXCoJymafz8uN06rx+NcVmelY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696623451; x=1697228251; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=44cFvtKqMAZFN6/2W4HaH3hNmYSsLMnAgOIOpwVomfM=; b=USgC/UitwFwEMRxmxWSwsi0pSKiDcssuUKIUTjM+80OgC69eVKEKKR71dOvBby0u+6 IGhydX9jl8e6/3tX3Y/M4UhlLSUT8GU4zpIrJyM9H7oOYqFHzCZ5HdjwTzFTxM/8x4Oz FDJYBDTJSlij87Bz7vA1Ik6vrybD/F+4e9ekVCWUl6Oqn00o9uanS6EGzvJAm4978lRq xjJBKPahN1WYkKE/BYUtNtbQzB95WJNBHoB8UmRDUAEAVe9zJmLjQLMpqF9z+7EqJ6ga CnPd3QFFB/SS+/DgGa0VSdLXJS63d33ka6nN0M417klTpCVQRPwpKBKogLmO9Cxlq3i3 N9Lw== X-Gm-Message-State: AOJu0Yx4PRpuI0hJmDuZOkIPG2/AvZNDzZ3HkBvf0jwBdcCyEZa3oeKl 3JTNSdumIMSA6fGc9DIuZsZlbg== X-Received: by 2002:a17:90a:e98c:b0:268:414c:ff3 with SMTP id v12-20020a17090ae98c00b00268414c0ff3mr9383030pjy.23.1696623450927; Fri, 06 Oct 2023 13:17:30 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id rm10-20020a17090b3eca00b0026d214a2b33sm5865157pjb.7.2023.10.06.13.17.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 13:17:30 -0700 (PDT) From: Kees Cook To: Miquel Raynal Cc: Kees Cook , Richard Weinberger , Vignesh Raghavendra , Matthias Brugger , AngeloGioacchino Del Regno , "Gustavo A. R. Silva" , Heiko Stuebner , Martin Blumenstingl , Thierry Reding , Roger Quadros , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Cai Huoqing , Chuanhong Guo , Rob Herring , Li Zetao , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-hardening@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] mtd: rawnand: Annotate struct mtk_nfc_nand_chip with __counted_by Date: Fri, 6 Oct 2023 13:17:28 -0700 Message-Id: <20231006201728.work.750-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1866; i=keescook@chromium.org; h=from:subject:message-id; bh=wj52WE7CwlsQ2BB8Uem6TW+tv4z8geFWBQTRgq+pZr0=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlIGtYrtnPKsIg2iO4Dd3ybiJdrRew0N9KKrFWo eR191/wOjuJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZSBrWAAKCRCJcvTf3G3A JjxZEACEq9RQuj5y0ShuaIfEUoej7S27zHMK5VDww5pUKfNkAzMupLwYOh2Yk6q7ltkpvX6IuWW ROopZqHz/SA0ETIcIKxfWi6DKM+3eaNFCK84JR573dTGlnCvAQEuzLRPoHp7gYUAc1voMXNV4Eb onEUUeNpgaVY1gO+a5QuSTDx1ZFLJpzhHf9AyuEJ1j4o4W7ftzF5ZOrXwh3m2AEcdNudTDX8sdt TZ2xWMWVUU96nOJ351JSEB2DYIQc9B6G2zPFUxsa5FcaCAn76Tll91uRAEcrn8ZIJUwEGFlZccG XWqPoVBzHp4HNxPVdE800NRDNHXVtIZ/7j43uOZPXxRzgdoIcKqScm6sbIAbXp0R1EmfwoYAwfW Nu4VRs3Ar1aLm0xV82hvR3gW6mSSiRLFzRxzj/fl415Q98XkwErnfKjkEmrFO0ox6U9JjwMM4Om gXE59HAKzBYeWuaGTg8Prfd706WGU9dX+bcmHkGhSjZi9/s5cjyliCYIlKW3SZ5/r8eVDT7U5eM Ul6QML+ml7X3z4kkuuJ+h/wDqoXcal+zei2gPVUMcumoxLw1LIC01d6WE/KJ3P8ubWfTWyLJmjp 13WmQW8lobfY1U0km8vVLpbpnjq3XkQP3rmrzLF282/rrCfukJH1zYa43nf6BLyjap2Bi6hSY66 4Z3lS7/ Aj1sqFAQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 06 Oct 2023 13:17:50 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779038654402894592 X-GMAIL-MSGID: 1779038654402894592 Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). As found with Coccinelle[1], add __counted_by for struct mtk_nfc_nand_chip. Cc: Miquel Raynal Cc: Richard Weinberger Cc: Vignesh Raghavendra Cc: Matthias Brugger Cc: AngeloGioacchino Del Regno Cc: "Gustavo A. R. Silva" Cc: Heiko Stuebner Cc: Martin Blumenstingl Cc: Thierry Reding Cc: Roger Quadros Cc: "Uwe Kleine-König" Cc: Cai Huoqing Cc: Chuanhong Guo Cc: Rob Herring Cc: Li Zetao Cc: linux-mtd@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-mediatek@lists.infradead.org Cc: linux-hardening@vger.kernel.org Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1] Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva --- drivers/mtd/nand/raw/mtk_nand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/mtk_nand.c b/drivers/mtd/nand/raw/mtk_nand.c index 29c8bddde67f..60198e33d2d5 100644 --- a/drivers/mtd/nand/raw/mtk_nand.c +++ b/drivers/mtd/nand/raw/mtk_nand.c @@ -130,7 +130,7 @@ struct mtk_nfc_nand_chip { u32 spare_per_sector; int nsels; - u8 sels[]; + u8 sels[] __counted_by(nsels); /* nothing after this field */ };