From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.69 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793225896; b=UNHMKBwZsT0AoVqoKnsbmzmsRwei1NHOvGsLxi5I68oW/CjmUGLdB1DXgCgoe1FZmFGf 0Uy9/IonuvluRTDgUStthSzJHXhLqD9+PC933HhDCvyL7KWrRWl6WGxa88mMCmOVQxTC5 O8HFLyNsK4+D4qxYA56SbDj+AnMLD55r2eU2dgfqIM49tO0piEQAEPYIA7YAG96drhk2N wlZReWBJbYrR4gZQ3Y5JMNb48QaQcGikO5hrvsBE0jO8HcSFXbbVgMZxjAUe7Kg6WG6ty XfrUtmWM8MXAHS9NGEu4Vja56ijV/fJhuMl3esmk6sPGlDaj7UPPvlFlogd0jWvl3+g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793225896; 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=yvreDV3mVn12xssyxceWDBLfPLu2J7UvovJL/zogm+L1i2zNJ9tXXeEb5zn/tfFySOvu d9Kby+Li30uF0wfKYw7NIViLMXM+0mQCvSp9JdZ+0+P2acJgEZIS6b/9oZO9LTKZ7H5Z0 /6Zr1PzDjsPKEt7q9Eug31KdiQNH7hseaJkbB8RF5DaqfFKihLTt13kgviVoeqMBSta8Q 7hZRfsKerMJyhJlW0syNwcwCn3jc4l0MFT/+44qcAymxbS4xGA9c43I0v4gF1jBJikSWE KdDpF4eiZySFuOIgTIEAvHBxMu7EIQxIbGzupzn5lgE/K/HKvSo6tJpOT9gG1vEqZCA== 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.69 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (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 95C4960A2620 for ; Wed, 28 Oct 2026 22:18:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 95C4960A2620 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-f69.google.com with SMTP id a640c23a62f3a-c29c391bd2fso129524366b.2 for ; Wed, 28 Oct 2026 15:18:16 -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=te015oHdAWigKzmYXViLu7CF16C8xxUQip7rr2DCCCxuTTaNIz3c4CiRkQ747tUUtm UJuxdCwvNs5dGvEu2YGB8kdkwoYuls/kLM9S9L5e5LGjMq/woDl2+SRny8bEmR/iDk2K 3kfhIJicfGrhhTnmkkOP+0tD42rED+MI7OB/drZ/bxAwF3h1U4aDqc3zi2vFrkhDcTnh icuQQSXOs4cRDmqWlJ03smxd94Ul65N2xRyq9CyodSy7pcztV0PnFoYXRowRWgE9Vlw9 ZGhQc7PERraOdJqI5vIeVFWgCmtmFbNC2l3Tm8wStWNqHw7L0nczHEoOnZoLdV7LNVEu lxww== X-Forwarded-Encrypted: i=1; AKwUvBz+9hX8MbBBdom0wKFdt1MXO4CW/JytK0I51sx0Szac+SuA5/yl1vFH+ioxno5vUNoe4tsoy8Q=@vger.kernel.org X-Gm-Message-State: AFq9FYKKNoq9ahxM2u3VpeP326PRiaaUheSV1g+2qo5rGB6STqCDEzCp 2DDBMkgbgOIsi+7PGuYtfM+H95D+mBS6xRwhcCTA/T2wfI7pGrGHTHKw6YxVr6poi51lNaPrrA= = 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: netdev@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