Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp215581rdb; Fri, 5 Jan 2024 07:37:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IE64WRbCEtlnIltoXVwXf/GqmEFtOe2xVpxoVGhUFR1i8Fgo9GfJ7yPCdAhEdxTriZHhQkw X-Received: by 2002:a7b:c7cf:0:b0:40d:884b:c8a9 with SMTP id z15-20020a7bc7cf000000b0040d884bc8a9mr1290258wmk.107.1704469025431; Fri, 05 Jan 2024 07:37:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704469025; cv=none; d=google.com; s=arc-20160816; b=Qx+g1ArUsl1WQknjSdl45wZNPP1bTFEXy4Xa5hXu/J7364c/XPoM81cJWQRYdjBcgt s3FsekZ8Jnt0F3eziqCHVh9VnQtWspOZsdr1qV40t7UUnaaeT6G9W4d5zY3UgMbzV2Gi voHrjLAQ8UJZMonWrXkxzG9iaSjhmZ/4T/aVTx7ncd7d1dFMLALYPBExEPzl8gVTFOYV Oyj0wu12HEQr2EDzutQrVgclC6TAJmhI8YMkxFXc6SjyXjmgnjModj0nvyFtHAe/715l JDm4z5JaMp3as2RLwmuFWRXkuYVl747FqsXZmfL7FPLwENKhyKAHKK5lqBXEbkRKV08j 0+XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=Eap6Bv7UqsiZ31u/Bbi6NwynETu5hHY2qpNTg74+3d4=; fh=i+NhMAH/JI0dqVM3qNZ5q7A4njsrSeYwUdGWwz+saP0=; b=sk5/ES4zlG6+8G8weDsx1IaIWVEE3En/P4IIRwutwzxX7UN3aNg+Yhw5F49o2w3zSZ U5EHqofPcZTxllKcP2O/DDKuR/pT42QOJnAewVps1V+fzKatD9XYvTSseja2uxuxE84i xwYJRaKXBL4aDm/1+5PJIKZPNmcaA6OEVXzsQre3Qbcu6wwzP2k0f8rTNYZXiVch5ixl kzoaAVy9I0CRmLj1cjYLzsfxETyoFklgZcvMiLG9Hk+XMQK6Ux5XcPEevrLPWbXJWvCH 6oT3smxtfJjwiN6RVViibrH6hmgMuR5VqUiovillXGV3oP2O4d0cVoKYHujOuN2KsKdF LVmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Kc4nxtF9; spf=pass (google.com: domain of linux-kernel+bounces-18000-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18000-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id gw24-20020a170906f15800b00a28c80df00asi663576ejb.496.2024.01.05.07.37.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 07:37:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18000-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Kc4nxtF9; spf=pass (google.com: domain of linux-kernel+bounces-18000-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18000-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 2DD081F2209B for ; Fri, 5 Jan 2024 15:37:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C08472E650; Fri, 5 Jan 2024 15:36:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Kc4nxtF9" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62DBD2E631; Fri, 5 Jan 2024 15:36:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2cd37c0b8e5so3795481fa.3; Fri, 05 Jan 2024 07:36:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704469011; x=1705073811; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Eap6Bv7UqsiZ31u/Bbi6NwynETu5hHY2qpNTg74+3d4=; b=Kc4nxtF9xb1ENTb1SiB2MbyxlpMycpuJr9KWN7U6dnxvT1TATB4ti1+YIgLZ4jQuyt 9BnnRKN5wD9A91OWn3PgUxeDt7bM2WMeT+mEsYEHb2tmv4GLTXcN9IT1FB4EAGtOUrt/ Ne4+TbKRlVE+Q9P+Ly+Jt91MjiccEEVrnxvfMXqYb+j+41LpuoYc4tUEB0wUA52KVzkw 7ryhj3wakHPee/A/gvIS2yBJPrtoNScgP1ihGiSmDqK+DmYWj/OBol1kkSMFm3JbbF5m kEccfZOkg56F+oGaSGin+ZBChMMTb2FmEbu+f+RmQkAh/yBmx9Z3qp1KVjrv1oBJ68V5 g1NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704469011; x=1705073811; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Eap6Bv7UqsiZ31u/Bbi6NwynETu5hHY2qpNTg74+3d4=; b=tTOh4LQ/0Ulae9/sAvJouIr35pr5LNAVOD8MFHrCmrl3u+QSvRHd7e/4o2nJG9EiTC 95hM7iz6i2uWXMXkBsoNUTVaukYHyDxiPN8RtZYSdmcXjZk9sD1b4PobqCoYTd1hy9fj 0XLc7QzIKloJ+bCF7A248LOtdk7qDQjenZUMysmVF/3ASc9KxYy63RyS6NDK2tfwApmI mPPJGTLOYmOYfjUy9EXQk393ayeySSreyrrlhNfZz57cfdE5eFw3vOTTIZcxrooMEr+h NQ7fPGCt8oCHrnaf9plBg39s8SKTL3of61pAI8VihutbfTP4x8MOI17vEI8yJhLOT/mg 8+Ow== X-Gm-Message-State: AOJu0YzIVewkjik5WdU2ivAdK44jl04/ztCFcDuUnkyxpxL6y9DHEZgt HuQCiXsuEjgT4zjk/2VdIIlXczLRdvmo+IvN+u5LTjWL X-Received: by 2002:a05:651c:1992:b0:2cc:8e9d:1769 with SMTP id bx18-20020a05651c199200b002cc8e9d1769mr1382307ljb.95.1704469011248; Fri, 05 Jan 2024 07:36:51 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240104115453.1.Iaa08c695d3dcf819910ea723c3eb502935638172@changeid> <63d2b52d-8f0b-4456-896c-ecdaf835c65a@wanadoo.fr> In-Reply-To: <63d2b52d-8f0b-4456-896c-ecdaf835c65a@wanadoo.fr> From: Luiz Augusto von Dentz Date: Fri, 5 Jan 2024 10:36:39 -0500 Message-ID: Subject: Re: [PATCH] Bluetooth: Avoid potential use-after-free in hci_error_reset To: Christophe JAILLET Cc: yinghsu@chromium.org, chromeos-bluetooth-upstreaming@chromium.org, linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Christophe, On Fri, Jan 5, 2024 at 2:15=E2=80=AFAM Christophe JAILLET wrote: > > Le 04/01/2024 =C3=A0 12:56, Ying Hsu a =C3=A9crit : > > While handling the HCI_EV_HARDWARE_ERROR event, if the underlying > > BT controller is not responding, the GPIO reset mechanism would > > free the hci_dev and lead to a use-after-free in hci_error_reset. > > > > Here's the call trace observed on a ChromeOS device with Intel AX201: > > queue_work_on+0x3e/0x6c > > __hci_cmd_sync_sk+0x2ee/0x4c0 [bluetooth ] > > ? init_wait_entry+0x31/0x31 > > __hci_cmd_sync+0x16/0x20 [bluetooth ] > > hci_error_reset+0x4f/0xa4 [bluetooth ] > > process_one_work+0x1d8/0x33f > > worker_thread+0x21b/0x373 > > kthread+0x13a/0x152 > > ? pr_cont_work+0x54/0x54 > > ? kthread_blkcg+0x31/0x31 > > ret_from_fork+0x1f/0x30 > > > > This patch holds the reference count on the hci_dev while processing > > a HCI_EV_HARDWARE_ERROR event to avoid potential crash. > > > > Signed-off-by: Ying Hsu > > --- > > Tested this commit on a chromebook with Intel BT controller. > > > > net/bluetooth/hci_core.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c > > index 65601aa52e0d..a42417926028 100644 > > --- a/net/bluetooth/hci_core.c > > +++ b/net/bluetooth/hci_core.c > > @@ -1049,6 +1049,7 @@ static void hci_error_reset(struct work_struct *w= ork) > > { > > struct hci_dev *hdev =3D container_of(work, struct hci_dev, error= _reset); > > > > + hci_dev_hold(hdev); > > BT_DBG("%s", hdev->name); > > > > if (hdev->hw_error) > > @@ -1060,6 +1061,7 @@ static void hci_error_reset(struct work_struct *w= ork) > > return; > > ^^^^^ > Should we also call hci_dev_put() if we hit this return? Yep, I will fix that since Ive already pushed to bluetooth-next. > > CJ > > > > > hci_dev_do_open(hdev); > > + hci_dev_put(hdev); > > } > > > > void hci_uuids_clear(struct hci_dev *hdev) > --=20 Luiz Augusto von Dentz