]> git.ipfire.org Git - thirdparty/linux.git/commit
selftests/bpf: Fix file descriptor assertion in open_tuntap helper
authorMarcus Wichelmann <marcus.wichelmann@hetzner-cloud.de>
Wed, 5 Mar 2025 21:34:38 +0000 (21:34 +0000)
committerMartin KaFai Lau <martin.lau@kernel.org>
Thu, 6 Mar 2025 20:31:08 +0000 (12:31 -0800)
commit49306d5bfc6a86e3a75f8d584cda65164fb3ed71
tree73721046c859f7d8df3aa4c6b02ff5e4034d3d88
parent73eeecc3cdfeb098f8859269b608589b8a919686
selftests/bpf: Fix file descriptor assertion in open_tuntap helper

The open_tuntap helper function uses open() to get a file descriptor for
/dev/net/tun.

The open(2) manpage writes this about its return value:

  On success, open(), openat(), and creat() return the new file
  descriptor (a nonnegative integer).  On error, -1 is returned and
  errno is set to indicate the error.

This means that the fd > 0 assertion in the open_tuntap helper is
incorrect and should rather check for fd >= 0.

When running the BPF selftests locally, this incorrect assertion was not
an issue, but the BPF kernel-patches CI failed because of this:

  open_tuntap:FAIL:open(/dev/net/tun) unexpected open(/dev/net/tun):
  actual 0 <= expected 0

Signed-off-by: Marcus Wichelmann <marcus.wichelmann@hetzner-cloud.de>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20250305213438.3863922-7-marcus.wichelmann@hetzner-cloud.de
tools/testing/selftests/bpf/network_helpers.c