* [PATCH] net: skmsg: fix NULL pointer dereference in sk_msg_recvmsg()
@ 2025-07-15 8:11 Pranav Tyagi
2025-07-15 8:19 ` Greg KH
2025-07-17 11:10 ` Paolo Abeni
0 siblings, 2 replies; 4+ messages in thread
From: Pranav Tyagi @ 2025-07-15 8:11 UTC (permalink / raw)
To: john.fastabend, jakub, davem, edumazet, kuba, pabeni, ast,
cong.wang, netdev, bpf, linux-kernel
Cc: skhan, linux-kernel-mentees, Pranav Tyagi,
syzbot+b18872ea9631b5dcef3b
A NULL page from sg_page() in sk_msg_recvmsg() can reach
__kmap_local_page_prot() and crash the kernel. Add a check for the page
before calling copy_page_to_iter() and fail early with -EFAULT to
prevent the crash.
Reported-by: syzbot+b18872ea9631b5dcef3b@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=b18872ea9631b5dcef3b
Fixes: 2bc793e3272a ("skmsg: Extract __tcp_bpf_recvmsg() and tcp_bpf_wait_data()")
Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
---
net/core/skmsg.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/core/skmsg.c b/net/core/skmsg.c
index 4d75ef9d24bf..f5367356a483 100644
--- a/net/core/skmsg.c
+++ b/net/core/skmsg.c
@@ -432,6 +432,10 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,
sge = sk_msg_elem(msg_rx, i);
copy = sge->length;
page = sg_page(sge);
+ if (!page) {
+ copied = copied ? copied : -EFAULT;
+ goto out;
+ }
if (copied + copy > len)
copy = len - copied;
copy = copy_page_to_iter(page, sge->offset, copy, iter);
--
2.49.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] net: skmsg: fix NULL pointer dereference in sk_msg_recvmsg()
2025-07-15 8:11 [PATCH] net: skmsg: fix NULL pointer dereference in sk_msg_recvmsg() Pranav Tyagi
@ 2025-07-15 8:19 ` Greg KH
2025-07-17 11:10 ` Paolo Abeni
1 sibling, 0 replies; 4+ messages in thread
From: Greg KH @ 2025-07-15 8:19 UTC (permalink / raw)
To: Pranav Tyagi
Cc: john.fastabend, jakub, davem, edumazet, kuba, pabeni, ast,
cong.wang, netdev, bpf, linux-kernel, skhan, linux-kernel-mentees,
syzbot+b18872ea9631b5dcef3b
On Tue, Jul 15, 2025 at 01:41:58PM +0530, Pranav Tyagi wrote:
> A NULL page from sg_page() in sk_msg_recvmsg() can reach
> __kmap_local_page_prot() and crash the kernel. Add a check for the page
> before calling copy_page_to_iter() and fail early with -EFAULT to
> prevent the crash.
>
> Reported-by: syzbot+b18872ea9631b5dcef3b@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=b18872ea9631b5dcef3b
> Fixes: 2bc793e3272a ("skmsg: Extract __tcp_bpf_recvmsg() and tcp_bpf_wait_data()")
> Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
> ---
> net/core/skmsg.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/net/core/skmsg.c b/net/core/skmsg.c
> index 4d75ef9d24bf..f5367356a483 100644
> --- a/net/core/skmsg.c
> +++ b/net/core/skmsg.c
> @@ -432,6 +432,10 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,
> sge = sk_msg_elem(msg_rx, i);
> copy = sge->length;
> page = sg_page(sge);
> + if (!page) {
> + copied = copied ? copied : -EFAULT;
> + goto out;
> + }
> if (copied + copy > len)
> copy = len - copied;
> copy = copy_page_to_iter(page, sge->offset, copy, iter);
> --
> 2.49.0
>
>
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him
a patch that has triggered this response. He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created. Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.
You are receiving this message because of the following common error(s)
as indicated below:
- This looks like a new version of a previously submitted patch, but you
did not list below the --- line any changes from the previous version.
Please read the section entitled "The canonical patch format" in the
kernel file, Documentation/process/submitting-patches.rst for what
needs to be done here to properly describe this.
If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.
thanks,
greg k-h's patch email bot
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net: skmsg: fix NULL pointer dereference in sk_msg_recvmsg()
2025-07-15 8:11 [PATCH] net: skmsg: fix NULL pointer dereference in sk_msg_recvmsg() Pranav Tyagi
2025-07-15 8:19 ` Greg KH
@ 2025-07-17 11:10 ` Paolo Abeni
2025-07-25 11:55 ` Pranav Tyagi
1 sibling, 1 reply; 4+ messages in thread
From: Paolo Abeni @ 2025-07-17 11:10 UTC (permalink / raw)
To: Pranav Tyagi, john.fastabend, jakub, davem, edumazet, kuba, ast,
cong.wang, netdev, bpf, linux-kernel
Cc: skhan, linux-kernel-mentees, syzbot+b18872ea9631b5dcef3b
On 7/15/25 10:11 AM, Pranav Tyagi wrote:
> A NULL page from sg_page() in sk_msg_recvmsg() can reach
> __kmap_local_page_prot() and crash the kernel. Add a check for the page
> before calling copy_page_to_iter() and fail early with -EFAULT to
> prevent the crash.
Interesting. I thought the sge in this case are build from the kernel, I
did not expect a null page to be possible. Can you describe in the
commit message how such bad sges are created?
>
> Reported-by: syzbot+b18872ea9631b5dcef3b@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=b18872ea9631b5dcef3b
> Fixes: 2bc793e3272a ("skmsg: Extract __tcp_bpf_recvmsg() and tcp_bpf_wait_data()")
> Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
Does not apply to net. Please rebase and resend, adding the target tree
in the subj prefix and specifying a revision number.
Thanks,
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net: skmsg: fix NULL pointer dereference in sk_msg_recvmsg()
2025-07-17 11:10 ` Paolo Abeni
@ 2025-07-25 11:55 ` Pranav Tyagi
0 siblings, 0 replies; 4+ messages in thread
From: Pranav Tyagi @ 2025-07-25 11:55 UTC (permalink / raw)
To: Paolo Abeni
Cc: john.fastabend, jakub, davem, edumazet, kuba, ast, cong.wang,
netdev, bpf, linux-kernel, skhan, linux-kernel-mentees,
syzbot+b18872ea9631b5dcef3b
On Thu, Jul 17, 2025 at 4:40 PM Paolo Abeni <pabeni@redhat.com> wrote:
>
> On 7/15/25 10:11 AM, Pranav Tyagi wrote:
> > A NULL page from sg_page() in sk_msg_recvmsg() can reach
> > __kmap_local_page_prot() and crash the kernel. Add a check for the page
> > before calling copy_page_to_iter() and fail early with -EFAULT to
> > prevent the crash.
>
> Interesting. I thought the sge in this case are build from the kernel, I
> did not expect a null page to be possible. Can you describe in the
> commit message how such bad sges are created?
>
> >
> > Reported-by: syzbot+b18872ea9631b5dcef3b@syzkaller.appspotmail.com
> > Closes: https://syzkaller.appspot.com/bug?extid=b18872ea9631b5dcef3b
> > Fixes: 2bc793e3272a ("skmsg: Extract __tcp_bpf_recvmsg() and tcp_bpf_wait_data()")
> > Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
>
> Does not apply to net. Please rebase and resend, adding the target tree
> in the subj prefix and specifying a revision number.
>
> Thanks,
>
> Paolo
>
>
Hi Paolo,
Apologies for a delayed response. I will send a v2 of the patch with all the
required changes shortly. Also, as I am a beginner at kernel work, my initial
intention was to just fix the bug and (honestly) I did not think about
the cause of
bad sges. But, I will definitely take a deep dive and try my level best
to look for a suitable explanation for the same.
Thanks for the feedback.
Regards
Pranav Tyagi
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-07-25 11:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-15 8:11 [PATCH] net: skmsg: fix NULL pointer dereference in sk_msg_recvmsg() Pranav Tyagi
2025-07-15 8:19 ` Greg KH
2025-07-17 11:10 ` Paolo Abeni
2025-07-25 11:55 ` Pranav Tyagi
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).