From patchwork Sat Oct 22 07:22:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7344 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1095082wrr; Sat, 22 Oct 2022 01:01:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4rM40ZT9gcFgaVrQcP7ei1M42UeRZUSt9eNKwRJSo/M6iW1hXIpwbfJoY6uuJxlFIPMA/9 X-Received: by 2002:a17:902:bd46:b0:17e:8ee5:7b61 with SMTP id b6-20020a170902bd4600b0017e8ee57b61mr23661983plx.44.1666425703937; Sat, 22 Oct 2022 01:01:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425703; cv=none; d=google.com; s=arc-20160816; b=uz1dcKMa8DrfwALOJ/loxVYD/MfqbfP2Rn6qgsX1ht45JRbZKYlSGWcZmumlt0QCrg qtJfJY7FX6jkiPBLJWthZc6k/tifr2gpqoCPatevSr7Vd5zFQaZad+w8MBE6BeQ4eOHN IebTn2J1HJFS/xepjsLuGwiI8hn4aVVjIJ+GxbiOh5ka7x7LY8+oKYYsl9NRQrHPsT3W uYyWmKIZmKv2JJwaOxbfJgwoyQEdq2gCSeBvz7JGGDY0e2rKWk6WirBZ4lVE3pPS+37B dWjvWsKzd2PoOnrNCqIWl8AC0JcbANf0nQrLLymL5ed7pDLsb49BnWLTT3sF6RXdr46D b4hA== 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=p8l2m2NHhPOpZ8OREbIlejd/CKEhwKGWuFVuNbozv38=; b=r533zUFuAeSfVHO5ZZTGvL18eTzr+HXTswwHqyt2Dmeh8QSZdNBJxB5A4XfGRe30aX RnRptHXaL/7pxJFNMLJ8WU+m8VsjE9n45cBFlab2zBYbVCV97yeuefvl2ToTZy6E895U efbv14L5+bKqzjrKQJfdT3dccZKA4MgzR0Kw66/m/XPgwl3rQI1c5lylrn/qNWQNr0tq Zb6cZlxhKBpbcmusVYa/tLG2IZD5cNVg8DqFUvB8P2TfI4Jw3Y2+vAbnt7mqo0fDj1Ns hQUWlLRotq/7+6/u6sMLRg0n/2w6Zt9V/8noM3ELg5mp6K8VOw7PwTY/wHQR7K2TOKfr KeFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ed9HtI76; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb12-20020a17090b35cc00b002009d750a2dsi1981377pjb.58.2022.10.22.01.01.30; Sat, 22 Oct 2022 01:01:43 -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=Ed9HtI76; 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 S232546AbiJVH7K (ORCPT + 99 others); Sat, 22 Oct 2022 03:59:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232152AbiJVHyK (ORCPT ); Sat, 22 Oct 2022 03:54:10 -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 8961A165C86; Sat, 22 Oct 2022 00:47:15 -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 5D11660AC7; Sat, 22 Oct 2022 07:46:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71317C433D6; Sat, 22 Oct 2022 07:46:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424795; bh=1vk9cCfPuQn9h6X3LRfdcgmD8iNffBsmLEgziE8/sDQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ed9HtI76yHNAaDwoPru4wIoyZqjOkZ8TejFPq+2PkQRPR3/6Yqaj9n7BGvO0ctwQl lU7Ht6RY+I6PTCkMYT62Fn3Ke7E6QFV4O4XeF8IVusrQ0YnxUhcxNB4eTHEXFvg/At 308/9yWX17jxvzqYbvrAoGGQbj4eAN5gkE+OAq+Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Duoming Zhou , Leon Romanovsky , "David S. Miller" , Sasha Levin Subject: [PATCH 5.19 279/717] mISDN: fix use-after-free bugs in l1oip timer handlers Date: Sat, 22 Oct 2022 09:22:38 +0200 Message-Id: <20221022072503.291343145@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747373998552424582?= X-GMAIL-MSGID: =?utf-8?q?1747373998552424582?= From: Duoming Zhou [ Upstream commit 2568a7e0832ee30b0a351016d03062ab4e0e0a3f ] 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 add a bool flag to show if card is released. Then, check this flag in hc->workq and hc->socket_thread. Fixes: 3712b42d4b1b ("Add layer1 over IP support") Signed-off-by: Duoming Zhou Reviewed-by: Leon Romanovsky Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/isdn/mISDN/l1oip.h | 1 + drivers/isdn/mISDN/l1oip_core.c | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/isdn/mISDN/l1oip.h b/drivers/isdn/mISDN/l1oip.h index 7ea10db20e3a..48133d022812 100644 --- a/drivers/isdn/mISDN/l1oip.h +++ b/drivers/isdn/mISDN/l1oip.h @@ -59,6 +59,7 @@ struct l1oip { int bundle; /* bundle channels in one frm */ int codec; /* codec to use for transmis. */ int limit; /* limit number of bchannels */ + bool shutdown; /* if card is released */ /* timer */ struct timer_list keep_tl; diff --git a/drivers/isdn/mISDN/l1oip_core.c b/drivers/isdn/mISDN/l1oip_core.c index 2c40412466e6..a77195e378b7 100644 --- a/drivers/isdn/mISDN/l1oip_core.c +++ b/drivers/isdn/mISDN/l1oip_core.c @@ -275,7 +275,7 @@ l1oip_socket_send(struct l1oip *hc, u8 localcodec, u8 channel, u32 chanmask, p = frame; /* restart timer */ - if (time_before(hc->keep_tl.expires, jiffies + 5 * HZ)) + if (time_before(hc->keep_tl.expires, jiffies + 5 * HZ) && !hc->shutdown) mod_timer(&hc->keep_tl, jiffies + L1OIP_KEEPALIVE * HZ); else hc->keep_tl.expires = jiffies + L1OIP_KEEPALIVE * HZ; @@ -601,7 +601,9 @@ l1oip_socket_parse(struct l1oip *hc, struct sockaddr_in *sin, u8 *buf, int len) goto multiframe; /* restart timer */ - if (time_before(hc->timeout_tl.expires, jiffies + 5 * HZ) || !hc->timeout_on) { + if ((time_before(hc->timeout_tl.expires, jiffies + 5 * HZ) || + !hc->timeout_on) && + !hc->shutdown) { hc->timeout_on = 1; mod_timer(&hc->timeout_tl, jiffies + L1OIP_TIMEOUT * HZ); } else /* only adjust timer */ @@ -1232,11 +1234,10 @@ release_card(struct l1oip *hc) { int ch; - if (timer_pending(&hc->keep_tl)) - del_timer(&hc->keep_tl); + hc->shutdown = true; - if (timer_pending(&hc->timeout_tl)) - del_timer(&hc->timeout_tl); + del_timer_sync(&hc->keep_tl); + del_timer_sync(&hc->timeout_tl); cancel_work_sync(&hc->workq);