All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: stable@vger.kernel.org
Cc: Benjamin Marzinski <bmarzins@redhat.com>,
	Mike Snitzer <snitzer@redhat.com>, Jiri Slaby <jslaby@suse.cz>
Subject: [patch added to 3.12-stable] dm space map metadata: fix 'struct sm_metadata' leak on failed create
Date: Fri, 13 Jan 2017 08:41:53 +0100	[thread overview]
Message-ID: <20170113074159.26811-27-jslaby@suse.cz> (raw)
In-Reply-To: <20170113074159.26811-1-jslaby@suse.cz>

From: Benjamin Marzinski <bmarzins@redhat.com>

This patch has been added to the 3.12 stable tree. If you have any
objections, please let us know.

===============

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'.

[js] no nr_blocks test in 3.12 yet

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: Jiri Slaby <jslaby@suse.cz>
---
 drivers/md/persistent-data/dm-space-map-metadata.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
index 8a8f06bcde60..1543f37c272a 100644
--- a/drivers/md/persistent-data/dm-space-map-metadata.c
+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
@@ -773,15 +773,13 @@ int dm_sm_metadata_create(struct dm_space_map *sm,
 	memcpy(&smm->sm, &bootstrap_ops, sizeof(smm->sm));
 
 	r = sm_ll_new_metadata(&smm->ll, tm);
+	if (!r) {
+		r = sm_ll_extend(&smm->ll, nr_blocks);
+	}
+	memcpy(&smm->sm, &ops, sizeof(smm->sm));
 	if (r)
 		return r;
 
-	r = sm_ll_extend(&smm->ll, nr_blocks);
-	if (r)
-		return r;
-
-	memcpy(&smm->sm, &ops, sizeof(smm->sm));
-
 	/*
 	 * Now we need to update the newly created data structures with the
 	 * allocated blocks that they were built from.
-- 
2.11.0


  parent reply	other threads:[~2017-01-13  7:44 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-13  7:41 [patch added to 3.12-stable] Btrfs: fix tree search logic when replaying directory entry deletes Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] USB: serial: option: add support for Telit LE922A PIDs 0x1040, 0x1041 Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] USB: serial: option: add dlink dwm-158 Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] USB: serial: kl5kusb105: fix open error path Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] USB: cdc-acm: add device id for GW Instek AFG-125 Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] usb: hub: Fix auto-remount of safely removed or ejected USB-3 devices Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] usb: gadget: composite: correctly initialize ep->maxpacket Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] USB: UHCI: report non-PME wakeup signalling for Intel hardware Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] ALSA: usb-audio: Add QuickCam Communicate Deluxe/S7500 to volume_control_quirks Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] ALSA: hiface: Fix M2Tech hiFace driver sampling rate change Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] ALSA: hda - Gate the mic jack on HP Z1 Gen3 AiO Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] Btrfs: fix memory leak in reading btree blocks Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] block_dev: don't test bdev->bd_contains when it is not stable Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] crypto: caam - fix AEAD givenc descriptors Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] ext4: fix mballoc breakage with 64k block size Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] ext4: fix stack memory corruption " Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] ext4: use more strict checks for inodes_per_block on mount Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] ext4: fix in-superblock mount options processing Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] ext4: add sanity checking to count_overhead() Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] ext4: reject inodes with negative size Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] ext4: return -ENOMEM instead of success Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] f2fs: set ->owner for debugfs status file's file_operations Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] mm/vmscan.c: set correct defer count for shrinker Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] fs: exec: apply CLOEXEC before changing dumpable task flags Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] usb: gadget: composite: always set ep->mult to a sensible value Jiri Slaby
2017-01-13  9:20   ` Felipe Balbi
2017-01-13  9:35     ` Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] dm crypt: mark key as invalid until properly loaded Jiri Slaby
2017-01-13  7:41 ` Jiri Slaby [this message]
2017-01-13  7:41 ` [patch added to 3.12-stable] CIFS: Fix a possible memory corruption during reconnect Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] CIFS: Fix missing nls unload in smb2_reconnect() Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] CIFS: Fix a possible memory corruption in push locks Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] xen/gntdev: Use VM_MIXEDMAP instead of VM_IO to avoid NUMA balancing Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] arm/xen: Use alloc_percpu rather than __alloc_percpu Jiri Slaby
2017-01-13  7:41 ` [patch added to 3.12-stable] xfs: set AGI buffer type in xlog_recover_clear_agi_bucket Jiri Slaby

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170113074159.26811-27-jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=bmarzins@redhat.com \
    --cc=snitzer@redhat.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.