From: LOLi Date: Mon, 12 Nov 2018 02:09:00 +0000 (+0100) Subject: Fix coverity defects: CID 184285 X-Git-Tag: zfs-0.8.0-rc2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c8fd652ce7abe85c5238356248d1918ea9ff5ff8;p=zfs Fix coverity defects: CID 184285 CID 184285: Read from pointer after free (USE_AFTER_FREE) This patch fixes an use-after-free in vdev_config_generate_stats() moving the kmem_free() call at the end of the function. Reviewed-by: George Melikov Reviewed-by: Brian Behlendorf Reviewed-by: Giuseppe Di Natale Signed-off-by: loli10K Closes #8120 --- diff --git a/module/zfs/vdev_label.c b/module/zfs/vdev_label.c index f99085146..65b847d66 100644 --- a/module/zfs/vdev_label.c +++ b/module/zfs/vdev_label.c @@ -228,8 +228,6 @@ vdev_config_generate_stats(vdev_t *vd, nvlist_t *nv) fnvlist_add_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS, (uint64_t *)vs, sizeof (*vs) / sizeof (uint64_t)); - kmem_free(vs, sizeof (*vs)); - /* * Add extended stats into a special extended stats nvlist. This keeps * all the extended stats nicely grouped together. The extended stats @@ -354,6 +352,7 @@ vdev_config_generate_stats(vdev_t *vd, nvlist_t *nv) fnvlist_add_nvlist(nv, ZPOOL_CONFIG_VDEV_STATS_EX, nvx); fnvlist_free(nvx); + kmem_free(vs, sizeof (*vs)); kmem_free(vsx, sizeof (*vsx)); }