Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6dfac5c3 authored by Hannes Frederic Sowa's avatar Hannes Frederic Sowa Committed by David S. Miller
Browse files

ipv6: strengthen fallback fragmentation id generation



First off, we don't need to check for non-NULL rt any more, as we are
guaranteed to always get a valid rt6_info. Drop the check.

In case we couldn't allocate an inet_peer for fragmentation information
we currently generate strictly incrementing fragmentation ids for all
destination. This is done to maximize the cycle and avoid collisions.

Those fragmentation ids are very predictable. At least we should try to
mix in the destination address.

While it should make no difference to simply use a PRNG at this point,
secure_ipv6_id ensures that we don't leak information from prandom,
so its internal state could be recoverable.

This fallback function should normally not get used thus this should
not affect performance at all. It is just meant as a safety net.

Signed-off-by: default avatarHannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a50e233c
Loading
Loading
Loading
Loading
+15 −12
Original line number Original line Diff line number Diff line
@@ -6,14 +6,15 @@
#include <net/ipv6.h>
#include <net/ipv6.h>
#include <net/ip6_fib.h>
#include <net/ip6_fib.h>
#include <net/addrconf.h>
#include <net/addrconf.h>
#include <net/secure_seq.h>


void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
{
{
	static atomic_t ipv6_fragmentation_id;
	static atomic_t ipv6_fragmentation_id;
	struct in6_addr addr;
	int old, new;
	int old, new;


#if IS_ENABLED(CONFIG_IPV6)
#if IS_ENABLED(CONFIG_IPV6)
	if (rt) {
	struct inet_peer *peer;
	struct inet_peer *peer;
	struct net *net;
	struct net *net;


@@ -24,7 +25,6 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
		inet_putpeer(peer);
		inet_putpeer(peer);
		return;
		return;
	}
	}
	}
#endif
#endif
	do {
	do {
		old = atomic_read(&ipv6_fragmentation_id);
		old = atomic_read(&ipv6_fragmentation_id);
@@ -32,7 +32,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
		if (!new)
		if (!new)
			new = 1;
			new = 1;
	} while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
	} while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
	fhdr->identification = htonl(new);

	addr = rt->rt6i_dst.addr;
	addr.s6_addr32[0] ^= (__force __be32)new;
	fhdr->identification = htonl(secure_ipv6_id(addr.s6_addr32));
}
}
EXPORT_SYMBOL(ipv6_select_ident);
EXPORT_SYMBOL(ipv6_select_ident);