inet: add RCU protection to inet->opt
We lack proper synchronization to manipulate inet->opt ip_options Problem is ip_make_skb() calls ip_setup_cork() and ip_setup_cork() possibly makes a copy of ipc->opt (struct ip_options), without any protection against another thread manipulating inet->opt. Another thread can change inet->opt pointer and free old one under us. Use RCU to protect inet->opt (changed to inet->inet_opt). Instead of handling atomic refcounts, just copy ip_options when necessary, to avoid cache line dirtying. We cant insert an rcu_head in struct ip_options since its included in skb->cb[], so this patch is large because I had to introduce a new ip_options_rcu structure. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Cc: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
Este commit está contenido en:

cometido por
David S. Miller

padre
0a14842f5a
commit
f6d8bd051c
@@ -48,6 +48,7 @@ int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
|
||||
struct flowi4 fl4;
|
||||
struct rtable *rt;
|
||||
int err;
|
||||
struct ip_options_rcu *inet_opt;
|
||||
|
||||
dp->dccps_role = DCCP_ROLE_CLIENT;
|
||||
|
||||
@@ -58,10 +59,13 @@ int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
|
||||
return -EAFNOSUPPORT;
|
||||
|
||||
nexthop = daddr = usin->sin_addr.s_addr;
|
||||
if (inet->opt != NULL && inet->opt->srr) {
|
||||
|
||||
inet_opt = rcu_dereference_protected(inet->inet_opt,
|
||||
sock_owned_by_user(sk));
|
||||
if (inet_opt != NULL && inet_opt->opt.srr) {
|
||||
if (daddr == 0)
|
||||
return -EINVAL;
|
||||
nexthop = inet->opt->faddr;
|
||||
nexthop = inet_opt->opt.faddr;
|
||||
}
|
||||
|
||||
orig_sport = inet->inet_sport;
|
||||
@@ -78,7 +82,7 @@ int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
|
||||
return -ENETUNREACH;
|
||||
}
|
||||
|
||||
if (inet->opt == NULL || !inet->opt->srr)
|
||||
if (inet_opt == NULL || !inet_opt->opt.srr)
|
||||
daddr = rt->rt_dst;
|
||||
|
||||
if (inet->inet_saddr == 0)
|
||||
@@ -89,8 +93,8 @@ int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
|
||||
inet->inet_daddr = daddr;
|
||||
|
||||
inet_csk(sk)->icsk_ext_hdr_len = 0;
|
||||
if (inet->opt != NULL)
|
||||
inet_csk(sk)->icsk_ext_hdr_len = inet->opt->optlen;
|
||||
if (inet_opt)
|
||||
inet_csk(sk)->icsk_ext_hdr_len = inet_opt->opt.optlen;
|
||||
/*
|
||||
* Socket identity is still unknown (sport may be zero).
|
||||
* However we set state to DCCP_REQUESTING and not releasing socket
|
||||
@@ -405,7 +409,7 @@ struct sock *dccp_v4_request_recv_sock(struct sock *sk, struct sk_buff *skb,
|
||||
newinet->inet_daddr = ireq->rmt_addr;
|
||||
newinet->inet_rcv_saddr = ireq->loc_addr;
|
||||
newinet->inet_saddr = ireq->loc_addr;
|
||||
newinet->opt = ireq->opt;
|
||||
newinet->inet_opt = ireq->opt;
|
||||
ireq->opt = NULL;
|
||||
newinet->mc_index = inet_iif(skb);
|
||||
newinet->mc_ttl = ip_hdr(skb)->ttl;
|
||||
|
@@ -573,7 +573,7 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk,
|
||||
|
||||
First: no IPv4 options.
|
||||
*/
|
||||
newinet->opt = NULL;
|
||||
newinet->inet_opt = NULL;
|
||||
|
||||
/* Clone RX bits */
|
||||
newnp->rxopt.all = np->rxopt.all;
|
||||
|
Referencia en una nueva incidencia
Block a user