From: Hangbin Liu <hangbin.liu@linux.dev>
To: Jingjing Xu <xujingjing@cmss.chinamobile.com>
Cc: donald.hunter@gmail.com, kuba@kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH net] tools: ynl: preserve non-ASCII string attribute bytes
Date: Tue, 10 Nov 2026 14:37:19 +0800 [thread overview]
Message-ID: <avK7M8VNcWNXrNEw@fedora> (raw)
In-Reply-To: <20261110033922.49297-1-xujingjing@cmss.chinamobile.com>
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>
next prev parent reply other threads:[~2026-11-10 6:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 3:39 [PATCH net] tools: ynl: preserve non-ASCII string attribute bytes Jingjing Xu
2026-11-10 6:37 ` Hangbin Liu [this message]
2026-11-10 11:50 ` Xia Yan
2026-11-10 18:58 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=avK7M8VNcWNXrNEw@fedora \
--to=hangbin.liu@linux.dev \
--cc=donald.hunter@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=xujingjing@cmss.chinamobile.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox