From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3EAAB36EAA8 for ; Fri, 12 Jun 2026 08:59:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781254793; cv=none; b=YyjBqL9739vJqNvMYefR/x+T5n1FiYCqhLPPmafe1LGcnbhltLupGATuI/T1U9FzREJPw0Q3n4VYzto++diWsZZtdwig+12AhQJBFCowoiD83bmeLzPGUMpfgtQqK+h7jH9TOsCZ98tkt4X/UlcTEX+6/7XIWaHm/x1h2n0fVKc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781254793; c=relaxed/simple; bh=G05kt+p38tNXHiYLTc4A2JJZbcOK706Y/c/CzobEF8Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FkVOnIWpgun4CaQHdMapyH1lIijvs0v7nR6ht622K3P781Bgogre1azxz1D/6H8j9dar+pBla6Nx6/Vgsm9yUaS47jNVjYpshjelQ34k5mc3zg9OKbeaL/ZFu+i2MEsfeo7ORc7G8FZS2AD8AINayyDi7aSv/yOj1WEZDxL/LHg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mrfxVDWB; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mrfxVDWB" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-8419ab3a297so365034b3a.2 for ; Fri, 12 Jun 2026 01:59:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781254790; x=1781859590; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=B3glrKxkjlf2Vk5WupEYNGotMiOWYzbthgIen70t2gY=; b=mrfxVDWBvaNrgAhXbOyJACb6wxOK3ns+pyBfAuyFYXsOUnMuMH3a5LSYSwYNCZeeTt IqTKNjrV+KVdsAMR4/y9e8Qj+kR5NL+xHIq8gcFfyT6UZHS8YbyASOq9fkwF5L994E2u hJWzbDnybGWZWQKv4SlzfUdOvDYi2ySpi53V2uyURqYBJaErvFTPyhkuNUoy+Y+D8Gf0 HwC0KggZs7rbb9YxlfTYRQaO5lIdT6c0KCWtrokuxuWQpwprDD9nTVFFlPIhxQ3b/gj8 U6tUZ5sG11Cxh+uiEI80AFi90piQKfJrFXfVl6N5YTHQPbi+mXch73m+wBpEiGCno74c weSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781254790; x=1781859590; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=B3glrKxkjlf2Vk5WupEYNGotMiOWYzbthgIen70t2gY=; b=ndeKoJNUWquSjQ1Nq+ZU+cfp3ScA10THfK5HVlC1uJLc4ZfiWESJXNSDKSraQzTWHq E8AUWFcVJ4/VcmeUNR3oFH/nwwamPxUVZhybg5jxruzZUARjf07IsxclCOENedUaIB7y 8WjpSTKCELAJj3zsWuBi2miJnggBGB8CHvHc4E23q0Bnab72TqeOa6TbbDURKQ2UJudy E4bHpVKMa1gUunwkVO3XkiMH1CcKkd7CAHpx5vn9NZ8IMfuCocDl35YVHAaNdu8GYO2L L6ruCmMFls+uhO0C4mkdHYmqQVyJbVcyIm6yxLoqmabxoYqv5xJYcGOR8t+ZygTQQrq5 PCDw== X-Forwarded-Encrypted: i=1; AFNElJ+tiY3Sm9UTbt1aTGPltbaEi0/prSG2fCr5lx6Bz/YQw+HAAne9sGW7iIfOA3CZhgKko/IQer3qXwJPCEs=@vger.kernel.org X-Gm-Message-State: AOJu0YzJ4SpIM2sQD3yuHW734NYT+brFOMRD3GhC5bBkjKfxHx0SjAMR /olsTTA9/yBabvPiSUBJogJ9ZSiNAX/z7LGm28qOGtgD1VGZvX0Mydul X-Gm-Gg: Acq92OFuUqKUC0XyXTuxMvORW6QppknAWtR2C0oD33izTXQ/bRpj93zTEELGUlCWpoy OqwZJgnAFI15tyy/WRcsow7aXlBz/MM6ygKYQbrXBSBC32EP1UsMfve5S+4T2H4149gO2CgoX0W /211WwOs9M1chbHxczHvLbwsk5t2W+kqtNeywvVPEBCW31axoo50ZN699eZ7N/vf+lvGkFhQ0zJ KYcdKz7YK7R/EPcZb8i7mC4SMB8FrncOTJFFoanWxS/OEEG3e6thpiK08Ni0ufpPDurlT6rXM/a EfuRMbyB6828iLxRJ+P/zb/8iH+5QSSonm3hPPtoGU4WlSF1k0SnSzpAw1eMW4vnYfuBUNWaEmf /K7cb57IChZswRD6jH8AVTdrz1Dx6kL0A216YPwuHMJI2CxM9emyi84EFKUcvELYxkOT1epiO3r XxldIfRl6NnRGKpEeuYyKyaVavHh3B6CqE+t7DnXLm8CnDRW4P X-Received: by 2002:a05:6a00:4b55:b0:842:248e:5d26 with SMTP id d2e1a72fcca58-8434cdf7dbamr2138726b3a.11.1781254790583; Fri, 12 Jun 2026 01:59:50 -0700 (PDT) Received: from csl-conti-dell7858.ntu.edu.sg ([155.69.195.57]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8434a934a97sm1646892b3a.0.2026.06.12.01.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2026 01:59:50 -0700 (PDT) From: Maoyi Xie To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Steffen Klassert , Herbert Xu , Simon Horman , Kuniyuki Iwashima , Xiao Liang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Maoyi Xie Subject: [PATCH net v6 1/7] net: ip_gre: require CAP_NET_ADMIN in the device netns for changelink Date: Fri, 12 Jun 2026 16:59:35 +0800 Message-Id: <20260612085941.3158249-2-maoyixie.tju@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260612085941.3158249-1-maoyixie.tju@gmail.com> References: <20260612085941.3158249-1-maoyixie.tju@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A tunnel changelink() operates on at most two netns, dev_net(dev) and the tunnel link netns t->net. They differ once the device is created in or moved to a netns other than the one the request runs in. The rtnl changelink path checks CAP_NET_ADMIN only against dev_net(dev), so a caller privileged there but not in t->net can rewrite a tunnel that lives in t->net. Add rtnl_dev_link_net_capable() next to rtnl_get_net_ns_capable() in net/core/rtnetlink.c. It requires CAP_NET_ADMIN in the link netns and is skipped when the link netns is dev_net(dev), where the rtnl path already checked it. The other patches in this series use the same helper. Gate ipgre_changelink() and erspan_changelink() with it, at the top of the op before any attribute is parsed, because the parsers update live tunnel fields first. ipgre_netlink_parms() sets t->collect_md before ip_tunnel_changelink() runs. Commit 8b484efd5cb4 ("ip6: vti: Use ip6_tnl.net in vti6_siocdevprivate().") added the same check on the ioctl path. This adds it on RTM_NEWLINK. Reported-by: Xiao Liang Closes: https://lore.kernel.org/netdev/CABAhCOSzP1vaThGV35_VnsRCb=87_CPjPVsTHbq905k8A+BuUg@mail.gmail.com/ Fixes: b57708add314 ("gre: add x-netns support") Cc: stable@vger.kernel.org Signed-off-by: Maoyi Xie Reviewed-by: Kuniyuki Iwashima --- include/net/rtnetlink.h | 2 ++ net/core/rtnetlink.c | 8 ++++++++ net/ipv4/ip_gre.c | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h index ec65a8cebb99..2bff41aacc98 100644 --- a/include/net/rtnetlink.h +++ b/include/net/rtnetlink.h @@ -256,6 +256,8 @@ int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm, int rtnl_nla_parse_ifinfomsg(struct nlattr **tb, const struct nlattr *nla_peer, struct netlink_ext_ack *exterr); struct net *rtnl_get_net_ns_capable(struct sock *sk, int netnsid); +bool rtnl_dev_link_net_capable(const struct net_device *dev, + const struct net *link_net); #define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 511c25bf6f2a..3be5f264f5ad 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -2421,6 +2421,14 @@ struct net *rtnl_get_net_ns_capable(struct sock *sk, int netnsid) } EXPORT_SYMBOL_GPL(rtnl_get_net_ns_capable); +bool rtnl_dev_link_net_capable(const struct net_device *dev, + const struct net *link_net) +{ + return net_eq(link_net, dev_net(dev)) || + ns_capable(link_net->user_ns, CAP_NET_ADMIN); +} +EXPORT_SYMBOL_GPL(rtnl_dev_link_net_capable); + static int rtnl_valid_dump_ifinfo_req(const struct nlmsghdr *nlh, bool strict_check, struct nlattr **tb, struct netlink_ext_ack *extack) diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index 169e2921a851..0ebed1438f6c 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -1457,6 +1457,9 @@ static int ipgre_changelink(struct net_device *dev, struct nlattr *tb[], __u32 fwmark = t->fwmark; int err; + if (!rtnl_dev_link_net_capable(dev, t->net)) + return -EPERM; + err = ipgre_newlink_encap_setup(dev, data); if (err) return err; @@ -1486,6 +1489,9 @@ static int erspan_changelink(struct net_device *dev, struct nlattr *tb[], __u32 fwmark = t->fwmark; int err; + if (!rtnl_dev_link_net_capable(dev, t->net)) + return -EPERM; + err = ipgre_newlink_encap_setup(dev, data); if (err) return err; -- 2.34.1