Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4964195rdb; Fri, 15 Sep 2023 19:32:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGhXoxoXLorYZgJHyXD4CN6NtNkvF4of1uWI55T/MYGRxozLrLricz2KROTn0OO2UAQvM6H X-Received: by 2002:a05:6358:897:b0:13c:fc85:6f0b with SMTP id m23-20020a056358089700b0013cfc856f0bmr3649574rwj.11.1694831568430; Fri, 15 Sep 2023 19:32:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694831568; cv=none; d=google.com; s=arc-20160816; b=b07LtwOdZ5Xv8cu9yyR2sklPHMxXWOKBrz8IZYiKDWyylQNSuSmJQMExiDub8SyJxi pGorv4ajlNk18jRyn0Lj1J3KtxB6iT8iANihAnJ5fw9xHsVueZ/pdNPGTso9w/iF6OR+ AsWAxNMWqQY1ko1pAlhqKFFYl1lrM2hePzepAfOFbAmBQYDkQMXnArXD0t8eAZJkvkzl oA4ZECDdJi9OYFRW1tf5uR6auPcXRq5vyQpmRFUtOk4Vwiq+Bd0f1Ri6O5kgHaJQ02xg Ot1IzC0v6zBgSfcTwEJs5x0FQVDIZOKVytqeamsHGD50nqgw3Z43nsaGeFHcgExfH51e HIGw== 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=6rGCQZXOZFob52Gnc+msXzDi2Oa5SKWBAnf/TmWNgRE=; fh=E4x4BYGV6MGhNwCjIbSBhdXH3+zAZwrD1TmEbrhSDEQ=; b=SGHOwbCde6wo2bXaJeZ40FCh8n8CjWDk4ehRgITGpJzN6xkcKWdhgBkjN5uPbLu08M WURiO9nbStsRrLGlUN1cpwLPS1Mr0j7zZMVpIbuG0EpK/y7X+2GTHpsziMYTe5wTzBE5 UUtbb4o6qh8osvGnV0DAgTE1JX6SmC912k66m2p5QfXVM6K5nbCrBz2fzAXsw81yvLMM Z46EP2ZtwL01+67Wwcr8QYOzjMRl1bfM2J4utZGCHUntDQlBQUfBdwOPjcePFk5jZ3mD TO9sH63NjGZaz3L4wko5GirgsquJEfsnWNSGL0icZj0hbuEaayARyHGigIkjT0k+k+QZ cikw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=RSLa+Sds; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id h192-20020a636cc9000000b0056ae965c538si4090630pgc.55.2023.09.15.19.32.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 19:32:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=RSLa+Sds; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 92DC781BB0A8; Fri, 15 Sep 2023 13:11:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237160AbjIOUL1 (ORCPT + 99 others); Fri, 15 Sep 2023 16:11:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237294AbjIOULF (ORCPT ); Fri, 15 Sep 2023 16:11:05 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBF102735 for ; Fri, 15 Sep 2023 13:10:54 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1c39a4f14bcso23390685ad.3 for ; Fri, 15 Sep 2023 13:10:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694808654; x=1695413454; 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=6rGCQZXOZFob52Gnc+msXzDi2Oa5SKWBAnf/TmWNgRE=; b=RSLa+SdsZjo7xryoCNlLiD17Vgf8IBCUn93v511Mr6wKCDJ0OZX22+5ch6X7toJa0d a3R5VLM75B736tA1Oy3bccnrLH7wMEInufT2W9oDyqYwOt0aJf0WS/RBZrTvn2uiPIdm lbJYlUX4dE+hBOpnChhPX7GgO1ivg621OIzDg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694808654; x=1695413454; 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=6rGCQZXOZFob52Gnc+msXzDi2Oa5SKWBAnf/TmWNgRE=; b=vv7aCbopKicvLDcE4bEh4tNn56wzZh4Gg9eQCgd0Ee+EJX1h+NsY6cMKpg+XBSQAR3 5uXFDgDoCTNnpFNYz5r9E82uGVlr6NUVStfrbTiuaRW0Hv2G6y3jsDF+9/AYRq0ZHJQe p1Hy97MlNtqXS/M4dHckg2cozGhV6XRVIgtsI26IqUzzF3j2SgiKbDC1ZshNCNRGu0Lw eNGJmAGrHxvpZkAyN44mJomo30LUiCQamxTzyQFy+3OwR+bLUd5STGzEGqfCodcyD44F fLD77vkMPMTXgZcYYpUlVTVhjPQmzcekPBpvFT4CpeqDIulr+x5Rs/t6srpO0/43dsv1 UesA== X-Gm-Message-State: AOJu0YytQCXDIf2MHU0WtaF6QztXfuWLhlnKep9jfcXelwUeE6dey2YY q3TktKgVaAQhfyvGyZQqNdYnKg== X-Received: by 2002:a17:903:22cc:b0:1c4:13f:9dd3 with SMTP id y12-20020a17090322cc00b001c4013f9dd3mr3457711plg.62.1694808654451; Fri, 15 Sep 2023 13:10:54 -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 b3-20020a170903228300b001bdca6456b9sm3904606plh.17.2023.09.15.13.10.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 13:10:53 -0700 (PDT) From: Kees Cook To: Pavel Machek Cc: Kees Cook , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Alice Chen , Jacek Anaszewski , ChiYuan Huang , ChiaEn Wu , kernel test robot , linux-leds@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@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] leds: mt6370: Annotate struct mt6370_priv with __counted_by Date: Fri, 15 Sep 2023 13:10:52 -0700 Message-Id: <20230915201051.never.429-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2257; i=keescook@chromium.org; h=from:subject:message-id; bh=coE/iSzW/9UhtjCTK3P8Gz63+gP8L3K/+tYQMkvh0is=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlBLpMEabFyu4iy+cSm/IiRf1sxT9B50iyRXrIa 1U8Y2+HfRSJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZQS6TAAKCRCJcvTf3G3A JqR9D/kB+HRM4Ne/WaOq10KenW2vk7P75UuXI5Jub8jHjnyyum8tphcbeG+hgOsmtv/58Whcs70 n0FswYXFTWoWh7E7chImCAqAjk7e1w+p6hX+cDqRx/p2Ye36TpSe4GRFESmTs8qvf5jJeqpkgI7 a13SXZalZVypMYSHWpxC8SnLbdfRnZjwc+aii8s7cwTxD6SRB6is0+q91VfuFeZzBX24z77AGtT VkXo6fdWWZV4GIWD12a0kzcul+7Uxpa0aB4DQ1NOFLjA9WrHyRhwrGmDGbHuswn5kFM4IayZzui Pkis6fT1iFeKKO6RdYKDGUtYbEP4mvXOVQ2/XMUodrY2c9x/oA+KosAoPSrir673KWOOHofAHD3 5AL8W5EzhbS3BnTwYJX669gI82yKLDX+IEX7CodlJVrK33ZNmVF31puCUqzL462U7tMxWPmnlBb OftVJhzzw7hfxwndI7LoXe8OevLuAy2DYbWh389xPIoLPh7X0BZR4xHqgMTHEypF08hh0q5lNlx +EZ03lTN7zwMfA/0RUG9XOexK+kmOhS8Y9Qj4aw45BxhvPHhRJw8XETmXO26Rc/+RRfL1+KH/o7 Mqw0xayOuPh650DTC2CZv0a+PoHnaYkOm1kaE4tFx0OX9R1VTMeJD8TmvF8+r4Il478NvyQxABt BcXYqKz l4fOiO5g== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Fri, 15 Sep 2023 13:11:56 -0700 (PDT) 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 mt6370_priv. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Cc: Pavel Machek Cc: Lee Jones Cc: Matthias Brugger Cc: AngeloGioacchino Del Regno Cc: Alice Chen Cc: Jacek Anaszewski Cc: ChiYuan Huang Cc: ChiaEn Wu Cc: kernel test robot Cc: linux-leds@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-mediatek@lists.infradead.org Signed-off-by: Kees Cook --- drivers/leds/flash/leds-mt6370-flash.c | 2 +- drivers/leds/rgb/leds-mt6370-rgb.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/leds/flash/leds-mt6370-flash.c b/drivers/leds/flash/leds-mt6370-flash.c index 931067c8a75f..912d9d622320 100644 --- a/drivers/leds/flash/leds-mt6370-flash.c +++ b/drivers/leds/flash/leds-mt6370-flash.c @@ -81,7 +81,7 @@ struct mt6370_priv { unsigned int fled_torch_used; unsigned int leds_active; unsigned int leds_count; - struct mt6370_led leds[]; + struct mt6370_led leds[] __counted_by(leds_count); }; static int mt6370_torch_brightness_set(struct led_classdev *lcdev, enum led_brightness level) diff --git a/drivers/leds/rgb/leds-mt6370-rgb.c b/drivers/leds/rgb/leds-mt6370-rgb.c index bb62431efe83..448d0da11848 100644 --- a/drivers/leds/rgb/leds-mt6370-rgb.c +++ b/drivers/leds/rgb/leds-mt6370-rgb.c @@ -153,7 +153,7 @@ struct mt6370_priv { const struct mt6370_pdata *pdata; unsigned int leds_count; unsigned int leds_active; - struct mt6370_led leds[]; + struct mt6370_led leds[] __counted_by(leds_count); }; static const struct reg_field common_reg_fields[F_MAX_FIELDS] = { -- 2.34.1