Merge: CVE-2024-49951: Bluetooth: MGMT: Fix possible crash on mgmt_index_removed
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/5621 JIRA: https://issues.redhat.com/browse/RHEL-64476 CVE: CVE-2024-49951 Depends: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/5549 ``` Bluetooth: MGMT: Fix possible crash on mgmt_index_removed If mgmt_index_removed is called while there are commands queued on cmd_sync it could lead to crashes like the bellow trace: 0x0000053D: __list_del_entry_valid_or_report+0x98/0xdc 0x0000053D: mgmt_pending_remove+0x18/0x58 [bluetooth] 0x0000053E: mgmt_remove_adv_monitor_complete+0x80/0x108 [bluetooth] 0x0000053E: hci_cmd_sync_work+0xbc/0x164 [bluetooth] So while handling mgmt_index_removed this attempts to dequeue commands passed as user_data to cmd_sync. Fixes: 7cf5c2978f23 ("Bluetooth: hci_sync: Refactor remove Adv Monitor") Reported-by: jiaymao <quic_jiaymao@quicinc.com> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> (cherry picked from commit f53e1c9c726d83092167f2226f32bd3b73f26c21) ``` Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com> Signed-off-by: Bastien Nocera <bnocera@redhat.com> --- <small>Created 2024-10-29 15:48 UTC by backporter - [KWF FAQ](https://red.ht/kernel_workflow_doc) - [Slack #team-kernel-workflow](https://redhat-internal.slack.com/archives/C04LRUPMJQ5) - [Source](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/webhook/utils/backporter.py) - [Documentation](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/docs/README.backporter.md) - [Report an issue](https://gitlab.com/cki-project/kernel-workflow/-/issues/new?issue%5Btitle%5D=backporter%20webhook%20issue)</small> Approved-by: Bastien Nocera <bnocera@redhat.com> Approved-by: Lenny Szubowicz <lszubowi@redhat.com> Approved-by: David Marlin <dmarlin@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Rado Vrbovsky <rvrbovsk@redhat.com>
This commit is contained in:
commit
b08efffa3f
|
@ -1446,10 +1446,15 @@ static void cmd_status_rsp(struct mgmt_pending_cmd *cmd, void *data)
|
|||
|
||||
static void cmd_complete_rsp(struct mgmt_pending_cmd *cmd, void *data)
|
||||
{
|
||||
if (cmd->cmd_complete) {
|
||||
u8 *status = data;
|
||||
struct cmd_lookup *match = data;
|
||||
|
||||
cmd->cmd_complete(cmd, *status);
|
||||
/* dequeue cmd_sync entries using cmd as data as that is about to be
|
||||
* removed/freed.
|
||||
*/
|
||||
hci_cmd_sync_dequeue(match->hdev, NULL, cmd, NULL);
|
||||
|
||||
if (cmd->cmd_complete) {
|
||||
cmd->cmd_complete(cmd, match->mgmt_status);
|
||||
mgmt_pending_remove(cmd);
|
||||
|
||||
return;
|
||||
|
@ -1498,7 +1503,8 @@ static void mgmt_set_discoverable_complete(struct hci_dev *hdev, void *data,
|
|||
bt_dev_dbg(hdev, "err %d", err);
|
||||
|
||||
/* Make sure cmd still outstanding. */
|
||||
if (cmd != pending_find(MGMT_OP_SET_DISCOVERABLE, hdev))
|
||||
if (err == -ECANCELED ||
|
||||
cmd != pending_find(MGMT_OP_SET_DISCOVERABLE, hdev))
|
||||
return;
|
||||
|
||||
hci_dev_lock(hdev);
|
||||
|
@ -1672,7 +1678,8 @@ static void mgmt_set_connectable_complete(struct hci_dev *hdev, void *data,
|
|||
bt_dev_dbg(hdev, "err %d", err);
|
||||
|
||||
/* Make sure cmd still outstanding. */
|
||||
if (cmd != pending_find(MGMT_OP_SET_CONNECTABLE, hdev))
|
||||
if (err == -ECANCELED ||
|
||||
cmd != pending_find(MGMT_OP_SET_CONNECTABLE, hdev))
|
||||
return;
|
||||
|
||||
hci_dev_lock(hdev);
|
||||
|
@ -1905,7 +1912,7 @@ static void set_ssp_complete(struct hci_dev *hdev, void *data, int err)
|
|||
bool changed;
|
||||
|
||||
/* Make sure cmd still outstanding. */
|
||||
if (cmd != pending_find(MGMT_OP_SET_SSP, hdev))
|
||||
if (err == -ECANCELED || cmd != pending_find(MGMT_OP_SET_SSP, hdev))
|
||||
return;
|
||||
|
||||
if (err) {
|
||||
|
@ -3751,7 +3758,8 @@ static void set_name_complete(struct hci_dev *hdev, void *data, int err)
|
|||
|
||||
bt_dev_dbg(hdev, "err %d", err);
|
||||
|
||||
if (cmd != pending_find(MGMT_OP_SET_LOCAL_NAME, hdev))
|
||||
if (err == -ECANCELED ||
|
||||
cmd != pending_find(MGMT_OP_SET_LOCAL_NAME, hdev))
|
||||
return;
|
||||
|
||||
if (status) {
|
||||
|
@ -3926,7 +3934,8 @@ static void set_default_phy_complete(struct hci_dev *hdev, void *data, int err)
|
|||
struct sk_buff *skb = cmd->skb;
|
||||
u8 status = mgmt_status(err);
|
||||
|
||||
if (cmd != pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev))
|
||||
if (err == -ECANCELED ||
|
||||
cmd != pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev))
|
||||
return;
|
||||
|
||||
if (!status) {
|
||||
|
@ -5817,13 +5826,16 @@ static void start_discovery_complete(struct hci_dev *hdev, void *data, int err)
|
|||
{
|
||||
struct mgmt_pending_cmd *cmd = data;
|
||||
|
||||
bt_dev_dbg(hdev, "err %d", err);
|
||||
|
||||
if (err == -ECANCELED)
|
||||
return;
|
||||
|
||||
if (cmd != pending_find(MGMT_OP_START_DISCOVERY, hdev) &&
|
||||
cmd != pending_find(MGMT_OP_START_LIMITED_DISCOVERY, hdev) &&
|
||||
cmd != pending_find(MGMT_OP_START_SERVICE_DISCOVERY, hdev))
|
||||
return;
|
||||
|
||||
bt_dev_dbg(hdev, "err %d", err);
|
||||
|
||||
mgmt_cmd_complete(cmd->sk, cmd->index, cmd->opcode, mgmt_status(err),
|
||||
cmd->param, 1);
|
||||
mgmt_pending_remove(cmd);
|
||||
|
@ -6056,7 +6068,8 @@ static void stop_discovery_complete(struct hci_dev *hdev, void *data, int err)
|
|||
{
|
||||
struct mgmt_pending_cmd *cmd = data;
|
||||
|
||||
if (cmd != pending_find(MGMT_OP_STOP_DISCOVERY, hdev))
|
||||
if (err == -ECANCELED ||
|
||||
cmd != pending_find(MGMT_OP_STOP_DISCOVERY, hdev))
|
||||
return;
|
||||
|
||||
bt_dev_dbg(hdev, "err %d", err);
|
||||
|
@ -8015,7 +8028,8 @@ static void read_local_oob_ext_data_complete(struct hci_dev *hdev, void *data,
|
|||
u8 status = mgmt_status(err);
|
||||
u16 eir_len;
|
||||
|
||||
if (cmd != pending_find(MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev))
|
||||
if (err == -ECANCELED ||
|
||||
cmd != pending_find(MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev))
|
||||
return;
|
||||
|
||||
if (!status) {
|
||||
|
@ -9337,12 +9351,12 @@ void mgmt_index_added(struct hci_dev *hdev)
|
|||
void mgmt_index_removed(struct hci_dev *hdev)
|
||||
{
|
||||
struct mgmt_ev_ext_index ev;
|
||||
u8 status = MGMT_STATUS_INVALID_INDEX;
|
||||
struct cmd_lookup match = { NULL, hdev, MGMT_STATUS_INVALID_INDEX };
|
||||
|
||||
if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks))
|
||||
return;
|
||||
|
||||
mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &status);
|
||||
mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &match);
|
||||
|
||||
if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) {
|
||||
mgmt_index_event(MGMT_EV_UNCONF_INDEX_REMOVED, hdev, NULL, 0,
|
||||
|
@ -9393,7 +9407,7 @@ void mgmt_power_on(struct hci_dev *hdev, int err)
|
|||
void __mgmt_power_off(struct hci_dev *hdev)
|
||||
{
|
||||
struct cmd_lookup match = { NULL, hdev };
|
||||
u8 status, zero_cod[] = { 0, 0, 0 };
|
||||
u8 zero_cod[] = { 0, 0, 0 };
|
||||
|
||||
mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match);
|
||||
|
||||
|
@ -9405,11 +9419,11 @@ void __mgmt_power_off(struct hci_dev *hdev)
|
|||
* status responses.
|
||||
*/
|
||||
if (hci_dev_test_flag(hdev, HCI_UNREGISTER))
|
||||
status = MGMT_STATUS_INVALID_INDEX;
|
||||
match.mgmt_status = MGMT_STATUS_INVALID_INDEX;
|
||||
else
|
||||
status = MGMT_STATUS_NOT_POWERED;
|
||||
match.mgmt_status = MGMT_STATUS_NOT_POWERED;
|
||||
|
||||
mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &status);
|
||||
mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &match);
|
||||
|
||||
if (memcmp(hdev->dev_class, zero_cod, sizeof(zero_cod)) != 0) {
|
||||
mgmt_limited_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev,
|
||||
|
|
Loading…
Reference in New Issue