From patchwork Tue Apr 23 20:47:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bethany Jamison X-Patchwork-Id: 1926774 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 4VPDhP5vYgz1yZP for ; Wed, 24 Apr 2024 06:47: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 1rzN2x-0005g0-4f; Tue, 23 Apr 2024 20:47:23 +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 1rzN2u-0005fR-Uv for kernel-team@lists.ubuntu.com; Tue, 23 Apr 2024 20:47:20 +0000 Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.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 B27083F2EA for ; Tue, 23 Apr 2024 20:47:20 +0000 (UTC) Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3c74e617dceso5690253b6e.1 for ; Tue, 23 Apr 2024 13:47:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713905239; x=1714510039; 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=O+Ohy4BuZAXOqpEM2FOSZXFIsnSI2Kp/3gkRAfbLQCtkYdY6BwgWbttR1TgFdUke9+ 13CAgOBRQHAu9qcxMV2KHKq6J4Q+cwY5UJEN6fj4aL13uLLv9suoGdJ+AKq7soKGmu9x wiT1upizg2CE5p2lPrxWZyrKHwzjDU8mVrQkzoO0WOSDTlhVupf06/nXUSVNZd6c88Oc OkTB9oXQSBtjuXjSguqOvgXU5rYEfMqskj/s88wd7oQo09veNNsw2aUKQHLNigYSxIcD iVPtYW8figajshI7vKqvsyLvSOjZNI5qv+s9wTFLRI10BhXnjCzQ/6o40DzamysttbDG toZg== X-Gm-Message-State: AOJu0YxSmQuY7Gx7DEc92LddgDYqQ7xCRNzSPhL+giFYR3D5y+T3NgTT FTk38jWjs+HIfe78E1CNS7ciWx9uLu/RbN6YVO5rDR2J4NoUiQBbVIWIEiAhgJjyTlz6e2VNyyZ Npfotjob7gBo8IGqy7M1W2K0VP9H6B+r44fnm7d8csvk8oMeK9oebXO4/bF5WbpNBJ2bOw+ZYDQ 6NDywIQjA9Bw== X-Received: by 2002:a05:6808:2d9:b0:3c8:3094:43ac with SMTP id a25-20020a05680802d900b003c8309443acmr476673oid.4.1713905239516; Tue, 23 Apr 2024 13:47:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFA6xvE98sX8VGsHmDt/Vlc0hUJi/xlqWYv0I/sJwS4daOkVLJX15nzM9zD5Q5yiuEMAup8hA== X-Received: by 2002:a05:6808:2d9:b0:3c8:3094:43ac with SMTP id a25-20020a05680802d900b003c8309443acmr476663oid.4.1713905239193; Tue, 23 Apr 2024 13:47:19 -0700 (PDT) Received: from smtp.gmail.com (72-46-51-119.lnk.ne.static.allophone.net. [72.46.51.119]) by smtp.gmail.com with ESMTPSA id p11-20020a0cf54b000000b0069b58f8c33dsm5536731qvm.45.2024.04.23.13.47.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 13:47:18 -0700 (PDT) From: Bethany Jamison To: kernel-team@lists.ubuntu.com Subject: [SRU][M][PATCH v2 1/1] powerpc/kasan: Fix addr error caused by page alignment Date: Tue, 23 Apr 2024 15:47:15 -0500 Message-Id: <20240423204716.27033-2-bethany.jamison@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240423204716.27033-1-bethany.jamison@canonical.com> References: <20240423204716.27033-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;