Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp5304262ybf; Wed, 4 Mar 2020 21:57:04 -0800 (PST) X-Google-Smtp-Source: ADFU+vvmE6ZNQ6qVJdirJ8zZN39saPLryMZofQ32GvMtaFsyhS8ilui2LT0ApPLYZQnarIGFniwS X-Received: by 2002:aca:fd90:: with SMTP id b138mr4504195oii.73.1583387824310; Wed, 04 Mar 2020 21:57:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583387824; cv=none; d=google.com; s=arc-20160816; b=V5SU4VptQo0tYaR07Sm72p/ZAgsAr+LEaNzo/pJ0A4tK4NatuKnkvBlD/WOkP7zEPH ExEkzsC+FEpO4fYc8ps5ilVgyJ2A4nW2BeCLe3A/Q6PCBgdf+5YPgLaOr9NysVD353Jh EeG+FrM8SldOuPxUmK+hFlkJAvjNKlpQ9ZRuy/esf0/k9uqI+eLkv1ffQtPza8UVkUTk 0fpxzUV5Edjf33knTzdLEIvyAT4D+afX4Q2+wahgdVBIcIKYC3MA/fPvNmrseiVIzyBz Kmd2imRYVv8FBkSnn5iB/SITwNw95oJMmheh/K6yBC8hfDtlZe7AGRiq7zUMwcwM/wIx 0S2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=Z0UD98IxbqBaiuaVklCQ1qAh/kKOqkXFHSdToBuM/38=; b=aVqktLnOlwpD9fEjgQtnWWQsPJgqgyIm9iLigHCVbaQThgX0PCSBkq+G4Uar9SjHfK g93c25O3HAaKE988NQN+nsv1YTf+sj9Q9IvJqiBqxYc0tBaZWj+ZzwhSjUw45TuNp5OW 6aXbNiuD+jjEbgBmQtDHKto2p7IFA1m3RV5qCW4H33I9QxA5i8Xj3pEuuvVLd35AB9Dy O/X7fm4HL3pumBMqCAtnzJXxRpJ6xKzXUQwAtNB/gRm0OCYBJCajBwTRPCbSPYYYVJ0B B6PSnf8ZV3MHTSXysQ/bixPvq46sMpI7uMFZ2OGnLQD5ENaCJiVSPxwmz621r+aAs7yw QRvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=pHHIxu+p; 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 t24si2948157oth.319.2020.03.04.21.56.53; Wed, 04 Mar 2020 21:57:04 -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=pHHIxu+p; 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 S1725816AbgCEF4i (ORCPT + 99 others); Thu, 5 Mar 2020 00:56:38 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:7879 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725914AbgCEF4h (ORCPT ); Thu, 5 Mar 2020 00:56:37 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 48Y0PH23ZTz9v0xf; Thu, 5 Mar 2020 06:56:35 +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=pHHIxu+p; 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 s9KFcENT85ew; Thu, 5 Mar 2020 06:56:35 +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 48Y0PH10gQz9v0xd; Thu, 5 Mar 2020 06:56:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1583387795; bh=Z0UD98IxbqBaiuaVklCQ1qAh/kKOqkXFHSdToBuM/38=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=pHHIxu+p6SvLOjMUKls9TTSin3xoS1sPtQCZuJ4L/CLI/D1CXLNwziilL4+lUVp+4 +kwyRvveqFA+gSbY93TJ+tnn2zFr/2LrtMLwCrg6M04AHIz541APRxu1qEVWaPpmyu 7GeQOh1JY6nhCgcYuG3fHXhRcTCdKNAZoaAJvtN8= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 382908B790; Thu, 5 Mar 2020 06:56:35 +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 HWPfKwU2Yntd; Thu, 5 Mar 2020 06:56:35 +0100 (CET) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 7A8E18B756; Thu, 5 Mar 2020 06:56:33 +0100 (CET) Subject: Re: [PATCH -next] powerpc/mm/ptdump: fix an undefined behaviour To: Qian Cai , mpe@ellerman.id.au, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, rashmicy@gmail.com, linux-kernel@vger.kernel.org References: <20200305044759.1279-1-cai@lca.pw> From: Christophe Leroy Message-ID: <3b724167-6bd2-f281-c6ee-fcb39cb9e24b@c-s.fr> Date: Thu, 5 Mar 2020 06:56:30 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200305044759.1279-1-cai@lca.pw> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 05/03/2020 à 05:47, Qian Cai a écrit : > Booting a power9 server with hash MMU could trigger an undefined > behaviour because pud_offset(p4d, 0) will do, > > 0 >> (PAGE_SHIFT:16 + PTE_INDEX_SIZE:8 + H_PMD_INDEX_SIZE:10) > > UBSAN: shift-out-of-bounds in arch/powerpc/mm/ptdump/ptdump.c:282:15 > shift exponent 34 is too large for 32-bit type 'int' > CPU: 6 PID: 1 Comm: swapper/0 Not tainted 5.6.0-rc4-next-20200303+ #13 > Call Trace: > dump_stack+0xf4/0x164 (unreliable) > ubsan_epilogue+0x18/0x78 > __ubsan_handle_shift_out_of_bounds+0x160/0x21c > walk_pagetables+0x2cc/0x700 > walk_pud at arch/powerpc/mm/ptdump/ptdump.c:282 > (inlined by) walk_pagetables at arch/powerpc/mm/ptdump/ptdump.c:311 > ptdump_check_wx+0x8c/0xf0 > mark_rodata_ro+0x48/0x80 > kernel_init+0x74/0x194 > ret_from_kernel_thread+0x5c/0x74 > > Fixes: 8eb07b187000 ("powerpc/mm: Dump linux pagetables") > Signed-off-by: Qian Cai > --- > > Notes for maintainers: > > This is on the top of the linux-next commit "powerpc: add support for > folded p4d page tables" which is in the Andrew's tree. > > arch/powerpc/mm/ptdump/ptdump.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/powerpc/mm/ptdump/ptdump.c b/arch/powerpc/mm/ptdump/ptdump.c > index 9d6256b61df3..b530f81398a7 100644 > --- a/arch/powerpc/mm/ptdump/ptdump.c > +++ b/arch/powerpc/mm/ptdump/ptdump.c > @@ -279,7 +279,7 @@ static void walk_pmd(struct pg_state *st, pud_t *pud, unsigned long start) > > static void walk_pud(struct pg_state *st, p4d_t *p4d, unsigned long start) > { > - pud_t *pud = pud_offset(p4d, 0); > + pud_t *pud = pud_offset(p4d, 0UL); Is that the only place we have to do this ? (In 5.6-rc) I see the same in: /arch/powerpc/mm/ptdump/hashpagetable.c /arch/powerpc/kvm/book3s_64_mmu_radix.c Wouldn't it be better to: - Either cast addr to unsigned long in pud_index() macro - Or change pud_index() macro to a static inline function as x86 ? Christophe