🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #12926

Re: [PATCH iproute2] libnetlink: zero padding in rta_addattr_l()

#12926
From: Stephen Hemminger
Date: Mon, 09 Nov 2026 01:57
85 lines
14567 bytes
On Tue,  3 Nov 2026 21:29:01 -0800
Dave Seddon <dave.seddon.ca@gmail.com> wrote:

> rta_addattr_l() copies alen bytes but advances the parent by
> RTA_ALIGN(len), so the 1-3 padding bytes are never written. Nests built
> in stack buffers (lwtunnel encap, RTA_MULTIPATH, RTA_METRICS) then send
> those bytes to the kernel. For example, in
> 
>   ip nexthop add id 53 encap mpls 101 ttl 10 via 192.0.2.1 dev d0
> 
> the three bytes after MPLS_IPTUNNEL_TTL are stack contents:
> 
>   05 00 02 00  0a 7f 00 00    MPLS_IPTUNNEL_TTL, ttl 10, stack bytes
>   05 00 02 00  0a 00 00 00    with this patch
> 
> and valgrind reports "sendmsg(msg.msg_iov[0]) points to uninitialised
> byte(s)".
> 
> The kernel skips padding when parsing, so nothing fails, but its own
> encoder zeroes it (__nla_reserve()). Do the same here.
> 
> Fixes: 6ef87f9cce21 ("ip: route: add congestion control metric")
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Dave Seddon <dave.seddon.ca@gmail.com>
> ---
> addattr_l() has the same gap, but all its callers zero their request,
> so it is left alone.
> 
> Kernel side: nla_next() advances by NLA_ALIGN(nla_len), so padding is
> never read; __nla_reserve() memsets it to zero.
> ---

Looks good but AI had some bike shedding on details.

Review summary: [PATCH iproute2] libnetlink: zero padding in rta_addattr_l()
Dave Seddon <dave.seddon.ca@gmail.com>, 2026-11-03
Patchwork-Id: 14942963  (delegate: dsahern@gmail.com)

VERDICT
  Fix is correct. Two commit-message problems. 

THE CHANGE
  lib/libnetlink.c, 1 insertion:
    +	memset((void *)subrta + len, 0, RTA_ALIGN(len) - len);

  rta_addattr_l() copies alen bytes but advances the parent by
  RTA_ALIGN(len), so 1-3 padding bytes were never written. Nests built
  in stack buffers sent stack contents to the kernel.

VERIFIED
  - Bounds safe: existing check reserves RTA_ALIGN(rta->rta_len) +
    RTA_ALIGN(len), so the memset cannot pass maxlen. Exact-fit case
    (maxlen=8, alen=1) returns -1 before reaching the memset.
  - alen == 0 (rta_nest path): len = RTA_LENGTH(0) = 4, already
    aligned, memset is a no-op, does not scribble past the header.
  - Byte pattern matches changelog exactly:
      before: 05 00 02 00  0a 7f 00 00
      after:  05 00 02 00  0a 00 00 00
  - Coverage complete: rta_addattr8/16/64 all route through
    rta_addattr_l(). rta_addattr32() needs nothing (len=8, aligned).
  - Applies to oss-nlseq tip (offset -7 lines), builds clean.
    Test apply reverted; working tree untouched.

