Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4102016ybb; Tue, 7 Apr 2020 00:23:52 -0700 (PDT) X-Google-Smtp-Source: APiQypI3bspLcXyGKeNCQjGp6LSK8XPYWsz59fVVDw40IJksh/n5qSpJLaaaM4PT35/dmDDKODe2 X-Received: by 2002:a9d:6a05:: with SMTP id g5mr501606otn.116.1586244231910; Tue, 07 Apr 2020 00:23:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586244231; cv=none; d=google.com; s=arc-20160816; b=HxOliQIJFs9EHGPCbqcpUMinhHfIwEaxMLDexp2bo5RJ90+06yJEf6XCqhViLHRJaP uGFH4V27i9k7famIpyqKfmlV5Id45wyhv2CTsD9/OeewkDEqfiaGPTiGGykmCsWVp81W Nl6+ac8cpaln8MaVdwUQIxdu3NAvVtqbE2n8BYIBkTk/oO9gRhnKgnuqod+8jDDMR6gP k2wiFU7RrPq3PhQ51tvipi7BNySkFXk0Bd8UVGUg7WjoFeFLHlGy5CNMOpD7U3YMvxp8 CMitfl/rbj9LT/dz0wdw26mzmTB/p3MtZPpOV2XC8VbqMVhtistvwzzPW06Hf8irR7xZ EMhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=moonz0vCzeKsZ7s3C/9s96mvunJbTbFjY/xq+QGQiFU=; b=YzlTgsJEkQtsa0xWKlQTxrjs5Y3Li1ny9bRz/MFXHo20L2yX8xQk/+Y8AvwB5/AScF x0d/b7ZThjGmthNSeyrcX99zQ5hfrbK+N21GyzJ4AiLwPL9sJXP3HSrj+S2eXG5PJRm/ UyDfOpMt8rd0GxkW/dg2pf0kLbC4ceNhBEK3L+h5osBHlHCtkTFjqNQGbbIrg5an0VR9 6GT8Efy+meoy+QM5oX0vuS2vpenDhzHDx/te3Ok7pJ2VwyS1xNc2WmjHKGKRiTPVsfJY kReQC6qpLSXhjIhdmDuFTojBEW+6pI1/NQJkU8GkT/R7l1OIEtvoFdvMk/Qe8zEWOApL VJ/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="f/cvJzs4"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w6si1048056oth.1.2020.04.07.00.23.38; Tue, 07 Apr 2020 00:23:51 -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=@google.com header.s=20161025 header.b="f/cvJzs4"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727549AbgDGHXe (ORCPT + 99 others); Tue, 7 Apr 2020 03:23:34 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:55433 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726635AbgDGHXe (ORCPT ); Tue, 7 Apr 2020 03:23:34 -0400 Received: by mail-wm1-f68.google.com with SMTP id e26so650580wmk.5 for ; Tue, 07 Apr 2020 00:23:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=moonz0vCzeKsZ7s3C/9s96mvunJbTbFjY/xq+QGQiFU=; b=f/cvJzs4hHBo0uRzPwRKSEvoC3stydmbBO9/RHgLtlmVPhWP+nyzfFZdtNIGIbs0EU 4RzTmbJpyGGvz5+Zkcm5cjQjtpk0iqx6xnNxtz0++n9qrq/+DnkTYiUQeDfeNc7LxN1E dZldt5xxuKm3bOvWCFQoJbYur6K1nDaG3kgP3HbXvcGaiBVOtTcDMnmRmHmwefq353Pm Fz/oUMXEo1Ber8wmEvc02lfsL5W4LjBFZMszN/NuTvN3SKckC8Cn9BFuEGqvAUx6IkMO o+MhXQc0kIW5j8dIYSFfqMVbpZy9uHgLsgdBpbCTaM+yVonbKx96PvVrv4yBcLSrx7Lu 8Bfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=moonz0vCzeKsZ7s3C/9s96mvunJbTbFjY/xq+QGQiFU=; b=VP/6fQEgLWvVAE4nj2g3A3iG5bIJTyle82sZWAKaZJEc8wa8BPBN5rpyPaIoa4VEBJ KBgM0m05p+UWIFvrsIS4EjICDKgZNGrMKmx7hTRoeZqwld/Pm+qlk9q7oypESISqLUd8 LgXxpXGa8tH6TfiQHKEokew5xjZVwW993eOeVc0YQ+myJ50nPBrjwty8EVlnSUpC/MWh UiqIO8xAmeJAl42DJw7F3UnetkWrPAzpxo9iDeqjL+4falX2L8mF0poSCTw8KhLkChR5 xVvm0jDlOSmtXAPxzVrV34T9jAtoHTX56NsvPeAKKWmEG7JuXHPa3Lm6+NRcSoawgaMx DfSw== X-Gm-Message-State: AGi0PubTEkIV9Xvu/2TNGODg2Opi5ml4NTI5i1HtANe/SrnJ0HkUdS6C waUFR8F5J7rkjtdr7QqVgi3k6glkH6gabto6XxKg1g== X-Received: by 2002:a1c:5f56:: with SMTP id t83mr862533wmb.61.1586244211840; Tue, 07 Apr 2020 00:23:31 -0700 (PDT) MIME-Version: 1.0 References: <20200406114845.255532-1-apusaka@google.com> <20200406194749.Bluez.v3.3.I28a54f18ca82b58e44689a0c76663e735fefb6f1@changeid> In-Reply-To: From: Archie Pusaka Date: Tue, 7 Apr 2020 15:23:20 +0800 Message-ID: Subject: Re: [Bluez PATCH v3 3/3] shared/att: Check the signature of att packets To: Luiz Augusto von Dentz Cc: linux-bluetooth , Archie Pusaka Content-Type: text/plain; charset="UTF-8" Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Luiz, The reason test-gatt.c is stuck is because there exists a test which sends pdu with opcode = 0xBF, an invalid opcode, to test the robustness of the system of an invalid request. By applying the patch, instead of replying to the pdu, we silently ignore it, which makes the test stuck. The opcode has the "signed" bit (0x80) on and "command" bit (0x40) off, which makes it in a difficult situation where it shouldn't be possible and as far as I know is not explicitly discussed in the spec. I shall fall back to this part from the BT spec, vol 3. Part C section 10.4.2: "A device receiving signed data shall authenticate it by performing the Signing Algorithm. If the MAC computed by the Signing Algorithm does not match the received MAC, the verification fails and the Host shall ignore the received Data PDU." Therefore, I shall modify the failing test, and add another case which is just "invalid request" but without the signed bit. Thanks, Archie On Tue, 7 Apr 2020 at 05:16, Luiz Augusto von Dentz wrote: > > Hi Archie, > > On Mon, Apr 6, 2020 at 4:49 AM Archie Pusaka wrote: > > > > From: Archie Pusaka > > > > Tested to pass these BT certification test > > SM/MAS/SIGN/BV-03-C > > SM/MAS/SIGN/BI-01-C > > > > --- > > > > Changes in v3: > > - Separate into three patches > > > > Changes in v2: > > - Move the signature verification part to crypto.c > > - Attempt not to copy the whole pdu while verifying the signature > > by not separating the opcode from the rest of pdu too early, so > > we don't have to rejoin them later. > > > > src/shared/att.c | 25 ++++++++++++------------- > > 1 file changed, 12 insertions(+), 13 deletions(-) > > > > diff --git a/src/shared/att.c b/src/shared/att.c > > index 948a5548b..31c6901fb 100644 > > --- a/src/shared/att.c > > +++ b/src/shared/att.c > > @@ -881,15 +881,15 @@ static void respond_not_supported(struct bt_att *att, uint8_t opcode) > > NULL); > > } > > > > -static bool handle_signed(struct bt_att *att, uint8_t opcode, uint8_t *pdu, > > - ssize_t pdu_len) > > +static bool handle_signed(struct bt_att *att, uint8_t *pdu, ssize_t pdu_len) > > { > > uint8_t *signature; > > uint32_t sign_cnt; > > struct sign_info *sign; > > + uint8_t opcode = pdu[0]; > > > > /* Check if there is enough data for a signature */ > > - if (pdu_len < 2 + BT_ATT_SIGNATURE_LEN) > > + if (pdu_len < 3 + BT_ATT_SIGNATURE_LEN) > > goto fail; > > > > sign = att->remote_sign; > > @@ -903,10 +903,8 @@ static bool handle_signed(struct bt_att *att, uint8_t opcode, uint8_t *pdu, > > if (!sign->counter(&sign_cnt, sign->user_data)) > > goto fail; > > > > - /* Generate signature and verify it */ > > - if (!bt_crypto_sign_att(att->crypto, sign->key, pdu, > > - pdu_len - BT_ATT_SIGNATURE_LEN, sign_cnt, > > - signature)) > > + /* Verify received signature */ > > + if (!bt_crypto_verify_att_sign(att->crypto, sign->key, pdu, pdu_len)) > > goto fail; > > > > return true; > > @@ -918,15 +916,16 @@ fail: > > return false; > > } > > > > -static void handle_notify(struct bt_att_chan *chan, uint8_t opcode, > > - uint8_t *pdu, ssize_t pdu_len) > > +static void handle_notify(struct bt_att_chan *chan, uint8_t *pdu, > > + ssize_t pdu_len) > > { > > struct bt_att *att = chan->att; > > const struct queue_entry *entry; > > bool found; > > + uint8_t opcode = pdu[0]; > > > > - if ((opcode & ATT_OP_SIGNED_MASK) && !att->crypto) { > > - if (!handle_signed(att, opcode, pdu, pdu_len)) > > + if ((opcode & ATT_OP_SIGNED_MASK) && att->crypto) { > > + if (!handle_signed(att, pdu, pdu_len)) > > return; > > pdu_len -= BT_ATT_SIGNATURE_LEN; > > } > > @@ -963,7 +962,7 @@ static void handle_notify(struct bt_att_chan *chan, uint8_t opcode, > > found = true; > > > > if (notify->callback) > > - notify->callback(chan, opcode, pdu, pdu_len, > > + notify->callback(chan, opcode, pdu + 1, pdu_len - 1, > > notify->user_data); > > > > /* callback could remove all entries from notify list */ > > @@ -1054,7 +1053,7 @@ static bool can_read_data(struct io *io, void *user_data) > > util_debug(att->debug_callback, att->debug_data, > > "(chan %p) ATT PDU received: 0x%02x", > > chan, opcode); > > - handle_notify(chan, opcode, pdu + 1, bytes_read - 1); > > + handle_notify(chan, pdu, bytes_read); > > break; > > } > > > > -- > > 2.26.0.292.g33ef6b2f38-goog > > This actually make unit/test-gatt get stuck for some reason, so you > will need to investigate and make it work with existing tests or fix > the tests if there are actually not conforming to the spec. > > -- > Luiz Augusto von Dentz