From patchwork Mon Apr 22 17:07:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bethany Jamison X-Patchwork-Id: 1926256 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 4VNWsf1dRqz23pD for ; Tue, 23 Apr 2024 03:08:06 +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 1ryx8u-0003S2-Uo; Mon, 22 Apr 2024 17:07:48 +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 1ryx8s-0003RO-5n for kernel-team@lists.ubuntu.com; Mon, 22 Apr 2024 17:07:46 +0000 Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) (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 DCBEE3FB6C for ; Mon, 22 Apr 2024 17:07:45 +0000 (UTC) Received: by mail-io1-f69.google.com with SMTP id ca18e2360f4ac-7dadcd5da7eso83222039f.3 for ; Mon, 22 Apr 2024 10:07:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713805664; x=1714410464; 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=XYKNhgaGHtnAkWGAzXMzAeuJnK5uhnhoM+JSVr5daVs=; b=G+eQOMzt3Hn0n6PpQ3hNN9TqOIv4vLotQPexY78SweNWNG4QE5qbcckrZpHCyY451W 8MVDiKS14TNrqq6nTXperSD6YNU7dXcJAWJb3ijgdtQfn6lI3C4kXigivD/6v6m57LDB YZOUFSC2KYb7QRvAspxv2C1kz++nO3pOZbfJonaevGnt/dzOJK1bTG0J6mrFstQLROQI DN9jHggSzWFz0shYFr4LyxfA9SMUUSR3djJyN3mSokfttSNBb1mEfUaPk+HjP8QGX04f Fq0E0GDspXpuYsttCiuERe+rsumtZ1fe/mY1ZayLvVGcVPKv3UWe6Y2rFO39WvbB7IFW P9aA== X-Gm-Message-State: AOJu0Yyj6PxyrLARL8DuttM5n6wA2/EbHznMANpSCYhz3DzO0bOHA5yG TFd3T/ngbgVtCUC4jqciAUzkrH0ilZyqATG/lFIhHAoVbwCnq4W2uEmWgAHwW1JcgPLHFXaBxgm y07LS+Hbngy/Mz7ZwbvmzQ/uixxfIiKNkmsydhejN8pWLvhfwhiWl9UCEB2UaHBG+FRUqhQpkEW dJv+3iGyaJJw== X-Received: by 2002:a05:6e02:1b01:b0:36a:3848:1eb0 with SMTP id i1-20020a056e021b0100b0036a38481eb0mr12974794ilv.9.1713805664229; Mon, 22 Apr 2024 10:07:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgBqpRT9A1fkxIEdyOrc3Ly+5ke/6QR2CGVpQvKsakVpP229wSwjvDKRKhkF78uZZ2jThIZg== X-Received: by 2002:a05:6e02:1b01:b0:36a:3848:1eb0 with SMTP id i1-20020a056e021b0100b0036a38481eb0mr12974773ilv.9.1713805663938; Mon, 22 Apr 2024 10:07:43 -0700 (PDT) Received: from smtp.gmail.com (104-218-69-129.dynamic.lnk.ne.allofiber.net. [104.218.69.129]) by smtp.gmail.com with ESMTPSA id m9-20020a92c529000000b0036a38481ec1sm2193227ili.72.2024.04.22.10.07.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 10:07:43 -0700 (PDT) From: Bethany Jamison To: kernel-team@lists.ubuntu.com Subject: [SRU][M][PATCH 1/1] powerpc/kasan: Fix addr error caused by page alignment Date: Mon, 22 Apr 2024 12:07:41 -0500 Message-Id: <20240422170742.19770-2-bethany.jamison@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240422170742.19770-1-bethany.jamison@canonical.com> References: <20240422170742.19770-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: Jiangfeng Xiao [ Upstream commit 4a7aee96200ad281a5cc4cf5c7a2e2a49d2b97b0 ] In kasan_init_region, when k_start is not page aligned, at the begin of for loop, k_cur = k_start & PAGE_MASK is less than k_start, and then `va = block + k_cur - k_start` is less than block, the addr va is invalid, because the memory address space from va to block is not alloced by memblock_alloc, which will not be reserved by memblock_reserve later, it will be used by other places. As a result, memory overwriting occurs. for example: int __init __weak kasan_init_region(void *start, size_t size) { [...] /* if say block(dcd97000) k_start(feef7400) k_end(feeff3fe) */ block = memblock_alloc(k_end - k_start, PAGE_SIZE); [...] for (k_cur = k_start & PAGE_MASK; k_cur < k_end; k_cur += PAGE_SIZE) { /* at the begin of for loop * block(dcd97000) va(dcd96c00) k_cur(feef7000) k_start(feef7400) * va(dcd96c00) is less than block(dcd97000), va is invalid */ void *va = block + k_cur - k_start; [...] } [...] } Therefore, page alignment is performed on k_start before memblock_alloc() to ensure the validity of the VA address. Fixes: 663c0c9496a6 ("powerpc/kasan: Fix shadow area set up for modules.") Signed-off-by: Jiangfeng Xiao Signed-off-by: Michael Ellerman Link: https://msgid.link/1705974359-43790-1-git-send-email-xiaojiangfeng@huawei.com Signed-off-by: Sasha Levin (cherry picked from commit 0516c06b19dc64807c10e01bb99b552bdf2d7dbe linux-6.6.y) CVE-2024-26712 Signed-off-by: Bethany Jamison --- arch/powerpc/mm/kasan/init_32.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/powerpc/mm/kasan/init_32.c b/arch/powerpc/mm/kasan/init_32.c index a70828a6d9357..aa9aa11927b2f 100644 --- a/arch/powerpc/mm/kasan/init_32.c +++ b/arch/powerpc/mm/kasan/init_32.c @@ -64,6 +64,7 @@ int __init __weak kasan_init_region(void *start, size_t size) if (ret) return ret; + k_start = k_start & PAGE_MASK; block = memblock_alloc(k_end - k_start, PAGE_SIZE); if (!block) return -ENOMEM;