Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1966837rwe; Fri, 2 Sep 2022 06:43:58 -0700 (PDT) X-Google-Smtp-Source: AA6agR7/ClQBPdmk/CZDk4w+wDVKCoCZlfmSxE43o4RHunG54u0LfX2mNzceuRWpkkUESGAqYEpM X-Received: by 2002:a63:c108:0:b0:41d:6bf3:6807 with SMTP id w8-20020a63c108000000b0041d6bf36807mr31045224pgf.157.1662126237988; Fri, 02 Sep 2022 06:43:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662126237; cv=none; d=google.com; s=arc-20160816; b=m3vRvAGjFgUEKbUPIJWQsJKLcQA7IYoWSa3yaDILk/6c7bAUEeTpD4uTK+w3VuGKdL +7maxnGDdf4n0qb+yEXlLEgVVLV+7S+1sDNizF2ET3+pf2OugurLju85C5kirsRmeC4r 0klf1SrJSjGjIkzNkNopefNfNG0twYmU3On6KsNPLC8GI9uXwxZh8HkNRlzjgwHn64FQ f7FDne2sbredzvub9+63sgrxk5kcrzcWSmd09u0Bw+91ca/+kSNmDZKKJWrNhhVHY9yr VBIKgrxnHLwXqoXyc8pFgNedeO4hFf91Gp2yI82LVPypiqpTCI9MUuUnXuoLIkqsywNH zieg== 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=j6VokE0ybk0IffyB/z1tHO/ATQRBwo97h4iRRK5vUWM=; b=rWfBsVWKQ+UWU+j/UhLad+sfGIFBO0fyK2M0yZYO89CUAuOLvoKabWqLd2kaqgiALx M/3gDyjpZqtfnlgmsFNfoJRHgM6NT+99WDZKyjsheE1RUcwS2PHyub40KrEDxjXYSzl6 Vmvc5NMlbtcAYV/uDk1oMbrKij18MPQs9rEllXasJA8a+si88CAr8k9STGYKgRIKnIQa PZB7pyEW7A3CHB6G80R83FyGaiJACdmxhrP9fiLhqPmA4zFJbzu+vAN0BZncVPlKHqN8 OiYphFSH+W+n4EBfAFKHdGITNeG3ISnFwYpjl0PJxOi4WRq/LB4aRU+3BRbdnNWXIOI5 uueA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iifTHv9P; 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 j7-20020a63b607000000b0041d85f3e817si2046064pgf.676.2022.09.02.06.43.46; Fri, 02 Sep 2022 06:43:57 -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=iifTHv9P; 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 S238056AbiIBMyv (ORCPT + 99 others); Fri, 2 Sep 2022 08:54:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236398AbiIBMxU (ORCPT ); Fri, 2 Sep 2022 08:53:20 -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 0581AFAC5E; Fri, 2 Sep 2022 05:38:10 -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 8B130B82A99; Fri, 2 Sep 2022 12:37:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7CDFC433C1; Fri, 2 Sep 2022 12:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662122226; bh=dQCyYYdHFTcYP0ibPebQBQKt6XsoJLS/blVx6w2TSvA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iifTHv9PuRq/LAmziGZ+CuAmQ8XsN3BdH0DvTfJ+O7p+SEUAjynpkuSE17/u6HWXu 09RXXx5riEDZ3+QMVrhQ9kRnlmrO8bq4lrFu0a3mh86opLLSj6RAuCinAERGx1Jiyg gcfllfhvjwrjMRkG/jLEi+jvOtU863nS1ml4dHEs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Daniel J. Ogorchock" , Jiri Kosina Subject: [PATCH 5.19 25/72] HID: nintendo: fix rumble worker null pointer deref Date: Fri, 2 Sep 2022 14:19:01 +0200 Message-Id: <20220902121405.623143625@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220902121404.772492078@linuxfoundation.org> References: <20220902121404.772492078@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.1 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,T_SCC_BODY_TEXT_LINE 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: Daniel J. Ogorchock commit 1ff89e06c2e5fab30274e4b02360d4241d6e605e upstream. We can dereference a null pointer trying to queue work to a destroyed workqueue. If the device is disconnected, nintendo_hid_remove is called, in which the rumble_queue is destroyed. Avoid using that queue to defer rumble work once the controller state is set to JOYCON_CTLR_STATE_REMOVED. This eliminates the null pointer dereference. Signed-off-by: Daniel J. Ogorchock Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-nintendo.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/hid/hid-nintendo.c +++ b/drivers/hid/hid-nintendo.c @@ -1222,6 +1222,7 @@ static void joycon_parse_report(struct j spin_lock_irqsave(&ctlr->lock, flags); if (IS_ENABLED(CONFIG_NINTENDO_FF) && rep->vibrator_report && + ctlr->ctlr_state != JOYCON_CTLR_STATE_REMOVED && (msecs - ctlr->rumble_msecs) >= JC_RUMBLE_PERIOD_MS && (ctlr->rumble_queue_head != ctlr->rumble_queue_tail || ctlr->rumble_zero_countdown > 0)) { @@ -1546,12 +1547,13 @@ static int joycon_set_rumble(struct joyc ctlr->rumble_queue_head = 0; memcpy(ctlr->rumble_data[ctlr->rumble_queue_head], data, JC_RUMBLE_DATA_SIZE); - spin_unlock_irqrestore(&ctlr->lock, flags); /* don't wait for the periodic send (reduces latency) */ - if (schedule_now) + if (schedule_now && ctlr->ctlr_state != JOYCON_CTLR_STATE_REMOVED) queue_work(ctlr->rumble_queue, &ctlr->rumble_worker); + spin_unlock_irqrestore(&ctlr->lock, flags); + return 0; }