From patchwork Tue Sep 10 01:44:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 1982888 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=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (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 4X2mj82hTqz1y1v for ; Tue, 10 Sep 2024 11:44:44 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1snpvp-0000BN-K0; Tue, 10 Sep 2024 01:44:37 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1snpvn-00009a-TA for kernel-team@lists.ubuntu.com; Tue, 10 Sep 2024 01:44:35 +0000 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.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-0.canonical.com (Postfix) with ESMTPS id EBABA3F5B8 for ; Tue, 10 Sep 2024 01:44:33 +0000 (UTC) Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-2d9a2b8af50so5185887a91.0 for ; Mon, 09 Sep 2024 18:44:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725932672; x=1726537472; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vJoOyAnARygsMWxh17YuH59Hn/bS1IZCZ70Jhb09/ws=; b=HR2GTlDT6jczFWIgEPkS2XHOIwniABK7QJfA0Imip9sJAwhN7BLjDZu0Uo6/ynzlxh zpkEXJqPAoKEa6zMQiXM3cXVo7+QjRIvNc3yg7YHf8eb3/yfOMrKEAYxfUhyMfkgbeKT XoYSh8OqJGhnxWwNYFbr39RZjGyMM7AjXg97ec0QAaQcK3BPrkvwnahAIjhRfUScrLO8 +32nlhMBkJBQ/7f/K1v33tdzHbLIedmygJT9C6gNQtM5nIaneFS0+e0F4lKcITayBIF5 g4XfokYCnMvve1XKc7kmRBbi0cRgz7JTjs0QiWRLhZo/Hy4Jvaq4bW2xaf/6J60gg+Hd KYKQ== X-Gm-Message-State: AOJu0YwFJb7PLHzHUSgH+j3R9fdtH4BvMBLCKRDNg2wjmW1viM8sbaBs 6mQdpK8sod/DfrebsrHK0qca1Cknduf46lnhbNpriizYX51kruykWD9FOW7jP5DJaqMPCglZrpJ DX9lGzvSdXpKW8TAdEb4dmkScaoapINJRgGIEWqudVIxxWoHpgsS9w2DbPjONPPcAn7dyupsdzN tnBEreijIqSw== X-Received: by 2002:a17:90b:3d89:b0:2cf:2bf6:b030 with SMTP id 98e67ed59e1d1-2dad51348b6mr7889752a91.33.1725932672369; Mon, 09 Sep 2024 18:44:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGX8+R86ioMTuAthKl87XS/KrDjZQHRu2rhrXcHiqWTXOT8iwJQ3+eG3an03w33h/d5lBz9jA== X-Received: by 2002:a17:90b:3d89:b0:2cf:2bf6:b030 with SMTP id 98e67ed59e1d1-2dad51348b6mr7889738a91.33.1725932671954; Mon, 09 Sep 2024 18:44:31 -0700 (PDT) Received: from localhost.localdomain ([240f:74:7be:1:959:86f5:52c1:2a4c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2dadbfe471asm7371780a91.9.2024.09.09.18.44.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 18:44:31 -0700 (PDT) From: Koichiro Den To: kernel-team@lists.ubuntu.com Subject: [SRU][F][PATCH 1/1] watchdog: cpu5wdt.c: Fix use-after-free bug caused by cpu5wdt_trigger Date: Tue, 10 Sep 2024 10:44:04 +0900 Message-ID: <20240910014409.1052185-2-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240910014409.1052185-1-koichiro.den@canonical.com> References: <20240910014409.1052185-1-koichiro.den@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 When the cpu5wdt module is removing, the origin code uses del_timer() to de-activate the timer. If the timer handler is running, del_timer() could not stop it and will return directly. If the port region is released by release_region() and then the timer handler cpu5wdt_trigger() calls outb() to write into the region that is released, the use-after-free bug will happen. Change del_timer() to timer_shutdown_sync() in order that the timer handler could be finished before the port region is released. Fixes: e09d9c3e9f85 ("watchdog: cpu5wdt.c: add missing del_timer call") Signed-off-by: Duoming Zhou Reviewed-by: Guenter Roeck Link: https://lore.kernel.org/r/20240324140444.119584-1-duoming@zju.edu.cn Signed-off-by: Guenter Roeck Signed-off-by: Wim Van Sebroeck (backported from commit 573601521277119f2e2ba5f28ae6e87fc594f4d4) [koichiroden: Adjusted context due to lack of timer_shutdown_sync(), which was introduced on upstream in the following patch series: [patch V3 00/17] timers: Provide timer_shutdown[_sync]() https://lore.kernel.org/all/20221123201306.823305113@linutronix.de/ Note that part of it was pulled in via stable upstream patches] CVE-2024-38630 Signed-off-by: Koichiro Den --- drivers/watchdog/cpu5wdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/watchdog/cpu5wdt.c b/drivers/watchdog/cpu5wdt.c index d6d53014cb68..02dd22114437 100644 --- a/drivers/watchdog/cpu5wdt.c +++ b/drivers/watchdog/cpu5wdt.c @@ -251,7 +251,7 @@ static void cpu5wdt_exit(void) if (cpu5wdt_device.queue) { cpu5wdt_device.queue = 0; wait_for_completion(&cpu5wdt_device.stop); - del_timer(&cpu5wdt_device.timer); + timer_delete_sync(&cpu5wdt_device.timer); } misc_deregister(&cpu5wdt_misc);