linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Andrey Konovalov <andreyknvl@google.com>
Cc: Julien Thierry <julien.thierry@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Christopher Li <sparse@chrisli.org>,
	Tyler Baicar <tbaicar@codeaurora.org>,
	Will Deacon <will.deacon@arm.com>,
	Paul Lawrence <paullawrence@google.com>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	Yury Norov <ynorov@caviumnetworks.com>,
	Alexander Potapenko <glider@google.com>,
	Christoph Lameter <cl@linux.com>,
	Michael Weiser <michael.weiser@gmx.de>,
	kvmarm@lists.cs.columbia.edu, Kees Cook <keescook@google.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Jonathan Corbet <corbet@lwn.net>,
	linux-doc@vger.kernel.org, Mark Brand <markbrand@google.com>,
	kasan-dev@googlegroups.com, linux-sparse@vger.kernel.org,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	linux-arm-kernel@lists.infradead.org,
	David Rientjes <rientjes@google.com>,
	Andrey Ryabinin <aryabinin@virtuozzo.com>,
	Ramana
Subject: Re: [RFC PATCH v2 11/15] khwasan, mm: perform untagged pointers comparison in krealloc
Date: Sat, 24 Mar 2018 09:29:47 +0100	[thread overview]
Message-ID: <20180324082947.3isostkpsjraefqt@gmail.com> (raw)
In-Reply-To: <6eb08c160ae23eb890bd937ddf8346ba211df09f.1521828274.git.andreyknvl@google.com>


* Andrey Konovalov <andreyknvl@google.com> wrote:

> The krealloc function checks where the same buffer was reused or a new one
> allocated by comparing kernel pointers. KHWASAN changes memory tag on the
> krealloc'ed chunk of memory and therefore also changes the pointer tag of
> the returned pointer. Therefore we need to perform comparison on untagged
> (with tags reset) pointers to check whether it's the same memory region or
> not.
> 
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> ---
>  mm/slab_common.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/slab_common.c b/mm/slab_common.c
> index a33e61315ca6..5911f2194cf7 100644
> --- a/mm/slab_common.c
> +++ b/mm/slab_common.c
> @@ -1494,7 +1494,7 @@ void *krealloc(const void *p, size_t new_size, gfp_t flags)
>  	}
>  
>  	ret = __do_krealloc(p, new_size, flags);
> -	if (ret && p != ret)
> +	if (ret && khwasan_reset_tag(p) != khwasan_reset_tag(ret))
>  		kfree(p);

Small nit:

If 'reset' here means an all zeroes tag (upper byte) then khwasan_clear_tag() 
might be a slightly easier to read primitive?

Thanks,

	Ingo

       reply	other threads:[~2018-03-24  8:29 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1521828273.git.andreyknvl@google.com>
     [not found] ` <6eb08c160ae23eb890bd937ddf8346ba211df09f.1521828274.git.andreyknvl@google.com>
2018-03-24  8:29   ` Ingo Molnar [this message]
2018-03-27 12:20     ` [RFC PATCH v2 11/15] khwasan, mm: perform untagged pointers comparison in krealloc Andrey Konovalov
2018-03-27 20:01       ` Ingo Molnar
     [not found] ` <1fb0a050a84d49f5c3b2210337339412475d1688.1521828273.git.andreyknvl@google.com>
2018-03-24  8:43   ` [RFC PATCH v2 03/15] khwasan: add CONFIG_KASAN_CLASSIC and CONFIG_KASAN_TAGS Ingo Molnar
2018-03-27 16:23     ` Andrey Konovalov
2018-03-27 20:02       ` Ingo Molnar
     [not found] ` <774016f707e494da419a2d0d8a03409e6befcaf8.1521828274.git.andreyknvl@google.com>
     [not found]   ` <2ab69c9c-6e80-ea79-e72e-012753ed3db0@virtuozzo.com>
2018-04-03 14:43     ` [RFC PATCH v2 05/15] khwasan: initialize shadow to 0xff Andrey Konovalov
     [not found] ` <b79947167d09478d3f61d2ec8de37322c0e1fe92.1521828274.git.andreyknvl@google.com>
     [not found]   ` <a724eee6-7aff-df8b-de2b-8e9446e94623@virtuozzo.com>
2018-04-03 14:45     ` [RFC PATCH v2 08/15] khwasan: add tag related helper functions Andrey Konovalov
     [not found] ` <ba4a74ba1bc48dd66a3831143c3119d13c291fe3.1521828274.git.andreyknvl@google.com>
     [not found]   ` <805d1e85-2d3c-2327-6e6c-f14a56dc0b67@virtuozzo.com>
2018-04-03 14:59     ` [RFC PATCH v2 13/15] khwasan: add hooks implementation Andrey Konovalov
2018-04-04 12:39       ` Andrey Ryabinin
2018-04-04 17:00         ` Andrey Konovalov
2018-04-05 13:02           ` Andrey Ryabinin
2018-04-06 12:14             ` Andrey Konovalov
2018-04-06 12:27               ` Andrey Ryabinin
2018-04-10 16:07                 ` Andrey Konovalov
     [not found]                   ` <bfc3da50-66df-c6ed-ad6a-a285efe617ec@virtuozzo.com>
2018-04-12 16:45                     ` Andrey Konovalov
2018-04-12 17:20                       ` Andrey Ryabinin
2018-04-12 17:37                         ` Andrey Konovalov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180324082947.3isostkpsjraefqt@gmail.com \
    --to=mingo@kernel.org \
    --cc=andreyknvl@google.com \
    --cc=aryabinin@virtuozzo.com \
    --cc=catalin.marinas@arm.com \
    --cc=cl@linux.com \
    --cc=corbet@lwn.net \
    --cc=geert@linux-m68k.org \
    --cc=glider@google.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=julien.thierry@arm.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=keescook@google.com \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=markbrand@google.com \
    --cc=michael.weiser@gmx.de \
    --cc=paullawrence@google.com \
    --cc=rientjes@google.com \
    --cc=sparse@chrisli.org \
    --cc=tbaicar@codeaurora.org \
    --cc=will.deacon@arm.com \
    --cc=yamada.masahiro@socionext.com \
    --cc=ynorov@caviumnetworks.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).