From patchwork Fri Sep 22 17:50:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13396287 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DF76DCD4847 for ; Fri, 22 Sep 2023 17:50:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=acBpo01DwwJqwu4AZZTAciusMr+ygVS7KgmySkWaz54=; b=eQRy6XO2sblwJp 2YPy2zoRFdeOcqlK1z0w2QSWEs6DMsTLt+lGSC05XXcSK/X8ENTc4itvCN4pwig6sgiFoe1DnVSwO hjlstKNFX7lAJtrd+GNFWbzmQymeIHJe+ZPazRwN4HO7xewMgC7aZ9ic/yTC7KmqKx81FGvBpWaxL oq7DuLmnM6GwJ3V5INwN40C1YywqXV3gIaE2mp31VtON3IdXTbm7RPMiEvbP1BTHcy9fOjqIoNMy1 FRIPDUvJ0GMWanXCXPN8hs4Ao3zgNGOBExY4CGZcAdEOhxxE0UhHnfY4qiErmbtD8Pt7Q8oeyZGCY T/y7B/hiMLyEp7udELag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qjkI9-009YDh-31; Fri, 22 Sep 2023 17:50:13 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qjkI7-009YCO-1P for linux-arm-kernel@lists.infradead.org; Fri, 22 Sep 2023 17:50:13 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1c364fb8a4cso23163995ad.1 for ; Fri, 22 Sep 2023 10:50:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695405008; x=1696009808; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=KgYTKXR/I1FPvObxorvJSFTW8JIzpStmNm7nH5Non2I=; b=UdMRhyDZS+7enKunCpgkMZuWRaLw3H65gLUKXfhvK+4k4L+8EkgpYflnM3DqLIiwlU h/Yg7REbYlWVukDQ/MmE4dh2HZiMDvaU0Rs8ENMN9yKE+eESDTJgNScGHgEg/iiZdgWV Q0u8rJa7/XbeMhcVAZCyIZz8fPkPXR2OQoqZ8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695405008; x=1696009808; 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=KgYTKXR/I1FPvObxorvJSFTW8JIzpStmNm7nH5Non2I=; b=o5RivYSj3T9mMMsq2UHG4TGgQazH/GUCo1+l/E5Q3DWuv7JsAzPOD3CUTfVCi1gSMt 7yKzWoA99mDoiovfUStKIxCONMNIoeyO2nI7NpKkkFCevq0cnht04Zo0JpjtxVyuHl+y FXGcc7FknYyGG4dd1fBviBeSAaMue78dey5zNIbiMHnKHYGroikDbl7oNRYJtYUvQSFX 4Zc5CyFZo6C5F81ED89Tjq1D52n3nY2m5Gw7cnslXBt6PagQvm8WRd2At0+RIl9+0PRa kq91pav1la68emHmhqsMvO5P20v8yCvHlQvQ+ydJs5wKRgzyqMzAmqTjITYdLGEDknkR CMAg== X-Gm-Message-State: AOJu0Yz3C8/d8wZInNLpmmpDiYsPkTAahELMFPwLUE53/px9SxGFd/Q8 inOS1rLmk8vEKbFbZY/sNA2cOQ== X-Google-Smtp-Source: AGHT+IFoNtsi25M+QrWUhiPSf6zW6D/xwoc6OJ3HOy2c3JyRBK7yqttvE9WeRwOY/cIOvf6x0iTR+Q== X-Received: by 2002:a17:902:f551:b0:1c3:3b5c:1fbf with SMTP id h17-20020a170902f55100b001c33b5c1fbfmr216816plf.10.1695405008186; Fri, 22 Sep 2023 10:50:08 -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 p7-20020a170902e74700b001bf6ea340b3sm3777501plf.116.2023.09.22.10.50.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 10:50:07 -0700 (PDT) From: Kees Cook To: Linus Walleij Cc: Kees Cook , Kunihiko Hayashi , Masami Hiramatsu , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org Subject: [PATCH] pinctrl: uniphier: Annotate struct uniphier_pinctrl_reg_region with __counted_by Date: Fri, 22 Sep 2023 10:50:06 -0700 Message-Id: <20230922175006.work.421-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1374; i=keescook@chromium.org; h=from:subject:message-id; bh=Tm7WSbhCUuk32XvIW7v3CIW2EM0z50wK155ChWrac9c=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlDdPOjizzHR2Fjm5ECZPVLRxlOXXgda6lwE7va Ga/RNMhW1yJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZQ3TzgAKCRCJcvTf3G3A JhnID/9BsoGqvMvrhL7fUCSef2KOrN+0LY8Y9Gh+WefjyMcP4C22g4sclGpsrxAQkqk8krUt+5w c7zIvVimPqMsIxiBaJWr1OqtIB0pDqA7Jb9lW7lh9N68utQ2cB2YXUYQmvUM4N6MgXplPdH42V8 y1MjcClXYSpmWA19UsRuXCGUG9dxZ4OdFC0yxoUW6D5nN3u4hL+hsWlwH50C4TBF0TEt2WWkNJ3 rBbr/WxM67dRdxxurhQZjdL1O1fFBezTz2PbpZJTg4BL1pRSwu/3zexiLxHjIi9mAugGtkzBWSb ueMncH+Gb06R2+p3vmMrWonH4OPujnK4xFzBcOfrfn4dEUF9UZBjHM7NE/I/KRR2VcYvr7n+LpB YZJDrvy+6inR3Am6Ib+dY8Vwo//eb/uPXD0KXtGAwA0H3098tSkdl3eDQxDR3/g+Ih66IWvwkrP GqJRkE8sF3Nxzk9eBkl3C2myQjSsEuodvl45xOyqOUPpqF5sZNeJfu9dSMTgV7izNogHL8n2OgE JLb5a0Akkl9jAqBRGsKQPxNFYEu1Pi+bMfCc0fiWj7xTMCrMPFQMrlOb+tH9RaYnX4eHZC3gfdj O/tYjcDU6tm2Ak81vIxZ9R+zc/Y45CD0xr09bAu8gjOGQfLMYC5IYhCqGT3fzqOCd4wI4BFWpGn nW5lHw/ 91efgg9g== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230922_105011_477748_65857745 X-CRM114-Status: GOOD ( 13.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 checking 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 uniphier_pinctrl_reg_region. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Cc: Linus Walleij Cc: Kunihiko Hayashi Cc: Masami Hiramatsu Cc: linux-gpio@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva --- drivers/pinctrl/uniphier/pinctrl-uniphier-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c b/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c index 18d3a4f69e63..fbd0fcdb42c8 100644 --- a/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c +++ b/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c @@ -31,7 +31,7 @@ struct uniphier_pinctrl_reg_region { struct list_head node; unsigned int base; unsigned int nregs; - u32 vals[]; + u32 vals[] __counted_by(nregs); }; struct uniphier_pinctrl_priv {