Skip to contentSkip to conversation

ceph: update the time stamps and try to drop the suid/sgid

PATCH In review [email protected] 2 participants 5 messages Feb 13, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ceph: update the time stamps and try to drop the suid/sgid

From: Xiubo Li <[email protected]>

The fallocate will try to clear the suid/sgid if a unprevileged user changed the file.

There is no Posix item requires that we should clear the suid/sgid in fallocate code path but this is the default behaviour for most of the filesystems and the VFS layer. And also the same for the write code path, which have already support it.

And also we need to update the time stamps since the fallocate will change the file contents.

Cc: [email protected]
URL: https://tracker.ceph.com/issues/58054

---
 fs/ceph/file.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/ceph/file.c +8 -0
index 903de296f0d3..dee3b445f415 100644
@@ -2502,6 +2502,9 @@ static long ceph_fallocate(struct file *file, int mode,
 	loff_t endoff = 0;
 	loff_t size;
 
+	dout("%s %p %llx.%llx mode %x, offset %llu length %llu\n", __func__,
+	     inode, ceph_vinop(inode), mode, offset, length);
+
 	if (mode != (FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
 		return -EOPNOTSUPP;
 
@@ -2539,6 +2542,10 @@ static long ceph_fallocate(struct file *file, int mode,
 	if (ret < 0)
 		goto unlock;
 
+	ret = file_modified(file);
+	if (ret)
+		goto put_caps;
+
 	filemap_invalidate_lock(inode->i_mapping);
 	ceph_fscache_invalidate(inode, false);
 	ceph_zero_pagecache_range(inode, offset, length);
@@ -2554,6 +2561,7 @@ static long ceph_fallocate(struct file *file, int mode,
 	}
 	filemap_invalidate_unlock(inode->i_mapping);
 
+put_caps:
 	ceph_put_cap_refs(ci, got);
 unlock:
 	inode_unlock(inode);
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · On Mon, 2023-02-13 at 19:10 +0800, [email protected] wrote:

From: Xiubo Li <[email protected]>

The fallocate will try to clear the suid/sgid if a unprevileged user changed the file.

There is no Posix item requires that we should clear the suid/sgid in fallocate code path but this is the default behaviour for most of the filesystems and the VFS layer. And also the same for the write code path, which have already support it.

Huh, you're right. It really doesn't say anything about the timestamps or setuid bits:

    https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html

That's arguably a bug in the spec. It really does need to do those things.

Quoted 36 lines

And also we need to update the time stamps since the fallocate will change the file contents.

Cc: [email protected]
URL: https://tracker.ceph.com/issues/58054

---
 fs/ceph/file.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/ceph/file.c +7 -0
index 903de296f0d3..dee3b445f415 100644
@@ -2502,6 +2502,9 @@ static long ceph_fallocate(struct file *file, int mode,
 	loff_t endoff = 0;
 	loff_t size;
 
+	dout("%s %p %llx.%llx mode %x, offset %llu length %llu\n", __func__,
+	     inode, ceph_vinop(inode), mode, offset, length);
+
 	if (mode != (FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
 		return -EOPNOTSUPP;
 
@@ -2539,6 +2542,10 @@ static long ceph_fallocate(struct file *file, int mode,
 	if (ret < 0)
 		goto unlock;
 
+	ret = file_modified(file);
+	if (ret)
+		goto put_caps;
+
 	filemap_invalidate_lock(inode->i_mapping);
 	ceph_fscache_invalidate(inode, false);
 	ceph_zero_pagecache_range(inode, offset, length);

fs/ceph/file.c static long ceph_fallocate(struct file *file, int mode, · line 2567

Quoted 7 lines
fs/ceph/file.c +1 -0
@@ -2554,6 +2561,7 @@ static long ceph_fallocate(struct file *file, int mode,
 	}
 	filemap_invalidate_unlock(inode->i_mapping);
 
+put_caps:
 	ceph_put_cap_refs(ci, got);
 unlock:
 	inode_unlock(inode);
author
#2 lore raw
Quoted 11 lines · Jeff Layton
Quoted 10 lines · On Mon, 2023-02-13 at 19:10 +0800, [email protected] wrote:

From: Xiubo Li <[email protected]>

The fallocate will try to clear the suid/sgid if a unprevileged user changed the file.

There is no Posix item requires that we should clear the suid/sgid in fallocate code path but this is the default behaviour for most of the filesystems and the VFS layer. And also the same for the write code path, which have already support it.

Quoted 8 lines

Huh, you're right. It really doesn't say anything about the timestamps or setuid bits:

     https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html

That's arguably a bug in the spec. It really does need to do those things.

Yeah.

Also the kernel fuse code and libfuse also need to be improved to make ceph-fuse work.

Thanks Jeff.

- Xiubo

Quoted 45 lines
Quoted 36 lines

And also we need to update the time stamps since the fallocate will change the file contents.

Cc: [email protected]
URL: https://tracker.ceph.com/issues/58054

---
  fs/ceph/file.c | 8 ++++++++
  1 file changed, 8 insertions(+)
fs/ceph/file.c +7 -0
index 903de296f0d3..dee3b445f415 100644
@@ -2502,6 +2502,9 @@ static long ceph_fallocate(struct file *file, int mode,
  	loff_t endoff = 0;
  	loff_t size;
 
+	dout("%s %p %llx.%llx mode %x, offset %llu length %llu\n", __func__,
+	     inode, ceph_vinop(inode), mode, offset, length);
+
  	if (mode != (FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
  		return -EOPNOTSUPP;
 
@@ -2539,6 +2542,10 @@ static long ceph_fallocate(struct file *file, int mode,
  	if (ret < 0)
  		goto unlock;
 
+	ret = file_modified(file);
+	if (ret)
+		goto put_caps;
+
  	filemap_invalidate_lock(inode->i_mapping);
  	ceph_fscache_invalidate(inode, false);
  	ceph_zero_pagecache_range(inode, offset, length);

fs/ceph/file.c static long ceph_fallocate(struct file *file, int mode, · line 2567

Quoted 7 lines
fs/ceph/file.c +1 -0
@@ -2554,6 +2561,7 @@ static long ceph_fallocate(struct file *file, int mode,
  	}
  	filemap_invalidate_unlock(inode->i_mapping);
 
+put_caps:
  	ceph_put_cap_refs(ci, got);
  unlock:
  	inode_unlock(inode);
Signature · 6 lines
Best Regards,

Xiubo Li (李秀波)

Email: [email protected]/[email protected]
Slack: @Xiubo Li
#3 lore raw
Quoted 15 lines · Xiubo Li
Quoted 14 lines · Jeff Layton
Quoted 10 lines · On Mon, 2023-02-13 at 19:10 +0800, [email protected] wrote:

From: Xiubo Li <[email protected]>

The fallocate will try to clear the suid/sgid if a unprevileged user changed the file.

There is no Posix item requires that we should clear the suid/sgid in fallocate code path but this is the default behaviour for most of the filesystems and the VFS layer. And also the same for the write code path, which have already support it.

Huh, you're right. It really doesn't say anything about the timestamps or setuid bits:

Quoted 8 lines
Quoted 5 lines
     https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html

That's arguably a bug in the spec. It really does need to do those things.

Yeah.

Actually, posix_fallocate doesn't do hole punching. It just ensures that blocks are reserved to back future writes. Given that that's not something "observable" and won't change the contents of the file, then there really is no need to change the times and clear set{u,g}id bits there.

Linux' fallocate is different. It's a GNU API not covered by POSIX, and can result in an observable change to the contents of the file. There, we _must_ clear the setuid/setgid bits and update timestamps, at least in the cases where the content can change.

Quoted 52 lines

Also the kernel fuse code and libfuse also need to be improved to make ceph-fuse work.

Thanks Jeff.

- Xiubo

Quoted 45 lines
Quoted 36 lines

And also we need to update the time stamps since the fallocate will change the file contents.

Cc: [email protected]
URL: https://tracker.ceph.com/issues/58054

---
  fs/ceph/file.c | 8 ++++++++
  1 file changed, 8 insertions(+)
fs/ceph/file.c +7 -0
index 903de296f0d3..dee3b445f415 100644
@@ -2502,6 +2502,9 @@ static long ceph_fallocate(struct file *file, int mode,
  	loff_t endoff = 0;
  	loff_t size;
 
+	dout("%s %p %llx.%llx mode %x, offset %llu length %llu\n", __func__,
+	     inode, ceph_vinop(inode), mode, offset, length);
+
  	if (mode != (FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
  		return -EOPNOTSUPP;
 
@@ -2539,6 +2542,10 @@ static long ceph_fallocate(struct file *file, int mode,
  	if (ret < 0)
  		goto unlock;
 
+	ret = file_modified(file);
+	if (ret)
+		goto put_caps;
+
  	filemap_invalidate_lock(inode->i_mapping);
  	ceph_fscache_invalidate(inode, false);
  	ceph_zero_pagecache_range(inode, offset, length);

fs/ceph/file.c static long ceph_fallocate(struct file *file, int mode, · line 2567

Quoted 7 lines
fs/ceph/file.c +1 -0
@@ -2554,6 +2561,7 @@ static long ceph_fallocate(struct file *file, int mode,
  	}
  	filemap_invalidate_unlock(inode->i_mapping);
 
+put_caps:
  	ceph_put_cap_refs(ci, got);
  unlock:
  	inode_unlock(inode);
Signature · 1 line
Jeff Layton <[email protected]>
author
#4 lore raw
Quoted 29 lines · Jeff Layton
Quoted 15 lines · Xiubo Li
Quoted 14 lines · Jeff Layton
Quoted 10 lines · On Mon, 2023-02-13 at 19:10 +0800, [email protected] wrote:

From: Xiubo Li <[email protected]>

The fallocate will try to clear the suid/sgid if a unprevileged user changed the file.

There is no Posix item requires that we should clear the suid/sgid in fallocate code path but this is the default behaviour for most of the filesystems and the VFS layer. And also the same for the write code path, which have already support it.

Huh, you're right. It really doesn't say anything about the timestamps or setuid bits:

Quoted 7 lines
Quoted 5 lines
      https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html

That's arguably a bug in the spec. It really does need to do those things.

Yeah.

Actually, posix_fallocate doesn't do hole punching. It just ensures that blocks are reserved to back future writes. Given that that's not something "observable" and won't change the contents of the file, then there really is no need to change the times and clear set{u,g}id bits there.

Quoted 5 lines

Linux' fallocate is different. It's a GNU API not covered by POSIX, and can result in an observable change to the contents of the file. There, we _must_ clear the setuid/setgid bits and update timestamps, at least in the cases where the content can change.

Okay, get it.

Thank you Jeff for detailed explaining about this.

- Xiubo

Quoted 52 lines
Quoted 52 lines

Also the kernel fuse code and libfuse also need to be improved to make ceph-fuse work.

Thanks Jeff.

- Xiubo

Quoted 45 lines
Quoted 36 lines

And also we need to update the time stamps since the fallocate will change the file contents.

Cc: [email protected]
URL: https://tracker.ceph.com/issues/58054

---
   fs/ceph/file.c | 8 ++++++++
   1 file changed, 8 insertions(+)
fs/ceph/file.c +7 -0
index 903de296f0d3..dee3b445f415 100644
@@ -2502,6 +2502,9 @@ static long ceph_fallocate(struct file *file, int mode,
   	loff_t endoff = 0;
   	loff_t size;
 
+	dout("%s %p %llx.%llx mode %x, offset %llu length %llu\n", __func__,
+	     inode, ceph_vinop(inode), mode, offset, length);
+
   	if (mode != (FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
   		return -EOPNOTSUPP;
 
@@ -2539,6 +2542,10 @@ static long ceph_fallocate(struct file *file, int mode,
   	if (ret < 0)
   		goto unlock;
 
+	ret = file_modified(file);
+	if (ret)
+		goto put_caps;
+
   	filemap_invalidate_lock(inode->i_mapping);
   	ceph_fscache_invalidate(inode, false);
   	ceph_zero_pagecache_range(inode, offset, length);

fs/ceph/file.c static long ceph_fallocate(struct file *file, int mode, · line 2567

Quoted 7 lines
fs/ceph/file.c +1 -0
@@ -2554,6 +2561,7 @@ static long ceph_fallocate(struct file *file, int mode,
   	}
   	filemap_invalidate_unlock(inode->i_mapping);
 
+put_caps:
   	ceph_put_cap_refs(ci, got);
   unlock:
   	inode_unlock(inode);
Signature · 6 lines
Best Regards,

Xiubo Li (李秀波)

Email: [email protected]/[email protected]
Slack: @Xiubo Li