aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2014-04-11 16:15:36 -0400
committerDavid S. Miller <davem@davemloft.net>2014-04-11 16:15:36 -0400
commit676d23690fb62b5d51ba5d659935e9f7d9da9f8e (patch)
treef6fbceee43e05c724868153ca37b702fb5e43b8c /fs
parentad20d5f673898578f9d8a156d7a4c921f5ca4584 (diff)
net: Fix use after free by removing length arg from sk_data_ready callbacks.
Several spots in the kernel perform a sequence like: skb_queue_tail(&sk->s_receive_queue, skb); sk->sk_data_ready(sk, skb->len); But at the moment we place the SKB onto the socket receive queue it can be consumed and freed up. So this skb->len access is potentially to freed up memory. Furthermore, the skb->len can be modified by the consumer so it is possible that the value isn't accurate. And finally, no actual implementation of this callback actually uses the length argument. And since nobody actually cared about it's value, lots of call sites pass arbitrary values in such as '0' and even '1'. So just remove the length argument from the callback, that way there is no confusion whatsoever and all of these use-after-free cases get fixed as a side effect. Based upon a patch by Eric Dumazet and his suggestion to audit this issue tree-wide. Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'fs')
-rw-r--r--fs/dlm/lowcomms.c2
-rw-r--r--fs/ncpfs/ncp_fs_sb.h4
-rw-r--r--fs/ncpfs/sock.c4
-rw-r--r--fs/ocfs2/cluster/tcp.c15
-rw-r--r--fs/ocfs2/cluster/tcp_internal.h2
5 files changed, 13 insertions, 14 deletions
diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c
index 3190ca973dd6..1e5b45359509 100644
--- a/fs/dlm/lowcomms.c
+++ b/fs/dlm/lowcomms.c
@@ -424,7 +424,7 @@ int dlm_lowcomms_addr(int nodeid, struct sockaddr_storage *addr, int len)
424} 424}
425 425
426/* Data available on socket or listen socket received a connect */ 426/* Data available on socket or listen socket received a connect */
427static void lowcomms_data_ready(struct sock *sk, int count_unused) 427static void lowcomms_data_ready(struct sock *sk)
428{ 428{
429 struct connection *con = sock2con(sk); 429 struct connection *con = sock2con(sk);
430 if (con && !test_and_set_bit(CF_READ_PENDING, &con->flags)) 430 if (con && !test_and_set_bit(CF_READ_PENDING, &con->flags))
diff --git a/fs/ncpfs/ncp_fs_sb.h b/fs/ncpfs/ncp_fs_sb.h
index b81e97adc5a9..fbb08818775e 100644
--- a/fs/ncpfs/ncp_fs_sb.h
+++ b/fs/ncpfs/ncp_fs_sb.h
@@ -111,7 +111,7 @@ struct ncp_server {
111 111
112 spinlock_t requests_lock; /* Lock accesses to tx.requests, tx.creq and rcv.creq when STREAM mode */ 112 spinlock_t requests_lock; /* Lock accesses to tx.requests, tx.creq and rcv.creq when STREAM mode */
113 113
114 void (*data_ready)(struct sock* sk, int len); 114 void (*data_ready)(struct sock* sk);
115 void (*error_report)(struct sock* sk); 115 void (*error_report)(struct sock* sk);
116 void (*write_space)(struct sock* sk); /* STREAM mode only */ 116 void (*write_space)(struct sock* sk); /* STREAM mode only */
117 struct { 117 struct {
@@ -153,7 +153,7 @@ extern void ncp_tcp_tx_proc(struct work_struct *work);
153extern void ncpdgram_rcv_proc(struct work_struct *work); 153extern void ncpdgram_rcv_proc(struct work_struct *work);
154extern void ncpdgram_timeout_proc(struct work_struct *work); 154extern void ncpdgram_timeout_proc(struct work_struct *work);
155extern void ncpdgram_timeout_call(unsigned long server); 155extern void ncpdgram_timeout_call(unsigned long server);
156extern void ncp_tcp_data_ready(struct sock* sk, int len); 156extern void ncp_tcp_data_ready(struct sock* sk);
157extern void ncp_tcp_write_space(struct sock* sk); 157extern void ncp_tcp_write_space(struct sock* sk);
158extern void ncp_tcp_error_report(struct sock* sk); 158extern void ncp_tcp_error_report(struct sock* sk);
159 159
diff --git a/fs/ncpfs/sock.c b/fs/ncpfs/sock.c
index 3a1587222c8a..652da0db932c 100644
--- a/fs/ncpfs/sock.c
+++ b/fs/ncpfs/sock.c
@@ -96,11 +96,11 @@ static void ncp_req_put(struct ncp_request_reply *req)
96 kfree(req); 96 kfree(req);
97} 97}
98 98
99void ncp_tcp_data_ready(struct sock *sk, int len) 99void ncp_tcp_data_ready(struct sock *sk)
100{ 100{
101 struct ncp_server *server = sk->sk_user_data; 101 struct ncp_server *server = sk->sk_user_data;
102 102
103 server->data_ready(sk, len); 103 server->data_ready(sk);
104 schedule_work(&server->rcv.tq); 104 schedule_work(&server->rcv.tq);
105} 105}
106 106
diff --git a/fs/ocfs2/cluster/tcp.c b/fs/ocfs2/cluster/tcp.c
index eb649d23a4de..d857534b886e 100644
--- a/fs/ocfs2/cluster/tcp.c
+++ b/fs/ocfs2/cluster/tcp.c
@@ -137,7 +137,7 @@ static int o2net_sys_err_translations[O2NET_ERR_MAX] =
137static void o2net_sc_connect_completed(struct work_struct *work); 137static void o2net_sc_connect_completed(struct work_struct *work);
138static void o2net_rx_until_empty(struct work_struct *work); 138static void o2net_rx_until_empty(struct work_struct *work);
139static void o2net_shutdown_sc(struct work_struct *work); 139static void o2net_shutdown_sc(struct work_struct *work);
140static void o2net_listen_data_ready(struct sock *sk, int bytes); 140static void o2net_listen_data_ready(struct sock *sk);
141static void o2net_sc_send_keep_req(struct work_struct *work); 141static void o2net_sc_send_keep_req(struct work_struct *work);
142static void o2net_idle_timer(unsigned long data); 142static void o2net_idle_timer(unsigned long data);
143static void o2net_sc_postpone_idle(struct o2net_sock_container *sc); 143static void o2net_sc_postpone_idle(struct o2net_sock_container *sc);
@@ -597,9 +597,9 @@ static void o2net_set_nn_state(struct o2net_node *nn,
597} 597}
598 598
599/* see o2net_register_callbacks() */ 599/* see o2net_register_callbacks() */
600static void o2net_data_ready(struct sock *sk, int bytes) 600static void o2net_data_ready(struct sock *sk)
601{ 601{
602 void (*ready)(struct sock *sk, int bytes); 602 void (*ready)(struct sock *sk);
603 603
604 read_lock(&sk->sk_callback_lock); 604 read_lock(&sk->sk_callback_lock);
605 if (sk->sk_user_data) { 605 if (sk->sk_user_data) {
@@ -613,7 +613,7 @@ static void o2net_data_ready(struct sock *sk, int bytes)
613 } 613 }
614 read_unlock(&sk->sk_callback_lock); 614 read_unlock(&sk->sk_callback_lock);
615 615
616 ready(sk, bytes); 616 ready(sk);
617} 617}
618 618
619/* see o2net_register_callbacks() */ 619/* see o2net_register_callbacks() */
@@ -1953,9 +1953,9 @@ static void o2net_accept_many(struct work_struct *work)
1953 cond_resched(); 1953 cond_resched();
1954} 1954}
1955 1955
1956static void o2net_listen_data_ready(struct sock *sk, int bytes) 1956static void o2net_listen_data_ready(struct sock *sk)
1957{ 1957{
1958 void (*ready)(struct sock *sk, int bytes); 1958 void (*ready)(struct sock *sk);
1959 1959
1960 read_lock(&sk->sk_callback_lock); 1960 read_lock(&sk->sk_callback_lock);
1961 ready = sk->sk_user_data; 1961 ready = sk->sk_user_data;
@@ -1978,7 +1978,6 @@ static void o2net_listen_data_ready(struct sock *sk, int bytes)
1978 */ 1978 */
1979 1979
1980 if (sk->sk_state == TCP_LISTEN) { 1980 if (sk->sk_state == TCP_LISTEN) {
1981 mlog(ML_TCP, "bytes: %d\n", bytes);
1982 queue_work(o2net_wq, &o2net_listen_work); 1981 queue_work(o2net_wq, &o2net_listen_work);
1983 } else { 1982 } else {
1984 ready = NULL; 1983 ready = NULL;
@@ -1987,7 +1986,7 @@ static void o2net_listen_data_ready(struct sock *sk, int bytes)
1987out: 1986out:
1988 read_unlock(&sk->sk_callback_lock); 1987 read_unlock(&sk->sk_callback_lock);
1989 if (ready != NULL) 1988 if (ready != NULL)
1990 ready(sk, bytes); 1989 ready(sk);
1991} 1990}
1992 1991
1993static int o2net_open_listening_sock(__be32 addr, __be16 port) 1992static int o2net_open_listening_sock(__be32 addr, __be16 port)
diff --git a/fs/ocfs2/cluster/tcp_internal.h b/fs/ocfs2/cluster/tcp_internal.h
index 4cbcb65784a3..dc024367110a 100644
--- a/fs/ocfs2/cluster/tcp_internal.h
+++ b/fs/ocfs2/cluster/tcp_internal.h
@@ -165,7 +165,7 @@ struct o2net_sock_container {
165 165
166 /* original handlers for the sockets */ 166 /* original handlers for the sockets */
167 void (*sc_state_change)(struct sock *sk); 167 void (*sc_state_change)(struct sock *sk);
168 void (*sc_data_ready)(struct sock *sk, int bytes); 168 void (*sc_data_ready)(struct sock *sk);
169 169
170 u32 sc_msg_key; 170 u32 sc_msg_key;
171 u16 sc_msg_type; 171 u16 sc_msg_type;