Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3641658pxf; Mon, 15 Mar 2021 14:43:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCuFwwpMZDUk4DVHJKebBogBw0fFhbJPwANzk8IH3/BKKAePDbkl1Ysa0YDK161SXLgiXo X-Received: by 2002:a17:906:380b:: with SMTP id v11mr26545708ejc.183.1615844634344; Mon, 15 Mar 2021 14:43:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615844634; cv=none; d=google.com; s=arc-20160816; b=aXLrkxmwnempSuAr+qFXlrFM8RIbCRuLWSf1sDXvwy2/6YYWb0+iBJYOhMzciY1Ktd gqfg/w4kpLWe46/ZTSO3vbl7IMIeW82CxmcUDECQK5CCAxR7wkrByROKrcGzngPIVpId sZiA/hw4+Kkq4xL3mzc5owNTaa2vFSkK0Agz1NULWx4khm6K3YrRXPWBYu2jY+7vQ+mQ T68ysdE7R2gzHwcPd1Ff/AKl5Gl1wm4OZXhgUujUh/l/Hm0mFhLiCl63mp76ay0ob2bf qn7xanR10iXujzNVMKZ+OAvsUn1nnlAbRL3NWUiLYmzpszCFu0kGbqOkkoOwIsMSKEk4 GgQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=VE9vYK16lIhebNeFtRwi4e5KFBe2scXiyRQNMULQxJE=; b=wiH4oU5nHNQGUFCk3NwrkyiW9ssIo7kRZnq0xvNeZYypMCSKyEIKH0N0MTmiumk1/n as1Sl3xg7wlOhl27zWxMHpNh8kaiqXuAHU5E3YHsPMjb+bOdpOF/ho8D5NAJ/d5ot3p/ WgbyyDl8ALHVXz7fOjlGXE1ZUWbCvQfhBQ+H0Q7pY4alXSuVT0hItLBqkQapfrlO4/re cEB7oNkSUIyJfuk8hj6fizMfGQoPaA/v0qBeeeN37C0DTCVu1Xz4vgkiNsRgEEWuOkTR NISvyT14exSQRgADUFdOZOj3qmbdQC9XfHtZZXiuOYQcAWkS/n6ttVOf+6RjC75kY0BV hpMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DIbBLE6A; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a1si12036364eds.169.2021.03.15.14.43.15; Mon, 15 Mar 2021 14:43:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DIbBLE6A; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233874AbhCOUCB (ORCPT + 99 others); Mon, 15 Mar 2021 16:02:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233793AbhCOUBa (ORCPT ); Mon, 15 Mar 2021 16:01:30 -0400 Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACCBDC06174A for ; Mon, 15 Mar 2021 13:01:29 -0700 (PDT) Received: by mail-oi1-x22f.google.com with SMTP id x78so35761422oix.1 for ; Mon, 15 Mar 2021 13:01:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VE9vYK16lIhebNeFtRwi4e5KFBe2scXiyRQNMULQxJE=; b=DIbBLE6AF0oznOeOBHSKHrnHDwan0qENsg3kCW7gyh6T7FENtbqWwcCXL/JHhLQNrl ZD7+68pPtUhouMu5ma4Xo5kN8zfMBVk6INL8I2CiH1T1fF98YTqJuD+D5vlcEagJmk/4 nqmQkdl+rWVRBlKFy4V6XBDdx828DsvXj7KxUGSsfTQ54F8OvupmP8hLCEtjz3x+rr1X 3X4ZIEjf2o8vWMpfb/dj41HJeLuLtX78mmMjSk6K9/uGWcbjXH9wfVBD/nJdQIS4neKK BlDcHlARWDUKFUo4/ZNMSn/bJ+XkRo3pevoFuGJBIDI70FbXeDXfV/xuH64A7mi1FYW4 nxQw== 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=VE9vYK16lIhebNeFtRwi4e5KFBe2scXiyRQNMULQxJE=; b=ge6tUj01b7m587fT+BLJl8cDO5bGUV79Wvz35RthVYdmXwvifHf5YzQmp4v490/c0/ cY841v8IsOT0oLKPe6ln2K0jek659gJCfduy/bXVbOsxLyr0GeEBSlf8VMk3ydED6F1C 0Jjf1LJUWxvNuMzEYgnAoxOUmYBQkj1sLnAyQylrSY8SzOhdbghobhcW7DwhnJJdobVh 2/8i5DdaN5InZDmW6r9Y5er7dyl6bd5VqEQyFcbi0KcUWxBLhANnKU5UhLRKcxPyLjTH Mo4LLo7QCU6aEeYR+dvXCJoksBL7pMsqmPXsMSntPofsC1jTIbwIWz7JdMEaJhoJLYq0 n5xA== X-Gm-Message-State: AOAM531oFoXzaqBhJZ4lS++qUgqF1SvQkiwIx2bD0rLNUY21KMV8C3BG fkoAfMoTb+WZl2WWPCiFYCfPAdyNAKdMquD8kJa5+m13DddqTg== X-Received: by 2002:a05:6808:1290:: with SMTP id a16mr559373oiw.161.1615838489039; Mon, 15 Mar 2021 13:01:29 -0700 (PDT) MIME-Version: 1.0 References: <20210312181948.1225833-1-luiz.dentz@gmail.com> In-Reply-To: From: Luiz Augusto von Dentz Date: Mon, 15 Mar 2021 13:01:18 -0700 Message-ID: Subject: Re: [PATCH] Bluetooth: L2CAP: Fix not checking for maximum number of DCID To: Marcel Holtmann Cc: "linux-bluetooth@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Marcel, On Sat, Mar 13, 2021 at 3:02 AM Marcel Holtmann wrote: > > Hi Luiz, > > > When receiving L2CAP_CREDIT_BASED_CONNECTION_REQ the remote may request > > more channels than allowed by the spec (10 octecs = 5 CIDs) so this > > truncates the response allowing it to create only the maximum allowed. > > so what does the spec say the behavior should be? Truncate or actually respond with an error? The spec is not very clear about this, well except by saying: 'The Source CID is an array of up to 5 two-octet values and represents the channel endpoints on the device sending the request.' So I guess responding with an error would still conform to the above statement so we would just strictly follow the maximum number of channels allowed. > > Signed-off-by: Luiz Augusto von Dentz > > --- > > include/net/bluetooth/l2cap.h | 1 + > > net/bluetooth/l2cap_core.c | 4 ++-- > > 2 files changed, 3 insertions(+), 2 deletions(-) > > > > diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h > > index 61800a7b6192..3c4f550e5a8b 100644 > > --- a/include/net/bluetooth/l2cap.h > > +++ b/include/net/bluetooth/l2cap.h > > @@ -494,6 +494,7 @@ struct l2cap_le_credits { > > > > #define L2CAP_ECRED_MIN_MTU 64 > > #define L2CAP_ECRED_MIN_MPS 64 > > +#define L2CAP_ECRED_MAX_CID 5 > > > > struct l2cap_ecred_conn_req { > > __le16 psm; > > diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c > > index 72c2f5226d67..6325d4a89b31 100644 > > --- a/net/bluetooth/l2cap_core.c > > +++ b/net/bluetooth/l2cap_core.c > > @@ -5921,7 +5921,7 @@ static inline int l2cap_ecred_conn_req(struct l2cap_conn *conn, > > struct l2cap_ecred_conn_req *req = (void *) data; > > struct { > > struct l2cap_ecred_conn_rsp rsp; > > - __le16 dcid[5]; > > + __le16 dcid[L2CAP_ECRED_MAX_CID]; > > } __packed pdu; > > struct l2cap_chan *chan, *pchan; > > u16 mtu, mps; > > @@ -5973,7 +5973,7 @@ static inline int l2cap_ecred_conn_req(struct l2cap_conn *conn, > > cmd_len -= sizeof(*req); > > num_scid = cmd_len / sizeof(u16); > > > > - for (i = 0; i < num_scid; i++) { > > + for (i = 0; i < num_scid && i < ARRAY_SIZE(pdu.dcid); i++) { > > u16 scid = __le16_to_cpu(req->scid[i]); > > > > BT_DBG("scid[%d] 0x%4.4x", i, scid); > > Is this really a good idea? I would prefer if we check the size first and then just respond with an error. Right, I will change it to just fail with L2CAP_CR_LE_INVALID_PARAMS instead. > Regards > > Marcel > -- Luiz Augusto von Dentz