From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
To: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org
Cc: netdev@vger.kernel.org, magnus.karlsson@intel.com,
bjorn@kernel.org, maciej.fijalkowski@intel.com,
jordyzomer@google.com, security@kernel.org
Subject: [PATCH v2 bpf 0/2] bpf: fix OOB accesses in map_delete_elem callbacks
Date: Fri, 22 Nov 2024 13:10:28 +0100 [thread overview]
Message-ID: <20241122121030.716788-1-maciej.fijalkowski@intel.com> (raw)
v1->v2:
- CC stable and collect tags from Toke & John
Hi,
Jordy reported that for big enough XSKMAPs and DEVMAPs, when deleting
elements, OOB writes occur.
Reproducer below:
// compile with gcc -o map_poc map_poc.c -lbpf
#include <errno.h>
#include <linux/bpf.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>
int main() {
// Create a large enough BPF XSK map
int map_fd;
union bpf_attr create_attr = {
.map_type = BPF_MAP_TYPE_XSKMAP,
.key_size = sizeof(int),
.value_size = sizeof(int),
.max_entries = 0x80000000 + 2,
};
map_fd = syscall(SYS_bpf, BPF_MAP_CREATE, &create_attr, sizeof(create_attr));
if (map_fd < 0) {
fprintf(stderr, "Failed to create BPF map: %s\n", strerror(errno));
return 1;
}
// Delete an element from the map using syscall
unsigned int key = 0x80000000 + 1;
if (syscall(SYS_bpf, BPF_MAP_DELETE_ELEM,
&(union bpf_attr){
.map_fd = map_fd,
.key = &key,
},
sizeof(union bpf_attr)) < 0) {
fprintf(stderr, "Failed to delete element from BPF map: %s\n",
strerror(errno));
return 1;
}
close(map_fd);
return 0;
}
This tiny series changes data types from int to u32 of keys being used
for map accesses.
Thanks,
Maciej
Maciej Fijalkowski (2):
xsk: fix OOB map writes when deleting elements
bpf: fix OOB devmap writes when deleting elements
kernel/bpf/devmap.c | 6 +++---
net/xdp/xskmap.c | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
--
2.34.1
next reply other threads:[~2024-11-22 12:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-22 12:10 Maciej Fijalkowski [this message]
2024-11-22 12:10 ` [PATCH v2 bpf 1/2] xsk: fix OOB map writes when deleting elements Maciej Fijalkowski
2024-11-22 12:10 ` [PATCH v2 bpf 2/2] bpf: fix OOB devmap " Maciej Fijalkowski
2024-11-25 22:30 ` [PATCH v2 bpf 0/2] bpf: fix OOB accesses in map_delete_elem callbacks patchwork-bot+netdevbpf
2024-11-30 0:43 ` Cong Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241122121030.716788-1-maciej.fijalkowski@intel.com \
--to=maciej.fijalkowski@intel.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jordyzomer@google.com \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
--cc=security@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox