Skip to content

quincy: client: disallow unprivileged users to escalate root privileges#60314

Merged
yuriw merged 1 commit intoceph:quincyfrom
vshankar:wip-client-secfix
Oct 22, 2024
Merged

quincy: client: disallow unprivileged users to escalate root privileges#60314
yuriw merged 1 commit intoceph:quincyfrom
vshankar:wip-client-secfix

Conversation

@vshankar
Copy link
Contributor

An unprivileged user can chmod 777 a directory owned by root and gain access. Fix this bug and also add a test case for the same.

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox
  • jenkins test windows
  • jenkins test rook e2e

An unprivileged user can `chmod 777` a directory owned by root
and gain access. Fix this bug and also add a test case for the
same.

Signed-off-by: Xiubo Li <xiubli@redhat.com>
Signed-off-by: Venky Shankar <vshankar@redhat.com>
@vshankar
Copy link
Contributor Author

jenkins retest this please

@vshankar
Copy link
Contributor Author

Copy link
Contributor

@yuriw yuriw left a comment

Choose a reason for hiding this comment

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

Reviewed-by: Venky Shankar vshankar@redhat.com

@yuriw
Copy link
Contributor

yuriw commented Oct 21, 2024

jenkins test docs

1 similar comment
@yuriw
Copy link
Contributor

yuriw commented Oct 21, 2024

jenkins test docs

@yuriw yuriw merged commit 527d64f into ceph:quincy Oct 22, 2024
*
* Only allow unprivileged users to clear S_ISUID and S_ISUID.
*/
if ((in->mode & (S_ISUID | S_ISGID)) != (stx->stx_mode & (S_ISUID | S_ISGID)) &&
Copy link
Contributor

@ThomasLamprecht ThomasLamprecht Jul 2, 2025

Choose a reason for hiding this comment

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

But this allows any change to SUID or SGID to happen for unprivileged users, not just clearing them like the comment would suggest? Which would then also allow escalating to the user the file is owned (like e.g., root), if it's already an executable.

Copy link
Contributor

@tchaikov tchaikov Jul 5, 2025

Choose a reason for hiding this comment

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

@ThomasLamprecht hi Thomas, i concur with you. i am not a filesystem expert, but after reading through the related documents, i found that

When the owner or group of an executable file is changed by an unprivileged user, the S_ISUID and S_ISGID mode bits are cleared.

see chown(2). so the mode value we receive in the FUSE operations has already been processed by the kernel. If SUID/SGID bits should be cleared according to POSIX rules, they will already be cleared in the mode value passed to the fuse driver.

so there are two cases when it comes to modification to SUID/SGID:

  1. SUID and/or SGID are the only bits cleared by kernel. we should allow this without even checking if current user is root/owner.
  2. otherwise we enforce the regular checks.

before fb1b72d, we allowed an unprivileged user to add mode bits if these bits do not include S_ISUID or S_ISGID.

after fb1b72d, we only allow an unprivileged user to change these two mode bits as long as they don't mutate other bits in the same operation. as you pointed out, this allows an unprivileged to set the S_ISUID and/or S_ISGID bits if they are the only changed bits in this operation.

will come up with a fix shortly.

BTW, the original commit introducing this change was fb1b72d . we should have referenced it in the backport commit..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @ThomasLamprecht - thanks for reporting the issue. This is a pretty serious bug and it is straightforward to reproduce.

ls -l xfile
----------. 1 root root 0 Jul  5 09:04 xfile

➜  tmp.y5yfT8L2Jf chmod 6766 xfile
chmod: changing permissions of 'xfile': Operation not permitted

➜  tmp.y5yfT8L2Jf chmod 6000 xfile
➜  tmp.y5yfT8L2Jf ls -l xfile
---S------. 1 root root 0 Jul  5 09:04 xfile

There isn't a test for this in our qa suite too :/

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks @vshankar for confirming this issue. created #64356

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW, the original commit introducing this change was fb1b72d . we should have referenced it in the backport commit..

@tchaikov - the reason for this is that the original issue (which this PR addressed) was raised in the ceph security list initially. The fixes were scrambled as email patches b/w the interested parties. At that point, there wasn't know how on how to test undisclosed security fixes (for which I spent a good amount of time since absolutely no-one seemed to know about it). Unfortunately, with centos8 support getting dropped, we had to do a final quincy point release and this fix had to be merged in the quincy branch first. Yes, this was a wild deviation from our backporting process, but it was something we did as a one time exception.

The fix itself was reviewed however, but, unfortunately, this bug (which @ThomasLamprecht reported) got overlooked during review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants