Skip to contentSkip to conversation

block: sed-opal: reject invalid method status tokens

PATCH New Avi Weiss 1 participant 1 message Oct 27

Subsystems (2)
lore
Share & tools
lore

Avi Weiss

author
#0 lore raw

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")
---
 block/sed-opal.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
block/sed-opal.c +8 -1
index 79b290d9458a9..1eb68ce33647b 100644
@@ -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