Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: Clear setuid bits when writing or truncating #12412

Merged
merged 5 commits into from Dec 19, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/client/Client.cc
Expand Up @@ -6494,7 +6494,9 @@ int Client::_do_setattr(Inode *in, struct ceph_statx *stx, int mask,
}

if (in->caps_issued_mask(CEPH_CAP_AUTH_EXCL)) {
bool kill_sguid = false;
bool kill_sguid = mask & CEPH_SETATTR_KILL_SGUID;

mask &= ~CEPH_SETATTR_KILL_SGUID;

if (mask & CEPH_SETATTR_UID) {
in->ctime = ceph_clock_now(cct);
Expand Down Expand Up @@ -6571,6 +6573,9 @@ int Client::_do_setattr(Inode *in, struct ceph_statx *stx, int mask,
req->set_filepath(path);
req->set_inode(in);

if (mask & CEPH_SETATTR_KILL_SGUID) {
req->inode_drop |= CEPH_CAP_AUTH_SHARED;
}
if (mask & CEPH_SETATTR_MODE) {
req->head.args.setattr.mode = stx->stx_mode;
req->inode_drop |= CEPH_CAP_AUTH_SHARED;
Expand Down Expand Up @@ -8828,9 +8833,22 @@ int Client::_write(Fh *f, int64_t offset, uint64_t size, const char *buf,
utime_t lat;
uint64_t totalwritten;
int have;
int r = get_caps(in, CEPH_CAP_FILE_WR, CEPH_CAP_FILE_BUFFER, &have, endoff);
if (r < 0) {
int r = get_caps(in, CEPH_CAP_FILE_WR|CEPH_CAP_AUTH_SHARED,
CEPH_CAP_FILE_BUFFER, &have, endoff);
if (r < 0)
return r;

/* clear the setuid/setgid bits, if any */
if (unlikely((in->mode & S_ISUID) ||
(in->mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) {
struct ceph_statx stx = { 0 };

put_cap_ref(in, CEPH_CAP_AUTH_SHARED);
r = __setattrx(in, &stx, CEPH_SETATTR_KILL_SGUID, f->actor_perms);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is asynchronously sending off an MDS request and then doing the normal write. That does mean under nasty failure conditions we could send off the write, fail to send off the setattr, and then crash...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that's a synchronous call. do_setattr calls make_request, which appears to wait on the reply (like we would for any other setattr). Am I missing something there?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...wow, I'm not sure how I got that confused. You're right of course.

if (r < 0)
return r;
} else {
put_cap_ref(in, CEPH_CAP_AUTH_SHARED);
}

if (f->flags & O_DIRECT)
Expand Down
1 change: 1 addition & 0 deletions src/include/ceph_fs.h
Expand Up @@ -380,6 +380,7 @@ extern const char *ceph_mds_op_name(int op);
#endif
#define CEPH_SETATTR_MTIME_NOW (1 << 7)
#define CEPH_SETATTR_ATIME_NOW (1 << 8)
#define CEPH_SETATTR_KILL_SGUID (1 << 10)

/*
* Ceph setxattr request flags.
Expand Down
4 changes: 2 additions & 2 deletions src/mds/Server.cc
Expand Up @@ -3740,7 +3740,7 @@ void Server::handle_client_setattr(MDRequestRef& mdr)
__u32 access_mask = MAY_WRITE;

// xlock inode
if (mask & (CEPH_SETATTR_MODE|CEPH_SETATTR_UID|CEPH_SETATTR_GID|CEPH_SETATTR_BTIME))
if (mask & (CEPH_SETATTR_MODE|CEPH_SETATTR_UID|CEPH_SETATTR_GID|CEPH_SETATTR_BTIME|CEPH_SETATTR_KILL_SGUID))
xlocks.insert(&cur->authlock);
if (mask & (CEPH_SETATTR_MTIME|CEPH_SETATTR_ATIME|CEPH_SETATTR_SIZE))
xlocks.insert(&cur->filelock);
Expand Down Expand Up @@ -3800,7 +3800,7 @@ void Server::handle_client_setattr(MDRequestRef& mdr)

if (mask & CEPH_SETATTR_MODE)
pi->mode = (pi->mode & ~07777) | (req->head.args.setattr.mode & 07777);
else if ((mask & (CEPH_SETATTR_UID|CEPH_SETATTR_GID)) &&
else if ((mask & (CEPH_SETATTR_UID|CEPH_SETATTR_GID|CEPH_SETATTR_KILL_SGUID)) &&
S_ISREG(pi->mode)) {
pi->mode &= ~S_ISUID;
if ((pi->mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is from the previous set of commits but I guess I didn't ask — why are we unconditionally removing S_ISUID and doing a check before removing S_ISGID?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the S_ISGID bit set on a file that does not have the group execute bit is (oddly enough) used to indicate that the file is a candidate for mandatory locking. So you only want to clear that bit if the group execute bit is also set.

Expand Down