Received: by 2002:a17:90a:9307:0:0:0:0 with SMTP id p7csp2839187pjo; Mon, 16 Mar 2020 05:40:47 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvxHGb5XdWWrybq/ttinmZxfSOtqzf+V8nwiEL/NYil71kBySTNVfkhc1HCwqSfXUhsfGRH X-Received: by 2002:aca:646:: with SMTP id 67mr14774304oig.4.1584362446946; Mon, 16 Mar 2020 05:40:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584362446; cv=none; d=google.com; s=arc-20160816; b=VPsj7JFgLYPD6H6qADaKDet71f2EeQsbHyzyaMRKyRngeVP3tSP+ymo0ceDuIPM3rz uNpsmy2poFrcXocnGNaktr/fECJRR1FI5vzd+/TcZXgRfyh/yxQm25gslwWsg5uI6jyh pN3iHA8YOFgQkpJOvQVNggsX0q6ngrIE45f5GihbQb0c1O9LIur6zwdtFU3JuVBRPuBX MLqzG3/ApTl1NytkitPzUMK+6OIJwaKzdkBkoQCBpbCWOeh8IMcHAT6Y9BBTE7AiNUEP R+cGS3T9+bDtCurjbwDpd9BGPjIX8L4Dd9HkX7tptWiHhqGNChM8gFvshd1QO+FCdBFJ ZdIQ== 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:references :in-reply-to:message-id:dkim-signature; bh=4O+JQAaxWU7vz/WlcBgddWLwVTeB5N/VcA1T6OcpC/o=; b=QSlF895qz86SE/r3qcI5aKgkcQgGhOC69QANDNylnizfxKDEAyl904DI4+AO5X33pz PzlybDBk8xGRmwwyNWxhLxgFT7O8/BNvtZ0/2sZqIqlrkCBYeRtU94hkE4ZDdE5KjhXk LoS8qfmNHHr8FUlJHVsLzb6UKmf7MC7BI53f75cd2JqrFKjPM6TthC4sTPbSqQt9OmZa ONLuP1oBHt4lo96WFENPCP+xZMo7oZs0NGleT7BhdIS69R/R/TirMZgNIgSQyf8wmwJ2 koSoDQWRJXALqTDjz9xIgrsAcoeR70zWlbRRsjS/MyN3KeFxgtbuDjMSeH/KNw9Aaw7e n2ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=XyjcltoI; 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 k1si4846321otr.52.2020.03.16.05.40.33; Mon, 16 Mar 2020 05:40:46 -0700 (PDT) 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=XyjcltoI; 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 S1731365AbgCPMiV (ORCPT + 99 others); Mon, 16 Mar 2020 08:38:21 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:52652 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731032AbgCPMfs (ORCPT ); Mon, 16 Mar 2020 08:35:48 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 48gwkk28YLz9tygN; Mon, 16 Mar 2020 13:35:42 +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=XyjcltoI; 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 yeYpyMC2g6FZ; Mon, 16 Mar 2020 13:35:42 +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 48gwkk13Ngz9tygM; Mon, 16 Mar 2020 13:35:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1584362142; bh=4O+JQAaxWU7vz/WlcBgddWLwVTeB5N/VcA1T6OcpC/o=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=XyjcltoIlya8jWgzlRPPbHh65HKWmJqKCkmrmOBRsuqaqOaE6Qwe51K7RXwu9Vlyf rFC06x/0ezzqEz2aDl5jaWPBPZWPLeKJZ+nniTT8HwjKtv4GS16RhsQFIp58p9gzQb IHeVdeeMm6NQ+JTjZDDfRh4k/MPwQNpWwIypywyk= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 21D528B7D0; Mon, 16 Mar 2020 13:35:47 +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 44S8FnZQyNMR; Mon, 16 Mar 2020 13:35:47 +0100 (CET) Received: from pc16570vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.230.100]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 04CF38B7CB; Mon, 16 Mar 2020 13:35:47 +0100 (CET) Received: by pc16570vm.idsi0.si.c-s.fr (Postfix, from userid 0) id F18AD65595; Mon, 16 Mar 2020 12:35:46 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v1 02/46] 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: Mon, 16 Mar 2020 12:35:46 +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 750a927839d7..60c2acdf73a7 100644 --- a/arch/powerpc/mm/kasan/kasan_init_32.c +++ b/arch/powerpc/mm/kasan/kasan_init_32.c @@ -76,15 +76,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_ptr_k(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