Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751638AbdGYTRN (ORCPT ); Tue, 25 Jul 2017 15:17:13 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60600 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751612AbdGYTRL (ORCPT ); Tue, 25 Jul 2017 15:17:11 -0400 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Jason A. Donenfeld" , Marcel Holtmann Subject: [PATCH 3.18 14/60] Bluetooth: use constant time memory comparison for secret values Date: Tue, 25 Jul 2017 12:16:05 -0700 Message-Id: <20170725191616.141466569@linuxfoundation.org> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170725191614.043749784@linuxfoundation.org> References: <20170725191614.043749784@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1509 Lines: 50 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jason A. Donenfeld commit 329d82309824ff1082dc4a91a5bbed8c3bec1580 upstream. This file is filled with complex cryptography. Thus, the comparisons of MACs and secret keys and curve points and so forth should not add timing attacks, which could either result in a direct forgery, or, given the complexity, some other type of attack. Signed-off-by: Jason A. Donenfeld Signed-off-by: Marcel Holtmann Signed-off-by: Greg Kroah-Hartman --- net/bluetooth/smp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/net/bluetooth/smp.c +++ b/net/bluetooth/smp.c @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -163,7 +164,7 @@ bool smp_irk_matches(struct hci_dev *hde if (err) return false; - return !memcmp(bdaddr->b, hash, 3); + return !crypto_memneq(bdaddr->b, hash, 3); } int smp_generate_rpa(struct hci_dev *hdev, u8 irk[16], bdaddr_t *rpa) @@ -584,7 +585,7 @@ static u8 smp_random(struct smp_chan *sm if (ret) return SMP_UNSPECIFIED; - if (memcmp(smp->pcnf, confirm, sizeof(smp->pcnf)) != 0) { + if (crypto_memneq(smp->pcnf, confirm, sizeof(smp->pcnf))) { BT_ERR("Pairing failed (confirmation values mismatch)"); return SMP_CONFIRM_FAILED; }