Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2211067imm; Tue, 10 Jul 2018 15:32:51 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeTOn6ltovkv4wc9k9UoIP44rQ2gRQ7MWV0BV7KfWg28YZCzTOcol7WYxDYzJ+NVnyHQU88 X-Received: by 2002:a63:e56:: with SMTP id 22-v6mr24617610pgo.438.1531261971186; Tue, 10 Jul 2018 15:32:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531261971; cv=none; d=google.com; s=arc-20160816; b=qxliPi4gTFC9xrYuENYj4SDJqtgO8DWVzIJhAECQNQ3CTnugRMS/v0DtzCmY5bZdDX rDYYbtjWxj2R9BLwO4O2rvR4cs7VS0yJ30py3vxnbsgJd41c3hrqem4jpM4fOyQkwqxV fCRudseDnVvlgRrGxzK7XRnjI080inxMruq48y6lIDcVdtAO9rnMG5fSSNzPCRgNKoN/ DUyfafQ/R19AqPhvTp0TtLeSWKQw93jCqvxQ2FwoHBG2DFj8sgYKQ5Taydw+GFiHB7vL WTqBOnn8xirLvHul5XBS2uwmA+vhavR0O49gVAblhPQ2obG3nT87x3y5GavhWv8p1qGr qo6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=wMOelUBk/4VNj8u8kphigUP3R/YB9e4JY4ubq6J1Fbg=; b=OQkKgkYocZjz/zpU/N/KEAPq23xe8syX7g/MDSR2E1js4FL87ywzjZufZFPftIKLbB FeUrA8zlpH0NU+WVQHd6zckXHDC02LDUQfCQpaMQbIAYtlv+m5SjasHiJ6D5uLPV7628 1zxMDKgW47sLG0fOKt8ISOl4x0SMoX9qcBHwuZReLZXvCC5eNYc6ZFYkyH7Qkmqn6VKD KwAJzUiEQK8hDykpurXJ6snKvemvF5/oFxOxeoNicaKbx4a9mn31Y/+cfoQ+a64HZfHr iUBY8F86ihth1kv8AgZ+bgUTTWSrxshx7Mytx3NZtU5F/PgiFyneIbEPVjoqARKB1xck 4Klw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v129-v6si9982150pfv.278.2018.07.10.15.32.36; Tue, 10 Jul 2018 15:32:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732556AbeGJWc3 (ORCPT + 99 others); Tue, 10 Jul 2018 18:32:29 -0400 Received: from mga11.intel.com ([192.55.52.93]:41890 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732519AbeGJWc2 (ORCPT ); Tue, 10 Jul 2018 18:32:28 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jul 2018 15:31:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,335,1526367600"; d="scan'208";a="70305451" Received: from 2b52.sc.intel.com ([143.183.136.52]) by fmsmga004.fm.intel.com with ESMTP; 10 Jul 2018 15:31:16 -0700 From: Yu-cheng Yu To: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Cyrill Gorcunov , Dave Hansen , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , "Ravi V. Shankar" , Vedvyas Shanbhogue Cc: Yu-cheng Yu Subject: [RFC PATCH v2 23/27] mm/mmap: Add IBT bitmap size to address space limit check Date: Tue, 10 Jul 2018 15:26:35 -0700 Message-Id: <20180710222639.8241-24-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180710222639.8241-1-yu-cheng.yu@intel.com> References: <20180710222639.8241-1-yu-cheng.yu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The indirect branch tracking legacy bitmap takes a large address space. This causes may_expand_vm() failure on the address limit check. For a IBT-enabled task, add the bitmap size to the address limit. Signed-off-by: Yu-cheng Yu --- arch/x86/include/uapi/asm/resource.h | 5 +++++ include/uapi/asm-generic/resource.h | 3 +++ mm/mmap.c | 12 +++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/uapi/asm/resource.h b/arch/x86/include/uapi/asm/resource.h index 04bc4db8921b..0741b2a6101a 100644 --- a/arch/x86/include/uapi/asm/resource.h +++ b/arch/x86/include/uapi/asm/resource.h @@ -1 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +#ifdef CONFIG_X86_INTEL_CET +#define rlimit_as_extra() current->thread.cet.ibt_bitmap_size +#endif + #include diff --git a/include/uapi/asm-generic/resource.h b/include/uapi/asm-generic/resource.h index f12db7a0da64..8a7608a09700 100644 --- a/include/uapi/asm-generic/resource.h +++ b/include/uapi/asm-generic/resource.h @@ -58,5 +58,8 @@ # define RLIM_INFINITY (~0UL) #endif +#ifndef rlimit_as_extra +#define rlimit_as_extra() 0 +#endif #endif /* _UAPI_ASM_GENERIC_RESOURCE_H */ diff --git a/mm/mmap.c b/mm/mmap.c index d1eb87ef4b1a..fad41b291ae1 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3242,7 +3242,17 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, */ bool may_expand_vm(struct mm_struct *mm, vm_flags_t flags, unsigned long npages) { - if (mm->total_vm + npages > rlimit(RLIMIT_AS) >> PAGE_SHIFT) + unsigned long as_limit = rlimit(RLIMIT_AS); + unsigned long as_limit_plus = as_limit + rlimit_as_extra(); + + /* as_limit_plus overflowed */ + if (as_limit_plus < as_limit) + as_limit_plus = RLIM_INFINITY; + + if (as_limit_plus > as_limit) + as_limit = as_limit_plus; + + if (mm->total_vm + npages > as_limit >> PAGE_SHIFT) return false; if (is_data_mapping(flags) && -- 2.17.1