Linux 6.18: namespace type moved to ns_common

The namespace type has moved from the namespace ops struct to the
"common" base namespace struct. Detect this and define a macro that does
the right thing for both versions.

Sponsored-by: https://despairlabs.com/sponsor/
Signed-off-by: Rob Norris <robn@despairlabs.com>
This commit is contained in:
Rob Norris
2025-09-29 09:16:36 +10:00
committed by Tony Hutter
parent 005c631499
commit 2778832e22
4 changed files with 51 additions and 80 deletions
+18 -1
View File
@@ -25,6 +25,10 @@
* SUCH DAMAGE.
*/
/*
* Copyright (c) 2025, Rob Norris <robn@despairlabs.com>
*/
#include <sys/types.h>
#include <sys/sysmacros.h>
#include <sys/kmem.h>
@@ -56,6 +60,19 @@ typedef struct zone_dataset {
} zone_dataset_t;
#ifdef CONFIG_USER_NS
/*
* Linux 6.18 moved the generic namespace type away from ns->ops->type onto
* ns_common itself.
*/
#ifdef HAVE_NS_COMMON_TYPE
#define ns_is_newuser(ns) \
((ns)->ns_type == CLONE_NEWUSER)
#else
#define ns_is_newuser(ns) \
((ns)->ops != NULL && (ns)->ops->type == CLONE_NEWUSER)
#endif
/*
* Returns:
* - 0 on success
@@ -84,7 +101,7 @@ user_ns_get(int fd, struct user_namespace **userns)
goto done;
}
ns = get_proc_ns(file_inode(nsfile));
if (ns->ops->type != CLONE_NEWUSER) {
if (!ns_is_newuser(ns)) {
error = ENOTTY;
goto done;
}