From nobody Thu Dec 25 03:19:43 2025 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E1ED7A737 for ; Tue, 23 Jan 2024 02:07:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705975647; cv=none; b=TbNBSmn4PLPBD+2UBAdqu6QSc7bJlynq2qAFd+YvmvRn6Se9k58cpAPvn5fBiULkjMcwZ4Q4iUUmL478LYq0/Z65fobqZm1PVDSacHMVoJxM4lsYoAa4rXzhnlu5qUu/Iv9uBcopx5LPBcz5qoCwz1zgFUeuSDP1ZPHyp8gxVYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705975647; c=relaxed/simple; bh=i8XZbJ81fBFIDUQE1pTnGiBnGeAvnlapZf4vuAhH/i0=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Sx1SsrDhaHjMwvlbKveASJvI4gdhBqABNhgpJDsC5BDxc4jUAPTekNIR+ZzLnwMyDn61pWPUf0Q8JZZJA9n99qG4DXuFXtGM8oyZK65/m8zAxLfGeJXfn0toHPXeOnhEADRTQYIuTA6oXQXEiz0xThzKarrKLdqVe9MAPkniCzA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4TJr5m3ddyz1gxwK; Tue, 23 Jan 2024 10:05:32 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id 6D06A140416; Tue, 23 Jan 2024 10:07:15 +0800 (CST) Received: from huawei.com (10.67.189.167) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 23 Jan 2024 10:06:00 +0800 From: Jiangfeng Xiao To: , , , , , , CC: , , , , , Subject: [PING PATCH] powerpc/kasan: Fix addr error caused by page alignment Date: Tue, 23 Jan 2024 09:45:59 +0800 Message-ID: <1705974359-43790-1-git-send-email-xiaojiangfeng@huawei.com> X-Mailer: git-send-email 1.8.5.6 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500010.china.huawei.com (7.192.105.118) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In kasan_init_region, when k_start is not page aligned, at the begin of for loop, k_cur =3D k_start & PAGE_MASK is less than k_start, and then va =3D 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 =3D memblock_alloc(k_end - k_start, PAGE_SIZE); [...] for (k_cur =3D k_start & PAGE_MASK; k_cur < k_end; k_cur +=3D 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 =3D 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 --- 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_3= 2.c index a70828a..aa9aa11 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 s= ize) if (ret) return ret; =20 + k_start =3D k_start & PAGE_MASK; block =3D memblock_alloc(k_end - k_start, PAGE_SIZE); if (!block) return -ENOMEM; --=20 1.8.5.6