Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3756689pxt; Tue, 10 Aug 2021 10:35:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzI1PsL1VUy10UHJdfSz6kfc12HPAm8RagbZ3TvLvv0extb8rBZNj+Lw/gCgaccSPYJDANi X-Received: by 2002:a17:906:4913:: with SMTP id b19mr2766824ejq.315.1628616925841; Tue, 10 Aug 2021 10:35:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628616925; cv=none; d=google.com; s=arc-20160816; b=0SEYGRTrQ/YynSat84VZi0wK2HEu6I4Slt2qsGJufYcwzIq0OPsWYXZ+yHOK/6Shqe JySL3mnQriEOrnoTYFYtuSWVI6pT8+P2IM+VbamqRLyt4slbNeCHpEf/BmgQyNhvEHOJ ItmgX0e2xX+nbTfPEWjpsFJx13aHS5JeNIKSQgOigTLBqBInJw2qHMjDX+Wn91b7DGIB /ZsODDlKL3sPT2W4IyHCfurU+zCz/Lt8xn9gOY5Eg7/5IDjXNkh1UyHOhX5LdukRIKlD +pNHl7q2S85QpmxP0CDMFeO7N6bVi8lKyEBKRijjqADMtDRAKKWLbQadvg7TuOKiXLrq HqJg== 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=vHEHTNuZQZS6APru4MY7GBAGHOtrmaqhdlqOQggx71Y=; b=JIAsgSQo6Dx62j7AeCL8vzqIOg1dL3fNDmPEpA6YLvqmBP2p81FzMmw+zaCIDstp9e 5b1mFS2hzG8umW2hiuv+dGGGPfyP6zGiD30aQWCv+8EK5PnzYeW3RaBObY/LQyhCCzir s5kkRXXVe3//hW75TK2ehsmkTfpylLv/Qe1zRVMOk20nF9wdgZM2WyUEeO5b3BKq6yYJ h5q9wUjPxMQveUKyu/uNX5iDqW4yvI+yYK2tnMYj1DpT9WDk9AOEKCrfp74Qwa194wc8 f7FwJJHnV5ILp47hDLfkTp+UthAmIP80Xw+o3QGkBIcoYbd2KbJMW4zZcXvD5vz7O34U 6pPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NPZn0Ofz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a18si19770456ejj.147.2021.08.10.10.35.01; Tue, 10 Aug 2021 10:35:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NPZn0Ofz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232323AbhHJRdR (ORCPT + 99 others); Tue, 10 Aug 2021 13:33:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:33850 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231921AbhHJRcz (ORCPT ); Tue, 10 Aug 2021 13:32:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C268A6108C; Tue, 10 Aug 2021 17:32:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628616753; bh=MGfQA6lcM9g8o8bScDfSMHw06mk8qD9asDGzQiw1DAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NPZn0Ofz+9Tna2TKpg9iW+uZVDU+PYM+tIfCZmf8wazzi1wKAl7OixJCoixNx3vze lEaTUEMHPoSIdkfWQvfdwWFTMtkh5iLm916rhj8oZvOuXS2+ahDJFEYBPUH/nftX0q cEIlDX5dXZTnPRAKW30CKZ5o40RwyRYVVwg0FqFs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Chen , Dmitry Osipenko Subject: [PATCH 4.19 31/54] usb: otg-fsm: Fix hrtimer list corruption Date: Tue, 10 Aug 2021 19:30:25 +0200 Message-Id: <20210810172945.199593424@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172944.179901509@linuxfoundation.org> References: <20210810172944.179901509@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dmitry Osipenko commit bf88fef0b6f1488abeca594d377991171c00e52a upstream. The HNP work can be re-scheduled while it's still in-fly. This results in re-initialization of the busy work, resetting the hrtimer's list node of the work and crashing kernel with null dereference within kernel/timer once work's timer is expired. It's very easy to trigger this problem by re-plugging USB cable quickly. Initialize HNP work only once to fix this trouble. Unable to handle kernel NULL pointer dereference at virtual address 00000126) ... PC is at __run_timers.part.0+0x150/0x228 LR is at __next_timer_interrupt+0x51/0x9c ... (__run_timers.part.0) from [] (run_timer_softirq+0x2f/0x50) (run_timer_softirq) from [] (__do_softirq+0xd5/0x2f0) (__do_softirq) from [] (irq_exit+0xab/0xb8) (irq_exit) from [] (handle_domain_irq+0x45/0x60) (handle_domain_irq) from [] (gic_handle_irq+0x6b/0x7c) (gic_handle_irq) from [] (__irq_svc+0x65/0xac) Cc: stable@vger.kernel.org Acked-by: Peter Chen Signed-off-by: Dmitry Osipenko Link: https://lore.kernel.org/r/20210717182134.30262-6-digetx@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/common/usb-otg-fsm.c | 6 +++++- include/linux/usb/otg-fsm.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) --- a/drivers/usb/common/usb-otg-fsm.c +++ b/drivers/usb/common/usb-otg-fsm.c @@ -193,7 +193,11 @@ static void otg_start_hnp_polling(struct if (!fsm->host_req_flag) return; - INIT_DELAYED_WORK(&fsm->hnp_polling_work, otg_hnp_polling_work); + if (!fsm->hnp_work_inited) { + INIT_DELAYED_WORK(&fsm->hnp_polling_work, otg_hnp_polling_work); + fsm->hnp_work_inited = true; + } + schedule_delayed_work(&fsm->hnp_polling_work, msecs_to_jiffies(T_HOST_REQ_POLL)); } --- a/include/linux/usb/otg-fsm.h +++ b/include/linux/usb/otg-fsm.h @@ -196,6 +196,7 @@ struct otg_fsm { struct mutex lock; u8 *host_req_flag; struct delayed_work hnp_polling_work; + bool hnp_work_inited; bool state_changed; };