From patchwork Tue Sep 12 22:02:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuxuan Luo X-Patchwork-Id: 1833220 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rlcz00TWxz1yh6 for ; Wed, 13 Sep 2023 08:03:07 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qgBTC-0004aw-10; Tue, 12 Sep 2023 22:02:54 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qgBT8-0004aX-6i for kernel-team@lists.ubuntu.com; Tue, 12 Sep 2023 22:02:50 +0000 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 023A23F639 for ; Tue, 12 Sep 2023 22:02:50 +0000 (UTC) Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-649b66c99b7so62526706d6.2 for ; Tue, 12 Sep 2023 15:02:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694556168; x=1695160968; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bSABvM6+5sXEgE3IlqnO9aScHhN1pThymgmeSbmiFEk=; b=X90bkIQs5i9eS9lvGPP0kpVw9Ptj7uOQ2q5Thi21Y4GFpfwvlUpLpOIJ8CWeZesDrF EgyNYJyGyH5sjgTgSqoqcQ/XOdt0HzYL1u3UY+Tlcp5SxVapcHYoXu6Iosnl8zYlDwAE HYIhVsuWb67fu7qS8z5EsRDSIra4VeOga5eYW/ZjKrMgdQG7YvuWQyitTHzzn5PFYBkP NbcBg8a3dmtHCBzJ1L8h6RCNKgwMktmazwnCGrJ/C0q/ibRZylS2cJQa6Q+0F3+oeD/8 suyqvIMN5ow/oEDDfNtDD1iqh5M49VzyEJQyEiJrKJ/4IGRwcvy4i15I+I1xQPA0FO93 GiSQ== X-Gm-Message-State: AOJu0YzPLlkUk2109GLDu4bgtbQr1mmFmUHZmhVj7SDSVAqFxau36yG/ 3IRkkA/LozBHoDoozSn9+OxqrhHL+dyVJC+JOwDI2qj3anO5XSA5cxTJrc53D8UqTAdYyEyk/F+ ooU7gcX48VWCDksnPEWg5D/UlS3OTrr7jrB7pIOv8GcrPdqpaLA== X-Received: by 2002:ad4:404c:0:b0:635:e0dd:db4c with SMTP id r12-20020ad4404c000000b00635e0dddb4cmr724470qvp.25.1694556168734; Tue, 12 Sep 2023 15:02:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGNAK412+wf10+Un+SDsVGpBPNpUimJ8tYtW/DDlc3G14lNq4hhu3H6y7pv39ulqbE1aiIcvw== X-Received: by 2002:ad4:404c:0:b0:635:e0dd:db4c with SMTP id r12-20020ad4404c000000b00635e0dddb4cmr724447qvp.25.1694556168466; Tue, 12 Sep 2023 15:02:48 -0700 (PDT) Received: from cache-ubuntu.hsd1.nj.comcast.net ([2601:86:200:98b0:84dd:3fc1:376d:5c09]) by smtp.gmail.com with ESMTPSA id kj22-20020a056214529600b00655dd38f65fsm2689831qvb.114.2023.09.12.15.02.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 15:02:48 -0700 (PDT) From: Yuxuan Luo To: kernel-team@lists.ubuntu.com Subject: [SRU][F/J/L][PATCH 1/1] Bluetooth: hci_ldisc: check HCI_UART_PROTO_READY flag in HCIUARTGETPROTO Date: Tue, 12 Sep 2023 18:02:45 -0400 Message-Id: <20230912220245.50337-2-yuxuan.luo@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912220245.50337-1-yuxuan.luo@canonical.com> References: <20230912220245.50337-1-yuxuan.luo@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Lee, Chun-Yi" This patch adds code to check HCI_UART_PROTO_READY flag before accessing hci_uart->proto. It fixes the race condition in hci_uart_tty_ioctl() between HCIUARTSETPROTO and HCIUARTGETPROTO. This issue bug found by Yu Hao and Weiteng Chen: BUG: general protection fault in hci_uart_tty_ioctl [1] The information of C reproducer can also reference the link [2] Reported-by: Yu Hao Closes: https://lore.kernel.org/all/CA+UBctC3p49aTgzbVgkSZ2+TQcqq4fPDO7yZitFT5uBPDeCO2g@mail.gmail.com/ [1] Reported-by: Weiteng Chen Closes: https://lore.kernel.org/lkml/CA+UBctDPEvHdkHMwD340=n02rh+jNRJNNQ5LBZNA+Wm4Keh2ow@mail.gmail.com/T/ [2] Signed-off-by: "Lee, Chun-Yi" Signed-off-by: Luiz Augusto von Dentz (cherry picked from commit 9c33663af9ad115f90c076a1828129a3fbadea98) CVE-2023-31083 Signed-off-by: Yuxuan Luo --- drivers/bluetooth/hci_ldisc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index 865112e96ff9f..c1feebd9e3a03 100644 --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c @@ -770,7 +770,8 @@ static int hci_uart_tty_ioctl(struct tty_struct *tty, unsigned int cmd, break; case HCIUARTGETPROTO: - if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) + if (test_bit(HCI_UART_PROTO_SET, &hu->flags) && + test_bit(HCI_UART_PROTO_READY, &hu->flags)) err = hu->proto->id; else err = -EUNATCH;