PROBLEM 1 - note below the --- is wrong
  Claims "addattr_l() has the same gap". It does not. addattr_l() has
  zeroed its padding since 07f9436201eb (2005, "Use NLMSG_TAIL and add
  addraw_l") -- same memset, same file. That is the precedent this
  patch follows, worth citing rather than disclaiming.

PROBLEM 2 - Fixes tag is misdirected
  Fixes: 6ef87f9cce21 ("ip: route: add congestion control metric")
  is a real unaligned caller (RTAX_CC_ALGO string) but not the cause.
  The defect is in rta_addattr_l() itself, back to the BitKeeper
  import (aba5acdf, 2004) -- no useful commit to tag. The MPLS TTL
  reproducer in the changelog is from 9688cf3b, different again.
  Recommend: drop the tag, state in the body that this affects every
  caller passing an unaligned length.

SEVERITY
  Hygiene, not a vulnerability. Kernel nla_next() advances by
  NLA_ALIGN(nla_len) so padding is never parsed; the 1-3 bytes go to
  the kernel, not onto the wire. Real motivations are the valgrind
  report and matching the kernel's own __nla_reserve(). The changelog
  already frames this accurately.
Technical Details
Message-ID: <20261108175712.37b4c6f7@phoenix.local>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358959-linux-kernel-netdev=dewy.ru
References: <20261104052901.2735000-1-dave.seddon.ca@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358959-linux-kernel-netdev=dewy.ru
From: stephen@networkplumber.org (Stephen Hemminger)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH iproute2] libnetlink: zero padding in rta_addattr_l()
Date: Sun, 8 Nov 2026 17:57:12 -0800
Organization: Usenet Network
Message-ID: <20261108175712.37b4c6f7@phoenix.local>
References: <20261104052901.2735000-1-dave.seddon.ca@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="248416"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:GkSGHizkak/HD2UmaDXUDBoeuQ0= sha256:jvK/axnGoLZuW7/rSACZaFkBAeQYc5oacD09ubq99S8=
	sha1:fMCmMrs76aMqefrJUMmuJzTCQGQ= sha256:hpY1DIxY69wEQQe0kIYyVpDVvqv/5/W4v87MKjXUnik=
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 D03ED113691; Mon,  9 Nov 2026 04:57:46 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.951
X-Spam-Status: No, score=-2.951 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-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]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=networkplumber-org.20260707.gappssmtp.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 WWpbJZyOFXp9;
	Mon,  9 Nov 2026 04:57:43 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-358959-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=quarantine dis=none) header.from=networkplumber.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 0F13C11368C; Mon,  9 Nov 2026 04:57:34 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id E0DA1C04AC; Mon,  9 Nov 2026 01:57:16 +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=1794189436;
	b=qLIwXK+eijBsiJw/iVDJetSfkzoPXMBmaKjLVzyXANBzOlcZmKcMT56rEGjI1mLFb0KA
	 iu7Pi6liZJLtHp0DostaGCqVZOXTCJGkddKWBMMu4UkOPtV4sfCx9vBJpJEEq7o6kEQKa
	 owWTtMwhEXAxVp6N6wxbS+6SRTYxIgubay+2cteOuRlJrbd46MlmR3NePLYLBwJOJE+Lb
	 WaVN0sdWwscaC3PFRAQT22/ORkjrwHc2+IM0Wl8TwwtreWlWq7Lc1Gn6NVl80+b2phXW4
	 dOjagmQh8mFRwCxrjdz7wL0NjTjcJayO17LtPJtRYtG0dnAF5zKoHPYD0QCC18dlXUw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794189436;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Transfer-Encoding;
	bh=8wgCcx+Ych3tnKf4y17fQUirM+lM1wAIJTSbb/Fy8Zk=;
	b=j9NByqYWq1RRCRV2Si7y+kRiNwcWwtGNYAtM0LSmWYPYfuqdce/KJktAxQ9GU8GKktlW
	 PVp0N/T9e2tmMmyjJpLfeCho6ubHRmp4H3KuQ+JcFzx3T7Ccc2Uf916sfBEn+zSHHWQmn
	 hZwS8olqmV+V961sBoJtVp69se1YYstJwfFixWTLFE8u7Eguc5vLXzONtrGqk+qb1Tw04
	 JRn4UQUnz49G/h+iFy9/p9n386qgwpzOtyDnFGxI0Urh2QV7nwUniCJsZzaC2CEFDNsPT
	 qVHyfrmCNP9rk/Wl7pZzVUwDgOyaiAg2pP2+viav4NpoJlzkaETbI6//aS9bYrJLIgA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b="Mzch/vZ7";
	dmarc=pass header.from=networkplumber.org;
	spf=pass smtp.mailfrom=networkplumber.org;
	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 B8F09606A323;
	Mon,  9 Nov 2026 01:57:16 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=Mzch/vZ7
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.178
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794189435;
	b=j4BY9g8c8fVL/NwRdhHPOZolKxJ1Hpw047g4J+1ft+7oyw+9qSG3BQG24BjQz5bVh2/2
	 1G+tCma910ik0TLXXC7QBk7AfVDhGBi56Jiy3lGgXeeT/PytMZ8SQWA6ooCkhn5DnQvFv
	 uQ4t0fEYaBcb7QBSVAbVj0h9aA6A/QF3jMPRrJlKEpkzGMboyU0XuWomdXtqy4Y7PfeRf
	 eH0np/41t0z4RH8SJ4B7/zl5FDXy5taD6hcS7ivIi34WhU7NZkN4RqifX7aNAbwG5YC9e
	 /Z3U10cytlhRF/1K954HtWQEWN/aP5EVTKuDxZYwnyLdYVqThUK/uGc7VG2mbMcACUg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794189435;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Date:From:To:Cc:
	 Subject:Message-ID:In-Reply-To:References:MIME-Version:Content-Type:
	 Content-Transfer-Encoding;
	bh=8wgCcx+Ych3tnKf4y17fQUirM+lM1wAIJTSbb/Fy8Zk=;
	b=AkYud5dW1Ndc3uwv78XPAdhkui3Zjlc7RjRglgfM5HiKpIId/joAsmmOEPvshzVqSbYz
	 Mxwl/HGvBZSMqXtxpKde6XoZ2JC3crC/S75SFViHgOG3GPvBFHwfXrEwCyPA8ONFOegC2
	 bS1waP4Du7nHcMPNvzRWVgQtcGPKEcetnY6Jyg8RF18VTLA8E9fLk8D6L2HDTDZ8ZCnGZ
	 N5iE2B0DDsEtNIvxO0pX5Ig1RPxZtj1t2NHxeckAD3cnj/AhHYBbWDzPCLyWtlgbsxQjo
	 b4/1BvlwD/6HiyuUguT4INHhVoipBOi+hknubO8RHSelq17ESZZUhuALOLuThU6xJcQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=networkplumber.org;
	spf=pass smtp.mailfrom=networkplumber.org;
	dkim=pass header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b="Mzch/vZ7";
	arc=none smtp.remote-ip=209.85.215.178
