diff mbox series

kasan: fix build for CONFIG_KASAN_HW_TAGS

Message ID 20210708144411.25467-1-mark.rutland@arm.com (mailing list archive)
State New, archived
Headers show
Series kasan: fix build for CONFIG_KASAN_HW_TAGS | expand

Commit Message

Mark Rutland July 8, 2021, 2:44 p.m. UTC
When CONFIG_KASAN_HW_TAGS is selected, <linux/kasan.h> uses _RET_IP_,
but doesn't explicitly include <linux/kernel.h> where this is defined.

We used to get this via a transitive include, but since commit:

  f39650de687e3576 ("kernel.h: split out panic and oops helpers")

... this is no longer the case, and so we get a build failure:

|   CC      arch/arm64/mm/kasan_init.o
| In file included from arch/arm64/mm/kasan_init.c:10:
| ./include/linux/kasan.h: In function 'kasan_slab_free':
| ./include/linux/kasan.h:211:39: error: '_RET_IP_' undeclared (first use in this function)
|   211 |   return __kasan_slab_free(s, object, _RET_IP_, init);
|       |                                       ^~~~~~~~
| ./include/linux/kasan.h:211:39: note: each undeclared identifier is reported only once for each function it appears in
| ./include/linux/kasan.h: In function 'kasan_kfree_large':
| ./include/linux/kasan.h:219:28: error: '_RET_IP_' undeclared (first use in this function)
|   219 |   __kasan_kfree_large(ptr, _RET_IP_);
|       |                            ^~~~~~~~
| ./include/linux/kasan.h: In function 'kasan_slab_free_mempool':
| ./include/linux/kasan.h:226:34: error: '_RET_IP_' undeclared (first use in this function)
|   226 |   __kasan_slab_free_mempool(ptr, _RET_IP_);
|       |                                  ^~~~~~~~
| ./include/linux/kasan.h: In function 'kasan_check_byte':
| ./include/linux/kasan.h:277:35: error: '_RET_IP_' undeclared (first use in this function)
|   277 |   return __kasan_check_byte(addr, _RET_IP_);
|       |                                   ^~~~~~~~

Fix this by including <linux/kernel.h> explicitly.

Fixes: 6028bf777417 ("kernel.h: split out panic and oops helpers")
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Will Deacon <will@kernel.org>
---
 include/linux/kasan.h | 1 +
 1 file changed, 1 insertion(+)

As a heads-up, there are some unrelated runtime issues with
CONFIG_KASAN_HW_TAGS and the recent arm64 string routines rework, which
I'm looking into now. If you boot-test with this applied, you should
expect to see those.

Andrew, I assume you'd be the one to pick this up?

Thanks,
Mark.

Comments

Andrey Konovalov July 10, 2021, 7:16 p.m. UTC | #1
On Thu, Jul 8, 2021 at 4:44 PM Mark Rutland <mark.rutland@arm.com> wrote:
>
> When CONFIG_KASAN_HW_TAGS is selected, <linux/kasan.h> uses _RET_IP_,
> but doesn't explicitly include <linux/kernel.h> where this is defined.
>
> We used to get this via a transitive include, but since commit:
>
>   f39650de687e3576 ("kernel.h: split out panic and oops helpers")
>
> ... this is no longer the case, and so we get a build failure:
>
> |   CC      arch/arm64/mm/kasan_init.o
> | In file included from arch/arm64/mm/kasan_init.c:10:
> | ./include/linux/kasan.h: In function 'kasan_slab_free':
> | ./include/linux/kasan.h:211:39: error: '_RET_IP_' undeclared (first use in this function)
> |   211 |   return __kasan_slab_free(s, object, _RET_IP_, init);
> |       |                                       ^~~~~~~~
> | ./include/linux/kasan.h:211:39: note: each undeclared identifier is reported only once for each function it appears in
> | ./include/linux/kasan.h: In function 'kasan_kfree_large':
> | ./include/linux/kasan.h:219:28: error: '_RET_IP_' undeclared (first use in this function)
> |   219 |   __kasan_kfree_large(ptr, _RET_IP_);
> |       |                            ^~~~~~~~
> | ./include/linux/kasan.h: In function 'kasan_slab_free_mempool':
> | ./include/linux/kasan.h:226:34: error: '_RET_IP_' undeclared (first use in this function)
> |   226 |   __kasan_slab_free_mempool(ptr, _RET_IP_);
> |       |                                  ^~~~~~~~
> | ./include/linux/kasan.h: In function 'kasan_check_byte':
> | ./include/linux/kasan.h:277:35: error: '_RET_IP_' undeclared (first use in this function)
> |   277 |   return __kasan_check_byte(addr, _RET_IP_);
> |       |                                   ^~~~~~~~
>
> Fix this by including <linux/kernel.h> explicitly.

Hi Mark,

Marco already sent a fix for this. It should be in the mm tree.
(Although the link to it in the Andrew's notification email doesn't
work. But they rarely do :)

