summaryrefslogtreecommitdiff
path: root/drivers/target/target_core_ua.c
diff options
context:
space:
mode:
authorCalvin Owens <calvinowens@fb.com>2015-10-30 16:57:00 -0700
committerTasayco Loarte, VictorX <victorx.tasayco.loarte@intel.com>2016-11-30 08:36:04 -0800
commit8ecedf4cce6dba914c946d9cde0c9917ecc0c316 (patch)
tree56b244a9af125ebe240da47e6ff06d7a8f4cd0b5 /drivers/target/target_core_ua.c
parentd483a10374009eb3f1098362621137a4985f25af (diff)
downloadx86-8ecedf4cce6dba914c946d9cde0c9917ecc0c316.tar.gz
sg: Fix double-free when drives detach during SG_IO
In sg_common_write(), we free the block request and return -ENODEV if the device is detached in the middle of the SG_IO ioctl(). Unfortunately, sg_finish_rem_req() also tries to free srp->rq, so we end up freeing rq->cmd in the already free rq object, and then free the object itself out from under the current user. This ends up corrupting random memory via the list_head on the rq object. The most common crash trace I saw is this: ------------[ cut here ]------------ kernel BUG at block/blk-core.c:1420! Call Trace: [<ffffffff81281eab>] blk_put_request+0x5b/0x80 [<ffffffffa0069e5b>] sg_finish_rem_req+0x6b/0x120 [sg] [<ffffffffa006bcb9>] sg_common_write.isra.14+0x459/0x5a0 [sg] [<ffffffff8125b328>] ? selinux_file_alloc_security+0x48/0x70 [<ffffffffa006bf95>] sg_new_write.isra.17+0x195/0x2d0 [sg] [<ffffffffa006cef4>] sg_ioctl+0x644/0xdb0 [sg] [<ffffffff81170f80>] do_vfs_ioctl+0x90/0x520 [<ffffffff81258967>] ? file_has_perm+0x97/0xb0 [<ffffffff811714a1>] SyS_ioctl+0x91/0xb0 [<ffffffff81602afb>] tracesys+0xdd/0xe2 RIP [<ffffffff81281e04>] __blk_put_request+0x154/0x1a0 The solution is straightforward: just set srp->rq to NULL in the failure branch so that sg_finish_rem_req() doesn't attempt to re-free it. Additionally, since sg_rq_end_io() will never be called on the object when this happens, we need to free memory backing ->cmd if it isn't embedded in the object itself. KASAN was extremely helpful in finding the root cause of this bug. Change-Id: I53ebaf6b9bfece0a5125f168bce21a8dad008247 Tracked-On: https://jira01.devtools.intel.com/browse/AW-2637 Signed-off-by: Calvin Owens <calvinowens@fb.com> Acked-by: Douglas Gilbert <dgilbert@interlog.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Reviewed-on: https://android.intel.com/546401 Reviewed-by: Mahe, Erwan <erwan.mahe@intel.com> Tested-by: Maalem, Saadi <saadi.maalem@intel.com> Reviewed-by: Tasayco Loarte, VictorX <victorx.tasayco.loarte@intel.com> Tested-by: Tasayco Loarte, VictorX <victorx.tasayco.loarte@intel.com> Reviewed-by: Maalem, Saadi <saadi.maalem@intel.com>
Diffstat (limited to 'drivers/target/target_core_ua.c')
0 files changed, 0 insertions, 0 deletions