From patchwork Fri Oct 6 20:17:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 149402 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp574282vqo; Fri, 6 Oct 2023 13:18:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+sKDIXHDXnuOSPjFWtL9WED8R0kKO5Yl70lpGwTa7jDYboQ+Y/bhJffdkUz0TPN7tBxgS X-Received: by 2002:a17:90b:180d:b0:26b:6095:bc3f with SMTP id lw13-20020a17090b180d00b0026b6095bc3fmr8603249pjb.33.1696623526785; Fri, 06 Oct 2023 13:18:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696623526; cv=none; d=google.com; s=arc-20160816; b=hbIpMslK+GB4+97bvg7t2AkWCYAtwtK0ox4nj8kH/IWbSxKrDaAtVlR14wfo0ZERfA 5qpZ1mzIZX8Wj0PghSRK8ZN0/vmQAjg4VMZODqwZdy9+kvwfwEaEMNKuxGcuf88fYWn6 yhdDWmimqMW2vDwxI8IpbN8UayBJ48BFXwmkhmP31DDSoRxgN+LcyGklsTLnZm2Ai45z Pfbm5sYO2dvNEm1DqlU7Je9mAHwNMQiUNaece6xdMyQm72WQ5Jrgtl0LCEK4lhqhjz3o vR/Jl0Jlcwjm5TIolxLzipO8+2GS34uag7Eqi+aM3+89xP7IShsBabYnIsmAuxovcrZf gPnA== 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=O2df0s7T7DwAtvRnEkwYeLwhw10mfRmv/AyASXBMHso=; fh=s4SQe6pxhMXPf6qFPxXiGdOZ7H0/rt45iifa+qYZKYw=; b=0o/nV+cMdVdf1tfPYVglVE2DeSlYBAbBK2X4/JNHTfnc0vUcpOp/5dvHd2aJQlrh3C ErllNPXLjCy4Uz9vkAUegAd/NHjyuUR/FQukAZCMSYm+11SwZ04qZ78lLAvSU83DWF+P L0Msmp6hZ6ekOlb5i0rkaqzshhsRJLefv2tuxyvxgjbl8xnn7MfTwaMuBDsVZdepuS9d LbymTtqQfRMWrIjXImHH96t14RlRlJTLi+9QNUa/vahpUW1Ool4iRRK0v42D3EhO0EWl RAUpixabXGzrH5ojkzN58xw1gLvXGdC6bjqRu36dEeWRL6Nl5gfNT1gkFMneG+mLjTud FBEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YXai4Dq2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id gm16-20020a17090b101000b0027924ff5de3si6610213pjb.68.2023.10.06.13.18.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 13:18:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YXai4Dq2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 7887E80B19C4; Fri, 6 Oct 2023 13:18:44 -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 S233493AbjJFUS0 (ORCPT + 18 others); Fri, 6 Oct 2023 16:18:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233480AbjJFUSS (ORCPT ); Fri, 6 Oct 2023 16:18:18 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19FF219E for ; Fri, 6 Oct 2023 13:17:58 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-578d0dcd4e1so1752193a12.2 for ; Fri, 06 Oct 2023 13:17:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696623477; x=1697228277; 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=O2df0s7T7DwAtvRnEkwYeLwhw10mfRmv/AyASXBMHso=; b=YXai4Dq2sGsTEOAhTy0aoK2jij79wTK5olD/+iI+s+xqZmfwYqA63f5P4nIYCnA/Jj 3UugGymonMmtcAyWNCyj7Yc6gXR6FVi6u2gKoSbXsT0PtelCq7+w/LmogPBPtaLJH669 Zm/6xegAlsWoc4ZyyNlVFnioU22rFDrATrQc4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696623477; x=1697228277; 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=O2df0s7T7DwAtvRnEkwYeLwhw10mfRmv/AyASXBMHso=; b=Q70jHX9bo8NxACZrw0jTlC6D6d/7lkEmRsZjp4ucNTu457UNNvScXxAzjkYWpreeMD N0tc7zEhQjK+Py7oVg53PQiN6msqs3qkyEWZN2rrculvuS2kFJy8+JxZ9/YnntURguFE i6m6dAUOJawDR4CaUa4GmaYjWvrudH+/N9m/IieOUkwEsKzSVtzeUzJgLUblMAm8ElRy jK6o3KOGBUpO9I3MDLJ2sYjigafkE4lSbS2R7nuNsWb2/L5mtWjFuxcFPRsx8DsB28tW 3lhqKTNpc0Z7h/1fYwXBoIcVJcrw7fdVcczH/cZf5+GcqAQj/OHKr4w0SQV+5QQVGZtM EbuQ== X-Gm-Message-State: AOJu0Yz0MgGjjZbjxoe77VYfVjRDW7EKVmrT8uumPffmU7wiJlA3YkJ3 dVu1Z5+glefBTtmHYZy2D9I7xA== X-Received: by 2002:a17:90b:4b4b:b0:276:79b6:8bd6 with SMTP id mi11-20020a17090b4b4b00b0027679b68bd6mr8931211pjb.15.1696623477195; Fri, 06 Oct 2023 13:17:57 -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 l12-20020a17090aec0c00b00268b439a0cbsm3938389pjy.23.2023.10.06.13.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 13:17:56 -0700 (PDT) From: Kees Cook To: Peter Zijlstra Cc: Kees Cook , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , "Gustavo A. R. Silva" , linux-perf-users@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] perf/x86/rapl: Annotate struct rapl_pmus with __counted_by Date: Fri, 6 Oct 2023 13:17:54 -0700 Message-Id: <20231006201754.work.473-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1695; i=keescook@chromium.org; h=from:subject:message-id; bh=0drUnBz5ZzeWNYzRelIIqK9QIPmE6lOPX4gIPEmIa48=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlIGtyvrX6v83QbzPXJ5dTBvLyzF6pqlRJw+9O+ IueqOLf5FmJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZSBrcgAKCRCJcvTf3G3A JpusD/wP8pAHR5OToG3w0MqsR8g+9U+NGN++3UuuAB24bMqNos6WKIV4PuytR0dEPoFxZv0n0WK rD/g/kXPqYmtnwxkO4uQPqSHwpu8hbhVaqeJnIacctZpmyzLOf61lAbhckX71WEtm7bwGaJea7N gvTrRmxHsjHFZBnibGz9zxhjMdgcwHzdltFDVYiL54bi9vgzrKzsy6+MAqwtmN+cmC/2YxGoZs3 zTRlmAaVlGEOpJl4OBd9oqB1YL+D7TAuXAB8k6TVBQQ8MYyEsMspkTuOO9i9gsSQC+guMzaOdNq XET91Jfo/Djb+MF9muIiX2HBKzisNxMg1sviXSwX6S1RZ4HRdJ9c++9DCcslJPUD3hSbJ8N2xDr yIeQNYH4WJMozBbo0UVonSsb/c0OeoYVghD5fKTQbklFel6JFto4hcxEnWHk+yBktnTROyVHrZR qT1Ju4TH0Usbo2NSH6BKuFNMkrdMeTVloFeaRDxqyCZ163ce3FbRgCLBjTqx/2mbu0ZMXysfd90 abETP0AyBsqFDbzcUgEtk1lNEDvmU3bevXe9kOCQ8o6yRrKhWVeGDsPWFFkknF38Xbuab/F4lry 9S7DLlfj6WdBJtTAVL1ubY1oHvCkAxH9vhJDgOictH0Hdn7ubcW/kIpon5tKCr+3huZQY1NHaiz 7Yaqpmr PH9qpiCw== 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:18:44 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779038711297962398 X-GMAIL-MSGID: 1779038711297962398 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 rapl_pmus. Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Mark Rutland Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Namhyung Kim Cc: Ian Rogers Cc: Adrian Hunter Cc: Thomas Gleixner Cc: Borislav Petkov Cc: Dave Hansen Cc: x86@kernel.org Cc: "H. Peter Anvin" Cc: "Gustavo A. R. Silva" Cc: linux-perf-users@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 Reviewed-by: Gustavo A. R. Silva --- arch/x86/events/rapl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index c2c37fb0a228..8d98d468b976 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -115,7 +115,7 @@ struct rapl_pmu { struct rapl_pmus { struct pmu pmu; unsigned int maxdie; - struct rapl_pmu *pmus[]; + struct rapl_pmu *pmus[] __counted_by(maxdie); }; enum rapl_unit_quirk {