Thread View: linux.kernel.netdev
5 messages
5 total messages
Started by Jingjing Xu
Tue, 10 Nov 2026 03:39
[PATCH net] tools: ynl: preserve non-ASCII string attribute bytes
Author: Jingjing Xu
Date: Tue, 10 Nov 2026 03:39
Date: Tue, 10 Nov 2026 03:39
49 lines
10318 bytes
10318 bytes
Netlink strings are not restricted to ASCII. A valid non-ASCII interface
name makes a getlink dump fail with UnicodeDecodeError, and encoding
such a name for a rename request raises UnicodeEncodeError.
Use UTF-8 with surrogateescape for both directions. This preserves ASCII
behavior, handles UTF-8 names and round-trips raw non-UTF-8 bytes that
Linux also permits in interface names. Do not replace invalid bytes and
lose the original name.
Discovered by Codex-assisted code inspection and reproduced using real
rtnetlink operations in a temporary network namespace. Tested ASCII
names, a UTF-8 name and a name containing byte 0xff in link dumps, plus
UTF-8 and non-UTF-8 rename requests. The original library fails on the
non-ASCII inputs; the fixed library reads and writes the names without
losing bytes. Python byte compilation passes. No kernel instrumentation
or hardware was needed.
Fixes: e4b48ed460d3 ("tools: ynl: add a completely generic client")
Signed-off-by: Jingjing Xu <xujingjing@cmss.chinamobile.com>
---
tools/net/ynl/pyynl/lib/ynl.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/net/ynl/pyynl/lib/ynl.py b/tools/net/ynl/pyynl/lib/ynl.py
index fb5acb8acded..2402d7c383e7 100644
--- a/tools/net/ynl/pyynl/lib/ynl.py
+++ b/tools/net/ynl/pyynl/lib/ynl.py
@@ -301,7 +301,7 @@ class NlAttr:
return format_.unpack(self.raw)[0]
def as_strz(self):
- return self.raw.decode('ascii')[:-1]
+ return self.raw.decode('utf-8', 'surrogateescape')[:-1]
def as_bin(self):
return self.raw
@@ -852,7 +852,7 @@ class YnlFamily(SpecFamily):
return b''
attr_payload = b''
elif attr["type"] == 'string':
- attr_payload = str(value).encode('ascii') + b'\x00'
+ attr_payload = str(value).encode('utf-8', 'surrogateescape') + b'\x00'
elif attr["type"] == 'binary':
if value is None:
attr_payload = b''
base-commit: 1d5e2c57e9ffc134e14b3f837c8d7c53b508bd22
--
2.53.0
Re: [PATCH net] tools: ynl: preserve non-ASCII string attribute bytes
Author: Hangbin Liu
Date: Tue, 10 Nov 2026 06:37
Date: Tue, 10 Nov 2026 06:37
53 lines
10354 bytes
10354 bytes
On Tue, Nov 10, 2026 at 03:39:22AM +0000, Jingjing Xu wrote:
> Netlink strings are not restricted to ASCII. A valid non-ASCII interface
> name makes a getlink dump fail with UnicodeDecodeError, and encoding
> such a name for a rename request raises UnicodeEncodeError.
>
> Use UTF-8 with surrogateescape for both directions. This preserves ASCII
> behavior, handles UTF-8 names and round-trips raw non-UTF-8 bytes that
> Linux also permits in interface names. Do not replace invalid bytes and
> lose the original name.
>
> Discovered by Codex-assisted code inspection and reproduced using real
> rtnetlink operations in a temporary network namespace. Tested ASCII
> names, a UTF-8 name and a name containing byte 0xff in link dumps, plus
> UTF-8 and non-UTF-8 rename requests. The original library fails on the
> non-ASCII inputs; the fixed library reads and writes the names without
> losing bytes. Python byte compilation passes. No kernel instrumentation
> or hardware was needed.
>
> Fixes: e4b48ed460d3 ("tools: ynl: add a completely generic client")
> Signed-off-by: Jingjing Xu <xujingjing@cmss.chinamobile.com>
> ---
> tools/net/ynl/pyynl/lib/ynl.py | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/net/ynl/pyynl/lib/ynl.py b/tools/net/ynl/pyynl/lib/ynl.py
> index fb5acb8acded..2402d7c383e7 100644
> --- a/tools/net/ynl/pyynl/lib/ynl.py
> +++ b/tools/net/ynl/pyynl/lib/ynl.py
> @@ -301,7 +301,7 @@ class NlAttr:
> return format_.unpack(self.raw)[0]
>
> def as_strz(self):
> - return self.raw.decode('ascii')[:-1]
> + return self.raw.decode('utf-8', 'surrogateescape')[:-1]
>
> def as_bin(self):
> return self.raw
> @@ -852,7 +852,7 @@ class YnlFamily(SpecFamily):
> return b''
> attr_payload = b''
> elif attr["type"] == 'string':
> - attr_payload = str(value).encode('ascii') + b'\x00'
> + attr_payload = str(value).encode('utf-8', 'surrogateescape') + b'\x00'
> elif attr["type"] == 'binary':
> if value is None:
> attr_payload = b''
> base-commit: 1d5e2c57e9ffc134e14b3f837c8d7c53b508bd22
> --
> 2.53.0
>
Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>
Re: [PATCH net] tools: ynl: preserve non-ASCII string attribute bytes
Author: Xia Yan
Date: Tue, 10 Nov 2026 11:50
Date: Tue, 10 Nov 2026 11:50
17 lines
9204 bytes
9204 bytes
On 11/10/26 03:39, Jingjing Xu wrote: > Netlink strings are not restricted to ASCII. A valid non-ASCII interface > name makes a getlink dump fail with UnicodeDecodeError, and encoding > such a name for a rename request raises UnicodeEncodeError. These are the only two ASCII codec sites in ynl.py, so the patch covers the full string path. I tested both calls in plain Python, without a live netlink dump. ASCII names are unchanged. Names with raw 0x80 or 0xff bytes round-trip byte for byte, and the old 'ascii' calls raise on the same input. e4b48ed460d3 added both ASCII calls, so the Fixes tag is accurate. Reviewed-by: Xia Yan <yanxia@cmss.chinamobile.com>
Re: [PATCH net] tools: ynl: preserve non-ASCII string attribute bytes
Author: Jakub Kicinski
Date: Tue, 10 Nov 2026 18:58
Date: Tue, 10 Nov 2026 18:58
19 lines
8228 bytes
8228 bytes
On Tue, 10 Nov 2026 03:39:22 +0000 Jingjing Xu wrote: > Netlink strings are not restricted to ASCII. Not sure where you got that idea. > A valid non-ASCII interface > name makes a getlink dump fail with UnicodeDecodeError, and encoding > such a name for a rename request raises UnicodeEncodeError. > > Use UTF-8 with surrogateescape for both directions. This preserves ASCII > behavior, handles UTF-8 names and round-trips raw non-UTF-8 bytes that > Linux also permits in interface names. Do not replace invalid bytes and > lose the original name. > > Discovered by Codex-assisted code inspection So you made up a problem and then decided to fix it? Please don't waste our time :/
Re: [PATCH net] tools: ynl: preserve non-ASCII string attribute bytes
Author: Jingjing Xu
Date: Fri, 20 Nov 2026 07:45
Date: Fri, 20 Nov 2026 07:45
20 lines
9165 bytes
9165 bytes
Hi Jakub, My opening statement was too broad. I inferred a general string contract from the kernel accepting non-ASCII interface names. The validation used locally created dummy interfaces in a network namespace: creating the name succeeded, and the unmodified YNL getlink dump then raised UnicodeDecodeError. This was a synthetic test case, not a reported production failure. That observation does not establish that these names are a supported YNL requirement. I also overlooked rtnetlink(7)'s description of IFLA_IFNAME as an asciiz string. It was not sufficient justification for changing the shared codec for every string attribute. I will drop this patch. Sorry for the unnecessary review work. Thanks, Jingjing
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads