Merge tag 'kvmarm-fixes-5.13-1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / net / netfilter / nft_set_hash.c
index 58f576a..7b3d0a7 100644 (file)
@@ -412,9 +412,17 @@ static void nft_rhash_destroy(const struct nft_set *set)
                                    (void *)set);
 }
 
+/* Number of buckets is stored in u32, so cap our result to 1U<<31 */
+#define NFT_MAX_BUCKETS (1U << 31)
+
 static u32 nft_hash_buckets(u32 size)
 {
-       return roundup_pow_of_two(size * 4 / 3);
+       u64 val = div_u64((u64)size * 4, 3);
+
+       if (val >= NFT_MAX_BUCKETS)
+               return NFT_MAX_BUCKETS;
+
+       return roundup_pow_of_two(val);
 }
 
 static bool nft_rhash_estimate(const struct nft_set_desc *desc, u32 features,
@@ -615,7 +623,7 @@ static u64 nft_hash_privsize(const struct nlattr * const nla[],
                             const struct nft_set_desc *desc)
 {
        return sizeof(struct nft_hash) +
-              nft_hash_buckets(desc->size) * sizeof(struct hlist_head);
+              (u64)nft_hash_buckets(desc->size) * sizeof(struct hlist_head);
 }
 
 static int nft_hash_init(const struct nft_set *set,
@@ -655,8 +663,8 @@ static bool nft_hash_estimate(const struct nft_set_desc *desc, u32 features,
                return false;
 
        est->size   = sizeof(struct nft_hash) +
-                     nft_hash_buckets(desc->size) * sizeof(struct hlist_head) +
-                     desc->size * sizeof(struct nft_hash_elem);
+                     (u64)nft_hash_buckets(desc->size) * sizeof(struct hlist_head) +
+                     (u64)desc->size * sizeof(struct nft_hash_elem);
        est->lookup = NFT_SET_CLASS_O_1;
        est->space  = NFT_SET_CLASS_O_N;
 
@@ -673,8 +681,8 @@ static bool nft_hash_fast_estimate(const struct nft_set_desc *desc, u32 features
                return false;
 
        est->size   = sizeof(struct nft_hash) +
-                     nft_hash_buckets(desc->size) * sizeof(struct hlist_head) +
-                     desc->size * sizeof(struct nft_hash_elem);
+                     (u64)nft_hash_buckets(desc->size) * sizeof(struct hlist_head) +
+                     (u64)desc->size * sizeof(struct nft_hash_elem);
        est->lookup = NFT_SET_CLASS_O_1;
        est->space  = NFT_SET_CLASS_O_N;