Skip to contentSkip to conversation

drivers/net: Make rtskb pool cache being an usercopy source

PATCH Applied Zqiang 2 participants 5 messages Sep 21, 2022 – Sep 26, 2022

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore

Zqiang

author
#0 lore raw

PATCH 1/1 drivers/net: Make rtskb pool cache being an usercopy source

When kernel enable CONFIG_HARDENED_USERCOPY option, since not marking rtskb_slab_pool cache is usercopy type, will trigger the following calltrace.

[  594.413602] invalid opcode: 0000 1 PREEMPT SMP PTI IRQ_PIPELINE
[  594.413603] CPU: 2 PID: 492 Comm: rtcfg Tainted:
[  594.413603] IRQ stage: Linux
[  594.413604] RIP: 0010:usercopy_abort+0x77/0x79
[  594.413610] Call Trace:
[  594.413610]  __check_heap_object+0xa6/0xc0
[  594.413611]  __check_object_size+0x136/0x150
[  594.413611]  copy_stage_1_data+0x48/0x70 [rtcfg]
[  594.413612]  rtnet_rtpc_dispatch_call+0x151/0x320 [rtnet]
[  594.413612]  ? cleanup_cmd_del+0x70/0x70 [rtcfg]
[  594.413612]  ? wait_woken+0x70/0x70
[  594.413613]  rtcfg_ioctl+0xa0/0x250 [rtcfg]
[  594.413613]  rtnet_ioctl+0xdf/0x170 [rtnet]
[  594.413613]  __x64_sys_ioctl+0x83/0xb0
[  594.413613]  do_syscall_64+0x39/0x50
[  594.413614]  entry_SYSCALL_64_after_hwframe+0x44/0xa9

This commit make rtskb_slab_pool cache being an usercopy source.

---
 kernel/drivers/net/stack/rtskb.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/drivers/net/stack/rtskb.c +3 -2
