Skip to content

Commit e24f7d5

Browse files
HexRabbitpelwell
authored andcommitted
xfrm: esp: avoid in-place decrypt on shared skb frags
commit f4c50a4 upstream. MSG_SPLICE_PAGES can attach pages from a pipe directly to an skb. TCP marks such skbs with SKBFL_SHARED_FRAG after skb_splice_from_iter(), so later paths that may modify packet data can first make a private copy. The IPv4/IPv6 datagram append paths did not set this flag when splicing pages into UDP skbs. That leaves an ESP-in-UDP packet made from shared pipe pages looking like an ordinary uncloned nonlinear skb. ESP input then takes the no-COW fast path for uncloned skbs without a frag_list and decrypts in place over data that is not owned privately by the skb. Mark IPv4/IPv6 datagram splice frags with SKBFL_SHARED_FRAG, matching TCP. Also make ESP input fall back to skb_cow_data() when the flag is present, so ESP does not decrypt externally backed frags in place. Private nonlinear skb frags still use the existing fast path. This intentionally does not change ESP output. In esp_output_head(), the path that appends the ESP trailer to existing skb tailroom without calling skb_cow_data() is not reachable for nonlinear skbs: skb_tailroom() returns zero when skb->data_len is nonzero, while ESP tailen is positive. Thus ESP output will either use the separate destination-frag path or fall back to skb_cow_data(). Fixes: cac2661 ("esp4: Avoid skb_cow_data whenever possible") Fixes: 03e2a30 ("esp6: Avoid skb_cow_data whenever possible") Fixes: 7da0dde ("ip, udp: Support MSG_SPLICE_PAGES") Fixes: 6d8192b ("ip6, udp6: Support MSG_SPLICE_PAGES") Reported-by: Hyunwoo Kim <imv4bel@gmail.com> Reported-by: Kuan-Ting Chen <h3xrabbit@gmail.com> Tested-by: Hyunwoo Kim <imv4bel@gmail.com> Cc: stable@vger.kernel.org Signed-off-by: Kuan-Ting Chen <h3xrabbit@gmail.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c5183a0 commit e24f7d5

4 files changed

Lines changed: 8 additions & 2 deletions

File tree

net/ipv4/esp4.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,8 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb)
873873
nfrags = 1;
874874

875875
goto skip_cow;
876-
} else if (!skb_has_frag_list(skb)) {
876+
} else if (!skb_has_frag_list(skb) &&
877+
!skb_has_shared_frag(skb)) {
877878
nfrags = skb_shinfo(skb)->nr_frags;
878879
nfrags++;
879880

net/ipv4/ip_output.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,8 @@ static int __ip_append_data(struct sock *sk,
12331233
if (err < 0)
12341234
goto error;
12351235
copy = err;
1236+
if (!(flags & MSG_NO_SHARED_FRAGS))
1237+
skb_shinfo(skb)->flags |= SKBFL_SHARED_FRAG;
12361238
wmem_alloc_delta += copy;
12371239
} else if (!zc) {
12381240
int i = skb_shinfo(skb)->nr_frags;

net/ipv6/esp6.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,8 @@ static int esp6_input(struct xfrm_state *x, struct sk_buff *skb)
915915
nfrags = 1;
916916

917917
goto skip_cow;
918-
} else if (!skb_has_frag_list(skb)) {
918+
} else if (!skb_has_frag_list(skb) &&
919+
!skb_has_shared_frag(skb)) {
919920
nfrags = skb_shinfo(skb)->nr_frags;
920921
nfrags++;
921922

net/ipv6/ip6_output.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,8 @@ static int __ip6_append_data(struct sock *sk,
17651765
if (err < 0)
17661766
goto error;
17671767
copy = err;
1768+
if (!(flags & MSG_NO_SHARED_FRAGS))
1769+
skb_shinfo(skb)->flags |= SKBFL_SHARED_FRAG;
17681770
wmem_alloc_delta += copy;
17691771
} else if (!zc) {
17701772
int i = skb_shinfo(skb)->nr_frags;

0 commit comments

Comments
 (0)