From 794fa125e8396c6b91eda7ff684280ac610683bc Mon Sep 17 00:00:00 2001 From: Rafal Stefanowski Date: Tue, 11 Mar 2025 16:43:28 +0100 Subject: [PATCH] Check if cache is attached before setting promotion and seqcutoff params Fixes null pointer dereference if setting those params is attempted on detached cache. Signed-off-by: Rafal Stefanowski --- src/mngt/ocf_mngt_cache.c | 3 +++ src/mngt/ocf_mngt_core.c | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index 5566228..f1575a1 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -3733,6 +3733,9 @@ int ocf_mngt_cache_promotion_set_param(ocf_cache_t cache, ocf_promotion_t type, if (ocf_cache_is_standby(cache)) return -OCF_ERR_CACHE_STANDBY; + if (!ocf_cache_is_device_attached(cache)) + return -OCF_ERR_CACHE_DETACHED; + ocf_metadata_start_exclusive_access(&cache->metadata.lock); result = ocf_promotion_set_param(cache, type, param_id, param_value); diff --git a/src/mngt/ocf_mngt_core.c b/src/mngt/ocf_mngt_core.c index c32e033..cc6dc93 100644 --- a/src/mngt/ocf_mngt_core.c +++ b/src/mngt/ocf_mngt_core.c @@ -1258,6 +1258,9 @@ int ocf_mngt_core_set_seq_cutoff_promote_on_threshold(ocf_core_t core, if (ocf_cache_is_standby(cache)) return -OCF_ERR_CACHE_STANDBY; + if (!ocf_cache_is_device_attached(cache)) + return -OCF_ERR_CACHE_DETACHED; + return _cache_mngt_set_core_seq_cutoff_promote_on_threshold(core, &promote); } @@ -1269,6 +1272,9 @@ int ocf_mngt_core_set_seq_cutoff_promote_on_threshold_all(ocf_cache_t cache, if (ocf_cache_is_standby(cache)) return -OCF_ERR_CACHE_STANDBY; + if (!ocf_cache_is_device_attached(cache)) + return -OCF_ERR_CACHE_DETACHED; + return ocf_core_visit(cache, _cache_mngt_set_core_seq_cutoff_promote_on_threshold, &promote, true);