Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp74012rdh; Sat, 23 Sep 2023 01:58:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsKAxDOFpWQi9pMfe0gPs3ZbN1zHFpDkUWspBE9+KN0ZsXpOtQpU6dEzODYvl+PqtXAlbI X-Received: by 2002:a17:903:1250:b0:1c5:59ea:84de with SMTP id u16-20020a170903125000b001c559ea84demr1471228plh.29.1695459532624; Sat, 23 Sep 2023 01:58:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695459532; cv=none; d=google.com; s=arc-20160816; b=JDC3nI/hNpVfaFnpN4Va3EDFj79uzvBq8X1ao8grGMpoAfC+wEkKKOSG1gNfRQ+LdI Uu2Yv1pPQvrX97PfU2F9DqkZHdWpZXsuw0uyJ74KGgDh4+/HppNpoPta41rpMLF+q7e/ K9v8k8w4JCECU1cgMaZJ0tqS/mxzI0TiVljyaNvSpr4VGCZRWgGu9/mJTia6JEOcVbER 7f7YyWbc+4/F9W/xiCVx1TopLJQsIiWQ5JIZ5BM9ass9yt09AkXiFtVPvfNsj0UXIUac 1C/LJ7Cb3kjED9uUjsMr1Vf2DcPf7q+LghSbglOwrg3pbKMm+6jqN5yepmE7GvK4Mi9b 2RJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9UCYQ1x9kdZ8hkMbFnKPoSF8mnI5g44LzwoZdTE3n20=; fh=3wwkaUgw93ViPvpFiHY0prq+VxaUdZ/nJFf6UdIyXa4=; b=utzrSbNaUYj3BSh/NQDjFH1HdjkWaEtrbKKCr5ZZ0prznLRD1TCD79OI4cIWFweb6H sGy4KZaIb2hn1tjOtPftCkQGmro8xTka/sjOGI59aOlqgYtxDuvupnFED5emOp3jTC3q hWkqtuROCDzroRmKVQPVl3Jh+gxEZfyj6F6yBKuZCDTw0tWlsLrmHGH2wUkbzHJeIect 7+oJIGoT8vcjd8aBwgB4PmaGl1146T9EymBQLff5qCqLdBQ+aHXzq7NnVIHgMdpvFDpG KHyO7a7WCpr4ftwbitRIk83en55aoJn80bZ4NReH5xcnzBVLtYNiicNBMuNnN0mKxatY s/QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aqEcSHEZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id i11-20020a17090332cb00b001c0a165a219si5737440plr.134.2023.09.23.01.58.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 01:58:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aqEcSHEZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 3FF728325198; Sat, 23 Sep 2023 01:58:49 -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 S231124AbjIWI6u (ORCPT + 99 others); Sat, 23 Sep 2023 04:58:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230450AbjIWI6t (ORCPT ); Sat, 23 Sep 2023 04:58:49 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EA9E194; Sat, 23 Sep 2023 01:58:43 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E22F9C433C8; Sat, 23 Sep 2023 08:58:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695459522; bh=O8EiSLhEdCxqqFSOJYtTaig/d7zFufVU+L6LPLjr9m8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aqEcSHEZ+l6vTmxiwq8AHSQFIC2Sh/9sXbMCfWkWLaXXX57fk5NVdF18/clTMpwoT J0r6lxieBB7Ke4qKFEcFWk9Z8GIB+6zt3hoVnCLZLZTjKasDeTlbmrpJzz6NpFJ5J2 r8RvD3Bqb+qEtjyqqSUXapGVesxUOwuHIg0ToI3oKwFDOak7mmxgU1bFJ41sbygkYb bf0JVA+7IqsUwG9w6Ow/ZyNPEpdnfAZX7ngTmL+u3HMimCfMm5VxkhO6h9rw3s5j5T QCXXdan51VuR3mKi0BP+OAKkP0I1eLcJ2yVWcg1csw6JASbE/hGbgBEXotA87XRhnq I1VlPogaVVBgQ== Date: Sat, 23 Sep 2023 10:59:43 -0600 From: "Gustavo A. R. Silva" To: Kees Cook Cc: Davidlohr Bueso , 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: References: <20230922175319.work.096-kees@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230922175319.work.096-kees@kernel.org> X-Spam-Status: No, score=2.4 required=5.0 tests=DATE_IN_FUTURE_06_12, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, 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 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]); Sat, 23 Sep 2023 01:58:49 -0700 (PDT) X-Spam-Level: ** On Fri, Sep 22, 2023 at 10:53:19AM -0700, 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. > > [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 Reviewed-by: Gustavo A. R. Silva Thanks -- Gustavo > --- > 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 > >