Subject: Re: [PATCH v2 1/1] xdp: avoid calling kfree twice

From: Toke Høiland-Jørgensen <[email-masked]>
Date: Wed, 09 Dec 2020 11:44:11 +0100

Zhu Yanjun <[email-masked]> writes:

> On Wed, Dec 9, 2020 at 1:12 AM Daniel Borkmann <[email-masked]> wrote:
>>
>> On 12/9/20 6:03 AM, Zhu Yanjun wrote:
>> > In the function xdp_umem_pin_pages, if npgs != umem->npgs and
>> > npgs >= 0, the function xdp_umem_unpin_pages is called. In this
>> > function, kfree is called to handle umem->pgs, and then in the
>> > function xdp_umem_pin_pages, kfree is called again to handle
>> > umem->pgs. Eventually, umem->pgs is freed twice.
>> >
>> > Acked-by: Björn Töpel <[email-masked]>
>> > Signed-off-by: Zhu Yanjun <[email-masked]>
>>
>> Please also fix up the commit log according to Bjorn's prior feedback [0].
>> If it's just a cleanup, it should state so, the commit message right now
>> makes it sound like an actual double free bug.
>
> The umem->pgs is actually freed twice. Since umem->pgs is set to NULL
> after the first kfree,
> the second kfree would not trigger call trace.
> IMO, the commit log is very clear about this.

Yes, it is very clear; and also wrong. As someone already pointed out,
passing a NULL pointer to kfree() doesn't actually lead to a double
free:

https://elixir.bootlin.com/linux/latest/source/mm/slub.c#L4106

-Toke