From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pdx-out-007.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-007.esa.us-west-2.outbound.mail-perimeter.amazon.com [52.34.181.151]) (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 0276D3A168B; Wed, 17 Jun 2026 08:28:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.34.181.151 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781684884; cv=none; b=U325VaKuvowi9zlc4yQeFSJe9gq803y6cHe9XJNteUoUc+//16Bd/v0Uq1GBlbNlW2sJqHbn3ytjGNg5QkDWRx1pSVjHs1Za5EXhECBM3TP1JVJgukck20INPXdWzBWfWUL0ZOAaP9U3JmbllQBlKr6v4yhUWcEnm7ChmIPrmXo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781684884; c=relaxed/simple; bh=T5tkYZ976ZkgiSIt/y/NOWzcQQ3uMQ/9ZOb6N8n8eRU=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=QIo74SXe3cS0PxMijJL9COqmfMDq06tpcdP+dT8RQU506vJ23nTfS/ku5CwCPqQcVibPvSG+uu8Az2irWxn1Unotd2aNpA0Xfy+6+qdDEA2Sjp/SzGv4q742SO7da7DTU7qmL8P6QEJhZV2vZ3mB1r8u7TH2EkhSRL98bIw2u5o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de; spf=pass smtp.mailfrom=amazon.de; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b=MSHRxeks; arc=none smtp.client-ip=52.34.181.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b="MSHRxeks" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazoncorp2; t=1781684883; x=1813220883; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=8/hvKiQ7BCbSwym9EORIsXoodo/++f2dAnRYRoKhSxw=; b=MSHRxeksnZp3qa43h43WCRPxsW+iMbs/9bxF/WFEDLAwUgnwQud5RnH9 rDjd9TfEjGSVB2vP7yGAUJRIi6lrF5DoauUmjY/JAwJGJ5BpjZUN1Si3m FcSaS7SRjLGKsM0ZhspWPqkfYLGyHyJ6nvPzxMuORDvKzXqRrtwxN07VR IMkli7s7GY1EehSIimQXwAApXvtJRRmuj8drbGnHK83Qo+QChgWbdrHY3 WMMFTovu3uJJqFMsNgY4CTmhB7//vaO/saMU71RPEXkpBD56CZbpzGM9Y 8yzFJlpoEi7mNAgUX7XGWSPoIHop2KVQPZKCLZ0rRska+U7lmlUyUcxG9 g==; X-CSE-ConnectionGUID: qWRsOfXrTa60dLwkYFn4IQ== X-CSE-MsgGUID: AXjvFCrFTIqdJ00CcwI4NQ== X-IronPort-AV: E=Sophos;i="6.24,209,1774310400"; d="scan'208";a="21919726" Received: from ip-10-5-0-115.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.0.115]) by internal-pdx-out-007.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2026 08:28:02 +0000 Received: from EX19MTAUWA001.ant.amazon.com [205.251.233.182:18964] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.5.146:2525] with esmtp (Farcaster) id 4313176d-899f-4564-a476-c8280a16e15f; Wed, 17 Jun 2026 08:28:02 +0000 (UTC) X-Farcaster-Flow-ID: 4313176d-899f-4564-a476-c8280a16e15f Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWA001.ant.amazon.com (10.250.64.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.37; Wed, 17 Jun 2026 08:28:02 +0000 Received: from dev-dsk-mheyne-1b-8cc83676.eu-west-1.amazon.com (10.13.235.223) by EX19D001UWA001.ant.amazon.com (10.13.138.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.37; Wed, 17 Jun 2026 08:28:00 +0000 From: Maximilian Heyne To: CC: Maximilian Heyne , Wolfgang Grandegger , Marc Kleine-Budde , "David S. Miller" , Jakub Kicinski , Eric Dumazet , "Eric W. Biederman" , , , Subject: [PATCH 5.15.y] net: add missing ns_capable check for peer netns Date: Wed, 17 Jun 2026 08:27:37 +0000 Message-ID: <20260617-forgot-manic-27dda774@mheyne-amazon> X-Mailer: git-send-email 2.50.1 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D032UWB003.ant.amazon.com (10.13.139.165) To EX19D001UWA001.ant.amazon.com (10.13.138.214) Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit The upstream commit 7b735ef81286 ("rtnetlink: add missing netlink_ns_capable() check for peer netns") doesn't apply on older stable kernels due to refactoring. Therefore, this patch is an attempt to implement the same capability check just directly in the respective interface types. Approximate the netlink_ns_capable check with an ns_capable check. As the newlink operation is synchronous this should result in the same behavior. Without this commit, for example, the following command creating a veth device in network namespace of pid 1 succeeds: $ unshare -U -r -n -- bash -c ' ip link add veth0 type veth peer name foobar netns 1 sleep 60' & $ ip link show foobar 13: foobar@if2: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 96:09:69:92:92:cc brd ff:ff:ff:ff:ff:ff link-netnsid 1 With this patch, it's returning -EPERM. This fixes CVE-2026-31692 Cc: stable@vger.kernel.org Fixes: 81adee47dfb6 ("net: Support specifying the network namespace upon device creation.") Assisted-by: Kiro:claude Signed-off-by: Maximilian Heyne --- drivers/net/can/vxcan.c | 5 +++++ drivers/net/veth.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/drivers/net/can/vxcan.c b/drivers/net/can/vxcan.c index afd9060c5421c..8a61011fdaeef 100644 --- a/drivers/net/can/vxcan.c +++ b/drivers/net/can/vxcan.c @@ -198,6 +198,11 @@ static int vxcan_newlink(struct net *net, struct net_device *dev, if (IS_ERR(peer_net)) return PTR_ERR(peer_net); + if (!ns_capable(peer_net->user_ns, CAP_NET_ADMIN)) { + put_net(peer_net); + return -EPERM; + } + peer = rtnl_create_link(peer_net, ifname, name_assign_type, &vxcan_link_ops, tbp, extack); if (IS_ERR(peer)) { diff --git a/drivers/net/veth.c b/drivers/net/veth.c index cfacf8965bc59..c644d59d70900 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -1664,6 +1664,11 @@ static int veth_newlink(struct net *src_net, struct net_device *dev, if (IS_ERR(net)) return PTR_ERR(net); + if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) { + put_net(net); + return -EPERM; + } + peer = rtnl_create_link(net, ifname, name_assign_type, &veth_link_ops, tbp, extack); if (IS_ERR(peer)) { -- 2.50.1 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597