Skip to content

Add defence in depth when dropping privileges#400

Merged
cgzones merged 3 commits intologrotate:masterfrom
cgzones:priv_sep
Jun 30, 2021
Merged

Add defence in depth when dropping privileges#400
cgzones merged 3 commits intologrotate:masterfrom
cgzones:priv_sep

Conversation

@cgzones
Copy link
Member

@cgzones cgzones commented Jun 11, 2021

No description provided.

return 1;
}

if (chdir("/") != 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Why are we changing the working directory? Is it an observable change of behavior? If yes, is it backward-compatible? I think this should be documented in any case.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think currently logrotate does not give any guarantee about the current working directory (when spawning the compress or mail process or when running any scripts).
In config.c we call chdir(), but be at the end we return into the previously directory.
When run by systemd the working directory is by default set to /, see https://www.freedesktop.org/software/systemd/man/systemd.exec.html section WorkingDirectory=.
I am not sure if cron implementations (cronie, ...) give any guarantees.
Adding to the man-page that the current working directory in scripts is unspecified and should not be relied on would make sense to me.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for digging the information. So the change should not be needed when logrotate is triggered by systemd as a system service, which is what many Linux distros do these days.

Copy link
Member Author

Choose a reason for hiding this comment

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

It makes a difference when logrotate is started from a root crontab, where the working directory is the home directory, i.e. /root.

Copy link
Member

@kdudka kdudka Jun 22, 2021

Choose a reason for hiding this comment

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

I have no strong opinion on this. It can improve security in some corner cases but also break compatibility in other corner cases. We should probably prefer the former to stay on the safe side.

@cgzones cgzones merged commit 7520be8 into logrotate:master Jun 30, 2021
@cgzones cgzones deleted the priv_sep branch June 30, 2021 17:36
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.

2 participants