Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2137897iof; Tue, 7 Jun 2022 21:01:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysBfwfls+eb88rKX+wV/ftj9ajxPPIHp3LdoHuOVPgZsL3VFGOe+IFQHuUd7P6iq5tv6kb X-Received: by 2002:a17:902:7b83:b0:162:2486:7837 with SMTP id w3-20020a1709027b8300b0016224867837mr32150072pll.21.1654660901251; Tue, 07 Jun 2022 21:01:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654660901; cv=none; d=google.com; s=arc-20160816; b=sQwwHi/6np1dRweZKI5HUiSGUvpD5TRp5mS/OSowq6trsLLIPmR/GkbitPeO2ZBlpE zkqsjzzLjKgq01jHsyN/SllK/Bthvg9qkDi3+x2MH6d6eVzSj8YV0sEg5gGasJQWNiMz pHYjdOYgvSKz5A4m8w9EpoyJrUheTMdaNrq+RAOxFdVtHWMYBPLAbcWt4xrYQHKzuCHI exuJMgh/ezTN6Dz/a4ccF+bY/d7AbHCnkme/zhICZy1niunoHCRx6pcojKqzPc9xhoOI mkv5ocWpRc4m7lHrK7ZPkY2MMDQjRKQ2yE/2D1wL05mCQ5CjVrejDsmsXmm936PXCwAV GXng== 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=VJMX6yxcHXagqsdeWa/yUu8sJvxTbiI99N4hG6V2rzI=; b=Wrs6rXyOENo6e0Dt7SygFYwroxo1+JKBxjCVUHHIQFyMntiu8YbmwaZNg4RgMv1WCr uVrgUqG/kZQNVDXuYfgaQApDcZ/RRhrtZIAOHcodN8xU3qzIfmFmNmmE1fF2yzstlSti DEIdokYRQQjrb0Dbyg74aSAMR5M/CDLG1Mz58twclEWh+By+3877kgHvnDPdBx2Pnhii 00cgVLKqT+XUma1nBKeCWMC5Nuy9QQ17xxG7w7nV6Bbfzl9VLa7N8pAWiA3s4WuExonq SaW/aqpTXv6ao+1KpnXlPSPr3/TlLFWzQ4QMsD7KigFuR3eel4V/bKnwBh4mpyLFHJAs N1qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VLRLNE3y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w62-20020a638241000000b003fe2bc67bbdsi1480445pgd.116.2022.06.07.21.01.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:01:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VLRLNE3y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 644CE17CE7F; Tue, 7 Jun 2022 20:36:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346681AbiFGR2K (ORCPT + 99 others); Tue, 7 Jun 2022 13:28:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345992AbiFGRXl (ORCPT ); Tue, 7 Jun 2022 13:23:41 -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 B514710A604; Tue, 7 Jun 2022 10:21:45 -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 5591CB82172; Tue, 7 Jun 2022 17:21:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9AF8C34115; Tue, 7 Jun 2022 17:21:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654622503; bh=5Lmd3+eZdEPNSsCtjnsLeMRcjHWJoPdqLRlFKh33qHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VLRLNE3yCb3aUO20BcsOELzB934u/gF85HHJKqQHDuHxUvt0FxgObsbWHt6IxswEA gg2+JBAf5YNW+UaAz6jhFg3R82wvnZ8iLVvMxW9nahccR74WMB2nO7yiBicJ5CoVPv yc4D6DDWjHigPLgoa623nPdYQxNVTnG5SVZPhDVc= 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.10 083/452] ASoC: rt5645: Fix errorenous cleanup order Date: Tue, 7 Jun 2022 18:59:00 +0200 Message-Id: <20220607164911.027597350@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164908.521895282@linuxfoundation.org> References: <20220607164908.521895282@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 420003d062c7..d1533e95a74f 100644 --- a/sound/soc/codecs/rt5645.c +++ b/sound/soc/codecs/rt5645.c @@ -4095,9 +4095,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