From patchwork Wed Nov 16 20:59:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuxuan Luo X-Patchwork-Id: 1704827 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=MJbN209J; 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 4NCFmc5Pzmz23mL for ; Thu, 17 Nov 2022 08:00:00 +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 1ovPVj-00088f-3K; Wed, 16 Nov 2022 20:59:55 +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 1ovPVh-00086o-Mu for kernel-team@lists.ubuntu.com; Wed, 16 Nov 2022 20:59:53 +0000 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (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 76CE23F0E1 for ; Wed, 16 Nov 2022 20:59:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1668632392; bh=Wlp35Hm39+8Uvx19OlfM2Ivj+x7ymWIQmLgjPPHn/IQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MJbN209J38bmh4EdLJc6iGMcd9qD+GP4ShIU84j96OAZ/WMcbnxv6zC5aztBq5pQk HRZ70EJvSX5CA3zQ7gclKntpXr23QFncB0wu7Y/TuOqX4ZGSFkDAsI4nbMTKRkwZ2V b1s6rNEL1GXkSWwjlTPi0ZcRp0xa1aTgEKXuVcrnebPS/26WeNr/wI+aLolgux5PCE SMF7MTq8ecst8ASvjjYNbDBZYuzZUFiIMD6cogw5dgDMiFaw9J3Uh0QphqthaebX8v ZqN8qCICW/1B3xaLGFgM5N8OLa9tnwUhxCDQxmMAOy1gxwv1zGF11xUVXIoMVnzzfS /RdIROFmQ2VAA== Received: by mail-qt1-f200.google.com with SMTP id cj6-20020a05622a258600b003a519d02f59so13968059qtb.5 for ; Wed, 16 Nov 2022 12:59:52 -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=Wlp35Hm39+8Uvx19OlfM2Ivj+x7ymWIQmLgjPPHn/IQ=; b=yMUGxDYV/J+6HHFFjU63/7VWTREyJzrdD3vcuQ6w9f/DZcEjaeXXsxIxFUTredXXN+ V27w5FWlNTD8XCh7aGHhggdyx5NX0Ux9PtqH9a9YiFppblxYOqWXyiagR3SQ9utJSv3x 7AjlKcA+Qv/J9zAIVgcjhUFlG/jmootE1hnrqxZiQNMOO7FVRG+l1jaZ2FLrHAGEyBvH SgdVXCkeuQc+ZlsvdqkmiJ2mVk2stfF89UMdaep85KE4HVgxcaf3wpsrnLkVTptGjrhO d0maBbIW3nBj0rXPPOdVx4FVGxtO8dnGdLhaz/wVE30EnYjOv5TMneNH5isQAXQqUMkf f29A== X-Gm-Message-State: ANoB5pmHkaWwby5e+hgKhb6Lhsn3FdJO6eff+4UshV58Sti9tf7iHzMB 18daf0wW/5VeghCHy7F+AURyGNle8rALTZ6bwbJBgp89p0GyaVSbAf5/ZLdA1RBD5m+zYifNF8N raIvJmwjAK7LcbcePmmV9Ef9cYQR2ZlK2EVGkT4AxRg== X-Received: by 2002:ac8:4a09:0:b0:3a5:40ac:598 with SMTP id x9-20020ac84a09000000b003a540ac0598mr22397476qtq.606.1668632390651; Wed, 16 Nov 2022 12:59:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf60qNSYXGMUPxhtWDdq0gvHW+Pl4VGsV8/4yVjOOFjCoiSX4mJ1mx4wzjf0t2ZEt6hdRUiNYA== X-Received: by 2002:ac8:4a09:0:b0:3a5:40ac:598 with SMTP id x9-20020ac84a09000000b003a540ac0598mr22397463qtq.606.1668632390408; Wed, 16 Nov 2022 12:59:50 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Nov 2022 12:59:49 -0800 (PST) From: Yuxuan Luo To: kernel-team@lists.ubuntu.com Subject: [SRU][F][PATCH] mISDN: fix use-after-free bugs in l1oip timer handlers Date: Wed, 16 Nov 2022 15:59:39 -0500 Message-Id: <20221116205940.20586-3-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 b57dcb834594..aec4f2a69c3b 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);