From: Jamal Hadi Salim <jhs@mojatatu.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Cong Wang <xiyou.wangcong@gmail.com>,
Jiri Pirko <jiri@resnulli.us>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] net: sched: cls_u32: Fix allocation in u32_init()
Date: Thu, 17 Aug 2023 12:32:31 -0400 [thread overview]
Message-ID: <CAM0EoMmK0VK1=5SSHVm28zz2CUCamxJPXNukehqY955uP17VPQ@mail.gmail.com> (raw)
In-Reply-To: <ZN5DvRyq6JNz20l1@work>
On Thu, Aug 17, 2023 at 11:57 AM Gustavo A. R. Silva
<gustavoars@kernel.org> wrote:
>
> 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 <u32_init+0xfc>
> | 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 <alx@kernel.org>
> Closes: https://lore.kernel.org/lkml/09b4a2ce-da74-3a19-6961-67883f634d98@kernel.org/
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> 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;
LGTM.
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
cheers,
jamal
> 2.34.1
>
next prev parent reply other threads:[~2023-08-17 16:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-17 15:58 [PATCH][next] net: sched: cls_u32: Fix allocation in u32_init() Gustavo A. R. Silva
2023-08-17 16:32 ` Jamal Hadi Salim [this message]
2023-08-19 2:38 ` Jakub Kicinski
2023-08-21 14:35 ` Jamal Hadi Salim
2023-08-21 18:48 ` Jakub Kicinski
2023-09-29 18:24 ` Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAM0EoMmK0VK1=5SSHVm28zz2CUCamxJPXNukehqY955uP17VPQ@mail.gmail.com' \
--to=jhs@mojatatu.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gustavoars@kernel.org \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).