From nobody Mon May 25 04:33:47 2026 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 660D02F7F06 for ; Tue, 19 May 2026 01:58:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779155933; cv=none; b=Xj5hdvyhDr0H0TOwdInyrIuePCaPB/FUQJgK3YaYNJjbHa9WKjym0b4wNkxFwd0s8dBwT5mti8QMbqm1Zb5f9uR6hhM+P7756Mddw/VDCTBGheab19H/Py/MVI6l7OB7RlWRNATCS+eC8WK2N46K10YMXZs/c5znFVvjTC+hahc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779155933; c=relaxed/simple; bh=o9tpwTNBKfUuronh2IiA7Q31eMmatIzAB4cU4aq6YU8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=nIWYg+QUxqXmWvmQyBg0k2QGxwWOa2pz75GSAG0LsNzPkYuMtq46Tn5ppjuBHyXtGkHh9uva3itVFqY3EUV1uX1scd/WOPGpyhSQiTfH1B0pD9/16x9LrxOz6AKTuotM/bF5dQtdamrMtT5sYxFJP41IQvIljB69s7s/Z7VHO1Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GFtwA/JM; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GFtwA/JM" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-36643b96b99so2793495a91.0 for ; Mon, 18 May 2026 18:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779155932; x=1779760732; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=cJBOwsmVOS7e0w8Q9mvj/KZhpczr6xeaK0EFoTPkDf4=; b=GFtwA/JMJRHL2m89MeRU6sYFKKNU00eqY7jiPwOPGNaBTmqhARmsVHtRRH0o3w0KCr VsrhyMx1OxWfgHgSTHurPIUlyYxtu4TKX5pEx5Z0o7a6mZ0hjmAXCQv5GmZBMx5TBdjN 5yOBH8SubWLi/gzQfpOzUM6PwAlx6YCYwmN5QLMIDSE+LHJY2Nz8EmNOM2b3K4t7MNKJ ZwWaEmACh8VyI7dIvC6DWZb74TmZT0UC/Kp8Lbg0/0tUA3qtkShBsrQozX+nNOzf/HZt a//YBa/yBVP1FayFjWcvma8GQSlYtuCGUaYDiwXn+CHwmi8wcxDYfq/refyNseze9LxG PbIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779155932; x=1779760732; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=cJBOwsmVOS7e0w8Q9mvj/KZhpczr6xeaK0EFoTPkDf4=; b=C/DXEpDqK6OzhZg+5Tl+NVAiS9ex0TRLdCh9j5g6lVQWorAeUWrSO5c2AdiYi3P5JZ AHu3zlzf2DA6ijCHzKd7Wg5zPPAEnunY47029wgpf+dZ5UjPgFCj81hQOZWzHKmMbPcG 593PihjTpLI7tItCMxHzi8aLs28OHf9aiwzCC9toUAactVa1A2+Bh9aBvtUn9RnPMeio hQhAK+aNM/bog+TxUTj0CgxFE9tO0d8Qp3IWpM+xlbf7z8BOHD1Qf37HQ9gs3kLPzfHA 3HZBFEWFTn1C7fcpAsml1DWaxtrdeLuUpaXD0w5ZBIyu9SS7WGRapqWsMx78efjPa+iu cw9w== X-Forwarded-Encrypted: i=1; AFNElJ/9sFmBtMLGXMFwAYLDtwX8DqJDD7mUdcX41HGzI578XiyUqXwe4X2sfQRwMh0vQutPVl9AQwQphmFDxCI=@vger.kernel.org X-Gm-Message-State: AOJu0YxVPKpDN22XPNP3DgQ+sCfSqcLDn3zAV+TVpXb1/jYqnEPTZDmL 7FVESvyAL+WemAfTEYWc6Sml/OLVSgi57Uq3lv3E4vcFRsF88iNmpjRq X-Gm-Gg: Acq92OElpQG4WYULpyRfb5l9O4sRuvoll3rOhdGT3QM8wGQ4OCetw1YsXpBuYRfzijb Yvjm87B6PgTC44W8bpQq3jpPx9+HSak8eObwMzOrdtLgHpQvwe5W6lUBVy57i6T1snyLqpHtL61 UWKAVkqu+MWdYzdmJjGyAbJfy5bG0q1Z/pF+yXYetWO+hhak+vnwEdBx4X+pFobGVAwv+lp6HqN z17hYmUkqvDdILo3H/vwZnHFJHo5PBTxc+8x83DK+ZoaRE8t/+AXyivIJLA3RRal4hqfhNVRn2j jh7zCXpiA6tLMnTFlxfcvaVPoJFHZI74iC7Axl0YnOA6vLxU92hc9PPfwMhbTgfqARL1be2gT06 RqSnsswyqXDSo0HeRucyDLcfYRKBMvjm5Cd8cNGUK2zojL0+e5KnRVphE6wYP3/jexTcFyXJWPP 6WNvTC/K9cv5ep1PFaWqmwU8zT6+C0uqoMWPu/zNGhCzNb2ewivftQhXjhMo/TcPTGEewEm/9MM 4YctrkrQacrAdFNBoMCIW384E6FZ/M5uSs= X-Received: by 2002:a17:90b:57c7:b0:365:7e4d:bcb8 with SMTP id 98e67ed59e1d1-369519cdb59mr16915705a91.1.1779155931783; Mon, 18 May 2026 18:58:51 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d:7285:c2ff:fe45:8a32]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-369513fe6f2sm12016286a91.0.2026.05.18.18.58.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 18:58:51 -0700 (PDT) From: Rosen Penev To: netdev@vger.kernel.org Cc: Jiri Pirko , Andrew Morton , Kees Cook , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org (open list:LIBRARY CODE), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be|_ptr)?\b) Subject: [PATCH] lib: objagg: Use flexible arrays for object storage Date: Mon, 18 May 2026 18:58:33 -0700 Message-ID: <20260519015833.634602-1-rosenp@gmail.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Store object payloads and temporary graph nodes in their parent allocations instead of open-coding trailing storage or allocating the node array separately. Use byte-sized flexible arrays for object payloads so kzalloc_flex() is passed the same byte count as the previous allocation sizes. Assisted-by: Codex:GPT-5.5 Signed-off-by: Rosen Penev --- lib/objagg.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/objagg.c b/lib/objagg.c index 23c7105a3f9f..995ec67fbc2f 100644 --- a/lib/objagg.c +++ b/lib/objagg.c @@ -28,7 +28,7 @@ struct objagg_hints_node { struct objagg_hints_node *parent; unsigned int root_id; struct objagg_obj_stats_info stats_info; - unsigned long obj[]; + u8 obj[]; }; =20 static struct objagg_hints_node * @@ -66,7 +66,7 @@ struct objagg_obj { * including nested objects */ struct objagg_obj_stats stats; - unsigned long obj[]; + u8 obj[]; }; =20 static unsigned int objagg_obj_ref_inc(struct objagg_obj *objagg_obj) @@ -369,8 +369,7 @@ static struct objagg_obj *objagg_obj_create(struct obja= gg *objagg, void *obj) struct objagg_obj *objagg_obj; int err; =20 - objagg_obj =3D kzalloc(sizeof(*objagg_obj) + objagg->ops->obj_size, - GFP_KERNEL); + objagg_obj =3D kzalloc_flex(*objagg_obj, obj, objagg->ops->obj_size); if (!objagg_obj) return ERR_PTR(-ENOMEM); objagg_obj_ref_inc(objagg_obj); @@ -657,7 +656,7 @@ objagg_hints_node_create(struct objagg_hints *objagg_hi= nts, struct objagg_hints_node *hnode; int err; =20 - hnode =3D kzalloc(sizeof(*hnode) + obj_size, GFP_KERNEL); + hnode =3D kzalloc_flex(*hnode, obj, obj_size); if (!hnode) return ERR_PTR(-ENOMEM); memcpy(hnode->obj, &objagg_obj->obj, obj_size); @@ -705,9 +704,9 @@ struct objagg_tmp_node { }; =20 struct objagg_tmp_graph { - struct objagg_tmp_node *nodes; unsigned long nodes_count; unsigned long *edges; + struct objagg_tmp_node nodes[] __counted_by(nodes_count); }; =20 static int objagg_tmp_graph_edge_index(struct objagg_tmp_graph *graph, @@ -786,13 +785,10 @@ static struct objagg_tmp_graph *objagg_tmp_graph_crea= te(struct objagg *objagg) struct objagg_obj *objagg_obj; int i, j; =20 - graph =3D kzalloc_obj(*graph); + graph =3D kzalloc_flex(*graph, nodes, nodes_count); if (!graph) return NULL; =20 - graph->nodes =3D kzalloc_objs(*graph->nodes, nodes_count); - if (!graph->nodes) - goto err_nodes_alloc; graph->nodes_count =3D nodes_count; =20 graph->edges =3D bitmap_zalloc(nodes_count * nodes_count, GFP_KERNEL); @@ -825,8 +821,6 @@ static struct objagg_tmp_graph *objagg_tmp_graph_create= (struct objagg *objagg) return graph; =20 err_edges_alloc: - kfree(graph->nodes); -err_nodes_alloc: kfree(graph); return NULL; } @@ -834,7 +828,6 @@ static struct objagg_tmp_graph *objagg_tmp_graph_create= (struct objagg *objagg) static void objagg_tmp_graph_destroy(struct objagg_tmp_graph *graph) { bitmap_free(graph->edges); - kfree(graph->nodes); kfree(graph); } =20 --=20 2.54.0