Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp579487iog; Mon, 13 Jun 2022 08:30:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCISBe7xOsQ8sms5lxmFaU51MgSFlefTp8STNrMwcIDzZ9f+hJF8+geXZfCCeGyZAfOiyc X-Received: by 2002:a17:907:d05:b0:6f4:3729:8e36 with SMTP id gn5-20020a1709070d0500b006f437298e36mr320933ejc.475.1655134239332; Mon, 13 Jun 2022 08:30:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655134239; cv=none; d=google.com; s=arc-20160816; b=waFO9kcQeuyc5RnhoRFKf+kYk2wNKkMUWRziAISf4Sv5/EyZBHqd2435qCowmrxdlc L3QyWCzn8DwSxTT+qJMNL/PCrnG97qg/OMR7wl7IC3ZXrrhuy1Lz6atZkT6HQrosbBJe qN4UJLRg1Rqq0fJB2q5ZHOzq06hGIG0Qa3fZy42HgLKy4GifmelZXqNhtXRAUM52d09b MO5uIHxPkluZVBjPeVbggFaBcKBFIfx3c6AdNckdl6aYf8IbJ3Ut1iQN1FDVu+tGyg1J yhZVSvv3/yuadSIPSkKNJ7vn+TvaFJw4HjVAKvWG7ClUsg2yW2VEd1eTLmQW0KRijwFG ND9w== 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=rw87+GbaQfxqvmYst5+91nXZbhGmSimURWrAyllQ/qk=; b=h4I5hhn0s1DQUEVetWkZfZX8e+50FYbkUYGq5Jf6rCzm7xkNDnlj0TneF0zdqTaIgx Qpq2h0YecbmLVZ6xofVoG1I+Carm6TkHf412ouSV3e6b81rc4LpdnEfhSjGT9zwRZbB6 NWtAzQhv1wn7mHFg46eKD03c1fc75nymabyGl8CG7JOQQukBRy3LJUVanfipZyOusmWT RDWJb5rQfaLLOCBuheuOugRT0mkxlcijeAdSv/kkc5IjFx/OtCUUdsF6yxUYnwwK+AOS DJ+lgsyFsdCcoqZ2otdeBOAck1vDuaieNFP2oadj13lzGI8VqUE2qQZIXg25gQjLr1e5 26QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UnmR7SEQ; 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 i19-20020a1709064fd300b0071584915a2asi6192972ejw.602.2022.06.13.08.30.13; Mon, 13 Jun 2022 08:30:39 -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=UnmR7SEQ; 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 S243720AbiFMKkx (ORCPT + 99 others); Mon, 13 Jun 2022 06:40:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347430AbiFMKi6 (ORCPT ); Mon, 13 Jun 2022 06:38:58 -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 8101B13F2B; Mon, 13 Jun 2022 03:23:08 -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 D66B060AE9; Mon, 13 Jun 2022 10:23:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5918C34114; Mon, 13 Jun 2022 10:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655115787; bh=wwpmpeKtWdv8Qo+7Qoo8H2U5yxSNp0eT7vNgXTst/RQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UnmR7SEQcibr7M6rKoD93Qg3+O5aiM1BXZ0CNJIw9DOSki/Cr72f1PK91GhamNVnI /yHlOR6DMHn045/LYDyYl5p628g4cDL17f2lf7Ohwo/dZhh249xxe6iJSOjBg6uMDj bnJft0DU9GrpxUwt0rU9rvKqGZiFvutYD0O9/oEs= 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 4.14 030/218] ASoC: rt5645: Fix errorenous cleanup order Date: Mon, 13 Jun 2022 12:08:08 +0200 Message-Id: <20220613094915.390697663@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094908.257446132@linuxfoundation.org> References: <20220613094908.257446132@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 a98647ac497c..01de25813c72 100644 --- a/sound/soc/codecs/rt5645.c +++ b/sound/soc/codecs/rt5645.c @@ -3972,9 +3972,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); snd_soc_unregister_codec(&i2c->dev); regulator_bulk_disable(ARRAY_SIZE(rt5645->supplies), rt5645->supplies); -- 2.35.1