Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3217378rdh; Thu, 28 Sep 2023 06:10:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEbi9qtz5EaWrlJw3qmzdV62odYMmLtPMwpiIMbUkk+FrPoDSfxnTIW8tU6LX8L0YdcCbEj X-Received: by 2002:a05:6a21:a58c:b0:135:1af6:9a01 with SMTP id gd12-20020a056a21a58c00b001351af69a01mr1485766pzc.8.1695906609660; Thu, 28 Sep 2023 06:10:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1695906609; cv=pass; d=google.com; s=arc-20160816; b=ituBLi3pwW6BiEnuOiVZ427ivutOn4NPsTavii8NAOo0cM51aDrdF+Ky8+wMIdUFv+ aQAZw3coEW0vEUWQLUF57Na2Blt8Tv7WZmE9JY2zIacVdNx8LjFXpZiEppyuOvnE4DCj FEw/CV2ec6l5LftIQKOiqMOtJjIgQSWFnugOcMV8FoLjzmbaxeMqUwwvtW83Rq4r31lF 74H4wtSErgioRUVrUYfdAFxbjLhsvNY0DgbacNmZsbQRvKXYd1AJv5rTwOWWI5mzp3T/ J2gJp+RzByEJgeRU0b2Hsxp2qkS7+IBz68FMEd+yiqdlCAh599/CDlEFMbrBJBpRsMV2 8XaA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=l+vBFqPjBMKFbqu5XhbV2rCmcl4slYz26Cs5fxb/yqc=; fh=uggD9fLZ07pUU84OmssoWTjM3Dd3F3jSGs6sLPW/8hc=; b=Isn+rrTmbj16kKLk3v2P+O+liHFBuho0LcWr019if1MYOcqi9oopE0z/DzAuz/ZWhX 2d2n6nE5v1+/8hjn9lya/5wYS89glhv3vNcZI7UFKMZwWf3MenCCWd+dg4ZWc6b0tLl9 DUk+TqoJ1OFD6Q0bK7JI8Z31WQvvDJ+JfhnT2JjC+lZvlJznXesliA/vzyT4AY6SrPZf dj34j0n/7VaT9BbhGVyp1huJa59iCUVXs3ZqS/cnQpmT67FaxgwHgz3vx4RyuNgM5dW9 u+kmiitsmWLDqQ6uIAG+oaxSAkPKO6/u9ENeB1hEtYCvqJ0HlNlL+1KpuXbqiGw/ej9O cfrQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@stgolabs.net header.s=dreamhost header.b=rJgekkco; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id q22-20020a056a00151600b0068fbac77dd0si19744980pfu.226.2023.09.28.06.10.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 06:10:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@stgolabs.net header.s=dreamhost header.b=rJgekkco; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 242CB80C4D8B; Wed, 27 Sep 2023 18:18:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229939AbjI1BSg (ORCPT + 99 others); Wed, 27 Sep 2023 21:18:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjI1BSf (ORCPT ); Wed, 27 Sep 2023 21:18:35 -0400 Received: from crane.ash.relay.mailchannels.net (crane.ash.relay.mailchannels.net [23.83.222.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25F4CF5; Wed, 27 Sep 2023 18:18:31 -0700 (PDT) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 0925681796; Thu, 28 Sep 2023 01:18:28 +0000 (UTC) Received: from pdx1-sub0-mail-a245.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 6035681907; Thu, 28 Sep 2023 01:18:27 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1695863907; a=rsa-sha256; cv=none; b=V4wYvncNg7bEDdCPtYHL+fbFo8S181rnzS/3S+9PYcembfJCHai+NfQXQoqKRHK+iFcxi9 8GBeqVTLC1nNkbYoIg1m92PPxWnq5++vc9g6zlcITra05VYL+maeOh4By5/cKT+bUYlnTN A5ry1Ziiii4Lkfl0uzaj6i/KEw6cNkj1H/ufu0Bzsk7USMGzC3X9ycBdv4SwvjsVQp0GLQ MGCk+GEOLYXZgu2I4ehra+neCg3n9it/j0i66YrFm9gi7IQcp33BHd8Ym+sNlg+ohjOfnt PBB2wc73OT2aBOt23qF/ZOHT9cAIYsc0jRYweZeGLw5GZeXAFUrjVslQMuVIUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1695863907; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=l+vBFqPjBMKFbqu5XhbV2rCmcl4slYz26Cs5fxb/yqc=; b=koec0pYPCw9g0QRdwaUdTM5lKi8bcpDDkH628od9Ivo9tlfb1AhyTnbSMlfIF3k35mPm1T i7/68OIGBoAfVRidX3GGb4ThoXjHSZqqxW/ZPXh+luSgGYnY2bmC7aSxser7DcyefuFbdK Y4UNAybBO9aE9u+sQQ9hgxbEbI/oQMD+9fWIAO5N7DxArTiKso7KBfLUMln3gc1FRlZlEb +qxC4YtFnTYowA4XzQmce5+SbUJbWA71ltusozXnjmsdb04UGU+xYKzxo1x2TFiX5UNsUy tALZfnDi0e2TBXdwmZq1sBjy7RVKN3LahwyUoXavqT09ZxDEfGWZehMYlToVhA== ARC-Authentication-Results: i=1; rspamd-7d5dc8fd68-mc6tx; auth=pass smtp.auth=dreamhost smtp.mailfrom=dave@stgolabs.net X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Arithmetic-Turn: 159e1a1812a75633_1695863907725_2640573531 X-MC-Loop-Signature: 1695863907725:2557605338 X-MC-Ingress-Time: 1695863907725 Received: from pdx1-sub0-mail-a245.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.109.110.212 (trex/6.9.1); Thu, 28 Sep 2023 01:18:27 +0000 Received: from offworld (ip72-199-50-187.sd.sd.cox.net [72.199.50.187]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a245.dreamhost.com (Postfix) with ESMTPSA id 4RwwbQ3gL3zK5; Wed, 27 Sep 2023 18:18:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1695863907; bh=l+vBFqPjBMKFbqu5XhbV2rCmcl4slYz26Cs5fxb/yqc=; h=Date:From:To:Cc:Subject:Content-Type; b=rJgekkcoy7Q8C/P9/eF8+K1d9bkC2cx9hbqs0snKgxexK5VLvQ3fQ298p9phsEqSD 4INrjIaxHYy+BSiXnr2s5AcKmHdIjbg0KDP3sF58PyfHxsRJ4T90Esv6rDKpMGhMV6 3Wv15rL/aMnmhqMXGuShpco3pgocfHTjvldifqcn4jyR2OTJ8FUeItexnVWPU3/1YO gi2K//U+19T9LI3ikyVQTPbKMMc0mxU8SGqk8qBgIT87+Ewx8+lKzQN1j9IKHU59A+ 0BpKre3NWP9SQhyrQb+jk0cRwxacZqbtjiqMpMWsiNgLnkFzsY+Po3lXA63efNHpwd TRy9yu5g9FcrA== Date: Wed, 27 Sep 2023 18:18:23 -0700 From: Davidlohr Bueso To: Kees Cook Cc: Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , linux-cxl@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org Subject: Re: [PATCH] cxl/acpi: Annotate struct cxl_cxims_data with __counted_by Message-ID: <2jvukfliknlhy2j4fespmmezbjc4q4kffznfyeloirs6flya42@hniebubdznlh> References: <20230922175319.work.096-kees@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20230922175319.work.096-kees@kernel.org> User-Agent: NeoMutt/20230517 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (howler.vger.email [0.0.0.0]); Wed, 27 Sep 2023 18:18:39 -0700 (PDT) On Fri, 22 Sep 2023, Kees Cook wrote: >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 cxl_cxims_data. >Additionally, since the element count member must be set before accessing >the annotated flexible array member, move its initialization earlier. Nice. Reviewed-by: Davidlohr Bueso > >[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci > >Cc: Davidlohr Bueso >Cc: Jonathan Cameron >Cc: Dave Jiang >Cc: Alison Schofield >Cc: Vishal Verma >Cc: Ira Weiny >Cc: Dan Williams >Cc: linux-cxl@vger.kernel.org >Signed-off-by: Kees Cook >--- > drivers/cxl/acpi.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > >diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c >index d1c559879dcc..40d055560e52 100644 >--- a/drivers/cxl/acpi.c >+++ b/drivers/cxl/acpi.c >@@ -14,7 +14,7 @@ > > struct cxl_cxims_data { > int nr_maps; >- u64 xormaps[]; >+ u64 xormaps[] __counted_by(nr_maps); > }; > > /* >@@ -112,9 +112,9 @@ static int cxl_parse_cxims(union acpi_subtable_headers *header, void *arg, > GFP_KERNEL); > if (!cximsd) > return -ENOMEM; >+ cximsd->nr_maps = nr_maps; > memcpy(cximsd->xormaps, cxims->xormap_list, > nr_maps * sizeof(*cximsd->xormaps)); >- cximsd->nr_maps = nr_maps; > cxlrd->platform_data = cximsd; > > return 0; >-- >2.34.1 >