Skip to content

Commit a13faca

Browse files
YuKuai-huaweimartinkpetersen
authored andcommitted
scsi: scsi_dh_alua: Fix memleak for 'qdata' in alua_activate()
If alua_rtpg_queue() failed from alua_activate(), then 'qdata' is not freed, which will cause following memleak: unreferenced object 0xffff88810b2c6980 (size 32): comm "kworker/u16:2", pid 635322, jiffies 4355801099 (age 1216426.076s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 40 39 24 c1 ff ff ff ff 00 f8 ea 0a 81 88 ff ff @9$............. backtrace: [<0000000098f3a26d>] alua_activate+0xb0/0x320 [<000000003b529641>] scsi_dh_activate+0xb2/0x140 [<000000007b296db3>] activate_path_work+0xc6/0xe0 [dm_multipath] [<000000007adc9ace>] process_one_work+0x3c5/0x730 [<00000000c457a985>] worker_thread+0x93/0x650 [<00000000cb80e628>] kthread+0x1ba/0x210 [<00000000a1e61077>] ret_from_fork+0x22/0x30 Fix the problem by freeing 'qdata' in error path. Fixes: 625fe85 ("scsi: scsi_dh_alua: Check scsi_device_get() return value") Signed-off-by: Yu Kuai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Benjamin Block <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent d3affde commit a13faca

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/scsi/device_handler/scsi_dh_alua.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,10 +1145,12 @@ static int alua_activate(struct scsi_device *sdev,
11451145
rcu_read_unlock();
11461146
mutex_unlock(&h->init_mutex);
11471147

1148-
if (alua_rtpg_queue(pg, sdev, qdata, true))
1148+
if (alua_rtpg_queue(pg, sdev, qdata, true)) {
11491149
fn = NULL;
1150-
else
1150+
} else {
1151+
kfree(qdata);
11511152
err = SCSI_DH_DEV_OFFLINED;
1153+
}
11521154
kref_put(&pg->kref, release_port_group);
11531155
out:
11541156
if (fn)

0 commit comments

Comments
 (0)