Merge ~enr0n/ubuntu/+source/systemd:ubuntu-jammy into ~ubuntu-core-dev/ubuntu/+source/systemd:ubuntu-jammy

Proposed by Nick Rosbrook
Status: Merged
Merged at revision: 5a33378dde845d7b7716b90c94ed0e54a23968e8
Proposed branch: ~enr0n/ubuntu/+source/systemd:ubuntu-jammy
Merge into: ~ubuntu-core-dev/ubuntu/+source/systemd:ubuntu-jammy
Diff against target: 351 lines (+311/-0)
6 files modified
debian/changelog (+12/-0)
debian/patches/lp2002445/core-device-ignore-failed-uevents.patch (+51/-0)
debian/patches/lp2002445/sd-device-introduce-device_get_property_int.patch (+56/-0)
debian/patches/lp2002445/sd-device-make-device_set_syspath-clear-sysname-and-sysnu.patch (+29/-0)
debian/patches/lp2002445/udev-restore-syspath-and-properties-on-failure.patch (+159/-0)
debian/patches/series (+4/-0)
Reviewer Review Type Date Requested Status
Lukas Märdian Approve
Review via email: mp+439253@code.launchpad.net

Description of the change

The fix for LP: #2002445 is incomplete without these patches. In particular, udev needs to properly clean up modified device properties after failed renaming attempts. The full upstream PR is here: https://github.com/systemd/systemd/pull/25980.

Only the necessary commits from that PR are backported here.

PPA: https://launchpad.net/~enr0n/+archive/ubuntu/systemd-249
autopkgtest:

systemd 249.11-0ubuntu3.9~ppa1 (amd64) -- Fail: https://autopkgtest.ubuntu.com/results/autopkgtest-jammy-enr0n-systemd-249/jammy/amd64/s/systemd/20230318_022614_2a0e9@/log.gz
systemd 249.11-0ubuntu3.9~ppa1 (arm64) -- Pass: https://autopkgtest.ubuntu.com/results/autopkgtest-jammy-enr0n-systemd-249/jammy/arm64/s/systemd/20230317_220446_9d627@/log.gz
systemd 249.11-0ubuntu3.9~ppa1 (armhf) -- Pass: https://autopkgtest.ubuntu.com/results/autopkgtest-jammy-enr0n-systemd-249/jammy/armhf/s/systemd/20230317_205813_0b841@/log.gz
systemd 249.11-0ubuntu3.9~ppa1 (ppc64el) -- Fail: https://autopkgtest.ubuntu.com/results/autopkgtest-jammy-enr0n-systemd-249/jammy/ppc64el/s/systemd/20230317_211917_e3ab0@/log.gz
systemd 249.11-0ubuntu3.9~ppa1 (s390x) -- Fail: https://autopkgtest.ubuntu.com/results/autopkgtest-jammy-enr0n-systemd-249/jammy/s390x/s/systemd/20230317_215320_04b93@/log.gz

The s390x failure was a test bed failure. The ppc64el and amd64 failures are both familiar flaky tests.

To post a comment you must log in.
Revision history for this message
Lukas Märdian (slyon) wrote :

Thanks, refreshed/backported patches lgtm.

praise: I really like how you provide full context in the commit messages and merge-proposal (test-builds, autopkgtest logs + explanation). Kudos!

review: Approve
Revision history for this message
Lukas Märdian (slyon) wrote :

Sponsored as `debuild -S -d -v249.11-0ubuntu3.7`, to keep the previous 249.11-0ubuntu3.8 SRU changelog available.

