Re: [PATCH bpf-next 1/2] libbpf: add support for using AF_XDP sockets
From: Magnus Karlsson <hidden>
Date: 2018-12-12 07:59:45
On Wed, Dec 12, 2018 at 2:15 AM Daniel Borkmann [off-list ref] wrote:
On 12/10/2018 04:34 PM, Magnus Karlsson wrote: [...]quoted
+int xsk_create_umem(void *umem_area, __u64 size, struct xsk_prod_ring *fq, + struct xsk_cons_ring *cq, + struct xsk_umem_config *usr_config) +{ + struct xdp_mmap_offsets off; + struct xsk_umem_info *umem; + struct xdp_umem_reg mr; + socklen_t optlen; + int err, fd; + void *map; + + if (!umem_area) + return -EFAULT; + if (!size && !xsk_page_aligned(umem_area)) + return -EINVAL; + + fd = socket(AF_XDP, SOCK_RAW, 0); + if (fd < 0) + return -errno; + + umem = calloc(1, sizeof(*umem)); + if (!umem) + return -ENOMEM;On error, we should also close fd and not 'leak' it into the app, similar for other errors below. Same in xsk_create_xdp_socket(), etc.
Yes definitely. My bad. Will fix this and undoing the mmaps plus any memory allocation and send a v2. Thanks: Magnus