From patchwork Tue Jan 24 15:23:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuxuan Luo X-Patchwork-Id: 1731275 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=IaGl2MXG; 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 4P1W300PJkz23hW for ; Wed, 25 Jan 2023 02:23:54 +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 1pKL9E-0006Eh-Lm; Tue, 24 Jan 2023 15:23:44 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pKL9B-0006EJ-2h for kernel-team@lists.ubuntu.com; Tue, 24 Jan 2023 15:23:41 +0000 Received: from mail-ua1-f71.google.com (mail-ua1-f71.google.com [209.85.222.71]) (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-1.canonical.com (Postfix) with ESMTPS id D86B23F761 for ; Tue, 24 Jan 2023 15:23:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1674573820; bh=92jgNyRTSr3ohA3nDX5pCgDc5/8sfN+malysJ8lyEdo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IaGl2MXGdSZQV3b/E1ijaBXz29kwxV9sPLijqaW5FQUZPWiS23MNcR4+C1mhCmygh NSpGVQEIP2hNSgXRcjX3QXHNFlIeZsbPSX9TpR+dpO2BzqS/D9vIH6qcJDu45yaQT0 Pzo9NrY0Xzv2OCgTzGUR7+qln4pxsEomFCZTHDTaISu6UnAEkDMIDkga3NM96JincQ +L4Fq05sIWu0W656iHxVBWFjxcP6/5jJWvdpTyexVGKWGUdx40QFXhCqqsSQcFZlHy Ew1bz12rNpf3z57skmO4kgdosWN6B4XL2G1IZScm7bykw/d+PIQIkAZfm0PWIA4MgB nWBEvGikdrrHg== Received: by mail-ua1-f71.google.com with SMTP id o6-20020ab01506000000b004f8c11096a9so4477639uae.20 for ; Tue, 24 Jan 2023 07:23:40 -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=92jgNyRTSr3ohA3nDX5pCgDc5/8sfN+malysJ8lyEdo=; b=l8StfVBQzektfuH4fmVLwM9l7OeNNoJjmXYhopo8v7g+b3tz5u6A4wM9QSaG/1ugIO 1R8XeFZI/wFJ4PA86Meuz9Xu263v0wNdnaNPoYoHPcxKyBqrP6O8psbb2XWIdlQoWGZ3 701uAUmbPHUqPgKZU40h+bDzDTJrHKtcIXMpo2kAI9hKzMVCaLBtsWyV83nx1OCOfKfA SDCehivvWUXb2WTvKWXjshcusvcI7nIS1MD8wSGF2S3uIZb4iOkIycorchom5rPKN+bE IgFvxy/bkLwRTRVyA2OrQizxXvGjQLPeFfkTDjeTchCRzrJ8PgbeJragiNhmbNMFLFfO LxNw== X-Gm-Message-State: AFqh2krrwcBCQ6H2mz8fsgyN2PXbHi0tn/rB7koVYnvoDZfQjQBkosXB cZh9/cvj55KC1ypY456SM6iXFseJMV+PeYaOqCxTsEqbNhPHx/jpoXiIVBTKBd5/snVEeqXeTC7 Oh7pn3GcvZE4q2zYwMktRrPAFc3bnW3Ts4byJqK/VRg== X-Received: by 2002:a05:6122:10ee:b0:3bd:5f54:dd3e with SMTP id m14-20020a05612210ee00b003bd5f54dd3emr17138579vko.8.1674573819388; Tue, 24 Jan 2023 07:23:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXt9h3aQXbmM29fQfg6YtRIPsImnt9G1JbBXCWCFLXG0EBcpOYyK2pcb7rHzpkDGOBsFJwcg9Q== X-Received: by 2002:a05:6122:10ee:b0:3bd:5f54:dd3e with SMTP id m14-20020a05612210ee00b003bd5f54dd3emr17138560vko.8.1674573819009; Tue, 24 Jan 2023 07:23:39 -0800 (PST) Received: from cache-ubuntu.hsd1.nj.comcast.net ([2601:86:200:98b0:dd50:94ea:eb2e:ee4b]) by smtp.gmail.com with ESMTPSA id n207-20020a3740d8000000b00705e0ad29cdsm1564838qka.77.2023.01.24.07.23.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 07:23:37 -0800 (PST) From: Yuxuan Luo To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/1] mISDN: fix use-after-free bugs in l1oip timer handlers Date: Tue, 24 Jan 2023 10:23:34 -0500 Message-Id: <20230124152334.14842-2-yuxuan.luo@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230124152334.14842-1-yuxuan.luo@canonical.com> References: <20230124152334.14842-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 Acked-by: Tim Gardner --- 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 7ea10db20e3a6..48133d0228120 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 2c40412466e6f..a77195e378b7b 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);