X-Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75A32606A320
	for <netdev@vger.kernel.org>; Mon,  9 Nov 2026 01:57:15 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 75A32606A320
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=networkplumber.org
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=networkplumber.org
X-Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-ccca948203aso100356a12.3
        for <netdev@vger.kernel.org>; Sun, 08 Nov 2026 17:57:15 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=networkplumber-org.20260707.gappssmtp.com; s=20260707; t=1794189435; x=1794794235; darn=vger.kernel.org;
        h=content-transfer-encoding:content-type:mime-version:references
         :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject
         :date:message-id:reply-to:content-type;
        bh=8wgCcx+Ych3tnKf4y17fQUirM+lM1wAIJTSbb/Fy8Zk=;
        b=Mzch/vZ77PPC0ZEwmvn877V3B8RBxkYhyLS9bK3fzVOiZACTCpXLJl8CMwdT/RaIh6
         6Io4gyFPlmZzG0k3rbWSqyKP4U7EM52lgsWVMAXn8OaI/H7iXAW9hj/oTsrD/vhijUao
         xO31gVlzJ2oeiCyDPasokX5lFZmKmijid9VR/vbN4IS0JnQLrf1rh3bdWoZY1YyyCtk3
         pvIVPoXk2CXyabbO+p/Puot8JtdSPvEwolYqjCyv7SyRdBlhP2m7ZmUi3sM7iwkA9OY1
         xfsLCnfFMLb5rvEEwiN8dokfN7yLoPNqTTW43DXLW2zkX8g+IlYbbVcljBQ9S2Xxrj1A
         mPog==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1794189435; x=1794794235;
        h=content-transfer-encoding:content-type:mime-version:references
         :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg
         :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
         :content-type;
        bh=8wgCcx+Ych3tnKf4y17fQUirM+lM1wAIJTSbb/Fy8Zk=;
        b=lDwScLsentksnLuJy7lTnlPsuObGHS8UhXWRaxGm+52Kkl9Zs6iOs6ZfDO0DSnY/6B
         Wd2KAunian2EX0q84uqRZN1rIaEgwtHI/81R1KjGLtMyboyScBKWDBKsXjQAvuMPcamd
         CMIxLfswV5LbkFNrNCJ+vLHxdYM5Wd6u3q1nVd0SWL0GoZxbknQqfM1pz4G47LVLQRP9
         M3RoPMJuoKV860p1KzxBGESO/UTnJOyzJd3fXdEPI3B6tUM5J33MvhfNL76lQvTsEka5
         oFzhkdbV0ygdWmhZUyG5GQSzCOb3GL2VnTdhCbesH1CRPA/b5KIW2taZ9wxChVS15vl1
         OELQ==
