From nobody Sun Feb 8 13:10:54 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63A8B1E25EB for ; Fri, 24 Oct 2025 13:25:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761312332; cv=none; b=MYqTVK5n+dTHPExvV9M50vQkVS1JqEvYGUqOFtwhFGf0fczHO3DCLR8wjqyzv27UFlw7/R6TESUgDr8jMsGufqd0hcu1uDEuWkTb+d0ySXsPNTFJyMOay+wNijJuF6+crtSxGCCgUz+EyxfPG2inWgZZB1tz7SGozqE38bO6MUQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761312332; c=relaxed/simple; bh=mBf4mnaGcfALj0V00XU63ToI/IMNO7pa5UlytqOLXb0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=utwLBG4+hCrTtP0uS2CA4B7MyiXXb0SZ0GXuihXezcSToRleqCEGQJf31tRNw9go3y8h1SMdWCaMQCip7DNoAz7ky46e8Y3N9QNmqXl94MLQYvlIm3axQOScmT1axfV84Pk8P5B2fdgRbJPgwkGcaLniRET4bmzXByshxmGh44A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Wk6MPXwy; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Wk6MPXwy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761312329; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=FlzBCflH9SvRTtMrOksDcMHlWo7c8Sb/jjoLNT1rHCc=; b=Wk6MPXwyKK2+P4sYwuc/L4Ky24uR+2FVgb+0jhGtqkeovD0CPqbSRwMhgI0xBsMgPep01r O2HwwlvpZE00rJPSzscBIKuq/pZ0EgvGgmqdvsInv2qNZ31HHC0bnD+rgsmp0m6ebXC3SL LlXhNBqaq8LHopKN1lu5W7090h2WESs= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-663-P4oJxubeOzaD9znGgDpfeQ-1; Fri, 24 Oct 2025 09:25:28 -0400 X-MC-Unique: P4oJxubeOzaD9znGgDpfeQ-1 X-Mimecast-MFC-AGG-ID: P4oJxubeOzaD9znGgDpfeQ_1761312326 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 61F2519560B4; Fri, 24 Oct 2025 13:25:26 +0000 (UTC) Received: from ShadowPeak.redhat.com (unknown [10.44.33.192]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7C2CC19540EB; Fri, 24 Oct 2025 13:25:22 +0000 (UTC) From: Petr Oros To: Donald Hunter , Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Jacob Keller , Petr Oros , =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= , netdev@vger.kernel.org (open list:NETWORKING [GENERAL]), linux-kernel@vger.kernel.org (open list) Cc: ivecera@redhat.com, mschmidt@redhat.com Subject: [PATCH net] tools: ynl: fix string attribute length to include null terminator Date: Fri, 24 Oct 2025 15:24:38 +0200 Message-ID: <20251024132438.351290-1-poros@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" The ynl_attr_put_str() function was not including the null terminator in the attribute length calculation. This caused kernel to reject CTRL_CMD_GETFAMILY requests with EINVAL: "Attribute failed policy validation". For a 4-character family name like "dpll": - Sent: nla_len=3D8 (4 byte header + 4 byte string without null) - Expected: nla_len=3D9 (4 byte header + 5 byte string with null) The bug was introduced in commit 15d2540e0d62 ("tools: ynl: check for overflow of constructed messages") when refactoring from stpcpy() to strlen(). The original code correctly included the null terminator: end =3D stpcpy(ynl_attr_data(attr), str); attr->nla_len =3D NLA_HDRLEN + NLA_ALIGN(end - (char *)ynl_attr_data(attr)); Since stpcpy() returns a pointer past the null terminator, the length included it. The refactored version using strlen() omitted the +1. The fix also removes NLA_ALIGN() from nla_len calculation, since nla_len should contain actual attribute length, not aligned length. Alignment is only for calculating next attribute position. This makes the code consistent with ynl_attr_put(). CTRL_ATTR_FAMILY_NAME uses NLA_NUL_STRING policy which requires null terminator. Kernel validates with memchr() and rejects if not found. Fixes: 15d2540e0d62 ("tools: ynl: check for overflow of constructed message= s") Signed-off-by: Petr Oros Reviewed-by: Ivan Vecera Tested-by: Ivan Vecera --- tools/net/ynl/lib/ynl-priv.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/net/ynl/lib/ynl-priv.h b/tools/net/ynl/lib/ynl-priv.h index 29481989ea7662..ced7dce44efb43 100644 --- a/tools/net/ynl/lib/ynl-priv.h +++ b/tools/net/ynl/lib/ynl-priv.h @@ -313,7 +313,7 @@ ynl_attr_put_str(struct nlmsghdr *nlh, unsigned int att= r_type, const char *str) struct nlattr *attr; size_t len; =20 - len =3D strlen(str); + len =3D strlen(str) + 1; if (__ynl_attr_put_overflow(nlh, len)) return; =20 @@ -321,7 +321,7 @@ ynl_attr_put_str(struct nlmsghdr *nlh, unsigned int att= r_type, const char *str) attr->nla_type =3D attr_type; =20 strcpy((char *)ynl_attr_data(attr), str); - attr->nla_len =3D NLA_HDRLEN + NLA_ALIGN(len); + attr->nla_len =3D NLA_HDRLEN + len; =20 nlh->nlmsg_len +=3D NLMSG_ALIGN(attr->nla_len); } --=20 2.51.0