tcp: reject devmem tx with fastopen and repair
Subsystems (3)
PATCH v2 1/1 tcp: reject devmem tx with fastopen and repair
tcp_sendmsg_locked() enforces that devmem TX can only proceed if the zero-copy path is active and a valid dmabuf binding exists. However, subsequent branches in tcp_sendmsg_locked() can still intercept the message before it reaches the devmem zero-copy loop:
1. TCP Fast Open (MSG_FASTOPEN or DEFER_CONNECT):
If TCP_FASTOPEN_CONNECT is set, the socket may have a valid dst with NETIF_F_SG (so zc == MSG_ZEROCOPY and binding is present), but tcp_sendmsg_fastopen() -> tcp_send_syn_data() will use copy_page_from_iter() to byte-copy from the iterator. Since iov_base represents dma-buf offsets rather than user virtual addresses, this misinterprets offsets as user pointers and copies the caller's memory at those addresses into the SYN packet.
2. TCP repair mode:
If tp->repair is enabled with TCP_RECV_QUEUE, tcp_send_rcvq() similarly calls skb_copy_datagram_from_iter(), byte-copying from the iterator.
Neither path supports or makes sense for devmem transmission. Reject devmem sends inside the Fast Open and TCP repair branches when a devmem binding is present. Checking inside the tp->repair branch also covers the case where repair mode is enabled while sk_stream_wait_connect() drops the socket lock.
Additionally, drop the !sockc_err gate from the devmem validation check and return sockc_err if set. Otherwise, if a valid SCM_DEVMEM_DMABUF is followed by a failing cmsg, sockc.dmabuf_id remains set while binding is not acquired, allowing the Fast Open and TCP_RECV_QUEUE repair paths to proceed and return before sockc_err is checked.
This pre-existing issue was identified by Sashiko AI review on commit 125755776bc6 ("tcp: reject non zerocopy devmem tx") and has not been hit in production.
---
v1 -> v2:
- Move the devmem rejection checks into the Fast Open and TCP repair branches directly, also covering the case where tp->repair is enabled while sk_stream_wait_connect() drops the socket lock.
- Drop the !sockc_err gate from the devmem validation check and return sockc_err if set, preventing a valid SCM_DEVMEM_DMABUF followed by a failing cmsg from bypassing the check.
net/ipv4/tcp.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
net/ipv4/tcp.c +10 -2
@@ -1169,14 +1169,18 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) zc =MSG_SPLICE_PAGES ; } -if (!sockc_err && sockc.dmabuf_id && (zc !=MSG_ZEROCOPY || !binding)) { - err = -EINVAL ; +if (sockc.dmabuf_id && (zc !=MSG_ZEROCOPY || !binding)) { + err = sockc_err ?: -EINVAL ; goto out_err; }if (unlikely (flags &MSG_FASTOPEN ||inet_test_bit (DEFER_CONNECT , sk)) && !tp->repair) { +if (binding) { + err = -EINVAL ; + goto out_err; + } err =tcp_sendmsg_fastopen (sk, msg, &copied_syn, size, uarg);if (err == -EINPROGRESS && copied_syn >0 ) goto out;
@@ -1200,6 +1204,10 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) }if (unlikely (tp->repair)) { +if (binding) { + err = -EINVAL ; + goto out_err; + }if (tp->repair_queue ==TCP_RECV_QUEUE ) { copied =tcp_send_rcvq (sk, msg, size); goto out_nopush;
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
Quoted 38 lines · Kaifeng Wang
tcp_sendmsg_locked()enforces that devmem TX can only proceed if the zero-copy path is active and a valid dmabuf binding exists. However, subsequent branches intcp_sendmsg_locked()can still intercept the message before it reaches the devmem zero-copy loop:1. TCP Fast Open (
MSG_FASTOPENorDEFER_CONNECT):
IfTCP_FASTOPEN_CONNECTis set, the socket may have a valid dst withNETIF_F_SG(so zc ==MSG_ZEROCOPYand binding is present), buttcp_sendmsg_fastopen()->tcp_send_syn_data()will usecopy_page_from_iter()to byte-copy from the iterator. Sinceiov_baserepresents dma-buf offsets rather than user virtual addresses, this misinterprets offsets as user pointers and copies the caller's memory at those addresses into the SYN packet.2. TCP repair mode:
Iftp->repairis enabled withTCP_RECV_QUEUE,tcp_send_rcvq()similarly callsskb_copy_datagram_from_iter(), byte-copying from the iterator.Neither path supports or makes sense for devmem transmission. Reject devmem sends inside the Fast Open and TCP repair branches when a devmem binding is present. Checking inside the
tp->repairbranch also covers the case where repair mode is enabled whilesk_stream_wait_connect()drops the socket lock.Additionally, drop the !sockc_err gate from the devmem validation check and return
sockc_errif set. Otherwise, if a validSCM_DEVMEM_DMABUFis followed by a failing cmsg, sockc.dmabuf_id remains set while binding is not acquired, allowing the Fast Open andTCP_RECV_QUEUErepair paths to proceed and return beforesockc_erris checked.This pre-existing issue was identified by Sashiko AI review on commit
125755776bc6("tcp: reject non zerocopy devmem tx") and has not been hit in production.Fixes 125755776bc6 ("tcp: reject non zerocopy devmem tx")Fixes bd61848900bf ("net: devmem: Implement TX path")Reviewed-by Mina Almasry <[email protected]>Signed-off-by Kaifeng Wang <[email protected]>
Quoted 8 lines
---
v1 -> v2:
- Move the devmem rejection checks into the Fast Open and TCP repair branches directly, also covering the case wheretp->repairis enabled whilesk_stream_wait_connect()drops the socket lock.
- Drop the !sockc_err gate from the devmem validation check and returnsockc_errif set, preventing a validSCM_DEVMEM_DMABUFfollowed by a failing cmsg from bypassing the check.
Paolo Abeni
maintainerAdding Eric (for real) and Kuniyuki
Quoted 76 lines · Kaifeng Wang
tcp_sendmsg_locked()enforces that devmem TX can only proceed if the zero-copy path is active and a valid dmabuf binding exists. However, subsequent branches intcp_sendmsg_locked()can still intercept the message before it reaches the devmem zero-copy loop:1. TCP Fast Open (
MSG_FASTOPENorDEFER_CONNECT):
IfTCP_FASTOPEN_CONNECTis set, the socket may have a valid dst withNETIF_F_SG(so zc ==MSG_ZEROCOPYand binding is present), buttcp_sendmsg_fastopen()->tcp_send_syn_data()will usecopy_page_from_iter()to byte-copy from the iterator. Sinceiov_baserepresents dma-buf offsets rather than user virtual addresses, this misinterprets offsets as user pointers and copies the caller's memory at those addresses into the SYN packet.2. TCP repair mode:
Iftp->repairis enabled withTCP_RECV_QUEUE,tcp_send_rcvq()similarly callsskb_copy_datagram_from_iter(), byte-copying from the iterator.Neither path supports or makes sense for devmem transmission. Reject devmem sends inside the Fast Open and TCP repair branches when a devmem binding is present. Checking inside the
tp->repairbranch also covers the case where repair mode is enabled whilesk_stream_wait_connect()drops the socket lock.Additionally, drop the !sockc_err gate from the devmem validation check and return
sockc_errif set. Otherwise, if a validSCM_DEVMEM_DMABUFis followed by a failing cmsg, sockc.dmabuf_id remains set while binding is not acquired, allowing the Fast Open andTCP_RECV_QUEUErepair paths to proceed and return beforesockc_erris checked.This pre-existing issue was identified by Sashiko AI review on commit
125755776bc6("tcp: reject non zerocopy devmem tx") and has not been hit in production.Fixes 125755776bc6 ("tcp: reject non zerocopy devmem tx")Fixes bd61848900bf ("net: devmem: Implement TX path")Reviewed-by Mina Almasry <[email protected]>Signed-off-by Kaifeng Wang <[email protected]>---
v1 -> v2:
- Move the devmem rejection checks into the Fast Open and TCP repair branches directly, also covering the case wheretp->repairis enabled whilesk_stream_wait_connect()drops the socket lock.
- Drop the !sockc_err gate from the devmem validation check and returnsockc_errif set, preventing a validSCM_DEVMEM_DMABUFfollowed by a failing cmsg from bypassing the check.net/ipv4/tcp.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)net/ipv4/tcp.c +6
-2@@ -1169,14 +1169,18 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) zc =MSG_SPLICE_PAGES ; } -if (!sockc_err && sockc.dmabuf_id && (zc !=MSG_ZEROCOPY || !binding)) { - err = -EINVAL ; +if (sockc.dmabuf_id && (zc !=MSG_ZEROCOPY || !binding)) { + err = sockc_err ?: -EINVAL ; goto out_err; }if (unlikely (flags &MSG_FASTOPEN ||inet_test_bit (DEFER_CONNECT , sk)) && !tp->repair) { +if (binding) { + err = -EINVAL ; + goto out_err; + } err =tcp_sendmsg_fastopen (sk, msg, &copied_syn, size, uarg);if (err == -EINPROGRESS && copied_syn >0 ) goto out;
net/ipv4/tcp.c int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) · line 1213
Quoted 10 lines
net/ipv4/tcp.c +4
-0@@ -1200,6 +1204,10 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) }if (unlikely (tp->repair)) { +if (binding) { + err = -EINVAL ; + goto out_err; + }if (tp->repair_queue ==TCP_RECV_QUEUE ) { copied =tcp_send_rcvq (sk, msg, size); goto out_nopush;
The ever increasing number of conditionals is a bit concerning, but I don't see how to avoid the new ones.
/P
Quoted 2 lines · Paolo Abeni
Adding Eric (for real) and Kuniyuki
Thanks Paolo.
Quoted 20 lines · Kaifeng Wang
Quoted 18 lines
tcp_sendmsg_locked()enforces that devmem TX can only proceed if the zero-copy path is active and a valid dmabuf binding exists. However, subsequent branches intcp_sendmsg_locked()can still intercept the message before it reaches the devmem zero-copy loop:1. TCP Fast Open (
MSG_FASTOPENorDEFER_CONNECT):
IfTCP_FASTOPEN_CONNECTis set, the socket may have a valid dst withNETIF_F_SG(so zc ==MSG_ZEROCOPYand binding is present), buttcp_sendmsg_fastopen()->tcp_send_syn_data()will usecopy_page_from_iter()to byte-copy from the iterator. Sinceiov_baserepresents dma-buf offsets rather than user virtual addresses, this misinterprets offsets as user pointers and copies the caller's memory at those addresses into the SYN packet.2. TCP repair mode:
Iftp->repairis enabled withTCP_RECV_QUEUE,tcp_send_rcvq()similarly callsskb_copy_datagram_from_iter(), byte-copying from the iterator.
Quoted 5 lines
Quoted 5 lines
Neither path supports or makes sense for devmem transmission. Reject devmem sends inside the Fast Open and TCP repair branches when a devmem binding is present. Checking inside the
tp->repairbranch also covers the case where repair mode is enabled whilesk_stream_wait_connect()drops the socket lock.
Note that the check in the tp->repair branch also rejects TCP_SEND_QUEUE, not only TCP_RECV_QUEUE. This is fine (a devmem binding can not be restored by CRIU anyway), but the changelog could say so.
Also, an application using TCP_FASTOPEN_CONNECT will now get -EINVAL on its first devmem sendmsg(), and the SYN is not sent. Again fine for a net fix, just worth being aware of.
Quoted 55 lines
Quoted 55 lines
Additionally, drop the !sockc_err gate from the devmem validation check and return
sockc_errif set. Otherwise, if a validSCM_DEVMEM_DMABUFis followed by a failing cmsg, sockc.dmabuf_id remains set while binding is not acquired, allowing the Fast Open andTCP_RECV_QUEUErepair paths to proceed and return beforesockc_erris checked.This pre-existing issue was identified by Sashiko AI review on commit
125755776bc6("tcp: reject non zerocopy devmem tx") and has not been hit in production.Fixes 125755776bc6 ("tcp: reject non zerocopy devmem tx")Fixes bd61848900bf ("net: devmem: Implement TX path")Reviewed-by Mina Almasry <[email protected]>Signed-off-by Kaifeng Wang <[email protected]>---
v1 -> v2:
- Move the devmem rejection checks into the Fast Open and TCP repair branches directly, also covering the case wheretp->repairis enabled whilesk_stream_wait_connect()drops the socket lock.
- Drop the !sockc_err gate from the devmem validation check and returnsockc_errif set, preventing a validSCM_DEVMEM_DMABUFfollowed by a failing cmsg from bypassing the check.net/ipv4/tcp.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)net/ipv4/tcp.c +6
-2@@ -1169,14 +1169,18 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) zc =MSG_SPLICE_PAGES ; } -if (!sockc_err && sockc.dmabuf_id && (zc !=MSG_ZEROCOPY || !binding)) { - err = -EINVAL ; +if (sockc.dmabuf_id && (zc !=MSG_ZEROCOPY || !binding)) { + err = sockc_err ?: -EINVAL ; goto out_err; }if (unlikely (flags &MSG_FASTOPEN ||inet_test_bit (DEFER_CONNECT , sk)) && !tp->repair) { +if (binding) { + err = -EINVAL ; + goto out_err; + } err =tcp_sendmsg_fastopen (sk, msg, &copied_syn, size, uarg);if (err == -EINPROGRESS && copied_syn >0 ) goto out;@@ -1200,6 +1204,10 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) }
Quoted 11 lines
net/ipv4/tcp.c int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) · line 1213
Quoted 8 lines
net/ipv4/tcp.c +4
-0if (unlikely (tp->repair)) { +if (binding) { + err = -EINVAL ; + goto out_err; + }if (tp->repair_queue ==TCP_RECV_QUEUE ) { copied =tcp_send_rcvq (sk, msg, size); goto out_nopush;The ever increasing number of conditionals is a bit concerning, but I don't see how to avoid the new ones.
Yes. sendmsg() has been hijacked by so many slow path components.
At least this patch only adds code in unlikely() branches.
Thanks.
Quoted 55 lines · Kaifeng Wang
tcp_sendmsg_locked()enforces that devmem TX can only proceed if the zero-copy path is active and a valid dmabuf binding exists. However, subsequent branches intcp_sendmsg_locked()can still intercept the message before it reaches the devmem zero-copy loop:1. TCP Fast Open (
MSG_FASTOPENorDEFER_CONNECT):
IfTCP_FASTOPEN_CONNECTis set, the socket may have a valid dst withNETIF_F_SG(so zc ==MSG_ZEROCOPYand binding is present), buttcp_sendmsg_fastopen()->tcp_send_syn_data()will usecopy_page_from_iter()to byte-copy from the iterator. Sinceiov_baserepresents dma-buf offsets rather than user virtual addresses, this misinterprets offsets as user pointers and copies the caller's memory at those addresses into the SYN packet.2. TCP repair mode:
Iftp->repairis enabled withTCP_RECV_QUEUE,tcp_send_rcvq()similarly callsskb_copy_datagram_from_iter(), byte-copying from the iterator.Neither path supports or makes sense for devmem transmission. Reject devmem sends inside the Fast Open and TCP repair branches when a devmem binding is present. Checking inside the
tp->repairbranch also covers the case where repair mode is enabled whilesk_stream_wait_connect()drops the socket lock.Additionally, drop the !sockc_err gate from the devmem validation check and return
sockc_errif set. Otherwise, if a validSCM_DEVMEM_DMABUFis followed by a failing cmsg, sockc.dmabuf_id remains set while binding is not acquired, allowing the Fast Open andTCP_RECV_QUEUErepair paths to proceed and return beforesockc_erris checked.This pre-existing issue was identified by Sashiko AI review on commit
125755776bc6("tcp: reject non zerocopy devmem tx") and has not been hit in production.Fixes 125755776bc6 ("tcp: reject non zerocopy devmem tx")Fixes bd61848900bf ("net: devmem: Implement TX path")Reviewed-by Mina Almasry <[email protected]>Signed-off-by Kaifeng Wang <[email protected]>---
v1 -> v2:
- Move the devmem rejection checks into the Fast Open and TCP repair branches directly, also covering the case wheretp->repairis enabled whilesk_stream_wait_connect()drops the socket lock.
- Drop the !sockc_err gate from the devmem validation check and returnsockc_errif set, preventing a validSCM_DEVMEM_DMABUFfollowed by a failing cmsg from bypassing the check.net/ipv4/tcp.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)net/ipv4/tcp.c +0
-0
net/ipv4/tcp.c int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) · line 1172
Quoted 6 lines
net/ipv4/tcp.c +1
-2@@ -1169,14 +1169,18 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) zc =MSG_SPLICE_PAGES ; } -if (!sockc_err && sockc.dmabuf_id && (zc !=MSG_ZEROCOPY || !binding)) { - err = -EINVAL ; +if (sockc.dmabuf_id && (zc !=MSG_ZEROCOPY || !binding)) {
I wonder why it does sockc_err checks like that for devmem, e.g. instead of failing earlier. Maybe Mina remembers?
Quoted 15 lines
net/ipv4/tcp.c +5
-0+ err = sockc_err ?: -EINVAL ; goto out_err; }if (unlikely (flags &MSG_FASTOPEN ||inet_test_bit (DEFER_CONNECT , sk)) && !tp->repair) { +if (binding) { + err = -EINVAL ; + goto out_err; + } err =tcp_sendmsg_fastopen (sk, msg, &copied_syn, size, uarg);if (err == -EINPROGRESS && copied_syn >0 ) goto out;
net/ipv4/tcp.c int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) · line 1213
Quoted 10 lines
net/ipv4/tcp.c +4
-0@@ -1200,6 +1204,10 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) }if (unlikely (tp->repair)) { +if (binding) { + err = -EINVAL ; + goto out_err; + }if (tp->repair_queue ==TCP_RECV_QUEUE ) { copied =tcp_send_rcvq (sk, msg, size); goto out_nopush;
Signature · 1 line
Pavel Begunkov
Quoted 60 lines · Pavel Begunkov
Quoted 58 lines · Kaifeng Wang
tcp_sendmsg_locked()enforces that devmem TX can only proceed if the zero-copy path is active and a valid dmabuf binding exists. However, subsequent branches intcp_sendmsg_locked()can still intercept the message before it reaches the devmem zero-copy loop:1. TCP Fast Open (
MSG_FASTOPENorDEFER_CONNECT):
IfTCP_FASTOPEN_CONNECTis set, the socket may have a valid dst withNETIF_F_SG(so zc ==MSG_ZEROCOPYand binding is present), buttcp_sendmsg_fastopen()->tcp_send_syn_data()will usecopy_page_from_iter()to byte-copy from the iterator. Sinceiov_baserepresents dma-buf offsets rather than user virtual addresses, this misinterprets offsets as user pointers and copies the caller's memory at those addresses into the SYN packet.2. TCP repair mode:
Iftp->repairis enabled withTCP_RECV_QUEUE,tcp_send_rcvq()similarly callsskb_copy_datagram_from_iter(), byte-copying from the iterator.Neither path supports or makes sense for devmem transmission. Reject devmem sends inside the Fast Open and TCP repair branches when a devmem binding is present. Checking inside the
tp->repairbranch also covers the case where repair mode is enabled whilesk_stream_wait_connect()drops the socket lock.Additionally, drop the !sockc_err gate from the devmem validation check and return
sockc_errif set. Otherwise, if a validSCM_DEVMEM_DMABUFis followed by a failing cmsg, sockc.dmabuf_id remains set while binding is not acquired, allowing the Fast Open andTCP_RECV_QUEUErepair paths to proceed and return beforesockc_erris checked.This pre-existing issue was identified by Sashiko AI review on commit
125755776bc6("tcp: reject non zerocopy devmem tx") and has not been hit in production.Fixes 125755776bc6 ("tcp: reject non zerocopy devmem tx")Fixes bd61848900bf ("net: devmem: Implement TX path")Reviewed-by Mina Almasry <[email protected]>Signed-off-by Kaifeng Wang <[email protected]>---
v1 -> v2:
- Move the devmem rejection checks into the Fast Open and TCP repair branches directly, also covering the case wheretp->repairis enabled whilesk_stream_wait_connect()drops the socket lock.
- Drop the !sockc_err gate from the devmem validation check and returnsockc_errif set, preventing a validSCM_DEVMEM_DMABUFfollowed by a failing cmsg from bypassing the check.net/ipv4/tcp.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)net/ipv4/tcp.c +0
-0@@ -1169,14 +1169,18 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) zc =MSG_SPLICE_PAGES ; }
Quoted 6 lines
net/ipv4/tcp.c int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) · line 1172
Quoted 3 lines
net/ipv4/tcp.c +1
-2-if (!sockc_err && sockc.dmabuf_id && (zc !=MSG_ZEROCOPY || !binding)) { - err = -EINVAL ; +if (sockc.dmabuf_id && (zc !=MSG_ZEROCOPY || !binding)) {I wonder why it does
sockc_errchecks like that for devmem, e.g. instead of failing earlier. Maybe Mina remembers?
IIRC, Paolo caught an issue where we were subtely changing behavior. Like if someone passes in a bad sockc flags, it's usually ignored, but if we process the sockc_err before we need it for devmem we change behavior for existing users that were passing bad sockc but not using devmem.
Signature · 2 lines
Thanks, Mina
Quoted 1 line · Mina Almasry
On Wed, Oct 21, 2026 at 8:17 AM Pavel Begunkov <[email protected]> wrote:
...>>> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
Quoted 14 lines
Quoted 7 lines
Quoted 7 lines
index
87ef6d5cbfeb..2792923f0748100644net/ipv4/tcp.c +0
-0@@ -1169,14 +1169,18 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) zc =MSG_SPLICE_PAGES ; }Quoted 6 lines
net/ipv4/tcp.c int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) · line 1172
Quoted 3 lines
net/ipv4/tcp.c +1
-2-if (!sockc_err && sockc.dmabuf_id && (zc !=MSG_ZEROCOPY || !binding)) { - err = -EINVAL ; +if (sockc.dmabuf_id && (zc !=MSG_ZEROCOPY || !binding)) {I wonder why it does
sockc_errchecks like that for devmem, e.g. instead of failing earlier. Maybe Mina remembers?
Quoted 5 lines
IIRC, Paolo caught an issue where we were subtely changing behavior. Like if someone passes in a bad sockc flags, it's usually ignored, but if we process the
sockc_errbefore we need it for devmem we change behavior for existing users that were passing bad sockc but not using devmem.
Got the idea, thanks. Sounds like this chunk can potentially change it in the same way, though I'd need to look up that thread with Paolo to be sure.
Signature · 1 line
Pavel Begunkov
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 14 lines · On Mon, 19 Oct 2026 17:45:22 +0000 you wrote:
tcp_sendmsg_locked()enforces that devmem TX can only proceed if the zero-copy path is active and a valid dmabuf binding exists. However, subsequent branches intcp_sendmsg_locked()can still intercept the message before it reaches the devmem zero-copy loop:1. TCP Fast Open (
MSG_FASTOPENorDEFER_CONNECT):
IfTCP_FASTOPEN_CONNECTis set, the socket may have a valid dst withNETIF_F_SG(so zc ==MSG_ZEROCOPYand binding is present), buttcp_sendmsg_fastopen()->tcp_send_syn_data()will usecopy_page_from_iter()to byte-copy from the iterator. Sinceiov_baserepresents dma-buf offsets rather than user virtual addresses, this misinterprets offsets as user pointers and copies the caller's memory at those addresses into the SYN packet.
Quoted 1 line
[...]
Here is the summary with links:
- [net,v2] tcp: reject devmem tx with fastopen and repair
https://git.kernel.org/netdev/net/c/89b9db72918b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html