Commit Graph
60045 Commits
Author SHA1 Message Date
Luca Boccassi 0096c83c5d boot: fix off-by-one truncation when reading efivars
'val' is allocated as 'size + 1', so the NUL terminator must be written
to 'size', rather than 'size - 1'.

Follow-up for fab8275646
2026-05-18 08:26:44 +02:00
Yu Watanabe e61ac7cd27 network/address: drop duplicated address earlier
network_adjust_dhcp_server() searches network->addresses_by_section,
hence without this change, an address entry picked by
network_adjust_dhcp_server() may be detached and freed by the cleanup
function.
2026-05-18 06:40:29 +02:00
Yu Watanabe a0177d96dc dhcp-message: introduce dhcp_message_{payload,packet}_size() 2026-05-18 09:34:32 +09:00
Yu Watanabe 3e6c08b967 Introduce several more helper functions to read sysfs attributes and use them where applicable (#41065)
Let's not use sd_device_get_sysattr_value() unless the result is
sanitized, escaped, or filtered.
2026-05-18 07:26:44 +09:00
Yu Watanabe 9b768b5bf5 Apply "ruff format" and "ruff check --fix" for all python scripts (#40758) 2026-05-18 07:26:11 +09:00
Luca Boccassi 1d73c5f04f dhcp-client: clear overloaded sname/file fields after parsing
When SD_DHCP_OPTION_OVERLOAD indicates that the sname and/or file header
fields are overloaded with extra DHCP options, dhcp_message_parse() merges
those options into message->options but leaves the raw bytes untouched in
the header. As a result, dhcp_message_build() emits the header (including
the overloaded bytes) verbatim, and the next parse re-parses those bytes,
appending duplicate entries to the options map (each tag's iov list grows).
Subsequent builds then differ from the first, breaking the parse/build
roundtrip.

This was caught by fuzz-dhcp-client, which asserts that two consecutive
build calls produce identical output.

Zero out the overloaded fields after parsing them, since their content has
already been merged into the options map. This makes the roundtrip
idempotent and avoids re-emitting stale overloaded data in the rebuilt
header. The JSON build/parse path was already correct (it omits sname/file
from the JSON when the overload bit is set), so only the binary path needed
fixing.

Fixes https://github.com/systemd/systemd/issues/42139

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-18 04:52:25 +09:00
Yu Watanabe 2a1a026d72 udev-builtin-input-id: drop unused value 2026-05-18 02:55:56 +09:00
Yu Watanabe 6f72bb7bc9 tree-wide: use device_get_sysattr_unsigned() and friends 2026-05-18 02:55:56 +09:00
Yu Watanabe 6ad682d70f udev-builtin-usb_id: make set_usb_iftype() and friends return const char* 2026-05-18 02:55:56 +09:00
Yu Watanabe 23c93e2cd6 udev-builtin-usb_id: use device_get_sysattr_unsigned() and friends
This also fix the parser of bInterfaceClass from safe_atoi() to
safe_atou_full() as it is unsigned hex.
2026-05-18 02:55:56 +09:00
Yu Watanabe 247e4caa3c sd-device: also add device_get_sysattr_streq() 2026-05-18 02:55:56 +09:00
Yu Watanabe 1e39d3eb08 sd-device: also add device_get_sysattr_u8() and _u16() 2026-05-18 02:55:56 +09:00
Yu Watanabe 3c230737f5 sd-device: use macro to define device_get_sysattr_int() and friends 2026-05-18 02:55:56 +09:00
Yu Watanabe dbfe8b162b test: add test cases for device_get_sysattr_int() and friends 2026-05-18 02:55:56 +09:00
Yu Watanabe 532276524f sd-device: rename argument names for storing result
When a function takes only one argument for storing result, the argument
is not necessary to be named as ret_xyz, but ret should be enough.
2026-05-18 02:55:56 +09:00
Yu Watanabe 06d687ffac tree-wide: use device_get_sysattr_safe_string()
The obtained strings are passed to another function, e,g, handled as a
path and opened, printed to the terminal, written to a file, saved to
udev database as udev property, exposed through DBus, passed to logger,
and so on. Hence, these should not contain any malicious characters.
2026-05-18 02:55:56 +09:00
Yu Watanabe fdce4d4687 udev-builtin-net_id: quote strings in log messages 2026-05-18 02:55:56 +09:00
Yu Watanabe 35edd031b9 udev-builtin-net_id: use EINVAL when we get unexpected sysattr value
The results are completely ignored or only checked if it is negative or
not. Hence, this does not change anything.
2026-05-18 02:55:56 +09:00
Yu Watanabe c5a04f59d9 udev: drop redundant checks
This partially reverts 16325b35fa,
as bad characters are already filtered.
2026-05-18 02:55:56 +09:00
Yu Watanabe c6ea72e39a Revert "udev-builtin-net-id: print cescaped bad attributes"
This reverts commit 7c4047957e.

This is not necessary, as bad characters are already filtered.
2026-05-18 02:55:56 +09:00
Yu Watanabe d0e48e2601 udev: use device_get_sysattr_safe_string() in device_get_sysattr_value_filtered()
Then, renamed to device_get_sysattr_safe_string_filtered().
2026-05-18 02:55:56 +09:00
Yu Watanabe 13ce62caba sd-device: use device_get_sysattr_safe_string()
The read value are exposed by sd_device_get_subsystem() and friends.
Hence, it is better to filter invalid characters.
Of course, these should be always safe unless the kernel is buggy.
But, just for safety.

Note, even if uevent file contains invalid characters, then
device_read_uevent_file() should succeed without parsing the contents.
The caller should fail later with a proper error code if a necessary
field is unset. E.g. sd_device_get_ifindex() should still return -ENOENT
even when uevent file contains an invalid characters.
2026-05-18 02:55:56 +09:00
Yu Watanabe 0341058ee6 sd-device: introduce device_get_sysattr_safe_string()
This introduce a helper function that verifies read sysattr value.
Some sysattr value may come from firmware, and kernel may expose unsafe
string. The introduced function should be used when we use the result as
a string.
2026-05-18 02:55:56 +09:00
Yu Watanabe b74f016e59 string-util: introduce STRING_ALLOW_NEWLINES switch for string_is_safe()
This also make StringSafeFlags defined in basic-forward.h so other
headers can use the enum.
2026-05-18 02:55:34 +09:00
Yu Watanabe 94f807be03 merge-bpf-compdb: apply "ruff format" 2026-05-18 02:47:09 +09:00
Yu Watanabe 58aa8824f3 test_ukify: apply "ruff format"
Also drops unnecessary noqa attribute for importing pefile.
2026-05-18 02:44:46 +09:00
Yu Watanabe d86df93f96 generate-syscall-list: apply "ruff check --fix" 2026-05-18 02:44:46 +09:00
Yu Watanabe 246e4594ed generate-dns_type: apply "ruff format" and "ruff check --fix" 2026-05-18 02:44:46 +09:00
Yu Watanabe 4084459014 ethtool-link-mode: apply "ruff format" 2026-05-18 02:44:46 +09:00
Yu Watanabe cd7bb96049 log-generator: apply "ruff format" and "ruff check --fix" 2026-05-18 02:44:46 +09:00
Yu Watanabe b0a06e2a81 generate-syscall: apply "ruff format" and "ruff check --fix"
Also, this makes opened files closed when not necessary.
2026-05-18 02:44:46 +09:00
Yu WatanabeandJörg Behrmann c5abf64d37 fuzz-bootspec: apply "ruff format"
This also replaces open().read() with Path().read_text().

Co-authored-by: Jörg Behrmann <behrmann@physik.fu-berlin.de>
2026-05-18 02:44:46 +09:00
Yu Watanabe a89c11b672 filesystem-sets: apply "ruff format" and "ruff check --fix" 2026-05-18 02:44:46 +09:00
Yu Watanabe 75f7304512 ruff: do not warn about too long line and lambda assignment 2026-05-18 02:32:42 +09:00
Yu Watanabe c54decc406 ruff: use single quotes for multiline strings 2026-05-18 02:32:39 +09:00
Yu Watanabe 8e8d3a22b2 sd-device: use string_is_safe() at one more place 2026-05-18 01:57:33 +09:00
Yu Watanabe 42c689f63d sd-device: logs about refused property
Follow-up for a62cd5a153.
2026-05-18 01:55:10 +09:00
Yu Watanabe aa0f03eb03 networkctl: introduce 'dhcp-lease' command to dump acquired DHCP lease (#42137) 2026-05-18 01:28:11 +09:00
Yu Watanabe a72f23d2b8 sd-dhcp-client: drop unused data in sd_dhcp_client
With the previous commit, now sd_dhcp_client.link is not used anymore.
Let's drop it.
2026-05-17 22:44:17 +09:00
Yu Watanabe 0c69b24741 dhcp-client-send: move/update BPF code and socket initialization from dhcp-network.c
- BPF code now supports the case when IP header has IP packet options,
- also set socket priority to UDP socket.

Co-developed-by: Google Gemini Pro
2026-05-17 22:44:17 +09:00
Yu Watanabe 89cf6d81f7 dhcp-client-send: use dhcp_message_send_{udp,raw}() 2026-05-17 22:44:17 +09:00
Yu Watanabe 6cbf8222ca networkctl: add dhcp-lease verb to dump DHCP lease
This shows the DHCP message of an acquired DHCP lease.
Example:
```
$ networkctl dhcp-lease eth0
Header:
              KEY VALUE
   Hardware Type: ETHER
Hardware Address: 41:42:43:31:32:33
  Client Address: 192.0.2.123
  Server Address: 192.0.2.1

Options:
CODE NAME               DATA
   1 subnet mask        255.255.255.0
   3 router             192.0.2.1
   6 domain name server 192.0.2.1
  12 hostname           test-node
  15 domain name        lan
  28 broadcast address  192.0.2.255
  42 NTP server         192.0.2.11
                        192.0.2.12
  51 lease time         1d
  53 message type       5
  54 server identifier  192.0.2.1
  58 renewal time       11h 5min 38s
  59 rebinding time     20h 5min 38s
 119 domain search      hoge.example.com
                        foo.example.com
```
2026-05-17 21:02:20 +09:00
Yu Watanabe 149adb2fdc dhcp-message-dump: introduce dump_dhcp_message()
It dumps DHCP messages in a human friendly format.
It will be used in networkctl in a later commit.
2026-05-17 20:09:47 +09:00
Yu Watanabe 335ac4a71d fuzz-dhcp-client: externally set socket fd, rather than override functions 2026-05-17 15:20:29 +09:00
Yu Watanabe acdaee339f test-dhcp-client: add test cases for discover attempt counter 2026-05-17 15:20:29 +09:00
Yu Watanabe 115c354b57 test-dhcp-client: add test cases for IPv6-only mode 2026-05-17 15:20:29 +09:00
Yu Watanabe 7df9210283 test-dhcp-client: add test case for BOOTP client mode 2026-05-17 15:20:29 +09:00
Yu Watanabe 9bd6b949d3 test-dhcp-client: add test case for INIT-REBOOT sequence 2026-05-17 15:20:29 +09:00
Yu Watanabe f7c144b9c7 test-dhcp-client: add test case for rapid commit mode 2026-05-17 15:20:24 +09:00
Yu Watanabe 3eba8d6265 test-dhcp-client: add test case for anonymized mode 2026-05-17 15:18:41 +09:00