https://launchpad.net/ubuntu/jammy/+queue?queue_state=1&queue_text=systemd

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 238b809..ec1d8ab 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,15 @@
6+systemd (249.11-0ubuntu3.9) jammy; urgency=medium
7+
8+ * udev: gracefully handle rename failures (LP: #2002445)
9+ Files:
10+ - debian/patches/lp2002445/core-device-ignore-failed-uevents.patch
11+ - debian/patches/lp2002445/sd-device-introduce-device_get_property_int.patch
12+ - debian/patches/lp2002445/sd-device-make-device_set_syspath-clear-sysname-and-sysnu.patch
13+ - debian/patches/lp2002445/udev-restore-syspath-and-properties-on-failure.patch
14+ https://git.launchpad.net/~ubuntu-core-dev/ubuntu/+source/systemd/commit/?id=a7ad4a9fc708500c61e3b8127f112d8c90049b2c
15+
16+ -- Nick Rosbrook <nick.rosbrook@canonical.com> Mon, 20 Mar 2023 10:32:08 -0400
17+
18 systemd (249.11-0ubuntu3.8) jammy; urgency=medium
19
20 * network/dhcp4: accept local subnet routes from DHCP (LP: #2004478)
21diff --git a/debian/patches/lp2002445/core-device-ignore-failed-uevents.patch b/debian/patches/lp2002445/core-device-ignore-failed-uevents.patch
22new file mode 100644
23index 0000000..1a2f9d1
24--- /dev/null
25+++ b/debian/patches/lp2002445/core-device-ignore-failed-uevents.patch
26@@ -0,0 +1,51 @@
27+From: Yu Watanabe <watanabe.yu+github@gmail.com>
28+Date: Mon, 9 Jan 2023 16:11:52 +0900
29+Subject: core/device: ignore failed uevents
30+
31+Origin: upstream, https://github.com/systemd/systemd/commit/e9336d6ac346df38d96c91ba0447b3c76ee6697b
32+Bug-Ubuntu: https://launchpad.net/bugs/2002445
33+
34+When udevd failed to process the device, SYSTEMD_ALIAS or any other
35+properties may contain invalid values. Let's refuse to handle the uevent.
36+---
37+ src/core/device.c | 20 ++++++++++++++++++++
38+ 1 file changed, 20 insertions(+)
39+
40+diff --git a/src/core/device.c b/src/core/device.c
41+index 5ed5ceb..e138754 100644
42+--- a/src/core/device.c
43++++ b/src/core/device.c
44+@@ -9,6 +9,7 @@
45+ #include "bus-error.h"
46+ #include "dbus-device.h"
47+ #include "dbus-unit.h"
48++#include "device-private.h"
49+ #include "device-util.h"
50+ #include "device.h"
51+ #include "log.h"
52+@@ -960,6 +961,25 @@ static int device_dispatch_io(sd_device_monitor *monitor, sd_device *dev, void *
53+ if (action == SD_DEVICE_MOVE)
54+ device_remove_old_on_move(m, dev);
55+
56++ /* When udevd failed to process the device, SYSTEMD_ALIAS or any other properties may contain invalid
57++ * values. Let's refuse to handle the uevent. */
58++ if (sd_device_get_property_value(dev, "UDEV_WORKER_FAILED", NULL) >= 0) {
59++ int v;
60++
61++ if (device_get_property_int(dev, "UDEV_WORKER_ERRNO", &v) >= 0)
62++ log_device_warning_errno(dev, v, "systemd-udevd failed to process the device, ignoring: %m");
63++ else if (device_get_property_int(dev, "UDEV_WORKER_EXIT_STATUS", &v) >= 0)
64++ log_device_warning(dev, "systemd-udevd failed to process the device with exit status %i, ignoring.", v);
65++ else if (device_get_property_int(dev, "UDEV_WORKER_SIGNAL", &v) >= 0) {
66++ const char *s;
67++ (void) sd_device_get_property_value(dev, "UDEV_WORKER_SIGNAL_NAME", &s);
68++ log_device_warning(dev, "systemd-udevd failed to process the device with signal %i(%s), ignoring.", v, strna(s));
69++ } else
70++ log_device_warning(dev, "systemd-udevd failed to process the device with unknown result, ignoring.");
71++
72++ return 0;
73++ }
74++
75+ /* A change event can signal that a device is becoming ready, in particular if the device is using
76+ * the SYSTEMD_READY logic in udev so we need to reach the else block of the following if, even for
77+ * change events */
78diff --git a/debian/patches/lp2002445/sd-device-introduce-device_get_property_int.patch b/debian/patches/lp2002445/sd-device-introduce-device_get_property_int.patch
79new file mode 100644
80index 0000000..3dcdf4a
81--- /dev/null
82+++ b/debian/patches/lp2002445/sd-device-introduce-device_get_property_int.patch
83@@ -0,0 +1,56 @@
84+From: Yu Watanabe <watanabe.yu+github@gmail.com>
85+Date: Mon, 9 Jan 2023 16:44:11 +0900
86+Subject: sd-device: introduce device_get_property_int()
87+
88+Origin: upstream, https://github.com/systemd/systemd/commit/eedfef0f0d2654fcde2a3b694e62518d688af827
89+Bug-Ubuntu: https://launchpad.net/bugs/2002445
90+
91+(modified to apply to v249.11)
92+---
93+ src/libsystemd/sd-device/device-private.h | 1 +
94+ src/libsystemd/sd-device/sd-device.c | 20 ++++++++++++++++++++
95+ 2 files changed, 21 insertions(+)
96+
97+diff --git a/src/libsystemd/sd-device/device-private.h b/src/libsystemd/sd-device/device-private.h
98+index 9bb5eff..0ed7807 100644
99+--- a/src/libsystemd/sd-device/device-private.h
100++++ b/src/libsystemd/sd-device/device-private.h
101+@@ -17,6 +17,7 @@ static inline int device_new_from_watch_handle(sd_device **ret, int wd) {
102+ return device_new_from_watch_handle_at(ret, -1, wd);
103+ }
104+
105++int device_get_property_int(sd_device *device, const char *key, int *ret);
106+ int device_get_device_id(sd_device *device, const char **ret);
107+
108+ int device_get_devlink_priority(sd_device *device, int *priority);
109+diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c
110+index 49f56ca..2b9be24 100644
111+--- a/src/libsystemd/sd-device/sd-device.c
112++++ b/src/libsystemd/sd-device/sd-device.c
113+@@ -1904,6 +1904,26 @@ _public_ int sd_device_get_property_value(sd_device *device, const char *key, co
114+ return 0;
115+ }
116+
117++int device_get_property_int(sd_device *device, const char *key, int *ret) {
118++ const char *value;
119++ int r, v;
120++
121++ assert(device);
122++ assert(key);
123++
124++ r = sd_device_get_property_value(device, key, &value);
125++ if (r < 0)
126++ return r;
127++
128++ r = safe_atoi(value, &v);
129++ if (r < 0)
130++ return r;
131++
132++ if (ret)
133++ *ret = v;
134++ return 0;
135++}
136++
137+ _public_ int sd_device_get_trigger_uuid(sd_device *device, sd_id128_t *ret) {
138+ const char *s;
139+ sd_id128_t id;
140diff --git a/debian/patches/lp2002445/sd-device-make-device_set_syspath-clear-sysname-and-sysnu.patch b/debian/patches/lp2002445/sd-device-make-device_set_syspath-clear-sysname-and-sysnu.patch
141new file mode 100644
142index 0000000..82c82e3
143--- /dev/null
144+++ b/debian/patches/lp2002445/sd-device-make-device_set_syspath-clear-sysname-and-sysnu.patch
145@@ -0,0 +1,29 @@
146+From: Yu Watanabe <watanabe.yu+github@gmail.com>
147+Date: Mon, 9 Jan 2023 14:00:09 +0900
148+Subject: sd-device: make device_set_syspath() clear sysname and sysnum
149+
150+Origin: upstream, https://github.com/systemd/systemd/commit/9a26098e90116fdb5fcffa03485b375ee0c82b6a
151+Bug-Ubuntu: https://launchpad.net/bugs/2002445
152+
153+Otherwise, when a new syspath is assigned to the sd-device object,
154+sd_device_get_sysname() or _sysnum() will provide an outdated device
155+name or number.
156+---
157+ src/libsystemd/sd-device/sd-device.c | 4 ++++
158+ 1 file changed, 4 insertions(+)
159+
160+diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c
161+index 418a5b1..49f56ca 100644
162+--- a/src/libsystemd/sd-device/sd-device.c
163++++ b/src/libsystemd/sd-device/sd-device.c
164+@@ -213,6 +213,10 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
165+
166+ free_and_replace(device->syspath, syspath);
167+ device->devpath = devpath;
168++
169++ /* Unset sysname and sysnum, they will be assigned when requested. */
170++ device->sysnum = NULL;
171++ device->sysname = mfree(device->sysname);
172+ return 0;
173+ }
174+
175diff --git a/debian/patches/lp2002445/udev-restore-syspath-and-properties-on-failure.patch b/debian/patches/lp2002445/udev-restore-syspath-and-properties-on-failure.patch
176new file mode 100644
177index 0000000..c7f5810
178--- /dev/null
179+++ b/debian/patches/lp2002445/udev-restore-syspath-and-properties-on-failure.patch
180@@ -0,0 +1,159 @@
181+From: Yu Watanabe <watanabe.yu+github@gmail.com>
182+Date: Mon, 9 Jan 2023 14:58:58 +0900
183+Subject: udev: restore syspath and properties on failure
184+
185+Origin: upstream, https://github.com/systemd/systemd/commit/210033847c340c43dd6835520f21f8b23ba29579
186+Bug-Ubuntu: https://launchpad.net/bugs/2002445
187+
188+Otherwise, invalid sysname or properties may be broadcast to udev
189+listeners.
190+
191+(modified to apply to v249.11)
192+---
193+ src/udev/udev-event.c | 92 ++++++++++++++++++++++++++++++++++++---------------
194+ 1 file changed, 65 insertions(+), 27 deletions(-)
195+
196+diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
197+index 84822d9..d538377 100644
198+--- a/src/udev/udev-event.c
199++++ b/src/udev/udev-event.c
200+@@ -12,6 +12,7 @@
201+ #include "sd-event.h"
202+
203+ #include "alloc-util.h"
204++#include "device-internal.h"
205+ #include "device-private.h"
206+ #include "device-util.h"
207+ #include "fd-util.h"
208+@@ -827,19 +828,13 @@ int udev_event_spawn(UdevEvent *event,
209+
210+ static int rename_netif(UdevEvent *event) {
211+ sd_device *dev = event->dev;
212+- const char *oldname;
213++ _cleanup_free_ char *old_syspath = NULL, *old_sysname = NULL;
214++ const char *s;
215+ int ifindex, r;
216+
217+ if (!event->name)
218+ return 0; /* No new name is requested. */
219+
220+- r = sd_device_get_sysname(dev, &oldname);
221+- if (r < 0)
222+- return log_device_error_errno(dev, r, "Failed to get sysname: %m");
223+-
224+- if (streq(event->name, oldname))
225+- return 0; /* The interface name is already requested name. */
226+-
227+ if (!device_for_action(dev, SD_DEVICE_ADD))
228+ return 0; /* Rename the interface only when it is added. */
229+
230+@@ -847,7 +842,7 @@ static int rename_netif(UdevEvent *event) {
231+ if (r == -ENOENT)
232+ return 0; /* Device is not a network interface. */
233+ if (r < 0)
234+- return log_device_error_errno(dev, r, "Failed to get ifindex: %m");
235++ return log_device_warning_errno(dev, r, "Failed to get ifindex: %m");
236+
237+ if (naming_scheme_has(NAMING_REPLACE_STRICTLY) &&
238+ !ifname_valid(event->name)) {
239+@@ -855,39 +850,82 @@ static int rename_netif(UdevEvent *event) {
240+ return 0;
241+ }
242+
243+- /* Set ID_RENAMING boolean property here, and drop it in the corresponding move uevent later. */
244+- r = device_add_property(dev, "ID_RENAMING", "1");
245++ r = sd_device_get_sysname(dev, &s);
246+ if (r < 0)
247+- return log_device_warning_errno(dev, r, "Failed to add 'ID_RENAMING' property: %m");
248++ return log_device_warning_errno(dev, r, "Failed to get sysname: %m");
249+
250+- r = device_rename(dev, event->name);
251++ if (streq(event->name, s))
252++ return 0; /* The interface name is already requested name. */
253++
254++ old_sysname = strdup(s);
255++ if (!old_sysname)
256++ return -ENOMEM;
257++
258++ r = sd_device_get_syspath(dev, &s);
259+ if (r < 0)
260+- return log_device_warning_errno(dev, r, "Failed to update properties with new name '%s': %m", event->name);
261++ return log_device_warning_errno(dev, r, "Failed to get syspath: %m");
262++
263++ old_syspath = strdup(s);
264++ if (!old_syspath)
265++ return -ENOMEM;
266++
267++ r = device_rename(dev, event->name);
268++ if (r < 0) {
269++ log_device_warning_errno(dev, r, "Failed to update properties with new name '%s': %m", event->name);
270++ goto revert;
271++ }
272++
273++ /* Set ID_RENAMING boolean property here. It will be dropped when the corresponding move uevent is processed. */
274++ r = device_add_property(dev, "ID_RENAMING", "1");
275++ if (r < 0) {
276++ log_device_warning_errno(dev, r, "Failed to add 'ID_RENAMING' property: %m");
277++ goto revert;
278++ }
279+
280+ /* Also set ID_RENAMING boolean property to cloned sd_device object and save it to database
281+ * before calling rtnl_set_link_name(). Otherwise, clients (e.g., systemd-networkd) may receive
282+ * RTM_NEWLINK netlink message before the database is updated. */
283+ r = device_add_property(event->dev_db_clone, "ID_RENAMING", "1");
284+- if (r < 0)
285+- return log_device_warning_errno(event->dev_db_clone, r, "Failed to add 'ID_RENAMING' property: %m");
286++ if (r < 0) {
287++ log_device_warning_errno(event->dev_db_clone, r, "Failed to add 'ID_RENAMING' property: %m");
288++ goto revert;
289++ }
290+
291+ r = device_update_db(event->dev_db_clone);
292+- if (r < 0)
293+- return log_device_debug_errno(event->dev_db_clone, r, "Failed to update database under /run/udev/data/: %m");
294++ if (r < 0) {
295++ log_device_debug_errno(event->dev_db_clone, r, "Failed to update database under /run/udev/data/: %m");
296++ goto revert;
297++ }
298+
299+ r = rtnl_set_link_name(&event->rtnl, ifindex, event->name);
300+- if (r == -EBUSY) {
301+- log_device_info(dev, "Network interface '%s' is already up, cannot rename to '%s'.",
302+- oldname, event->name);
303+- return 0;
304++ if (r < 0) {
305++ if (r == -EBUSY) {
306++ log_device_info(dev, "Network interface '%s' is already up, cannot rename to '%s'.",
307++ old_sysname, event->name);
308++ r = 0;
309++ } else
310++ log_device_error_errno(dev, r, "Failed to rename network interface %i from '%s' to '%s': %m",
311++ ifindex, old_sysname, event->name);
312++ goto revert;
313+ }
314+- if (r < 0)
315+- return log_device_error_errno(dev, r, "Failed to rename network interface %i from '%s' to '%s': %m",
316+- ifindex, oldname, event->name);
317+-
318+- log_device_debug(dev, "Network interface %i is renamed from '%s' to '%s'", ifindex, oldname, event->name);
319+
320++ log_device_debug(dev, "Network interface %i is renamed from '%s' to '%s'", ifindex, old_sysname, event->name);
321+ return 1;
322++
323++revert:
324++ /* Restore 'dev_db_clone' */
325++ (void) device_add_property(event->dev_db_clone, "ID_RENAMING", NULL);
326++ (void) device_update_db(event->dev_db_clone);
327++
328++ /* Restore 'dev' */
329++ (void) device_set_syspath(dev, old_syspath, /* verify = */ false);
330++ if (sd_device_get_property_value(dev, "INTERFACE_OLD", &s) >= 0) {
331++ (void) device_add_property_internal(dev, "INTERFACE", s);
332++ (void) device_add_property_internal(dev, "INTERFACE_OLD", NULL);
333++ }
334++ (void) device_add_property(dev, "ID_RENAMING", NULL);
335++
336++ return r;
337+ }
338+
339+ static int update_devnode(UdevEvent *event) {
340diff --git a/debian/patches/series b/debian/patches/series
341index 44b471e..c98336a 100644
342--- a/debian/patches/series
343+++ b/debian/patches/series
344@@ -109,3 +109,7 @@ lp2002445/udev-attempt-device-rename-even-if-interface-is-up.patch
345 lp2002445/sd-netlink-add-a-test-for-rtnl_set_link_name.patch
346 lp2000880-network-create-stacked-netdevs-after-the-underlying-link-.patch
347 lp2009502-Enable-dev-sgx_vepc-access-for-the-group-sgx.patch
348+lp2002445/sd-device-make-device_set_syspath-clear-sysname-and-sysnu.patch
349+lp2002445/udev-restore-syspath-and-properties-on-failure.patch
350+lp2002445/sd-device-introduce-device_get_property_int.patch
351+lp2002445/core-device-ignore-failed-uevents.patch

Subscribers

People subscribed via source and target branches