Skip to contentSkip to conversation

Fix KASAN: slab-out-of-bounds Read in sk_psock_get

RFC PATCH In review Khalid Masum 3 participants 5 messages Jul 13, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Fix KASAN: slab-out-of-bounds Read in sk_psock_get

Using size of sk_psock as the size for kcm_psock_cache size no longer reproduces the issue. There might be a better way to solve this issue though so I would like to ask for feedback.

Khalid Masum (1):
net: kcm: Use sk_psock size for kcm_psock_cache

 net/kcm/kcmsock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.36.1
#1 lore raw

RFC PATCH 1/1 net: kcm: Use sk_psock size for kcm_psock_cache

struct sock has a member sk_user_data, which got its memory allocated in kcm_attach by kcm_psock_cache with the size of kcm_psock. Which is not enough when the member is used as sk_psock causing out of bound read.

Use sk_psock size to allocate memory instead for sk_user_data.

---
 net/kcm/kcmsock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/kcm/kcmsock.c +2 -1
index 71899e5a5a11..688bee56f90c 100644
@@ -23,6 +23,7 @@
 #include <linux/workqueue.h>
 #include <linux/syscalls.h>
 #include <linux/sched/signal.h>
+#include <linux/skmsg.h>
 
 #include <net/kcm.h>
 #include <net/netns/generic.h>
@@ -2041,7 +2042,7 @@ static int __init kcm_init(void)
 		goto fail;
 
 	kcm_psockp = kmem_cache_create("kcm_psock_cache",
-				       sizeof(struct kcm_psock), 0,
+				       sizeof(struct sk_psock), 0,
 					SLAB_HWCACHE_ALIGN, NULL);
 	if (!kcm_psockp)
 		goto fail;
Signature · 1 line
2.36.1
maintainer
#2 lore raw

Re: [RFC PATCH 1/1] net: kcm: Use sk_psock size for kcm_psock_cache

Quoted 5 lines · Khalid Masum

struct sock has a member sk_user_data, which got its memory allocated in kcm_attach by kcm_psock_cache with the size of kcm_psock. Which is not enough when the member is used as sk_psock causing out of bound read.

Quoted 7 lines

Use sk_psock size to allocate memory instead for sk_user_data.

---
 net/kcm/kcmsock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

What commit id does this fix?

thanks,

greg k-h

maintainer
#3 lore raw

Re: [RFC PATCH 1/1] net: kcm: Use sk_psock size for kcm_psock_cache

In reply to Khalid Masum
Quoted 9 lines · On Wed, 13 Jul 2022 12:32:04 +0600 Khalid Masum wrote:

struct sock has a member sk_user_data, which got its memory allocated in kcm_attach by kcm_psock_cache with the size of kcm_psock. Which is not enough when the member is used as sk_psock causing out of bound read.

Use sk_psock size to allocate memory instead for sk_user_data.

Odd CC list, it looks like a netdev problem but netdev@ is not copied.

We had an other parson looking at this on netdev. Is this happening when legit kernel socket gets mixed with BPF sockmap?

Does this fix work?

https://lore.kernel.org/netdev/[email protected]/

#4 lore raw

Re: [RFC PATCH 1/1] net: kcm: Use sk_psock size for kcm_psock_cache

Quoted 7 lines · Jakub Kicinski
Quoted 5 lines · On Wed, 13 Jul 2022 12:32:04 +0600 Khalid Masum wrote:

struct sock has a member sk_user_data, which got its memory allocated in kcm_attach by kcm_psock_cache with the size of kcm_psock. Which is not enough when the member is used as sk_psock causing out of bound read.

Quoted 6 lines
Quoted 4 lines

Use sk_psock size to allocate memory instead for sk_user_data.

Odd CC list, it looks like a netdev problem but netdev@ is not copied.

I am sorry for the inconvenience. I resent the patch with netdev in CC here:
https://lore.kernel.org/netdev/[email protected]/

Quoted 4 lines

We had an other parson looking at this on netdev. Is this happening when legit kernel socket gets mixed with BPF sockmap?

Does this fix work?

I will take a look at it.

Quoted 1 line

https://lore.kernel.org/netdev/[email protected]/

Thanks,
Khalid Masum