block: sed-opal: reject invalid method status tokens
Subsystems (2)
PATCH 1/1 block: sed-opal: reject invalid method status tokens
response_status() uses response_get_u64() to read the method status. The helper returns zero for an invalid type or unsupported atom width, so malformed responses can be reported as successful. Values such as 256 also become zero when truncated to u8.
Validate the status token before returning its value. Report DTAERROR_NO_METHOD_STATUS for invalid tokens while preserving valid status values and the end-session special case.
Fixes 455a7b238cd6 ("block: Add Sed-opal library")
Signed-off-by Avi Weiss <[email protected]>
--- block/sed-opal.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
block/sed-opal.c +8 -1
@@ -1167,7 +1167,14 @@ static u8 response_status(const struct parsed_resp *resp)if (!response_token_matches (tok,OPAL_ENDLIST ))return DTAERROR_NO_METHOD_STATUS ; -return response_get_u64 (resp, resp->num -4 ); + tok =response_get_token (resp, resp->num -4 ); +if (IS_ERR (tok) || tok->type !=OPAL_DTA_TOKENID_UINT || + (tok->width !=OPAL_WIDTH_TINY && + tok->width !=OPAL_WIDTH_SHORT ) || + tok->stored.u >U8_MAX ) +return DTAERROR_NO_METHOD_STATUS ; + +return tok->stored.u; }/* Parses and checks for errors */
base-commit: d135ab453a7400a34930bdda1ef4bdc8acfac80e
Signature · 1 line
2.43.0