Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3884158rwi; Sat, 22 Oct 2022 01:31:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM71qXtgpO4/H12jzoAGdBxJOWr76UHLGnhkQXznx0emmk9uDGXVhS2SYaYSSTNpw9lnCFKr X-Received: by 2002:a17:903:2591:b0:17f:8b74:f3c0 with SMTP id jb17-20020a170903259100b0017f8b74f3c0mr24071450plb.36.1666427503594; Sat, 22 Oct 2022 01:31:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666427503; cv=none; d=google.com; s=arc-20160816; b=dvampLMiqsA4W7HH0oUGKheH8/fU5ShS3M7yNch36SufzNagRIyEmAHdTZoqEWnPmw Kn18kq8GM18yKGoEYpIJU+q1qiekx95HvIEs5D7jSEa8kQmsJ0W9KCBR1rDrDTofe6a5 wMznKJHznWP2UauV0zJLSvJ4KossH5BMJOVQhyxiA9sT8EALDxwHM/2y3cBL/g02YWJP yg0LHLziCAtkzGqkc03Ws6CzKdicKTUXlui4SeDx1xNhxmlel4wJiCnW3l5RjsAB7fmr KJDhYV13524CUNcfGNj0YTy29T+xdgaOsFT+HaEzUsZ65wXHaaBDpJx92lU/y1C7PNGA iSag== 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=jBmgXJ8K6yp4MDAR/Vz9g/VdIsz9YpXr3oeS/n3LXZoBqKbLe1NE714/1o7vaRILQj 91QT5Lia04TuT5y05ffkAqNmOMUWgWsSBIBRKqUQl7FtwfgIp57VIrjSWk38kVmXjJBL e5of/Hr/YFSXvzUCzS85lMG7xVdffbxNl7siYZrOzuR0ROFivCX3WlIGyXejUnOFhhH7 BadMVVxzQd6JS5oqqEbIoVr8FpC29GZv33njOCyp2d37J4rJIllFnOmg0TEGg2s4O8Wn 0dmaGD1tQqhcneTquaOZphDZ7+DM8GFD3spqm65j8ERA1p2CWPX/CEuy3oFyRtp9bQWX n6fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=emN9mDtV; 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 h8-20020a170902704800b001713df0c8b2si24171267plt.213.2022.10.22.01.31.31; Sat, 22 Oct 2022 01:31:43 -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=emN9mDtV; 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 S232048AbiJVHzi (ORCPT + 99 others); Sat, 22 Oct 2022 03:55:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231791AbiJVHwG (ORCPT ); Sat, 22 Oct 2022 03:52:06 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B7042C2AFF; Sat, 22 Oct 2022 00:46:26 -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 771D8B82E28; Sat, 22 Oct 2022 07:45:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB40AC433D6; Sat, 22 Oct 2022 07:45:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424732; bh=7h9aWcGCfgx2rKr3+DGUU7gZV0M1EwXuVeR7W2iK1KQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=emN9mDtVj3IS3r3i+RJpZWPV2zYr0HZ/H+goF+IBZBeXCewcrB44B2/Yr+0T+W5ts h+xRP4tBteUOAnT/nByRJOk3sMHwVIlEVFHbjOZYgTOjpFY6f1jyj8l+uliccET884 K98NqwEXlx1pI5bO4cVoJyRI1YTc6JptJ2aRswTs= 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 5.19 255/717] Bluetooth: hci_{ldisc,serdev}: check percpu_init_rwsem() failure Date: Sat, 22 Oct 2022 09:22:14 +0200 Message-Id: <20221022072459.894957866@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@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.3 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