Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp384640ybb; Wed, 25 Mar 2020 01:32:13 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtiK81Py4xL0lufYzYv3rU1ZNuHg1IORQZWeimOHyVO+ZqeBjf4YgqVP6GZa+MaHxugg3hx X-Received: by 2002:a9d:ed5:: with SMTP id 79mr1498284otj.249.1585125133807; Wed, 25 Mar 2020 01:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585125133; cv=none; d=google.com; s=arc-20160816; b=Vc37SC5Q90e4RTBmIEdKDGspZcRiTsBPyhpyV30sBMoJGA5VcTWiVzsiiYGt5fqD8I 0sPfzYTawhUV0GV/CzyagW3ArOCn80F5zsWKTg2D+BIOq0APDs/+oelfm/PW+clIeCZB Ocm+3a4zq7kWFjiIpe3abLx2mRfKX5hkeQpFoqXCU6xQ+nq+wiII5H2luIlkTPbNzSMj TzXqkKRPf6i0r+KlcXmEQjAXHHhQKD217B2k0Fm381s21uXpE95TUMUCGxzvYG38ClBK 1B3OLJZP0VEgfmUzjP+AxXp7AYSD3LyXZwn/QMsoIRhuNyJX2QRSjXUHqj2z4Ng9oiGs I8Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=HAjilORSWp8vF+pmTDWBL8PhrutpXJ26tFF1cf2faAk=; b=EvLRD6m5r4g5a5sdl6hKKDydpvGg4nD1kSjLcXFY8cWLIi0XBybjUL1DgNyzFJq1i0 JbU6hbWSMVqjtwhW+kYD16peQiEF4CesnuVC7oskOC6HWM9soNiGW+qZEv03DxnHrWp/ p/XKjQwsxY4pKJvhOY6L3gHb78OTt1JvpU25iKJf6dqOHvu2/FbkEPwXoqNAi2mJHpR6 k8vYppmkGlEx/TUCsABhk8yhwREferzh3ZbEY0ye1SrWZrndRasCb8eVhNR/p186FTKd v2Ra3PB35buI17aMXhTjTW1yUzJGnFmPhCyX1CpBPyKRdNCQjFxErsDvsS00iXQMC6vG TUyA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 96si10428135oty.198.2020.03.25.01.32.01; Wed, 25 Mar 2020 01:32:13 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726906AbgCYIaq convert rfc822-to-8bit (ORCPT + 99 others); Wed, 25 Mar 2020 04:30:46 -0400 Received: from coyote.holtmann.net ([212.227.132.17]:48110 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726116AbgCYIaq (ORCPT ); Wed, 25 Mar 2020 04:30:46 -0400 Received: from marcel-macbook.fritz.box (p4FEFC5A7.dip0.t-ipconnect.de [79.239.197.167]) by mail.holtmann.org (Postfix) with ESMTPSA id E925CCECCA; Wed, 25 Mar 2020 09:40:16 +0100 (CET) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) Subject: Re: [PATCH v2] bluetooth: don't assume key size is 16 when the command fails. From: Marcel Holtmann In-Reply-To: <20200324195008.10822-1-alainm@chromium.org> Date: Wed, 25 Mar 2020 09:30:44 +0100 Cc: linux-bluetooth@vger.kernel.org Content-Transfer-Encoding: 8BIT Message-Id: References: <20200324195008.10822-1-alainm@chromium.org> To: Alain Michaud X-Mailer: Apple Mail (2.3608.60.0.2.5) Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Alain, can please prefix the subject with “Bluetooth: “ then I have to stop fixing it up after applying ;) > 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 | 6 +----- > 1 file changed, 1 insertion(+), 5 deletions(-) > > diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c > index cd3d7d90029b..8a7a94e6f956 100644 > --- a/net/bluetooth/hci_event.c > +++ b/net/bluetooth/hci_event.c > @@ -2963,14 +2963,10 @@ 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. > - */ /* When the command to read the encryption key size fails, then this * normally indicates a bad handle or an invalid handle. However in * this case we are pretty certain that the parameters provided have * been correct. This means that if the command fails, something * serious went wrong between the controller and the host. The best * approach is to fail the connection now and for that the key size * is set to 0 to force a disconnect. */ > 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; > } So I wouldn’t scrap the comment. I would extend it to something like above. Feel free to copy it or reword or use your own words. I just want a comment there that when I read the code in 6 month from now, I remember why this is done. Regards Marcel