Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp2427478rwo; Thu, 3 Aug 2023 09:11:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlFQKU55JKX47FApkCuk7qFn3C3SPxnCEyvalgePC5DN8Dyc+bpAslTtMk9fUqC8TDmY099U X-Received: by 2002:a05:6512:2e8:b0:4fd:ba8d:d4ed with SMTP id m8-20020a05651202e800b004fdba8dd4edmr6347629lfq.24.1691079094636; Thu, 03 Aug 2023 09:11:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691079094; cv=none; d=google.com; s=arc-20160816; b=Dtyt6KT0cBKo7SGv0Gd+MQ9iw7Z4dog6mS2L6bvXoPicqfttQptX2e0aK/Reo003NS cQkMqZ1+L8JIFC1hCeVgVJZvfM+ZG5YJPMPhwGw/VHe/21fLk7fU4mNva6R03HIM0FP7 bFWkGx4vdlYOgE2NJCCe4u0Fd3Oh7BbAhh1C9OJJH9WdJABMFUbc8skmDXGrd/0nAjsF jjrp/BilFb/LP8C4kcjD8GNb+r5SId0RMOnKPUNjCCsfp9TBuYdMb3oATMG8xb+IsLkG mTyaEMbSj8V2IiQZrJ3GR34Fs7of7SHp7mWVynXCmEF3cyqFgSxjfHuiKJmx3/t0p2fr 9qwQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=WdTHsjgEOvmnmgFlq61uExq4ZFJriDofF8tcorPi+nM=; fh=tvvvXxKpgmvZpaJ3quryuqcqx2uu+MjrOigviOlbR+4=; b=buC8bC0qOXRL0zePBsZKt9GvNLBlVFDCuL4vAj/1UxRbld18KuFrnEsCl4NsLdEbmW PYhyiMJNv/7jV33degslrtkU0Xvi+BDIzFKZ6O/4bkhCO7eO8CddGLdS3JX2fcMfGhKI iDHrFyUa0tX9v7T4Cp+I32X6iR51eRC6/LP9kbFlUafOafC+8hZU03PnIHNs75JawWkG EjHj+aAd+oYXaJPKDHjy1cKDQqMDc2bzqcvMZNsb/UfsA50rqZG5W4DCkYknmRu/Lzc5 lY1cdkUByib3vv7vjupHyO7WGjBsCLBfUkmPe6StEebOBsDG63b7jrSZRNxBEQoL2L6a 7bbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cWDWhnC3; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n20-20020aa7c694000000b00523108daf57si733967edq.67.2023.08.03.09.11.10; Thu, 03 Aug 2023 09:11:34 -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=@intel.com header.s=Intel header.b=cWDWhnC3; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235254AbjHCPQf (ORCPT + 99 others); Thu, 3 Aug 2023 11:16:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234544AbjHCPQd (ORCPT ); Thu, 3 Aug 2023 11:16:33 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0066E77 for ; Thu, 3 Aug 2023 08:16:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691075792; x=1722611792; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=/nVvtIp70+FSePc0879BDHNt5uW/EgkRqUTXM82sSno=; b=cWDWhnC3OUokidSSVHBK2/I17p1Wb/lbBqa19EnWSBqGTAvx4YZ2D2hg DvF4DKUSZ9qsQLcDKoo1al3AmKC5etHwlU7s2qcMXFaFbwhsLLaW7fLMQ SkaC3MSm1Wt84EUZdqQI9pqUJZaxmx2cVvO7Vch4B4bKOgXe4/QFtTkRl orujQH4R6J5wjWWhlQcbyZOc+kFtUYcpo6F2gHBpXJI5J7XG5yyFu5Lgj WLQzmCT3Mb5LeMJn0MD7YNl/Lf0ZP9Rg0T264rxMlZqaxZuFYa1QVvb9c 1mgvZ3ogPPmk59G69vMZjapI0GqNzSx+JGcriMnvMEAIRdIa+8+kCu+5Z A==; X-IronPort-AV: E=McAfee;i="6600,9927,10791"; a="354833962" X-IronPort-AV: E=Sophos;i="6.01,252,1684825200"; d="scan'208";a="354833962" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2023 08:16:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10791"; a="903418183" X-IronPort-AV: E=Sophos;i="6.01,252,1684825200"; d="scan'208";a="903418183" Received: from sosterlu-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.209.233]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2023 08:16:18 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id CBB2E109FCF; Thu, 3 Aug 2023 18:16:13 +0300 (+03) From: "Kirill A. Shutemov" To: dave.hansen@intel.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de Cc: x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Yingcong Wu Subject: [PATCHv2] x86/mm: Fix VDSO and VVAR placement on 5-level paging machines Date: Thu, 3 Aug 2023 18:16:09 +0300 Message-ID: <20230803151609.22141-1-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 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_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,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 Yingcong has noticed that on the 5-level paging machine, VDSO and VVAR VMAs are placed above the 47-bit border: 8000001a9000-8000001ad000 r--p 00000000 00:00 0 [vvar] 8000001ad000-8000001af000 r-xp 00000000 00:00 0 [vdso] This might confuse users who are not aware of 5-level paging and expect all userspace addresses to be under the 47-bit border. So far problem has only been triggered with ASLR disabled, although it may also occur with ASLR enabled if the layout is randomized in a just right way. The problem happens due to custom placement for the VMAs in the VDSO code: vdso_addr() tries to place them above the stack and checks the result against TASK_SIZE_MAX, which is wrong. TASK_SIZE_MAX is set to the 56-bit border on 5-level paging machines. Use DEFAULT_MAP_WINDOW instead. Signed-off-by: Kirill A. Shutemov Reported-by: Yingcong Wu Fixes: b569bab78d8d ("x86/mm: Prepare to expose larger address space to userspace") --- v2: - Fix commit message: grammar and passive voice arch/x86/entry/vdso/vma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c index 11a5c68d1218..7645730dc228 100644 --- a/arch/x86/entry/vdso/vma.c +++ b/arch/x86/entry/vdso/vma.c @@ -299,8 +299,8 @@ static unsigned long vdso_addr(unsigned long start, unsigned len) /* Round the lowest possible end address up to a PMD boundary. */ end = (start + len + PMD_SIZE - 1) & PMD_MASK; - if (end >= TASK_SIZE_MAX) - end = TASK_SIZE_MAX; + if (end >= DEFAULT_MAP_WINDOW) + end = DEFAULT_MAP_WINDOW; end -= len; if (end > start) { -- 2.41.0