Skip to content

Commit decb705

Browse files
igsilyaAlexei Starovoitov
authored andcommitted
libbpf: fix using uninitialized ioctl results
'channels.max_combined' initialized only on ioctl success and errno is only valid on ioctl failure. The code doesn't produce any runtime issues, but makes memory sanitizers angry: Conditional jump or move depends on uninitialised value(s) at 0x55C056F: xsk_get_max_queues (xsk.c:336) by 0x55C05B2: xsk_create_bpf_maps (xsk.c:354) by 0x55C089F: xsk_setup_xdp_prog (xsk.c:447) by 0x55C0E57: xsk_socket__create (xsk.c:601) Uninitialised value was created by a stack allocation at 0x55C04CD: xsk_get_max_queues (xsk.c:318) Additionally fixed warning on uninitialized bytes in ioctl arguments: Syscall param ioctl(SIOCETHTOOL) points to uninitialised byte(s) at 0x648D45B: ioctl (in /usr/lib64/libc-2.28.so) by 0x55C0546: xsk_get_max_queues (xsk.c:330) by 0x55C05B2: xsk_create_bpf_maps (xsk.c:354) by 0x55C089F: xsk_setup_xdp_prog (xsk.c:447) by 0x55C0E57: xsk_socket__create (xsk.c:601) Address 0x1ffefff378 is on thread 1's stack in frame #1, created by xsk_get_max_queues (xsk.c:318) Uninitialised value was created by a stack allocation at 0x55C04CD: xsk_get_max_queues (xsk.c:318) CC: Magnus Karlsson <[email protected]> Fixes: 1cad078 ("libbpf: add support for using AF_XDP sockets") Signed-off-by: Ilya Maximets <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 7c8b87f commit decb705

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

tools/lib/bpf/xsk.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,14 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk)
317317

318318
static int xsk_get_max_queues(struct xsk_socket *xsk)
319319
{
320-
struct ethtool_channels channels;
321-
struct ifreq ifr;
320+
struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
321+
struct ifreq ifr = {};
322322
int fd, err, ret;
323323

324324
fd = socket(AF_INET, SOCK_DGRAM, 0);
325325
if (fd < 0)
326326
return -errno;
327327

328-
channels.cmd = ETHTOOL_GCHANNELS;
329328
ifr.ifr_data = (void *)&channels;
330329
strncpy(ifr.ifr_name, xsk->ifname, IFNAMSIZ - 1);
331330
ifr.ifr_name[IFNAMSIZ - 1] = '\0';
@@ -335,7 +334,7 @@ static int xsk_get_max_queues(struct xsk_socket *xsk)
335334
goto out;
336335
}
337336

338-
if (channels.max_combined == 0 || errno == EOPNOTSUPP)
337+
if (err || channels.max_combined == 0)
339338
/* If the device says it has no channels, then all traffic
340339
* is sent to a single stream, so max queues = 1.
341340
*/

0 commit comments

Comments
 (0)