From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDB7DC7618E for ; Mon, 20 Mar 2023 01:19:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230384AbjCTBTO (ORCPT ); Sun, 19 Mar 2023 21:19:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230247AbjCTBSj (ORCPT ); Sun, 19 Mar 2023 21:18: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 A7B2420692; Sun, 19 Mar 2023 18:09:17 -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 2363F611EC; Mon, 20 Mar 2023 00:56:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9931BC433D2; Mon, 20 Mar 2023 00:56:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679273803; bh=zxOf/nGpknIPFp7a70Wr/dNwaARtrLnZu7RGXHKLgxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qjp9qIQ1Y5cJHcJV4gnrfivfiAgpQfj4JzgY9mjg9MzoI7H/VAKr0PrjgmrWjVL1t Vn7aIMWaog3pAhQpjg245e0R0j7DN7WfdIfrSQxyVaomRfq73UQWJPR1IcZGtzlpEj b56boNXhUsb0lbelRIxTjXjzfMnWCxPyBIOW7CgwzzjITifW2YiOqtiD5w+nuN2l1m 6Ec2sqmDDJCv+3n1Z/WbVi1O9yyItuBmd/xexCgjB+MtkLOo4es8KbYBOu6tQXg6k6 dIkTLqYfmU3Xsq7vlE+7kb6F9Ok8IuseImx5kZ8lCZyO49rWc7CGIyiFvxFnCEiici OqX7W9y7f6iXA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Reka Norman , Srinivas Pandruvada , Jiri Kosina , Sasha Levin , jikos@kernel.org, benjamin.tissoires@redhat.com, liqiong@nfschina.com, linux-input@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 03/12] HID: intel-ish-hid: ipc: Fix potential use-after-free in work function Date: Sun, 19 Mar 2023 20:56:26 -0400 Message-Id: <20230320005636.1429242-3-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230320005636.1429242-1-sashal@kernel.org> References: <20230320005636.1429242-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Reka Norman [ Upstream commit 8ae2f2b0a28416ed2f6d8478ac8b9f7862f36785 ] When a reset notify IPC message is received, the ISR schedules a work function and passes the ISHTP device to it via a global pointer ishtp_dev. If ish_probe() fails, the devm-managed device resources including ishtp_dev are freed, but the work is not cancelled, causing a use-after-free when the work function tries to access ishtp_dev. Use devm_work_autocancel() instead, so that the work is automatically cancelled if probe fails. Signed-off-by: Reka Norman Acked-by: Srinivas Pandruvada Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/intel-ish-hid/ipc/ipc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/hid/intel-ish-hid/ipc/ipc.c b/drivers/hid/intel-ish-hid/ipc/ipc.c index 8f8dfdf64833e..e23766ca9d3e1 100644 --- a/drivers/hid/intel-ish-hid/ipc/ipc.c +++ b/drivers/hid/intel-ish-hid/ipc/ipc.c @@ -5,6 +5,7 @@ * Copyright (c) 2014-2016, Intel Corporation. */ +#include #include #include #include @@ -594,7 +595,6 @@ static void recv_ipc(struct ishtp_device *dev, uint32_t doorbell_val) case MNG_RESET_NOTIFY: if (!ishtp_dev) { ishtp_dev = dev; - INIT_WORK(&fw_reset_work, fw_reset_work_fn); } schedule_work(&fw_reset_work); break; @@ -885,6 +885,7 @@ struct ishtp_device *ish_dev_init(struct pci_dev *pdev) { struct ishtp_device *dev; int i; + int ret; dev = devm_kzalloc(&pdev->dev, sizeof(struct ishtp_device) + sizeof(struct ish_hw), @@ -920,6 +921,12 @@ struct ishtp_device *ish_dev_init(struct pci_dev *pdev) list_add_tail(&tx_buf->link, &dev->wr_free_list); } + ret = devm_work_autocancel(&pdev->dev, &fw_reset_work, fw_reset_work_fn); + if (ret) { + dev_err(dev->devc, "Failed to initialise FW reset work\n"); + return NULL; + } + dev->ops = &ish_hw_ops; dev->devc = &pdev->dev; dev->mtu = IPC_PAYLOAD_SIZE - sizeof(struct ishtp_msg_hdr); -- 2.39.2