From f3a2bc1eccb884e62be4c0b42935466b79b1342d Mon Sep 17 00:00:00 2001 From: Andy Fiddaman Date: Thu, 8 Jul 2021 13:16:10 +0000 Subject: 6161 zero-sized kmem_alloc() in zfs`spa_load_l2cache Reviewed by: Andrew Stormont Reviewed by: Jason King Approved by: Dan McDonald --- usr/src/uts/common/fs/zfs/spa.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'usr/src') diff --git a/usr/src/uts/common/fs/zfs/spa.c b/usr/src/uts/common/fs/zfs/spa.c index bf3e8a6fd4..70d690d587 100644 --- a/usr/src/uts/common/fs/zfs/spa.c +++ b/usr/src/uts/common/fs/zfs/spa.c @@ -30,8 +30,8 @@ * Copyright (c) 2017, 2019, Datto Inc. All rights reserved. * Copyright 2019 Joyent, Inc. * Copyright (c) 2017, Intel Corporation. - * Copyright 2018 OmniOS Community Edition (OmniOSce) Association. * Copyright 2020 Joshua M. Clulow + * Copyright 2021 OmniOS Community Edition (OmniOSce) Association. */ /* @@ -1731,13 +1731,15 @@ spa_load_l2cache(spa_t *spa) ASSERT(spa_config_held(spa, SCL_ALL, RW_WRITER) == SCL_ALL); + nl2cache = 0; + newvdevs = NULL; if (sav->sav_config != NULL) { VERIFY(nvlist_lookup_nvlist_array(sav->sav_config, ZPOOL_CONFIG_L2CACHE, &l2cache, &nl2cache) == 0); - newvdevs = kmem_alloc(nl2cache * sizeof (void *), KM_SLEEP); - } else { - nl2cache = 0; - newvdevs = NULL; + if (nl2cache > 0) { + newvdevs = kmem_alloc( + nl2cache * sizeof (void *), KM_SLEEP); + } } oldvdevs = sav->sav_vdevs; @@ -1829,7 +1831,11 @@ spa_load_l2cache(spa_t *spa) VERIFY(nvlist_remove(sav->sav_config, ZPOOL_CONFIG_L2CACHE, DATA_TYPE_NVLIST_ARRAY) == 0); - l2cache = kmem_alloc(sav->sav_count * sizeof (void *), KM_SLEEP); + l2cache = NULL; + if (sav->sav_count > 0) { + l2cache = kmem_alloc( + sav->sav_count * sizeof (void *), KM_SLEEP); + } for (i = 0; i < sav->sav_count; i++) l2cache[i] = vdev_config_generate(spa, sav->sav_vdevs[i], B_TRUE, VDEV_CONFIG_L2CACHE); -- cgit v1.2.3