Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2316438imm; Thu, 11 Oct 2018 08:24:37 -0700 (PDT) X-Google-Smtp-Source: ACcGV61mxEX+pNlipfMt5ptbRNHq+0bHjk//cxATC67FPdW4YB7Z+sbAASNrfEaoH0pZ4TAiSinC X-Received: by 2002:a63:3e06:: with SMTP id l6-v6mr1745671pga.96.1539271477429; Thu, 11 Oct 2018 08:24:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539271477; cv=none; d=google.com; s=arc-20160816; b=s75YmwobsoHRquU7grPMvpw5mrUw+Ap6z/LRai49xI3nc4LXFdtbqefAT1+8eocF0R UeQWn7C94p7Pe3zM5teECrsNLciC6yZRl/n0yOBp2pYr70EQ62HfeHTKEG/vx5J2l9iK kjLHnz5EkREMMd1yuHWTjCmduWfXfqNLpM7RLTT7ZgRAUbGA5N2/QFFZa2bVfE1XJNJH 2JywEp0xmocKpbdIzrg5xitYNhQnyxu+5Yl6D6OhBELtOcnho6MEsDCJ2DzTQ6zFbELz J+6ZAG5wbdc4zg9oX59LckOM+8tw/rJCINo4K50RMN5VA9W58AGAAiwvnqSsTj3vwbQk q6KA== 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; bh=8LG+JGAGZT/96PIDACi1jNzfYo3k6CvhPo8ogtFgGUM=; b=zXhj8CKsT4SgyCceoPrLPRwZ1Ttjqt9l3MQGhbx7LP+OVAYa1ehF5xC9zHwMXKNhUw QpMV3Aqm2cBynGyLp2CnbWuTDSiKoxKfJk5fySoeIADb/jXfbYd33kPz2wPJ7CMZedKS rCYKhId0fCSrn3Q38x8s0oArJHxMzNQZwLzbyMWZbl5y9HXH1RrlZzaJl9Ts7nVVYvpF SGCa3PHfztS/pMF+XGz+OJyJ4y6wIQpr8bdblmBcua+dQHCDcthSBsaCG0rmT2MiMB3Z tORtaKymMoMAsACqjsrbb4lz4KDZwdv0xPLyJSo+CLP4TrlM4ZAYgpBFOF+l4fYzINUM dLGg== 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 v67-v6si29264786pfk.264.2018.10.11.08.24.22; Thu, 11 Oct 2018 08:24:37 -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 S1728553AbeJKWs0 (ORCPT + 99 others); Thu, 11 Oct 2018 18:48:26 -0400 Received: from mga05.intel.com ([192.55.52.43]:3986 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728145AbeJKWsX (ORCPT ); Thu, 11 Oct 2018 18:48:23 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Oct 2018 08:20:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,368,1534834800"; d="scan'208";a="78019098" Received: from 2b52.sc.intel.com ([143.183.136.147]) by fmsmga008.fm.intel.com with ESMTP; 11 Oct 2018 08:20:43 -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 , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue Cc: Yu-cheng Yu Subject: [PATCH v5 07/27] mm/mmap: Create a guard area between VMAs Date: Thu, 11 Oct 2018 08:15:03 -0700 Message-Id: <20181011151523.27101-8-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181011151523.27101-1-yu-cheng.yu@intel.com> References: <20181011151523.27101-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 Create a guard area between VMAs to detect memory corruption. Signed-off-by: Yu-cheng Yu --- include/linux/mm.h | 30 ++++++++++++++++++++---------- mm/Kconfig | 7 +++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 0416a7204be3..53cfc104c0fb 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2417,24 +2417,34 @@ static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * m static inline unsigned long vm_start_gap(struct vm_area_struct *vma) { unsigned long vm_start = vma->vm_start; + unsigned long gap = 0; + + if (vma->vm_flags & VM_GROWSDOWN) + gap = stack_guard_gap; + else if (IS_ENABLED(CONFIG_VM_AREA_GUARD)) + gap = PAGE_SIZE; + + vm_start -= gap; + if (vm_start > vma->vm_start) + vm_start = 0; - if (vma->vm_flags & VM_GROWSDOWN) { - vm_start -= stack_guard_gap; - if (vm_start > vma->vm_start) - vm_start = 0; - } return vm_start; } static inline unsigned long vm_end_gap(struct vm_area_struct *vma) { unsigned long vm_end = vma->vm_end; + unsigned long gap = 0; + + if (vma->vm_flags & VM_GROWSUP) + gap = stack_guard_gap; + else if (IS_ENABLED(CONFIG_VM_AREA_GUARD)) + gap = PAGE_SIZE; + + vm_end += gap; + if (vm_end < vma->vm_end) + vm_end = -PAGE_SIZE; - if (vma->vm_flags & VM_GROWSUP) { - vm_end += stack_guard_gap; - if (vm_end < vma->vm_end) - vm_end = -PAGE_SIZE; - } return vm_end; } diff --git a/mm/Kconfig b/mm/Kconfig index de64ea658716..0cdcad65640d 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -764,4 +764,11 @@ config GUP_BENCHMARK config ARCH_HAS_PTE_SPECIAL bool +config VM_AREA_GUARD + bool "VM area guard" + default n + help + Create a guard area between VM areas so that access beyond + limit can be detected. + endmenu -- 2.17.1