Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp443771iog; Mon, 13 Jun 2022 06:07:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxw33X+0jN3b74r5BBWSYd6KxFjgKMwv1Fw5sZa5Nf3z3l9k7gIuN95kVWq2NqkFdVO7GeE X-Received: by 2002:a05:6402:17d0:b0:42d:ccc1:f4e4 with SMTP id s16-20020a05640217d000b0042dccc1f4e4mr65688151edy.150.1655125621331; Mon, 13 Jun 2022 06:07:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125621; cv=none; d=google.com; s=arc-20160816; b=RvzCnQnILQ/Aw+0eWwn8/Bsx+19dgLdyuCJNSE+gBZ9zFFE2T1MAHYXXCFdZpnaLPq ENBzYEEmvrHnfdRTOWKQ1OfopU/H/+Rj9XB2cftIxxQpz5iLbflE6FqjU6C1Jmfuzrqa Izm6XuyeX9z8kGoHgYwPK/VpM29hzxGWrj0uy+lsqJ4dIDXxnS91KXPoor8dqRF3u8FK onfKsSvf/SmWd491Ygs6Fu95/5gZP7NXaxGK+lqugGCKd9/vkQoqlc93Qa+kJD1m41sP uWA2pAqFddKEPHHgKEcTd30TRwtgA4uH8pi7eUIzdoI9ySe9KBiPzGDCWWqJFvBNpKoa RHBQ== 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=GK8F1S1KSK2a4f6pscN/XZo3lccI4xMii2/aziAo82M=; b=i19A/o8ulSEeX9NRw6hHwkEDle2vPzjr5wtACja/1QbYtw54JGT3AFkHuRgrxNvyx/ XA0ly4+sSnUFnsWf8qFBSsalB0QHU5VIA0H5PkUlUBaZcA5yYaO5dsh1tqx5jAQeSGip gjTVw/Ox+Ngc0Gdfqm1QEYWjpw+0NXIGovkteKQZACkhtBd4E4jCT+IFEvn1Eo1DUxFp orz5NLe3t6s8bPMRTXCtilD2O+1FJyj72sjFe/LITeiu0ZAIT6pA8018ooNSqK1mosda wbLbH3yDbmUKjD5LUbPE3YcJMs6Linew8jd+NnjDA7uHCKSo3ICNpVAMIEU0paG49mco hhfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=17qfC1ZX; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f10-20020a056402354a00b004319d8ba8a7si8951827edd.505.2022.06.13.06.06.34; Mon, 13 Jun 2022 06:07:01 -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=@linuxfoundation.org header.s=korg header.b=17qfC1ZX; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351018AbiFMLCi (ORCPT + 99 others); Mon, 13 Jun 2022 07:02:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350344AbiFMKyu (ORCPT ); Mon, 13 Jun 2022 06:54:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93FDD1EC6A; Mon, 13 Jun 2022 03:31:05 -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 311B060F09; Mon, 13 Jun 2022 10:31:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C715C3411E; Mon, 13 Jun 2022 10:31:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116264; bh=9PJD3Qn9tZV44T/FEmmw6UElYs3+9edj15+ybckTrGQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=17qfC1ZX11J1AzBW2pQqLWe8GSTJGoQw/7Mut01HzudtpJSidCxXy2LYfh0HIQEeW Fw3mseWQWHjcOJnTNqccLgImFXoLadh5/JcFmlWYDJDRPZX2pdU7ei/VQr2V73Z6aO 5jc2HyLSCn0Vll26SwfurbiPvycjKHI2/rPAP4Wc= 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.4 054/411] ASoC: rt5645: Fix errorenous cleanup order Date: Mon, 13 Jun 2022 12:05:27 +0200 Message-Id: <20220613094930.132861618@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@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=-8.3 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 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c index c83f7f5da96b..a66e93a3af74 100644 --- a/sound/soc/codecs/rt5645.c +++ b/sound/soc/codecs/rt5645.c @@ -4074,9 +4074,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