|
| 1 | +From 03bb697b8df0339c37f4b845025320b261aeb7cc Mon Sep 17 00:00:00 2001 |
| 2 | +From: Luca Boccassi <luca.boccassi@gmail.com> |
| 3 | +Date: Fri, 6 Mar 2026 19:32:35 +0000 |
| 4 | +Subject: [PATCH] udev: check for invalid chars in various fields received from |
| 5 | + the kernel |
| 6 | + |
| 7 | +(cherry picked from commit 16325b35fa6ecb25f66534a562583ce3b96d52f3) |
| 8 | +(cherry picked from commit 3513862eabe9ec4a6a095d7266e98f998f289ed2) |
| 9 | +(cherry picked from commit c20d21e0da293e715db468f9f4a15a5c8fbf8273) |
| 10 | + |
| 11 | +From 5887e72ff87d3a66a4c3fa91897fbec1545f4d3d Mon Sep 17 00:00:00 2001 |
| 12 | +From: Luca Boccassi <luca.boccassi@gmail.com> |
| 13 | +Date: Fri, 13 Mar 2026 11:10:47 +0000 |
| 14 | +Subject: [PATCH] udev: fix review mixup |
| 15 | + |
| 16 | +The previous version in the PR changed variable and sanitized it |
| 17 | +in place. The second version switched to skip if CCs are in the |
| 18 | +string instead, but didn't move back to the original variable. |
| 19 | +Because it's an existing variable, no CI caught it. |
| 20 | + |
| 21 | +Upstream Patch reference: |
| 22 | +1. https://github.com/systemd/systemd/commit/03bb697b8df0339c37f4b845025320b261aeb7cc.patch |
| 23 | +2. https://github.com/systemd/systemd/commit/5887e72ff87d3a66a4c3fa91897fbec1545f4d3d.patch |
| 24 | +--- |
| 25 | + src/udev/dmi_memory_id/dmi_memory_id.c | 3 ++- |
| 26 | + src/udev/scsi_id/scsi_id.c | 3 ++- |
| 27 | + src/udev/udev-builtin-net_id.c | 9 +++++++++ |
| 28 | + src/udev/v4l_id/v4l_id.c | 5 ++++- |
| 29 | + 4 files changed, 17 insertions(+), 3 deletions(-) |
| 30 | + |
| 31 | +diff --git a/src/udev/dmi_memory_id/dmi_memory_id.c b/src/udev/dmi_memory_id/dmi_memory_id.c |
| 32 | +index 37c098a..c965f4a 100644 |
| 33 | +--- a/src/udev/dmi_memory_id/dmi_memory_id.c |
| 34 | ++++ b/src/udev/dmi_memory_id/dmi_memory_id.c |
| 35 | +@@ -51,6 +51,7 @@ |
| 36 | + #include "string-util.h" |
| 37 | + #include "udev-util.h" |
| 38 | + #include "unaligned.h" |
| 39 | ++#include "utf8.h" |
| 40 | + |
| 41 | + #define SUPPORTED_SMBIOS_VER 0x030300 |
| 42 | + |
| 43 | +@@ -185,7 +186,7 @@ static void dmi_memory_device_string( |
| 44 | + |
| 45 | + str = strdupa_safe(dmi_string(h, s)); |
| 46 | + str = strstrip(str); |
| 47 | +- if (!isempty(str)) |
| 48 | ++ if (!isempty(str) && utf8_is_valid(str) && !string_has_cc(str, /* ok= */ NULL)) |
| 49 | + printf("MEMORY_DEVICE_%u_%s=%s\n", slot_num, attr_suffix, str); |
| 50 | + } |
| 51 | + |
| 52 | +diff --git a/src/udev/scsi_id/scsi_id.c b/src/udev/scsi_id/scsi_id.c |
| 53 | +index 6308c52..b2df8d9 100644 |
| 54 | +--- a/src/udev/scsi_id/scsi_id.c |
| 55 | ++++ b/src/udev/scsi_id/scsi_id.c |
| 56 | +@@ -27,6 +27,7 @@ |
| 57 | + #include "strv.h" |
| 58 | + #include "strxcpyx.h" |
| 59 | + #include "udev-util.h" |
| 60 | ++#include "utf8.h" |
| 61 | + |
| 62 | + static const struct option options[] = { |
| 63 | + { "device", required_argument, NULL, 'd' }, |
| 64 | +@@ -443,7 +444,7 @@ static int scsi_id(char *maj_min_dev) { |
| 65 | + } |
| 66 | + if (dev_scsi.tgpt_group[0] != '\0') |
| 67 | + printf("ID_TARGET_PORT=%s\n", dev_scsi.tgpt_group); |
| 68 | +- if (dev_scsi.unit_serial_number[0] != '\0') |
| 69 | ++ if (dev_scsi.unit_serial_number[0] != '\0' && utf8_is_valid(dev_scsi.unit_serial_number) && !string_has_cc(dev_scsi.unit_serial_number, /* ok= */ NULL)) |
| 70 | + printf("ID_SCSI_SERIAL=%s\n", dev_scsi.unit_serial_number); |
| 71 | + goto out; |
| 72 | + } |
| 73 | +diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c |
| 74 | +index 91b4008..715184e 100644 |
| 75 | +--- a/src/udev/udev-builtin-net_id.c |
| 76 | ++++ b/src/udev/udev-builtin-net_id.c |
| 77 | +@@ -39,6 +39,7 @@ |
| 78 | + #include "strv.h" |
| 79 | + #include "strxcpyx.h" |
| 80 | + #include "udev-builtin.h" |
| 81 | ++#include "utf8.h" |
| 82 | + |
| 83 | + #define ONBOARD_14BIT_INDEX_MAX ((1U << 14) - 1) |
| 84 | + #define ONBOARD_16BIT_INDEX_MAX ((1U << 16) - 1) |
| 85 | +@@ -247,6 +248,9 @@ static int get_port_specifier(sd_device *dev, bool fallback_to_dev_id, char **re |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | ++ if (!utf8_is_valid(phys_port_name) || string_has_cc(phys_port_name, /* ok= */ NULL)) |
| 90 | ++ return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL), "Invalid phys_port_name"); |
| 91 | ++ |
| 92 | + /* Otherwise, use phys_port_name as is. */ |
| 93 | + buf = strjoin("n", phys_port_name); |
| 94 | + if (!buf) |
| 95 | +@@ -351,6 +355,9 @@ static int names_pci_onboard_label(sd_device *dev, sd_device *pci_dev, const cha |
| 96 | + if (r < 0) |
| 97 | + return log_device_debug_errno(pci_dev, r, "Failed to get PCI onboard label: %m"); |
| 98 | + |
| 99 | ++ if (!utf8_is_valid(label) || string_has_cc(label, /* ok= */ NULL)) |
| 100 | ++ return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL), "Invalid label"); |
| 101 | ++ |
| 102 | + char str[ALTIFNAMSIZ]; |
| 103 | + if (snprintf_ok(str, sizeof str, "%s%s", |
| 104 | + naming_scheme_has(NAMING_LABEL_NOPREFIX) ? "" : prefix, |
| 105 | +@@ -1209,6 +1216,8 @@ static int names_netdevsim(sd_device *dev, const char *prefix, bool test) { |
| 106 | + if (isempty(phys_port_name)) |
| 107 | + return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EOPNOTSUPP), |
| 108 | + "The 'phys_port_name' attribute is empty."); |
| 109 | ++ if (!utf8_is_valid(phys_port_name) || string_has_cc(phys_port_name, /* ok= */ NULL)) |
| 110 | ++ return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL), "Invalid phys_port_name"); |
| 111 | + |
| 112 | + char str[ALTIFNAMSIZ]; |
| 113 | + if (snprintf_ok(str, sizeof str, "%si%un%s", prefix, addr, phys_port_name)) |
| 114 | +diff --git a/src/udev/v4l_id/v4l_id.c b/src/udev/v4l_id/v4l_id.c |
| 115 | +index 30527e9..2ec96d8 100644 |
| 116 | +--- a/src/udev/v4l_id/v4l_id.c |
| 117 | ++++ b/src/udev/v4l_id/v4l_id.c |
| 118 | +@@ -29,6 +29,8 @@ |
| 119 | + #include "build.h" |
| 120 | + #include "fd-util.h" |
| 121 | + #include "main-func.h" |
| 122 | ++#include "string-util.h" |
| 123 | ++#include "utf8.h" |
| 124 | + |
| 125 | + static const char *arg_device = NULL; |
| 126 | + |
| 127 | +@@ -82,7 +84,8 @@ static int run(int argc, char *argv[]) { |
| 128 | + int capabilities; |
| 129 | + |
| 130 | + printf("ID_V4L_VERSION=2\n"); |
| 131 | +- printf("ID_V4L_PRODUCT=%s\n", v2cap.card); |
| 132 | ++ if (utf8_is_valid((char *)v2cap.card) && !string_has_cc((char *)v2cap.card, /* ok= */ NULL)) |
| 133 | ++ printf("ID_V4L_PRODUCT=%s\n", v2cap.card); |
| 134 | + printf("ID_V4L_CAPABILITIES=:"); |
| 135 | + |
| 136 | + if (v2cap.capabilities & V4L2_CAP_DEVICE_CAPS) |
| 137 | +-- |
| 138 | +2.43.0 |
| 139 | + |
0 commit comments