From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.72 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796412365; b=0caSulEFCdSbENmPRHTpTaalpYfnLSoCX4BdaQ4yt48CZY016M9UTS45LbYqQoy3JywM bxdTJH8TWgqoKmxAFOF0Aa7864YwsgK6My4srLMBLIepLfb6VBUSR22ld92k6AeC2An4J IIJ8gqNrVGF98yV2EwMWpxJlJTDGJRHH4Zzgmfow5WHsOPmuk8BW05XGO9V/ZjcchJ+af Z3E2SUjfmxbqL9ekgARKphNxahwQGq7MaDBLt5HN5ZRRQAAs1Hbj4D/YaB1u3KFpTbAkD mvj2lLuL7GCDDfocSEOg9L/MRzcTy9l3MzstUKV6TQfFOPtNOC8ZgcoTGv2YqKFJxWw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796412365; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:Message-ID:Subject:From:To:Cc:Content-Type; bh=HPPGpH/5fw6fnkXxGqM02iFTobIJXO9Xf4bRphmCi/8=; b=OokbFmORWatqgQcJ9N562j1CS9KNc5kB43uKIvUovICfTUYHLfUiSH/Jnnsq8F8x4cF+ vIGn3WxWs6ac7ZlmxSAZcWtogtR36J0MB6NH+yxVuXK/lWxw2Kb6PSGK7+v1tlViY/2/1 fytuj5W5kmv7Ot/b9URlLsadPhZ0YVjKF+hisucxvLT3RU5ZcSM6sLGVn31jxxk+mYGrt G+EWSVtUCzHOqL7zu4IASTmOqHDxqg51ukAbOc4hcH8MP52GmJoU1HBu+N5rTBWO7mU0e PmUj3nxCQeV6LyonZMUbWlhsqd+U5PxhW6Wia5oaYEx7TMr3IuRbMk9ehDLC6D67bgw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--justinstitt.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=Qmlxvacy; arc=none smtp.remote-ip=209.85.161.72 Received: from mail-oo1-f72.google.com (mail-oo1-f72.google.com [209.85.161.72]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB2CE606A32D for ; Fri, 4 Dec 2026 19:26:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DB2CE606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--justinstitt.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=Qmlxvacy Received: by mail-oo1-f72.google.com with SMTP id 006d021491bc7-71be386bb06so1652528eaf.1 for ; Fri, 04 Dec 2026 11:26:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796412364; x=1797017164; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=HPPGpH/5fw6fnkXxGqM02iFTobIJXO9Xf4bRphmCi/8=; b=QmlxvacysgX9OvsZdG6CnfOv36yu1/gqeYAOJKps5tdCrcdyUQE37YDOF1HGJrUdNK V93DJ1TJyrGVhmhIHuR77z0U/27X998yUi8+KI5mcfwC6g58ErpGjFGgB4iLePxRWXcM pDvK6f33BNkLqU49D+rZ1U0bAcMx1Y2qqPDdbH3e9lbWOQ+Z4IDD09WuK/lJQhPFlHtA 90u3eq7mEp+fGVpCixlg3Efk73MZBephh+jzwUn87bmeFdlr9H3Yl5aONM+n9ciE429Z qHrOlTpTmUcZVQmDcuj3icXomVT3N7warDr9doc6zQ1l9+2l1vjlvTPHfLBR+zWSn8dK W8yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796412364; x=1797017164; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=HPPGpH/5fw6fnkXxGqM02iFTobIJXO9Xf4bRphmCi/8=; b=POJBTDIdmPfCMq5V2hJAkmciOAmj+h81T58h7h2Cdlx8iKdXrdX3Fp7vU0BWE2o3i6 4TilIeVw3W2M4aScUIvUeMgfvPBSbGwQ1DttEPiiS1Hk3Kb+oeqBB6g04XdiXbgNy8pZ ejwyLjIsweJnHkGg/VidD/IqK9E6v1Py2paWgj+qbSq87QWc1Hr3c4oM7Hml1Qy6iWp0 +IUeLe2Ar35YeyJBXI1aQrTlPGt/FINw+Fq85i98ac1s4d/wRvklsNtj3aU4u7hXuFJV 9z1u48WNAoQdce46svEeLPiCjrZzQP7n9j5iXMOjfo4UguIMYQWetINYUoHwkIQSUUq/ 45AA== X-Forwarded-Encrypted: i=1; AL+hErEH6I+s0SKlJ33/KDxv1JIu7ifcZe9N2CdfxYmeTNKxqFs7IYhkqrovDOYJaObfP6IWBvOAXeWPaJcTG835BXo=@vger.kernel.org X-Gm-Message-State: APuU4Z/YHRFSM431rRypDnV1yxHPIf1aRt3WB/ijOZd0WpqrH4h+PNAt 2CHZPd7eGesiZiJbck1Ci8zvV4OC1UldpXOdM872T0A16Tfq+43TNK6Ime7GWKy0Cwdh5LWYTrr mq4g/7JtQ2VxYHNisOg0YKuFruw== X-Received: from iobhd10.prod.google.com ([2002:a05:6602:680a:b0:9ea:3fb0:262]) (user=justinstitt job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6820:c446:10b0:71a:e74b:f97e with SMTP id 006d021491bc7-71bf203aa78mr1896235eaf.23.1796412363659; Fri, 04 Dec 2026 11:26:03 -0800 (PST) Date: Fri, 4 Dec 2026 11:26:03 -0800 In-Reply-To: <20261203-clk-onecell-count-order-v1-4-2b0e4e8d9ea6@cressey.dev> X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261203-clk-onecell-count-order-v1-0-2b0e4e8d9ea6@cressey.dev> <20261203-clk-onecell-count-order-v1-4-2b0e4e8d9ea6@cressey.dev> Message-ID: Subject: Re: [PATCH 04/11] clk: sifive: prci: Assign .num before accessing .hws From: Justin Stitt To: Ben Cressey Cc: Junhui Liu , Manivannan Sadhasivam , Nobuhiro Iwamatsu , Michal Simek , Stephen Boyd , Brian Masney , Jerome Brunet , Paul Walmsley , Samuel Holland , Emil Renner Berthing , Hal Feng , Nathan Chancellor , Kees Cook , Nick Desaulniers , Bill Wendling , "Gustavo A. R. Silva" , linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org, linux-riscv@lists.infradead.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org, Harry Austen , Changhuang Liang , stable@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Hi, On Thu, Dec 03, 2026 at 04:15:42PM -0800, Ben Cressey wrote: > hws[] is annotated with __counted_by(num), but __prci_register_clocks() > fills it before it sets num. The count is still zero with Clang 20 and > 21, where devm_kzalloc_flex() does not set it, and on v6.6 to v7.3, > which use devm_kzalloc(). With __counted_by enabled, CONFIG_UBSAN_BOUNDS > reports the accesses and CONFIG_UBSAN_TRAP makes the first one trap > during probe. > > Set num right after the allocation. > > Found by an LLM-assisted check of __counted_by users. > > Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") > Cc: stable@vger.kernel.org > Signed-off-by: Ben Cressey > --- > drivers/clk/sifive/sifive-prci.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/clk/sifive/sifive-prci.c b/drivers/clk/sifive/sifive-prci.c > index 402b905d010ed..b4544d024dd88 100644 > --- a/drivers/clk/sifive/sifive-prci.c > +++ b/drivers/clk/sifive/sifive-prci.c > @@ -540,8 +540,6 @@ static int __prci_register_clocks(struct device *dev, struct __prci_data *pd, > pd->hw_clks.hws[i] = &pic->hw; > } > > - pd->hw_clks.num = i; > - > r = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, > &pd->hw_clks); > if (r) { > @@ -571,6 +569,8 @@ static int sifive_prci_probe(struct platform_device *pdev) > if (!pd) > return -ENOMEM; > > + pd->hw_clks.num = desc->num_clks; > + > pd->va = devm_platform_ioremap_resource(pdev, 0); > if (IS_ERR(pd->va)) > return PTR_ERR(pd->va); > > -- > 2.56.0 > Reviewed-by: Justin Stitt Justin