* [RESEND PATCH] ceph: don't truncate file in atomic_open
[not found] <59d7c10f-7419-971b-c13c-71865f897953@redhat.com>
@ 2022-07-01 2:52 ` Hu Weiwen
2022-07-01 3:21 ` Xiubo Li
2022-10-12 1:51 ` Xiubo Li
0 siblings, 2 replies; 7+ messages in thread
From: Hu Weiwen @ 2022-07-01 2:52 UTC (permalink / raw)
To: Xiubo Li, ceph-devel; +Cc: Hu Weiwen
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>
---
rebased onto ceph_client repo testing branch
fs/ceph/file.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index 296fd1c7ece8..289e66e9cbb0 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -745,6 +745,11 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
err = ceph_wait_on_conflict_unlink(dentry);
if (err)
return err;
+ /*
+ * Do not truncate the file, since atomic_open is called before the
+ * permission check. The caller will do the truncation afterward.
+ */
+ flags &= ~O_TRUNC;
retry:
if (flags & O_CREAT) {
@@ -836,9 +841,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
req->r_new_inode = new_inode;
new_inode = NULL;
- 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)) {
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [RESEND PATCH] ceph: don't truncate file in atomic_open
2022-07-01 2:52 ` [RESEND PATCH] ceph: don't truncate file in atomic_open Hu Weiwen
@ 2022-07-01 3:21 ` Xiubo Li
2022-10-12 1:51 ` Xiubo Li
1 sibling, 0 replies; 7+ messages in thread
From: Xiubo Li @ 2022-07-01 3:21 UTC (permalink / raw)
To: Hu Weiwen, ceph-devel
On 7/1/22 10:52 AM, Hu Weiwen wrote:
> 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>
> ---
> rebased onto ceph_client repo testing branch
>
> fs/ceph/file.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ceph/file.c b/fs/ceph/file.c
> index 296fd1c7ece8..289e66e9cbb0 100644
> --- a/fs/ceph/file.c
> +++ b/fs/ceph/file.c
> @@ -745,6 +745,11 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
> err = ceph_wait_on_conflict_unlink(dentry);
> if (err)
> return err;
> + /*
> + * Do not truncate the file, since atomic_open is called before the
> + * permission check. The caller will do the truncation afterward.
> + */
> + flags &= ~O_TRUNC;
>
> retry:
> if (flags & O_CREAT) {
> @@ -836,9 +841,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
> set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
> req->r_new_inode = new_inode;
> new_inode = NULL;
> - 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)) {
Merged it and thanks!
-- Xiubo
^ permalink raw reply [flat|nested] 7+ messages in thread
* ceph: don't truncate file in atomic_open
2022-07-01 2:52 ` [RESEND PATCH] ceph: don't truncate file in atomic_open Hu Weiwen
2022-07-01 3:21 ` Xiubo Li
@ 2022-10-12 1:51 ` Xiubo Li
2022-10-13 3:30 ` Xiubo Li
2022-10-13 9:12 ` Greg KH
1 sibling, 2 replies; 7+ messages in thread
From: Xiubo Li @ 2022-10-12 1:51 UTC (permalink / raw)
To: stable
Hi Maitainers
This patch is a fix in kceph module and should be backported to any
affected stable old kernels. And the original patch missed tagging
stable and got merged already months ago:
commit 7cb9994754f8a36ae9e5ec4597c5c4c2d6c03832
Author: Hu Weiwen <sehuww@mail.scut.edu.cn>
Date: Fri Jul 1 10:52:27 2022 +0800
ceph: don't truncate file in atomic_open
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>
Just a single patch.
I am not very sure this is the correct way to do this, if anything else
I need to do to backport this to old kernels please let me know.
Thanks!
- Xiubo
On 01/07/2022 10:52, Hu Weiwen wrote:
> 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>
> ---
> rebased onto ceph_client repo testing branch
>
> fs/ceph/file.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ceph/file.c b/fs/ceph/file.c
> index 296fd1c7ece8..289e66e9cbb0 100644
> --- a/fs/ceph/file.c
> +++ b/fs/ceph/file.c
> @@ -745,6 +745,11 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
> err = ceph_wait_on_conflict_unlink(dentry);
> if (err)
> return err;
> + /*
> + * Do not truncate the file, since atomic_open is called before the
> + * permission check. The caller will do the truncation afterward.
> + */
> + flags &= ~O_TRUNC;
>
> retry:
> if (flags & O_CREAT) {
> @@ -836,9 +841,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
> set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
> req->r_new_inode = new_inode;
> new_inode = NULL;
> - 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)) {
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: ceph: don't truncate file in atomic_open
2022-10-12 1:51 ` Xiubo Li
@ 2022-10-13 3:30 ` Xiubo Li
2022-10-13 9:15 ` Greg KH
2022-10-13 9:12 ` Greg KH
1 sibling, 1 reply; 7+ messages in thread
From: Xiubo Li @ 2022-10-13 3:30 UTC (permalink / raw)
To: stable; +Cc: Ilya Dryomov, Gregory Farnum, Venky Shankar
[-- Attachment #1: Type: text/plain, Size: 3240 bytes --]
Hi Maintainers:
This is one very important bug fixing patch needed to be backported for
ceph.
I have attached the patches based one the latest branches[1] of 4.9.y,
4.14.y, 4.19.y, 5.4.y, 5.10.y, 5.15.y and 5.19.y.
This patch is simple and the conflict is trivial.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Thanks!
- Xiubo
On 12/10/2022 09:51, Xiubo Li wrote:
> Hi Maitainers
>
> This patch is a fix in kceph module and should be backported to any
> affected stable old kernels. And the original patch missed tagging
> stable and got merged already months ago:
>
> commit 7cb9994754f8a36ae9e5ec4597c5c4c2d6c03832
> Author: Hu Weiwen <sehuww@mail.scut.edu.cn>
> Date: Fri Jul 1 10:52:27 2022 +0800
>
> ceph: don't truncate file in atomic_open
>
> 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>
>
>
> Just a single patch.
>
> I am not very sure this is the correct way to do this, if anything
> else I need to do to backport this to old kernels please let me know.
>
> Thanks!
>
> - Xiubo
>
>
>
> On 01/07/2022 10:52, Hu Weiwen wrote:
>> 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>
>> ---
>> rebased onto ceph_client repo testing branch
>>
>> fs/ceph/file.c | 9 ++++++---
>> 1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/fs/ceph/file.c b/fs/ceph/file.c
>> index 296fd1c7ece8..289e66e9cbb0 100644
>> --- a/fs/ceph/file.c
>> +++ b/fs/ceph/file.c
>> @@ -745,6 +745,11 @@ int ceph_atomic_open(struct inode *dir, struct
>> dentry *dentry,
>> err = ceph_wait_on_conflict_unlink(dentry);
>> if (err)
>> return err;
>> + /*
>> + * Do not truncate the file, since atomic_open is called before the
>> + * permission check. The caller will do the truncation afterward.
>> + */
>> + flags &= ~O_TRUNC;
>> retry:
>> if (flags & O_CREAT) {
>> @@ -836,9 +841,7 @@ int ceph_atomic_open(struct inode *dir, struct
>> dentry *dentry,
>> set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
>> req->r_new_inode = new_inode;
>> new_inode = NULL;
>> - 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)) {
[-- Attachment #2: 4.9.patch --]
[-- Type: text/x-patch, Size: 1824 bytes --]
From 54677a489cce48b6477042f7e843c9c45af475a3 Mon Sep 17 00:00:00 2001
From: Xiubo Li <xiubli@redhat.com>
Date: Thu, 13 Oct 2022 10:33:07 +0800
Subject: [PATCH] ceph: don't truncate file in atomic_open
[ Upstream commit 7cb9994754f8a36ae9e5ec4597c5c4c2d6c03832]
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 4.9 backport]
Signed-off-by: Xiubo Li <xiubli@redhat.com>
---
fs/ceph/file.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index e818344a052c..e6bf3cd8fae0 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -354,6 +354,11 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
err = ceph_init_dentry(dentry);
if (err < 0)
return err;
+ /*
+ * 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) {
err = ceph_pre_init_acls(dir, &mode, &acls);
@@ -384,9 +389,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
req->r_args.open.mask = cpu_to_le32(mask);
req->r_locked_dir = dir; /* caller holds dir->i_mutex */
- 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);
err = ceph_handle_snapdir(req, dentry, err);
if (err)
goto out_req;
--
2.31.1
[-- Attachment #3: 4.14.patch --]
[-- Type: text/x-patch, Size: 1802 bytes --]
From e435a506cd5846839c3981316752d13a15662d94 Mon Sep 17 00:00:00 2001
From: Xiubo Li <xiubli@redhat.com>
Date: Thu, 13 Oct 2022 10:58:51 +0800
Subject: [PATCH] ceph: don't truncate file in atomic_open
[ Upstream commit 7cb9994754f8a36ae9e5ec4597c5c4c2d6c03832]
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 4.14 backport]
Signed-off-by: Xiubo Li <xiubli@redhat.com>
---
fs/ceph/file.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index 1f873034f469..ddfa6ce3a0fb 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -381,6 +381,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) {
err = ceph_pre_init_acls(dir, &mode, &acls);
if (err < 0)
@@ -411,9 +417,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
req->r_parent = dir;
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);
err = ceph_handle_snapdir(req, dentry, err);
if (err)
goto out_req;
--
2.31.1
[-- Attachment #4: 4.19.patch --]
[-- Type: text/x-patch, Size: 1804 bytes --]
From 7846c7a8083c6355dbf0713811f2e405791b315b Mon Sep 17 00:00:00 2001
From: Xiubo Li <xiubli@redhat.com>
Date: Thu, 13 Oct 2022 11:04:52 +0800
Subject: [PATCH] ceph: don't truncate file in atomic_open
[ Upstream commit 7cb9994754f8a36ae9e5ec4597c5c4c2d6c03832]
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 4.19 backport]
Signed-off-by: Xiubo Li <xiubli@redhat.com>
---
fs/ceph/file.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index 4ce2752c8b71..95d7906fb9ea 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -446,6 +446,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;
@@ -478,9 +484,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
req->r_parent = dir;
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);
err = ceph_handle_snapdir(req, dentry, err);
if (err)
goto out_req;
--
2.31.1
[-- Attachment #5: 5.4.patch --]
[-- Type: text/x-patch, Size: 1803 bytes --]
From ebce1c991e59c57684782c9e506bc474918ee882 Mon Sep 17 00:00:00 2001
From: Xiubo Li <xiubli@redhat.com>
Date: Thu, 13 Oct 2022 11:08:15 +0800
Subject: [PATCH] ceph: don't truncate file in atomic_open
[ Upstream commit 7cb9994754f8a36ae9e5ec4597c5c4c2d6c03832]
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.4 backport]
Signed-off-by: Xiubo Li <xiubli@redhat.com>
---
fs/ceph/file.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index aa1eac6d89f2..83122fc5f813 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -452,6 +452,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;
@@ -490,9 +496,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
req->r_parent = dir;
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);
err = ceph_handle_snapdir(req, dentry, err);
if (err)
goto out_req;
--
2.31.1
[-- Attachment #6: 5.10.patch --]
[-- Type: text/x-patch, Size: 1785 bytes --]
From db49cff7e45b4884657e9932f069ce9ad7d63978 Mon Sep 17 00:00:00 2001
From: Xiubo Li <xiubli@redhat.com>
Date: Thu, 13 Oct 2022 10:51:19 +0800
Subject: [PATCH] ceph: don't truncate file in atomic_open
[ Upstream commit 7cb9994754f8a36ae9e5ec4597c5c4c2d6c03832]
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.10 backport]
Signed-off-by: Xiubo Li <xiubli@redhat.com>
---
fs/ceph/file.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index 93d986856f1c..943655e36a79 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -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;
@@ -769,9 +775,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
}
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);
err = ceph_handle_snapdir(req, dentry, err);
if (err)
goto out_req;
--
2.31.1
[-- Attachment #7: 5.15.patch --]
[-- Type: text/x-patch, Size: 1805 bytes --]
From 3524a8ab33573375a14a3d5608501598ad26e007 Mon Sep 17 00:00:00 2001
From: Xiubo Li <xiubli@redhat.com>
Date: Thu, 13 Oct 2022 11:12:23 +0800
Subject: [PATCH] ceph: don't truncate file in atomic_open
[ Upstream commit 7cb9994754f8a36ae9e5ec4597c5c4c2d6c03832]
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.15 backport]
Signed-off-by: Xiubo Li <xiubli@redhat.com>
---
fs/ceph/file.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index e34d52df4a13..53bffda3c76c 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -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 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
}
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)) {
--
2.31.1
[-- Attachment #8: 5.19.patch --]
[-- Type: text/x-patch, Size: 1805 bytes --]
From ea2af51ef3c67bbf34855cd4d5c95437600047e5 Mon Sep 17 00:00:00 2001
From: Xiubo Li <xiubli@redhat.com>
Date: Thu, 13 Oct 2022 11:15:18 +0800
Subject: [PATCH] ceph: don't truncate file in atomic_open
[ Upstream commit 7cb9994754f8a36ae9e5ec4597c5c4c2d6c03832]
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>
---
fs/ceph/file.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index da59e836a06e..a43e40138a3b 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -740,6 +740,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;
@@ -807,9 +813,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
}
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)) {
--
2.31.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: ceph: don't truncate file in atomic_open
2022-10-12 1:51 ` Xiubo Li
2022-10-13 3:30 ` Xiubo Li
@ 2022-10-13 9:12 ` Greg KH
2022-10-13 9:20 ` Xiubo Li
1 sibling, 1 reply; 7+ messages in thread
From: Greg KH @ 2022-10-13 9:12 UTC (permalink / raw)
To: Xiubo Li; +Cc: stable
On Wed, Oct 12, 2022 at 09:51:43AM +0800, Xiubo Li wrote:
> Hi Maitainers
>
> This patch is a fix in kceph module and should be backported to any affected
> stable old kernels. And the original patch missed tagging stable and got
> merged already months ago:
Does not apply to the trees, sorry. Please provide a working backport
if you wish to see it applied.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: ceph: don't truncate file in atomic_open
2022-10-13 3:30 ` Xiubo Li
@ 2022-10-13 9:15 ` Greg KH
0 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2022-10-13 9:15 UTC (permalink / raw)
To: Xiubo Li; +Cc: stable, Ilya Dryomov, Gregory Farnum, Venky Shankar
On Thu, Oct 13, 2022 at 11:30:06AM +0800, Xiubo Li wrote:
> Hi Maintainers:
>
> This is one very important bug fixing patch needed to be backported for
> ceph.
>
> I have attached the patches based one the latest branches[1] of 4.9.y,
> 4.14.y, 4.19.y, 5.4.y, 5.10.y, 5.15.y and 5.19.y.
>
> This patch is simple and the conflict is trivial.
>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Ah, missed this, thanks, now queued up.
greg k-h
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: ceph: don't truncate file in atomic_open
2022-10-13 9:12 ` Greg KH
@ 2022-10-13 9:20 ` Xiubo Li
0 siblings, 0 replies; 7+ messages in thread
From: Xiubo Li @ 2022-10-13 9:20 UTC (permalink / raw)
To: Greg KH; +Cc: stable
Hi Greg,
On 13/10/2022 17:12, Greg KH wrote:
> On Wed, Oct 12, 2022 at 09:51:43AM +0800, Xiubo Li wrote:
>> Hi Maitainers
>>
>> This patch is a fix in kceph module and should be backported to any affected
>> stable old kernels. And the original patch missed tagging stable and got
>> merged already months ago:
> Does not apply to the trees, sorry. Please provide a working backport
> if you wish to see it applied.
Already sent it out and I saw your have applied to them.
Thanks very much!
- Xiubo
> thanks,
>
> greg k-h
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-10-13 9:20 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <59d7c10f-7419-971b-c13c-71865f897953@redhat.com>
2022-07-01 2:52 ` [RESEND PATCH] ceph: don't truncate file in atomic_open Hu Weiwen
2022-07-01 3:21 ` Xiubo Li
2022-10-12 1:51 ` Xiubo Li
2022-10-13 3:30 ` Xiubo Li
2022-10-13 9:15 ` Greg KH
2022-10-13 9:12 ` Greg KH
2022-10-13 9:20 ` Xiubo Li
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.