1 From 940bc471780b004a5277c1931f52af363c2fc9da Mon Sep 17 00:00:00 2001
2 From: Martin Wilck <mwilck@suse.com>
3 Date: Mon, 29 Apr 2019 11:48:15 +0200
4 Subject: dm mpath: always free attached_handler_name in parse_path()
6 From: Martin Wilck <mwilck@suse.com>
8 commit 940bc471780b004a5277c1931f52af363c2fc9da upstream.
10 Commit b592211c33f7 ("dm mpath: fix attached_handler_name leak and
11 dangling hw_handler_name pointer") fixed a memory leak for the case
12 where setup_scsi_dh() returns failure. But setup_scsi_dh may return
13 success and not "use" attached_handler_name if the
14 retain_attached_hwhandler flag is not set on the map. As setup_scsi_sh
15 properly "steals" the pointer by nullifying it, freeing it
16 unconditionally in parse_path() is safe.
18 Fixes: b592211c33f7 ("dm mpath: fix attached_handler_name leak and dangling hw_handler_name pointer")
19 Cc: stable@vger.kernel.org
20 Reported-by: Yufen Yu <yuyufen@huawei.com>
21 Signed-off-by: Martin Wilck <mwilck@suse.com>
22 Signed-off-by: Mike Snitzer <snitzer@redhat.com>
23 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
26 drivers/md/dm-mpath.c | 2 +-
27 1 file changed, 1 insertion(+), 1 deletion(-)
29 --- a/drivers/md/dm-mpath.c
30 +++ b/drivers/md/dm-mpath.c
31 @@ -882,6 +882,7 @@ static struct pgpath *parse_path(struct
32 if (attached_handler_name || m->hw_handler_name) {
33 INIT_DELAYED_WORK(&p->activate_path, activate_path_work);
34 r = setup_scsi_dh(p->path.dev->bdev, m, &attached_handler_name, &ti->error);
35 + kfree(attached_handler_name);
37 dm_put_device(ti, p->path.dev);
39 @@ -896,7 +897,6 @@ static struct pgpath *parse_path(struct
43 - kfree(attached_handler_name);