From 05e0590fbc1696ff53caa1a8b474b68a7f1e3a98 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Mon, 10 Jan 2022 20:03:50 +0100 Subject: [PATCH] Protect core config preparation function against non-existing cache It is legal to call KCAS_IOCTL_INSERT_CORE against non-existing cache (in try_add mode), however in that case core_id has to be provded. Return error code in case when given cache id does not exist and core_id is set to OCF_CORE_MAX. Signed-off-by: Robert Baldyga --- modules/cas_cache/layer_cache_management.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/cas_cache/layer_cache_management.c b/modules/cas_cache/layer_cache_management.c index 6d60e60..13be44c 100644 --- a/modules/cas_cache/layer_cache_management.c +++ b/modules/cas_cache/layer_cache_management.c @@ -1178,6 +1178,10 @@ int cache_mngt_prepare_core_cfg(struct ocf_mngt_core_config *cfg, if (cmd_info->core_id == OCF_CORE_MAX) { struct cache_priv *cache_priv; + + if (!cache) + return -OCF_ERR_CACHE_NOT_EXIST; + cache_priv = ocf_cache_get_priv(cache); core_id = find_free_core_id(cache_priv->core_id_bitmap); if (core_id == OCF_CORE_MAX)