Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3494766pxb; Mon, 25 Jan 2021 18:48:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJwNMI3I1vGzgV/m78q2RBWN/CtNe/5u5X7lv579LUWLO3ciNUcxCxTzINyJBgPZ993vUJfP X-Received: by 2002:a50:9ee9:: with SMTP id a96mr2834778edf.343.1611629301712; Mon, 25 Jan 2021 18:48:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611629301; cv=none; d=google.com; s=arc-20160816; b=JpgJMNqvt3QpyVTfOqIHXBItjzCnZBtKndWkVoM4h1B+DMokHBU/jG/gAP7Aiao7rO ZFcfr3E1FuhiVf7mr1KgyXzmXL9mDItLrjMShJtuPA9puUKiIB72V3yndQwTwvm9xYkQ adoyEMPKKv2JTWgbZOBX3dDb77CLK7/kCjgPLmT5vvJOzO4KDmr7cK3PMU9D3DdwNbRE yfI/cLv1hdKB5SGKYufaXdSk0crdLbZEGW5EaDUooP2WU4d0ZZTFiJe19cLw0q71BZDK RqfV9NQqDlLXV2fVjCqFm8dsc8hFfxnTXie9FRaSfeGsWAUYhCi91/jRERpudDv+2Y3z 9gOQ== 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=RaA5DzCUr1gMC2ZIX3M6uX3YVjkeLDbK5Bx2VQTR7BU=; b=J76LnvJ9YvCT8Vw7gVA6gTRTrEsAxc1+TR2Gt+D72AZqVyHJXFIKBNYny15cfTWfW8 LmQWyVe2tq0VrqNIh1TD/FuaJpGvMNUm/RV6qZBL3HPgrvYq3+nnOrRiTOVCw/22Dhra FNVzeZIOpZF5vNIsBLQSKORKDsNCkBPqzWpuqzAG2CAx0Y/zm1B69Bupg/gtdUbOezOJ BFwT9ujDh7braSIkrY1AGI6aaUfIo01/ASe2LqFfHI7ppMjxO5DEKWwOI1vef3YpSPMa 18IfOSLOCShlvYmc8UUO4h3ji1cxYerY3tsLUKpRUjdUMRoeGuuy6tsZnMtMzQrFgXxf m7KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="au3dlO/i"; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt22si6566720ejb.256.2021.01.25.18.47.44; Mon, 25 Jan 2021 18:48:21 -0800 (PST) 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=@chromium.org header.s=google header.b="au3dlO/i"; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731969AbhAYThC (ORCPT + 99 others); Mon, 25 Jan 2021 14:37:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731960AbhAYTgu (ORCPT ); Mon, 25 Jan 2021 14:36:50 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98936C0613D6 for ; Mon, 25 Jan 2021 11:36:10 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id r12so19681311ejb.9 for ; Mon, 25 Jan 2021 11:36:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RaA5DzCUr1gMC2ZIX3M6uX3YVjkeLDbK5Bx2VQTR7BU=; b=au3dlO/iMpaCnvOJnvMn7W+D9Qh9iV3B1BUkb+l5oPCm2JMaZ75iaovnyqrjcvpRH7 l3Jm6SLRSvtFjQFgkV7Vc5HyE2PtUJUvmBKci7PxO1/mon2ddmWKXjJw0nj7jffz6Sz1 A1Z6A8MJmcl9XV7kIt6XMFGzcqUQ/j+BUoUpI= 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=RaA5DzCUr1gMC2ZIX3M6uX3YVjkeLDbK5Bx2VQTR7BU=; b=Z7tLvX0/PkC/+gBHruffGkhcC74JmF8spFpzMIq7b7e3yOQfSQyeXXhve9EO6Ckvgr txRhF9TJ/xREVfsXZCZk76VJ9TxK3cPjebnn7O1gIl1FWaUa5AGUAIwg6ZhVSmSPfCBm IqVZ2kheJHzm9OviR4CCPKiu/EMp5fYkGlZwCLsMdMSLIuHYDMjqbjUeVPBdF9T7Eqbx LdMKz2wdEwTyaPFRuBWtsaYHHD1ppUHZNYiRRiBWmEPipV/w5xuOyVltZn/RSmyvmGcF QU9kuXInqOGuTtZ71wWXoesJ1Ev+miCeleHOJOLZ6KuV7LpvR2yYmASprmBgbuynSP7O HUUw== X-Gm-Message-State: AOAM531hzeCCBhRyXfJOYTi9GvPGg2xjg/WGf3J0z5NYwPh5BBTms97c d4UAN127D8qXBppPjKk18ygfBD1JlcAPvg== X-Received: by 2002:a17:907:7252:: with SMTP id ds18mr1329347ejc.239.1611603369082; Mon, 25 Jan 2021 11:36:09 -0800 (PST) Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com. [209.85.128.48]) by smtp.gmail.com with ESMTPSA id di28sm11094932edb.71.2021.01.25.11.36.08 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Jan 2021 11:36:08 -0800 (PST) Received: by mail-wm1-f48.google.com with SMTP id j18so479063wmi.3 for ; Mon, 25 Jan 2021 11:36:08 -0800 (PST) X-Received: by 2002:a05:600c:20c:: with SMTP id 12mr1514477wmi.125.1611603368239; Mon, 25 Jan 2021 11:36:08 -0800 (PST) MIME-Version: 1.0 References: <20210122001326.14263-1-sonnysasaka@chromium.org> <20210122001326.14263-2-sonnysasaka@chromium.org> In-Reply-To: From: Sonny Sasaka Date: Mon, 25 Jan 2021 11:35:56 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH BlueZ v2 2/2] input/hog: Do not create UHID if report map is broken To: Luiz Augusto von Dentz 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 Luiz, I have been trying to reproduce the issue again but it turns out to be very rare. Let's defer this patch until I can get a clear log of what is happening and why we get the corrupted cache. On Thu, Jan 21, 2021 at 5:24 PM Sonny Sasaka wrote: > > Hi Luiz, > > On Thu, Jan 21, 2021 at 4:37 PM Luiz Augusto von Dentz > wrote: > > > > Hi Sonny, > > > > On Thu, Jan 21, 2021 at 4:18 PM Sonny Sasaka wrote: > > > > > > The report map in the cache could be dirty, for example when reading a > > > report map from peer was cancelled, we should be able to detect it and > > > not try to create UHID. Instead we will read it again from the peer. > > > > Don't we clean the cache if it had failed? Or you meant to say the > > read long procedure was not complete so we got just part of the report > > map? > Looks like this is the case. It happened to me once when I cancel > reconnection (trigger pairing mode during reconnection) from the > keyboard side. It's hard to confirm since I have to get the timing > right. > > > In that case we should have failed > I agree. However it seems that the code already tries to fail by > looking at the status inside report_map_read_cb, but somehow it still > gets through. It could be the keyboard bug that we have to detect > anyway? > > > also if we need to protect > > uhid from malformed report map, which sounds like a kernel bug, then > > we should at least have it inside bt_uhid instance so we can at least > > attempt to have some unit testing done with broken report maps. > > > > > --- > > > profiles/input/hog-lib.c | 21 ++++++++++++++++++--- > > > 1 file changed, 18 insertions(+), 3 deletions(-) > > > > > > diff --git a/profiles/input/hog-lib.c b/profiles/input/hog-lib.c > > > index 089f42826..d6a3bda4d 100644 > > > --- a/profiles/input/hog-lib.c > > > +++ b/profiles/input/hog-lib.c > > > @@ -946,7 +946,7 @@ static void uhid_create(struct bt_hog *hog, uint8_t *report_map, > > > struct uhid_event ev; > > > ssize_t vlen = report_map_len; > > > char itemstr[20]; /* 5x3 (data) + 4 (continuation) + 1 (null) */ > > > - int i, err; > > > + int i, err, collection_depth = 0; > > > GError *gerr = NULL; > > > > > > DBG("Report MAP:"); > > > @@ -960,6 +960,14 @@ static void uhid_create(struct bt_hog *hog, uint8_t *report_map, > > > if (!long_item && (value[i] & 0xfc) == 0x84) > > > hog->has_report_id = TRUE; > > > > > > + // Start Collection > > > + if (value[i] == 0xa1) > > > + collection_depth++; > > > + > > > + // End Collection > > > + if (value[i] == 0xc0) > > > + collection_depth--; > > > + > > > DBG("\t%s", item2string(itemstr, &value[i], ilen)); > > > > > > i += ilen; > > > @@ -968,10 +976,15 @@ static void uhid_create(struct bt_hog *hog, uint8_t *report_map, > > > > > > /* Just print remaining items at once and break */ > > > DBG("\t%s", item2string(itemstr, &value[i], vlen - i)); > > > - break; > > > + return; > > > } > > > } > > > > > > + if (collection_depth != 0) { > > > + error("Report Map error: unbalanced collection"); > > > + return; > > > + } > > > + > > > /* create uHID device */ > > > memset(&ev, 0, sizeof(ev)); > > > ev.type = UHID_CREATE; > > > @@ -1365,7 +1378,9 @@ static void foreach_hog_chrc(struct gatt_db_attribute *attr, void *user_data) > > > * UHID to optimize reconnection. > > > */ > > > uhid_create(hog, report_map.value, report_map.length); > > > - } else { > > > + } > > > + > > > + if (!hog->uhid_created) { > > > read_char(hog, hog->attrib, value_handle, > > > report_map_read_cb, hog); > > > } > > > -- > > > 2.29.2 > > > > > > > > > -- > > Luiz Augusto von Dentz