]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
bpf, devmap: Fix premature entry free on destroying map
authorToshiaki Makita <toshiaki.makita1@gmail.com>
Fri, 14 Jun 2019 08:20:13 +0000 (17:20 +0900)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
BugLink: https://bugs.launchpad.net/bugs/1839036
[ Upstream commit d4dd153d551634683fccf8881f606fa9f3dfa1ef ]

dev_map_free() waits for flush_needed bitmap to be empty in order to
ensure all flush operations have completed before freeing its entries.
However the corresponding clear_bit() was called before using the
entries, so the entries could be used after free.

All access to the entries needs to be done before clearing the bit.
It seems commit a5e2da6e9787 ("bpf: netdev is never null in
__dev_map_flush") accidentally changed the clear_bit() and memory access
order.

Note that the problem happens only in __dev_map_flush(), not in
dev_map_flush_old(). dev_map_flush_old() is called only after nulling
out the corresponding netdev_map entry, so dev_map_free() never frees
the entry thus no such race happens there.

Fixes: a5e2da6e9787 ("bpf: netdev is never null in __dev_map_flush")
Signed-off-by: Toshiaki Makita <toshiaki.makita1@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
kernel/bpf/devmap.c

index 0f00b4fd20b56bf07a9f9b2dde98e2eb01beedfd..ab9e4ad9a9141c55ffb55eeb43f4746d9925d9a1 100644 (file)
@@ -238,10 +238,11 @@ void __dev_map_flush(struct bpf_map *map)
                if (unlikely(!dev))
                        continue;
 
-               __clear_bit(bit, bitmap);
                netdev = dev->dev;
                if (likely(netdev->netdev_ops->ndo_xdp_flush))
                        netdev->netdev_ops->ndo_xdp_flush(netdev);
+
+               __clear_bit(bit, bitmap);
        }
 }