]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: check validity of the internal interface name only explicitly specified
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 23 Aug 2023 03:13:44 +0000 (12:13 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 24 Aug 2023 13:55:32 +0000 (15:55 +0200)
Follow-up for 2f091b1b49543aade4aad9ec3b35b3665abac3e7.

Fixes #28844.

src/nspawn/nspawn-network.c
test/units/testsuite-13.nspawn.sh

index 89b50026db34e491bf1d0361e2af249261735dc9..b83e472245c9308f4a2a099a024c217c2ed035d9 100644 (file)
@@ -774,20 +774,22 @@ static int network_iface_pair_parse(const char* iftype, char ***l, const char *p
                         return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                                "%s, interface name not valid: %s", iftype, a);
 
-                if (isempty(interface)) {
-                        if (ifprefix)
-                                b = strjoin(ifprefix, a);
-                        else
-                                b = strdup(a);
-                } else
+                /* Here, we only check the validity of the specified second name. If it is not specified,
+                 * the copied or prefixed name should be already valid, except for its length. If it is too
+                 * long, then it will be shortened later. */
+                if (!isempty(interface)) {
+                        if (!ifname_valid(interface))
+                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                                       "%s, interface name not valid: %s", iftype, interface);
+
                         b = strdup(interface);
+                } else if (ifprefix)
+                        b = strjoin(ifprefix, a);
+                else
+                        b = strdup(a);
                 if (!b)
                         return log_oom();
 
-                if (!ifname_valid(b))
-                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
-                                               "%s, interface name not valid: %s", iftype, b);
-
                 r = strv_consume_pair(l, TAKE_PTR(a), TAKE_PTR(b));
                 if (r < 0)
                         return log_oom();
index 9bcdec9298a1db1cedc656d4606730b22e7709ca..8d7a2e92ab0752fadfb680616fd874ea155ecc08 100755 (executable)
@@ -341,7 +341,7 @@ testcase_nspawn_settings() {
     rm -f "/etc/systemd/nspawn/$container.nspawn"
     mkdir -p "$root/tmp" "$root"/opt/{tmp,inaccessible,also-inaccessible}
 
-    for dev in sd-host-only sd-shared{1,2} sd-macvlan{1,2} sd-ipvlan{1,2}; do
+    for dev in sd-host-only sd-shared{1,2} sd-macvlan{1,2} sd-macvlanloong sd-ipvlan{1,2} sd-ipvlanlooong; do
         ip link add "$dev" type dummy
     done
     udevadm settle
@@ -395,8 +395,8 @@ VirtualEthernet=yes
 VirtualEthernetExtra=my-fancy-veth1
 VirtualEthernetExtra=fancy-veth2:my-fancy-veth2
 Interface=sd-shared1 sd-shared2:sd-shared2
-MACVLAN=sd-macvlan1 sd-macvlan2:my-macvlan2
-IPVLAN=sd-ipvlan1 sd-ipvlan2:my-ipvlan2
+MACVLAN=sd-macvlan1 sd-macvlan2:my-macvlan2 sd-macvlanloong
+IPVLAN=sd-ipvlan1 sd-ipvlan2:my-ipvlan2 sd-ipvlanlooong
 Zone=sd-zone0
 Port=80
 Port=81:8181