Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1076744pxv; Thu, 1 Jul 2021 16:47:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0OPhdhickLnzctXEYbNVjH21Wk3ADqNdbHH//A1PXSpRzV2gpFJCTzPno9kDUB0uE5Blu X-Received: by 2002:a17:906:b851:: with SMTP id ga17mr2549572ejb.86.1625183261777; Thu, 01 Jul 2021 16:47:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625183261; cv=none; d=google.com; s=arc-20160816; b=vDyW+qLQM1aQPqONcfbBgQ5uXkizVHoaKwKEqol6eNhG17Z4WgAZV/VPrXA6F1MVi/ WBIp/kQX2RcXcVP8NCrmQjPPVLLu2rfyWOfqGRXN1nulbHY8DsazeVBO+ktaj/j5DZlz zksskLN17NR1TFOAuEuQDmXLTVmDt0UZKyu4b+N16NzLodIWv7geWpEBDxezvIxtJElk ZQ4/cjXdBvLsfCrncKXGvER3u5gZiNqLTGFJ1auVN0huWVwWIC3f9bAKM8RojlXZbsXj ZbLeYf37oXSOOtpBRxvR6sgKtmrpjDzLx2V/wDl+stvbRCuFqsGk8ZtHEjyZZ0D8w+b6 igng== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=B5wbH7/HMNjanvR8tAtZwAF7kIgDHX/YS9tb4UgAOWc=; b=jC+7KObAXyKzKdchc/cnb7XADnc70huytIXKwtTG7C+WCIFg8IReaJZQvsuI0NDjY4 buakv//QdXAjh4DJJwPs7cu35XskR3B8gidXv9IJLVX3YkgcBhEKbMyfOl40/V9aACUA nzNMGnE+gF2uChxE0QfTc9PN3RZUX0Y20uvAmZ8vzLIcsdxUnUC7Ge6clOah6TvVwaKZ Bxm2fDG9HUZRgekb3At5G9MIazfJAV3nqjI4cUFDpsAss9q2c5+emJ6zkqzcjGqGi2m0 7xAFIlmtJaAqlfoPU3wWaTaljrMXvULMM1NvQ/w2pp5trfFapHRSNnOtVTc+ad6euXKQ ISAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=h0vlT1Ol; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t8si1149241eds.185.2021.07.01.16.47.19; Thu, 01 Jul 2021 16:47:41 -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=@gmail.com header.s=20161025 header.b=h0vlT1Ol; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234584AbhGAXqd (ORCPT + 99 others); Thu, 1 Jul 2021 19:46:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234447AbhGAXq1 (ORCPT ); Thu, 1 Jul 2021 19:46:27 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9ED33C0613DE; Thu, 1 Jul 2021 16:43:55 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id u25so10799141ljj.11; Thu, 01 Jul 2021 16:43:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=B5wbH7/HMNjanvR8tAtZwAF7kIgDHX/YS9tb4UgAOWc=; b=h0vlT1OlSlEAUB13UOuY9xFCOZ5aFqW82re6QtgaLgVBidGuj7DW94ugdc4fOCjnXa mpKvGPEGWIJ8DVAKgARSG7aL5aBCNl+bxIugTxxSnWlGIbJ0ZRg7AlpK1vtBUM2LZ9Xp Ikr3dKe8y6r9xAudOSnbKmuBeSrpYAvV1V6IiPh2Ca+DxiyJTKaSA6AyPpXagbgvwy7+ sYvBZAZQQ+1PEdQTW8bP1gZOdbAIjSiycJxAs6A6bBuQ1Yz/DgRKGoG1kguh+90Xfx8U ozJW4qIR8GzruYBKPSPW7gp6dCYuX03PfTGkoMDNXUwoR+ccfKm5Zzv/nCkXfWelbE/L SToQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B5wbH7/HMNjanvR8tAtZwAF7kIgDHX/YS9tb4UgAOWc=; b=Ogp0HltWfe4tSxTaMuLagS5L+sDlW3kKmxY/Y8ti73ZBTtmuOmW2pX/Qw/RduvS2Qi X5A4mvrHhUlEriQ7Je+e2eoufubfFTqgJ6xf6n6sbFqqgqg1gXjdJCK6bGUKfVk9Kp1T QiCuJv9+yKdvGROiM2rt1Ygrt5JVvFQD2jsO+g57j7YxmN/ApLY/+DqM/Zxo40GLGSDD Ikq/xufy7EwvaY7ko51PV4M2zArMi3upuqVsWvwGKpBfDU44G8k2GB5Izi7UX3+LgIh4 O9Adq0orKl1K1zbULWI8umLravJatpaqbP6fXs9Ay7MY/KVZoLypjhNbQECFtu1gG0Zw zUXA== X-Gm-Message-State: AOAM5323EIKR0E3Hx8JvTNp8JQOsrkWCv3CtboafI0czay/o2R1mVs+J X5zjLvsSJNdXVSYKkgjpvCw= X-Received: by 2002:a2e:9ace:: with SMTP id p14mr1571292ljj.188.1625183034051; Thu, 01 Jul 2021 16:43:54 -0700 (PDT) Received: from localhost.localdomain (94-29-37-113.dynamic.spd-mgts.ru. [94.29.37.113]) by smtp.gmail.com with ESMTPSA id e23sm60743lfq.221.2021.07.01.16.43.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jul 2021 16:43:53 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Mark Brown , Rob Herring , Sebastian Reichel , Peter Chen , Greg Kroah-Hartman , Felipe Balbi , David Heidelberg Cc: devicetree@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH v2 05/12] usb: otg-fsm: Fix hrtimer list corruption Date: Fri, 2 Jul 2021 02:43:10 +0300 Message-Id: <20210701234317.26393-6-digetx@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210701234317.26393-1-digetx@gmail.com> References: <20210701234317.26393-1-digetx@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Cc: stable@vger.kernel.org Signed-off-by: Dmitry Osipenko --- drivers/usb/common/usb-otg-fsm.c | 6 +++++- include/linux/usb/otg-fsm.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/usb/common/usb-otg-fsm.c b/drivers/usb/common/usb-otg-fsm.c index 3740cf95560e..0697fde51d00 100644 --- 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 otg_fsm *fsm) 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)); } diff --git a/include/linux/usb/otg-fsm.h b/include/linux/usb/otg-fsm.h index 3aee78dda16d..784659d4dc99 100644 --- 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; }; -- 2.30.2