Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1101019rdg; Wed, 11 Oct 2023 14:41:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHHhlpYtXnadFCUO0tjC4S8z6O+HoPuHOlTR17Mr0pJwAjEoJTzy3MvAzJT+THHfS3Zq8hh X-Received: by 2002:a17:902:bb84:b0:1c7:4334:6540 with SMTP id m4-20020a170902bb8400b001c743346540mr16982590pls.63.1697060495602; Wed, 11 Oct 2023 14:41:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697060495; cv=none; d=google.com; s=arc-20160816; b=dq6nTTCXYJyX0D6c/xDtUprwMrzhohmGo+Ey5zdHmTE+2qU6qJEGnVEAlb/DZDFFdi qhv0cqEUOUeEHYR101f8+IdkFiyIsAOya3bc4CaVPHDC8MWesK4X20YgRRkK8PDswrQ6 3QlZaV4bJgQv0qNDyL4ZR96oHPqJ1S0neIpMqREcGYyHD/2KgrFg+RtGYeeiDPLanm16 eNvCAFYdvQxAfkIwZnA1fvh7N7xv9ybv5kpK79rO60bJnCDQOaET15UH4C8T/TQ4FX6J ZzcJNgBG5Aj52CVzpj3arDKSDHV2s+sYSfATqR4uf46VoTDggPEZICBRoiopboSgVZ6Z P3IQ== 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=C9utCBiCdOTyVV2yijJlin/2F56vToEAaXQDWZUK9xk=; fh=rZZgWxLiTDTIqHYV/5tJYgxa+wghMUigNbbc5DgNl/I=; b=zriRJ1HUScmwY2EsV9+iHVHaAsKQMWk7gkwBDc4GT2+e50bTR+dPy2GvqEIUuPymKE Fzfqob83meylbQL7tCWppv7m9zaiFLbJAcnRecbqYOuZ2ne+3G5YoyW4EtApE6CgH/u8 OQHaNZrQzQvNPEXGdFa98/DrmQ+pto6X32yoEpp2zUyefZedx7E3O451FVnm5oRMIYEB +MByWTeOrI1Lajpv4nsZ4wUJoZr/3jhcWvV12cfxlzcIazfkgllky25mccD3x5IzS7BK SygRrHfHVWaudNEw7Iv81O0b3PQMiOUUW80Hq2zH3iQj6SRV5yPdbPP/2PzHDbDe6/8o IWig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KfXaPkm7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id l5-20020a170903120500b001c60ec1e650si730381plh.82.2023.10.11.14.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 14:41:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KfXaPkm7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 4DAF580477B7; Wed, 11 Oct 2023 14:41:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233527AbjJKVlH (ORCPT + 99 others); Wed, 11 Oct 2023 17:41:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233390AbjJKVlG (ORCPT ); Wed, 11 Oct 2023 17:41:06 -0400 Received: from mail-oo1-xc2f.google.com (mail-oo1-xc2f.google.com [IPv6:2607:f8b0:4864:20::c2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 975719E for ; Wed, 11 Oct 2023 14:41:05 -0700 (PDT) Received: by mail-oo1-xc2f.google.com with SMTP id 006d021491bc7-57b6c7d0cabso188876eaf.1 for ; Wed, 11 Oct 2023 14:41:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1697060465; x=1697665265; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=C9utCBiCdOTyVV2yijJlin/2F56vToEAaXQDWZUK9xk=; b=KfXaPkm7m+oRIwlMiiIHcsazYgkO86v1Sj8k3lCn9TH50FLrc2yiYBBJ5R5cjl0DPG L1Xo7xDo9UrUr/nnsmadHroZ+fPaC8ZadTSjcIMxr5eqah8BKMR6KZUwRCoeXhkmtnxf BPhnkM6Q4Vj5NR0J9d61kFaJAjFyllD+i6ums= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697060465; x=1697665265; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=C9utCBiCdOTyVV2yijJlin/2F56vToEAaXQDWZUK9xk=; b=GFwuotKeFvP30Ol8MUsPoRw6hSJLR0n5LZQGNytlxhjLoSqU2pbBYLTwxWygKtPJl1 JrJY/gQ2uwka8e8nb8qXzMbDh8VMpg3JRN47Qdc2qDJ91WQlxx/eAQHlloqGwH0Wv6om y5uYlJ6fk21aSupMSyRjvMY7OD56vEJStcQvOA5ls5DzSGDMHMxUuoKrBdA9iicch3n4 Xv3NQeA14/6vp5UhzT4cQy1RwjlFKIXS9dgys+nyIO0qYAyF2xNa8abhJ7QyQvrGndVT wzzPdI25+PXjIEEse3YfU8v7kZekbVuiI2S/TSvOY9jzgY3VhuIn/yWoM1L4UZo9uGiP pjrQ== X-Gm-Message-State: AOJu0YyfyIfyo2qkYtdyx9Nmy1ntzzN5g/bdN3CQ/Ehs0F+15TjfsIWS n3fWjLyt+P8xUe+suPyJ+sUE/Q== X-Received: by 2002:a05:6358:2496:b0:13a:cb52:4837 with SMTP id m22-20020a056358249600b0013acb524837mr20580632rwc.31.1697060464890; Wed, 11 Oct 2023 14:41:04 -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 c26-20020aa781da000000b0068be3489b0dsm10864161pfn.172.2023.10.11.14.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 14:41:04 -0700 (PDT) Date: Wed, 11 Oct 2023 14:41:03 -0700 From: Kees Cook To: "Gustavo A. R. Silva" Cc: Dinh Nguyen , Michael Turquette , Stephen Boyd , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH 2/2][next] clk: socfpga: agilex: Add bounds-checking coverage for struct stratix10_clock_data Message-ID: <202310111439.35CB04432F@keescook> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 (snail.vger.email [0.0.0.0]); Wed, 11 Oct 2023 14:41:12 -0700 (PDT) On Wed, Oct 11, 2023 at 03:35:26PM -0600, Gustavo A. R. Silva wrote: > In order to gain the bounds-checking coverage that __counted_by provides > to flexible-array members at run-time via CONFIG_UBSAN_BOUNDS (for array > indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions), > we must make sure that the counter member, in this case `num`, is updated > before the first access to the flex-array member, in this case array `hws`. > > commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with > __counted_by") introduced `__counted_by` for `struct clk_hw_onecell_data` > together with changes to relocate some of assignments of counter `num` > before `hws` is accessed: > > include/linux/clk-provider.h: > 1380 struct clk_hw_onecell_data { > 1381 unsigned int num; > 1382 struct clk_hw *hws[] __counted_by(num); > 1383 }; > > However, this structure is used as a member in other structs, in this > case in `struct sstratix10_clock_data`: > > drivers/clk/socfpga/stratix10-clk.h: > 9 struct stratix10_clock_data { > 10 void __iomem *base; > 11 > 12 /* Must be last */ > 13 struct clk_hw_onecell_data clk_data; > 14 }; > > Hence, we need to move the assignments to `clk_data->clk_data.num` after > allocations for `struct stratix10_clock_data` and before accessing the > flexible array `clk_data->clk_data.hws`. And, as assignments for both > `clk_data->clk_data.num` and `clk_data->base` are originally adjacent to > each other, relocate both assignments together. > > Signed-off-by: Gustavo A. R. Silva Yeah, ew. That's super tricky. Nice find. Reviewed-by: Kees Cook -- Kees Cook