diff options
author | Benjamin Marzinski <bmarzins@redhat.com> | 2016-11-30 18:56:14 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-01-06 04:40:16 -0500 |
commit | f5dca4881fac42e2db76b1d93a3b3c0895ba49bb (patch) | |
tree | 11a82358b62f281abe570021fc783a6d7621a843 | |
parent | 461f272954cf7a86ce60963bc8b95a9f123b4036 (diff) |
dm space map metadata: fix 'struct sm_metadata' leak on failed create
commit 314c25c56c1ee5026cf99c570bdfe01847927acb upstream.
In dm_sm_metadata_create() we temporarily change the dm_space_map
operations from 'ops' (whose .destroy function deallocates the
sm_metadata) to 'bootstrap_ops' (whose .destroy function doesn't).
If dm_sm_metadata_create() fails in sm_ll_new_metadata() or
sm_ll_extend(), it exits back to dm_tm_create_internal(), which calls
dm_sm_destroy() with the intention of freeing the sm_metadata, but it
doesn't (because the dm_space_map operations is still set to
'bootstrap_ops').
Fix this by setting the dm_space_map operations back to 'ops' if
dm_sm_metadata_create() fails when it is set to 'bootstrap_ops'.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Acked-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/md/persistent-data/dm-space-map-metadata.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c index 7e44005595c1..20557e2c60c6 100644 --- a/drivers/md/persistent-data/dm-space-map-metadata.c +++ b/drivers/md/persistent-data/dm-space-map-metadata.c | |||
@@ -775,17 +775,15 @@ int dm_sm_metadata_create(struct dm_space_map *sm, | |||
775 | memcpy(&smm->sm, &bootstrap_ops, sizeof(smm->sm)); | 775 | memcpy(&smm->sm, &bootstrap_ops, sizeof(smm->sm)); |
776 | 776 | ||
777 | r = sm_ll_new_metadata(&smm->ll, tm); | 777 | r = sm_ll_new_metadata(&smm->ll, tm); |
778 | if (!r) { | ||
779 | if (nr_blocks > DM_SM_METADATA_MAX_BLOCKS) | ||
780 | nr_blocks = DM_SM_METADATA_MAX_BLOCKS; | ||
781 | r = sm_ll_extend(&smm->ll, nr_blocks); | ||
782 | } | ||
783 | memcpy(&smm->sm, &ops, sizeof(smm->sm)); | ||
778 | if (r) | 784 | if (r) |
779 | return r; | 785 | return r; |
780 | 786 | ||
781 | if (nr_blocks > DM_SM_METADATA_MAX_BLOCKS) | ||
782 | nr_blocks = DM_SM_METADATA_MAX_BLOCKS; | ||
783 | r = sm_ll_extend(&smm->ll, nr_blocks); | ||
784 | if (r) | ||
785 | return r; | ||
786 | |||
787 | memcpy(&smm->sm, &ops, sizeof(smm->sm)); | ||
788 | |||
789 | /* | 787 | /* |
790 | * Now we need to update the newly created data structures with the | 788 | * Now we need to update the newly created data structures with the |
791 | * allocated blocks that they were built from. | 789 | * allocated blocks that they were built from. |