Skip to content

Commit

Permalink
Don't leak packed recieved proprties
Browse files Browse the repository at this point in the history
When local properties (e.g., from -o and -x) are provided, don't leak
the packed representation of the received properties due to variable
reuse.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Brooks Davis <brooks.davis@sri.com>
Closes openzfs#14197
  • Loading branch information
brooksdavis authored and andrewc12 committed Dec 17, 2022
1 parent fac66e7 commit 119e51e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/libzfs_core/libzfs_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,8 @@ recv_impl(const char *snapname, nvlist_t *recvdprops, nvlist_t *localprops,
fnvlist_free(outnvl);
} else {
zfs_cmd_t zc = {"\0"};
char *packed = NULL;
char *rp_packed = NULL;
char *lp_packed = NULL;
size_t size;

ASSERT3S(g_refcount, >, 0);
Expand All @@ -1125,14 +1126,14 @@ recv_impl(const char *snapname, nvlist_t *recvdprops, nvlist_t *localprops,
(void) strlcpy(zc.zc_value, snapname, sizeof (zc.zc_value));

if (recvdprops != NULL) {
packed = fnvlist_pack(recvdprops, &size);
zc.zc_nvlist_src = (uint64_t)(uintptr_t)packed;
rp_packed = fnvlist_pack(recvdprops, &size);
zc.zc_nvlist_src = (uint64_t)(uintptr_t)rp_packed;
zc.zc_nvlist_src_size = size;
}

if (localprops != NULL) {
packed = fnvlist_pack(localprops, &size);
zc.zc_nvlist_conf = (uint64_t)(uintptr_t)packed;
lp_packed = fnvlist_pack(localprops, &size);
zc.zc_nvlist_conf = (uint64_t)(uintptr_t)lp_packed;
zc.zc_nvlist_conf_size = size;
}

Expand Down Expand Up @@ -1167,8 +1168,10 @@ recv_impl(const char *snapname, nvlist_t *recvdprops, nvlist_t *localprops,
zc.zc_nvlist_dst_size, errors, KM_SLEEP));
}

if (packed != NULL)
fnvlist_pack_free(packed, size);
if (rp_packed != NULL)
fnvlist_pack_free(rp_packed, size);
if (lp_packed != NULL)
fnvlist_pack_free(lp_packed, size);
free((void *)(uintptr_t)zc.zc_nvlist_dst);
}

Expand Down

0 comments on commit 119e51e

Please sign in to comment.