client: Don't write permission when the file is marked with SUID or SGID#34821
client: Don't write permission when the file is marked with SUID or SGID#34821renhwztetecs wants to merge 1 commit intoceph:masterfrom
Conversation
src/client/Client.cc
Outdated
| goto out; | ||
|
|
||
| if ((in->mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) | ||
| goto out; |
There was a problem hiding this comment.
this allow all operation for file with setuid/setgid, which is incorrect.
In may_setattr CEPH_SETATTR_MODE backet, we should allow removing SUID/SGID if file write is allowed for uid.
A better fix is set FUSE_HANDLE_KILLPRIV fuse flag, and let libcephfs handle removing suid/sgid on write.
There was a problem hiding this comment.
something like:
diff --git a/src/client/Client.cc b/src/client/Client.cc
index 84fcf91d0d..25a917c704 100644
--- a/src/client/Client.cc
+++ b/src/client/Client.cc
@@ -5394,8 +5394,16 @@ int Client::may_setattr(Inode *in, struct ceph_statx *stx, int mask,
}
if (mask & CEPH_SETATTR_MODE) {
- if (perms.uid() != 0 && perms.uid() != in->uid)
- goto out;
+ if (perms.uid() != 0 && perms.uid() != in->uid) {
+ auto to_clear = ~stx->stx_mode & in->mode & 07777;
+ if (to_clear && !(to_clear & ~(S_ISUID | S_ISGID)) && // only remove setuid/setgid
+ !(stx->stx_mode & ~in->mode & 07777) && // not add new bits
+ !inode_permission(in, perms, MAY_WRITE)) { // may write
+ // hack: kill setuid/setguid on write?
+ } else {
+ goto out;
+ }
+ }
gid_t i_gid = (mask & CEPH_SETATTR_GID) ? stx->stx_gid : in->gid;
if (perms.uid() != 0 && !perms.gid_in_groups(i_gid))
There was a problem hiding this comment.
Thank you
FUSE_HANDLE_KILLPRIV fuse flag is the best way , but only supported in fuse3.0
There was a problem hiding this comment.
!I first try to test it
There was a problem hiding this comment.
The provided method cannot be verified, and the write function will clear out suid and sgid
e400094 to
43c1ce6
Compare
src/client/Client.cc
Outdated
| if (perms.uid() != 0 && perms.uid() != in->uid) | ||
| goto out; | ||
| if (perms.uid() != 0 && perms.uid() != in->uid) { | ||
| if(in->caps_issued_mask(CEPH_CAP_AUTH_EXCL)) { |
There was a problem hiding this comment.
why do you check CEPH_CAP_AUTH_EXCL? It's possible that multiple clients open a setuid file for write at the same time.
There was a problem hiding this comment.
This place is wrong, I modified it, please review again.
I use the pjdfstest tool for a test, the compatibility result is correct
43c1ce6 to
7359389
Compare
| if (perms.uid() != 0 && perms.uid() != in->uid) | ||
| goto out; | ||
| if (perms.uid() != 0 && perms.uid() != in->uid) { | ||
| if((in->mode & S_ISUID) || (in->mode & S_ISGID)) { |
There was a problem hiding this comment.
this means that any user can modify mode of file with setuid/setgid. I don't think it's correct
There was a problem hiding this comment.
the newest code still has this issue
7359389 to
72d371b
Compare
… SUID or SGID The problem appears in the ceph-fuse mount,there is no problem with the kernel mount. we can add the judgment of S_ISUID and S_ISGID in may_setattr. Fixes: https://tracker.ceph.com/issues/45320 Signed-off-by: huanwen ren <ren.huanwen@zte.com.cn>
|
This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days. |
|
This pull request has been automatically closed because there has been no activity for 90 days. Please feel free to reopen this pull request (or open a new one) if the proposed change is still appropriate. Thank you for your contribution! |
… SUID or SGID
The problem appears in the ceph-fuse mount,there is no problem with the kernel mount.
we can add the identification of S_ISUID and S_ISGID in may_setattr.
Fixes: https://tracker.ceph.com/issues/45320
Signed-off-by: huanwen ren ren.huanwen@zte.com.cn
Checklist
Show available Jenkins commands
jenkins retest this pleasejenkins test classic perfjenkins test crimson perfjenkins test signedjenkins test make checkjenkins test make check arm64jenkins test submodulesjenkins test dashboardjenkins test dashboard backendjenkins test docsjenkins render docsjenkins test ceph-volume alljenkins test ceph-volume tox