Skip to content

Commit

Permalink
fix(uzfs): Fix zc_nvlist_dst buffer allocation when ioctl is ZFS_IOC_…
Browse files Browse the repository at this point in the history
…ERROR_LOG (#82)


Normally, when the ZFS client/userland performs an ioctl, zc_nvlist_dst_size
refers to the amount of bytes that should be allocated for zc_nvlist_dst.
However, for ZFS_IOC_ERROR_LOG specifically, zc_nvlist_dst_size refers to the
amount of error log objects (zbookmark_phys_t) that must be written into
zc_nvlist_dst. When allocating memory for the zc_nvlist_dst, take this
exception into account. This fixes a crash when retrieving a nonempty ZFS error
log.

Signed-off-by: Sjors Gielen <[email protected]>
  • Loading branch information
sgielen authored Feb 22, 2021
1 parent 0a77074 commit b7e1247
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelogs/unreleased/82-sgielen
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix zc_nvlist_dst buffer allocation when ioctl is ZFS_IOC_ERROR_LOG.
6 changes: 5 additions & 1 deletion src/libuzfs_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ static int inline uzfs_ioctl_init(uzfs_ioctl_t *cmd, zfs_cmd_t *zc)
zc->zc_nvlist_src = (uint64_t)ptr;
}
if (zc->zc_nvlist_dst_size) {
ptr = malloc(zc->zc_nvlist_dst_size);
uint64_t alloc_size = zc->zc_nvlist_dst_size;
if (cmd->ioc_num == ZFS_IOC_ERROR_LOG) {
alloc_size *= sizeof (zbookmark_phys_t);
}
ptr = malloc(alloc_size);
if (ptr == NULL)
goto err;
zc->zc_nvlist_dst = (uint64_t)ptr;
Expand Down

0 comments on commit b7e1247

Please sign in to comment.