Skip to content

Commit 9063de6

Browse files
mmhalkuba-moo
authored andcommitted
kcm: Fix splice support
Flags passed in for splice() syscall should not end up in skb_recv_datagram(). As SPLICE_F_NONBLOCK == MSG_PEEK, kernel gets confused: skb isn't unlinked from a receive queue, while strp_msg::offset and strp_msg::full_len are updated. Unbreak the logic a bit more by mapping both O_NONBLOCK and SPLICE_F_NONBLOCK to MSG_DONTWAIT. This way we align with man splice(2) in regard to errno EAGAIN: SPLICE_F_NONBLOCK was specified in flags or one of the file descriptors had been marked as nonblocking (O_NONBLOCK), and the operation would block. Fixes: 5121197 ("kcm: close race conditions on sk_receive_queue") Fixes: 9168735 ("kcm: Splice support") Signed-off-by: Michal Luczaj <mhal@rbox.co> Link: https://patch.msgid.link/20250725-kcm-splice-v1-1-9a725ad2ee71@rbox.co Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent d9104ce commit 9063de6

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

net/kcm/kcmsock.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/rculist.h>
2020
#include <linux/skbuff.h>
2121
#include <linux/socket.h>
22+
#include <linux/splice.h>
2223
#include <linux/uaccess.h>
2324
#include <linux/workqueue.h>
2425
#include <linux/syscalls.h>
@@ -1029,6 +1030,11 @@ static ssize_t kcm_splice_read(struct socket *sock, loff_t *ppos,
10291030
ssize_t copied;
10301031
struct sk_buff *skb;
10311032

1033+
if (sock->file->f_flags & O_NONBLOCK || flags & SPLICE_F_NONBLOCK)
1034+
flags = MSG_DONTWAIT;
1035+
else
1036+
flags = 0;
1037+
10321038
/* Only support splice for SOCKSEQPACKET */
10331039

10341040
skb = skb_recv_datagram(sk, flags, &err);

0 commit comments

Comments
 (0)