Fix for race condition introduced by the temporary drop of the socket lock in skb_splice_bits.
Subsystems (3)
PATCH 1/1 Fix for race condition introduced by the temporary drop of the socket lock in skb_splice_bits.
Hi David,
This patch applies to 2.6.25 and fixes the crashes in tcp_read_sock and skb_splice_bits reported on the mailing list earlier.
Thanks,
tavi
Quoted 1 line
From
e701750462892024a2260fd344aa9ef9900f4454Mon Sep 17 00:00:00 2001
From: Octavian Purdila <[email protected]>
Date: Wed, 28 May 2008 22:14:56 +0300
Subject: [PATCH] Fix for race condition introduced by the temporary drop of the socket
lock in skb_splice_bits.
skb_splice_bits temporary drops the socket lock while iterating over the socket queue in order to break a reverse locking condition which happens with sendfile. This, however, opens a window of opportunity for tcp_collapse() to aggregate skbs and thus potentially free the current skb used in skb_splice_bits and tcp_read_sock.
This patch fixes the problem by (re-)getting the same "logical skb" after the lock has been temporary dropped.
Based on idea and initial patch from Evgeniy Polyakov.
--- net/core/skbuff.c | 5 +++-- net/ipv4/tcp.c | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-)
net/core/skbuff.c +3 -2
@@ -1358,6 +1358,7 @@ done:if (spd.nr_pages) {int ret; +struct sock *sk = __skb->sk;/* * Drop the socket lock, otherwise we have reverse
@@ -1368,9 +1369,9 @@ done:* we call into ->sendpage() with the i_mutex lock held * and networking will grab the socket lock. */ -release_sock (__skb->sk); +release_sock (sk); ret =splice_to_pipe (pipe, &spd); -lock_sock (__skb->sk); +lock_sock (sk);return ret; }
net/ipv4/tcp.c +8 -1
@@ -1227,7 +1227,14 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc, copied += used; offset += used; } -if (offset != skb->len) +/* +* If recv_actor drops the lock (e.g. TCP splice +* receive) the skb pointer might be invalid when +* getting here: tcp_collapse might have deleted it +* while aggregating skbs from the socket queue. +*/ + skb =tcp_recv_skb (sk, seq-1 , &offset); +if (!skb || (offset+1 != skb->len))break ; }if (tcp_hdr (skb)->fin) {
Signature · 1 line
1.5.4.3
Quoted 2 lines · Octavian Purdila
This patch applies to 2.6.25 and fixes the crashes in
tcp_read_sockandskb_splice_bitsreported on the mailing list earlier.
Ack :)
Signature · 1 line
Evgeniy Polyakov
Re: [PATCH] Fix for race condition_introduced_by_the_temporary_drop_of_the_socket_ lock in skb_splice_bits.
From: Evgeniy Polyakov <[email protected]>
Date: Thu, 29 May 2008 00:05:04 +0400
Quoted 5 lines · Octavian Purdila
Quoted 2 lines
This patch applies to 2.6.25 and fixes the crashes in
tcp_read_sockandskb_splice_bitsreported on the mailing list earlier.Ack :)
Applied, thanks everyone.