Skip to content

Commit

Permalink
Linux 6.8 compat: handle mnt_idmap user_namespace change
Browse files Browse the repository at this point in the history
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/
  • Loading branch information
robn committed Jan 24, 2024
1 parent 20e91c0 commit 6e589ec
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
25 changes: 25 additions & 0 deletions config/kernel-idmap_mnt_api.m4
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,28 @@ AC_DEFUN([ZFS_AC_KERNEL_IDMAP_MNT_API], [
])
])

dnl #
dnl # 6.8 decouples mnt_idmap from user_namespace. This is all internal
dnl # to mnt_idmap so we can't detect it directly, but we detect a related
dnl # change as use that as a signal.
dnl #
AC_DEFUN([ZFS_AC_KERNEL_SRC_IDMAP_NO_USERNS], [
ZFS_LINUX_TEST_SRC([idmap_no_userns], [
#include <linux/uidgid.h>
], [
struct uid_gid_map *map = NULL;
map_id_down(map, 0);
])
])


AC_DEFUN([ZFS_AC_KERNEL_IDMAP_NO_USERNS], [
AC_MSG_CHECKING([whether idmapped mounts have a user namespace])
ZFS_LINUX_TEST_RESULT([idmap_no_userns], [
AC_MSG_RESULT([yes])
AC_DEFINE(HAVE_IDMAP_NO_USERNS, 1,
[mnt_idmap does not have user_namespace])
], [
AC_MSG_RESULT([no])
])
])
2 changes: 2 additions & 0 deletions config/kernel.m4
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [
ZFS_AC_KERNEL_SRC___COPY_FROM_USER_INATOMIC
ZFS_AC_KERNEL_SRC_USER_NS_COMMON_INUM
ZFS_AC_KERNEL_SRC_IDMAP_MNT_API
ZFS_AC_KERNEL_SRC_IDMAP_NO_USERNS
ZFS_AC_KERNEL_SRC_IATTR_VFSID
ZFS_AC_KERNEL_SRC_FILEMAP
ZFS_AC_KERNEL_SRC_WRITEPAGE_T
Expand Down Expand Up @@ -305,6 +306,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
ZFS_AC_KERNEL___COPY_FROM_USER_INATOMIC
ZFS_AC_KERNEL_USER_NS_COMMON_INUM
ZFS_AC_KERNEL_IDMAP_MNT_API
ZFS_AC_KERNEL_IDMAP_NO_USERNS
ZFS_AC_KERNEL_IATTR_VFSID
ZFS_AC_KERNEL_FILEMAP
ZFS_AC_KERNEL_WRITEPAGE_T
Expand Down
3 changes: 2 additions & 1 deletion include/os/linux/spl/sys/cred.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ static inline struct user_namespace *zfs_i_user_ns(struct inode *inode)
static inline boolean_t zfs_no_idmapping(struct user_namespace *mnt_userns,
struct user_namespace *fs_userns)
{
return (zfs_is_init_userns(mnt_userns) || mnt_userns == fs_userns);
return (mnt_userns == NULL || zfs_is_init_userns(mnt_userns) ||
mnt_userns == fs_userns);
}

static inline uid_t zfs_uid_to_vfsuid(zidmap_t *mnt_userns,
Expand Down
11 changes: 11 additions & 0 deletions include/os/linux/spl/sys/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,23 @@ typedef int minor_t;
struct user_namespace;
#ifdef HAVE_IOPS_CREATE_IDMAP
#include <linux/refcount.h>
#ifdef HAVE_IDMAP_NO_USERNS
#include <linux/user_namespace.h>
struct mnt_idmap {
struct uid_gid_map uid_map;
struct uid_gid_map gid_map;
refcount_t count;
};
typedef struct mnt_idmap zidmap_t;
#define idmap_owner(p) (NULL)
#else
struct mnt_idmap {
struct user_namespace *owner;
refcount_t count;
};
typedef struct mnt_idmap zidmap_t;
#define idmap_owner(p) (((struct mnt_idmap *)p)->owner)
#endif
#else
typedef struct user_namespace zidmap_t;
#define idmap_owner(p) ((struct user_namespace *)p)
Expand Down

0 comments on commit 6e589ec

Please sign in to comment.