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

zfs_ioctl: saved_poolname can be truncated #10469

Merged
merged 1 commit into from
Jun 17, 2020

Conversation

lundman
Copy link
Contributor

@lundman lundman commented Jun 16, 2020

The ioctl handler will at times save the poolname, truncate it, causing free to mismatch size.

Motivation and Context

Freeing with wrong size causes panic on illumos based kmem implementations.

Description

zfs_ioctl.c's ioctl handler will make a copy of poolname, and truncate it to be only the poolname. It will also call tsd_set() with it, to be freed at a later time. This makes it hard to know the original size. This new code will make a new string for tsd_set() that is exactly the size needed, and keep a strlen copy for local free.

How Has This Been Tested?

Many runs of zfs-tests on macOS

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:

  • My code follows the ZFS on Linux code style requirements.
  • I have updated the documentation accordingly.
  • I have read the contributing document.
  • I have added tests to cover my changes.
  • I have run the ZFS Test Suite with this change applied.
  • All commit messages are properly formatted and contain Signed-off-by.

@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Jun 16, 2020
@codecov
Copy link

codecov bot commented Jun 17, 2020

Codecov Report

Merging #10469 into master will decrease coverage by 1.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10469      +/-   ##
==========================================
- Coverage   80.24%   79.21%   -1.04%     
==========================================
  Files         293      393     +100     
  Lines       83882   123858   +39976     
==========================================
+ Hits        67313    98116   +30803     
- Misses      16569    25742    +9173     
Flag Coverage Δ
#kernel 80.00% <100.00%> (-0.25%) ⬇️
#user 64.97% <ø> (?)
Impacted Files Coverage Δ
module/zfs/zfs_ioctl.c 86.47% <100.00%> (+0.03%) ⬆️
module/zfs/zcp_set.c 87.09% <0.00%> (-12.91%) ⬇️
module/zfs/zfs_ratelimit.c 90.47% <0.00%> (-9.53%) ⬇️
module/os/linux/spl/spl-kmem-cache.c 75.58% <0.00%> (-9.41%) ⬇️
module/zfs/dmu_redact.c 82.15% <0.00%> (-6.24%) ⬇️
module/zfs/zfs_byteswap.c 79.45% <0.00%> (-5.85%) ⬇️
module/zcommon/zfs_deleg.c 92.45% <0.00%> (-5.55%) ⬇️
module/zfs/bpobj.c 86.86% <0.00%> (-5.15%) ⬇️
module/zcommon/zfeature_common.c 92.85% <0.00%> (-4.82%) ⬇️
module/zfs/aggsum.c 95.34% <0.00%> (-4.66%) ⬇️
... and 281 more

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 883a40f...d09bc2f. Read the comment docs.

module/zfs/zfs_ioctl.c Outdated Show resolved Hide resolved
module/zfs/zfs_ioctl.c Outdated Show resolved Hide resolved
module/zfs/zfs_ioctl.c Show resolved Hide resolved
module/zfs/zfs_ioctl.c Outdated Show resolved Hide resolved
As it uses kmem_strdup() and kmem_strfree() which both rely on
strlen() being the same, but saved_poolname can be truncated causing:

SPL: kernel memory allocator:
buffer freed to wrong cache
SPL: buffer was allocated from kmem_alloc_16,
SPL: caller attempting free to kmem_alloc_8.
SPL: buffer=0xffffff90acc66a38  bufctl=0x0  cache: kmem_alloc_8

Signed-off-by: Jorgen Lundman <lundman@lundman.net>
@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Jun 17, 2020
@behlendorf behlendorf merged commit 4458157 into openzfs:master Jun 17, 2020
lundman referenced this pull request in openzfsonosx/openzfs Jun 19, 2020
As it uses kmem_strdup() and kmem_strfree() which both rely on
strlen() being the same, but saved_poolname can be truncated causing:

SPL: kernel memory allocator:
buffer freed to wrong cache
SPL: buffer was allocated from kmem_alloc_16,
SPL: caller attempting free to kmem_alloc_8.
SPL: buffer=0xffffff90acc66a38  bufctl=0x0  cache: kmem_alloc_8

Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Jorgen Lundman <lundman@lundman.net>
Closes #10469
jsai20 pushed a commit to jsai20/zfs that referenced this pull request Mar 30, 2021
As it uses kmem_strdup() and kmem_strfree() which both rely on
strlen() being the same, but saved_poolname can be truncated causing:

SPL: kernel memory allocator:
buffer freed to wrong cache
SPL: buffer was allocated from kmem_alloc_16,
SPL: caller attempting free to kmem_alloc_8.
SPL: buffer=0xffffff90acc66a38  bufctl=0x0  cache: kmem_alloc_8

Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Jorgen Lundman <lundman@lundman.net>
Closes openzfs#10469
@lundman lundman deleted the macOS_pr9 branch May 28, 2021 05:21
sempervictus pushed a commit to sempervictus/zfs that referenced this pull request May 31, 2021
As it uses kmem_strdup() and kmem_strfree() which both rely on
strlen() being the same, but saved_poolname can be truncated causing:

SPL: kernel memory allocator:
buffer freed to wrong cache
SPL: buffer was allocated from kmem_alloc_16,
SPL: caller attempting free to kmem_alloc_8.
SPL: buffer=0xffffff90acc66a38  bufctl=0x0  cache: kmem_alloc_8

Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Jorgen Lundman <lundman@lundman.net>
Closes openzfs#10469
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants