Skip to content

libct/validate: fix netdev name length check - #5606

Open
RaphaelFakhri wants to merge 1 commit into
opencontainers:mainfrom
RaphaelFakhri:netdev-ifname-len
Open

RaphaelFakhri wants to merge 1 commit into
opencontainers:mainfrom
RaphaelFakhri:netdev-ifname-len

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

IFNAMSIZ (16) includes the terminating NUL byte, so the longest valid network interface name is 15 bytes, and the kernel rejects a 16-byte one (see dev_valid_name and the IFLA_IFNAME netlink policy).

devValidName accepted 16-byte names, so a config with such a linux.netDevices name passed validation, and runc failed later, while moving the device, with numerical result out of range. By then, the host interface was already set down, and it stayed down.

This change rejects names of IFNAMSIZ bytes or longer, and fixes the TestDevValidName case that treated a 16-byte name as valid.

Fixes #5605

Testing

  • go test -run TestDevValidName ./libcontainer/configs/validate/ fails without the fix (16-byte case) and passes with it.
  • With a dummy host interface and a 16-byte netDevices name, runc run now fails with invalid network device name "abcdefghijklmnop" and the host interface stays up. A 15-byte name still works.

@kolyshkin

Copy link
Copy Markdown
Contributor

@RaphaelFakhri can you please use your real email in the Signed-off-by?

@kolyshkin

This comment was marked as outdated.

IFNAMSIZ (16) includes the terminating NUL byte, so the longest valid
network interface name is 15 bytes, and the kernel rejects a 16-byte
one (see dev_valid_name and the IFLA_IFNAME netlink policy).

devValidName accepted 16-byte names, so a config with such a
linux.netDevices name passed validation, and runc failed later, when
moving the device, with "numerical result out of range". By then, the
host interface was already set down, and it stayed down.

Reject names of IFNAMSIZ bytes or longer, and fix the test case which
treated a 16-byte name as valid.

Signed-off-by: Raphael Fakhri <mail@raphaelfakhri.com>
@RaphaelFakhri

Copy link
Copy Markdown
Author

@kolyshkin The commit now uses Signed-off-by: Raphael Fakhri <mail@raphaelfakhri.com> (e152f7a).

For the unit test: the commit already changes the TestDevValidName case for a name of IFNAMSIZ bytes from valid to invalid, and adds a valid case for IFNAMSIZ-1 bytes. Without the fix, the test fails on the 16-byte name. Is there another test case you want changed?

@lifubang lifubang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

16-byte linux.netDevices name passes validation and leaves the host interface down

3 participants