Skip to content

Commit

Permalink
Add null-checks to prevent null pointer derefernece.
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Mielewczyk <michal.mielewczyk@intel.com>
  • Loading branch information
Michal Mielewczyk committed Apr 19, 2019
1 parent ea66039 commit 65edd33
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 17 additions & 3 deletions modules/cas_cache/layer_cache_management.c
Original file line number Diff line number Diff line change
Expand Up @@ -1232,9 +1232,19 @@ int cache_mng_init_instance(struct ocf_mngt_cache_config *cfg,
}

if (cmd) {
ocf_volume_t cache_obj = ocf_cache_get_volume(cache);
struct bd_object *bd_cache_obj = bd_object(cache_obj);
struct block_device *bdev = bd_cache_obj->btm_bd;
ocf_volume_t cache_obj;
struct bd_object *bd_cache_obj;
struct block_device *bdev;

cache_obj = ocf_cache_get_volume(cache);
if (!cache_obj) {
ocf_mngt_cache_unlock(cache);
cache_mng_exit_instance(ocf_cache_get_id(cache), false);
return -KCAS_ERR_NO_CACHE_ATTACHED;
}

bd_cache_obj = bd_object(cache_obj);
bdev = bd_cache_obj->btm_bd;

/* If we deal with whole device, reread partitions */
if (bdev->bd_contains == bdev)
Expand Down Expand Up @@ -1641,6 +1651,10 @@ int cache_mng_get_info(struct kcas_cache_info *info)

if (info->info.attached) {
uuid = ocf_cache_get_uuid(cache);
if (!uuid) {
result = -OCF_ERR_CACHE_NOT_AVAIL;
goto unlock;
}
strlcpy(info->cache_path_name, uuid->data,
min(sizeof(info->cache_path_name), uuid->size));

Expand Down
6 changes: 6 additions & 0 deletions modules/cas_cache/volume/vol_block_dev_top.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,9 @@ void _blockdev_set_exported_object_flush_fua(ocf_core_t core)
struct request_queue *core_q, *exp_q, *cache_q;
bool flush, fua;

if (!cache_vol)
return;

bd_core_vol = bd_object(core_vol);
bd_cache_vol = bd_object(cache_vol);

Expand Down Expand Up @@ -624,6 +627,9 @@ static int _blockdev_set_geometry(struct casdsk_disk *dsk, void *private)
cache = ocf_core_get_cache(core);
core_vol = ocf_core_get_volume(core);
cache_vol = ocf_cache_get_volume(cache);
if (!cache_vol)
return -KCAS_ERR_NO_CACHE_ATTACHED;

bd_cache_vol = bd_object(cache_vol);
path = ocf_volume_get_uuid(core_vol)->data;

Expand Down

0 comments on commit 65edd33

Please sign in to comment.