Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 2827bad

Browse files
lxbszidryomov
authored andcommitted
ceph: check the cephx mds auth access for async dirop
Before doing the op locally we need to check the cephx access. Link: https://tracker.ceph.com/issues/61333 Signed-off-by: Xiubo Li <xiubli@redhat.com> Reviewed-by: Milind Changire <mchangir@redhat.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent 845ae9d commit 2827bad

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

fs/ceph/dir.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,8 +1336,12 @@ static int ceph_unlink(struct inode *dir, struct dentry *dentry)
13361336
struct inode *inode = d_inode(dentry);
13371337
struct ceph_mds_request *req;
13381338
bool try_async = ceph_test_mount_opt(fsc, ASYNC_DIROPS);
1339+
struct dentry *dn;
13391340
int err = -EROFS;
13401341
int op;
1342+
char *path;
1343+
int pathlen;
1344+
u64 pathbase;
13411345

13421346
if (ceph_snap(dir) == CEPH_SNAPDIR) {
13431347
/* rmdir .snap/foo is RMSNAP */
@@ -1351,6 +1355,30 @@ static int ceph_unlink(struct inode *dir, struct dentry *dentry)
13511355
CEPH_MDS_OP_RMDIR : CEPH_MDS_OP_UNLINK;
13521356
} else
13531357
goto out;
1358+
1359+
dn = d_find_alias(dir);
1360+
if (!dn) {
1361+
try_async = false;
1362+
} else {
1363+
path = ceph_mdsc_build_path(mdsc, dn, &pathlen, &pathbase, 0);
1364+
if (IS_ERR(path)) {
1365+
try_async = false;
1366+
err = 0;
1367+
} else {
1368+
err = ceph_mds_check_access(mdsc, path, MAY_WRITE);
1369+
}
1370+
ceph_mdsc_free_path(path, pathlen);
1371+
dput(dn);
1372+
1373+
/* For none EACCES cases will let the MDS do the mds auth check */
1374+
if (err == -EACCES) {
1375+
return err;
1376+
} else if (err < 0) {
1377+
try_async = false;
1378+
err = 0;
1379+
}
1380+
}
1381+
13541382
retry:
13551383
req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS);
13561384
if (IS_ERR(req)) {

fs/ceph/file.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,9 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
790790
bool try_async = ceph_test_mount_opt(fsc, ASYNC_DIROPS);
791791
int mask;
792792
int err;
793+
char *path;
794+
int pathlen;
795+
u64 pathbase;
793796

794797
doutc(cl, "%p %llx.%llx dentry %p '%pd' %s flags %d mode 0%o\n",
795798
dir, ceph_vinop(dir), dentry, dentry,
@@ -807,6 +810,34 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
807810
*/
808811
flags &= ~O_TRUNC;
809812

813+
dn = d_find_alias(dir);
814+
if (!dn) {
815+
try_async = false;
816+
} else {
817+
path = ceph_mdsc_build_path(mdsc, dn, &pathlen, &pathbase, 0);
818+
if (IS_ERR(path)) {
819+
try_async = false;
820+
err = 0;
821+
} else {
822+
int fmode = ceph_flags_to_mode(flags);
823+
824+
mask = MAY_READ;
825+
if (fmode & CEPH_FILE_MODE_WR)
826+
mask |= MAY_WRITE;
827+
err = ceph_mds_check_access(mdsc, path, mask);
828+
}
829+
ceph_mdsc_free_path(path, pathlen);
830+
dput(dn);
831+
832+
/* For none EACCES cases will let the MDS do the mds auth check */
833+
if (err == -EACCES) {
834+
return err;
835+
} else if (err < 0) {
836+
try_async = false;
837+
err = 0;
838+
}
839+
}
840+
810841
retry:
811842
if (flags & O_CREAT) {
812843
if (ceph_quota_is_max_files_exceeded(dir))

0 commit comments

Comments
 (0)