From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2068AC433FE for ; Thu, 10 Dec 2020 04:35:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE79E22D75 for ; Thu, 10 Dec 2020 04:35:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731986AbgLJEfP (ORCPT ); Wed, 9 Dec 2020 23:35:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731718AbgLJEfA (ORCPT ); Wed, 9 Dec 2020 23:35:00 -0500 Received: from mail-ot1-x343.google.com (mail-ot1-x343.google.com [IPv6:2607:f8b0:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AA51C0613CF for ; Wed, 9 Dec 2020 20:34:20 -0800 (PST) Received: by mail-ot1-x343.google.com with SMTP id 11so3710999oty.9 for ; Wed, 09 Dec 2020 20:34:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=YuCTFAaAxreWABeq+DhtSFvJAhBFMMBZ+mON2QcqSSo=; b=qAzQ7gdebTOgmorjS0OdJDMYeBFTqrptleLgMenA4ELOk+aOadWzS8JGe3KlP9gp5G HzX1zbunhb5LNLzOgUE9KEhwOaeCWt5fExbrrwKHvaHcP1OVsW5LJFpmabRJ6cpP1hdK i8f4j+DrUWHo0fdnNjJhqoIk8JAPKhFMOYjLBLKfDiGgw7ZBTzj+gmxL/hOEtOm3NVcc eZIwePq2yK4DE+9NAtI7zxoUxesDD3abOG6H9pwHeNhXsdjLBNpHDWS2FdbYsv7qacpE ol8HkDXqzrnTWtODywegRIi1zlJ4LqTb6Dv/oijxTwDMo8d1mj1ohTGv03sFOPSEYop9 oDsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=YuCTFAaAxreWABeq+DhtSFvJAhBFMMBZ+mON2QcqSSo=; b=AhGIciDuf/ao8Tp+Ht01uU8GWuJ3hSD2UZUUFp2XwdTcG/bPduiky6tgharbv3/vaE lZ89cyWIjF4AANjiN9S/4pKtT+oiSvHXOMaLFOQCkjz6eYPL8FpUKxuUFrprT87iwFCg aFEUW3TkP2x21tF6gyTj8VpgUhFwbVGPj0Vad95Tv9cRdFGOq+AVROXeYPfJEnjjKy5S SjanxUUCB3TJXm6ihZ6jV4HeLtDXJxFvmviqKt06wuR/BZNcJZH55gQXQClBIMSI6sR+ 2SktocSYmF9VDveoFj76HRrFEsxtyVh7TXhhA7bI8noBkGTHIabAYJzf2IhSCDqqYSqe tCLw== X-Gm-Message-State: AOAM531OCFKUQA05TKKQMWpi2jo7Wzex0McjeKTEmFDz07MJopsf3s+p bbZmqiyhMy+gMqreMtjxJmVgXTiL+XnpqhkElRo= X-Google-Smtp-Source: ABdhPJw7eCCbxiN8bXDsezuk6u34Hnv9DzcE+beU+JF5wjqGrVMZ2/MrcVNLJnEKlmjQp+Kj/OEZv5G2HjER+MGfJGQ= X-Received: by 2002:a05:6830:784:: with SMTP id w4mr4592614ots.53.1607574859826; Wed, 09 Dec 2020 20:34:19 -0800 (PST) MIME-Version: 1.0 References: <20201209050315.5864-1-yanjun.zhu@intel.com> <87a6unp8ck.fsf@toke.dk> In-Reply-To: <87a6unp8ck.fsf@toke.dk> From: Zhu Yanjun Date: Thu, 10 Dec 2020 12:34:08 +0800 Message-ID: Subject: Re: [PATCH v2 1/1] xdp: avoid calling kfree twice To: =?UTF-8?B?VG9rZSBIw7hpbGFuZC1Kw7hyZ2Vuc2Vu?= Cc: Daniel Borkmann , Zhu Yanjun , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , "Karlsson, Magnus" , netdev , jonathan.lemon@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Wed, Dec 9, 2020 at 6:44 PM Toke H=C3=B8iland-J=C3=B8rgensen wrote: > > Zhu Yanjun writes: > > > On Wed, Dec 9, 2020 at 1:12 AM Daniel Borkmann w= rote: > >> > >> On 12/9/20 6:03 AM, Zhu Yanjun wrote: > >> > In the function xdp_umem_pin_pages, if npgs !=3D umem->npgs and > >> > npgs >=3D 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=C3=B6rn T=C3=B6pel > >> > Signed-off-by: Zhu Yanjun > >> > >> 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 n= ow > >> 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: In your commit, does "double free" mean the call trace bug? If so, I will correct it in my commit log. In my commit log, I just mean that kfree is called twice. And the second kfree is meaningless. And since NULL is passed to it, this will not trigger "double free" CallTrace. I will send the latest version soon. Zhu Yanjun > > https://elixir.bootlin.com/linux/latest/source/mm/slub.c#L4106 > > -Toke >