From patchwork Wed Nov 16 20:59:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuxuan Luo X-Patchwork-Id: 1704828 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=ZXpnS0GW; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NCFmg2x6gz23mL for ; Thu, 17 Nov 2022 08:00:03 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1ovPVl-0008Bg-9M; Wed, 16 Nov 2022 20:59:57 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ovPVh-00087J-SG for kernel-team@lists.ubuntu.com; Wed, 16 Nov 2022 20:59:53 +0000 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 6BA6D3F11B for ; Wed, 16 Nov 2022 20:59:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1668632393; bh=PV2Sa9+EjTorS2wsaTTeBwDPUHhiY6abDKtNjLO1PnY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZXpnS0GWsutcZWgc1mcK4xElccTzk24/f6moAE1m6dMwg533sSEbkTo6dwqeR9COf K5tZQfZYO7RZbC+Anw2V/FHQb7koZBrrfz8oGtQsW7qBnXYg9AaRs8PakEguFQjmHZ JjXShhO9jIErqdKM/VGsJ9MhnkLcqLGQjJI5cmHJqYY8gykd86gQ7iHe1hjeFi82/s aQ7LeqzgrQE7NM5txQGE9aFG5gDZkaRslf+vWSQcaYzZoA6xBfX62pavswInsLLfyx 40F2SDZGfVBmXg038y0VQXCudvR79bhaOxokLhcVYTdZVYK3Fb1PDHnisHKW0kGCLq 0UKaImwCRxUYA== Received: by mail-qt1-f199.google.com with SMTP id gc12-20020a05622a59cc00b003a5444280e1so14136392qtb.13 for ; Wed, 16 Nov 2022 12:59:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PV2Sa9+EjTorS2wsaTTeBwDPUHhiY6abDKtNjLO1PnY=; b=3rI4yBVonoZjfylNnBZ/bRGG5ny/s9WTI0hroBqsy8tZxPVhmcvwvCZ67XfJPvIdTw rF53B7YfHWEGzTKI3CvkkY8LK4yBqgdjQq2CZiDvA/RJyEO+a+CZOimW2D3cl2rFhN4Q V7vpQefpmCOSSYt1NAsXAE3Q6CYBMJVg6c/EHri04mcuUF7y+TcPzPnnTdOgxhzARhE+ XV3p+Qs6USHjRT5zTlKiAcwdAFLcUzinHR4QybdKc0brmaX1/6EUqWcgl0KZIQMFqesa xw9QR0EMb/871afKIL3IAtS5SBuq1vbLC7RmGykXkcrlOGRlLyhrQ+jao0lCxKkJbhkB 8ZcA== X-Gm-Message-State: ANoB5pn7lUgybJVuaXnaLobsBiab5TtrkF17elvkRqxKsK5qUbjKrYoB qtiz/veKGMPKZ9lq0dsvS4s4Cj+BPFyLae/vZ7Z+TtKctf05WnOdFAWrK3QfYtpIM+4aLoaWEaC 1/l15B7OAFi5MaLNMjsvTdVcCHq8cxEuSFWXwR2CwQw== X-Received: by 2002:ac8:7d92:0:b0:3a5:2037:5a11 with SMTP id c18-20020ac87d92000000b003a520375a11mr22432016qtd.105.1668632392129; Wed, 16 Nov 2022 12:59:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ovkqsScGiVGj+7HDlSclWCWMoT1wYGaefY2ksgprwXB10XoF1WwlrihV5iaIzt9urR+2PkQ== X-Received: by 2002:ac8:7d92:0:b0:3a5:2037:5a11 with SMTP id c18-20020ac87d92000000b003a520375a11mr22432004qtd.105.1668632391911; Wed, 16 Nov 2022 12:59:51 -0800 (PST) Received: from cache-ubuntu.hsd1.nj.comcast.net ([2601:86:200:98b0:ad63:7d49:828c:930f]) by smtp.gmail.com with ESMTPSA id h2-20020ac85042000000b003a606428a59sm1909983qtm.91.2022.11.16.12.59.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Nov 2022 12:59:50 -0800 (PST) From: Yuxuan Luo To: kernel-team@lists.ubuntu.com Subject: [SRU][J][PATCH 1/1] mISDN: fix use-after-free bugs in l1oip timer handlers Date: Wed, 16 Nov 2022 15:59:40 -0500 Message-Id: <20221116205940.20586-4-yuxuan.luo@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221116205940.20586-1-yuxuan.luo@canonical.com> References: <20221116205940.20586-1-yuxuan.luo@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Duoming Zhou 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 (cherry picked from commit 2568a7e0832ee30b0a351016d03062ab4e0e0a3f) CVE-2022-3565 Signed-off-by: Yuxuan Luo --- 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);