LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] kasan: Zero initialize tag in __kasan_kmalloc
@ 2019-05-02 15:35 Nathan Chancellor
  2019-05-02 16:24 ` Andrey Konovalov
  2019-05-02 16:30 ` [PATCH v2] kasan: Initialize tag to 0xff " Nathan Chancellor
  0 siblings, 2 replies; 6+ messages in thread
From: Nathan Chancellor @ 2019-05-02 15:35 UTC (permalink / raw)
  To: Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov
  Cc: kasan-dev, linux-mm, linux-kernel, Nick Desaulniers,
	clang-built-linux, Nathan Chancellor

When building with -Wuninitialized and CONFIG_KASAN_SW_TAGS unset, Clang
warns:

mm/kasan/common.c:484:40: warning: variable 'tag' is uninitialized when
used here [-Wuninitialized]
        kasan_unpoison_shadow(set_tag(object, tag), size);
                                              ^~~

set_tag ignores tag in this configuration but clang doesn't realize it
at this point in its pipeline, as it points to arch_kasan_set_tag as
being the point where it is used, which will later be expanded to
(void *)(object) without a use of tag. Just zero initialize tag, as it
removes this warning and doesn't change the meaning of the code.

Link: https://github.com/ClangBuiltLinux/linux/issues/465
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
 mm/kasan/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/kasan/common.c b/mm/kasan/common.c
index 36afcf64e016..4c5af68f2a8b 100644
--- a/mm/kasan/common.c
+++ b/mm/kasan/common.c
@@ -464,7 +464,7 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object,
 {
 	unsigned long redzone_start;
 	unsigned long redzone_end;
-	u8 tag;
+	u8 tag = 0;
 
 	if (gfpflags_allow_blocking(flags))
 		quarantine_reduce();
-- 
2.21.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] kasan: Zero initialize tag in __kasan_kmalloc
  2019-05-02 15:35 [PATCH] kasan: Zero initialize tag in __kasan_kmalloc Nathan Chancellor
@ 2019-05-02 16:24 ` Andrey Konovalov
  2019-05-02 16:30 ` [PATCH v2] kasan: Initialize tag to 0xff " Nathan Chancellor
  1 sibling, 0 replies; 6+ messages in thread
From: Andrey Konovalov @ 2019-05-02 16:24 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov, kasan-dev,
	Linux Memory Management List, LKML, Nick Desaulniers,
	clang-built-linux

On Thu, May 2, 2019 at 5:36 PM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> When building with -Wuninitialized and CONFIG_KASAN_SW_TAGS unset, Clang
> warns:
>
> mm/kasan/common.c:484:40: warning: variable 'tag' is uninitialized when
> used here [-Wuninitialized]
>         kasan_unpoison_shadow(set_tag(object, tag), size);
>                                               ^~~
>
> set_tag ignores tag in this configuration but clang doesn't realize it
> at this point in its pipeline, as it points to arch_kasan_set_tag as
> being the point where it is used, which will later be expanded to
> (void *)(object) without a use of tag. Just zero initialize tag, as it
> removes this warning and doesn't change the meaning of the code.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/465
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> ---
>  mm/kasan/common.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/kasan/common.c b/mm/kasan/common.c
> index 36afcf64e016..4c5af68f2a8b 100644
> --- a/mm/kasan/common.c
> +++ b/mm/kasan/common.c
> @@ -464,7 +464,7 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object,
>  {
>         unsigned long redzone_start;
>         unsigned long redzone_end;
> -       u8 tag;
> +       u8 tag = 0;

Hi Nathan,

Could you change this value to 0xff? This doesn't make any difference,
since set_tag() ignores the tag anyway, but is less confusing, as all
the non-tagged kernel pointers have 0xff in the top byte.

Thanks!

>
>         if (gfpflags_allow_blocking(flags))
>                 quarantine_reduce();
> --
> 2.21.0
>
> --
> You received this message because you are subscribed to the Google Groups "kasan-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com.
> To post to this group, send email to kasan-dev@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20190502153538.2326-1-natechancellor%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] kasan: Initialize tag to 0xff in __kasan_kmalloc
  2019-05-02 15:35 [PATCH] kasan: Zero initialize tag in __kasan_kmalloc Nathan Chancellor
  2019-05-02 16:24 ` Andrey Konovalov
@ 2019-05-02 16:30 ` Nathan Chancellor
  2019-05-02 16:40   ` Andrey Konovalov
  2019-05-23  8:53   ` Andrey Ryabinin
  1 sibling, 2 replies; 6+ messages in thread
