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 filesystem_limit enforcement #8280

Closed
wants to merge 1 commit into from
Closed

Conversation

loli10K
Copy link
Contributor

@loli10K loli10K commented Jan 13, 2019

Motivation and Context

Fix #8226
Alternative version #8228

filesystem_limit should not be enforced for users allowed to change it.

Current behaviour:

root@linux:~# # misc functions
root@linux:~# function is_linux() {
>    if [[ "$(uname)" == "Linux" ]]; then
>       return 0
>    else
>       return 1
>    fi
> }
root@linux:~# # setup
root@linux:~# POOLNAME='testpool'
root@linux:~# if is_linux; then
>    TMPDIR='/var/tmp'
>    mountpoint -q $TMPDIR || mount -t tmpfs tmpfs $TMPDIR
>    zpool destroy $POOLNAME
>    rm -f $TMPDIR/zpool_$POOLNAME.dat
>    truncate -s 128m $TMPDIR/zpool_$POOLNAME.dat
>    zpool create $POOLNAME $TMPDIR/zpool_$POOLNAME.dat
> else
>    TMPDIR='/tmp'
>    zpool destroy $POOLNAME
>    rm -f $TMPDIR/zpool_$POOLNAME.dat
>    truncate -s 128m $TMPDIR/zpool_$POOLNAME.dat
>    zpool create $POOLNAME $TMPDIR/zpool_$POOLNAME.dat
> fi
root@linux:~# useradd staff1
root@linux:~# sudo zfs create -o filesystem_limit=3 $POOLNAME/limited
root@linux:~# sudo zfs allow -u staff1 create,mount $POOLNAME/limited
root@linux:~# zfs create $POOLNAME/limited/fs1
root@linux:~# zfs create $POOLNAME/limited/fs2
root@linux:~# zfs create $POOLNAME/limited/fs3
root@linux:~# zfs create $POOLNAME/limited/fs4
cannot create 'testpool/limited/fs4': out of space
root@linux:~# zfs create $POOLNAME/limited/fs4
cannot create 'testpool/limited/fs4': out of space
root@linux:~# zfs create $POOLNAME/limited/fs5
cannot create 'testpool/limited/fs5': out of space
root@linux:~# 

Patch applied:

root@linux:~# modprobe zfs
root@linux:~# # misc functions
root@linux:~# function is_linux() {
>    if [[ "$(uname)" == "Linux" ]]; then
>       return 0
>    else
>       return 1
>    fi
> }
root@linux:~# # setup
root@linux:~# POOLNAME='testpool'
root@linux:~# if is_linux; then
>    TMPDIR='/var/tmp'
>    mountpoint -q $TMPDIR || mount -t tmpfs tmpfs $TMPDIR
>    zpool destroy $POOLNAME
>    rm -f $TMPDIR/zpool_$POOLNAME.dat
>    truncate -s 128m $TMPDIR/zpool_$POOLNAME.dat
>    zpool create $POOLNAME $TMPDIR/zpool_$POOLNAME.dat
> else
>    TMPDIR='/tmp'
>    zpool destroy $POOLNAME
>    rm -f $TMPDIR/zpool_$POOLNAME.dat
>    truncate -s 128m $TMPDIR/zpool_$POOLNAME.dat
>    zpool create $POOLNAME $TMPDIR/zpool_$POOLNAME.dat
> fi
cannot open 'testpool': no such pool
root@linux:~# useradd staff1
root@linux:~# sudo zfs create -o filesystem_limit=3 $POOLNAME/limited
root@linux:~# sudo zfs allow -u staff1 create,mount $POOLNAME/limited
root@linux:~# zfs create $POOLNAME/limited/fs1
root@linux:~# zfs create $POOLNAME/limited/fs2
root@linux:~# zfs create $POOLNAME/limited/fs3
root@linux:~# zfs create $POOLNAME/limited/fs4
root@linux:~# zfs create $POOLNAME/limited/fs4
cannot create 'testpool/limited/fs4': dataset already exists
root@linux:~# zfs create $POOLNAME/limited/fs5

Description

The proposed solution is to verify the CRED() only in open context and then use the kcred for the same secpolicy_zfs() checks in syncing context: this allows the check to be correctly performed a second time while still verifying the caller credentials.

How Has This Been Tested?

Update ZFS Test Suite

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (a change to man pages or other documentation)

Checklist:

As described in the zfs(8) man page the 'filesystem_limit' does not
apply to users who are allowed to change the property.

This was incorrectly failing because unlike all other operations
the credential was being checked again outside the user context in
the syncing context.   Checking the stored user credential in a
different context will always fail on Linux.  See the comment above
priv_policy_ns() for details.

