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

Fix zfsctl_snapshot_{,un}mount() issues #5250

Merged
merged 2 commits into from
Oct 11, 2016
Merged

Conversation

stiell
Copy link
Contributor

@stiell stiell commented Oct 8, 2016

Fix use after free in zfsctl_snapshot_unmount(). Use /usr/bin/env instead of /bin/sh to fix a shell code injection flaw and allow use with grsecurity.

Not yet tested on a kernel with grsecurity.

Fixes #4377. Supersedes #4568 and #4573.

stiell added 2 commits October 8, 2016 17:42
Call mount and umount via /usr/bin/env instead of /bin/sh in
zfsctl_snapshot_mount() and zfsctl_snapshot_unmount().

This change fixes a shell code injection flaw.  The call to /bin/sh
passed the mountpoint unescaped, only surrounded by single quotes.  A
mountpoint containing one or more single quotes would cause the command
to fail or potentially execute arbitrary shell code.

This change also provides compatibility with grsecurity patches.
Grsecurity only allows call_usermodehelper() to use helper binaries in
certain paths.  /usr/bin/* is allowed, /bin/* is not.
@mention-bot
Copy link

@stiell, thanks for your PR! By analyzing the history of the files in this pull request, we identified @behlendorf, @dweeezil and @nedbass to be potential reviewers.

Copy link
Contributor

@behlendorf behlendorf left a comment

Choose a reason for hiding this comment

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

This is much simpler solution, and I like how you were able to remove the memory allocations. Assuming this does resolve the Grsecurity issues and pending the results of the buildbot this LGTM.

@stiell
Copy link
Contributor Author

stiell commented Oct 10, 2016

Tested on Gentoo hardened-sources-4.4.8-r1 (grsecurity-3.1-4.4.8-201604252206), automatic mounting and unmounting under .zfs/snapshot works.

@behlendorf
Copy link
Contributor

@rlaager @tuxoko you both commented on the original PRs, could you also review this updated simpler version.

dprintf("unmount; path=%s\n", se->se_path);
error = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
strfree(argv[2]);
zfsctl_snapshot_rele(se);
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the point of this patch when your other patch negate the possibility of use-after-free?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh sorry, the use-after-free is in dprintf not strfree. Then you should just move the zfsctl_snapshot_rele right after dprintf.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The second patch also uses se in argv, so then zfsctl_snapshot_rele would have to be moved to after call_usermodehelper again in that patch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right.

Copy link
Contributor

Choose a reason for hiding this comment

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

@tuxoko can you approve the patch if you're happy with this.

@behlendorf behlendorf merged commit 1697d2d into openzfs:master Oct 11, 2016
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.

grsec: cannot enter .zfs/snapshot/X
5 participants