From: Nathan Chancellor @ 2019-05-02 16:30 UTC (permalink / raw)
  To: Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov
  Cc: kasan-dev, linux-mm, linux-kernel, Nick Desaulniers,
	clang-built-linux, Nathan Chancellor

When building with -Wuninitialized and CONFIG_KASAN_SW_TAGS unset, Clang
warns:

mm/kasan/common.c:484:40: warning: variable 'tag' is uninitialized when
used here [-Wuninitialized]
        kasan_unpoison_shadow(set_tag(object, tag), size);
                                              ^~~

set_tag ignores tag in this configuration but clang doesn't realize it
at this point in its pipeline, as it points to arch_kasan_set_tag as
being the point where it is used, which will later be expanded to
(void *)(object) without a use of tag. Initialize tag to 0xff, as it
removes this warning and doesn't change the meaning of the code.

Link: https://github.com/ClangBuiltLinux/linux/issues/465
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---

v1 -> v2:

* Initialize tag to 0xff at Andrey's request

 mm/kasan/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/kasan/common.c b/mm/kasan/common.c
index 36afcf64e016..242fdc01aaa9 100644
--- a/mm/kasan/common.c
+++ b/mm/kasan/common.c
@@ -464,7 +464,7 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object,
 {
 	unsigned long redzone_start;
 	unsigned long redzone_end;
-	u8 tag;
+	u8 tag = 0xff;
 
 	if (gfpflags_allow_blocking(flags))
 		quarantine_reduce();
-- 
2.21.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] kasan: Initialize tag to 0xff in __kasan_kmalloc
  2019-05-02 16:30 ` [PATCH v2] kasan: Initialize tag to 0xff " Nathan Chancellor
@ 2019-05-02 16:40   ` Andrey Konovalov
  2019-05-23  1:47     ` Nathan Chancellor
  2019-05-23  8:53   ` Andrey Ryabinin
  1 sibling, 1 reply; 6+ messages in thread
From: Andrey Konovalov @ 2019-05-02 16:40 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov, kasan-dev,
	Linux Memory Management List, LKML, Nick Desaulniers,
	clang-built-linux

On Thu, May 2, 2019 at 6:31 PM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> When building with -Wuninitialized and CONFIG_KASAN_SW_TAGS unset, Clang
> warns:
>
> mm/kasan/common.c:484:40: warning: variable 'tag' is uninitialized when
> used here [-Wuninitialized]
>         kasan_unpoison_shadow(set_tag(object, tag), size);
>                                               ^~~
>
> set_tag ignores tag in this configuration but clang doesn't realize it
> at this point in its pipeline, as it points to arch_kasan_set_tag as
> being the point where it is used, which will later be expanded to
> (void *)(object) without a use of tag. Initialize tag to 0xff, as it
> removes this warning and doesn't change the meaning of the code.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/465
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Reviewed-by: Andrey Konovalov <andreyknvl@google.com>

Thanks!

> ---
>
> v1 -> v2:
>
> * Initialize tag to 0xff at Andrey's request
>
>  mm/kasan/common.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/kasan/common.c b/mm/kasan/common.c
> index 36afcf64e016..242fdc01aaa9 100644
> --- a/mm/kasan/common.c
> +++ b/mm/kasan/common.c
> @@ -464,7 +464,7 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object,
>  {
>         unsigned long redzone_start;
>         unsigned long redzone_end;
> -       u8 tag;
> +       u8 tag = 0xff;
>
>         if (gfpflags_allow_blocking(flags))
>                 quarantine_reduce();
> --
> 2.21.0
>
> --
> You received this message because you are subscribed to the Google Groups "kasan-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com.
> To post to this group, send email to kasan-dev@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20190502163057.6603-1-natechancellor%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] kasan: Initialize tag to 0xff in __kasan_kmalloc
  2019-05-02 16:40   ` Andrey Konovalov
@ 2019-05-23  1:47     ` Nathan Chancellor
  0 siblings, 0 replies; 6+ messages in thread
