Skip to contentSkip to conversation

kasan: include the hashed pointer for an object's location

RFC In review Lyude Paul 2 participants 3 messages Oct 22, 2019

Subsystems (2)
lore
Share & tools
lore

Lyude Paul

author
#0 lore raw

RFC 1/1 kasan: include the hashed pointer for an object's location

The vast majority of the kernel that needs to print out pointers as a way to keep track of a specific object in the kernel for debugging purposes does so using hashed pointers, since these are "good enough". Ironically, the one place we don't do this is within kasan. While simply printing a hashed version of where an out of bounds memory access occurred isn't too useful, printing out the hashed address of the object in question usually is since that's the format most of the kernel is likely to be using in debugging output.

Of course this isn't perfect though-having the object's originating address doesn't help users at all that need to do things like printing the address of a struct which is embedded within another struct, but it's certainly better then not printing any hashed addresses. And users which need to handle less trivial cases like that can simply fall back to careful usage of %px.

Cc Sean Paul <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Andrey Ryabinin <[email protected]>
Cc Alexander Potapenko <[email protected]>
Cc Dmitry Vyukov <[email protected]>
---
 mm/kasan/report.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/kasan/report.c +3 -2
index 621782100eaa..0a5663fee1f7 100644
@@ -128,8 +128,9 @@ static void describe_object_addr(struct kmem_cache *cache, void *object,
 	int rel_bytes;
 
 	pr_err("The buggy address belongs to the object at %px\n"
-	       " which belongs to the cache %s of size %d\n",
-		object, cache->name, cache->object_size);
+	       " (aka %p) which belongs to the cache\n"
+	       " %s of size %d\n",
+	       object, object, cache->name, cache->object_size);
 
 	if (!addr)
 		return;
Signature · 1 line
2.21.0
reviewer
#1 lore raw
Quoted 33 lines · Lyude Paul

The vast majority of the kernel that needs to print out pointers as a way to keep track of a specific object in the kernel for debugging purposes does so using hashed pointers, since these are "good enough". Ironically, the one place we don't do this is within kasan. While simply printing a hashed version of where an out of bounds memory access occurred isn't too useful, printing out the hashed address of the object in question usually is since that's the format most of the kernel is likely to be using in debugging output.

Of course this isn't perfect though-having the object's originating address doesn't help users at all that need to do things like printing the address of a struct which is embedded within another struct, but it's certainly better then not printing any hashed addresses. And users which need to handle less trivial cases like that can simply fall back to careful usage of %px.

Cc Sean Paul <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Andrey Ryabinin <[email protected]>
Cc Alexander Potapenko <[email protected]>
Cc Dmitry Vyukov <[email protected]>
---
 mm/kasan/report.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/kasan/report.c +0 -0
index 621782100eaa..0a5663fee1f7 100644

mm/kasan/report.c static void describe_object_addr(struct kmem_cache *cache, void *object, · line 133

Quoted 8 lines
mm/kasan/report.c +3 -2
@@ -128,8 +128,9 @@ static void describe_object_addr(struct kmem_cache *cache, void *object,
        int rel_bytes;
 
        pr_err("The buggy address belongs to the object at %px\n"
-              " which belongs to the cache %s of size %d\n",
-               object, cache->name, cache->object_size);
+              " (aka %p) which belongs to the cache\n"
+              " %s of size %d\n",
+              object, object, cache->name, cache->object_size);

Hi Lyude,

This only prints hashed address for heap objects, but print_address_description() has 4 different code paths for different types of addresses (heap, global, stack, page). Plus there is a case for address without shadow.
Should we print the hashed address at least for all cases in print_address_description()?

Quoted 5 lines
mm/kasan/report.c +0 -1
        if (!addr)
                return;
--

2.21.0

author
#2 lore raw
Quoted 45 lines · Dmitry Vyukov
Quoted 32 lines · Lyude Paul

The vast majority of the kernel that needs to print out pointers as a way to keep track of a specific object in the kernel for debugging purposes does so using hashed pointers, since these are "good enough". Ironically, the one place we don't do this is within kasan. While simply printing a hashed version of where an out of bounds memory access occurred isn't too useful, printing out the hashed address of the object in question usually is since that's the format most of the kernel is likely to be using in debugging output.

Of course this isn't perfect though-having the object's originating address doesn't help users at all that need to do things like printing the address of a struct which is embedded within another struct, but it's certainly better then not printing any hashed addresses. And users which need to handle less trivial cases like that can simply fall back to careful usage of %px.

Cc Sean Paul <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Andrey Ryabinin <[email protected]>
Cc Alexander Potapenko <[email protected]>
Cc Dmitry Vyukov <[email protected]>
---
 mm/kasan/report.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/kasan/report.c +0 -0
index 621782100eaa..0a5663fee1f7 100644

mm/kasan/report.c static void describe_object_addr(struct kmem_cache · line 134

Quoted 9 lines
mm/kasan/report.c +3 -2
@@ -128,8 +128,9 @@ static void describe_object_addr(struct kmem_cache
 *cache, void *object,
        int rel_bytes;
 
        pr_err("The buggy address belongs to the object at %px\n"
-              " which belongs to the cache %s of size %d\n",
-               object, cache->name, cache->object_size);
+              " (aka %p) which belongs to the cache\n"
+              " %s of size %d\n",
+              object, object, cache->name, cache->object_size);

Hi Lyude,

Quoted 6 lines

This only prints hashed address for heap objects, but print_address_description() has 4 different code paths for different types of addresses (heap, global, stack, page). Plus there is a case for address without shadow.
Should we print the hashed address at least for all cases in print_address_description()?

Yep-this is probably a good idea. Will send a respin in a little bit

Quoted 7 lines
Quoted 7 lines
mm/kasan/report.c +0 -1
        if (!addr)
                return;
--

2.21.0

Signature · 2 lines
Cheers,
	Lyude Paul