Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dm mpath: always free attached_handler_name in parse_path()

Commit b592211c33f7 ("dm mpath: fix attached_handler_name leak and
dangling hw_handler_name pointer") fixed a memory leak for the case
where setup_scsi_dh() returns failure. But setup_scsi_dh may return
success and not "use" attached_handler_name if the
retain_attached_hwhandler flag is not set on the map. As setup_scsi_sh
properly "steals" the pointer by nullifying it, freeing it
unconditionally in parse_path() is safe.

Fixes: b592211c33f7 ("dm mpath: fix attached_handler_name leak and dangling hw_handler_name pointer")
Cc: stable@vger.kernel.org
Reported-by: Yufen Yu <yuyufen@huawei.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>

authored by

Martin Wilck and committed by
Mike Snitzer
940bc471 8e890c1a

+1 -1
+1 -1
drivers/md/dm-mpath.c
··· 897 897 if (attached_handler_name || m->hw_handler_name) { 898 898 INIT_DELAYED_WORK(&p->activate_path, activate_path_work); 899 899 r = setup_scsi_dh(p->path.dev->bdev, m, &attached_handler_name, &ti->error); 900 + kfree(attached_handler_name); 900 901 if (r) { 901 902 dm_put_device(ti, p->path.dev); 902 903 goto bad; ··· 912 911 913 912 return p; 914 913 bad: 915 - kfree(attached_handler_name); 916 914 free_pgpath(p); 917 915 return ERR_PTR(r); 918 916 }