The proposed solution is to verify the CRED() only in open context
and then use the kcred for the same secpolicy_zfs() checks in syncing
context: this allows the check to be correctly performed a second time
while still verifying the caller credentials.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: loli10K <ezomori.nozomu@gmail.com>
@loli10K loli10K mentioned this pull request Jan 13, 2019
12 tasks
@loli10K loli10K added the Status: Work in Progress Not yet ready for general review label Jan 13, 2019
@codecov
Copy link

codecov bot commented Jan 14, 2019

Codecov Report

Merging #8280 into master will increase coverage by 8.64%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8280      +/-   ##
==========================================
+ Coverage   68.24%   76.89%   +8.64%     
==========================================
  Files         335      368      +33     
  Lines      109770   114827    +5057     
==========================================
+ Hits        74917    88293   +13376     
+ Misses      34853    26534    -8319
Flag Coverage Δ
#kernel 76.57% <100%> (+9.5%) ⬆️
#user 66.67% <25%> (+6.34%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6955b40...9259403. Read the comment docs.

@behlendorf
Copy link
Contributor

@loli10K thanks for picking up this work. I'm going to close #8228, and let's more forward with your more targeted alternate solution.

@loli10K
Copy link
Contributor Author

loli10K commented Jan 14, 2019

This solution seems to work for "filesystem_limit" but not with "snapshot_limit": for instance in dsl_dataset_snapshot_check() we call dsl_fs_ss_limit_check() only in syncing context:

https://github.com/zfsonlinux/zfs/blob/master/module/zfs/dsl_dataset.c#L1463.

@tcaputi
Copy link
Contributor

tcaputi commented Mar 11, 2019

@loli10K any updates coming here?

@loli10K
Copy link
Contributor Author

loli10K commented May 21, 2019

@tcaputi this code won't work without modifying every dsl_fs_ss_limit_check() consumer calling the function only in syncing context, which could add slowness in day-to-day operations.

I don't own the hardware to test such a change performance-wise, i'm going to close this.

@loli10K loli10K closed this May 21, 2019
ghost pushed a commit to zfsonfreebsd/ZoF that referenced this pull request Feb 29, 2020
See issue openzfs#8226: Property filesystem_limit does not work as documented

There have been previous attempts to fix the behavior on Linux, but so
far the issue is still open.  See PRs openzfs#8228, openzfs#8280.

The existing tests pass for the incorrect behavior.  This is a problem
on FreeBSD; we are failing the tests because we implement the feature
correctly.

I have adapted the tests based on the work by @loli10K in openzfs#8280 and
extended the changes to fix the snapshot_limit test as well.

Linux now fails these tests, so entries linking to the issue have been
added to the "maybe" group in zts-report.py.

Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
@ghost ghost mentioned this pull request Feb 29, 2020
12 tasks
ghost pushed a commit to zfsonfreebsd/ZoF that referenced this pull request Feb 29, 2020
See issue openzfs#8226: Property filesystem_limit does not work as documented

There have been previous attempts to fix the behavior on Linux, but so
far the issue is still open.  See PRs openzfs#8228, openzfs#8280.

The existing tests pass for the incorrect behavior.  This is a problem
on FreeBSD; we are failing the tests because we implement the feature
correctly.

I have adapted the tests based on the work by @loli10K in openzfs#8280 and
extended the changes to fix the snapshot_limit test as well.

Linux now fails these tests, so entries linking to the issue have been
added to the "maybe" group in zts-report.py.

Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
behlendorf added a commit that referenced this pull request Mar 4, 2020
See issue #8226: Property filesystem_limit does not work as documented

There have been previous attempts to fix the behavior on Linux, but so
far the issue is still open.  See PRs #8228, #8280.

The existing tests pass for the incorrect behavior.  This is a problem
on FreeBSD; we are failing the tests because we implement the feature
correctly.

I have adapted the tests based on the work by @loli10K in #8280 and
extended the changes to fix the snapshot_limit test as well.

Linux now fails these tests, so entries linking to the issue have been
added to the "maybe" group in zts-report.py.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Closes #10082
jsai20 pushed a commit to jsai20/zfs that referenced this pull request Mar 30, 2021
See issue openzfs#8226: Property filesystem_limit does not work as documented

There have been previous attempts to fix the behavior on Linux, but so
far the issue is still open.  See PRs openzfs#8228, openzfs#8280.

The existing tests pass for the incorrect behavior.  This is a problem
on FreeBSD; we are failing the tests because we implement the feature
correctly.

I have adapted the tests based on the work by @loli10K in openzfs#8280 and
extended the changes to fix the snapshot_limit test as well.

Linux now fails these tests, so entries linking to the issue have been
added to the "maybe" group in zts-report.py.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Closes openzfs#10082
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Work in Progress Not yet ready for general review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Property filesystem_limit does not work as documented
3 participants