Netdev List
 help / color / mirror / Atom feed
* [PATCH net] tools: ynl: preserve non-ASCII string attribute bytes
@ 2026-11-10  3:39 Jingjing Xu
  2026-11-10  6:37 ` Hangbin Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jingjing Xu @ 2026-11-10  3:39 UTC (permalink / raw)
  To: donald.hunter, kuba; +Cc: netdev

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




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] tools: ynl: preserve non-ASCII string attribute bytes
  2026-11-10  3:39 [PATCH net] tools: ynl: preserve non-ASCII string attribute bytes Jingjing Xu
@ 2026-11-10  6:37 ` Hangbin Liu
  2026-11-10 11:50 ` Xia Yan
  2026-11-10 18:58 ` Jakub Kicinski
  2 siblings, 0 replies; 4+ messages in thread
From: Hangbin Liu @ 2026-11-10  6:37 UTC (permalink / raw)
  To: Jingjing Xu; +Cc: donald.hunter, kuba, netdev

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>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] tools: ynl: preserve non-ASCII string attribute bytes
  2026-11-10  3:39 [PATCH net] tools: ynl: preserve non-ASCII string attribute bytes Jingjing Xu
  2026-11-10  6:37 ` Hangbin Liu
@ 2026-11-10 11:50 ` Xia Yan
  2026-11-10 18:58 ` Jakub Kicinski
  2 siblings, 0 replies; 4+ messages in thread
From: Xia Yan @ 2026-11-10 11:50 UTC (permalink / raw)
  To: Jingjing Xu, Donald Hunter, kuba; +Cc: netdev, yana06070

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>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] tools: ynl: preserve non-ASCII string attribute bytes
  2026-11-10  3:39 [PATCH net] tools: ynl: preserve non-ASCII string attribute bytes Jingjing Xu
  2026-11-10  6:37 ` Hangbin Liu
  2026-11-10 11:50 ` Xia Yan
@ 2026-11-10 18:58 ` Jakub Kicinski
  2 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2026-11-10 18:58 UTC (permalink / raw)
  To: Jingjing Xu; +Cc: donald.hunter, netdev

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 :/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-10 18:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-10  3:39 [PATCH net] tools: ynl: preserve non-ASCII string attribute bytes Jingjing Xu
2026-11-10  6:37 ` Hangbin Liu
2026-11-10 11:50 ` Xia Yan
2026-11-10 18:58 ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox