Pull IPMI fixes from Corey Minyard: "Some changes that went in 5.16 had issues. When working on the design a piece was redesigned and things got missed. And the message type was not being initialized when it was allocated, resulting in crashes. In addition, the IPMI driver has had a shutdown issue where it could still have an item in a system workqueue after it had been shutdown. Move to a private workqueue to avoid that problem" * tag 'for-linus-5.16-2' of git://github.com/cminyard/linux-ipmi: ipmi:ipmb: Fix unknown command response ipmi: fix IPMI_SMI_MSG_TYPE_IPMB_DIRECT response length checking ipmi: fix oob access due to uninit smi_msg type ipmi: msghandler: Make symbol 'remove_work_wq' static ipmi: Move remove_work to dedicated workqueue
Unified · Split
| @@ -191,6 +191,8 @@ struct ipmi_user { · 190 unmodified lines | ||
| 191 | 191 | struct work_struct remove_work; |
| 192 | 192 | }; |
| 193 | 193 | |
| 194 | +static struct workqueue_struct *remove_work_wq; | |
| 195 | + | |
| 194 | 196 | static struct ipmi_user *acquire_ipmi_user(struct ipmi_user *user, int *index) |
| 195 | 197 | __acquires(user->release_barrier) |
| 196 | 198 | { |
| @@ -1297,7 +1299,7 @@ static void free_user(struct kref *ref) · 1100 unmodified lines | ||
| 1297 | 1299 | struct ipmi_user *user = container_of(ref, struct ipmi_user, refcount); |
| 1298 | 1300 | |
| 1299 | 1301 | /* SRCU cleanup must happen in task context. */ |
| 1300 | − schedule_work(&user->remove_work); | |
| 1302 | + queue_work(remove_work_wq, &user->remove_work); | |
| 1301 | 1303 | } |
| 1302 | 1304 | |
| 1303 | 1305 | static void _ipmi_destroy_user(struct ipmi_user *user) |
| @@ -3918,9 +3920,11 @@ static int handle_ipmb_direct_rcv_cmd(struct ipmi_smi *intf, · 2614 unmodified lines | ||
| 3918 | 3920 | /* We didn't find a user, deliver an error response. */ |
| 3919 | 3921 | ipmi_inc_stat(intf, unhandled_commands); |
| 3920 | 3922 | |
| 3921 | − msg->data[0] = ((netfn + 1) << 2) | (msg->rsp[4] & 0x3); | |
| 3922 | − msg->data[1] = msg->rsp[2]; | |
| 3923 | − msg->data[2] = msg->rsp[4] & ~0x3; | |
| 3923 | + msg->data[0] = (netfn + 1) << 2; | |
| 3924 | + msg->data[0] |= msg->rsp[2] & 0x3; /* rqLUN */ | |
| 3925 | + msg->data[1] = msg->rsp[1]; /* Addr */ | |
| 3926 | + msg->data[2] = msg->rsp[2] & ~0x3; /* rqSeq */ | |
| 3927 | + msg->data[2] |= msg->rsp[0] & 0x3; /* rsLUN */ | |
| 3924 | 3928 | msg->data[3] = cmd; |
| 3925 | 3929 | msg->data[4] = IPMI_INVALID_CMD_COMPLETION_CODE; |
| 3926 | 3930 | msg->data_size = 5; |
| @@ -4455,13 +4459,24 @@ return_unspecified: · 528 unmodified lines | ||
| 4455 | 4459 | msg->rsp[2] = IPMI_ERR_UNSPECIFIED; |
| 4456 | 4460 | msg->rsp_size = 3; |
| 4457 | 4461 | } else if (msg->type == IPMI_SMI_MSG_TYPE_IPMB_DIRECT) { |
| 4458 | − /* commands must have at least 3 bytes, responses 4. */ | |
| 4459 | − if (is_cmd && (msg->rsp_size < 3)) { | |
| 4462 | + /* commands must have at least 4 bytes, responses 5. */ | |
| 4463 | + if (is_cmd && (msg->rsp_size < 4)) { | |
| 4460 | 4464 | ipmi_inc_stat(intf, invalid_commands); |
| 4461 | 4465 | goto out; |
| 4462 | 4466 | } |
| 4463 | − if (!is_cmd && (msg->rsp_size < 4)) | |
| 4464 | − goto return_unspecified; | |
| 4467 | + if (!is_cmd && (msg->rsp_size < 5)) { | |
| 4468 | + ipmi_inc_stat(intf, invalid_ipmb_responses); | |
| 4469 | + /* Construct a valid error response. */ | |
| 4470 | + msg->rsp[0] = msg->data[0] & 0xfc; /* NetFN */ | |
| 4471 | + msg->rsp[0] |= (1 << 2); /* Make it a response */ | |
| 4472 | + msg->rsp[0] |= msg->data[2] & 3; /* rqLUN */ | |
| 4473 | + msg->rsp[1] = msg->data[1]; /* Addr */ | |
| 4474 | + msg->rsp[2] = msg->data[2] & 0xfc; /* rqSeq */ | |
| 4475 | + msg->rsp[2] |= msg->data[0] & 0x3; /* rsLUN */ | |
| 4476 | + msg->rsp[3] = msg->data[3]; /* Cmd */ | |
| 4477 | + msg->rsp[4] = IPMI_ERR_UNSPECIFIED; | |
| 4478 | + msg->rsp_size = 5; | |
| 4479 | + } | |
| 4465 | 4480 | } else if ((msg->data_size >= 2) |
| 4466 | 4481 | && (msg->data[0] == (IPMI_NETFN_APP_REQUEST << 2)) |
| 4467 | 4482 | && (msg->data[1] == IPMI_SEND_MSG_CMD) |
| @@ -5031,6 +5046,7 @@ struct ipmi_smi_msg *ipmi_alloc_smi_msg(void) · 563 unmodified lines | ||
| 5031 | 5046 | if (rv) { |
| 5032 | 5047 | rv->done = free_smi_msg; |
| 5033 | 5048 | rv->user_data = NULL; |
| 5049 | + rv->type = IPMI_SMI_MSG_TYPE_NORMAL; | |
| 5034 | 5050 | atomic_inc(&smi_msg_inuse_count); |
| 5035 | 5051 | } |
| 5036 | 5052 | return rv; |
| @@ -5383,6 +5399,13 @@ static int ipmi_init_msghandler(void) · 346 unmodified lines | ||
| 5383 | 5399 | |
| 5384 | 5400 | atomic_notifier_chain_register(&panic_notifier_list, &panic_block); |
| 5385 | 5401 | |
| 5402 | + remove_work_wq = create_singlethread_workqueue("ipmi-msghandler-remove-wq"); | |
| 5403 | + if (!remove_work_wq) { | |
| 5404 | + pr_err("unable to create ipmi-msghandler-remove-wq workqueue"); | |
| 5405 | + rv = -ENOMEM; | |
| 5406 | + goto out; | |
| 5407 | + } | |
| 5408 | + | |
| 5386 | 5409 | initialized = true; |
| 5387 | 5410 | |
| 5388 | 5411 | out: |
| @@ -5408,6 +5431,8 @@ static void __exit cleanup_ipmi(void) · 19 unmodified lines | ||
| 5408 | 5431 | int count; |
| 5409 | 5432 | |
| 5410 | 5433 | if (initialized) { |
| 5434 | + destroy_workqueue(remove_work_wq); | |
| 5435 | + | |
| 5411 | 5436 | atomic_notifier_chain_unregister(&panic_notifier_list, |
| 5412 | 5437 | &panic_block); |
| 5413 | 5438 | |