Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp342620rwb; Wed, 28 Sep 2022 03:35:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7N1Esxhej0/zG8OCYPfPZUDDRf7wcvdmEQhH44oFtFq5MCGFbCjjP3/bYi1E1cqepy1jI4 X-Received: by 2002:a05:6402:270d:b0:452:2b68:90a0 with SMTP id y13-20020a056402270d00b004522b6890a0mr32680456edd.132.1664361302891; Wed, 28 Sep 2022 03:35:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664361302; cv=none; d=google.com; s=arc-20160816; b=VmrEhgnwNuK+etiK9UkPiG8S3H4ipuYa03bT/zDlJZxPa1zKPvlueID0hOxjRwyCwt SAsSnIp+MPcl6kN/M4Bk4pbv9NE8DRel/vlbOliZgSHfLALxVpP0rsOizzzPANpdnjqt ylv4PTZByb2I49oE7ZB2hrhZB/7m9Wc/ZIrtEZS2AswGGkYAX14mA9iVGFL5GtGQL2CN hHoe0ijByy7x+PFJZztq0/hoZ/N5YR2BLp7CcnoE5CFImn6Zd1UbeyoaN534XIXCGzZp DH6ZavIY99hxbhkFs5zRBEusm8C2l0mp1Ujv5TEgFyP7XOQVVcjsNMP15RICIwBBVZ86 7cVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=y8iCIbup1m8I+DhLME7pQbo21IbPJrn/gL1OAhTP9U0=; b=Two9k/OlP/yZaF5cCyhrwFp6JseaBGGp3JxttUKQhgOdMmkXIxHmFIUQgwPuBvWwG3 gLj+Ss0UxaMRN35ZCMNAZVEE7PhRhr5qn0tH4VimoKAHhlHeqQtBZTmPG9yKFf/KNaKX BBxV31gV/cDu4oHY6IvWw0dzTBizBb16wBJtERYBRrIHi+VsJRjaHmcQ4Eik0HMeBQ5b bk7BAxebOmX9Fg+cqbgNj9SqIeRqbDMEFp09Ri1kL8wMx2GL7pZxo2c93uDRhLlecybp XQlyl/mccnsTNxx7dOH4L6jfQKmlAM4nDDux9Wmu3aPutKJwEyAgdsM4zlUobfwkhgMu 5pmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W8O7gjTW; 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 dd11-20020a1709069b8b00b00782faf12c6esi5019977ejc.78.2022.09.28.03.34.37; Wed, 28 Sep 2022 03:35:02 -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=W8O7gjTW; 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 S231167AbiI1JqV (ORCPT + 99 others); Wed, 28 Sep 2022 05:46:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233298AbiI1JqS (ORCPT ); Wed, 28 Sep 2022 05:46:18 -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 60D4597D42; Wed, 28 Sep 2022 02:46: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 dfw.source.kernel.org (Postfix) with ESMTPS id CF5BB61DE6; Wed, 28 Sep 2022 09:46:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE924C433D6; Wed, 28 Sep 2022 09:46:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664358375; bh=X0Qhc9iLIP8xYLEQvpMkrhuGs70pVHyhsJYCdLtOALY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=W8O7gjTWXq9XhF7ur5LksP3gzuLYWEeKWzx19KOd8bNm2US2qTEQsV3Tmyq72XjnC rX831/OIxEYwdccBOy9cWs/2u5N0yIIlSzb3JmIsG7kG6ZSEqdXO8XMHPOPqHQCqda T0RHLx5Mv4b69qoII7Ea9PJmuXx8HNu9qGTFEmgYTGlHeU29Ak+IF2ZEX6cogUOxkn knq+G2vSg5rWTNa5iNp5mNvaL4XPRA13ktsFTNFthwCCmkt4PWIhW61autviUdAw+n FSJdRK7CcDbf9ZNzUHU01IPQ7Mno0w0kxpThtdRWb/gda/0glCY0kOCSAx2kqmbhCQ lI0vyFV8U6bQQ== Date: Wed, 28 Sep 2022 12:46:10 +0300 From: Leon Romanovsky To: Duoming Zhou Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, isdn@linux-pingi.de, kuba@kernel.org Subject: Re: [PATCH V2] mISDN: fix use-after-free bugs in l1oip timer handlers Message-ID: References: <20220923142514.58838-1-duoming@zju.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220923142514.58838-1-duoming@zju.edu.cn> X-Spam-Status: No, score=-7.2 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 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 On Fri, Sep 23, 2022 at 10:25:14PM +0800, Duoming Zhou wrote: > The l1oip_cleanup() traverses the l1oip_ilist and calls > release_card() to cleanup module and stack. However, > release_card() calls del_timer() to delete the timers > such as keep_tl and timeout_tl. If the timer handler is > running, the del_timer() will not stop it and result in > UAF bugs. One of the processes is shown below: > > (cleanup routine) | (timer handler) > release_card() | l1oip_timeout() > ... | > del_timer() | ... > ... | > kfree(hc) //FREE | > | hc->timeout_on = 0 //USE > > Fix by calling del_timer_sync() in release_card(), which > makes sure the timer handlers have finished before the > resources, such as l1oip and so on, have been deallocated. > > What's more, the hc->workq and hc->socket_thread can kick > those timers right back in. We use del_timer_sync(&hc->keep_tl) > and cancel_work_sync(&hc->keep_tl) twice to stop keep_tl timer > and hc->workq. Then, we add del_timer_sync(&hc->timeout_tl) > behind l1oip_socket_close() to stop timeout_tl timer. > > Fixes: 3712b42d4b1b ("Add layer1 over IP support") > Signed-off-by: Duoming Zhou > --- > Changes in v2: > - Solve the problem that timers could be restarted by other threads. > > drivers/isdn/mISDN/l1oip_core.c | 11 +++++------ > 1 file changed, 5 insertions(+), 6 deletions(-) > > diff --git a/drivers/isdn/mISDN/l1oip_core.c b/drivers/isdn/mISDN/l1oip_core.c > index 2c40412466e..7b89d98a781 100644 > --- a/drivers/isdn/mISDN/l1oip_core.c > +++ b/drivers/isdn/mISDN/l1oip_core.c > @@ -1232,17 +1232,16 @@ release_card(struct l1oip *hc) > { > int ch; > > - if (timer_pending(&hc->keep_tl)) > - del_timer(&hc->keep_tl); > - > - if (timer_pending(&hc->timeout_tl)) > - del_timer(&hc->timeout_tl); > - > + del_timer_sync(&hc->keep_tl); > + cancel_work_sync(&hc->workq); > + del_timer_sync(&hc->keep_tl); > cancel_work_sync(&hc->workq); It is racy, the call twice to del_timer_sync and cancel_work_sync doesn't solve "the problem that timers could be restarted by other threads." Thanks > > if (hc->socket_thread) > l1oip_socket_close(hc); > > + del_timer_sync(&hc->timeout_tl); > + > if (hc->registered && hc->chan[hc->d_idx].dch) > mISDN_unregister_device(&hc->chan[hc->d_idx].dch->dev); > for (ch = 0; ch < 128; ch++) { > -- > 2.17.1 >