Skip to content

Commit d2c12f5

Browse files
committed
ipmi: fix IPMI_SMI_MSG_TYPE_IPMB_DIRECT response length checking
A couple of issues: The tested data sizes are wrong; during the design that changed and this got missed. The formatting of the reponse couldn't use the normal one, it has to be an IPMB formatted response. Reported-by: Jakub Kicinski <[email protected]> Fixes: 059747c ("ipmi: Add support for IPMB direct messages") Signed-off-by: Corey Minyard <[email protected]>
1 parent c33fdfb commit d2c12f5

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

drivers/char/ipmi/ipmi_msghandler.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4457,13 +4457,24 @@ static int handle_one_recv_msg(struct ipmi_smi *intf,
44574457
msg->rsp[2] = IPMI_ERR_UNSPECIFIED;
44584458
msg->rsp_size = 3;
44594459
} else if (msg->type == IPMI_SMI_MSG_TYPE_IPMB_DIRECT) {
4460-
/* commands must have at least 3 bytes, responses 4. */
4461-
if (is_cmd && (msg->rsp_size < 3)) {
4460+
/* commands must have at least 4 bytes, responses 5. */
4461+
if (is_cmd && (msg->rsp_size < 4)) {
44624462
ipmi_inc_stat(intf, invalid_commands);
44634463
goto out;
44644464
}
4465-
if (!is_cmd && (msg->rsp_size < 4))
4466-
goto return_unspecified;
4465+
if (!is_cmd && (msg->rsp_size < 5)) {
4466+
ipmi_inc_stat(intf, invalid_ipmb_responses);
4467+
/* Construct a valid error response. */
4468+
msg->rsp[0] = msg->data[0] & 0xfc; /* NetFN */
4469+
msg->rsp[0] |= (1 << 2); /* Make it a response */
4470+
msg->rsp[0] |= msg->data[2] & 3; /* rqLUN */
4471+
msg->rsp[1] = msg->data[1]; /* Addr */
4472+
msg->rsp[2] = msg->data[2] & 0xfc; /* rqSeq */
4473+
msg->rsp[2] |= msg->data[0] & 0x3; /* rsLUN */
4474+
msg->rsp[3] = msg->data[3]; /* Cmd */
4475+
msg->rsp[4] = IPMI_ERR_UNSPECIFIED;
4476+
msg->rsp_size = 5;
4477+
}
44674478
} else if ((msg->data_size >= 2)
44684479
&& (msg->data[0] == (IPMI_NETFN_APP_REQUEST << 2))
44694480
&& (msg->data[1] == IPMI_SEND_MSG_CMD)

0 commit comments

Comments
 (0)