Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp860103pxb; Wed, 16 Feb 2022 06:04:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJwtUGvNCIOH8Ud6QLlIvntZHzVfMGGlmQFlX/ig9NnDztXlnSLRTnIN/XqQ9HEnteqjjXaC X-Received: by 2002:a63:da0d:0:b0:364:b771:ff4 with SMTP id c13-20020a63da0d000000b00364b7710ff4mr2459712pgh.514.1645020263169; Wed, 16 Feb 2022 06:04:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645020263; cv=none; d=google.com; s=arc-20160816; b=ipDyTXRqDvAcXuvG4zvibWmiIt+LfaoiFhDJob3uoQ4zVzFm0kA4KFgPAKAkYuYydL V7mATIME98y3qIQ8iGXlATrzNovD7gId/bDe+dNxU9yUaOs/guIWi6u+s1dJMDvnASap e6+peaNGDdInKtr8vI/tunzBcHptFSMHk8GbolkiPRGjqRoAPkKmdcj5ys6dzKe9sWlf 0nBcMU5J8HVrtiJlt2wWgibLb2O6qx+7tvKvoSWXAvf1ugFh6/AuNjWSDHAvWPwts6YN MbISQ3qP2S3RBMCrqQxi0eTG3qbow7zXzFFdt+KpjRxCFXp+1JgbnXbbcb+QEOLr/uTr EV9g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8kvyZmBBaLI4CEP62Kyq7fRmvMaM2/SHnFS7sWTyVco=; b=BVE72ol3oloLHbmXsIaZyRbCv5gUgfz+qt+iP4/Hbj6deMuzMJ1edmBn1chSZgWZ0O YhGMdHKFkuXAOIfLeQZCTULZwoqjnQ1rf3MMxO/DWemTvICpdX1nWOIzC8jD5xFZ6s34 xJibw1ol4nHW7uyNCNOhjvfAQAF7esAImDlY31ZstGIaozuRv+70c0AY2f3eJ1QvTH+r stIIbkMbKIHNHY1I6CSnRlDnFRCgvLtEOcVtluAvpjk/pgqOtTVTwV1UHVihf9jnse8a I/k4Xu4xq8Bmz64bBscn70Gg3wUK4KVsO3OJnxRkxFmYZMTfVzlqtmzYig4BsHwC2qAN imuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CHCgfRQJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mi7si6766104pjb.124.2022.02.16.06.03.58; Wed, 16 Feb 2022 06:04:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CHCgfRQJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S234160AbiBPNTh (ORCPT + 99 others); Wed, 16 Feb 2022 08:19:37 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:38132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234052AbiBPNSq (ORCPT ); Wed, 16 Feb 2022 08:18:46 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F24162AB520; Wed, 16 Feb 2022 05:18:07 -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 sin.source.kernel.org (Postfix) with ESMTPS id 60152CE26F2; Wed, 16 Feb 2022 13:18:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12440C340F0; Wed, 16 Feb 2022 13:17:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645017484; bh=VX4KkQyuIR3tQGDR6prM8ou6pbxkhf/vAdqGON90Cm0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CHCgfRQJGdosNV1evKFnaA5ei4xJAQnutJJPhJDJedQb8ubdZ/7Y4gbjZfBoHlpfu 02zUcTsVmwftwP3VFFw8cf1xplYfxud05Hq90fcOl+6pChvWJp2VuJGg6f1dhDmeKP 2Ku7d6y9bCG/B7QQIkLEQll/VqhOb3oxvRxpjL7bHiIP7fh7rr3NkfNXH+hMaXbIfa qHFBF3xOTCoSqLhRyub3LajzF4xQe4lV+XRk2zeVmUEYrZWjONVkWPfTimkvr5qUGC VogArIAmhrmBKTIWZOEA4fZwuT8tCTP8ztaTT853tTOy2yqxBDNJ8/RxehDqdkvFhY Yb158iS57sWQQ== From: Arnd Bergmann To: Linus Torvalds , Christoph Hellwig , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-api@vger.kernel.org, arnd@arndb.de, linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk Cc: linux@armlinux.org.uk, will@kernel.org, guoren@kernel.org, bcain@codeaurora.org, geert@linux-m68k.org, monstr@monstr.eu, tsbogend@alpha.franken.de, nickhu@andestech.com, green.hu@gmail.com, dinguyen@kernel.org, shorne@gmail.com, deller@gmx.de, mpe@ellerman.id.au, peterz@infradead.org, mingo@redhat.com, mark.rutland@arm.com, hca@linux.ibm.com, dalias@libc.org, davem@davemloft.net, richard@nod.at, x86@kernel.org, jcmvbkbc@gmail.com, ebiederm@xmission.com, akpm@linux-foundation.org, ardb@kernel.org, linux-alpha@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, openrisc@lists.librecores.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, linux-xtensa@linux-xtensa.org Subject: [PATCH v2 14/18] lib/test_lockup: fix kernel pointer check for separate address spaces Date: Wed, 16 Feb 2022 14:13:28 +0100 Message-Id: <20220216131332.1489939-15-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220216131332.1489939-1-arnd@kernel.org> References: <20220216131332.1489939-1-arnd@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnd Bergmann test_kernel_ptr() uses access_ok() to figure out if a given address points to user space instead of kernel space. However on architectures that set CONFIG_ALTERNATE_USER_ADDRESS_SPACE, a pointer can be valid for both, and the check always fails because access_ok() returns true. Make the check for user space pointers conditional on the type of address space layout. Signed-off-by: Arnd Bergmann --- lib/test_lockup.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/test_lockup.c b/lib/test_lockup.c index 6a0f329a794a..c3fd87d6c2dd 100644 --- a/lib/test_lockup.c +++ b/lib/test_lockup.c @@ -417,9 +417,14 @@ static bool test_kernel_ptr(unsigned long addr, int size) return false; /* should be at least readable kernel address */ - if (access_ok((void __user *)ptr, 1) || - access_ok((void __user *)ptr + size - 1, 1) || - get_kernel_nofault(buf, ptr) || + if (!IS_ENABLED(CONFIG_ALTERNATE_USER_ADDRESS_SPACE) && + (access_ok((void __user *)ptr, 1) || + access_ok((void __user *)ptr + size - 1, 1))) { + pr_err("user space ptr invalid in kernel: %#lx\n", addr); + return true; + } + + if (get_kernel_nofault(buf, ptr) || get_kernel_nofault(buf, ptr + size - 1)) { pr_err("invalid kernel ptr: %#lx\n", addr); return true; -- 2.29.2