Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp714863pxb; Thu, 9 Sep 2021 10:17:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzQmL0u5cxHVTXWRFaLei4+NCVxARPhiPDpSdNYiOPzPrI3/ha99ulRTTPxtLZdFUzTsQa X-Received: by 2002:aa7:d710:: with SMTP id t16mr4215679edq.42.1631207862566; Thu, 09 Sep 2021 10:17:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631207862; cv=none; d=google.com; s=arc-20160816; b=T4hbJjbiUYgkjCDsMKgCVhaOCzbQ4SZe0cUbRRdoIOrCSSCcpuQmKRIGxW9T6usnrd FnoR285Xp+gZqRW8zpZ3kxDzUSTlP/0kZ6kVWnU0dgl11RHkITvB986efQo7srRPtTMP WRwKZj2dVnJinTQlMS8cLKa2GL1GgAkSs37t3urMNE35aT/Tcn7b7NIX23d4BsQFfuVx yfY0DLgogd6w20Xqhj5DL+n4vgNafS3VgkVfJbtA3M75tyduUf5Gl62FsIRjTbr6BHUL QzxTgIqa0NeHgWJtMF8Oz0zZSboORymBbVXXqXMHpgMD72KbF7tmg7YsOa4YYcAVTBYv aBIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=t6R8eEc3dAmoTOcAlSBC8/eAMhoLiJ9o2v0ZjAH+j7w=; b=lF1pOv/86B5PuNbjbahwG8Wl9nxKFKu4wJ4gGkDGew5TbkblD/qIaqT2ONXkrwj+sG SNmzKmtvMGnDNFgLD23Xi8pVOi2shMqwIo8KYkYaWcLxlpAKox9+hVAwHzp0gwqyHQmp txT+htDQx9ZM2rs2WPsMECsa/wUZY4jl/7DbttIDQ6ap7sP2gsLr/7LwM/DmdjCQdvtP WHhPAzEbzrQq7OdPXBKeR/MBUylgJxsI2GnnSKIbvgaHEl9sfi6I6vCmPJmd6OD1IxmF pxX+R5ABGk5D+txktoW0hpGrFbjngBCatR+9bSfdOZnmyH2xtFC5lI4G6Bah3WtMsXm8 QJmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Xuzpdlgy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e26si2404986ejm.104.2021.09.09.10.17.09; Thu, 09 Sep 2021 10:17:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Xuzpdlgy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237122AbhIIRQx (ORCPT + 99 others); Thu, 9 Sep 2021 13:16:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237002AbhIIRQx (ORCPT ); Thu, 9 Sep 2021 13:16:53 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5E48C061574 for ; Thu, 9 Sep 2021 10:15:43 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id y18so3296137ioc.1 for ; Thu, 09 Sep 2021 10:15:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=t6R8eEc3dAmoTOcAlSBC8/eAMhoLiJ9o2v0ZjAH+j7w=; b=Xuzpdlgy0Mglp2Q6DiZ1UcVdF1mmB7GMVukvfDl4CXkDoEzbMmbpuglVHmcZh/2QAC I2ipMBRcXuKGt7eD6A/VQMYeUpg3XsJVENqX10CT5SEFLzRouH2a0g/gHKkoY1MsX2nS pzoVHk9LtWqs8bUyJR3JVmxhwGBzMQMjDYgaQYrCyLH9kCOIN7Bzuyb3klX9ndOwuUVo HIsaoSW22mzzvOSDvzK8v/QTmTdKE/7ZTwKjI2t+jEh5KOWSZ2m4Xa4vydDh/5CHIJ5u 0qxEJE1F4LJtI0ufVNhOO2ratIshIVh6vOSC2m1xAlx1exjIBD+0J8o+s7KweaTCQ2Za ANYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=t6R8eEc3dAmoTOcAlSBC8/eAMhoLiJ9o2v0ZjAH+j7w=; b=tVBR2rfKiXBHKA47LFHer8Q2e/OKBUYBbtuA+vP2NrZZVfDCtIl8/ZZLuetTYVIRvF 53d4m9yGAIrJC/OS8qgG/TuGQHCFI0qD7zUez4BxXPSACYOXWtYzxtByc1Q7dZjgyDH6 rGeu9JBuUnMhd3W8G558W5J5yru887JiGBriWtufMIqvjM07DRzgupOXQtRq+/uzRmcv UkNGvDkUeGW2dnlWwP8JSZxAsaiO39gycQC594kKOqFw6IBWIjXcgP23Z0gbHCUnokJF CGjstjHlzsBmBOYg+gGpF3L/8TB+/ATHYIBCelR2bHw4SUrB00FSTvI7Y8K0z3cz5tMP OZKg== X-Gm-Message-State: AOAM5335PsccJw3UL2irKNHASLiorH6y8HJemXTYLJGRMpUE/fsnNh2X dklswEe5Te/HwnPaOV+4UcAhc1xEIx+eNAgvtJcQ4Q== X-Received: by 2002:a5d:9da4:: with SMTP id ay36mr3685386iob.153.1631207742866; Thu, 09 Sep 2021 10:15:42 -0700 (PDT) MIME-Version: 1.0 References: <1631172276-82914-1-git-send-email-xiyuyang19@fudan.edu.cn> In-Reply-To: From: Daniel Latypov Date: Thu, 9 Sep 2021 10:15:31 -0700 Message-ID: Subject: Re: [PATCH v2] kunit: fix reference count leak in kfree_at_end To: Xiyu Yang Cc: Brendan Higgins , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, yuanxzhang@fudan.edu.cn, Xin Tan Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 9, 2021 at 9:59 AM Daniel Latypov wrote: > > On Thu, Sep 9, 2021 at 12:26 AM 'Xiyu Yang' via KUnit Development > wrote: > > > > The reference counting issue happens in the normal path of > > kfree_at_end(). When kunit_alloc_and_get_resource() is invoked, the > > function forgets to handle the returned resource object, whose refcount > > increased inside, causing a refcount leak. > > > > Fix this issue by calling kunit_alloc_resource() instead of > > kunit_alloc_and_get_resource(). > > > > Signed-off-by: Xiyu Yang > > Signed-off-by: Xin Tan > > Reviewed-by: Daniel Latypov > > Ah, thanks for finding and fixing this! > We really should have better documentation/otherwise make it clearer > that people shouldn't use the "_and_get" version. > > I went and added some pr_info() calls to verify that these were being > leaked before and they're fixed now. > > I copy-pasted this mistake into > https://lore.kernel.org/linux-kselftest/20210831171926.3832806-2-dlatypov@google.com/. > I'll send a v3 fix for that patch as well. Fixed that patch: https://lore.kernel.org/linux-kselftest/20210909171052.3192326-2-dlatypov@google.com/ I assume this patch and that one shouldn't have merge conflicts, so we don't need these to be applied in any specific order. > > > --- > > lib/kunit/executor_test.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/lib/kunit/executor_test.c b/lib/kunit/executor_test.c > > index cdbe54b16501..c2dcfb1f6e97 100644 > > --- a/lib/kunit/executor_test.c > > +++ b/lib/kunit/executor_test.c > > @@ -116,7 +116,7 @@ static void kfree_at_end(struct kunit *test, const void *to_free) > > /* kfree() handles NULL already, but avoid allocating a no-op cleanup. */ > > if (IS_ERR_OR_NULL(to_free)) > > return; > > - kunit_alloc_and_get_resource(test, NULL, kfree_res_free, GFP_KERNEL, > > + kunit_alloc_resource(test, NULL, kfree_res_free, GFP_KERNEL, > > (void *)to_free); > > } > > > > -- > > 2.7.4 > > > > -- > > You received this message because you are subscribed to the Google Groups "KUnit Development" group. > > To unsubscribe from this group and stop receiving emails from it, send an email to kunit-dev+unsubscribe@googlegroups.com. > > To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/1631172276-82914-1-git-send-email-xiyuyang19%40fudan.edu.cn.