lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 9 Sep 2021 09:59:56 -0700
From:   Daniel Latypov <dlatypov@...gle.com>
To:     Xiyu Yang <xiyuyang19@...an.edu.cn>
Cc:     Brendan Higgins <brendanhiggins@...gle.com>,
        linux-kselftest@...r.kernel.org, kunit-dev@...glegroups.com,
        linux-kernel@...r.kernel.org, yuanxzhang@...an.edu.cn,
        Xin Tan <tanxin.ctf@...il.com>
Subject: Re: [PATCH v2] kunit: fix reference count leak in kfree_at_end

On Thu, Sep 9, 2021 at 12:26 AM 'Xiyu Yang' via KUnit Development
<kunit-dev@...glegroups.com> 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 <xiyuyang19@...an.edu.cn>
> Signed-off-by: Xin Tan <tanxin.ctf@...il.com>

Reviewed-by: Daniel Latypov <dlatypov@...gle.com>

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.

> ---
>  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@...glegroups.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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