netfilter: ipset: Make sure element data size is a multiple of u32
authorJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Fri, 26 Jun 2015 09:16:28 +0000 (11:16 +0200)
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Thu, 10 Nov 2016 12:28:47 +0000 (13:28 +0100)
Data for hashing required to be array of u32. Make sure that
element data always multiple of u32.

Ported from a patch proposed by Sergey Popovich <popovich_sergei@mail.ua>.

Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
net/netfilter/ipset/ip_set_hash_gen.h

index 6c88c20ae1d4b9d07a909ff9ba12bae3b6a4ebae..34f115f874ab02c1634a8c44a8d3d70b4cc6df4a 100644 (file)
@@ -260,8 +260,14 @@ htable_bits(u32 hashsize)
 #endif
 
 #define HKEY(data, initval, htable_bits)                       \
-(jhash2((u32 *)(data), HKEY_DATALEN / sizeof(u32), initval)    \
-       & jhash_mask(htable_bits))
+({                                                             \
+       const u32 *__k = (const u32 *)data;                     \
+       u32 __l = HKEY_DATALEN / sizeof(u32);                   \
+                                                               \
+       BUILD_BUG_ON(HKEY_DATALEN % sizeof(u32) != 0);          \
+                                                               \
+       jhash2(__k, __l, initval) & jhash_mask(htable_bits);    \
+})
 
 #ifndef htype
 #ifndef HTYPE