Skip to content

Commit b0270e9

Browse files
edumazetdavem330
authored andcommitted
ipv4: add a sock pointer to ip_queue_xmit()
ip_queue_xmit() assumes the skb it has to transmit is attached to an inet socket. Commit 31c70d5 ("l2tp: keep original skb ownership") changed l2tp to not change skb ownership and thus broke this assumption. One fix is to add a new 'struct sock *sk' parameter to ip_queue_xmit(), so that we do not assume skb->sk points to the socket used by l2tp tunnel. Fixes: 31c70d5 ("l2tp: keep original skb ownership") Reported-by: Zhan Jianyu <[email protected]> Tested-by: Zhan Jianyu <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1dd333f commit b0270e9

File tree

10 files changed

+13
-13
lines changed

10 files changed

+13
-13
lines changed

include/net/inet6_connection_sock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void inet6_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req,
4040

4141
void inet6_csk_addr2sockaddr(struct sock *sk, struct sockaddr *uaddr);
4242

43-
int inet6_csk_xmit(struct sk_buff *skb, struct flowi *fl);
43+
int inet6_csk_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl);
4444

4545
struct dst_entry *inet6_csk_update_pmtu(struct sock *sk, u32 mtu);
4646
#endif /* _INET6_CONNECTION_SOCK_H */

include/net/inet_connection_sock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct tcp_congestion_ops;
3636
* (i.e. things that depend on the address family)
3737
*/
3838
struct inet_connection_sock_af_ops {
39-
int (*queue_xmit)(struct sk_buff *skb, struct flowi *fl);
39+
int (*queue_xmit)(struct sock *sk, struct sk_buff *skb, struct flowi *fl);
4040
void (*send_check)(struct sock *sk, struct sk_buff *skb);
4141
int (*rebuild_header)(struct sock *sk);
4242
void (*sk_rx_dst_set)(struct sock *sk, const struct sk_buff *skb);

include/net/ip.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ int ip_do_nat(struct sk_buff *skb);
111111
void ip_send_check(struct iphdr *ip);
112112
int __ip_local_out(struct sk_buff *skb);
113113
int ip_local_out(struct sk_buff *skb);
114-
int ip_queue_xmit(struct sk_buff *skb, struct flowi *fl);
114+
int ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl);
115115
void ip_init(void);
116116
int ip_append_data(struct sock *sk, struct flowi4 *fl4,
117117
int getfrag(void *from, char *to, int offset, int len,

net/dccp/output.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static int dccp_transmit_skb(struct sock *sk, struct sk_buff *skb)
138138

139139
DCCP_INC_STATS(DCCP_MIB_OUTSEGS);
140140

141-
err = icsk->icsk_af_ops->queue_xmit(skb, &inet->cork.fl);
141+
err = icsk->icsk_af_ops->queue_xmit(sk, skb, &inet->cork.fl);
142142
return net_xmit_eval(err);
143143
}
144144
return -ENOBUFS;

net/ipv4/ip_output.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ static void ip_copy_addrs(struct iphdr *iph, const struct flowi4 *fl4)
315315
sizeof(fl4->saddr) + sizeof(fl4->daddr));
316316
}
317317

318-
int ip_queue_xmit(struct sk_buff *skb, struct flowi *fl)
318+
/* Note: skb->sk can be different from sk, in case of tunnels */
319+
int ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl)
319320
{
320-
struct sock *sk = skb->sk;
321321
struct inet_sock *inet = inet_sk(sk);
322322
struct ip_options_rcu *inet_opt;
323323
struct flowi4 *fl4;
@@ -389,6 +389,7 @@ int ip_queue_xmit(struct sk_buff *skb, struct flowi *fl)
389389
ip_select_ident_more(skb, &rt->dst, sk,
390390
(skb_shinfo(skb)->gso_segs ?: 1) - 1);
391391

392+
/* TODO : should we use skb->sk here instead of sk ? */
392393
skb->priority = sk->sk_priority;
393394
skb->mark = sk->sk_mark;
394395

net/ipv4/tcp_output.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
981981
TCP_ADD_STATS(sock_net(sk), TCP_MIB_OUTSEGS,
982982
tcp_skb_pcount(skb));
983983

984-
err = icsk->icsk_af_ops->queue_xmit(skb, &inet->cork.fl);
984+
err = icsk->icsk_af_ops->queue_xmit(sk, skb, &inet->cork.fl);
985985
if (likely(err <= 0))
986986
return err;
987987

net/ipv6/inet6_connection_sock.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,8 @@ static struct dst_entry *inet6_csk_route_socket(struct sock *sk,
224224
return dst;
225225
}
226226

227-
int inet6_csk_xmit(struct sk_buff *skb, struct flowi *fl_unused)
227+
int inet6_csk_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl_unused)
228228
{
229-
struct sock *sk = skb->sk;
230229
struct ipv6_pinfo *np = inet6_sk(sk);
231230
struct flowi6 fl6;
232231
struct dst_entry *dst;

net/l2tp/l2tp_core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,10 +1131,10 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb,
11311131
skb->local_df = 1;
11321132
#if IS_ENABLED(CONFIG_IPV6)
11331133
if (tunnel->sock->sk_family == PF_INET6 && !tunnel->v4mapped)
1134-
error = inet6_csk_xmit(skb, NULL);
1134+
error = inet6_csk_xmit(tunnel->sock, skb, NULL);
11351135
else
11361136
#endif
1137-
error = ip_queue_xmit(skb, fl);
1137+
error = ip_queue_xmit(tunnel->sock, skb, fl);
11381138

11391139
/* Update stats */
11401140
if (error >= 0) {

net/l2tp/l2tp_ip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ static int l2tp_ip_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
487487

488488
xmit:
489489
/* Queue the packet to IP for output */
490-
rc = ip_queue_xmit(skb, &inet->cork.fl);
490+
rc = ip_queue_xmit(sk, skb, &inet->cork.fl);
491491
rcu_read_unlock();
492492

493493
error:

net/sctp/protocol.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
957957

958958
SCTP_INC_STATS(sock_net(&inet->sk), SCTP_MIB_OUTSCTPPACKS);
959959

960-
return ip_queue_xmit(skb, &transport->fl);
960+
return ip_queue_xmit(&inet->sk, skb, &transport->fl);
961961
}
962962

963963
static struct sctp_af sctp_af_inet;

0 commit comments

Comments
 (0)