From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 904A41805B; Wed, 19 Feb 2025 09:20:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739956840; cv=none; b=A1MMXTz6hpgQIjrDhKDcKL4kYfA0BN7mwi595o3KsGFtsceqFXKvtKtymHl4xK1tqgwB/+kP/EVnoU8VUq8DXvr69NY0zlFeq+qHuGiYdnO+O6T7n3qdFvc/3knIl5dh5VXfnItQ7T8x5XgOETD3pOVRGiLwveq7y5t5qOwtZd4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739956840; c=relaxed/simple; bh=piTd/uvJ1rAxb4mkaghV6vV5tCsjm8E7S83dYLA5nAg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iaHgruXe+QdU/seXfGyV4JbdiCglPGbh9xzDp2dj33Sv+Its1hSH1Qmm+CkmKc93Sf63sb4A5vSCBn8k0yo7U6N/oZyZz0QHZiB+xr6VZ8KrAqGRJ/wi/fUMMU261ySiR8eYH7tzTFHAWfmZO1IoV5G3/CxTzeLSYMueZgJqOo4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=mEZASgwC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="mEZASgwC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18EEBC4CEE7; Wed, 19 Feb 2025 09:20:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1739956840; bh=piTd/uvJ1rAxb4mkaghV6vV5tCsjm8E7S83dYLA5nAg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mEZASgwCfl7ysXaEsxfPcdG2UWqbjk+oYVkQBBRy4Vex3nSN4ttGhGYlBAXfFLkgL 9heOsgc3cBSaxo/xTK+KGGj1cJGnhzZHzvWALWznkq4VMExDskXhXAgIUXxj8Y/e/x VeQavKpmoh7lxQwBHI9808/+44m/3xE5fIirPJy8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Stas Sergeev , Willem de Bruijn , Jason Wang , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.1 286/578] tun: fix group permission check Date: Wed, 19 Feb 2025 09:24:50 +0100 Message-ID: <20250219082704.262699770@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219082652.891560343@linuxfoundation.org> References: <20250219082652.891560343@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stas Sergeev [ Upstream commit 3ca459eaba1bf96a8c7878de84fa8872259a01e3 ] Currently tun checks the group permission even if the user have matched. Besides going against the usual permission semantic, this has a very interesting implication: if the tun group is not among the supplementary groups of the tun user, then effectively no one can access the tun device. CAP_SYS_ADMIN still can, but its the same as not setting the tun ownership. This patch relaxes the group checking so that either the user match or the group match is enough. This avoids the situation when no one can access the device even though the ownership is properly set. Also I simplified the logic by removing the redundant inversions: tun_not_capable() --> !tun_capable() Signed-off-by: Stas Sergeev Reviewed-by: Willem de Bruijn Acked-by: Jason Wang Link: https://patch.msgid.link/20241205073614.294773-1-stsp2@yandex.ru Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/tun.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index ea98d93138c12..a6c9f9062dbd4 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -574,14 +574,18 @@ static u16 tun_select_queue(struct net_device *dev, struct sk_buff *skb, return ret; } -static inline bool tun_not_capable(struct tun_struct *tun) +static inline bool tun_capable(struct tun_struct *tun) { const struct cred *cred = current_cred(); struct net *net = dev_net(tun->dev); - return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) || - (gid_valid(tun->group) && !in_egroup_p(tun->group))) && - !ns_capable(net->user_ns, CAP_NET_ADMIN); + if (ns_capable(net->user_ns, CAP_NET_ADMIN)) + return 1; + if (uid_valid(tun->owner) && uid_eq(cred->euid, tun->owner)) + return 1; + if (gid_valid(tun->group) && in_egroup_p(tun->group)) + return 1; + return 0; } static void tun_set_real_num_queues(struct tun_struct *tun) @@ -2767,7 +2771,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) !!(tun->flags & IFF_MULTI_QUEUE)) return -EINVAL; - if (tun_not_capable(tun)) + if (!tun_capable(tun)) return -EPERM; err = security_tun_dev_open(tun->security); if (err < 0) -- 2.39.5