From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pdx-out-012.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-012.esa.us-west-2.outbound.mail-perimeter.amazon.com [35.162.73.231]) (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 32FB437FF5E; Wed, 17 Jun 2026 08:28:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.162.73.231 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781684881; cv=none; b=CGBpyiSHUuOeUPwOSJANE5blOPzUkXT0ohCl3jtvi/1yzQnzm8fyjmSSkFx+JEX9oh7iX9or+3LLbiRzCCpL9bs7RVnkmDg+1uyuTbriIL8Rj7JDk+GIky1Vfh+E8u36Q5Mm58FtTJajvAR9DbnhZHQjKGOrX0PQY3Ne+u/1Xw4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781684881; c=relaxed/simple; bh=UcJOorZnS9GtSC7O8fCuBKyC87j3VM6VYrblIL3Q0uA=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=o5lfX1NIbMdCu0c9Bq+esZuVZlj9r1lmPlkJCeUdzFfRBSSYAC8Pxu52BZIemDAS3PqfL1erz+uyt0RLUXLXSUk92Orm53VRo4JXvx6PgI+fh2DUiemAx4ixpkc6ObpTYLUM9ZcxIpAr5i2hiO/soBCil+6o30iLd4el8e4kJFw= 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=aJCXoq1S; arc=none smtp.client-ip=35.162.73.231 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="aJCXoq1S" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazoncorp2; t=1781684880; x=1813220880; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=+gfbE8/PRlfzjkNkV2VDVmqaPimFYzuuEjnAZBwf+LU=; b=aJCXoq1SqP0iy67w+BDtM/HxTcORykljOcCDePE0CgUpf8XDYBFIuYH4 20RJ5f7Tl867ZjSIFHVnefJhuv+ey5uzL8aaHPz/1+VUhX3Yke+GpSNDt UkPxyKQ79sRjcYgOhHAxXefKqlEbiqynVU+pV2OPSiWZqMxf7n2/kpOEF j6oQ7ajw1NbcgolndyjzgNT+SkheLTq93HRRPzyq/iOPUQgDg2ru8HgnY f5EPE/Bp67T/E7Vql0FShzyioBgB4BEqNlX7bDff+vjG95NL6eeC+BDWW chOI9s1wWXxODOjjWYDlNikD89+DmURNspmYHMg8CQZlWDgoazNv0ttKP g==; X-CSE-ConnectionGUID: kDrtkTd6T662P5H47eQEkA== X-CSE-MsgGUID: PkXRpYb1SwS3VdkTP8cE4g== X-IronPort-AV: E=Sophos;i="6.24,209,1774310400"; d="scan'208";a="21726777" Received: from ip-10-5-9-48.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.9.48]) by internal-pdx-out-012.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2026 08:27:57 +0000 Received: from EX19MTAUWC002.ant.amazon.com [205.251.233.51:16347] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.13.145:2525] with esmtp (Farcaster) id 8630db9a-550c-4d3a-9513-30d77e2aa6ef; Wed, 17 Jun 2026 08:27:57 +0000 (UTC) X-Farcaster-Flow-ID: 8630db9a-550c-4d3a-9513-30d77e2aa6ef Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWC002.ant.amazon.com (10.250.64.143) 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:27:56 +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:27:54 +0000 From: Maximilian Heyne To: CC: Maximilian Heyne , Wolfgang Grandegger , Marc Kleine-Budde , "David S. Miller" , Eric Dumazet , "Jakub Kicinski" , Paolo Abeni , "Eric W. Biederman" , , , Subject: [PATCH 6.1.y] net: add missing ns_capable check for peer netns Date: Wed, 17 Jun 2026 08:27:35 +0000 Message-ID: <20260617-keyed-dude-3493dbdb@mheyne-amazon> X-Mailer: git-send-email 2.50.1 Precedence: bulk X-Mailing-List: linux-can@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D042UWA003.ant.amazon.com (10.13.139.44) 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 98c669ad51414..da4affff65476 100644 --- a/drivers/net/can/vxcan.c +++ b/drivers/net/can/vxcan.c @@ -211,6 +211,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 e1e8c825483aa..dac8cc5a79f5a 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -1707,6 +1707,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