Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp712593pxb; Tue, 5 Apr 2022 19:54:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0Rjo2BZi+gZs+hhhBvX5R6w1ynf1uNBTSpo0m9mqrvMz9hU+kBiZYIVR8ZWnY8vlMlQDw X-Received: by 2002:a17:906:4fd5:b0:6e1:2084:99d2 with SMTP id i21-20020a1709064fd500b006e1208499d2mr6284579ejw.639.1649213681042; Tue, 05 Apr 2022 19:54:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649213681; cv=none; d=google.com; s=arc-20160816; b=s98QTMFwkdQXnAXBZfUePJVlkVzeIjYaGkkmwjc0CPgfgFgCpsgGSDEPLEkIApGkjb gzcixBtzJDo12ZezCRY7bTqVnMna/gsDTKMM1qUd8sxuwj5F0MTuetmH/nuG/2oo2pPB QV544rL3gDp1u87TQo//xAfNagjVORJypnJ6XVyjDuDXlS3em4ltf6hKEAEsR+5V3DsG M1Q8QNHLYfg4X7ZxKE48dpoBBaB1UCut/KWnT23UP0EzE9Hy2Ct5nHgEgtDwqSDHsvWi jdfFChoFzdvlaAz1+n7ru/tIWI6/CNNOY/J+G9qTb7dyJnKuflLXu0uyyFx6oO0kjknC oJLA== 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=a5ZQaA1WRl8cWXLZiRHhHTTXtNrG3D9yZA2D0JK8Yg8xi27UN9oMykBCWwhMCt7vCH YlxRrrS1Ngjt1CAvRSxy2N3XwjtCasRcPbWQUnHGkjbs632gIJj4Hel3AaoFzGnvCkN9 VE1RYoc0hzfnBoGzAN1aj+vFVnudhFUzGrzlAgOmeG47t+P9kbncOi8NLzUe8GiMD5Ac 425sW2kopQPpw5IQku8XeOv/k3sQnFFPYNXGVeQyHk7sfW54ucrV3rRdoBfqLNKcaSqm fknVD7Sa9M78Suv5+RVB4EZJbtGbsKhFS7tYi4lpDP6xTdNhSZcUwme7D2Cq1V3NjY+n amiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IUD6fql9; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p30-20020a50cd9e000000b0041ce0973936si3316725edi.508.2022.04.05.19.54.15; Tue, 05 Apr 2022 19:54:41 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=IUD6fql9; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244500AbiDEK7H (ORCPT + 99 others); Tue, 5 Apr 2022 06:59:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239149AbiDEIbL (ORCPT ); Tue, 5 Apr 2022 04:31:11 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39FD75370B; Tue, 5 Apr 2022 01:23:19 -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 ams.source.kernel.org (Postfix) with ESMTPS id 8B554B81BBF; Tue, 5 Apr 2022 08:23:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2B05C385A1; Tue, 5 Apr 2022 08:23:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649146996; bh=B+LL6HqRHaXg/j5A4/f7HpsysJBncMEphF9/Mdw/N7Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IUD6fql9DbiCYm3NHsHPKEYt7AQo1osr2JnApSPcpi5wRbmpIJJ89sUNpAOU1fAHP 53ShSUG7p/lv0rQ5oaVOW9yrGgJqORHm7kVddKeUndcueBaIxk9ICF6jm+5+NeiaPd phNCVcMydfsVRXlS7UQBhEa0yNd0vndwEpfknFvU= 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.17 0926/1126] lib/test_lockup: fix kernel pointer check for separate address spaces Date: Tue, 5 Apr 2022 09:27:53 +0200 Message-Id: <20220405070434.700016124@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@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=-7.1 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=ham 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