index c9042db93..fa75ca6ec 100644
@@ -497,10 +497,11 @@ EXPORT_SYMBOL_GPL(rtskb_clone);
 
 int rtskb_pools_init(void)
 {
-	rtskb_slab_pool = kmem_cache_create("rtskb_slab_pool",
+	rtskb_slab_pool = kmem_cache_create_usercopy("rtskb_slab_pool",
 					    ALIGN_RTSKB_STRUCT_LEN +
 						    SKB_DATA_ALIGN(RTSKB_SIZE),
-					    0, SLAB_HWCACHE_ALIGN, NULL);
+					    0, SLAB_HWCACHE_ALIGN,
+						0, SKB_DATA_ALIGN(RTSKB_SIZE), NULL);
 	if (rtskb_slab_pool == NULL)
 		return -ENOMEM;
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 33 lines · Zqiang

When kernel enable CONFIG_HARDENED_USERCOPY option, since not marking rtskb_slab_pool cache is usercopy type, will trigger the following calltrace.

[  594.413602] invalid opcode: 0000 1 PREEMPT SMP PTI IRQ_PIPELINE
[  594.413603] CPU: 2 PID: 492 Comm: rtcfg Tainted:
[  594.413603] IRQ stage: Linux
[  594.413604] RIP: 0010:usercopy_abort+0x77/0x79
[  594.413610] Call Trace:
[  594.413610]  __check_heap_object+0xa6/0xc0
[  594.413611]  __check_object_size+0x136/0x150
[  594.413611]  copy_stage_1_data+0x48/0x70 [rtcfg]
[  594.413612]  rtnet_rtpc_dispatch_call+0x151/0x320 [rtnet]
[  594.413612]  ? cleanup_cmd_del+0x70/0x70 [rtcfg]
[  594.413612]  ? wait_woken+0x70/0x70
[  594.413613]  rtcfg_ioctl+0xa0/0x250 [rtcfg]
[  594.413613]  rtnet_ioctl+0xdf/0x170 [rtnet]
[  594.413613]  __x64_sys_ioctl+0x83/0xb0
[  594.413613]  do_syscall_64+0x39/0x50
[  594.413614]  entry_SYSCALL_64_after_hwframe+0x44/0xa9

This commit make rtskb_slab_pool cache being an usercopy source.

---
 kernel/drivers/net/stack/rtskb.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/drivers/net/stack/rtskb.c +0 -0
index c9042db93..fa75ca6ec 100644

kernel/drivers/net/stack/rtskb.c EXPORT_SYMBOL_GPL(rtskb_clone); · line 500

Quoted 5 lines
kernel/drivers/net/stack/rtskb.c +1 -1
@@ -497,10 +497,11 @@ EXPORT_SYMBOL_GPL(rtskb_clone);
 
 int rtskb_pools_init(void)
 {
-	rtskb_slab_pool = kmem_cache_create("rtskb_slab_pool",
+	rtskb_slab_pool = kmem_cache_create_usercopy("rtskb_slab_pool",

Since when (kernel version) is this function available? Can also be important when we decide to pick this patch into stable versions which still support older kernels than 5.10.

kernel/drivers/net/stack/rtskb.c EXPORT_SYMBOL_GPL(rtskb_clone); · line 504

Quoted 5 lines
kernel/drivers/net/stack/rtskb.c +2 -1
 					    ALIGN_RTSKB_STRUCT_LEN +
 						    SKB_DATA_ALIGN(RTSKB_SIZE),
-					    0, SLAB_HWCACHE_ALIGN, NULL);
+					    0, SLAB_HWCACHE_ALIGN,
+						0, SKB_DATA_ALIGN(RTSKB_SIZE), NULL);

I suppose the indention should be done a bit nicer, possibly by indenting much less (two or three tabs?) but consistently.

Thanks,
Jan

Quoted 3 lines
kernel/drivers/net/stack/rtskb.c +0 -0
 	if (rtskb_slab_pool == NULL)
 		return -ENOMEM;
 
Signature · 2 lines
Siemens AG, Technology
Competence Center Embedded Linux
#2 lore raw
Quoted 39 lines

When kernel enable CONFIG_HARDENED_USERCOPY option, since not marking rtskb_slab_pool cache is usercopy type, will trigger the following calltrace.

[  594.413602] invalid opcode: 0000 1 PREEMPT SMP PTI IRQ_PIPELINE
[  594.413603] CPU: 2 PID: 492 Comm: rtcfg Tainted:
[  594.413603] IRQ stage: Linux
[  594.413604] RIP: 0010:usercopy_abort+0x77/0x79
[  594.413610] Call Trace:
[  594.413610]  __check_heap_object+0xa6/0xc0
[  594.413611]  __check_object_size+0x136/0x150
[  594.413611]  copy_stage_1_data+0x48/0x70 [rtcfg]
[  594.413612]  rtnet_rtpc_dispatch_call+0x151/0x320 [rtnet]
[  594.413612]  ? cleanup_cmd_del+0x70/0x70 [rtcfg]
[  594.413612]  ? wait_woken+0x70/0x70
[  594.413613]  rtcfg_ioctl+0xa0/0x250 [rtcfg]
[  594.413613]  rtnet_ioctl+0xdf/0x170 [rtnet]
[  594.413613]  __x64_sys_ioctl+0x83/0xb0
[  594.413613]  do_syscall_64+0x39/0x50
[  594.413614]  entry_SYSCALL_64_after_hwframe+0x44/0xa9

This commit make rtskb_slab_pool cache being an usercopy source.

---
 kernel/drivers/net/stack/rtskb.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/drivers/net/stack/rtskb.c +1 -1
index c9042db93..fa75ca6ec 100644
@@ -497,10 +497,11 @@ EXPORT_SYMBOL_GPL(rtskb_clone);
 
 int rtskb_pools_init(void)
 {
-	rtskb_slab_pool = kmem_cache_create("rtskb_slab_pool",
+	rtskb_slab_pool = kmem_cache_create_usercopy("rtskb_slab_pool",
 
Quoted 3 lines

Since when (kernel version) is this function available? Can also be important when we decide to pick this patch into stable versions which still support older kernels than 5.10.

This function has been available since v3.0.

Quoted 9 lines
kernel/drivers/net/stack/rtskb.c +2 -1
 					    ALIGN_RTSKB_STRUCT_LEN +
 						    SKB_DATA_ALIGN(RTSKB_SIZE),
-					    0, SLAB_HWCACHE_ALIGN, NULL);
+					    0, SLAB_HWCACHE_ALIGN,
+						0, SKB_DATA_ALIGN(RTSKB_SIZE), NULL);

I suppose the indention should be done a bit nicer, possibly by indenting much less (two or three tabs?) but consistently.

Thanks, I will resend.

Quoted 11 lines

Thanks,
Jan

kernel/drivers/net/stack/rtskb.c +0 -0
 	if (rtskb_slab_pool == NULL)
 		return -ENOMEM;
Signature · 3 lines
-- 
Siemens AG, Technology
Competence Center Embedded Linux
Applied
#3 lore raw
In reply to Zqiang
Quoted 36 lines · Zqiang

When kernel enable CONFIG_HARDENED_USERCOPY option, since not marking rtskb_slab_pool cache is usercopy type, will trigger the following calltrace.

[  594.413602] invalid opcode: 0000 1 PREEMPT SMP PTI IRQ_PIPELINE
[  594.413603] CPU: 2 PID: 492 Comm: rtcfg Tainted:
[  594.413603] IRQ stage: Linux
[  594.413604] RIP: 0010:usercopy_abort+0x77/0x79
[  594.413610] Call Trace:
[  594.413610]  __check_heap_object+0xa6/0xc0
[  594.413611]  __check_object_size+0x136/0x150
[  594.413611]  copy_stage_1_data+0x48/0x70 [rtcfg]
[  594.413612]  rtnet_rtpc_dispatch_call+0x151/0x320 [rtnet]
[  594.413612]  ? cleanup_cmd_del+0x70/0x70 [rtcfg]
[  594.413612]  ? wait_woken+0x70/0x70
[  594.413613]  rtcfg_ioctl+0xa0/0x250 [rtcfg]
[  594.413613]  rtnet_ioctl+0xdf/0x170 [rtnet]
[  594.413613]  __x64_sys_ioctl+0x83/0xb0
[  594.413613]  do_syscall_64+0x39/0x50
[  594.413614]  entry_SYSCALL_64_after_hwframe+0x44/0xa9

This commit make rtskb_slab_pool cache being an usercopy source.

---
 kernel/drivers/net/stack/rtskb.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/drivers/net/stack/rtskb.c +0 -0
index c9042db93..fa75ca6ec 100644
@@ -497,10 +497,11 @@ EXPORT_SYMBOL_GPL(rtskb_clone);
 
 int rtskb_pools_init(void)
 {

kernel/drivers/net/stack/rtskb.c EXPORT_SYMBOL_GPL(rtskb_clone); · line 507

Quoted 10 lines
kernel/drivers/net/stack/rtskb.c +3 -2
-	rtskb_slab_pool = kmem_cache_create("rtskb_slab_pool",
+	rtskb_slab_pool = kmem_cache_create_usercopy("rtskb_slab_pool",
 					    ALIGN_RTSKB_STRUCT_LEN +
 						    SKB_DATA_ALIGN(RTSKB_SIZE),
-					    0, SLAB_HWCACHE_ALIGN, NULL);
+					    0, SLAB_HWCACHE_ALIGN,
+						0, SKB_DATA_ALIGN(RTSKB_SIZE), NULL);
 	if (rtskb_slab_pool == NULL)
 		return -ENOMEM;
 

Thanks, applied.

Jan

Signature · 2 lines
Siemens AG, Technology
Competence Center Embedded Linux
#4 lore raw
Quoted 50 lines · Jan Kiszka
Quoted 36 lines · Zqiang

When kernel enable CONFIG_HARDENED_USERCOPY option, since not marking rtskb_slab_pool cache is usercopy type, will trigger the following calltrace.

[  594.413602] invalid opcode: 0000 1 PREEMPT SMP PTI IRQ_PIPELINE
[  594.413603] CPU: 2 PID: 492 Comm: rtcfg Tainted:
[  594.413603] IRQ stage: Linux
[  594.413604] RIP: 0010:usercopy_abort+0x77/0x79
[  594.413610] Call Trace:
[  594.413610]  __check_heap_object+0xa6/0xc0
[  594.413611]  __check_object_size+0x136/0x150
[  594.413611]  copy_stage_1_data+0x48/0x70 [rtcfg]
[  594.413612]  rtnet_rtpc_dispatch_call+0x151/0x320 [rtnet]
[  594.413612]  ? cleanup_cmd_del+0x70/0x70 [rtcfg]
[  594.413612]  ? wait_woken+0x70/0x70
[  594.413613]  rtcfg_ioctl+0xa0/0x250 [rtcfg]
[  594.413613]  rtnet_ioctl+0xdf/0x170 [rtnet]
[  594.413613]  __x64_sys_ioctl+0x83/0xb0
[  594.413613]  do_syscall_64+0x39/0x50
[  594.413614]  entry_SYSCALL_64_after_hwframe+0x44/0xa9

This commit make rtskb_slab_pool cache being an usercopy source.

---
 kernel/drivers/net/stack/rtskb.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/drivers/net/stack/rtskb.c +0 -0
index c9042db93..fa75ca6ec 100644
@@ -497,10 +497,11 @@ EXPORT_SYMBOL_GPL(rtskb_clone);
 
 int rtskb_pools_init(void)
 {

kernel/drivers/net/stack/rtskb.c EXPORT_SYMBOL_GPL(rtskb_clone); · line 507

Quoted 10 lines
kernel/drivers/net/stack/rtskb.c +3 -2
-	rtskb_slab_pool = kmem_cache_create("rtskb_slab_pool",
+	rtskb_slab_pool = kmem_cache_create_usercopy("rtskb_slab_pool",
 					    ALIGN_RTSKB_STRUCT_LEN +
 						    SKB_DATA_ALIGN(RTSKB_SIZE),
-					    0, SLAB_HWCACHE_ALIGN, NULL);
+					    0, SLAB_HWCACHE_ALIGN,
+						0, SKB_DATA_ALIGN(RTSKB_SIZE), NULL);
 	if (rtskb_slab_pool == NULL)
 		return -ENOMEM;
 

Thanks, applied.

Quoted 2 lines

Jan

v2, I meant...

Jan

Signature · 2 lines
Siemens AG, Technology
Competence Center Embedded Linux