Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp938204pxb; Wed, 6 Apr 2022 04:51:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz64XUMrJjWQVLQ8aOtpsepG/jMgkpCgdrRtbMWgdaTU5GxPwr4SAQmVG8isAz3F2DPLsvN X-Received: by 2002:a63:1d0d:0:b0:382:5f9c:9391 with SMTP id d13-20020a631d0d000000b003825f9c9391mr6917214pgd.617.1649245861961; Wed, 06 Apr 2022 04:51:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649245861; cv=none; d=google.com; s=arc-20160816; b=kEdVJ705bqMtHgMNxO3Im2sUVqxmFCnx/MxCJ3dwVZJC9LxU5VaEggdTvhk9qd0K6q OFeTnql53Jig2rWyIg8zdVqzHsuW2s3kM4qKpCBB2sYz0tem/mS5l77aRz6Fqsusx24I FY8k0Hf/4/oP4TvZNrODPWjp4Xo3Mw6hsBK+b0eQdz78jqbebbj/LHkpzLGQrvBofVRq KgLJkdcsgyYTnAhinSCzD3mgCiKyalQMJXJsa9FrKgzK0KvhA8FNMUdtJpm/XHNtNuwN XsTnoBMIJYEZAmHfhDDK9iVmmIKdXl8BLLVVuERw4xWjhMYFqn7TcTvDxbzmec/zU+G4 m1Nw== 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=HHAVbv3S9mLXY2DwYZcfhgDiRV7Wqi4wzdrutHs4XyU=; b=wpexz7SeEjU92bQgscUqhxMtJY18ZlPFTEUOwINChqgIuG3PZtX2XtZGDq2wt9CAHp svwKeV3UW0GTJNGRCfLA0rwl+hTJDOaZgyuyO2WP9I1qbmxQIlASOyxhGcvr3wfRlT/Z RmU9X/8O+OXZlGgLiWEYp4zBMzTL6d5hIuSTIOi4SbaHRqjMdbYvpWTxib4W1CNFjBEO t9aSFTY1q5niKlbmpChjW8UtsQgURs8XgGIe8kiSgl33TSjrLI69nobrAc5HQuLXR7UN luL8VqIdN5oXa9FFvVGnrgFAVv3LcfnjAPPGiSefFq1Dm9RouSAEkjoSW2E/76DBRGbu 22gA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uYMD8gc+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id fy6-20020a17090b020600b001c7ec7fbfc4si4617669pjb.75.2022.04.06.04.51.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 04:51:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uYMD8gc+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6885963557D; Wed, 6 Apr 2022 03:09:37 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231948AbiDEU4e (ORCPT + 99 others); Tue, 5 Apr 2022 16:56:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352269AbiDEKEL (ORCPT ); Tue, 5 Apr 2022 06:04:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33478B820B; Tue, 5 Apr 2022 02:53:02 -0700 (PDT) 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 8EFC76165C; Tue, 5 Apr 2022 09:53:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C782C385A2; Tue, 5 Apr 2022 09:53:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649152381; bh=B+LL6HqRHaXg/j5A4/f7HpsysJBncMEphF9/Mdw/N7Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uYMD8gc+THaZpaFBs03KrRZP+JTrGNhzY+NW58tKNkVFfnAfacks+xCpbidcKcQhV 7vIEh1/oK9RiUyW7ro2rv4Lvy4EoHAAxdOo+ay0nO9jH4HgtMYBM2zxm5gkck+mvnH eT+foddQ9XRnVlZ+MwbeB9Gv3vx6bEjubulYLaPI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , Sasha Levin Subject: [PATCH 5.15 757/913] lib/test_lockup: fix kernel pointer check for separate address spaces Date: Tue, 5 Apr 2022 09:30:19 +0200 Message-Id: <20220405070402.524030414@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 [ Upstream commit 5a06fcb15b43d1f7bf740c672950122331cb5655 ] 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 Signed-off-by: Sasha Levin --- 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.34.1