2021-02-11 13:19:22

by Vincenzo Frascino

[permalink] [raw]
Subject: [PATCH] arm64: Fix warning in mte_get_random_tag()

The simplification of mte_get_random_tag() caused the introduction of the
warning below:

In file included from arch/arm64/include/asm/kasan.h:9,
from include/linux/kasan.h:16,
from mm/kasan/common.c:14:
mm/kasan/common.c: In function ‘mte_get_random_tag’:
arch/arm64/include/asm/mte-kasan.h:45:9: warning: ‘addr’ is used
uninitialized [-Wuninitialized]
45 | asm(__MTE_PREAMBLE "irg %0, %0"
|

Fix the warning initializing the address to NULL.

Note: mte_get_random_tag() returns a tag and it never dereferences the address,
hence 'addr' can be safely initialized to NULL.

Fixes: c8f8de4c0887 ("arm64: kasan: simplify and inline MTE functions")
Cc: Catalin Marinas <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Andrey Konovalov <[email protected]>
Cc: Andrew Morton <[email protected]>
Signed-off-by: Vincenzo Frascino <[email protected]>
---

This patch is based on linux-next/akpm

arch/arm64/include/asm/mte-kasan.h | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/mte-kasan.h b/arch/arm64/include/asm/mte-kasan.h
index 3d58489228c0..b2850b750726 100644
--- a/arch/arm64/include/asm/mte-kasan.h
+++ b/arch/arm64/include/asm/mte-kasan.h
@@ -40,7 +40,12 @@ static inline u8 mte_get_mem_tag(void *addr)
/* Generate a random tag. */
static inline u8 mte_get_random_tag(void)
{
- void *addr;
+ /*
+ * mte_get_random_tag() returns a tag and it
+ * never dereferences the address, hence addr
+ * can be safely initialized to NULL.
+ */
+ void *addr = NULL;

asm(__MTE_PREAMBLE "irg %0, %0"
: "+r" (addr));
--
2.30.0


2021-02-11 13:50:46

by Ard Biesheuvel

[permalink] [raw]
Subject: Re: [PATCH] arm64: Fix warning in mte_get_random_tag()

On Thu, 11 Feb 2021 at 13:57, Vincenzo Frascino
<[email protected]> wrote:
>
> The simplification of mte_get_random_tag() caused the introduction of the
> warning below:
>
> In file included from arch/arm64/include/asm/kasan.h:9,
> from include/linux/kasan.h:16,
> from mm/kasan/common.c:14:
> mm/kasan/common.c: In function ‘mte_get_random_tag’:
> arch/arm64/include/asm/mte-kasan.h:45:9: warning: ‘addr’ is used
> uninitialized [-Wuninitialized]
> 45 | asm(__MTE_PREAMBLE "irg %0, %0"
> |
>
> Fix the warning initializing the address to NULL.
>
> Note: mte_get_random_tag() returns a tag and it never dereferences the address,
> hence 'addr' can be safely initialized to NULL.
>
> Fixes: c8f8de4c0887 ("arm64: kasan: simplify and inline MTE functions")
> Cc: Catalin Marinas <[email protected]>
> Cc: Will Deacon <[email protected]>
> Cc: Andrey Konovalov <[email protected]>
> Cc: Andrew Morton <[email protected]>
> Signed-off-by: Vincenzo Frascino <[email protected]>
> ---
>
> This patch is based on linux-next/akpm
>
> arch/arm64/include/asm/mte-kasan.h | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm64/include/asm/mte-kasan.h b/arch/arm64/include/asm/mte-kasan.h
> index 3d58489228c0..b2850b750726 100644
> --- a/arch/arm64/include/asm/mte-kasan.h
> +++ b/arch/arm64/include/asm/mte-kasan.h
> @@ -40,7 +40,12 @@ static inline u8 mte_get_mem_tag(void *addr)
> /* Generate a random tag. */
> static inline u8 mte_get_random_tag(void)
> {
> - void *addr;
> + /*
> + * mte_get_random_tag() returns a tag and it
> + * never dereferences the address, hence addr
> + * can be safely initialized to NULL.
> + */
> + void *addr = NULL;
>
> asm(__MTE_PREAMBLE "irg %0, %0"
> : "+r" (addr));
> --
> 2.30.0
>

Might it be better to simply change the asm constraint to "=r" ?

2021-02-11 15:50:59

by Vincenzo Frascino

[permalink] [raw]
Subject: Re: [PATCH] arm64: Fix warning in mte_get_random_tag()



On 2/11/21 1:35 PM, Ard Biesheuvel wrote:
> On Thu, 11 Feb 2021 at 13:57, Vincenzo Frascino
> <[email protected]> wrote:
>>
>> The simplification of mte_get_random_tag() caused the introduction of the
>> warning below:
>>
>> In file included from arch/arm64/include/asm/kasan.h:9,
>> from include/linux/kasan.h:16,
>> from mm/kasan/common.c:14:
>> mm/kasan/common.c: In function ‘mte_get_random_tag’:
>> arch/arm64/include/asm/mte-kasan.h:45:9: warning: ‘addr’ is used
>> uninitialized [-Wuninitialized]
>> 45 | asm(__MTE_PREAMBLE "irg %0, %0"
>> |
>>
>> Fix the warning initializing the address to NULL.
>>
>> Note: mte_get_random_tag() returns a tag and it never dereferences the address,
>> hence 'addr' can be safely initialized to NULL.
>>
>> Fixes: c8f8de4c0887 ("arm64: kasan: simplify and inline MTE functions")
>> Cc: Catalin Marinas <[email protected]>
>> Cc: Will Deacon <[email protected]>
>> Cc: Andrey Konovalov <[email protected]>
>> Cc: Andrew Morton <[email protected]>
>> Signed-off-by: Vincenzo Frascino <[email protected]>
>> ---
>>
>> This patch is based on linux-next/akpm
>>
>> arch/arm64/include/asm/mte-kasan.h | 7 ++++++-
>> 1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/arm64/include/asm/mte-kasan.h b/arch/arm64/include/asm/mte-kasan.h
>> index 3d58489228c0..b2850b750726 100644
>> --- a/arch/arm64/include/asm/mte-kasan.h
>> +++ b/arch/arm64/include/asm/mte-kasan.h
>> @@ -40,7 +40,12 @@ static inline u8 mte_get_mem_tag(void *addr)
>> /* Generate a random tag. */
>> static inline u8 mte_get_random_tag(void)
>> {
>> - void *addr;
>> + /*
>> + * mte_get_random_tag() returns a tag and it
>> + * never dereferences the address, hence addr
>> + * can be safely initialized to NULL.
>> + */
>> + void *addr = NULL;
>>
>> asm(__MTE_PREAMBLE "irg %0, %0"
>> : "+r" (addr));
>> --
>> 2.30.0
>>
>
> Might it be better to simply change the asm constraint to "=r" ?
>

Indeed, did not notice the "+r". I will change it accordingly and post v2.

Thanks!

--
Regards,
Vincenzo