> As a heads-up, there are some unrelated runtime issues with
> CONFIG_KASAN_HW_TAGS and the recent arm64 string routines rework, which
> I'm looking into now. If you boot-test with this applied, you should
> expect to see those.

+Sam, +Robin

Looks like the new strlen routine is making accesses past the allocated buffer.

The guilty commit is 325a1de81287 ("arm64: Import updated version of
Cortex Strings' strlen").

Thanks!
Mark Rutland July 12, 2021, 8:37 a.m. UTC | #2
On Sat, Jul 10, 2021 at 09:16:14PM +0200, Andrey Konovalov wrote:
> On Thu, Jul 8, 2021 at 4:44 PM Mark Rutland <mark.rutland@arm.com> wrote:
> >
> > When CONFIG_KASAN_HW_TAGS is selected, <linux/kasan.h> uses _RET_IP_,
> > but doesn't explicitly include <linux/kernel.h> where this is defined.
> >
> > We used to get this via a transitive include, but since commit:
> >
> >   f39650de687e3576 ("kernel.h: split out panic and oops helpers")
> >
> > ... this is no longer the case, and so we get a build failure:
> >
> > |   CC      arch/arm64/mm/kasan_init.o
> > | In file included from arch/arm64/mm/kasan_init.c:10:
> > | ./include/linux/kasan.h: In function 'kasan_slab_free':
> > | ./include/linux/kasan.h:211:39: error: '_RET_IP_' undeclared (first use in this function)
> > |   211 |   return __kasan_slab_free(s, object, _RET_IP_, init);
> > |       |                                       ^~~~~~~~
> > | ./include/linux/kasan.h:211:39: note: each undeclared identifier is reported only once for each function it appears in
> > | ./include/linux/kasan.h: In function 'kasan_kfree_large':
> > | ./include/linux/kasan.h:219:28: error: '_RET_IP_' undeclared (first use in this function)
> > |   219 |   __kasan_kfree_large(ptr, _RET_IP_);
> > |       |                            ^~~~~~~~
> > | ./include/linux/kasan.h: In function 'kasan_slab_free_mempool':
> > | ./include/linux/kasan.h:226:34: error: '_RET_IP_' undeclared (first use in this function)
> > |   226 |   __kasan_slab_free_mempool(ptr, _RET_IP_);
> > |       |                                  ^~~~~~~~
> > | ./include/linux/kasan.h: In function 'kasan_check_byte':
> > | ./include/linux/kasan.h:277:35: error: '_RET_IP_' undeclared (first use in this function)
> > |   277 |   return __kasan_check_byte(addr, _RET_IP_);
> > |       |                                   ^~~~~~~~
> >
> > Fix this by including <linux/kernel.h> explicitly.
> 
> Hi Mark,
> 
> Marco already sent a fix for this. It should be in the mm tree.
> (Although the link to it in the Andrew's notification email doesn't
> work. But they rarely do :)
> 
> > As a heads-up, there are some unrelated runtime issues with
> > CONFIG_KASAN_HW_TAGS and the recent arm64 string routines rework, which
> > I'm looking into now. If you boot-test with this applied, you should
> > expect to see those.
> 
> +Sam, +Robin
> 
> Looks like the new strlen routine is making accesses past the allocated buffer.
> 
> The guilty commit is 325a1de81287 ("arm64: Import updated version of
> Cortex Strings' strlen").

FWIW, I already have a fix for this, I'm just cleaning it up and will
post shortly.

The issue is that the new strlen() will make unaligned 16-byte accesses
within a naturally-aligned 4096-byte window and over-read by up to 15
bytes; we can fiddle with its alignment fixup to always align to 16
bytes when MTE is in use so any over-read is within the same MTE granule
as the final byte of the string.

I've checked the other routines, and AFAICT they never make accesses
which staddle a 16-byte boundary.

Thanks,
Mark.
Will Deacon July 12, 2021, 9:58 a.m. UTC | #3
On Sat, Jul 10, 2021 at 09:16:14PM +0200, Andrey Konovalov wrote:
> On Thu, Jul 8, 2021 at 4:44 PM Mark Rutland <mark.rutland@arm.com> wrote:
> >
> > When CONFIG_KASAN_HW_TAGS is selected, <linux/kasan.h> uses _RET_IP_,
> > but doesn't explicitly include <linux/kernel.h> where this is defined.
> >
> > We used to get this via a transitive include, but since commit:
> >
> >   f39650de687e3576 ("kernel.h: split out panic and oops helpers")
> >
> > ... this is no longer the case, and so we get a build failure:
> >
> > |   CC      arch/arm64/mm/kasan_init.o
> > | In file included from arch/arm64/mm/kasan_init.c:10:
> > | ./include/linux/kasan.h: In function 'kasan_slab_free':
> > | ./include/linux/kasan.h:211:39: error: '_RET_IP_' undeclared (first use in this function)
> > |   211 |   return __kasan_slab_free(s, object, _RET_IP_, init);
> > |       |                                       ^~~~~~~~
> > | ./include/linux/kasan.h:211:39: note: each undeclared identifier is reported only once for each function it appears in
> > | ./include/linux/kasan.h: In function 'kasan_kfree_large':
> > | ./include/linux/kasan.h:219:28: error: '_RET_IP_' undeclared (first use in this function)
> > |   219 |   __kasan_kfree_large(ptr, _RET_IP_);
> > |       |                            ^~~~~~~~
> > | ./include/linux/kasan.h: In function 'kasan_slab_free_mempool':
> > | ./include/linux/kasan.h:226:34: error: '_RET_IP_' undeclared (first use in this function)
> > |   226 |   __kasan_slab_free_mempool(ptr, _RET_IP_);
> > |       |                                  ^~~~~~~~
> > | ./include/linux/kasan.h: In function 'kasan_check_byte':
> > | ./include/linux/kasan.h:277:35: error: '_RET_IP_' undeclared (first use in this function)
> > |   277 |   return __kasan_check_byte(addr, _RET_IP_);
> > |       |                                   ^~~~~~~~
> >
> > Fix this by including <linux/kernel.h> explicitly.
> 
> Hi Mark,
> 
> Marco already sent a fix for this. It should be in the mm tree.
> (Although the link to it in the Andrew's notification email doesn't
> work. But they rarely do :)

Do you have a link to the patch? I couldn't spot it in linux-next.

Thanks,

Will
Marco Elver July 12, 2021, 10:03 a.m. UTC | #4
On Mon, 12 Jul 2021 at 11:58, Will Deacon <will@kernel.org> wrote:
> On Sat, Jul 10, 2021 at 09:16:14PM +0200, Andrey Konovalov wrote:
> > On Thu, Jul 8, 2021 at 4:44 PM Mark Rutland <mark.rutland@arm.com> wrote:
> > >
> > > When CONFIG_KASAN_HW_TAGS is selected, <linux/kasan.h> uses _RET_IP_,
> > > but doesn't explicitly include <linux/kernel.h> where this is defined.
> > >
> > > We used to get this via a transitive include, but since commit:
> > >
> > >   f39650de687e3576 ("kernel.h: split out panic and oops helpers")
> > >
> > > ... this is no longer the case, and so we get a build failure:
> > >
> > > |   CC      arch/arm64/mm/kasan_init.o
> > > | In file included from arch/arm64/mm/kasan_init.c:10:
> > > | ./include/linux/kasan.h: In function 'kasan_slab_free':
> > > | ./include/linux/kasan.h:211:39: error: '_RET_IP_' undeclared (first use in this function)
> > > |   211 |   return __kasan_slab_free(s, object, _RET_IP_, init);
> > > |       |                                       ^~~~~~~~
> > > | ./include/linux/kasan.h:211:39: note: each undeclared identifier is reported only once for each function it appears in
> > > | ./include/linux/kasan.h: In function 'kasan_kfree_large':
> > > | ./include/linux/kasan.h:219:28: error: '_RET_IP_' undeclared (first use in this function)
> > > |   219 |   __kasan_kfree_large(ptr, _RET_IP_);
> > > |       |                            ^~~~~~~~
> > > | ./include/linux/kasan.h: In function 'kasan_slab_free_mempool':
> > > | ./include/linux/kasan.h:226:34: error: '_RET_IP_' undeclared (first use in this function)
> > > |   226 |   __kasan_slab_free_mempool(ptr, _RET_IP_);
> > > |       |                                  ^~~~~~~~
> > > | ./include/linux/kasan.h: In function 'kasan_check_byte':
> > > | ./include/linux/kasan.h:277:35: error: '_RET_IP_' undeclared (first use in this function)
> > > |   277 |   return __kasan_check_byte(addr, _RET_IP_);
> > > |       |                                   ^~~~~~~~
> > >
> > > Fix this by including <linux/kernel.h> explicitly.
> >
> > Hi Mark,
> >
> > Marco already sent a fix for this. It should be in the mm tree.
> > (Although the link to it in the Andrew's notification email doesn't
> > work. But they rarely do :)
>
> Do you have a link to the patch? I couldn't spot it in linux-next.

https://lkml.kernel.org/r/20210705072716.2125074-1-elver@google.com
( https://lore.kernel.org/mm-commits/20210706204723.O1wZ2%25akpm@linux-foundation.org/
)

Looks like latest -mm is not yet reflected in -next.
diff mbox series

Patch

diff --git a/include/linux/kasan.h b/include/linux/kasan.h
index 5310e217bd74..dd874a1ee862 100644
--- a/include/linux/kasan.h
+++ b/include/linux/kasan.h
@@ -3,6 +3,7 @@ 
 #define _LINUX_KASAN_H
 
 #include <linux/bug.h>
+#include <linux/kernel.h>
 #include <linux/static_key.h>
 #include <linux/types.h>