Skip to content

Commit 6e589ec

Browse files
committed
Linux 6.8 compat: handle mnt_idmap user_namespace change
struct mnt_idmap no longer has a struct user_namespace within it. The only place where that matters is when mapping through the initial no-op mapping. Detect this case and handle it by mapping the uid directly. Signed-off-by: Rob Norris <[email protected]> Sponsored-by: https://despairlabs.com/sponsor/
1 parent 20e91c0 commit 6e589ec

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

config/kernel-idmap_mnt_api.m4

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,28 @@ AC_DEFUN([ZFS_AC_KERNEL_IDMAP_MNT_API], [
2323
])
2424
])
2525

26+
dnl #
27+
dnl # 6.8 decouples mnt_idmap from user_namespace. This is all internal
28+
dnl # to mnt_idmap so we can't detect it directly, but we detect a related
29+
dnl # change as use that as a signal.
30+
dnl #
31+
AC_DEFUN([ZFS_AC_KERNEL_SRC_IDMAP_NO_USERNS], [
32+
ZFS_LINUX_TEST_SRC([idmap_no_userns], [
33+
#include <linux/uidgid.h>
34+
], [
35+
struct uid_gid_map *map = NULL;
36+
map_id_down(map, 0);
37+
])
38+
])
39+
40+
41+
AC_DEFUN([ZFS_AC_KERNEL_IDMAP_NO_USERNS], [
42+
AC_MSG_CHECKING([whether idmapped mounts have a user namespace])
43+
ZFS_LINUX_TEST_RESULT([idmap_no_userns], [
44+
AC_MSG_RESULT([yes])
45+
AC_DEFINE(HAVE_IDMAP_NO_USERNS, 1,
46+
[mnt_idmap does not have user_namespace])
47+
], [
48+
AC_MSG_RESULT([no])
49+
])
50+
])

config/kernel.m4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [
158158
ZFS_AC_KERNEL_SRC___COPY_FROM_USER_INATOMIC
159159
ZFS_AC_KERNEL_SRC_USER_NS_COMMON_INUM
160160
ZFS_AC_KERNEL_SRC_IDMAP_MNT_API
161+
ZFS_AC_KERNEL_SRC_IDMAP_NO_USERNS
161162
ZFS_AC_KERNEL_SRC_IATTR_VFSID
162163
ZFS_AC_KERNEL_SRC_FILEMAP
163164
ZFS_AC_KERNEL_SRC_WRITEPAGE_T
@@ -305,6 +306,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
305306
ZFS_AC_KERNEL___COPY_FROM_USER_INATOMIC
306307
ZFS_AC_KERNEL_USER_NS_COMMON_INUM
307308
ZFS_AC_KERNEL_IDMAP_MNT_API
309+
ZFS_AC_KERNEL_IDMAP_NO_USERNS
308310
ZFS_AC_KERNEL_IATTR_VFSID
309311
ZFS_AC_KERNEL_FILEMAP
310312
ZFS_AC_KERNEL_WRITEPAGE_T

include/os/linux/spl/sys/cred.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ static inline struct user_namespace *zfs_i_user_ns(struct inode *inode)
7373
static inline boolean_t zfs_no_idmapping(struct user_namespace *mnt_userns,
7474
struct user_namespace *fs_userns)
7575
{
76-
return (zfs_is_init_userns(mnt_userns) || mnt_userns == fs_userns);
76+
return (mnt_userns == NULL || zfs_is_init_userns(mnt_userns) ||
77+
mnt_userns == fs_userns);
7778
}
7879

7980
static inline uid_t zfs_uid_to_vfsuid(zidmap_t *mnt_userns,

include/os/linux/spl/sys/types.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,23 @@ typedef int minor_t;
5757
struct user_namespace;
5858
#ifdef HAVE_IOPS_CREATE_IDMAP
5959
#include <linux/refcount.h>
60+
#ifdef HAVE_IDMAP_NO_USERNS
61+
#include <linux/user_namespace.h>
62+
struct mnt_idmap {
63+
struct uid_gid_map uid_map;
64+
struct uid_gid_map gid_map;
65+
refcount_t count;
66+
};
67+
typedef struct mnt_idmap zidmap_t;
68+
#define idmap_owner(p) (NULL)
69+
#else
6070
struct mnt_idmap {
6171
struct user_namespace *owner;
6272
refcount_t count;
6373
};
6474
typedef struct mnt_idmap zidmap_t;
6575
#define idmap_owner(p) (((struct mnt_idmap *)p)->owner)
76+
#endif
6677
#else
6778
typedef struct user_namespace zidmap_t;
6879
#define idmap_owner(p) ((struct user_namespace *)p)

0 commit comments

Comments
 (0)