🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #5540

Re: [PATCH v3] tun: Require CAP_NET_ADMIN to attach to an ownerless device

#5540
From: Willem de Bruijn
Date: Tue, 20 Oct 2026 13:47
102 lines
14740 bytes
David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
> 
> Twenty years ago I made creating a tuntap device require CAP_NET_ADMIN
> in commit ca6bb5d7ab22 ("[NET]: Require CAP_NET_ADMIN to create tuntap
> devices.")
> 
> The idea was to allow the permissions on /dev/net/tun to be relaxed to
> 0666 and thus allow owners of tun devices assigned with TUNSETOWNER to
> actually open it and get at their devices.
> 
> What we missed at the time was that persistent devices with *no* owner
> were already essentially world-consumable, and anyone who could open
> the device node could also attach to those.
> 
> Even then, using persistent devices with no explicitly set owner — on
> the (false) presumption that CAP_NET_ADMIN would be required to open
> them — wasn't an egregious userspace bug. There are cases where it does
> make sense to separate the creation/configuration of the netdevice, from
> the process which shovels packets into it.
> 
> Since then, TUNSETGROUP was added a year later in commit 8c644623fe7e
> ("[NET]: Allow group ownership of TUN/TAP devices."). Its commit message
> noted that if both uid and gid are set, both have to match (in itself a
> bizarre choice) — but still not that with *neither* set, no permission
> at all was required.
> 
> Then in 2012 commit c8d68e6be1c3 ("tuntap: multiqueue support") allowed
> new queues to be attached to a device from the moment of its creation,
> with no way for userspace to close the race between creation and a
> subsequent TUNSET{OWNER,GROUP}.
> 
> In 2024, commit 3ca459eaba1bf ("tun: fix group permission check") tried
> to fix things to be saner: only require the user *or* the group to
> match, in line with standard POSIX permissions, and require
> CAP_NET_ADMIN if neither the user nor group authorised the access
> (although it put the CAP_NET_ADMIN check first, and would wrongly have
> reported the capability as having been used even when it was not).
> 
> That fix was reverted in commit a70c7b3cbc06 ("tun: revert fix group
> permission check") due to allegedly causing a regression in an selinux
> test suite which *expected* the attachment to succeed when authorised
> by none of user, group, nor CAP_NET_ADMIN:
> https://lore.kernel.org/netdev/CAFqZXNtkCBT4f+PwyVRmQGoT3p1eVa01fCG_aNtpt6dakXncUg@mail.gmail.com/
> 
> We should not break UAPI. But we don't have to consider an selinux test
> case which deliberately exercises a security flaw to be UAPI worth
> preserving either. To which end, I have fixed it in selinux-testsuite
> commit b2f894f0016b ("tests/tun_tap: set an owner on the device for the
> relabel tests").
> 
> So: fix the lack of CAP_NET_ADMIN check on devices which *haven't* been
> assigned an owner or group, while leaving the weird tun ownership model
> as it was (user *and* group have to match, if both are set). If someone
> still wants to fix the latter (which wasn't actually the reason the
> previous attempt was reverted), they can do it under separate cover.
> 
> Permit attaching to an existing device only if an owner and/or group was
> set and the caller matches all that were set, or if the caller has
> CAP_NET_ADMIN. The only behavioural change is that a device with no
> owner or group now requires CAP_NET_ADMIN to attach — precisely the
> loophole we want to close.
> 
> And put the CAP_NET_ADMIN check in the right place this time.
> 
> Fixes: ca6bb5d7ab22 ("[NET]: Require CAP_NET_ADMIN to create tuntap devices.")
> Reported-by: Andrew Lutomirski <luto@kernel.org>
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> Cc: stable@vger.kernel.org

Reviewed-by: Willem de Bruijn <willemb@google.com> 
Technical Details
Message-ID: <willemdebruijn.kernel.1104f7f83e0dc@gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-349329-linux-kernel-netdev=dewy.ru
References: <3c77f88acff5b3c2617b22d64faad15f6212619c.camel@infradead.org>

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-349329-linux-kernel-netdev=dewy.ru
From: willemdebruijn.kernel@gmail.com (Willem de Bruijn)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v3] tun: Require CAP_NET_ADMIN to attach to an ownerless
 device
Date: Tue, 20 Oct 2026 09:47:05 -0400
Organization: Usenet Network
Message-ID: <willemdebruijn.kernel.1104f7f83e0dc@gmail.com>
References: <3c77f88acff5b3c2617b22d64faad15f6212619c.camel@infradead.org>
MIME-Version: 1.0
Content-Type: text/plain;
 charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="3873319"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:M2KdLbOo4N2Gu9u+xE/6TXa7A2E= sha256:qs+zbekWKZP2tQmDEqo5AIEB1v0/bnPvPRoX1aID/sc=
	sha1:B+JV6xiP7fnP+wKhhIJECKXo1do= sha256:5HbpSkDYEFasI3oyBpoyiJrwnMpb+Sq4lOvr7una0KQ=
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 86F48110D36; Tue, 20 Oct 2026 17:30:23 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
	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=gmail.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 60Gi0yeF4ip8;
	Tue, 20 Oct 2026 17:30:19 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-349329-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 1D1FB110D2A; Tue, 20 Oct 2026 17:30:10 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 9B96A3055D; Tue, 20 Oct 2026 13:49:38 +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=1792504029;
	b=rdvBaSKQMZAub0yIEkfH8rDmo7DiM+0Ug53F3A1vSwq/t0z693V0I1oSSffnxP8a6r6o
	 NigCYc4yUA4QRRicdFgNXbxGLCkC+4c1rWUr+0Il2pI5kMay24e/IbUxVKnvwfDTw49Vc
	 oKLqUZF4nvt/h6KDYIzMXSoRMuJRGX8b0R9AdIb3v7nB5rD9/1CkkgLZ+nvj7XAhrm4Re
	 Me9FcGLNTUtvHw6nbRycHYL1ABBDkP0rwDsBJt7FJ87hfMRcvZz0xi3v+WzFQv1uztxJ6
	 Tg7L2YyFoYC1fUNohFmW/FCp+Qqwt2oB0E3C8kQ3AKtM638SL6/VwCuU5WAoGhjjttg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792504029;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
	 X-Gm-Gg:X-Received:Received:Date:From:To:Cc:Message-ID:In-Reply-To:
	 References:Subject:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Type:Content-Transfer-Encoding;
	bh=2kCP+NrK9u0l64HrUhPWiPnv+LrjBBVOpvFV3ymku6E=;
	b=0QLfiz1Hz/BMqo5znIm7AHCSnQ8Tdi1vLo6smsoFN0FQN9wmKfkDbf4Tcr0Sl1mdccOm
	 IcKiXomBUhJW2IDYvAU3MckMGEZokKwZjeBXb2XpbWyPjo/7vNUWLN6QR5loWwc9fS2qV
	 WdWbe1XPsJiLwVM4mU4cHYeZU9d+aw62mI0SCgkc6p/F8bch1qyUMBU7RhqS/rx9MAfQW
	 44J10f8PrEQunU5QNc6wfRmJNxKIVJDCEn4L5KyToSTcQSliqzh59ZyfA2GcEILNEqB9f
	 LNt9JegD97HYkLSMmjkdHmyvsZQJNzEtNCfvuJgJ5u6TB3fjLD8IYlFnKkH5otw9XxA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=B6PJ+rk1;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	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 A73BE606B66F;
	Tue, 20 Oct 2026 13:47:09 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=B6PJ+rk1
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.217.53
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792504028;
	b=UHQP0c7LUTLqgOoIxGKLU8MXdj4rv7xd3wV98x1PzMqeUiRLbw+opgdvXN+dJfGzQLx2
	 5aJ4+Em3rk89683FPhIvtAJage23+9JGxNP/vosipDuRf6+ECuuvzzDspiGWuIokl9LFj
	 iqDDPMnZIXR5dHgl1RXsWTkJ/CWosMhbFk4lGfy+p8nOc2KDpoojimukUb3AdqkRYAZtz
	 Z1A7ryfnNY1sUFU7lMwzln0LzJ+tBmxBqX0PITvLvPbd7o2JuHyyZybwL1dyA2dOc4cAH
	 qkiSuap0NpM6YZo49muiHN7aLIggFOnY0TnCffH91IvTWFxqzn/KCLlwpCqvksPCvOA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792504028;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
	 Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject:
	 MIME-Version:Content-Type:Content-Transfer-Encoding;
	bh=2kCP+NrK9u0l64HrUhPWiPnv+LrjBBVOpvFV3ymku6E=;
	b=1tR8YOL0kIaigtUn1uHov/caWr1TDT7SrNQVWCpgrL7Uw/Avxm9xhL+hHoQMLjrV3X/o
	 hGxlCncOcJkIAmr2y9wD73gk3EJRtQZpcfYB67MLM4r4a3cQgHhCW4g/bbBve+dUgolAO
	 psi7UlNuboACxixnZ3WWnvJAqeXeld75mifxB9BD9abFl164a/KY+BIZp1GpRct298Ow/
	 NfBujvKt26Cdp1q3VVxOL2BEvNXgAbqiOho/F0KJ1mOSCVlXsNNnS2s6q16uYE/+YYbGu
	 C9iZwi82brpglOkjL1CclroYo7w0qcDtoTw9Su1I9JtU/pcuWc2zUuQKMfUnaBUL3mw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=B6PJ+rk1;
	arc=none smtp.remote-ip=209.85.217.53
X-Received: from mail-vs1-f53.google.com (mail-vs1-f53.google.com [209.85.217.53])
	(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 5F573606B66A
	for <netdev@vger.kernel.org>; Tue, 20 Oct 2026 13:47:08 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5F573606B66A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-vs1-f53.google.com with SMTP id ada2fe7eead31-7cc0e865dd1so1000812137.1
        for <netdev@vger.kernel.org>; Tue, 20 Oct 2026 06:47:08 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1792504027; x=1793108827; darn=vger.kernel.org;
        h=content-transfer-encoding:content-type:mime-version:subject
         :references:in-reply-to:message-id:cc:to:from:date:from:to:cc
         :subject:date:message-id:reply-to:content-type;
        bh=2kCP+NrK9u0l64HrUhPWiPnv+LrjBBVOpvFV3ymku6E=;
        b=B6PJ+rk18ylLoxkPCJ6F32NV8IjBP+Pb/tc4dc9syOL0SREx81gpcKat3KPjeZY/cr
         NrUgbbF+SfbqXVptEQajnq+74clZgXW1WTy6b96nThTXO0mmAOP+u0mIdI2Mt+blYPMQ
         fUhfg487puTajHVCeLlhZxcRlj+kaBfe4otbqXg82ETYO3D5nYaCjNycND9npASccKq/
         AG0XaDIkLzscaxFsR+KeFC2HoDyPhKtKWSMgnFNkSJrkZUhZvVsw1+GvMzTCIQ4Z+DvJ
         rdD8QmS4G1I+A0YUMmpC1eWvNB+VUjlTFjiJODyK3LW1btbWgVi6oFiPk8Iv0R2reA8r
         tEKg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1792504027; x=1793108827;
        h=content-transfer-encoding:content-type:mime-version:subject
         :references:in-reply-to:message-id:cc:to:from:date:x-gm-gg
         :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
         :content-type;
        bh=2kCP+NrK9u0l64HrUhPWiPnv+LrjBBVOpvFV3ymku6E=;
        b=2Vg+cCWpHyFnkiTzCiIfZ7IrO1KJ/Vczo4A+TW6X5tFdHvD9Eno6DE/aYIDw9sblgk
         a/G2InYaiHI62TO1mnytleQOjurz2l5n1LYq2mw48Xtdp9u5B6qM36T0bHwj97XvE3S1
         l5j6lU/lhgiL2GRxDuqcgjq6Rd/U0+/oECXr9L5UgUp9xdy4daQ+gU/5MQ1y6vPjjviw
         tSF8kx08QAKnX9++KxnjjRcYXY39vzhOS7I2SFX1/MCmyzxO8sQzyP4Tkq8eW06E4zGl
         Y8MR/vn4b1YuVtniDBQNTA6pQfFgVgnk8Rsm4O9dyJ+tHbQ7sxBBXWvZiSm1UDRVRUmr
         hyuQ==
X-Forwarded-Encrypted: i=1; AKwUvByuONLdOyPJqogj2acN9L6q5Ipa3Hhdjg7rWE74SBGEq49rP9fHMRvkp6FC74sHbjKo0p3bO1c=@vger.kernel.org
X-Gm-Message-State: AFq9FYInpvj/vZlxdn9oQlqe3Vz7r2GEXH36Vd0TWkC7mX8sWeoAh0J2
	MLJpW1+N3sI92QbwHZBxBibrvKybyRKsWxbieQ+ZTvvN8KRrVttVpkZ+
X-Gm-Gg: AYBFou0XklqC/3y4tHT3MF9omXZnNC6cdXuyXDdRuWulh+2G1OXj5q10ykbZUdVPjxI
	YE9vvkxdgPR+b3pJ4YcZy6kziuoGuBC+BjFyBFe9AnYNSKovB5gF30cnAt4UCSvBWLX0nsKcZUV
	JQbocR8y3ze/t5sTUrop/KdpvBSsNN6uEYdqtw1CtK8KRgPymuRDCWWuGrhwDH50Pr12Ca61xRE
	6A6oEIjdYg78tpfNS/7Llprr3u6+pKpu5dTMnmfzdALmmG5o4x0m4+PBxbViiqknjuI4fmAD1M4
	n5os84IrubD4CaiFtiCSHIEQxkgVCjQ3lB8M2wLXv5L+tYQOUgpn1Qc+OKIw/Ag4rpxgvbxZYrW
	t9vv8CFKDxp0cauEnPfryUg8eCWowxnfKW+1d5bFJh0j2/lZ+tlYtFBxJXERBOQ24qRn4EuyNYA
	ubLfUJOTDgNgKFE6eoEaVW0RDTsxW+r27qud2jtZ54dESJxG3y0Upc8EgU7bP8kJWP++5PTlUGe
	gILgztp4W8vFUB/yRzs6LbStmziRga+FbFIumu1tSqE3qRivXdpKMpXmrQXTpKkWhR1s6zC/PYS
	rzclLf4ywITQodErNMyoCRM4+dMF77SGvehQlw==
X-Received: by 2002:a05:6102:4193:b0:7cc:1942:c156 with SMTP id ada2fe7eead31-7cc36a827aemr2659157137.31.1792504027212;
        Tue, 20 Oct 2026 06:47:07 -0700 (PDT)
X-Received: from gmail.com (111.46.245.35.bc.googleusercontent.com. [35.245.46.111])
        by smtp.gmail.com with ESMTPSA id ada2fe7eead31-7cc7722e6fasm2724111137.7.2026.10.20.06.47.05
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Tue, 20 Oct 2026 06:47:05 -0700 (PDT)
X-Cc: Simon Horman <horms@kernel.org>, 
 Ondrej Mosnacek <omosnace@redhat.com>, 
 Stas Sergeev <stsp2@yandex.ru>, 
 Andrew Lutomirski <luto@kernel.org>
X-In-Reply-To: <3c77f88acff5b3c2617b22d64faad15f6212619c.camel@infradead.org>
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