From patchwork Fri Oct 6 20:17:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 731795 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C30AE94114 for ; Fri, 6 Oct 2023 20:17:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233420AbjJFURM (ORCPT ); Fri, 6 Oct 2023 16:17:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233167AbjJFURL (ORCPT ); Fri, 6 Oct 2023 16:17:11 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE5AEBD for ; Fri, 6 Oct 2023 13:17:10 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6969b391791so2054555b3a.3 for ; Fri, 06 Oct 2023 13:17:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696623430; x=1697228230; 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=K1eBnvmyPH2CZ9nM0L4OdqfRabPTQXIENd6RkEgpAic=; b=K/BMsDKnBX4LyJETsKidzzFjYBgMstd12+yf3lq/HGbPmyDvyR2pKB7NeeL+entCxA 3Y0vjXXj2keeWn8iw/IXNce3THRUSs7TZiXMlrcsUkHapFLTaoxjMsP+gY2zBfJEdhRT BUZ6bxMP8lMEzZ6oLkXv+tCftdzNj7enupxxk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696623430; x=1697228230; 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=K1eBnvmyPH2CZ9nM0L4OdqfRabPTQXIENd6RkEgpAic=; b=tOWb9mD3Rew9OThkcf0zgWN2T1FJNYU8L5z7hbDKY6A9O10caKRAOETejcTgaHLhKZ Mc/Xh++W/IgnR3vyQlBfL/2peJUlqh0aFIrdyLaYJNftRY8CWNJciAOB7NF0oZsAOUGa GopSsc54aSJXuERiUNCFHvjUryFSFROVklTW1iml5VQIKRkie+DgYHJDblElWn1kgP3E VcQDkQUysqsnRoFRQ3omqt+yxbo5HUZPUcxq1ZGMJUv3Pv/1w74W+dizibSFJz3B3PT8 GUGaH3sz1u3uvG2DVoc8I5+AMRJa7v2ERSbhENx5VTvB3hnJ9kkb0+O+OqSIXSR1J56D fPDQ== X-Gm-Message-State: AOJu0Yx4vPvi2AjVsG7XOd42H7oFiPLZ0XMNOPrl90JcYIfp3w4kHgft I5pDVJ/3Tk4k+C/gMxYF7iPdfA== X-Google-Smtp-Source: AGHT+IEtlTeDLTCL/lFi+oJBgl0DcZtNH+OVNahSkKRT97SzL7fnVmB7IYgd/mR8i75HJAy9DMPCdg== X-Received: by 2002:a05:6a20:2451:b0:14d:5580:8ff0 with SMTP id t17-20020a056a20245100b0014d55808ff0mr10184865pzc.25.1696623430379; Fri, 06 Oct 2023 13:17:10 -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 15-20020aa7914f000000b00692c5b1a731sm1875791pfi.186.2023.10.06.13.17.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 13:17:09 -0700 (PDT) From: Kees Cook To: Tomasz Figa Cc: Kees Cook , Krzysztof Kozlowski , Sylwester Nawrocki , Alim Akhtar , Linus Walleij , "Gustavo A. R. Silva" , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-gpio@vger.kernel.org, linux-hardening@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] pinctrl: samsung: Annotate struct exynos_muxed_weint_data with __counted_by Date: Fri, 6 Oct 2023 13:17:07 -0700 Message-Id: <20231006201707.work.405-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2568; i=keescook@chromium.org; h=from:subject:message-id; bh=lsTbTj1Qtp6GgXJHYDIN0GpRbyjpp/e7Ct6QQbjSy0Q=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlIGtDy9BWBe1i4kwKNKaTCXh1WjWe/M2wbybFm RGQGh5dTv+JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZSBrQwAKCRCJcvTf3G3A JkxPEACXFEGhNrvxBkTKUfgVjkyDrnxC4WfPJdhQxqmOPOzyY7EPwkDCEoiad2SUhfNal9NNCX2 YG6o8XD/Uh2tW7jyIlkOfT6uBfN7mpF6v8hCUD+fj68+miZhqVOIS/HHe0lZoS+pIPABq9VOexQ jjhxKYKoT8/9zXbQpD73TUCh9JHPIVlA3/ogT3ZoqWFJxtyNsuR//kYxSK3cTmx7KTH2cjdhNfE FOVAGIaap8Ql40LUwC7YnOL3GgFklirZ49tih0ydJ92l/cBHsNFOneuAL9sAORZPXrC9U3zx2wl 5PwxcY6gIE6Qt+/crsR7qoAO5VwSQGiDcgv/NfhyFZ8WIeDnffMI47fj8qHurqCTH2to25FGThw Wae7K4YrpBU7BQ1VjmJpSAT3vTjH/7gsV1m6n93iTXw6A+M8li7P5V1kpw1VTdyRmEvikJfo5SL HIJ89R8z5r9OZLteo3msJf6liREQIfgVYXvyAFMP5F/MRQO2jV2nRG9V9Q9epbB6SdpTjzxiO3Q 971qa3ROTD5xraPe3iEYKh/b5jWN9fzoYD4WWl+ptluj6FTIhL0MqsPBkRwH2EkTIYRsncnJZd+ Yrf3FjEvpL7AzCI34QOyMBEeP2ttb4NVoGGAQWWt5I97UEdH5QyqDsOL/vI8bR3Oj3ccd8l77Eq 6vqzydT cWFqXEJQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.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 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 exynos_muxed_weint_data. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier. Cc: Tomasz Figa Cc: Krzysztof Kozlowski Cc: Sylwester Nawrocki Cc: Alim Akhtar Cc: Linus Walleij Cc: "Gustavo A. R. Silva" Cc: linux-arm-kernel@lists.infradead.org Cc: linux-samsung-soc@vger.kernel.org Cc: linux-gpio@vger.kernel.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 --- drivers/pinctrl/samsung/pinctrl-exynos.c | 2 +- drivers/pinctrl/samsung/pinctrl-exynos.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pinctrl/samsung/pinctrl-exynos.c b/drivers/pinctrl/samsung/pinctrl-exynos.c index a8212fc126bf..6b58ec84e34b 100644 --- a/drivers/pinctrl/samsung/pinctrl-exynos.c +++ b/drivers/pinctrl/samsung/pinctrl-exynos.c @@ -616,6 +616,7 @@ __init int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d) + muxed_banks*sizeof(struct samsung_pin_bank *), GFP_KERNEL); if (!muxed_data) return -ENOMEM; + muxed_data->nr_banks = muxed_banks; irq_set_chained_handler_and_data(irq, exynos_irq_demux_eint16_31, muxed_data); @@ -628,7 +629,6 @@ __init int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d) muxed_data->banks[idx++] = bank; } - muxed_data->nr_banks = muxed_banks; return 0; } diff --git a/drivers/pinctrl/samsung/pinctrl-exynos.h b/drivers/pinctrl/samsung/pinctrl-exynos.h index 7bd6d82c9f36..3ac52c2cf998 100644 --- a/drivers/pinctrl/samsung/pinctrl-exynos.h +++ b/drivers/pinctrl/samsung/pinctrl-exynos.h @@ -159,7 +159,7 @@ struct exynos_weint_data { */ struct exynos_muxed_weint_data { unsigned int nr_banks; - struct samsung_pin_bank *banks[]; + struct samsung_pin_bank *banks[] __counted_by(nr_banks); }; int exynos_eint_gpio_init(struct samsung_pinctrl_drv_data *d);