From: Nathan Chancellor @ 2019-05-23  1:47 UTC (permalink / raw)
  To: Andrey Konovalov
  Cc: Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov, kasan-dev,
	Linux Memory Management List, LKML, Nick Desaulniers,
	clang-built-linux

On Thu, May 02, 2019 at 06:40:52PM +0200, Andrey Konovalov wrote:
> On Thu, May 2, 2019 at 6:31 PM Nathan Chancellor
> <natechancellor@gmail.com> wrote:
> >
> > When building with -Wuninitialized and CONFIG_KASAN_SW_TAGS unset, Clang
> > warns:
> >
> > mm/kasan/common.c:484:40: warning: variable 'tag' is uninitialized when
> > used here [-Wuninitialized]
> >         kasan_unpoison_shadow(set_tag(object, tag), size);
> >                                               ^~~
> >
> > set_tag ignores tag in this configuration but clang doesn't realize it
> > at this point in its pipeline, as it points to arch_kasan_set_tag as
> > being the point where it is used, which will later be expanded to
> > (void *)(object) without a use of tag. Initialize tag to 0xff, as it
> > removes this warning and doesn't change the meaning of the code.
> >
> > Link: https://github.com/ClangBuiltLinux/linux/issues/465
> > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> 
> Reviewed-by: Andrey Konovalov <andreyknvl@google.com>
> 
> Thanks!
> 

Thanks Andrey! Did anyone else have any other comments or can this be
picked up?

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] kasan: Initialize tag to 0xff in __kasan_kmalloc
  2019-05-02 16:30 ` [PATCH v2] kasan: Initialize tag to 0xff " Nathan Chancellor
  2019-05-02 16:40   ` Andrey Konovalov
@ 2019-05-23  8:53   ` Andrey Ryabinin
  1 sibling, 0 replies; 6+ messages in thread
From: Andrey Ryabinin @ 2019-05-23  8:53 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Nathan Chancellor, Alexander Potapenko, Dmitry Vyukov, kasan-dev,
	linux-mm, linux-kernel, Nick Desaulniers, clang-built-linux



On 5/2/19 7:30 PM, Nathan Chancellor wrote:
> When building with -Wuninitialized and CONFIG_KASAN_SW_TAGS unset, Clang
> warns:
> 
> mm/kasan/common.c:484:40: warning: variable 'tag' is uninitialized when
> used here [-Wuninitialized]
>         kasan_unpoison_shadow(set_tag(object, tag), size);
>                                               ^~~
> 
> set_tag ignores tag in this configuration but clang doesn't realize it
> at this point in its pipeline, as it points to arch_kasan_set_tag as
> being the point where it is used, which will later be expanded to
> (void *)(object) without a use of tag. Initialize tag to 0xff, as it
> removes this warning and doesn't change the meaning of the code.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/465
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Fixes: 7f94ffbc4c6a ("kasan: add hooks implementation for tag-based mode")
Cc: <stable@vger.kernel.org>
Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com>

> ---
> 
> v1 -> v2:
> 
> * Initialize tag to 0xff at Andrey's request
> 
>  mm/kasan/common.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/kasan/common.c b/mm/kasan/common.c
> index 36afcf64e016..242fdc01aaa9 100644
> --- a/mm/kasan/common.c
> +++ b/mm/kasan/common.c
> @@ -464,7 +464,7 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object,
>  {
>  	unsigned long redzone_start;
>  	unsigned long redzone_end;
> -	u8 tag;
> +	u8 tag = 0xff;
>  
>  	if (gfpflags_allow_blocking(flags))
>  		quarantine_reduce();
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-05-23  8:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-02 15:35 [PATCH] kasan: Zero initialize tag in __kasan_kmalloc Nathan Chancellor
2019-05-02 16:24 ` Andrey Konovalov
2019-05-02 16:30 ` [PATCH v2] kasan: Initialize tag to 0xff " Nathan Chancellor
2019-05-02 16:40   ` Andrey Konovalov
2019-05-23  1:47     ` Nathan Chancellor
2019-05-23  8:53   ` Andrey Ryabinin

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).