Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp783357imm; Fri, 21 Sep 2018 08:13:56 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbRAA1G/tXY5+Zg06D5Om2wc39dc19pjrqXezG4AtwyBPtZL7nM8jbOs0j8wUz3FU9wlTk4 X-Received: by 2002:a17:902:bb84:: with SMTP id m4-v6mr9699889pls.328.1537542836610; Fri, 21 Sep 2018 08:13:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537542836; cv=none; d=google.com; s=arc-20160816; b=dAqQ5lTtr6J7eT8rgXHkjDi0e9eYcYsqD+a/vjl05qsEj+V14yQ0B46EGJffM5ePM4 qsKtC6pNjilRHJd/NB0o9G8/SuJGpgds5vXUlhRFsrCwKuZ4+qFEvDeliyvsKYmwPVQE 5OxnkCnBlU2UeHIdj9URzhyLqC5lwOSbQ70dpDzXzost/4hpuPGCxeqs7iwmNY9SQkIz ruBysmo38fDmmPDmS91eVe2Wsxbnjrro2pSsUJEH2VQ2ddPaG+LsqBkrs2qnbhuUhqtH 3SPYuwsRpI7wCQ2/q2Y9CmNmyu8XsVa4tOpaio4s/EbuPzRgCbdhNssSscmM36nRrhR6 uTOw== 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=coov9TMBwRb+m8/Fllbc10SqeFfZ/zqjB+YRUB70eiI=; b=rET6EW6G7XZL5PUJKTTaFdVFOfE2s+tVQRd3vJBH79fPp60cq5GMxY8C+omIrx8PPi oKsYo0lmCXLUSQlvNZHvhL0/4lXUBxTmTF5U28rdaS9n21h9pQGgJI0rUv0yv/dqMyBj hzPhsYwc4xAMVuqufT2vCN4s4KaOREUw8mJLSqLkbwqk9aLSdV7wFHfBDZ+EgVKGrx/2 ieL1eVCDTpPjriAgIbLImbrA4eBVOdPwq0NNtnidDf1YlViB4+7gY713FSMudq5XMV/0 PgfQvo1D6J6TT8O5SBON1oqGcMSDyv0xG77hBJ7MyVN/hO4F7J31ynN7yA2LuPSZxCJl x+zA== 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 f185-v6si26332357pgc.625.2018.09.21.08.13.39; Fri, 21 Sep 2018 08:13:56 -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 S2390551AbeIUU7o (ORCPT + 99 others); Fri, 21 Sep 2018 16:59:44 -0400 Received: from mga11.intel.com ([192.55.52.93]:13761 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390794AbeIUU7n (ORCPT ); Fri, 21 Sep 2018 16:59:43 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Sep 2018 08:10:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,285,1534834800"; d="scan'208";a="71856869" Received: from 2b52.sc.intel.com ([143.183.136.51]) by fmsmga007.fm.intel.com with ESMTP; 21 Sep 2018 08:09:54 -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 , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue Cc: Yu-cheng Yu Subject: [RFC PATCH v4 24/27] mm/mmap: Create a guard area between VMAs Date: Fri, 21 Sep 2018 08:03:48 -0700 Message-Id: <20180921150351.20898-25-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921150351.20898-1-yu-cheng.yu@intel.com> References: <20180921150351.20898-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 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index c4cc07baccda..3a823bdae09d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2443,24 +2443,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; + + if (vma->vm_flags & VM_GROWSDOWN) + gap = stack_guard_gap; + else + 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; + + if (vma->vm_flags & VM_GROWSUP) + gap = stack_guard_gap; + else + 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; } -- 2.17.1