From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793225911; b=ONpzy8MN/+sfv2yURX1/wae/NEnN3wp9R4Rm2ook2vkvIQVBHV38KQP2gEL9chqd8iFM kI5x7py5I+ExKZUyBquPvFS+YiNEDiBR9q+qJuB2shtO9in++V4WHv/pNjBHy6f33ucwc Rk0pMF05c7KJggKOQlegDU0wCvEAxZpPyh4o30CKPCyrcqGmifrdcviZHfE+8HD97YgfW hlPDe+G5w/FXrawwc3r+6csTJFHyexrC9/dcSg4v/F6WDOxwKPP7H8dlVG2M5Okb+Ts1l AGactzv2kL2gh2KNax5CbNEvxaaUY6IpzQD+m6VEHSIPT0ZGLkbVLEN9BH+XhHpx88A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793225911; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=IliLvxEFhtUoKzlsMTRJTupCYDKTYP3W6Uvf0vlrqBM=; b=vkNy0+yq8xP4zxjX6RxW3A3AgxYYhC06cO5U9pFtTf6CO/c+Dz9pl2sH7ExsVFMPHxDX twVRAYJqqU0yM3oIdLfAOfDoZSuLtfWbHzYumU6oMvXmPODrNJK7Pav31dyOrlGsI+uJ1 Dj2jfX4pmPcpupP9AXb2zmUjzWoEiaAWzXEIvQLP952MUpiC6by+oWSk2z1aqQ1RVh/ZC EYLRnJmHb79eU5tOLF9s2H7VUjyYnTU6OlkgXbGN0y4/0gQW/zT6DQWqR6lMESALcqz+I uJBf5J20pwBQpa3KNfIpRcolT23++uEW5YJVq3KjjochT7tOzYRivNjgH6e7NRhX93A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--halg.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=gYALcxqy; arc=none smtp.remote-ip=209.85.218.71 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (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 6D5E260A6F73 for ; Wed, 28 Oct 2026 22:18:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6D5E260A6F73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--halg.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=gYALcxqy Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-c41f85ee4a3so129688566b.1 for ; Wed, 28 Oct 2026 15:18:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1793225895; x=1793830695; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=IliLvxEFhtUoKzlsMTRJTupCYDKTYP3W6Uvf0vlrqBM=; b=gYALcxqyt70MQ79J9EPFtsq/ZeSTxirIEH01aK2bomk/GvpfcsAjBJqb4Y09rzuNLt mO44k7f46rtJ9wunMGpfQFt9lPWqgkNaiFl0SALdNHuEVLvyiq5kt/KV0iSWPCT3tP1c zWS2yVnyhtdinRcEUS5DF+dd6ZPtqU4//4OhOvSQSXIQEeSpBlOhVgl5N3HoKZ8HyqgM 0mOlVcGpmjZAg21fMo5VhSqBp3oUNBCE57ekigI3J8RJl6Rr/QajW+JDtCDvJeRQt3ph p+hNl2pv82gkoFDKvZA/guZs8SZ56A95NQsHaEdHFIKKnIsIwK+zXnT381OZUxwV0rNz Rg8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793225895; x=1793830695; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=IliLvxEFhtUoKzlsMTRJTupCYDKTYP3W6Uvf0vlrqBM=; b=R+7jvWSOj8mqrnk6H+GFfBCG4K5euToEgCV48DCOx3fFFOd0XzmSuGlX55wymTHTLW ndlckhIK02DS2JGtTJdRNXmQAOxtDjgDI768ilchYCWj7i0XtTZ4kqjzL/ce3MMFp4Wh OyLq2hdl1vTgMoECGK27SWvdiSLviGp1UPYbfS715/QAsPQU4Cpk3fQT4UwicS5YpUQk gUEdE88N5XI0hXYzveqgHlb1mRaMK1pYTSRPf/hiDlybZL2ieECDB6h+oDBkpGLznKCc VvHaLvFZiveNTUgqAJeIx65Aa2oyln8r72xxIOZpFIulYP+ynWqIQE4mSUa0LblEObAY c5tg== X-Forwarded-Encrypted: i=1; AKwUvBwCea/qKJ3VpO3draGbPyGmObgMP8sW4OdCzTcJKDgoLh+75EWAmBbrgV7fwFRVeXBO6e51ESZ8cLYST/w/340=@vger.kernel.org X-Gm-Message-State: AFq9FYJOeKvPGNXIp1SCx0viYUkjrLQTRBfmZSSXb/RLQI80xrQspg/c XvNcM0cSGxqSFy+pKC8GjGNM+jatmcdxgDT6PIX7++5b57WkzmdYiMrbgQvFDsXdlyKjI7OjTg= = X-Received: from ejad9.prod.google.com ([2002:a17:906:409:b0:c32:473d:4a4b]) (user=halg job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:3f88:b0:c40:80eb:c54e with SMTP id a640c23a62f3a-c49bddac533mr311667066b.4.1793225894675; Wed, 28 Oct 2026 15:18:14 -0700 (PDT) Date: Wed, 28 Oct 2026 22:17:01 +0000 In-Reply-To: <20261028221705.3915340-1-halg@google.com> X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261028221705.3915340-1-halg@google.com> X-Mailer: git-send-email 2.56.0.313.g2479322e68-goog Message-ID: <20261028221705.3915340-5-halg@google.com> Subject: [PATCH 4/8] nsfs: add NS_USER_GET_INFO ioctl to inspect user namespace capabilities From: "Hallgrimur H. Gunnarsson" To: Christian Brauner , Alexander Viro , Paul Moore , Serge Hallyn , Kees Cook , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Jan Kara , James Morris , Simon Horman , Jonathan Corbet , Shuah Khan , Randy Dunlap , Jann Horn , "=?UTF-8?q?G=C3=BCnther=20Noack?=" , KP Singh , Jonathan Calmels , Casey Schaufler , linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-api@vger.kernel.org, containers@lists.linux.dev, netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, "Hallgrimur H. Gunnarsson" Content-Type: text/plain; charset="UTF-8" With the introduction of a capability bounding set for user namespaces, userspace needs a way to inspect the capability ceiling enforced on a given user namespace. Introduce the NS_USER_GET_INFO ioctl on nsfs file descriptors to query user namespace metadata, mirroring the extensible structure pattern used by NS_MNT_GET_INFO. Signed-off-by: Hallgrimur H. Gunnarsson --- fs/nsfs.c | 29 +++++++++++++++++++++++++++++ include/uapi/linux/nsfs.h | 17 +++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/fs/nsfs.c b/fs/nsfs.c index c3b6ae76594a..50711362d792 100644 --- a/fs/nsfs.c +++ b/fs/nsfs.c @@ -170,6 +170,17 @@ static int copy_ns_info_to_user(const struct mnt_namespace *mnt_ns, return 0; } +static int copy_user_ns_info_to_user(const struct user_namespace *user_ns, + struct user_ns_info __user *uinfo, + size_t usize, struct user_ns_info *kinfo) +{ + kinfo->size = min(usize, sizeof(*kinfo)); + kinfo->spare = 0; + kinfo->cap_bset = user_ns->cap_bset.val; + + return copy_struct_to_user(uinfo, usize, kinfo, sizeof(*kinfo), NULL); +} + static bool nsfs_ioctl_valid(unsigned int cmd) { switch (cmd) { @@ -194,6 +205,8 @@ static bool nsfs_ioctl_valid(unsigned int cmd) return extensible_ioctl_valid(cmd, NS_MNT_GET_NEXT, MNT_NS_INFO_SIZE_VER0); case _IOC_NR(NS_MNT_GET_PREV): return extensible_ioctl_valid(cmd, NS_MNT_GET_PREV, MNT_NS_INFO_SIZE_VER0); + case _IOC_NR(NS_USER_GET_INFO): + return extensible_ioctl_valid(cmd, NS_USER_GET_INFO, USER_NS_INFO_SIZE_VER0); } return false; @@ -360,6 +373,22 @@ static long ns_ioctl(struct file *filp, unsigned int ioctl, ret = fd_publish(fdf); break; } + case _IOC_NR(NS_USER_GET_INFO): { + struct user_ns_info __user *uinfo = (struct user_ns_info __user *)arg; + struct user_ns_info kinfo = {}; + size_t usize = _IOC_SIZE(ioctl); + + if (ns->ns_type != CLONE_NEWUSER) + return -EINVAL; + + if (!uinfo) + return -EINVAL; + + if (usize < USER_NS_INFO_SIZE_VER0) + return -EINVAL; + + return copy_user_ns_info_to_user(to_user_ns(ns), uinfo, usize, &kinfo); + } default: ret = -ENOTTY; } diff --git a/include/uapi/linux/nsfs.h b/include/uapi/linux/nsfs.h index 007fed5971b4..d2996d47c857 100644 --- a/include/uapi/linux/nsfs.h +++ b/include/uapi/linux/nsfs.h @@ -44,6 +44,23 @@ struct mnt_ns_info { #define NS_GET_MNTNS_ID _IOR(NSIO, 5, __u64) #define NS_GET_ID _IOR(NSIO, 13, __u64) +/** + * struct user_ns_info - information about a user namespace + * @size: size of this structure + * @spare: reserved for future use + * @cap_bset: capability bounding set of the user namespace + */ +struct user_ns_info { + __u32 size; + __u32 spare; + __u64 cap_bset; +}; + +#define USER_NS_INFO_SIZE_VER0 16 /* sizeof first published struct */ + +/* Get information about user namespace. */ +#define NS_USER_GET_INFO _IOR(NSIO, 14, struct user_ns_info) + enum init_ns_ino { IPC_NS_INIT_INO = 0xEFFFFFFFU, UTS_NS_INIT_INO = 0xEFFFFFFEU, -- 2.56.0.313.g2479322e68-goog