@@ -283,6 +283,7 @@ enum {
HCI_FORCE_STATIC_ADDR,
HCI_LL_RPA_RESOLUTION,
HCI_CMD_PENDING,
+ HCI_PERMIT_JUST_WORK_REPAIR,
__HCI_NUM_FLAGS,
};
@@ -172,10 +172,57 @@ static const struct file_operations vendor_diag_fops = {
.llseek = default_llseek,
};
+static ssize_t permit_just_work_repair_read(struct file *file,
+ char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ struct hci_dev *hdev = file->private_data;
+ char buf[3];
+
+ buf[0] = hci_dev_test_flag(hdev, HCI_PERMIT_JUST_WORK_REPAIR) ? 'Y'
+ : 'N';
+ buf[1] = '\n';
+ buf[2] = '\0';
+ return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+}
+
+static ssize_t permit_just_work_repair_write(struct file *file,
+ const char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ struct hci_dev *hdev = file->private_data;
+ char buf[32];
+ size_t buf_size = min(count, (sizeof(buf) - 1));
+ bool enable;
+
+ if (copy_from_user(buf, user_buf, buf_size))
+ return -EFAULT;
+
+ buf[buf_size] = '\0';
+ if (strtobool(buf, &enable))
+ return -EINVAL;
+
+ if (enable)
+ hci_dev_set_flag(hdev, HCI_PERMIT_JUST_WORK_REPAIR);
+ else
+ hci_dev_clear_flag(hdev, HCI_PERMIT_JUST_WORK_REPAIR);
+
+ return count;
+}
+
+static const struct file_operations permit_just_work_repair_fops = {
+ .open = simple_open,
+ .read = permit_just_work_repair_read,
+ .write = permit_just_work_repair_write,
+ .llseek = default_llseek,
+};
+
static void hci_debugfs_create_basic(struct hci_dev *hdev)
{
debugfs_create_file("dut_mode", 0644, hdev->debugfs, hdev,
&dut_mode_fops);
+ debugfs_create_file("permit_just_work_repair", 0644, hdev->debugfs,
+ hdev, &permit_just_work_repair_fops);
if (hdev->set_diag)
debugfs_create_file("vendor_diag", 0644, hdev->debugfs, hdev,
@@ -4539,6 +4539,18 @@ static void hci_user_confirm_request_evt(struct hci_dev *hdev,
goto unlock;
}
+ /* If there already exists link key in local host, terminate the
+ * connection by default since the remote device could be malicious.
+ * Permit the connection if permit_just_work_repair is enabled.
+ */
+ if (!hci_dev_test_flag(hdev, HCI_PERMIT_JUST_WORK_REPAIR) &&
+ hci_find_link_key(hdev, &ev->bdaddr)) {
+ BT_DBG("Rejecting request: local host already have link key");
+ hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_NEG_REPLY,
+ sizeof(ev->bdaddr), &ev->bdaddr);
+ goto unlock;
+ }
+
/* If no side requires MITM protection; auto-accept */
if ((!loc_mitm || conn->remote_cap == HCI_IO_NO_INPUT_OUTPUT) &&
(!rem_mitm || conn->io_capability == HCI_IO_NO_INPUT_OUTPUT)) {