From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.69 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796413217; b=q+H4wAk7hVWI8OYeb/qnt3wdVHlL7EDlPoRpka0fz9K8ZZIB5wBQ3NLXvrBMRYXnSK6a Se2WhKqJC4JvX8gbUgezNgN33jF0R5tEIM7AqQQStCiJdEfA+WwWyabVUEuUTxm2SbIzc 9wD984IKQY3bFo5VklK6fOmzMqfe+S8fP0TvOTCOBuPxc3RIqpfxFYvmnfMdR7pusdA6o GITU+b4T+EPt5RHuWTNOF6QDRMdNfMXD7h33Nek0gTfdrmolAV9Warh1gSSYtVeI8w9+5 JwjRXo6fQqTjh0ucRrX4mpUtqz53ZLccBJesbjJCDkxdYB3KtwGtshCRtx88DNrrSkw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796413217; 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=2qJHEybOfUDmEAavus/SRlCLHdMXub/Udw0V4rff2Z8=; b=ZJ7X/1Z/qb9Zd8sVPGMGxFUKheIsoKeJrzy19JJRXme5mpHCp9nF6TDaTF7gLOuYUasc i9k+JrnltqkCnBQ2Rr1lJOGNyJMi8fTItStn6wGRhgghykYOq1DNVTDFl3Q7+P6OaAM63 9rtSqzhfRoSn+ES5zlOZIofJWyqNdOhvf91uycwzeX7kjH5DFtZzVbxMUMPQPwb4074EW xmin5QYWzpWJHFkhlaMlegdEc8x21szYo6xghDjfyvDrGKli9s0l8W/4YIB5x0gg3v850 ca0OlfiQxQcP6gqIO/J9VXN0NL3OobThi992Iza7ksVfRenu1+PgzsF1yyS08My4fqA== 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=WqlCpemT; arc=none smtp.remote-ip=209.85.161.69 Received: from mail-oo1-f69.google.com (mail-oo1-f69.google.com [209.85.161.69]) (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 13EDF606A6AC for ; Fri, 4 Dec 2026 19:40:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 13EDF606A6AC 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=WqlCpemT Received: by mail-oo1-f69.google.com with SMTP id 006d021491bc7-71ad7f06ab4so1269232eaf.1 for ; Fri, 04 Dec 2026 11:40:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796413207; x=1797018007; 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=2qJHEybOfUDmEAavus/SRlCLHdMXub/Udw0V4rff2Z8=; b=WqlCpemTtaZ2gh3fc6LVquK8DZUfWXTcOHWYqTYbaL8CEVewhM9Km+ucdKQqIaoRCi IzAWZv1EvkHTeDJPPuLzRRgDLrRBzzZemmL1WP5INQLw1sS+b2J+/4BkDGKQAuKMvMXE njTkHxjpew/Wl2eGEdv+FpzGpaX5RdFBNQqet8KFkf8KVW+WdHC3S9JHJi6ysj21zQ3L MOIEC9Wokk6qisRjwD3ufDRCMTwm0dBH4HQ8N2JmYitYouBewE6rpwCM5bX855w65mP+ aNXEHY6PNt+gO1nfQqgHkC3HxscHTk1Dn23zagrHv2/j4X8a+43sDivk7/0IeZqvb4aE w8ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796413207; x=1797018007; 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=2qJHEybOfUDmEAavus/SRlCLHdMXub/Udw0V4rff2Z8=; b=qOuywpPjhvsWKfrJLacvi9VE79Y7d68TuRH9OcegAw38YqtGsHUHsX/cgIXt59K+Z+ O/aRt4sMCJPndEWXIZcSEPoarn9eZx3aMxDcWFotdkfC18zmwCbvk767HKJEh3u1xNvF ntST4d4C/H2XjJbb2aq2wQiIWvoWvE7U6lb5/HiUFe02qAAerw3hP0jhBw0nk7zzPw36 Nlb7tQD9aE33YXs8AfcEDkShzIljK5QUcvAWREihLxKClZGSLvUIK6Vp0CHX3MlKOnjk yLQz7TZP2tI7k+UGpG+mMVjrDxtXfXZkysIm9I5Oe10ULm3VbLM2PiulndrmR6Yxbt3v 6lrQ== X-Forwarded-Encrypted: i=1; AL+hErGZ2EItfDCW/DCoIY+wxYaGpazEpxQ2x935W92iNVhqrarFT3Xlm/3lVfibV9YGUPq2vPeLNahqxYknPrUB/BA=@vger.kernel.org X-Gm-Message-State: APuU4Z+rkIgCr+lqJ3n/+7Gak25kHS+DcgVEjQys8H9CQRVvdMNCLN9N QZKN3gJNzqbOZwGbEIcJZ+cOy24tbkE/tiCb0t+8YMWanMlzL6LWefkWLSWXpWzLSwROX3GX59f gEGKn1/hYqVR4PA0J+W+EwwMPLQ== X-Received: from iofl6-n1.prod.google.com ([2002:a05:6602:8386:10b0:9e8:9d0f:5a50]) (user=justinstitt job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6820:c7ca:b0:717:163:aeac with SMTP id 006d021491bc7-71bf21b18edmr2298554eaf.68.1796413206774; Fri, 04 Dec 2026 11:40:06 -0800 (PST) Date: Fri, 4 Dec 2026 11:40:06 -0800 In-Reply-To: <20261203-clk-onecell-count-order-v1-11-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-11-2b0e4e8d9ea6@cressey.dev> Message-ID: Subject: Re: [PATCH 11/11] clk: zynqmp: 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:49PM -0800, Ben Cressey wrote: > hws[] is annotated with __counted_by(num), but zynqmp_register_clocks() > fills it before zynqmp_clk_setup() sets num. The count is still zero > with Clang 20 and 21, where kzalloc_flex() does not set it, and on v6.6 > to v6.19, which use 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/zynqmp/clkc.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/clk/zynqmp/clkc.c b/drivers/clk/zynqmp/clkc.c > index d62f1901d0ab5..88d1281c284b8 100644 > --- a/drivers/clk/zynqmp/clkc.c > +++ b/drivers/clk/zynqmp/clkc.c > @@ -762,6 +762,7 @@ static int zynqmp_clk_setup(struct device_node *np) > zynqmp_data = kzalloc_flex(*zynqmp_data, hws, clock_max_idx); > if (!zynqmp_data) > return -ENOMEM; > + zynqmp_data->num = clock_max_idx; > > clock = kzalloc_objs(*clock, clock_max_idx); > if (!clock) { > @@ -772,7 +773,6 @@ static int zynqmp_clk_setup(struct device_node *np) > zynqmp_get_clock_info(); > zynqmp_register_clocks(np); > > - zynqmp_data->num = clock_max_idx; > return of_clk_add_hw_provider(np, of_clk_hw_onecell_get, zynqmp_data); > } > > > -- > 2.56.0 > Reviewed-by: Justin Stitt Justin