From 6a638313fec6f9a4a2a0a78139b7012185d84736 Mon Sep 17 00:00:00 2001 From: Andy Grover Date: Mon, 21 Nov 2016 16:35:30 -0800 Subject: [PATCH] target/user: Fix use-after-free of tcmu_cmds if they are expired 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 Orabug: 25395066 (cherry picked from commit d0905ca757bc40bd1ebc261a448a521b064777d7) Signed-off-by: Kyle Fortin Reviewed-by: Shan Hai --- drivers/target/target_core_user.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index e584dc419921..099f82ffe5bd 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -684,8 +684,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; } -- 2.50.1