Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp708663ybv; Wed, 19 Feb 2020 07:40:50 -0800 (PST) X-Google-Smtp-Source: APXvYqxrYZafWOltuuxU0Acz6Zovt/JdFgK6RlEC1N7ohsmOp4RJWTh1IlEO58UwgwEaV485D2c0 X-Received: by 2002:aca:be09:: with SMTP id o9mr5134899oif.177.1582126850078; Wed, 19 Feb 2020 07:40:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582126850; cv=none; d=google.com; s=arc-20160816; b=FYvD0T9lqSyFWQx3jNYvK0Glsq5QKmw2BVpQmUuV+8EdChwNWcRytNNInDgDfnNA+5 6KR03BXkw1G55aHAmkRJ0K/3tP1dAOEgMq6AevAZ9RQiRlvd/LUBZZkb0EC2Y2xaGf0H eySh6NZKQY6qzG239bu/pdNQV0ex5re2FfT+INk54zlvAXWVXqfjoHBbjP7m7L992unO BDtmx3Sc8YXjmY+IzZxs/FkvInOqorIWsjsqPYKb+gVuTLopFPizulIdYB5DGnrkV84i ZZ/hahLJkD3v7fwln/nnsGw1ASxEK7/3jk1sydFa0IBKM6W6D3/yrGbR56gYKP9IZdTL NWzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:message-id :dkim-signature; bh=eUO+h2tmIsZDDPRpWTpjttyrkmWIQuxStTtECWph288=; b=AQg/mHb3aFK3MPZMZSRPhl5GpIXEnPv7CYqOCOsJPGiwPog1AlIKyVi4OKuGDfyfTs PgqLDX0Bs61Q5/ud3NGL0H2C4z/BUJe3N5QcRcHxKb8V06O181qIyv2wvlkXVzxF9W6O 9SLby2ZfQm4AqNjZcwmxXlmW7WFsfUXCL5k2X4HFAfCaEl42untRxucN7eg46d18XzzK OpCeS1eX3yN+YauuZYAs5CJZ3qQ25AO477p7/tGwrRoJB7L8TPvcuXoiyHCnhjs29o8E H20Dp0PQXXuhOIsJfk+YSSzi5QMgLUJRxWq070sfrQRIBkWmtxz4AyDH5KC5Zww3KyLH gTCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=Ec5DVi3J; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q25si13174otg.128.2020.02.19.07.40.37; Wed, 19 Feb 2020 07:40:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=Ec5DVi3J; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726604AbgBSPjJ (ORCPT + 99 others); Wed, 19 Feb 2020 10:39:09 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:31953 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726450AbgBSPjI (ORCPT ); Wed, 19 Feb 2020 10:39:08 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 48N22L0vM1z9tyQp; Wed, 19 Feb 2020 16:39:06 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=Ec5DVi3J; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id F7NQYazWhv04; Wed, 19 Feb 2020 16:39:06 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 48N22K6W0Cz9tyQn; Wed, 19 Feb 2020 16:39:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1582126745; bh=eUO+h2tmIsZDDPRpWTpjttyrkmWIQuxStTtECWph288=; h=From:Subject:To:Cc:Date:From; b=Ec5DVi3JadiopR9ptMYYwNvb7+TvwNVut6VS5PDM6hLkkH8c1+XfDiFM79VYOflYw 5DWwyFzzoVH4LzaGKaQTEkgjOF4l48dOZeBBH0stalXo8GfHn4W1YYdcURqW8JekM/ WRVOD7gmnregRqGO3ZXoUJjliC8yD7wny8YKnihA= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 70EC68B856; Wed, 19 Feb 2020 16:39:07 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id AOFhe5s48LHn; Wed, 19 Feb 2020 16:39:07 +0100 (CET) Received: from pc16570vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.230.102]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 206D38B85E; Wed, 19 Feb 2020 16:39:07 +0100 (CET) Received: by pc16570vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 13CBC6532A; Wed, 19 Feb 2020 15:39:07 +0000 (UTC) Message-Id: From: Christophe Leroy Subject: [PATCH] powerpc/kasan: Fix error detection on memory allocation To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Wed, 19 Feb 2020 15:39:07 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In case (k_start & PAGE_MASK) doesn't equal (kstart), 'va' will never be NULL allthough 'block' is NULL Check the return of memblock_alloc() directly instead of the resulting address in the loop. Fixes: 509cd3f2b473 ("powerpc/32: Simplify KASAN init") Signed-off-by: Christophe Leroy --- arch/powerpc/mm/kasan/kasan_init_32.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/mm/kasan/kasan_init_32.c b/arch/powerpc/mm/kasan/kasan_init_32.c index b533e7a8319d..e998c3576ae1 100644 --- a/arch/powerpc/mm/kasan/kasan_init_32.c +++ b/arch/powerpc/mm/kasan/kasan_init_32.c @@ -78,15 +78,14 @@ static int __init kasan_init_region(void *start, size_t size) return ret; block = memblock_alloc(k_end - k_start, PAGE_SIZE); + if (!block) + return -ENOMEM; for (k_cur = k_start & PAGE_MASK; k_cur < k_end; k_cur += PAGE_SIZE) { pmd_t *pmd = pmd_offset(pud_offset(pgd_offset_k(k_cur), k_cur), k_cur); void *va = block + k_cur - k_start; pte_t pte = pfn_pte(PHYS_PFN(__pa(va)), PAGE_KERNEL); - if (!va) - return -ENOMEM; - __set_pte_at(&init_mm, k_cur, pte_offset_kernel(pmd, k_cur), pte, 0); } flush_tlb_kernel_range(k_start, k_end); -- 2.25.0