Skip to content

Commit 6bf21b5

Browse files
magnus-karlssonborkmann
authored andcommitted
libbpf: fix to reject unknown flags in xsk_socket__create()
In xsk_socket__create(), the libbpf_flags field was not checked for setting currently unused/unknown flags. This patch fixes that by returning -EINVAL if the user has set any flag that is not in use at this point in time. Fixes: 1cad078 ("libbpf: add support for using AF_XDP sockets") Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com> Reviewed-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent d6f1837 commit 6bf21b5

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

‎tools/lib/bpf/xsk.c‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,28 @@ static void xsk_set_umem_config(struct xsk_umem_config *cfg,
126126
cfg->frame_headroom = usr_cfg->frame_headroom;
127127
}
128128

129-
static void xsk_set_xdp_socket_config(struct xsk_socket_config *cfg,
130-
const struct xsk_socket_config *usr_cfg)
129+
static int xsk_set_xdp_socket_config(struct xsk_socket_config *cfg,
130+
const struct xsk_socket_config *usr_cfg)
131131
{
132132
if (!usr_cfg) {
133133
cfg->rx_size = XSK_RING_CONS__DEFAULT_NUM_DESCS;
134134
cfg->tx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS;
135135
cfg->libbpf_flags = 0;
136136
cfg->xdp_flags = 0;
137137
cfg->bind_flags = 0;
138-
return;
138+
return 0;
139139
}
140140

141+
if (usr_cfg->libbpf_flags & ~XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD)
142+
return -EINVAL;
143+
141144
cfg->rx_size = usr_cfg->rx_size;
142145
cfg->tx_size = usr_cfg->tx_size;
143146
cfg->libbpf_flags = usr_cfg->libbpf_flags;
144147
cfg->xdp_flags = usr_cfg->xdp_flags;
145148
cfg->bind_flags = usr_cfg->bind_flags;
149+
150+
return 0;
146151
}
147152

148153
int xsk_umem__create(struct xsk_umem **umem_ptr, void *umem_area, __u64 size,
@@ -557,7 +562,9 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname,
557562
}
558563
strncpy(xsk->ifname, ifname, IFNAMSIZ);
559564

560-
xsk_set_xdp_socket_config(&xsk->config, usr_config);
565+
err = xsk_set_xdp_socket_config(&xsk->config, usr_config);
566+
if (err)
567+
goto out_socket;
561568

562569
if (rx) {
563570
err = setsockopt(xsk->fd, SOL_XDP, XDP_RX_RING,

0 commit comments

Comments
 (0)