hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/dccp/ipv4.c
....@@ -1,13 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * net/dccp/ipv4.c
34 *
45 * An implementation of the DCCP protocol
56 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
6
- *
7
- * This program is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU General Public License
9
- * as published by the Free Software Foundation; either version
10
- * 2 of the License, or (at your option) any later version.
117 */
128
139 #include <linux/dccp.h>
....@@ -134,6 +130,8 @@
134130 * This unhashes the socket and releases the local port, if necessary.
135131 */
136132 dccp_set_state(sk, DCCP_CLOSED);
133
+ if (!(sk->sk_userlocks & SOCK_BINDADDR_LOCK))
134
+ inet_reset_saddr(sk);
137135 ip_rt_put(rt);
138136 sk->sk_route_caps = 0;
139137 inet->inet_dport = 0;
....@@ -231,7 +229,7 @@
231229 * check at all. A more general error queue to queue errors for later handling
232230 * is probably better.
233231 */
234
-static void dccp_v4_err(struct sk_buff *skb, u32 info)
232
+static int dccp_v4_err(struct sk_buff *skb, u32 info)
235233 {
236234 const struct iphdr *iph = (struct iphdr *)skb->data;
237235 const u8 offset = iph->ihl << 2;
....@@ -245,12 +243,12 @@
245243 int err;
246244 struct net *net = dev_net(skb->dev);
247245
248
- /* Only need dccph_dport & dccph_sport which are the first
249
- * 4 bytes in dccp header.
250
- * Our caller (icmp_socket_deliver()) already pulled 8 bytes for us.
251
- */
252
- BUILD_BUG_ON(offsetofend(struct dccp_hdr, dccph_sport) > 8);
253
- BUILD_BUG_ON(offsetofend(struct dccp_hdr, dccph_dport) > 8);
246
+ if (!pskb_may_pull(skb, offset + sizeof(*dh)))
247
+ return -EINVAL;
248
+ dh = (struct dccp_hdr *)(skb->data + offset);
249
+ if (!pskb_may_pull(skb, offset + __dccp_basic_hdr_len(dh)))
250
+ return -EINVAL;
251
+ iph = (struct iphdr *)skb->data;
254252 dh = (struct dccp_hdr *)(skb->data + offset);
255253
256254 sk = __inet_lookup_established(net, &dccp_hashinfo,
....@@ -259,16 +257,18 @@
259257 inet_iif(skb), 0);
260258 if (!sk) {
261259 __ICMP_INC_STATS(net, ICMP_MIB_INERRORS);
262
- return;
260
+ return -ENOENT;
263261 }
264262
265263 if (sk->sk_state == DCCP_TIME_WAIT) {
266264 inet_twsk_put(inet_twsk(sk));
267
- return;
265
+ return 0;
268266 }
269267 seq = dccp_hdr_seq(dh);
270
- if (sk->sk_state == DCCP_NEW_SYN_RECV)
271
- return dccp_req_err(sk, seq);
268
+ if (sk->sk_state == DCCP_NEW_SYN_RECV) {
269
+ dccp_req_err(sk, seq);
270
+ return 0;
271
+ }
272272
273273 bh_lock_sock(sk);
274274 /* If too many ICMPs get dropped on busy
....@@ -357,6 +357,7 @@
357357 out:
358358 bh_unlock_sock(sk);
359359 sock_put(sk);
360
+ return 0;
360361 }
361362
362363 static inline __sum16 dccp_v4_csum_finish(struct sk_buff *skb,
....@@ -428,7 +429,7 @@
428429
429430 if (__inet_inherit_port(sk, newsk) < 0)
430431 goto put_and_exit;
431
- *own_req = inet_ehash_nolisten(newsk, req_to_sk(req_unhash));
432
+ *own_req = inet_ehash_nolisten(newsk, req_to_sk(req_unhash), NULL);
432433 if (*own_req)
433434 ireq->ireq_opt = NULL;
434435 else
....@@ -465,7 +466,7 @@
465466 .fl4_dport = dccp_hdr(skb)->dccph_sport,
466467 };
467468
468
- security_skb_classify_flow(skb, flowi4_to_flowi(&fl4));
469
+ security_skb_classify_flow(skb, flowi4_to_flowi_common(&fl4));
469470 rt = ip_route_output_flow(net, &fl4, sk);
470471 if (IS_ERR(rt)) {
471472 IP_INC_STATS(net, IPSTATS_MIB_OUTNOROUTES);
....@@ -496,7 +497,8 @@
496497 rcu_read_lock();
497498 err = ip_build_and_send_pkt(skb, sk, ireq->ir_loc_addr,
498499 ireq->ir_rmt_addr,
499
- rcu_dereference(ireq->ireq_opt));
500
+ rcu_dereference(ireq->ireq_opt),
501
+ inet_sk(sk)->tos);
500502 rcu_read_unlock();
501503 err = net_xmit_eval(err);
502504 }
....@@ -538,7 +540,8 @@
538540 local_bh_disable();
539541 bh_lock_sock(ctl_sk);
540542 err = ip_build_and_send_pkt(skb, ctl_sk,
541
- rxiph->daddr, rxiph->saddr, NULL);
543
+ rxiph->daddr, rxiph->saddr, NULL,
544
+ inet_sk(ctl_sk)->tos);
542545 bh_unlock_sock(ctl_sk);
543546
544547 if (net_xmit_eval(err) == 0) {
....@@ -695,6 +698,8 @@
695698
696699 /**
697700 * dccp_invalid_packet - check for malformed packets
701
+ * @skb: Packet to validate
702
+ *
698703 * Implements RFC 4340, 8.5: Step 1: Check header basics
699704 * Packets that fail these checks are ignored and do not receive Resets.
700705 */
....@@ -730,7 +735,7 @@
730735 return 1;
731736 }
732737 /*
733
- * If P.Data Offset is too too large for packet, drop packet and return
738
+ * If P.Data Offset is too large for packet, drop packet and return
734739 */
735740 if (!pskb_may_pull(skb, dccph_doff * sizeof(u32))) {
736741 DCCP_WARN("P.Data Offset(%u) too large\n", dccph_doff);
....@@ -872,7 +877,7 @@
872877
873878 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
874879 goto discard_and_relse;
875
- nf_reset(skb);
880
+ nf_reset_ct(skb);
876881
877882 return __sk_receive_skb(sk, skb, 1, dh->dccph_doff * 4, refcounted);
878883
....@@ -912,10 +917,6 @@
912917 .getsockopt = ip_getsockopt,
913918 .addr2sockaddr = inet_csk_addr2sockaddr,
914919 .sockaddr_len = sizeof(struct sockaddr_in),
915
-#ifdef CONFIG_COMPAT
916
- .compat_setsockopt = compat_ip_setsockopt,
917
- .compat_getsockopt = compat_ip_getsockopt,
918
-#endif
919920 };
920921
921922 static int dccp_v4_init_sock(struct sock *sk)
....@@ -962,10 +963,6 @@
962963 .rsk_prot = &dccp_request_sock_ops,
963964 .twsk_prot = &dccp_timewait_sock_ops,
964965 .h.hashinfo = &dccp_hashinfo,
965
-#ifdef CONFIG_COMPAT
966
- .compat_setsockopt = compat_dccp_setsockopt,
967
- .compat_getsockopt = compat_dccp_getsockopt,
968
-#endif
969966 };
970967
971968 static const struct net_protocol dccp_v4_protocol = {
....@@ -988,6 +985,7 @@
988985 /* FIXME: work on tcp_poll to rename it to inet_csk_poll */
989986 .poll = dccp_poll,
990987 .ioctl = inet_ioctl,
988
+ .gettstamp = sock_gettstamp,
991989 /* FIXME: work on inet_listen to rename it to sock_common_listen */
992990 .listen = inet_dccp_listen,
993991 .shutdown = inet_shutdown,
....@@ -997,10 +995,6 @@
997995 .recvmsg = sock_common_recvmsg,
998996 .mmap = sock_no_mmap,
999997 .sendpage = sock_no_sendpage,
1000
-#ifdef CONFIG_COMPAT
1001
- .compat_setsockopt = compat_sock_common_setsockopt,
1002
- .compat_getsockopt = compat_sock_common_getsockopt,
1003
-#endif
1004998 };
1005999
10061000 static struct inet_protosw dccp_v4_protosw = {