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

Commit 1b9b70ea authored by Patrick McHardy's avatar Patrick McHardy Committed by David S. Miller
Browse files

[NETFILTER]: xt_hashlimit: fix mask calculation



Shifts larger than the data type are undefined, don't try to shift
an u32 by 32. Also remove some special-casing of bitmasks divisible
by 32.

Based on patch by Jan Engelhardt <jengelh@computergmbh.de>.

Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b41f5bff
Loading
Loading
Loading
Loading
+5 −18
Original line number Original line Diff line number Diff line
@@ -466,38 +466,25 @@ static inline void rateinfo_recalc(struct dsthash_ent *dh, unsigned long now)


static inline __be32 maskl(__be32 a, unsigned int l)
static inline __be32 maskl(__be32 a, unsigned int l)
{
{
	return htonl(ntohl(a) & ~(~(u_int32_t)0 >> l));
	return l ? htonl(ntohl(a) & ~0 << (32 - l)) : 0;
}
}


#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
static void hashlimit_ipv6_mask(__be32 *i, unsigned int p)
static void hashlimit_ipv6_mask(__be32 *i, unsigned int p)
{
{
	switch (p) {
	switch (p) {
	case 0:
	case 0 ... 31:
		i[0] = i[1] = 0;
		i[2] = i[3] = 0;
		break;
	case 1 ... 31:
		i[0] = maskl(i[0], p);
		i[0] = maskl(i[0], p);
		i[1] = i[2] = i[3] = 0;
		i[1] = i[2] = i[3] = 0;
		break;
		break;
	case 32:
	case 32 ... 63:
		i[1] = i[2] = i[3] = 0;
		break;
	case 33 ... 63:
		i[1] = maskl(i[1], p - 32);
		i[1] = maskl(i[1], p - 32);
		i[2] = i[3] = 0;
		i[2] = i[3] = 0;
		break;
		break;
	case 64:
	case 64 ... 95:
		i[2] = i[3] = 0;
		break;
	case 65 ... 95:
		i[2] = maskl(i[2], p - 64);
		i[2] = maskl(i[2], p - 64);
		i[3] = 0;
		i[3] = 0;
	case 96:
	case 96 ... 127:
		i[3] = 0;
		break;
	case 97 ... 127:
		i[3] = maskl(i[3], p - 96);
		i[3] = maskl(i[3], p - 96);
		break;
		break;
	case 128:
	case 128: