Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3946492ioo; Mon, 30 May 2022 13:43:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJDOp8b+hLJsUq/LyolZr+QldTvXK8fUJMnSqhRak30BSN43VUadF4EJUcYaxcoOy+XOpe X-Received: by 2002:a05:6402:2994:b0:42b:7c29:dcb with SMTP id eq20-20020a056402299400b0042b7c290dcbmr36970834edb.182.1653943427910; Mon, 30 May 2022 13:43:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653943427; cv=none; d=google.com; s=arc-20160816; b=b9L7squb/E31+dlpxjLTUIs+q7F6aTgZvkQLV0k6oWMqAOkOR3gx/HTW1Pa3CS7X3I fxE79CtM9oqDMmoXu+2Hsc6KXofqvA2UIRskryRC42z8AiibHo0W+o3H6P9BBwqf6hUQ wk2fwEH3GrfZQbVcvwe801U6JmaHwZhWiH98kCfIlFwkVMflMXwv+BsBvpR1/0rA+5dP hbjXSJ2FziOoROo6L3aTVhs4nIhwZGTq9ZekFfLjIQ2IFdQJOnpzYqVVXK1TAhCxoaJe rrmZ5jKECuEfGjSZTJLwmbdsjF91gub7AghmIO4SCHv3LOIUdzULjxHuryr6lsisRVbN 6n1A== 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=/VScGwwQVqhc3Crv4EEnon24+OlA00xnO1FCsOH1D9o=; b=CjPPptjhRrs0MEY+nd55HcU9qjr7F3YEloQalUs1JDtT3piLlADvITZw2QUdu8MAc0 tAzP36ZO5Ur+bKVM/zWsHwjyvxkDp7nNUjY/r/vA4bVEj4Fr8PbYJp8aGwd2ezmR1bSY lIwHn3RFvymmFHdx2M3LdLXkKYQY5U/v55gfwiMUsZHCq9E73qHRw1Hmsr27XFP4ihLa MhmATnIIPcq1+WcAVEybmo3cVpiSggI6rVnDXyELHQhSHl2lGzSJh2bw83BcvPPUj3uv Vi9UnNSPNeVg49p9Vm8eVzVIoqxkwChEA95g7SYCA8X1Pn2Quc00SS4++AGHiA2UEdWm XBiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OQvM+maz; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di7-20020a170906730700b006fefa469b6fsi14187863ejc.610.2022.05.30.13.43.23; Mon, 30 May 2022 13:43:47 -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=@kernel.org header.s=k20201202 header.b=OQvM+maz; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241692AbiE3Ows (ORCPT + 99 others); Mon, 30 May 2022 10:52:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242689AbiE3Ob2 (ORCPT ); Mon, 30 May 2022 10:31:28 -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 9BDB312DBFB; Mon, 30 May 2022 06:53:16 -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 1898AB80D86; Mon, 30 May 2022 13:53:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7AB7C3411F; Mon, 30 May 2022 13:53:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653918782; bh=FUexYxaRsvee6a4Kuwpw9ly8fry/guwfgp+ZPHLQiCg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OQvM+mazQQMInayt9PCUkuRFPwlLHV8tJAxWd6UgLnA5NVbiZzroijUarxZITNYXu pzUWkTghG0DrXWrUEUESV8KiNLlQQSmveEov7cTW7h4/yMnOMgTbTiBI47xMPkSwpb A3vLvXMgUFpPjfYS/mIDAkMzUCCFUQ34MBM+TIzbajyNvkSXYDH99OyQTMCkDLD5kC sTI40m9ThAnxTeBWdG+SyKaF9QyOJhJHnmTWk24fWSKbqZr0c3FRLJf7MUjcWDmPKG CoEllIhd5zlYYkuJmP0b8K/YcLKK7+/AEnruFIse2pI6ZdsVtEsca+url7G6Z/fFh7 jWA+jY9kHwfMg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Lin Ma , Mark Brown , Sasha Levin , oder_chiou@realtek.com, lgirdwood@gmail.com, perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org Subject: [PATCH AUTOSEL 4.9 20/24] ASoC: rt5645: Fix errorenous cleanup order Date: Mon, 30 May 2022 09:52:07 -0400 Message-Id: <20220530135211.1937674-20-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220530135211.1937674-1-sashal@kernel.org> References: <20220530135211.1937674-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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: 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 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c index 1ac96ef9ee20..703b26ec4e15 100644 --- a/sound/soc/codecs/rt5645.c +++ b/sound/soc/codecs/rt5645.c @@ -3878,6 +3878,12 @@ 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); -- 2.35.1