Skip to content

Commit 482fc60

Browse files
strssndktndavem330
authored andcommitted
ipv4: introduce new IP_MTU_DISCOVER mode IP_PMTUDISC_INTERFACE
Sockets marked with IP_PMTUDISC_INTERFACE won't do path mtu discovery, their sockets won't accept and install new path mtu information and they will always use the interface mtu for outgoing packets. It is guaranteed that the packet is not fragmented locally. But we won't set the DF-Flag on the outgoing frames. Florian Weimer had the idea to use this flag to ensure DNS servers are never generating outgoing fragments. They may well be fragmented on the path, but the server never stores or usees path mtu values, which could well be forged in an attack. (The root of the problem with path MTU discovery is that there is no reliable way to authenticate ICMP Fragmentation Needed But DF Set messages because they are sent from intermediate routers with their source addresses, and the IMCP payload will not always contain sufficient information to identify a flow.) Recent research in the DNS community showed that it is possible to implement an attack where DNS cache poisoning is feasible by spoofing fragments. This work was done by Amir Herzberg and Haya Shulman: <https://sites.google.com/site/hayashulman/files/fragmentation-poisoning.pdf> This issue was previously discussed among the DNS community, e.g. <http://www.ietf.org/mail-archive/web/dnsext/current/msg01204.html>, without leading to fixes. This patch depends on the patch "ipv4: fix DO and PROBE pmtu mode regarding local fragmentation with UFO/CORK" for the enforcement of the non-fragmentable checks. If other users than ip_append_page/data should use this semantic too, we have to add a new flag to IPCB(skb)->flags to suppress local fragmentation and check for this in ip_finish_output. Many thanks to Florian Weimer for the idea and feedback while implementing this patch. Cc: David S. Miller <davem@davemloft.net> Suggested-by: Florian Weimer <fweimer@redhat.com> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b915550 commit 482fc60

7 files changed

Lines changed: 28 additions & 9 deletions

File tree

‎include/net/route.h‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,20 @@ static inline int ip4_dst_hoplimit(const struct dst_entry *dst)
313313
return hoplimit;
314314
}
315315

316-
static inline int ip_skb_dst_mtu(struct sk_buff *skb)
316+
static inline bool ip_sk_accept_pmtu(const struct sock *sk)
317317
{
318-
struct inet_sock *inet = skb->sk ? inet_sk(skb->sk) : NULL;
318+
return inet_sk(sk)->pmtudisc != IP_PMTUDISC_INTERFACE;
319+
}
319320

320-
return (inet && inet->pmtudisc == IP_PMTUDISC_PROBE) ?
321-
skb_dst(skb)->dev->mtu : dst_mtu(skb_dst(skb));
321+
static inline bool ip_sk_use_pmtu(const struct sock *sk)
322+
{
323+
return inet_sk(sk)->pmtudisc < IP_PMTUDISC_PROBE;
324+
}
325+
326+
static inline int ip_skb_dst_mtu(const struct sk_buff *skb)
327+
{
328+
return (!skb->sk || ip_sk_use_pmtu(skb->sk)) ?
329+
dst_mtu(skb_dst(skb)) : skb_dst(skb)->dev->mtu;
322330
}
323331

324332
#endif /* _ROUTE_H */

‎include/uapi/linux/in.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ struct in_addr {
115115
#define IP_PMTUDISC_WANT 1 /* Use per route hints */
116116
#define IP_PMTUDISC_DO 2 /* Always DF */
117117
#define IP_PMTUDISC_PROBE 3 /* Ignore dst pmtu */
118+
/* Always use interface mtu (ignores dst pmtu) but don't set DF flag.
119+
* Also incoming ICMP frag_needed notifications will be ignored on
120+
* this socket to prevent accepting spoofed ones.
121+
*/
122+
#define IP_PMTUDISC_INTERFACE 4
118123

119124
#define IP_MULTICAST_IF 32
120125
#define IP_MULTICAST_TTL 33

‎net/dccp/ipv4.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ static inline void dccp_do_pmtu_discovery(struct sock *sk,
174174
mtu = dst_mtu(dst);
175175

176176
if (inet->pmtudisc != IP_PMTUDISC_DONT &&
177+
ip_sk_accept_pmtu(sk) &&
177178
inet_csk(sk)->icsk_pmtu_cookie > mtu) {
178179
dccp_sync_mss(sk, mtu);
179180

‎net/ipv4/ip_output.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,6 @@ static int __ip_append_data(struct sock *sk,
10371037
static int ip_setup_cork(struct sock *sk, struct inet_cork *cork,
10381038
struct ipcm_cookie *ipc, struct rtable **rtp)
10391039
{
1040-
struct inet_sock *inet = inet_sk(sk);
10411040
struct ip_options_rcu *opt;
10421041
struct rtable *rt;
10431042

@@ -1063,8 +1062,8 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork,
10631062
* We steal reference to this route, caller should not release it
10641063
*/
10651064
*rtp = NULL;
1066-
cork->fragsize = inet->pmtudisc == IP_PMTUDISC_PROBE ?
1067-
rt->dst.dev->mtu : dst_mtu(&rt->dst);
1065+
cork->fragsize = ip_sk_use_pmtu(sk) ?
1066+
dst_mtu(&rt->dst) : rt->dst.dev->mtu;
10681067
cork->dst = &rt->dst;
10691068
cork->length = 0;
10701069
cork->ttl = ipc->ttl;
@@ -1315,7 +1314,8 @@ struct sk_buff *__ip_make_skb(struct sock *sk,
13151314
/* DF bit is set when we want to see DF on outgoing frames.
13161315
* If local_df is set too, we still allow to fragment this frame
13171316
* locally. */
1318-
if (inet->pmtudisc >= IP_PMTUDISC_DO ||
1317+
if (inet->pmtudisc == IP_PMTUDISC_DO ||
1318+
inet->pmtudisc == IP_PMTUDISC_PROBE ||
13191319
(skb->len <= dst_mtu(&rt->dst) &&
13201320
ip_dont_fragment(sk, &rt->dst)))
13211321
df = htons(IP_DF);

‎net/ipv4/ip_sockglue.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
627627
inet->nodefrag = val ? 1 : 0;
628628
break;
629629
case IP_MTU_DISCOVER:
630-
if (val < IP_PMTUDISC_DONT || val > IP_PMTUDISC_PROBE)
630+
if (val < IP_PMTUDISC_DONT || val > IP_PMTUDISC_INTERFACE)
631631
goto e_inval;
632632
inet->pmtudisc = val;
633633
break;

‎net/ipv4/route.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,10 @@ void ipv4_sk_update_pmtu(struct sk_buff *skb, struct sock *sk, u32 mtu)
10361036
bool new = false;
10371037

10381038
bh_lock_sock(sk);
1039+
1040+
if (!ip_sk_accept_pmtu(sk))
1041+
goto out;
1042+
10391043
rt = (struct rtable *) __sk_dst_get(sk);
10401044

10411045
if (sock_owned_by_user(sk) || !rt) {

‎net/ipv4/tcp_ipv4.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ static void tcp_v4_mtu_reduced(struct sock *sk)
288288
mtu = dst_mtu(dst);
289289

290290
if (inet->pmtudisc != IP_PMTUDISC_DONT &&
291+
ip_sk_accept_pmtu(sk) &&
291292
inet_csk(sk)->icsk_pmtu_cookie > mtu) {
292293
tcp_sync_mss(sk, mtu);
293294

0 commit comments

Comments
 (0)