Revert "bpf: Fix DEVMAP_HASH overflow check on 32-bit arches"
authorPu Lehui <pulehui@huawei.com>
Fri, 27 Sep 2024 13:51:16 +0000 (13:51 +0000)
committerBen Hutchings <benh@debian.org>
Thu, 3 Oct 2024 21:58:46 +0000 (23:58 +0200)
This reverts commit 225da02acdc97af01b6bc6ce1a3e5362bf01d3fb which is
commit 281d464a34f540de166cee74b723e97ac2515ec3 upstream.

Commit 225da02acdc9 ("bpf: fix DEVMAP_HASH overflow check on 32-bit
architectures") relies on the v5.11+ base mechanism of memcg-based
memory accounting[0], which is not yet supported on the 5.10 stable
branch, so let's revert this commit in preparation for re-adapting it.

Link: https://lore.kernel.org/bpf/20201201215900.3569844-1-guro@fb.com
Signed-off-by: Pu Lehui <pulehui@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Gbp-Pq: Topic bugfix/all
Gbp-Pq: Name revert-bpf-fix-devmap_hash-overflow-check-on-32-bit-arches.patch

kernel/bpf/devmap.c

index 07b5edb2c70f579a7735e04ab24674391f4e1071..ca2cade2871b868690f71b5a84c7d529094a48d7 100644 (file)
@@ -129,14 +129,13 @@ static int dev_map_init_map(struct bpf_dtab *dtab, union bpf_attr *attr)
        bpf_map_init_from_attr(&dtab->map, attr);
 
        if (attr->map_type == BPF_MAP_TYPE_DEVMAP_HASH) {
-               /* hash table size must be power of 2; roundup_pow_of_two() can
-                * overflow into UB on 32-bit arches, so check that first
-                */
-               if (dtab->map.max_entries > 1UL << 31)
-                       return -EINVAL;
-
                dtab->n_buckets = roundup_pow_of_two(dtab->map.max_entries);
 
+               if (!dtab->n_buckets) /* Overflow check */
+                       return -EINVAL;
+       }
+
+       if (attr->map_type == BPF_MAP_TYPE_DEVMAP_HASH) {
                dtab->dev_index_head = dev_map_create_hash(dtab->n_buckets,
                                                           dtab->map.numa_node);
                if (!dtab->dev_index_head)