X-Gm-Message-State: APuU4Z+nXbWiLgGwXwCyfX2FgsDzJymB9cJ+h6C7moIoOMiLHuVA9EJU
	Uk+rm5dK2SGn5f06afa9BofY4lpAfqcNOAfWHJYUp3ScOWu2BEYkndOipOaubyTfLwNJKb5mlJ0
	MLOdq/uc=
X-Gm-Gg: AYBFou22Aqy88NpcSwFDFEtreBqycv+s0VBk0GSWHKCNas4hMYyRa9EcCxm52ttqsyV
	hEWYg0fKApee1KiFeBHllCr2N8IGsN9GcTyz8FORX+ut3eCayISdBLczLDwn5RDwXihHKd/TUrI
	eLAsQCg+lmy+lYj6pJUpZPN/SvdzHYTWcNqHIaYtP7BuwvKb/4DZyybAKlSAKmAFsJYt6SqVxb+
	+fS6Cf7Sv2KMwsyR02+7UtwtdZi0Y58TR2VzP6bXUqbtMKoiPWGWQmws2SD4VAuAOIWINYpSNNP
	rPLKeHYTGmVhaDJSIQtv1I+MX7PQLgpVUZOHzN57pFsXRgwWgePifn2NzkM2QuryGdGDdkuovTp
	4tDFK2QzK3GTRkGi2cQuDwAHSih921W7xLSAWQn0o0XNX44u4uEJAOrhzn2XDeQo7ofdRhzxRE6
	GGKC/oGGYQVz+xki9gGpCUliLzc1Y3kQrbfigoRhJseLaWjHrVINZ3zh4NBqp0hNJ2LMxLRxqku
	CTJ+BQvsDZ+46RW+lfli/J7YnQisPf84Ht1i5gxTeRemGTZVLM9LuFGj3dJ0aZQ5MiES3GDZj6X
	4h2/Z5paeZMKtu5XGSzfdhw4toZFahtp1O0AgAQkh74vcbSR0LkH3hSNkTxFMT0tuGP5UAuY
X-Received: by 2002:a17:90b:3ecd:b0:3ab:c80:9365 with SMTP id 98e67ed59e1d1-3b12d3e71d8mr2622681a91.42.1794189434631;
        Sun, 08 Nov 2026 17:57:14 -0800 (PST)
X-Received: from phoenix.local (204-195-112-43.wavecable.com. [204.195.112.43])
        by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b12743e889sm4799418a91.0.2026.11.08.17.57.14
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Sun, 08 Nov 2026 17:57:14 -0800 (PST)
X-Cc: netdev@vger.kernel.org, David Ahern <dsahern@kernel.org>
X-In-Reply-To: <20261104052901.2735000-1-dave.seddon.ca@gmail.com>
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