Skip to content

Commit a3d7809

Browse files
yuwatakeszybz
authored andcommitted
nspawn: check validity of the internal interface name only explicitly specified
Follow-up for 2f091b1. Fixes #28844. (cherry picked from commit 927e20f)
1 parent 8046167 commit a3d7809

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/nspawn/nspawn-network.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -774,20 +774,22 @@ static int network_iface_pair_parse(const char* iftype, char ***l, const char *p
774774
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
775775
"%s, interface name not valid: %s", iftype, a);
776776

777-
if (isempty(interface)) {
778-
if (ifprefix)
779-
b = strjoin(ifprefix, a);
780-
else
781-
b = strdup(a);
782-
} else
777+
/* Here, we only check the validity of the specified second name. If it is not specified,
778+
* the copied or prefixed name should be already valid, except for its length. If it is too
779+
* long, then it will be shortened later. */
780+
if (!isempty(interface)) {
781+
if (!ifname_valid(interface))
782+
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
783+
"%s, interface name not valid: %s", iftype, interface);
784+
783785
b = strdup(interface);
786+
} else if (ifprefix)
787+
b = strjoin(ifprefix, a);
788+
else
789+
b = strdup(a);
784790
if (!b)
785791
return log_oom();
786792

787-
if (!ifname_valid(b))
788-
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
789-
"%s, interface name not valid: %s", iftype, b);
790-
791793
r = strv_consume_pair(l, TAKE_PTR(a), TAKE_PTR(b));
792794
if (r < 0)
793795
return log_oom();

test/units/testsuite-13.nspawn.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ testcase_nspawn_settings() {
341341
rm -f "/etc/systemd/nspawn/$container.nspawn"
342342
mkdir -p "$root/tmp" "$root"/opt/{tmp,inaccessible,also-inaccessible}
343343

344-
for dev in sd-host-only sd-shared{1,2} sd-macvlan{1,2} sd-ipvlan{1,2}; do
344+
for dev in sd-host-only sd-shared{1,2} sd-macvlan{1,2} sd-macvlanloong sd-ipvlan{1,2} sd-ipvlanlooong; do
345345
ip link add "$dev" type dummy
346346
done
347347
udevadm settle
@@ -395,8 +395,8 @@ VirtualEthernet=yes
395395
VirtualEthernetExtra=my-fancy-veth1
396396
VirtualEthernetExtra=fancy-veth2:my-fancy-veth2
397397
Interface=sd-shared1 sd-shared2:sd-shared2
398-
MACVLAN=sd-macvlan1 sd-macvlan2:my-macvlan2
399-
IPVLAN=sd-ipvlan1 sd-ipvlan2:my-ipvlan2
398+
MACVLAN=sd-macvlan1 sd-macvlan2:my-macvlan2 sd-macvlanloong
399+
IPVLAN=sd-ipvlan1 sd-ipvlan2:my-ipvlan2 sd-ipvlanlooong
400400
Zone=sd-zone0
401401
Port=80
402402
Port=81:8181

0 commit comments

Comments
 (0)