Inode operations that create a new filesystem object such as ->mknod, ->create, ->mkdir() and others don't take a {g,u}id argument explicitly. Instead the caller's fs{g,u}id is used for the {g,u}id of the new filesystem object. In order to ensure that the correct {g,u}id is used map the caller's fs{g,u}id for creation requests. This doesn't require complex changes. It suffices to pass in the relevant idmapping recorded in the request message. If this request message was triggered from an inode operation that creates filesystem objects it will have passed down the relevant idmaping. If this is a request message that was triggered from an inode operation that doens't need to take idmappings into account the initial idmapping is passed down which is an identity mapping. This change uses a new cephfs protocol extension CEPHFS_FEATURE_HAS_OWNER_UIDGID which adds two new fields (owner_{u,g}id) to the request head structure. So, we need to ensure that MDS supports it otherwise we need to fail any IO that comes through an idmapped mount because we can't process it in a proper way. MDS server without such an extension will use caller_{u,g}id fields to set a new inode owner UID/GID which is incorrect because caller_{u,g}id values are unmapped. At the same time we can't map these fields with an idmapping as it can break UID/GID-based permission checks logic on the MDS side. This problem was described with a lot of details at [1], [2]. [1] https://lore.kernel.org/lkml/CAEivzxfw1fHO2TFA4dx3u23ZKK6Q+EThfzuibrhA3RKM=ZOYLg@mail.gmail.com/ [2] https://lore.kernel.org/all/20220104140414.155198-3-brauner@kernel.org/
Showing the changes to include/linux/ceph (1 of 3 files). Show all
Unified · Split
| @@ -357,6 +357,11 @@ enum { · 356 unmodified lines | |||
| 357 | CEPH_MDS_OP_RENAMESNAP = 0x01403, | 357 | CEPH_MDS_OP_RENAMESNAP = 0x01403, |
| 358 | }; | 358 | }; |
| 359 | 359 | ||
| 360 | #define IS_CEPH_MDS_OP_NEWINODE(op) (op == CEPH_MDS_OP_CREATE || \ | ||
| 361 | op == CEPH_MDS_OP_MKNOD || \ | ||
| 362 | op == CEPH_MDS_OP_MKDIR || \ | ||
| 363 | op == CEPH_MDS_OP_SYMLINK) | ||
| 364 | |||
| 360 | extern const char *ceph_mds_op_name(int op); | 365 | extern const char *ceph_mds_op_name(int op); |
| 361 | 366 | ||
| 362 | #define CEPH_SETATTR_MODE (1 << 0) | 367 | #define CEPH_SETATTR_MODE (1 << 0) |
| @@ -497,7 +502,7 @@ struct ceph_mds_request_head_legacy { · 134 unmodified lines | |||
| 497 | union ceph_mds_request_args args; | 502 | union ceph_mds_request_args args; |
| 498 | } __attribute__ ((packed)); | 503 | } __attribute__ ((packed)); |
| 499 | 504 | ||
| 500 | #define CEPH_MDS_REQUEST_HEAD_VERSION 2 | 505 | #define CEPH_MDS_REQUEST_HEAD_VERSION 3 |
| 501 | 506 | ||
| 502 | struct ceph_mds_request_head_old { | 507 | struct ceph_mds_request_head_old { |
| 503 | __le16 version; /* struct version */ | 508 | __le16 version; /* struct version */ |
| @@ -528,6 +533,9 @@ struct ceph_mds_request_head { · 24 unmodified lines | |||
| 528 | 533 | ||
| 529 | __le32 ext_num_retry; /* new count retry attempts */ | 534 | __le32 ext_num_retry; /* new count retry attempts */ |
| 530 | __le32 ext_num_fwd; /* new count fwd attempts */ | 535 | __le32 ext_num_fwd; /* new count fwd attempts */ |
| 536 | |||
| 537 | __le32 struct_len; /* to store size of struct ceph_mds_request_head */ | ||
| 538 | __le32 owner_uid, owner_gid; /* used for OPs which create inodes */ | ||
| 531 | } __attribute__ ((packed)); | 539 | } __attribute__ ((packed)); |
| 532 | 540 | ||
| 533 | /* cap/lease release record */ | 541 | /* cap/lease release record */ |