[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <bee16e8c-2ec9-7a17-1f5d-82cc4891603b@redhat.com>
Date: Wed, 17 Jun 2020 09:09:24 +0200
From: David Hildenbrand <david@...hat.com>
To: William Kucharski <william.kucharski@...cle.com>,
linux-mm@...ck.org, linux-kernel@...r.kernel.org
Cc: Christoph Lameter <cl@...ux.com>,
Pekka Enberg <penberg@...nel.org>,
David Rientjes <rientjes@...gle.com>,
Joonsoo Kim <iamjoonsoo.kim@....com>,
Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH] mm: ksize() should silently accept a NULL pointer
On 17.06.20 00:54, William Kucharski wrote:
> Other mm routines such as kfree() and kzfree() silently do the right
> thing if passed a NULL pointer, so ksize() should do the same.
>
> Signed-off-by: William Kucharski <william.kucharski@...cle.com>
> ---
> mm/slab_common.c | 14 +++++---------
> 1 file changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/mm/slab_common.c b/mm/slab_common.c
> index 9e72ba224175..2bff01ad94d8 100644
> --- a/mm/slab_common.c
> +++ b/mm/slab_common.c
> @@ -1660,10 +1660,9 @@ static __always_inline void *__do_krealloc(const void *p, size_t new_size,
> gfp_t flags)
> {
> void *ret;
> - size_t ks = 0;
> + size_t ks;
>
> - if (p)
> - ks = ksize(p);
> + ks = ksize(p);
>
> if (ks >= new_size) {
> p = kasan_krealloc((void *)p, new_size, flags);
> @@ -1723,10 +1722,9 @@ void kzfree(const void *p)
> size_t ks;
> void *mem = (void *)p;
>
> - if (unlikely(ZERO_OR_NULL_PTR(mem)))
> - return;
> ks = ksize(mem);
> - memset(mem, 0, ks);
> + if (ks)
> + memset(mem, 0, ks);
> kfree(mem);
> }
> EXPORT_SYMBOL(kzfree);
> @@ -1749,8 +1747,6 @@ size_t ksize(const void *objp)
> {
> size_t size;
>
> - if (WARN_ON_ONCE(!objp))
> - return 0;
> /*
> * We need to check that the pointed to object is valid, and only then
> * unpoison the shadow memory below. We use __kasan_check_read(), to
> @@ -1764,7 +1760,7 @@ size_t ksize(const void *objp)
> * We want to perform the check before __ksize(), to avoid potentially
> * crashing in __ksize() due to accessing invalid metadata.
> */
> - if (unlikely(objp == ZERO_SIZE_PTR) || !__kasan_check_read(objp, 1))
> + if (unlikely(ZERO_OR_NULL_PTR(objp)) || !__kasan_check_read(objp, 1))
> return 0;
>
> size = __ksize(objp);
>
Reviewed-by: David Hildenbrand <david@...hat.com>
--
Thanks,
David / dhildenb
Powered by blists - more mailing lists