From: Andy Grover Date: Tue, 22 Nov 2016 00:35:30 +0000 (-0800) Subject: target/user: Fix use-after-free of tcmu_cmds if they are expired X-Git-Tag: v4.1.38~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d1b9fb84c423d6a6777da3238abf7e08c13bd7f5;p=platform%2Fkernel%2Flinux-exynos.git target/user: Fix use-after-free of tcmu_cmds if they are expired [ Upstream commit d0905ca757bc40bd1ebc261a448a521b064777d7 ] Don't free the cmd in tcmu_check_expired_cmd, it's still referenced by an entry in our cmd_id->cmd idr. If userspace ever resumes processing, tcmu_handle_completions() will use the now-invalid cmd pointer. Instead, don't free cmd. It will be freed by tcmu_handle_completion() if userspace ever recovers, or tcmu_free_device if not. Cc: stable@vger.kernel.org Reported-by: Bryant G Ly Tested-by: Bryant G Ly Signed-off-by: Andy Grover Signed-off-by: Bart Van Assche Signed-off-by: Sasha Levin --- diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index 07d2996d8c1f..39e8f22be68b 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -605,8 +605,6 @@ static int tcmu_check_expired_cmd(int id, void *p, void *data) target_complete_cmd(cmd->se_cmd, SAM_STAT_CHECK_CONDITION); cmd->se_cmd = NULL; - kmem_cache_free(tcmu_cmd_cache, cmd); - return 0; }