Skip to content

from_utf8_unchecked on non-UTF-8 network interface names #1704

Description

@Eh2406

Hi,

I am on the Cargo Team and was recently hired by the Rust Foundation to help triage AI discovered bugs. This bug was found with AI, namely scrutineer and Fable. Except where specifically labeled this report was written by me.

This safety comment is simply wrong, Linux allows non UTF-8 strings. Here's the source code https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/core/dev.c#n1325 or https://github.com/torvalds/linux/blob/481ed5dd3ed7136f627b8ec372ba39f5b2e7d27f/net/core/dev.c#L1325
and here is a POC:

unshare --user --map-root-user --net --mount --pid --fork --mount-proc bash -c 'ip link set lo up; ip link add "$1" type dummy; ip link set "$1" up; exec sh -i' bash "$(printf 'abc\xffdef')" 
then run

Then in that shell run ip link or ifconfig -a

Because of the function returns a string, to_string_lossy Is probably all we can do without a breaking change. With a breaking change, It should probably be OSString.

cc libpnet/libpnet#772

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions