Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp886264rwi; Wed, 19 Oct 2022 04:19:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Fbjdd171OBKxCRHwmt0XunnpEud9k1hxhQyo0hGS4heh4zXjWefRjJpieqvp3SN0J3Z2A X-Received: by 2002:a05:6402:181a:b0:458:c6a0:b69 with SMTP id g26-20020a056402181a00b00458c6a00b69mr7142356edy.52.1666178360191; Wed, 19 Oct 2022 04:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666178360; cv=none; d=google.com; s=arc-20160816; b=oRORJArU6otlATBZ+V6fPFRvm899P6w9oE3iySkeAr+1hQ6EhXkYzVehR6F1pX5TWA hV0YeSGVCn2RQZT6lP1zwlA5A2pfPRD+N0otyr4XeGJmLUA+WV8NM2he7YMJPyLpaeEY WHfw+Jg2VxaC3Ln13+5mtI0Bo3WOm9zIqtE7UbbHi8m6Fjg54mS2K7vNLmATRK+/MygG wSmgWysP6pQ5T1prZA6qF3vjWpZPqA2CALXx+EKFW4y5a3B6X6ep4kEk0akzP3pLJ+Tt eS6oba7890lV2W1G1RcO+t5hIwKHaSz5AjZTcdLdE4Nm2CfB6dx04m8FBdSi/Y4+OtOZ Fv+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iDZxBpHEMuWW/IHcoGPFen8vKYrYIQgt1kpP0dt7gdk=; b=qbzRn6nwTqQgF6RI1EG2LxmF3ZH0VIwvrmZQkqJgXwAKF0sx3cieSpuLb4DihUZeVD q/y/y8bPxb20ofmEgD03mYUeuhBuYnyT0k/zoahMUZjJU83VhE3GrA0hlZa0HW9q0gXW 2HuqPWPfcjUz9LpKxekab3yRL62nViydIwTWrecrG8r3UEeRiOI63oYB/iiFCM2lqn6g obKRrklQI/GBVRNTgzGImE+Pcy6erQn591Du4Ta8j3swGpnJ0v+qt9shEBzVnVdfLXyF 6TaRUI2/aTsTpTczuzGEXYYzxYybYZfZpoP75twJtRI99C4ljCc/DEiyWqba8CPSE2rM ImvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1Mb57gMi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wv2-20020a170907080200b0073146b3f95asi14643306ejb.632.2022.10.19.04.18.53; Wed, 19 Oct 2022 04:19:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1Mb57gMi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234615AbiJSKwz (ORCPT + 99 others); Wed, 19 Oct 2022 06:52:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234550AbiJSKw2 (ORCPT ); Wed, 19 Oct 2022 06:52:28 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAFAC15DB36; Wed, 19 Oct 2022 03:23:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B3F66B82390; Wed, 19 Oct 2022 08:51:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DF16C433D6; Wed, 19 Oct 2022 08:51:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169498; bh=7h9aWcGCfgx2rKr3+DGUU7gZV0M1EwXuVeR7W2iK1KQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1Mb57gMi8Zzw+vx0lh0NZZ1XWGIowbwIVVwpLD8EQYaZMjke31LhZ8ntiNMtI5D9+ fEn1tf5E72VzLjNq6rtGIXKYHyPvQgFhp4EAsYXfn43SG+zTt05e6zGI8I41B5fZn0 gmgH/lT8KzNE5XZ4BZKzvQamthMI7M9tgZDfgeiE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Tetsuo Handa , Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 6.0 298/862] Bluetooth: hci_{ldisc,serdev}: check percpu_init_rwsem() failure Date: Wed, 19 Oct 2022 10:26:25 +0200 Message-Id: <20221019083303.176643973@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tetsuo Handa [ Upstream commit 3124d320c22f3f4388d9ac5c8f37eaad0cefd6b1 ] syzbot is reporting NULL pointer dereference at hci_uart_tty_close() [1], for rcu_sync_enter() is called without rcu_sync_init() due to hci_uart_tty_open() ignoring percpu_init_rwsem() failure. While we are at it, fix that hci_uart_register_device() ignores percpu_init_rwsem() failure and hci_uart_unregister_device() does not call percpu_free_rwsem(). Link: https://syzkaller.appspot.com/bug?extid=576dfca25381fb6fbc5f [1] Reported-by: syzbot Signed-off-by: Tetsuo Handa Fixes: 67d2f8781b9f00d1 ("Bluetooth: hci_ldisc: Allow sleeping while proto locks are held.") Fixes: d73e172816652772 ("Bluetooth: hci_serdev: Init hci_uart proto_lock to avoid oops") Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- drivers/bluetooth/hci_ldisc.c | 7 +++++-- drivers/bluetooth/hci_serdev.c | 10 +++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index f537673ede17..865112e96ff9 100644 --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c @@ -493,6 +493,11 @@ static int hci_uart_tty_open(struct tty_struct *tty) BT_ERR("Can't allocate control structure"); return -ENFILE; } + if (percpu_init_rwsem(&hu->proto_lock)) { + BT_ERR("Can't allocate semaphore structure"); + kfree(hu); + return -ENOMEM; + } tty->disc_data = hu; hu->tty = tty; @@ -505,8 +510,6 @@ static int hci_uart_tty_open(struct tty_struct *tty) INIT_WORK(&hu->init_ready, hci_uart_init_work); INIT_WORK(&hu->write_work, hci_uart_write_work); - percpu_init_rwsem(&hu->proto_lock); - /* Flush any pending characters in the driver */ tty_driver_flush_buffer(tty); diff --git a/drivers/bluetooth/hci_serdev.c b/drivers/bluetooth/hci_serdev.c index c0e5f42ec6b7..f16fd79bc02b 100644 --- a/drivers/bluetooth/hci_serdev.c +++ b/drivers/bluetooth/hci_serdev.c @@ -310,11 +310,12 @@ int hci_uart_register_device(struct hci_uart *hu, serdev_device_set_client_ops(hu->serdev, &hci_serdev_client_ops); + if (percpu_init_rwsem(&hu->proto_lock)) + return -ENOMEM; + err = serdev_device_open(hu->serdev); if (err) - return err; - - percpu_init_rwsem(&hu->proto_lock); + goto err_rwsem; err = p->open(hu); if (err) @@ -389,6 +390,8 @@ int hci_uart_register_device(struct hci_uart *hu, p->close(hu); err_open: serdev_device_close(hu->serdev); +err_rwsem: + percpu_free_rwsem(&hu->proto_lock); return err; } EXPORT_SYMBOL_GPL(hci_uart_register_device); @@ -410,5 +413,6 @@ void hci_uart_unregister_device(struct hci_uart *hu) clear_bit(HCI_UART_PROTO_READY, &hu->flags); serdev_device_close(hu->serdev); } + percpu_free_rwsem(&hu->proto_lock); } EXPORT_SYMBOL_GPL(hci_uart_unregister_device); -- 2.35.1