* [PATCH v2] net: skbuff: add usercopy region to skbuff_fclone_cache
@ 2025-12-15 18:09 Weiming Shi
2025-12-20 14:45 ` kernel test robot
2025-12-20 15:57 ` kernel test robot
0 siblings, 2 replies; 3+ messages in thread
From: Weiming Shi @ 2025-12-15 18:09 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni
Cc: horms, netdev, linux-kernel, xmei5, Weiming Shi
From: "Weiming Shi" <bestswngs@gmail.com>
skbuff_fclone_cache was created without defining a usercopy region, [1]
unlike skbuff_head_cache which properly whitelists the cb[] field. [2]
This causes a usercopy BUG() when CONFIG_HARDENED_USERCOPY is enabled
and the kernel attempts to copy sk_buff.cb data to userspace via
sock_recv_errqueue() -> put_cmsg().
The crash occurs when:
1. TCP allocates an skb using alloc_skb_fclone() (from skbuff_fclone_cache) [1]
2. The skb is cloned via skb_clone() using the pre-allocated fclone [3]
3. The cloned skb is queued to sk_error_queue for timestamp reporting
4. Userspace reads the error queue via recvmsg(MSG_ERRQUEUE)
5. sock_recv_errqueue() calls put_cmsg() to copy serr->ee from skb->cb [4]
6. __check_heap_object() fails because skbuff_fclone_cache has no
usercopy whitelist [5]
When cloned skbs allocated from skbuff_fclone_cache are used in the
socket error queue, accessing the sock_exterr_skb structure in skb->cb
via put_cmsg() triggers a usercopy hardening violation:
[ 5.379589] usercopy: Kernel memory exposure attempt detected from SLUB object 'skbuff_fclone_cache' (offset 296, size 16)!
[ 5.382796] kernel BUG at mm/usercopy.c:102!
[ 5.383923] Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI
[ 5.384903] CPU: 1 UID: 0 PID: 138 Comm: poc_put_cmsg Not tainted 6.12.57 #7
[ 5.384903] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014
[ 5.384903] RIP: 0010:usercopy_abort+0x6c/0x80
[ 5.384903] Code: 1a 86 51 48 c7 c2 40 15 1a 86 41 52 48 c7 c7 c0 15 1a 86 48 0f 45 d6 48 c7 c6 80 15 1a 86 48 89 c1 49 0f 45 f3 e8 84 27 88 ff <0f> 0b 490
[ 5.384903] RSP: 0018:ffffc900006f77a8 EFLAGS: 00010246
[ 5.384903] RAX: 000000000000006f RBX: ffff88800f0ad2a8 RCX: 1ffffffff0f72e74
[ 5.384903] RDX: 0000000000000000 RSI: 0000000000000004 RDI: ffffffff87b973a0
[ 5.384903] RBP: 0000000000000010 R08: 0000000000000000 R09: fffffbfff0f72e74
[ 5.384903] R10: 0000000000000003 R11: 79706f6372657375 R12: 0000000000000001
[ 5.384903] R13: ffff88800f0ad2b8 R14: ffffea00003c2b40 R15: ffffea00003c2b00
[ 5.384903] FS: 0000000011bc4380(0000) GS:ffff8880bf100000(0000) knlGS:0000000000000000
[ 5.384903] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 5.384903] CR2: 000056aa3b8e5fe4 CR3: 000000000ea26004 CR4: 0000000000770ef0
[ 5.384903] PKRU: 55555554
[ 5.384903] Call Trace:
[ 5.384903] <TASK>
[ 5.384903] __check_heap_object+0x9a/0xd0
[ 5.384903] __check_object_size+0x46c/0x690
[ 5.384903] put_cmsg+0x129/0x5e0
[ 5.384903] sock_recv_errqueue+0x22f/0x380
[ 5.384903] tls_sw_recvmsg+0x7ed/0x1960
[ 5.384903] ? srso_alias_return_thunk+0x5/0xfbef5
[ 5.384903] ? schedule+0x6d/0x270
[ 5.384903] ? srso_alias_return_thunk+0x5/0xfbef5
[ 5.384903] ? mutex_unlock+0x81/0xd0
[ 5.384903] ? __pfx_mutex_unlock+0x10/0x10
[ 5.384903] ? __pfx_tls_sw_recvmsg+0x10/0x10
[ 5.384903] ? _raw_spin_lock_irqsave+0x8f/0xf0
[ 5.384903] ? _raw_read_unlock_irqrestore+0x20/0x40
[ 5.384903] ? srso_alias_return_thunk+0x5/0xfbef5
In our patch, we referenced net: Whitelist the `skb_head_cache` "cb" field. [5]
Fix by using kmem_cache_create_usercopy() with the same cb[] region
whitelist as skbuff_head_cache.
[1] https://elixir.bootlin.com/linux/v6.12.62/source/net/ipv4/tcp.c#L885
[2] https://elixir.bootlin.com/linux/v6.12.62/source/net/core/skbuff.c#L5104
[3] https://elixir.bootlin.com/linux/v6.12.62/source/net/core/skbuff.c#L5566
[4] https://elixir.bootlin.com/linux/v6.12.62/source/net/core/skbuff.c#L5491
[5] https://elixir.bootlin.com/linux/v6.12.62/source/mm/slub.c#L5719
[6] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=79a8a642bf05c
Fixes: 6d07d1cd300f ("usercopy: Restrict non-usercopy caches to size 0")
Signed-off-by: Weiming Shi <bestswngs@gmail.com>
Reported-by: Xiang Mei <xmei5@asu.edu>
---
v2: Fix the Commit Message
net/core/skbuff.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index c52e955dd3a0..89c98ce6106a 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -5157,7 +5157,7 @@ void __init skb_init(void)
NULL);
skbuff_cache_size = kmem_cache_size(net_hotdata.skbuff_cache);
- net_hotdata.skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
+ net_hotdata.skbuff_fclone_cache = kmem_cache_create_usercopy("skbuff_fclone_cache",
sizeof(struct sk_buff_fclones),
0,
SLAB_HWCACHE_ALIGN|SLAB_PANIC,
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] net: skbuff: add usercopy region to skbuff_fclone_cache
2025-12-15 18:09 [PATCH v2] net: skbuff: add usercopy region to skbuff_fclone_cache Weiming Shi
@ 2025-12-20 14:45 ` kernel test robot
2025-12-20 15:57 ` kernel test robot
1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2025-12-20 14:45 UTC (permalink / raw)
To: Weiming Shi, davem, edumazet, kuba, pabeni
Cc: oe-kbuild-all, horms, netdev, linux-kernel, xmei5, Weiming Shi
Hi Weiming,
kernel test robot noticed the following build errors:
[auto build test ERROR on net-next/main]
[also build test ERROR on net/main linus/master v6.19-rc1 next-20251219]
[cannot apply to horms-ipvs/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Weiming-Shi/net-skbuff-add-usercopy-region-to-skbuff_fclone_cache/20251216-021811
base: net-next/main
patch link: https://lore.kernel.org/r/20251215180903.954968-2-bestswngs%40gmail.com
patch subject: [PATCH v2] net: skbuff: add usercopy region to skbuff_fclone_cache
config: i386-randconfig-003-20251216 (https://download.01.org/0day-ci/archive/20251220/202512202238.ULq0lvo7-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251220/202512202238.ULq0lvo7-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202512202238.ULq0lvo7-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from include/uapi/linux/posix_types.h:5,
from include/uapi/linux/types.h:14,
from include/linux/types.h:6,
from include/linux/kasan-checks.h:5,
from include/asm-generic/rwonce.h:26,
from ./arch/x86/include/generated/asm/rwonce.h:1,
from include/linux/compiler.h:386,
from include/linux/build_bug.h:5,
from include/linux/container_of.h:5,
from include/linux/list.h:5,
from include/linux/module.h:12,
from net/core/skbuff.c:37:
net/core/skbuff.c: In function 'skb_init':
>> include/linux/stddef.h:8:14: error: passing argument 5 of 'kmem_cache_create_usercopy' makes integer from pointer without a cast [-Wint-conversion]
8 | #define NULL ((void *)0)
| ^~~~~~~~~~~
| |
| void *
net/core/skbuff.c:5164:49: note: in expansion of macro 'NULL'
5164 | NULL);
| ^~~~
In file included from include/linux/mm.h:34,
from net/core/skbuff.c:40:
include/linux/slab.h:408:41: note: expected 'unsigned int' but argument is of type 'void *'
408 | unsigned int useroffset, unsigned int usersize,
| ~~~~~~~~~~~~~^~~~~~~~~~
>> net/core/skbuff.c:5160:43: error: too few arguments to function 'kmem_cache_create_usercopy'
5160 | net_hotdata.skbuff_fclone_cache = kmem_cache_create_usercopy("skbuff_fclone_cache",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/slab.h:406:1: note: declared here
406 | kmem_cache_create_usercopy(const char *name, unsigned int size,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
vim +/kmem_cache_create_usercopy +8 include/linux/stddef.h
^1da177e4c3f41 Linus Torvalds 2005-04-16 6
^1da177e4c3f41 Linus Torvalds 2005-04-16 7 #undef NULL
^1da177e4c3f41 Linus Torvalds 2005-04-16 @8 #define NULL ((void *)0)
6e218287432472 Richard Knutsson 2006-09-30 9
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] net: skbuff: add usercopy region to skbuff_fclone_cache
2025-12-15 18:09 [PATCH v2] net: skbuff: add usercopy region to skbuff_fclone_cache Weiming Shi
2025-12-20 14:45 ` kernel test robot
@ 2025-12-20 15:57 ` kernel test robot
1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2025-12-20 15:57 UTC (permalink / raw)
To: Weiming Shi, davem, edumazet, kuba, pabeni
Cc: oe-kbuild-all, horms, netdev, linux-kernel, xmei5, Weiming Shi
Hi Weiming,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net-next/main]
[also build test WARNING on net/main linus/master v6.19-rc1 next-20251219]
[cannot apply to horms-ipvs/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Weiming-Shi/net-skbuff-add-usercopy-region-to-skbuff_fclone_cache/20251216-021811
base: net-next/main
patch link: https://lore.kernel.org/r/20251215180903.954968-2-bestswngs%40gmail.com
patch subject: [PATCH v2] net: skbuff: add usercopy region to skbuff_fclone_cache
config: arm-randconfig-r073-20251216 (https://download.01.org/0day-ci/archive/20251220/202512202310.PGCBLw9b-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 10.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251220/202512202310.PGCBLw9b-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202512202310.PGCBLw9b-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from include/uapi/linux/posix_types.h:5,
from include/uapi/linux/types.h:14,
from include/linux/types.h:6,
from include/linux/kasan-checks.h:5,
from include/asm-generic/rwonce.h:26,
from ./arch/arm/include/generated/asm/rwonce.h:1,
from include/linux/compiler.h:386,
from include/linux/build_bug.h:5,
from include/linux/container_of.h:5,
from include/linux/list.h:5,
from include/linux/module.h:12,
from net/core/skbuff.c:37:
net/core/skbuff.c: In function 'skb_init':
>> include/linux/stddef.h:8:14: warning: passing argument 5 of 'kmem_cache_create_usercopy' makes integer from pointer without a cast [-Wint-conversion]
8 | #define NULL ((void *)0)
| ^~~~~~~~~~~
| |
| void *
net/core/skbuff.c:5164:7: note: in expansion of macro 'NULL'
5164 | NULL);
| ^~~~
In file included from arch/arm/include/asm/pgtable-nommu.h:13,
from arch/arm/include/asm/pgtable.h:25,
from include/linux/pgtable.h:6,
from include/linux/mm.h:31,
from net/core/skbuff.c:40:
include/linux/slab.h:408:20: note: expected 'unsigned int' but argument is of type 'void *'
408 | unsigned int useroffset, unsigned int usersize,
| ~~~~~~~~~~~~~^~~~~~~~~~
net/core/skbuff.c:5160:36: error: too few arguments to function 'kmem_cache_create_usercopy'
5160 | net_hotdata.skbuff_fclone_cache = kmem_cache_create_usercopy("skbuff_fclone_cache",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from arch/arm/include/asm/pgtable-nommu.h:13,
from arch/arm/include/asm/pgtable.h:25,
from include/linux/pgtable.h:6,
from include/linux/mm.h:31,
from net/core/skbuff.c:40:
include/linux/slab.h:406:1: note: declared here
406 | kmem_cache_create_usercopy(const char *name, unsigned int size,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for CAN_DEV
Depends on [n]: NETDEVICES [=n] && CAN [=y]
Selected by [y]:
- CAN [=y] && NET [=y]
vim +/kmem_cache_create_usercopy +8 include/linux/stddef.h
^1da177e4c3f41 Linus Torvalds 2005-04-16 6
^1da177e4c3f41 Linus Torvalds 2005-04-16 7 #undef NULL
^1da177e4c3f41 Linus Torvalds 2005-04-16 @8 #define NULL ((void *)0)
6e218287432472 Richard Knutsson 2006-09-30 9
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-20 15:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-15 18:09 [PATCH v2] net: skbuff: add usercopy region to skbuff_fclone_cache Weiming Shi
2025-12-20 14:45 ` kernel test robot
2025-12-20 15:57 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).