Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1588992imd; Sun, 4 Nov 2018 05:55:45 -0800 (PST) X-Google-Smtp-Source: AJdET5e7doZFO49167PZYK/L7XQA4GjnTl/dKJtftBQ5GJYvkQSaF/cJ2VyLq7UGQs8ksECnamIj X-Received: by 2002:a17:902:8b8c:: with SMTP id ay12-v6mr17833798plb.69.1541339745633; Sun, 04 Nov 2018 05:55:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541339745; cv=none; d=google.com; s=arc-20160816; b=hSJeHnZ1ke7dkTXOUxNUdq6VpzSjTjxIAzY2phkzmMXsDKGtMjpf3+E54Pm05eM0YM GHN/Txx8nck8CkHloXKAUN0zGR0Ymp2KaXrmE+t8zLPQ0/tguySzLSD5gMLm/CmH2c/R HF5R7zogNqHxgP+jD3bXbee7Cbb+sqMnEHOjNR+2V0/BquQRWqiE5fHV0e3qT1RzXO24 wewfGOLYP0vINn1lMczqYGIT8KN63wY7T+DjZOhd/Dydph+G13ToBVZ4ke9epn1jz+kO XG+JEGNuz+C/MDlTjVkXPJq7CInFbfQIZ56I4vu+HQEm+pr/o5rz3rseiRigk7xLDx7o sj7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=t7WMT4WZcJiChCd96yRXemVoM6prW+4NRfe7rjV50dY=; b=xIIwI/N+94MX6gO/tdfY1e80mMg1cd2AAnl4alf4mmXMsw/FsESCccAiiA2iqqdn9D pgXbfV9OT7rZT1sUwwuGsM++RUUNAm5OjqR0rwpPUbi0IoBINzX5SoWFoTM4YRLmABl4 5WDhJ7t1eqgMjD3S7SQEwaTAlWNsgJm5HGfTmS0oM25ap9YqWKad7bmPFqSLG2vO0rO8 9D/+g1P0mgGQqd53GBM61uYGlglHKkkSn7cBQpILX61xzlzTWyZw9bSCBYVw0i9uNyU4 KkYBkspVw2VBlJ9KxWaI+/2eIwJ0xKTun7pjIbC5OxI+sNkRPsJD6jmLJzZMd3Asgic/ hcgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ugvCKrJK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b31-v6si31401474plb.309.2018.11.04.05.55.30; Sun, 04 Nov 2018 05:55:45 -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=@kernel.org header.s=default header.b=ugvCKrJK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731257AbeKDXIn (ORCPT + 99 others); Sun, 4 Nov 2018 18:08:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:47668 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731227AbeKDXIm (ORCPT ); Sun, 4 Nov 2018 18:08:42 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F33642086B; Sun, 4 Nov 2018 13:53:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541339617; bh=JXP9n9QiEVUgR/bPL40dd/Iz3X384jhW5fL0T6UGHHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ugvCKrJKoKMjN3u1l7njym39dr9Zcksp3zV0oJPXEBgL28bzgg8172cB88RfcBn9t 2dlvGXMoWwVIOBUF2r/FNZWkeKMmHXtsgHiscuVF145v3J/6bqakyvhbXyBNXjjyiV QvjLuFG1psL9ftvksQclVtSVzKxZIHnpM3DcNVZM= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Daniel Axtens , Michael Ellerman , Sasha Levin Subject: [PATCH AUTOSEL 4.14 11/30] powerpc/nohash: fix undefined behaviour when testing page size support Date: Sun, 4 Nov 2018 08:53:06 -0500 Message-Id: <20181104135325.88524-11-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181104135325.88524-1-sashal@kernel.org> References: <20181104135325.88524-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Axtens [ Upstream commit f5e284803a7206d43e26f9ffcae5de9626d95e37 ] When enumerating page size definitions to check hardware support, we construct a constant which is (1U << (def->shift - 10)). However, the array of page size definitions is only initalised for various MMU_PAGE_* constants, so it contains a number of 0-initialised elements with def->shift == 0. This means we end up shifting by a very large number, which gives the following UBSan splat: ================================================================================ UBSAN: Undefined behaviour in /home/dja/dev/linux/linux/arch/powerpc/mm/tlb_nohash.c:506:21 shift exponent 4294967286 is too large for 32-bit type 'unsigned int' CPU: 0 PID: 0 Comm: swapper Not tainted 4.19.0-rc3-00045-ga604f927b012-dirty #6 Call Trace: [c00000000101bc20] [c000000000a13d54] .dump_stack+0xa8/0xec (unreliable) [c00000000101bcb0] [c0000000004f20a8] .ubsan_epilogue+0x18/0x64 [c00000000101bd30] [c0000000004f2b10] .__ubsan_handle_shift_out_of_bounds+0x110/0x1a4 [c00000000101be20] [c000000000d21760] .early_init_mmu+0x1b4/0x5a0 [c00000000101bf10] [c000000000d1ba28] .early_setup+0x100/0x130 [c00000000101bf90] [c000000000000528] start_here_multiplatform+0x68/0x80 ================================================================================ Fix this by first checking if the element exists (shift != 0) before constructing the constant. Signed-off-by: Daniel Axtens Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- arch/powerpc/mm/tlb_nohash.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/powerpc/mm/tlb_nohash.c b/arch/powerpc/mm/tlb_nohash.c index bfc4a0869609..2ae18e90e0ba 100644 --- a/arch/powerpc/mm/tlb_nohash.c +++ b/arch/powerpc/mm/tlb_nohash.c @@ -500,6 +500,9 @@ static void setup_page_sizes(void) for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) { struct mmu_psize_def *def = &mmu_psize_defs[psize]; + if (!def->shift) + continue; + if (tlb1ps & (1U << (def->shift - 10))) { def->flags |= MMU_PAGE_SIZE_DIRECT; -- 2.17.1