From patchwork Mon Jul 8 15:38:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bethany Jamison X-Patchwork-Id: 1958015 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 4WHpDm4z0Qz1xrJ for ; Tue, 9 Jul 2024 01:38:32 +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 1sQqRK-0004JG-KS; Mon, 08 Jul 2024 15:38:06 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1sQqRH-0004Il-RP for kernel-team@lists.ubuntu.com; Mon, 08 Jul 2024 15:38:03 +0000 Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.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 8A2E33F63C for ; Mon, 8 Jul 2024 15:38:03 +0000 (UTC) Received: by mail-io1-f71.google.com with SMTP id ca18e2360f4ac-7f8f8538036so244452339f.1 for ; Mon, 08 Jul 2024 08:38:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720453082; x=1721057882; 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=psMmWZ0ytgAfMe1MMgSlZXjqN5pHCAQglnR/MrtO0gY=; b=xJK8MwcTKUHv7QsdtM49NvO7I6LNHj27cj11am/xUw4DCL1vEL8LKR9GHid8PNCqZ1 saiCgqWCM8kVsyazJsGJ3oQjx82aiZf7cpiZl1Q/bbU/cTLjQKtvy75LH8SVPqsPWZjD 2UAzhxQduWlIU1w1y2gNWwwJVuoFLEN4UjwuaPznB7b73Jd2HdBt7XIcb8bMsk8m1/ZS jZgKPmJuPoUG8zWH5gwi/k8enP3MatVpmw1ZHHlyRuxoQs5iuc6T11m6+PpWTgYUxlx3 Lb9qzlDSV+RbcecaasfvPEgCI0HM8hHg7RbGhNMOH6G+cYIn6R0l8bMqEcgp2n3qpVoG gSgQ== X-Gm-Message-State: AOJu0YyewJKGD7cjQ3xDcYjxQgfnLJ21xwcZayMqKCjQ6axpH5/5LJ7s Z4P3rsIvLE54WBMfTE4j8CEYGEQhce2knJ/GOkJJZJxVMp74N0T5hGUrkqIt3tkGZgOFiqEXgWI jyabdXnKeTRLraXIFDbIWpgjP+uuxGd6QO4F5OhBrpyxLLI1pASbvSX2t+uo0cFib9CQOlTplrj XKaP5w1DMaww== X-Received: by 2002:a05:6602:184f:b0:7f9:59af:c26b with SMTP id ca18e2360f4ac-7f959afc527mr676970339f.17.1720453082284; Mon, 08 Jul 2024 08:38:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEUevhRY9WBazWCCvtgeqTt8aMvQISZYDhI/2Q5GAoQKdhmITeM/mnw4D8ZFEGMe2EqDS3YUg== X-Received: by 2002:a05:6602:184f:b0:7f9:59af:c26b with SMTP id ca18e2360f4ac-7f959afc527mr676968639f.17.1720453081973; Mon, 08 Jul 2024 08:38:01 -0700 (PDT) Received: from smtp.gmail.com (167-248-51-36.oa02.lnk04.ne.dynamic.allophone.net. [167.248.51.36]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-7ffecec668dsm1784939f.36.2024.07.08.08.38.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jul 2024 08:38:01 -0700 (PDT) From: Bethany Jamison To: kernel-team@lists.ubuntu.com Subject: [SRU][J/F][PATCH 1/1] sh: push-switch: Reorder cleanup operations to avoid use-after-free bug Date: Mon, 8 Jul 2024 10:38:00 -0500 Message-Id: <20240708153800.16332-2-bethany.jamison@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240708153800.16332-1-bethany.jamison@canonical.com> References: <20240708153800.16332-1-bethany.jamison@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 original code puts flush_work() before timer_shutdown_sync() in switch_drv_remove(). Although we use flush_work() to stop the worker, it could be rescheduled in switch_timer(). As a result, a use-after-free bug can occur. The details are shown below: (cpu 0) | (cpu 1) switch_drv_remove() | flush_work() | ... | switch_timer // timer | schedule_work(&psw->work) timer_shutdown_sync() | ... | switch_work_handler // worker kfree(psw) // free | | psw->state = 0 // use This patch puts timer_shutdown_sync() before flush_work() to mitigate the bugs. As a result, the worker and timer will be stopped safely before the deallocate operations. Fixes: 9f5e8eee5cfe ("sh: generic push-switch framework.") Signed-off-by: Duoming Zhou Reviewed-by: Geert Uytterhoeven Reviewed-by: John Paul Adrian Glaubitz Link: https://lore.kernel.org/r/20230802033737.9738-1-duoming@zju.edu.cn Signed-off-by: John Paul Adrian Glaubitz (backported from commit 246f80a0b17f8f582b2c0996db02998239057c65) [bjamison: made fix change manually as I can't modify the neighboring line to fix the context conflict, I can't change del_timer_sync to timer_shutdown_sync - 292a089d7 treewide: Convert del_timer*() to timer_shutdown*()] CVE-2023-52629 Signed-off-by: Bethany Jamison --- arch/sh/drivers/push-switch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/sh/drivers/push-switch.c b/arch/sh/drivers/push-switch.c index 2813140fd92bb..c3e8feedfe372 100644 --- a/arch/sh/drivers/push-switch.c +++ b/arch/sh/drivers/push-switch.c @@ -101,8 +101,8 @@ static int switch_drv_remove(struct platform_device *pdev) device_remove_file(&pdev->dev, &dev_attr_switch); platform_set_drvdata(pdev, NULL); - flush_work(&psw->work); del_timer_sync(&psw->debounce); + flush_work(&psw->work); free_irq(irq, pdev); kfree(psw);