]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
client/fuse: Fix directory DACs overriding for root
authorKotresh HR <khiremat@redhat.com>
Thu, 28 Apr 2022 10:31:48 +0000 (16:01 +0530)
committerKotresh HR <khiremat@redhat.com>
Tue, 17 May 2022 06:45:41 +0000 (12:15 +0530)
DACs are overridable for directories. For files,
Read/write DACs are always overridable but executable
DACs are overridable when there is at least one exec bit
set.

The files and directory DACS overriding were handled the
same way for root which is incorrect. This patch fixes
DACs overriding as described above for the root.

Fixes: https://tracker.ceph.com/issues/55313
Signed-off-by: Kotresh HR <khiremat@redhat.com>
qa/suites/fs/permission/tasks/cfuse_workunit_misc.yaml
qa/workunits/fs/misc/dac_override.sh [new file with mode: 0755]
src/client/Client.cc

index 6ff6195bfb473959daeaa716863598307b93df9d..ca026c45ff1ec3c49ecf3768d28e14dc84e0ad97 100644 (file)
@@ -9,3 +9,4 @@ tasks:
       all:
         - fs/misc/acl.sh
         - fs/misc/chmod.sh
+        - fs/misc/dac_override.sh
diff --git a/qa/workunits/fs/misc/dac_override.sh b/qa/workunits/fs/misc/dac_override.sh
new file mode 100755 (executable)
index 0000000..dfb1a90
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh -x
+
+expect_failure() {
+       if "$@"; then return 1; else return 0; fi
+}
+
+set -e
+
+mkdir -p testdir
+file=test_chmod.$$
+
+echo "foo" > testdir/${file}
+sudo chmod 600 testdir
+
+# only root can read
+expect_failure cat testdir/${file}
+
+# directory read/write DAC override for root should allow read
+sudo cat testdir/${file}
index 4d9c0dfe8e79b955c372e530cedc169bae2a873c..9d2c4b185df175263e70a88c1954e16ad253f696 100644 (file)
@@ -5721,8 +5721,10 @@ void Client::handle_cap_grant(MetaSession *session, Inode *in, Cap *cap, const M
 int Client::inode_permission(Inode *in, const UserPerm& perms, unsigned want)
 {
   if (perms.uid() == 0) {
-    // Executable are overridable when there is at least one exec bit set
-    if((want & MAY_EXEC) && !(in->mode & S_IXUGO))
+    // For directories, DACs are overridable.
+    // For files, Read/write DACs are always overridable but executable DACs are
+    // overridable when there is at least one exec bit set
+    if(!S_ISDIR(in->mode) && (want & MAY_EXEC) && !(in->mode & S_IXUGO))
       return -CEPHFS_EACCES;
     return 0;
   }