ceph: don't truncate file in atomic_open
authorHu Weiwen <sehuww@mail.scut.edu.cn>
Fri, 1 Jul 2022 02:52:27 +0000 (10:52 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 15 Oct 2022 05:59:01 +0000 (07:59 +0200)
commit 7cb9994754f8a36ae9e5ec4597c5c4c2d6c03832 upstream.

Clear O_TRUNC from the flags sent in the MDS create request.

`atomic_open' is called before permission check. We should not do any
modification to the file here. The caller will do the truncation
afterward.

Fixes: 124e68e74099 ("ceph: file operations")
Signed-off-by: Hu Weiwen <sehuww@mail.scut.edu.cn>
Reviewed-by: Xiubo Li <xiubli@redhat.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
[Xiubo: fixed a trivial conflict for 5.19 backport]
Signed-off-by: Xiubo Li <xiubli@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/ceph/file.c

index e34d52d..53bffda 100644 (file)
@@ -703,6 +703,12 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
        if (dentry->d_name.len > NAME_MAX)
                return -ENAMETOOLONG;
 
+       /*
+        * Do not truncate the file, since atomic_open is called before the
+        * permission check. The caller will do the truncation afterward.
+        */
+       flags &= ~O_TRUNC;
+
        if (flags & O_CREAT) {
                if (ceph_quota_is_max_files_exceeded(dir))
                        return -EDQUOT;
@@ -770,9 +776,7 @@ retry:
        }
 
        set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
-       err = ceph_mdsc_do_request(mdsc,
-                                  (flags & (O_CREAT|O_TRUNC)) ? dir : NULL,
-                                  req);
+       err = ceph_mdsc_do_request(mdsc, (flags & O_CREAT) ? dir : NULL, req);
        if (err == -ENOENT) {
                dentry = ceph_handle_snapdir(req, dentry);
                if (IS_ERR(dentry)) {