Article View: linux.kernel.netdev
Article #13633[PATCH net] tools: ynl: preserve non-ASCII string attribute bytes
From: 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
Technical Details
Message-ID:
<20261110033922.49297-1-xujingjing@cmss.chinamobile.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359834-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359834-linux-kernel-netdev=dewy.ru From: xujingjing@cmss.chinamobile.com (Jingjing Xu) Newsgroups: linux.kernel.netdev Subject: [PATCH net] tools: ynl: preserve non-ASCII string attribute bytes Date: Tue, 10 Nov 2026 03:39:22 +0000 Organization: Usenet Network Message-ID: <20261110033922.49297-1-xujingjing@cmss.chinamobile.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="514529"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:kZAqRoQHu5nY+tkijjovGoI+w3o= sha256:dN55d46PwQthePHHBG/WtGCnNmyKwA9MFyxcQrcibkk= sha1:WK88ECecLjNpTIqBEFyBDtazXXE= sha256:N8KMlaPshJalrUiIYdk+IDep0nEQUObWlSqdAsPV8pA= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 9B127113A29; Tue, 10 Nov 2026 06:44:38 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.75 X-Spam-Status: No, score=-2.75 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=fail (1024-bit key) reason="fail (body has been altered)" header.d=cmss.chinamobile.com X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id k9icCKj-UUtP; Tue, 10 Nov 2026 06:44:30 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-359834-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=cmss.chinamobile.com X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 69FCA113A17; Tue, 10 Nov 2026 06:44:19 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 26C11E53B0; Tue, 10 Nov 2026 03:39:59 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794281966; b=uYZ3HlxVEMcH8TRFhz+6qTTk9H67k+HCBTIhJz0DKBK4rWVRrEV7R6iJP7YT2gcpbG2p m5jeiBWj+yXmnafjBWekWVzj7KibyES5dd02+s0De+nuBN4QIMY75X6KKLt8phH+7CZLf JK67NGiGPAnOwLpQzSC5VzD+AUo/XHRRXb4OIZv0+v8CVlzf7uAJXuycOmrUzU1na4AXw 1w7nbbhbgxd6BQNLzKcQqjreZdlDpiT2HxM970jTckDYkrWwZyZNRKHHMhd//fvP2WaWj B+c9cr4FurSQVe01sYWxnNwHH4TJhxmuSuRPcY13TGS/2wcIdK24dIvFDjdCGTY77dw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794281966; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:X-RM-TagInfo: X-RM-SPAM-FLAG:Received:X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG: Received:X-RM-TRANSID:From:To:Cc:Subject:Date:Message-ID:X-Mailer: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Transfer-Encoding; bh=81yNW9MxXSEiMfVZef54YQxMugIL8gfj9hoUUXY/7q4=; b=nxKk4FU8AveDzUPYg1gK/p/jMZjBH5HXWlVcewLGEDY2VNC14fuF8HPeJsmndNrxp51x WA0UkMM7pdQ+rV8AAZlSUAt/mDBQU4xQJL32337AjIMMXgQflloitFVIgqma8QQvM+lg4 DgL7jIfUgC0i11jXdWa7Yj52+UEUOKT0+JxZwXVYQL8Q3a5k1vkLmPKVi8xpJLUNxZBk8 mT8wYm03kl4FQjJiFv5L81OeA2iVO5ePsYb3c3KiMseI6sJXRWF6spI7UtYqV8sfnMiP7 kiVin8lMY2p8h2BXAW49fYTw9jYMdyQoetAq5EkdkkqTHlmnKFNO6Kh9qipetv9n5XA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=K50xDW5Q; dmarc=pass header.from=cmss.chinamobile.com; spf=pass smtp.mailfrom=cmss.chinamobile.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C024D606AA0C; Tue, 10 Nov 2026 03:39:26 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=K50xDW5Q X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=111.22.67.135 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794281965; b=pgXJmQNYE0G/pcXYvB3lAg6gq1fURlbWsHNu+DOLBhA20YV5SEHnTkVjkDj1p0zFD7gv Ad6BIlLcPJNxZ8sdx/9aZur+iPLK2oadqw9BcjiKnGwO6ZwCQ/HAJLAAHHUrT8eRuczTV sXUOXV1bGSFF1V51XTXIop0HenkXbxDYSjgeaqxatxbtdxOURihqwHaVfKS3AWU16z4Ks codaiDaVIKUhIX+7Es2KovDrB4q8lu+hwlUCKKdld10TMwmNDNxCqEzxcB41r6o9eOOAX OOg8sStevW2Grf3CgQA7/g8SGicfPdNTBpXtTXjtvnfrMadtkBVPGiW0sDOFCSf3atQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794281965; h=DMARC-Filter:DKIM-Signature:X-RM-TagInfo:X-RM-SPAM-FLAG:Received: X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:X-RM-TRANSID:From: To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=81yNW9MxXSEiMfVZef54YQxMugIL8gfj9hoUUXY/7q4=; b=TakP++swjJSN/gP++qghmfqXGME08sJafWgCDf6nTU5FcVISzQfwFqRDWiDWq+WdlYUb VtZroj1DuDZE5qrilgSrJgv++J0csI1rKD87rkijXavWPwOXcDRHCEEnhPBnlR6mBaZzX gDjoEIKESPiQ1u/D3fIryLdiEICu1p7A9unOhutzxGHecDY5RxSqYuK1X5BjayxfjaiUd BvpbTecoDc+WyyIt9Qse31z6zmTCO/5IhW1I4b8AsUQZBMcEulrQ3zuDyvygjx5i1Vqfh iVEjeZ/lTflXicrU2Fr3x3iD7lmHPjiutjlaxwW0m1JqgSshfQlGIr98gmvQ5PMx+uw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=cmss.chinamobile.com; spf=pass smtp.mailfrom=cmss.chinamobile.com; dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=K50xDW5Q; arc=none smtp.remote-ip=111.22.67.135 X-Received: from cmccmta2.chinamobile.com (cmccmta2.chinamobile.com [111.22.67.135]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 858DE606A337 for <netdev@vger.kernel.org>; Tue, 10 Nov 2026 03:39:24 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 858DE606A337 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmss.chinamobile.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmss.chinamobile.com X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmss.chinamobile.com; s=default; l=0; h=from:subject:message-id:to:cc:mime-version; bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=; b=K50xDW5QW2c6vcgwdw8sCuvSUfsw1ssz/NnTpl9P/hASM7a0Pf/50yV8xP2oaCoeHXyXmmGIEpDVU PCsgzxanmMR3G4QTtZM6D8X8oBQZwRg/xZQEAgyrfTOofguD9C4o/i3T4mCqZYmCCLu3CfWOZTQ5Ny P5vDH5H854eiMwfU= X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 X-Received: from spf.mail.chinamobile.com (unknown[10.188.0.87]) by rmmx-syy-dmz-app03-12003 (RichMail) with SMTP id 2ee36af291ea022-967b8; Tue, 10 Nov 2026 11:39:23 +0800 (CST) X-RM-TRANSID: 2ee36af291ea022-967b8 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 X-Received: from home-ubuntu-251 (unknown[180.106.244.228]) by rmsmtp-syy-appsvr01-12001 (RichMail) with SMTP id 2ee16af291eaacc-a58d8; Tue, 10 Nov 2026 11:39:23 +0800 (CST) X-RM-TRANSID: 2ee16af291eaacc-a58d8 X-Cc: netdev@vger.kernel.org X-Mailer: git-send-email 2.53.0 X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-Received-Bytes: 10032