Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp687784ybb; Wed, 25 Mar 2020 07:46:05 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuVZ4SZUr+f2hOecIuCHXb2r2WYcW2513GHg1L/ImYUUjnaeCIKjBPndlt98XAUj/lEy1fq X-Received: by 2002:aca:1e1a:: with SMTP id m26mr2730024oic.39.1585147565056; Wed, 25 Mar 2020 07:46:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585147565; cv=none; d=google.com; s=arc-20160816; b=ZlYUBiefrHOBpdBsbp47302er5Us8gefVvOWom2wP6tmAk2cVmjmsIjBkaAFqJotc6 7VQWLtXK85iB6wfoIaFbz1xLt2Rny99vMHo9hRXp4JRQ8qJ8FUydGjeglwEMvB9Wgoei r/Ye8goS6iXThemeQwbi2Hap+467d11S7dpaCYGB8j3l/Y1pEkRKyYlRlZsovUFZsUse 1ZtcZ90dC4OHPqOFNbenGNuzeRub5/4wdNVoc8wWzSvRaqtJEnvqnZOzfA7fnW7589lu 7Yb2EyC8afxM3q1wPIIaPYdoON5j/+5QM4CmNKJLRjVFZf7i9qQs5ldqIUuSUb9bgYh3 38Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=SfhyuSXT4SCQ4COQg/Q/ZZmgacUcKu21DcrYrYtj610=; b=VIYqFdSavobisvzHBFT4W/mYuiUAVcU066cHlv5U9qdfA/HEeU6FIMaZZcGTxK4/qc CQevhHqyU32Q30hxZLwYdz4EIJf32A/JXYldCoXY5z8V2jBoKVPmdE80jW+yFsn5t6cp MFeybY90W6iQKHKo8BDBgy/1wroM4fS6kiEhmL/WRK286H4UgC6iPEQB5p9gwhrtFlpq d6r1JYaSlpNz88ODewSordcaoBhRtuBPOLON00PY3dqp9wUsRQOpimo1Zyr+vr3w9lxD AeNC+kxbKo71VLGO/Atocicm3vlWbG3yi1Tp9xMBllx+1y9D6cL7b//7M4onpIVPpDfm CJAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dnJRgQfj; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h6si1513237oom.43.2020.03.25.07.45.52; Wed, 25 Mar 2020 07:46:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dnJRgQfj; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727722AbgCYOpp (ORCPT + 99 others); Wed, 25 Mar 2020 10:45:45 -0400 Received: from mail-ua1-f67.google.com ([209.85.222.67]:39956 "EHLO mail-ua1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727123AbgCYOpp (ORCPT ); Wed, 25 Mar 2020 10:45:45 -0400 Received: by mail-ua1-f67.google.com with SMTP id t20so813726uao.7 for ; Wed, 25 Mar 2020 07:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SfhyuSXT4SCQ4COQg/Q/ZZmgacUcKu21DcrYrYtj610=; b=dnJRgQfjpnz8EmTcFM9Iq0Po+j8+nN60b8kMNUH20Wq0RBImLQ9JI79SqFyq+zS7J/ mcu7YXriZ289Lx9ZuWgCHIUbVRRQJUTh0RCjQzLB4S8b359kJzDep9Ktf97CsuqZFDTt xgHd5lKCJI7QPIXuVrrX5s9yi1l/6lqz/hHG4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SfhyuSXT4SCQ4COQg/Q/ZZmgacUcKu21DcrYrYtj610=; b=kNZbvkjk9n2IqZwDF6eBqBymHRfednoq+jftjtN7UhY80gCoXee4dYoc6CHr9NS6X7 jBYt7a5e4c9+BYv3gYbYGYyRDM0Jgfw9AiWnG/855KihPY4xIFZjmOd6Hm27YuVZY5jL ZD+z15syROGO1dB9MbH/VwpLnVxNIwNXkCub8CwM3O0WxsrW4D1r1dsHSFNortagwRjx tXsS8GSNVoqeabsMFTVhN8j+RlhAWju7pwkynKPOmxFKn0Zog8XmSah2sseroPiTSHAK GgMY/6ez001uyNmwOM5p/0Wcg3cW6tCm+pL+3b0dQ+Ye7abuCBoDX89QYZiXpZqYgqqE hXfA== X-Gm-Message-State: ANhLgQ2leToojATxLmvForaCh0V1cMAn8zbQYUYCaAlbNc1nyVEK1gAV wjPSrPxUL1F6k6dd0xv0wWZt3Or6fFB7dA== X-Received: by 2002:ab0:604f:: with SMTP id o15mr2630375ual.120.1585147543488; Wed, 25 Mar 2020 07:45:43 -0700 (PDT) Received: from alain.c.googlers.com.com (57.152.190.35.bc.googleusercontent.com. [35.190.152.57]) by smtp.gmail.com with ESMTPSA id d20sm10629579vsc.6.2020.03.25.07.45.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2020 07:45:42 -0700 (PDT) From: Alain Michaud To: linux-bluetooth@vger.kernel.org Cc: Alain Michaud Subject: [PATCH v3] bluetooth: don't assume key size is 16 when the command fails. Date: Wed, 25 Mar 2020 14:45:40 +0000 Message-Id: <20200325144540.206658-1-alainm@chromium.org> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org With this change, the encryption key size is not assumed to be 16 if the read_encryption_key_size command fails for any reason. This ensures that if the controller fails the command for any reason that the encryption key size isn't implicitely set to 16 and instead take a more concervative posture to assume it is 0. Signed-off-by: Alain Michaud --- net/bluetooth/hci_event.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index cd3d7d90029b..baad7efdc508 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2963,14 +2963,14 @@ static void read_enc_key_size_complete(struct hci_dev *hdev, u8 status, if (!conn) goto unlock; - /* If we fail to read the encryption key size, assume maximum - * (which is the same we do also when this HCI command isn't - * supported. + /* While unexpected, the failure of the read_enc_key_size command may + * fail. The most secure approach is to then assume the key size is 0 to + * force a disconnection. */ if (rp->status) { bt_dev_err(hdev, "failed to read key size for handle %u", handle); - conn->enc_key_size = HCI_LINK_KEY_SIZE; + conn->enc_key_size = 0; } else { conn->enc_key_size = rp->key_size; } -- 2.25.1.696.g5e7596f4ac-goog