Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2226833pxb; Wed, 30 Mar 2022 19:59:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6py9avTILeLh0vhBsf7JRWts0iYinkulCYiwrD7iE9iYtgS003rkutR89MVXRnjonn0+f X-Received: by 2002:a05:6a00:4303:b0:4fa:c75b:f716 with SMTP id cb3-20020a056a00430300b004fac75bf716mr3047605pfb.29.1648695542586; Wed, 30 Mar 2022 19:59:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648695542; cv=none; d=google.com; s=arc-20160816; b=AtgyqVcY8qCHDchHNbyhsirZOhM/1guUiFRbN2IolvfzbpGcuTuN47kdI40rsZQ/xN ONzY5g9l6nFVIOt/SRMl5TsOVkV1tDX0yGRkFcy68VQm0BQUrZo+O36MlcuL7/C1PDLX TXye2SGLixmvixJ/y8xTWybKLSfcr7hGk6vAulNMeDTPJGkLbn0oDcUtN+emIxiUQkfi J8Ji0q++82e7ciTyfcgoN4towBxaJKKigqXgkKbLuVQIWOYAzMjBccKk5CGRLWFDD+DB C3chUpG6L5cNp63C31IgXUvzmKHjfabgyJvpIwDpL8kZNKU7MHBcIzvD9MhOCLQRz4Od 9vtQ== 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=HHAVbv3S9mLXY2DwYZcfhgDiRV7Wqi4wzdrutHs4XyU=; b=CpnfpPfzvd0sm7NjdrtL1mitPx4IskQssoHVcxqco9JTkdTtIhH/Zp4m4LZlE6pNSN cTiVgOCzvszN8F67rj9WQ5xLYglOzUANtGCwWy5/OZpbqAIxSzyiUhpdNyvYHUe1VEeD hTSWzqYW/sLa9GOuK0GXK27r4ZgRrTiCtBAOQJF6pMxy4DL6xNjrJjqsZQV9xhjNp6/a 0mKGjcAiRh/zom3ZHQjkfVGj2oK9F1HvdG1H/mo7MgD0DCSnwLiVmWKQv1yHda+kgy+/ 0kX6Pow6U4tOKvQ38wat15PH6ZoS+3Puj+PoUCzL84kS0syeSf5BU/R6d/EvTF6++JlZ 3v1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cs8vojwp; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d16-20020a170902ced000b00153b2d1648esi24622111plg.150.2022.03.30.19.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 19:59:02 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cs8vojwp; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E59ACA27CA; Wed, 30 Mar 2022 19:42:12 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344572AbiC3MBp (ORCPT + 99 others); Wed, 30 Mar 2022 08:01:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344767AbiC3Lxd (ORCPT ); Wed, 30 Mar 2022 07:53:33 -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 AAC1726C2FF; Wed, 30 Mar 2022 04:49:38 -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 E77EAB81BBA; Wed, 30 Mar 2022 11:49:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E51FC34112; Wed, 30 Mar 2022 11:49:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648640976; bh=B+LL6HqRHaXg/j5A4/f7HpsysJBncMEphF9/Mdw/N7Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cs8vojwpVPhQ8EHsRPIOW3bARxTJfVGFFAGqwzhEMxtj3zDTms0W80pz93yXJTmnl PdPMjocKj7xLz4qwehRlgg/poBrMTPiNts4AJGUigLzemx4spXbXy3xQQHTOBg+fQA APtGnLwNJUDJpy4lI5/7+L47awbrnZwtVMNfwc2VJDSAe/ASGOhmQ/7aJ5UCnjtxAY RWTeKF4QY/4zhc5tVctlDhqbUgxk9whgDp3UbNWeVsNeZeqpuwqNomCTx3MxIvE00E i4Mbdhg2oYd2uPm/f/By/IIuAQHFP2TJ943U9q60KiAA255nPObAAg8SlLbb7fpGaU w/LvVdu3Jn9iA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Arnd Bergmann , Sasha Levin Subject: [PATCH AUTOSEL 5.16 41/59] lib/test_lockup: fix kernel pointer check for separate address spaces Date: Wed, 30 Mar 2022 07:48:13 -0400 Message-Id: <20220330114831.1670235-41-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220330114831.1670235-1-sashal@kernel.org> References: <20220330114831.1670235-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,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 [ 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