Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1065438pxb; Wed, 6 Apr 2022 07:56:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWInmSuaaz20XpOgbmQ3EIrpon1tpzfkKi9jg4jaoEnMUQuFfynjTGdsarYSzegAHQmt5J X-Received: by 2002:a17:902:e889:b0:14f:c4bc:677b with SMTP id w9-20020a170902e88900b0014fc4bc677bmr8954836plg.68.1649257017298; Wed, 06 Apr 2022 07:56:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649257017; cv=none; d=google.com; s=arc-20160816; b=XQJdAzKbpBNhvFmZuhylWts6knfXWBrQGhBE7zm6Kn8ugJ8vHLTjCqKTeo0sQ37peA B6bOEN2anu3nkV4bkR7OB9Ei08blPIj1aO5eyatUdivJ/ybHIN990PQxlFVU+A8YUbVp rx8goGf8J+uYbBlcfadmtqhrBXbMrE0OIjc2j+EEcoAv3kdjxrWqFg2OJX9tYOOIMAip wV7Jkkv4SqH9BmCBWNaOA1nyjhckJLBtqxVr+jtVm4QahZeVPH7XzSBr6bRwI0Tki1GP kBeuzZ7CaHrTDX9PEnJ4Ds/4OpkkgK985/eai/gKOfmXCcXwXke5QCvjdow7VEKcOt6m gBmg== 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=3cuyrh8+h6NwjEexqK+98uxctPEwxuJvxe+8Faz7bP0=; b=XxqZlk8eosStfCqLENp7tryCSGG3gcyUN+qhApivh257K90vwUU9sNikoCndVXJ9DB OnXQ91XfD4gUG80dywV8QWNHY85PqxfhuabmTPOyyjlGgHD3VwC598Ggp59ESAVEglyR OjU58zWjJ2GrPcbYQchpdioVvf/ripiHgRxXCVJuYaMDdjKAVh98uJZfmu5DtsUtHD58 kAvSDCcRSTOCDo0GdU8o/oya/9Ycl2DglK25VEJGKwX4MTT0DzkxBHVkshq+WWmtii9f pCO4AjFTpD+oke07CKs8LHrR1Dwbjelcl1uY8HqFTvBrGriYE+ZuTuZCZLBTiFU0NqjA P6ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=og2SSEgZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id o11-20020a170902d4cb00b00156bb3c32b4si6966585plg.323.2022.04.06.07.56.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 07:56:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=og2SSEgZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7178F38ADB0; Wed, 6 Apr 2022 05:43:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1580069AbiDEXdr (ORCPT + 99 others); Tue, 5 Apr 2022 19:33:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348819AbiDEJsj (ORCPT ); Tue, 5 Apr 2022 05:48:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 695DAADD66; Tue, 5 Apr 2022 02:36:15 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 043C061675; Tue, 5 Apr 2022 09:36:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E146C385A0; Tue, 5 Apr 2022 09:36:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151374; bh=cHh6Am89UvKmAAC6DhpJgKI9IPbPSd8DeXy2OH/l794=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=og2SSEgZXqrAJDWTGwOmos+tVuYTV4fOqA/Lek8t1d7jHdchr/ErrV5DNiX51UfwC En3L0tqDabMuvzwyOJN5/s2Ybt+nkj/iLEQaz4eUUZvgZDYmv3yB1MLoSZlvJDqSvf df4BmomxUFuLbRdhC8D4IVPAEo1oDot9ESK7/BOE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yiru Xu , Pavel Skripkin , Marcel Holtmann , Sasha Levin Subject: [PATCH 5.15 392/913] Bluetooth: hci_serdev: call init_rwsem() before p->open() Date: Tue, 5 Apr 2022 09:24:14 +0200 Message-Id: <20220405070351.598011800@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: Pavel Skripkin [ Upstream commit 9d7cbe2b9cf5f650067df4f402fdd799d4bbb4e1 ] kvartet reported, that hci_uart_tx_wakeup() uses uninitialized rwsem. The problem was in wrong place for percpu_init_rwsem() call. hci_uart_proto::open() may register a timer whose callback may call hci_uart_tx_wakeup(). There is a chance, that hci_uart_register_device() thread won't be fast enough to call percpu_init_rwsem(). Fix it my moving percpu_init_rwsem() call before p->open(). INFO: trying to register non-static key. The code is fine but needs lockdep annotation, or maybe you didn't initialize this object before use? turning off the locking correctness validator. CPU: 2 PID: 18524 Comm: syz-executor.5 Not tainted 5.16.0-rc6 #9 ... Call Trace: __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106 assign_lock_key kernel/locking/lockdep.c:951 [inline] register_lock_class+0x148d/0x1950 kernel/locking/lockdep.c:1263 __lock_acquire+0x106/0x57e0 kernel/locking/lockdep.c:4906 lock_acquire kernel/locking/lockdep.c:5637 [inline] lock_acquire+0x1ab/0x520 kernel/locking/lockdep.c:5602 percpu_down_read_trylock include/linux/percpu-rwsem.h:92 [inline] hci_uart_tx_wakeup+0x12e/0x490 drivers/bluetooth/hci_ldisc.c:124 h5_timed_event+0x32f/0x6a0 drivers/bluetooth/hci_h5.c:188 call_timer_fn+0x1a5/0x6b0 kernel/time/timer.c:1421 Fixes: d73e17281665 ("Bluetooth: hci_serdev: Init hci_uart proto_lock to avoid oops") Reported-by: Yiru Xu Signed-off-by: Pavel Skripkin Signed-off-by: Marcel Holtmann Signed-off-by: Sasha Levin --- drivers/bluetooth/hci_serdev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/bluetooth/hci_serdev.c b/drivers/bluetooth/hci_serdev.c index 3b00d82d36cf..4cda890ce647 100644 --- a/drivers/bluetooth/hci_serdev.c +++ b/drivers/bluetooth/hci_serdev.c @@ -305,6 +305,8 @@ int hci_uart_register_device(struct hci_uart *hu, if (err) return err; + percpu_init_rwsem(&hu->proto_lock); + err = p->open(hu); if (err) goto err_open; @@ -327,7 +329,6 @@ int hci_uart_register_device(struct hci_uart *hu, INIT_WORK(&hu->init_ready, hci_uart_init_work); INIT_WORK(&hu->write_work, hci_uart_write_work); - percpu_init_rwsem(&hu->proto_lock); /* Only when vendor specific setup callback is provided, consider * the manufacturer information valid. This avoids filling in the -- 2.34.1