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

Fixes for CVE-2017-18925 #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

KenjiBrown
Copy link

Signed-off-by: Sandio Araico Sanchez [email protected]
Bug #540006
hardened mode for opentmpfiles
Ignore some recursive options
Refuse to remove root-owned dirs and files
Refuse to chmod/chdir/chown user-owned dirs and files
Check non-existence before creating a directory
Ensure directory has been newly created before chown/chmod/chgrp
exit on error

Signed-off-by: Sandio Araico Sanchez <[email protected]>
Bug #540006
hardened mode for opentmpfiles
Ignore some recursive options
Refuse to remove root-owned dirs and files
Refuse to chmod/chdir/chown user-owned dirs and files
Check non-existence before creating a directory
Ensure directory has been newly created before chown/chmod/chgrp
exit on error
@KenjiBrown KenjiBrown mentioned this pull request Jun 2, 2022
tmpfiles.sh Outdated
[ "${CREATE}" -gt 0 ] || return 0

relabel "$@"
echo "Ignoring recursively *"

Choose a reason for hiding this comment

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

This makes us non-compliant with the spec: https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html.

@KenjiBrown
Copy link
Author

If some administrator has changed the context, it is for a reason. A regular user doesn't have enough permission to change context.

Allowing the robot to silently restore the context might have unwanted consequences better dealt manually.

An example:

# the administrator gives Wordpress write permission
chcon -R -t httpd_rw_content_t /var/www/wordpress/wp_upload

Some months later, the system reboots and the robot restores context on /var/www recursively, silently removing Wordpress write permissions.

@KenjiBrown
Copy link
Author

KenjiBrown commented Jun 2, 2022

I see no major danger if we skip both _z() and _Z() chunks, porovided the package maintainer has previously defined the correct policies.
Do you want me to roll them back?

Copy link
Member

@vapier vapier left a comment

Choose a reason for hiding this comment

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

kind of seems like we should just shutdown the project. systemd tmpfiles.d can be built independently, so it's questionable whether there's any value in trying to maintain an independent implementation. at least, certainly not one using shell code.

tmpfiles.sh Outdated
return 404
fi
FOUND=$(find "${path}" -maxdepth 0 -uid 0 -gid 0)
if [ -z $FOUND ] ; then
Copy link
Member

Choose a reason for hiding this comment

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

afaict, FOUND is only used here, so there's no need to create it at all. this line also lacks quoting.

if [ -z "$(find "${path}" -maxdepth 0 -uid 0 -gid 0)" ] ; then

Copy link
Author

Choose a reason for hiding this comment

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

Changed in commit 4f4576a

tmpfiles.sh Outdated
@@ -55,6 +69,10 @@ _chattr() {
*) attr="+${attr}" ;;
esac
local IFS=
if ! owned_by_root $1 ; then
Copy link
Member

Choose a reason for hiding this comment

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

need to quote "$1"

comes up below too

Copy link
Author

Choose a reason for hiding this comment

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

Changed in commit 4f4576a

tmpfiles.sh Outdated
if [ -x /sbin/restorecon ]; then
dryrun_or_real restorecon ${CHOPTS} "${path}" || status="$?"
if [ $status -ne 0 ]; then
Copy link
Member

Choose a reason for hiding this comment

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

use braces with ${status}

Copy link
Author

Choose a reason for hiding this comment

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

Changed in commit 4f4576a

if [ -x /sbin/restorecon ]; then
dryrun_or_real restorecon -F "$(splitpath "${path}")"
fi
}

_chmod() {
local path=$2 mode=$1
if ! owned_by_root "${path}" ; then
Copy link
Member

Choose a reason for hiding this comment

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

bad indentation in this code

Copy link
Author

Choose a reason for hiding this comment

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

Changed in commit 4f4576a

@@ -253,7 +401,12 @@ _D() {
local path=$1 mode=$2 uid=$3 gid=$4

if [ -d "${path}" ] && [ "${REMOVE}" -gt 0 ]; then
dryrun_or_real find "${path}" -mindepth 1 -maxdepth 1 -xdev -exec rm -rf {} +
if owned_by_root "${path}" ; then
echo "Cowardly refusing to remove directory" >&2
Copy link
Member

Choose a reason for hiding this comment

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

doesn't this defeat the purpose of using tmpfiles.d ? the entries are supposed to get arbitrary filesystem state back into a known good state. by bailing out here (and elsewhere), the project is only good to create files when they don't yet exist.

Copy link
Author

Choose a reason for hiding this comment

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

The coward refusal happens only when the owner is root.
Removing root-owned directories implies a potential security risk.
user-owned directories are allowed to be removed.

@@ -253,7 +401,12 @@ _D() {
local path=$1 mode=$2 uid=$3 gid=$4

if [ -d "${path}" ] && [ "${REMOVE}" -gt 0 ]; then
dryrun_or_real find "${path}" -mindepth 1 -maxdepth 1 -xdev -exec rm -rf {} +
if owned_by_root "${path}" ; then
Copy link
Member

Choose a reason for hiding this comment

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

can't tmpfiles.d rules create dirs not owned by root by design ? so this basically wedges the state after a single run ?

Copy link
Author

Choose a reason for hiding this comment

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

Directory creation is refused only when a directory with the same name, owned by root already exists.
Removing directories owned by root creates potential a security risk.
Changing ownership of directories owned by root creates potential a security risk.
Only the system administrator should be able to knowingly remove directories owned by root or change ownership.

@lu-zero
Copy link

lu-zero commented Jun 6, 2022

kind of seems like we should just shutdown the project. systemd tmpfiles.d can be built independently, so it's questionable whether there's any value in trying to maintain an independent implementation. at least, certainly not one using shell code.

You started your alternative impl in C++, I guess that can be a valid path forward, the rust impl of the parser is already done and has at least few tests, I guess it could be freshen and documented for those that like to try that way as well.

@vapier
Copy link
Member

vapier commented Jun 6, 2022

i started a rewrite because the systemd one wasn't buildable in isolation. that has changed, so i don't feel the need to pursue my own version anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants