netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hangyu Hua <hbh25y@gmail.com>
To: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	tgraf@suug.ch, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: sched: em_text: fix possible memory leak in em_text_destroy()
Date: Thu, 21 Dec 2023 10:14:09 +0800	[thread overview]
Message-ID: <a2634a6e-6630-4db7-8b66-81b315038f9e@gmail.com> (raw)
In-Reply-To: <CAM0EoM=4ZRteGbjAdBuLGtbM_qpnJoUuky-Yj+i+3FOqXXra+Q@mail.gmail.com>

On 21/12/2023 00:05, Jamal Hadi Salim wrote:
> On Wed, Dec 20, 2023 at 6:55 AM Jamal Hadi Salim <jhs@mojatatu.com> wrote:
>>
>> Hi Hangyu,
>> While the fix looks correct - can you please describe how you came
>> across this issue? Was it a tool or by inspection? Do you have a text
>> case that triggered something etc, etc.

I discovered this accidentally when I used gdb to debug a program that 
uses em_text. And I think putting the code in the commit log will will 
make it too bulky.

>>
>> On Tue, Dec 19, 2023 at 10:09 PM Hangyu Hua <hbh25y@gmail.com> wrote:
>>>
>>> m->data needs to be freed when em_text_destroy is called.
>>>
>>> Fixes: d675c989ed2d ("[PKT_SCHED]: Packet classification based on textsearch (ematch)")
>>> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
>>> ---
>>>   net/sched/em_text.c | 4 +++-
>>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/net/sched/em_text.c b/net/sched/em_text.c
>>> index 6f3c1fb2fb44..b9d5d4dca2c9 100644
>>> --- a/net/sched/em_text.c
>>> +++ b/net/sched/em_text.c
>>> @@ -97,8 +97,10 @@ static int em_text_change(struct net *net, void *data, int len,
>>>
>>>   static void em_text_destroy(struct tcf_ematch *m)
>>>   {
>>> -       if (EM_TEXT_PRIV(m) && EM_TEXT_PRIV(m)->config)
>>> +       if (EM_TEXT_PRIV(m) && EM_TEXT_PRIV(m)->config) {
>>>                  textsearch_destroy(EM_TEXT_PRIV(m)->config);
>>> +               kfree(m->data);
>>> +       }
>>>   }
>>>
>>
> 
> the bot just complained about needing a cast, use this:
> struct text_match *

I see. I will send a v2 later.

Thanks,
Hangyu

> 
> cheers,
> jamal
>> Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
>>
>> cheers,
>> jamal
>>
>>>   static int em_text_dump(struct sk_buff *skb, struct tcf_ematch *m)
>>> --
>>> 2.34.1
>>>

  reply	other threads:[~2023-12-21  2:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-20  3:08 [PATCH] net: sched: em_text: fix possible memory leak in em_text_destroy() Hangyu Hua
2023-12-20 11:55 ` Jamal Hadi Salim
2023-12-20 16:05   ` Jamal Hadi Salim
2023-12-21  2:14     ` Hangyu Hua [this message]
2023-12-20 15:13 ` kernel test robot
2023-12-20 23:29 ` kernel test robot

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=a2634a6e-6630-4db7-8b66-81b315038f9e@gmail.com \
    --to=hbh25y@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=tgraf@suug.ch \
    --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).