public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 6.6] sched/task_stack: fix object_is_on_stack() for KASAN tagged pointers
@ 2024-12-24  8:10 Wenshan Lan
  2024-12-26  1:21 ` Sasha Levin
  0 siblings, 1 reply; 2+ messages in thread
From: Wenshan Lan @ 2024-12-24  8:10 UTC (permalink / raw)
  To: stable, qun-wei.lin

From: Qun-Wei Lin <qun-wei.lin@mediatek.com>

[ Upstream commit fd7b4f9f46d46acbc7af3a439bb0d869efdc5c58 ]

When CONFIG_KASAN_SW_TAGS and CONFIG_KASAN_STACK are enabled, the
object_is_on_stack() function may produce incorrect results due to the
presence of tags in the obj pointer, while the stack pointer does not have
tags.  This discrepancy can lead to incorrect stack object detection and
subsequently trigger warnings if CONFIG_DEBUG_OBJECTS is also enabled.

Example of the warning:

ODEBUG: object 3eff800082ea7bb0 is NOT on stack ffff800082ea0000, but annotated.
------------[ cut here ]------------
WARNING: CPU: 0 PID: 1 at lib/debugobjects.c:557 __debug_object_init+0x330/0x364
Modules linked in:
CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.12.0-rc5 #4
Hardware name: linux,dummy-virt (DT)
pstate: 600000c5 (nZCv daIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : __debug_object_init+0x330/0x364
lr : __debug_object_init+0x330/0x364
sp : ffff800082ea7b40
x29: ffff800082ea7b40 x28: 98ff0000c0164518 x27: 98ff0000c0164534
x26: ffff800082d93ec8 x25: 0000000000000001 x24: 1cff0000c00172a0
x23: 0000000000000000 x22: ffff800082d93ed0 x21: ffff800081a24418
x20: 3eff800082ea7bb0 x19: efff800000000000 x18: 0000000000000000
x17: 00000000000000ff x16: 0000000000000047 x15: 206b63617473206e
x14: 0000000000000018 x13: ffff800082ea7780 x12: 0ffff800082ea78e
x11: 0ffff800082ea790 x10: 0ffff800082ea79d x9 : 34d77febe173e800
x8 : 34d77febe173e800 x7 : 0000000000000001 x6 : 0000000000000001
x5 : feff800082ea74b8 x4 : ffff800082870a90 x3 : ffff80008018d3c4
x2 : 0000000000000001 x1 : ffff800082858810 x0 : 0000000000000050
Call trace:
 __debug_object_init+0x330/0x364
 debug_object_init_on_stack+0x30/0x3c
 schedule_hrtimeout_range_clock+0xac/0x26c
 schedule_hrtimeout+0x1c/0x30
 wait_task_inactive+0x1d4/0x25c
 kthread_bind_mask+0x28/0x98
 init_rescuer+0x1e8/0x280
 workqueue_init+0x1a0/0x3cc
 kernel_init_freeable+0x118/0x200
 kernel_init+0x28/0x1f0
 ret_from_fork+0x10/0x20
---[ end trace 0000000000000000 ]---
ODEBUG: object 3eff800082ea7bb0 is NOT on stack ffff800082ea0000, but annotated.
------------[ cut here ]------------

Link: https://lkml.kernel.org/r/20241113042544.19095-1-qun-wei.lin@mediatek.com
Signed-off-by: Qun-Wei Lin <qun-wei.lin@mediatek.com>
Cc: Andrew Yang <andrew.yang@mediatek.com>
Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Cc: Casper Li <casper.li@mediatek.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Chinwen Chang <chinwen.chang@mediatek.com>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ Resolve line conflicts ]
Signed-off-by: Wenshan Lan <jetlan9@163.com>
---
 include/linux/sched/task_stack.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/sched/task_stack.h b/include/linux/sched/task_stack.h
index f158b025c175..d2117e1c8fa5 100644
--- a/include/linux/sched/task_stack.h
+++ b/include/linux/sched/task_stack.h
@@ -8,6 +8,7 @@
 
 #include <linux/sched.h>
 #include <linux/magic.h>
+#include <linux/kasan.h>
 
 #ifdef CONFIG_THREAD_INFO_IN_TASK
 
@@ -88,6 +89,7 @@ static inline int object_is_on_stack(const void *obj)
 {
 	void *stack = task_stack_page(current);
 
+	obj = kasan_reset_tag(obj);
 	return (obj >= stack) && (obj < (stack + THREAD_SIZE));
 }
 
-- 
2.43.0


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

* Re: [PATCH 6.6] sched/task_stack: fix object_is_on_stack() for KASAN tagged pointers
  2024-12-24  8:10 [PATCH 6.6] sched/task_stack: fix object_is_on_stack() for KASAN tagged pointers Wenshan Lan
@ 2024-12-26  1:21 ` Sasha Levin
  0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2024-12-26  1:21 UTC (permalink / raw)
  To: stable; +Cc: Wenshan Lan, Sasha Levin

[ Sasha's backport helper bot ]

Hi,

The upstream commit SHA1 provided is correct: fd7b4f9f46d46acbc7af3a439bb0d869efdc5c58

WARNING: Author mismatch between patch and upstream commit:
Backport author: Wenshan Lan <jetlan9@163.com>
Commit author: Qun-Wei Lin <qun-wei.lin@mediatek.com>


Status in newer kernel trees:
6.12.y | Present (exact SHA1)
6.6.y | Not found

Note: The patch differs from the upstream commit:
---
1:  fd7b4f9f46d4 ! 1:  3e999d5c22ab sched/task_stack: fix object_is_on_stack() for KASAN tagged pointers
    @@ Metadata
      ## Commit message ##
         sched/task_stack: fix object_is_on_stack() for KASAN tagged pointers
     
    +    [ Upstream commit fd7b4f9f46d46acbc7af3a439bb0d869efdc5c58 ]
    +
         When CONFIG_KASAN_SW_TAGS and CONFIG_KASAN_STACK are enabled, the
         object_is_on_stack() function may produce incorrect results due to the
         presence of tags in the obj pointer, while the stack pointer does not have
    @@ Commit message
         Cc: Shakeel Butt <shakeel.butt@linux.dev>
         Cc: <stable@vger.kernel.org>
         Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    +    [ Resolve line conflicts ]
    +    Signed-off-by: Wenshan Lan <jetlan9@163.com>
     
      ## include/linux/sched/task_stack.h ##
     @@
    + 
      #include <linux/sched.h>
      #include <linux/magic.h>
    - #include <linux/refcount.h>
     +#include <linux/kasan.h>
      
      #ifdef CONFIG_THREAD_INFO_IN_TASK
---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-6.6.y        |  Success    |  Success   |

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

end of thread, other threads:[~2024-12-26  1:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-24  8:10 [PATCH 6.6] sched/task_stack: fix object_is_on_stack() for KASAN tagged pointers Wenshan Lan
2024-12-26  1:21 ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox