Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2170876iof; Tue, 7 Jun 2022 22:05:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0Z1lBSXUjBIpYHavp/wjci2GWQB+5KVz1u+vhoCNXetA6LBkVEy4WYQxUxI0yynzsNpiY X-Received: by 2002:a17:902:d504:b0:167:756a:f992 with SMTP id b4-20020a170902d50400b00167756af992mr16403668plg.160.1654664749309; Tue, 07 Jun 2022 22:05:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654664749; cv=none; d=google.com; s=arc-20160816; b=ifuXE76/THkSmCGGxEMssvk25AjoDRbDRUj+1UCozEoOFLs1SWyU3AU7nW6mfbvZxs aC+buFyEaLQUhe5vR+T9HZwlDK3sS1/mHc6LT9gzL9AVzBKH7OQ3x1khqF5M1eDR2X9b 9I9awScQsvlykA8+tW9lAT6sm+AL56lPkPoEsUKcfdrzUojvBh8rNjixfthWLIqamnGq bzymQSHc42myDRRXds6Wu38iw4uHimo70w5wRXpxD/LU2w3Z02U7OFz8ysdRt5sPVR/K 1foBcrH4f7n8hVn5cQrbRoxlneYxl3ZlAF7E+vTDHzz0AnIqIel5fOFZk8NWe81Ybaxm F3Bw== 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=MlveFHvqCI+At4pp8nuOTyqWH/f88OhcUWQhnUrzOGE=; b=U6zHuhFc8yDjLfPwsMB7ikGq7a4hCAy6p+QdLKN+qI11U3qtPVfJOiTLPbzKwMv65B JRO/aQyAzr+QrrE3nBkkspktcVSUVimAJm9YFCk2JRq9vU1DBLAY4NMKpE/XYCqMrDpg KoREDu5SDZELthffzZ0FQ07F6upjMWWxIZUX8f7IwsDyu2DE5ayr3kfuolxEmhulhaMD XZs00x3nB+RwCs/M+zv3fmAwrrLGSvDVODPe+u7aW1owXajkWPOmZEILfSQ6vrmTbqzm g5bZX7vjo095THpe5ZgcMY7l5gmFgOVZT507V8enCXXa8d912NgbyaisouHbKHqjQ/ee n+cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y8V9OfzY; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id s16-20020a63ff50000000b003db2ab645d5si26550631pgk.308.2022.06.07.22.05.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:05:49 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y8V9OfzY; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6F5D33A7824; Tue, 7 Jun 2022 21:33:26 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384894AbiFGWQk (ORCPT + 99 others); Tue, 7 Jun 2022 18:16:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380243AbiFGVLm (ORCPT ); Tue, 7 Jun 2022 17:11:42 -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 3DA0B14AA51; Tue, 7 Jun 2022 11:53:38 -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 A23BF616A9; Tue, 7 Jun 2022 18:53:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AED3CC385A2; Tue, 7 Jun 2022 18:53:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654628017; bh=exPGkkNvsUk+zn+DuPTfeI/LZZeoAt13rijdsRPZbco=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y8V9OfzYCwrCiosZQNm9HlsPLIy1MF8FVa5vFZ/FXLe0yrF+PaKyUmhqUHjCWNaEo gA5hxENCvihs2nal5KYdguEsQoNTbEroHKQM8LivflPnJQIcuZiNnBqcQMDBH1G/wS 2CAFvsLI7K9JhuqIiuH6lUoKiu1D6vJ9khKeCBB0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lin Ma , Mark Brown , Sasha Levin Subject: [PATCH 5.18 176/879] ASoC: rt5645: Fix errorenous cleanup order Date: Tue, 7 Jun 2022 18:54:54 +0200 Message-Id: <20220607165007.950520523@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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=-3.1 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=unavailable 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: Lin Ma [ Upstream commit 2def44d3aec59e38d2701c568d65540783f90f2f ] There is a logic error when removing rt5645 device as the function rt5645_i2c_remove() first cancel the &rt5645->jack_detect_work and delete the &rt5645->btn_check_timer latter. However, since the timer handler rt5645_btn_check_callback() will re-queue the jack_detect_work, this cleanup order is buggy. That is, once the del_timer_sync in rt5645_i2c_remove is concurrently run with the rt5645_btn_check_callback, the canceled jack_detect_work will be rescheduled again, leading to possible use-after-free. This patch fix the issue by placing the del_timer_sync function before the cancel_delayed_work_sync. Signed-off-by: Lin Ma Link: https://lore.kernel.org/r/20220516092035.28283-1-linma@zju.edu.cn Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/codecs/rt5645.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c index 197c56047947..4b2e027c1033 100644 --- a/sound/soc/codecs/rt5645.c +++ b/sound/soc/codecs/rt5645.c @@ -4154,9 +4154,14 @@ static int rt5645_i2c_remove(struct i2c_client *i2c) if (i2c->irq) free_irq(i2c->irq, rt5645); + /* + * Since the rt5645_btn_check_callback() can queue jack_detect_work, + * the timer need to be delted first + */ + del_timer_sync(&rt5645->btn_check_timer); + cancel_delayed_work_sync(&rt5645->jack_detect_work); cancel_delayed_work_sync(&rt5645->rcclock_work); - del_timer_sync(&rt5645->btn_check_timer); regulator_bulk_disable(ARRAY_SIZE(rt5645->supplies), rt5645->supplies); -- 2.35.1