linux/tools
Petr Oros 65f9c4c588 tools: ynl: fix string attribute length to include null terminator
The ynl_attr_put_str() function was not including the null terminator
in the attribute length calculation. This caused kernel to reject
CTRL_CMD_GETFAMILY requests with EINVAL:
"Attribute failed policy validation".

For a 4-character family name like "dpll":
- Sent: nla_len=8 (4 byte header + 4 byte string without null)
- Expected: nla_len=9 (4 byte header + 5 byte string with null)

The bug was introduced in commit 15d2540e0d ("tools: ynl: check for
overflow of constructed messages") when refactoring from stpcpy() to
strlen(). The original code correctly included the null terminator:

  end = stpcpy(ynl_attr_data(attr), str);
  attr->nla_len = NLA_HDRLEN + NLA_ALIGN(end -
                                (char *)ynl_attr_data(attr));

Since stpcpy() returns a pointer past the null terminator, the length
included it. The refactored version using strlen() omitted the +1.

The fix also removes NLA_ALIGN() from nla_len calculation, since
nla_len should contain actual attribute length, not aligned length.
Alignment is only for calculating next attribute position. This makes
the code consistent with ynl_attr_put().

CTRL_ATTR_FAMILY_NAME uses NLA_NUL_STRING policy which requires
null terminator. Kernel validates with memchr() and rejects if not
found.

Fixes: 15d2540e0d ("tools: ynl: check for overflow of constructed messages")
Signed-off-by: Petr Oros <poros@redhat.com>
Tested-by: Ivan Vecera <ivecera@redhat.com>
Reviewed-by: Ivan Vecera <ivecera@redhat.com>
Link: https://lore.kernel.org/20251018151737.365485-3-zahari.doychev@linux.com
Link: https://patch.msgid.link/20251024132438.351290-1-poros@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2025-10-27 16:47:29 -07:00
..
accounting tools/delaytop: improve error handling for missing PSI support 2025-09-13 17:32:56 -07:00
arch - Simplify inline asm flag output operands now that the minimum compiler 2025-10-11 10:51:14 -07:00
bootconfig
bpf bpftool: Remove duplicate string.h header 2025-09-27 04:23:15 -07:00
build perf build: Correct CROSS_ARCH for clang 2025-10-06 16:49:25 -03:00
certs
cgroup
counter
crypto
debugging
docs docs: add tools/docs/gen-redirects.py 2025-09-09 13:37:16 -06:00
firewire
firmware
gpio tools: gpio: remove the include directory on make clean 2025-09-04 16:29:28 +02:00
hv
iio iio: add power and energy measurement modifiers 2025-09-13 13:47:19 +01:00
include - Remove a bunch of asm implementing condition flags testing in KVM's 2025-10-11 11:19:16 -07:00
kvm/kvm_stat
laptop
leds
lib bpf-fixes 2025-10-11 10:31:38 -07:00
memory-model
mm tools/mm/slabinfo: fix access to null terminator in string boundary 2025-09-21 14:22:00 -07:00
net tools: ynl: fix string attribute length to include null terminator 2025-10-27 16:47:29 -07:00
objtool - Remove a bunch of asm implementing condition flags testing in KVM's 2025-10-11 11:19:16 -07:00
pcmcia
perf - Simplify inline asm flag output operands now that the minimum compiler 2025-10-11 10:51:14 -07:00
power Kbuild updates for 6.18 2025-10-01 20:58:51 -07:00
rcu
sched
sched_ext tools/sched_ext: scx_qmap: Make debug output quieter by default 2025-09-23 09:03:26 -10:00
scripts
sound
spi
testing Including fixes from can. Slim pickings, I'm guessing people haven't 2025-10-23 07:03:18 -10:00
thermal
time
tracing rtla: Updates for v6.18 2025-10-05 09:38:26 -07:00
usb tools/usb/usbip: fix spelling mistakes in usbipd.c 2025-09-06 15:22:14 +02:00
verification
virtio kmsan: convert kmsan_handle_dma to use physical addresses 2025-09-12 00:18:20 +02:00
wmi
workqueue
writeback
Makefile