From patchwork Thu Aug 17 15:58:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13356764 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D77A2C3DA4D for ; Thu, 17 Aug 2023 15:58:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237102AbjHQP6P (ORCPT ); Thu, 17 Aug 2023 11:58:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353404AbjHQP54 (ORCPT ); Thu, 17 Aug 2023 11:57:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7094830EE; Thu, 17 Aug 2023 08:57:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 03C8E6683E; Thu, 17 Aug 2023 15:57:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 378FFC433C8; Thu, 17 Aug 2023 15:57:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692287873; bh=T9o5S2GdvkG2Pkc/OLCddeweqtUCQ0WPfudrDdceg1s=; h=Date:From:To:Cc:Subject:From; b=Gt5eHu+Ndh/lS1IVgtLL91xVN7xhH/tg7qHdYI6uQkE1IxtHDI1scE4YIHcVmGOYz o2YaERDl6Eh66CquI4XgLi9PJI586oHgtxe7ZyPU2/pBH52DBqcoTQWgnDXIcuqBM8 n6kAM/JwNOXSppcFrxZ29W2DAnQAmGhgLxxD7I5f69WrMryWEHVjWwIKxFb8QP1Xmw /fqWupE9fp2DvqRcIOqus7Vx41GMUtAJ0mY8U03wjm4faO+BP6ENY6P+OgoxUqOGOL vgySyObxhwDV1uPQ8nDVkLElPUNfNe4cdYQLH5wmDj/0QRLNT0XBAXHbi0JY4u9n6E 3DZbICpoYfGwg== Date: Thu, 17 Aug 2023 09:58:53 -0600 From: "Gustavo A. R. Silva" To: Jamal Hadi Salim , Cong Wang , Jiri Pirko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Gustavo A. R. Silva" Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] net: sched: cls_u32: Fix allocation in u32_init() Message-ID: MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Replace struct_size() with sizeof(), and avoid allocating 8 too many bytes. The following difference in binary output is expected and reflects the desired change: | net/sched/cls_u32.o | @@ -6148,7 +6148,7 @@ | include/linux/slab.h:599 | 2cf5: mov 0x0(%rip),%rdi # 2cfc | 2cf8: R_X86_64_PC32 kmalloc_caches+0xc |- 2cfc: mov $0x98,%edx |+ 2cfc: mov $0x90,%edx Fixes: d61491a51f7e ("net/sched: cls_u32: Replace one-element array with flexible-array member") Reported-by: Alejandro Colomar Closes: https://lore.kernel.org/lkml/09b4a2ce-da74-3a19-6961-67883f634d98@kernel.org/ Signed-off-by: Gustavo A. R. Silva Acked-by: Jamal Hadi Salim --- net/sched/cls_u32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index da4c179a4d41..6663e971a13e 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -366,7 +366,7 @@ static int u32_init(struct tcf_proto *tp) idr_init(&root_ht->handle_idr); if (tp_c == NULL) { - tp_c = kzalloc(struct_size(tp_c, hlist->ht, 1), GFP_KERNEL); + tp_c = kzalloc(sizeof(*tp_c), GFP_KERNEL); if (tp_c == NULL) { kfree(root_ht); return -ENOBUFS;