Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3702459pxb; Mon, 24 Jan 2022 15:48:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwyYbyhMRREswQImtUrIwUNeTAQgyhUoJ0g1v1vPuLVpiugoOAVUg79E0aEgYt0tZNdH+wk X-Received: by 2002:a17:90a:e64e:: with SMTP id ep14mr636476pjb.111.1643068115407; Mon, 24 Jan 2022 15:48:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643068115; cv=none; d=google.com; s=arc-20160816; b=qh4k/TP4r9nq8bTYx0jRZ7QB9DpYphmjWDgoMlx5y7DroauZQnmQaqCmHbVfjKI25z UizJjd2eB9K//NY/pjC6Mb3tGfV10FkbW9f2u0trzD5aslHZjOpP4LI7Y4wD8qvdcex7 qKQTck1Iirc6C05reIQT+pTFTGSY8h5/TTxay9JE/EiiIYHdPV7K+u+lTOHte+fnd1fw 9w+FfvuxTDkUJ7XVQhfkn2MWyxF+t+SQPC0BzfEjPw4z0DtiBER8/QrxCW+IwXrQECZZ AgODx8rknEJCDsFDstmUbXDUJPvyZnU4AaNnFBQjGgSY/frtQQdlADhYq9FZuAVRb66m JPZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UkGfza0Al4kzjyuReJUCzUxxRtDqvRAHlHBM1Gak0uU=; b=YxH+uXHpshQEmd/rq4Dp+d5ymUPWMmQIDu/UdjrHWe6+rKb6UA5s++9Ck7XR06uUmp 74PxDbV0i8KH4LbFMtOW8xW2GpG+J1Sn3BPrQ9jkApMTquZPhpz5eWB6NlcyJarzQ6i9 CRPUQCwefvYutaZrY/SQJ+omDr5jOpq45hte+uPH1FFzcd0hp0DLqj7xRRzJy7JQGz4N lYBQqq+efAtGHdzMEKKvC1OXDMI8sFeWtzVElDIJLvfc2wa5n8SwKsv3fAoqCeyJNFVT vu4vd5X5N7nLIHWcHOHqHrREL4t5QC+lMCsGoK3fk5CJtjyBx1vW7H6poLbeoVbXsn52 J59w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XRf+eJZ8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c10si14731290plg.392.2022.01.24.15.48.22; Mon, 24 Jan 2022 15:48:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XRf+eJZ8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2362474AbiAXXmZ (ORCPT + 99 others); Mon, 24 Jan 2022 18:42:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1843544AbiAXXEH (ORCPT ); Mon, 24 Jan 2022 18:04:07 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B151BC06E00C; Mon, 24 Jan 2022 13:16:20 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5111961484; Mon, 24 Jan 2022 21:16:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15D49C340E4; Mon, 24 Jan 2022 21:16:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058979; bh=th4VKO5Ug+nK9IqtFEODJ6OwStYjXRjMQK8H8lx4WDQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XRf+eJZ8fzzgxjOrp1CHCVDxxSG8cz+oeEE8FrYRm+bs0ECGbHxD6FtHLljSz0Sgu hbDBadwn6dBpIjchdsvmujIq4cUN7O+le8DjqI9dyMJwuVL9pjWFL9tBeJR52UXCr6 qxYOJBHQOhEmmzzrKWj0oncOuqw0ExMDYrYZeD9Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Erhard Furtner , Christophe Leroy , Michael Ellerman , Sasha Levin Subject: [PATCH 5.16 0464/1039] powerpc/32s: Fix shift-out-of-bounds in KASAN init Date: Mon, 24 Jan 2022 19:37:33 +0100 Message-Id: <20220124184140.875034720@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christophe Leroy [ Upstream commit af11dee4361b3519981fa04d014873f9d9edd6ac ] ================================================================================ UBSAN: shift-out-of-bounds in arch/powerpc/mm/kasan/book3s_32.c:22:23 shift exponent -1 is negative CPU: 0 PID: 0 Comm: swapper Not tainted 5.15.5-gentoo-PowerMacG4 #9 Call Trace: [c214be60] [c0ba0048] dump_stack_lvl+0x80/0xb0 (unreliable) [c214be80] [c0b99288] ubsan_epilogue+0x10/0x5c [c214be90] [c0b98fe0] __ubsan_handle_shift_out_of_bounds+0x94/0x138 [c214bf00] [c1c0f010] kasan_init_region+0xd8/0x26c [c214bf30] [c1c0ed84] kasan_init+0xc0/0x198 [c214bf70] [c1c08024] setup_arch+0x18/0x54c [c214bfc0] [c1c037f0] start_kernel+0x90/0x33c [c214bff0] [00003610] 0x3610 ================================================================================ This happens when the directly mapped memory is a power of 2. Fix it by checking the shift and set the result to 0 when shift is -1 Fixes: 7974c4732642 ("powerpc/32s: Implement dedicated kasan_init_region()") Reported-by: Erhard Furtner Signed-off-by: Christophe Leroy Signed-off-by: Michael Ellerman Link: https://bugzilla.kernel.org/show_bug.cgi?id=215169 Link: https://lore.kernel.org/r/15cbc3439d4ad988b225e2119ec99502a5cc6ad3.1638261744.git.christophe.leroy@csgroup.eu Signed-off-by: Sasha Levin --- arch/powerpc/mm/kasan/book3s_32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/mm/kasan/book3s_32.c b/arch/powerpc/mm/kasan/book3s_32.c index 202bd260a0095..35b287b0a8da4 100644 --- a/arch/powerpc/mm/kasan/book3s_32.c +++ b/arch/powerpc/mm/kasan/book3s_32.c @@ -19,7 +19,8 @@ int __init kasan_init_region(void *start, size_t size) block = memblock_alloc(k_size, k_size_base); if (block && k_size_base >= SZ_128K && k_start == ALIGN(k_start, k_size_base)) { - int k_size_more = 1 << (ffs(k_size - k_size_base) - 1); + int shift = ffs(k_size - k_size_base); + int k_size_more = shift ? 1 << (shift - 1) : 0; setbat(-1, k_start, __pa(block), k_size_base, PAGE_KERNEL); if (k_size_more >= SZ_128K) -- 2.34.1