From 70e0d81436b47a1a23e527252296a1aabe83cd86 Mon Sep 17 00:00:00 2001 From: Tony Battersby Date: Mon, 8 Sep 2025 16:09:52 +0300 Subject: [PATCH] scst_user: Fix oops in SCST_USER_PARSE_EXCEPTION If dev->generic_parse() detects a math overflow and calls scst_set_cmd_error(), and scst_user is using SCST_USER_PARSE_EXCEPTION, then it will trigger a sBUG() in scst_targ.c::scst_parse_cmd() where it checks for a valid cmd->state: scst: scst_parse_cmd:1385:***CRITICAL ERROR***: Bad state for completed cmd (cmd 000000005abc21e1, state 1) BUG at /usr/src/debug/scst/3.10+git/scst/src/scst_targ.c:1387 Fix by treating negative generic_parse() errors as final. Signed-off-by: Tony Battersby --- scst/src/dev_handlers/scst_user.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scst/src/dev_handlers/scst_user.c b/scst/src/dev_handlers/scst_user.c index cfd9ce21d..88b37eb3d 100644 --- a/scst/src/dev_handlers/scst_user.c +++ b/scst/src/dev_handlers/scst_user.c @@ -757,6 +757,15 @@ static int dev_user_parse(struct scst_cmd *cmd) res = SCST_CMD_STATE_NEED_THREAD_CTX; goto out; } + if (rc < 0) { + /* + * May have already called e.g. scst_set_cmd_error(); + * too late to try user parse without cleaning up + * first. + */ + PRINT_ERROR("PARSE failed (ucmd %p, rc %d)", ucmd, rc); + goto out_error; + } fallthrough; case SCST_USER_PARSE_CALL: