From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41679C433DF for ; Tue, 13 Oct 2020 01:34:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D661620870 for ; Tue, 13 Oct 2020 01:34:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=arista.com header.i=@arista.com header.b="YoPP5Gks" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D661620870 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=arista.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 84FE5940014; Mon, 12 Oct 2020 21:34:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 73EDC940013; Mon, 12 Oct 2020 21:34:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59E7A94000F; Mon, 12 Oct 2020 21:34:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1D4FE94000F for ; Mon, 12 Oct 2020 21:34:30 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id BBF971EF1 for ; Tue, 13 Oct 2020 01:34:29 +0000 (UTC) X-FDA: 77365182258.03.snail69_2b13d7c271ff Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id A482128A4EC for ; Tue, 13 Oct 2020 01:34:29 +0000 (UTC) X-HE-Tag: snail69_2b13d7c271ff X-Filterd-Recvd-Size: 11573 Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Tue, 13 Oct 2020 01:34:29 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id e18so21821829wrw.9 for ; Mon, 12 Oct 2020 18:34:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QI03JfUdAeqx8H20V8QB+drTDnXgJr9KGaylcrY6E98=; b=YoPP5GksBayPf3YA7iKAhJRnUEw9hLY1epr3iRj1JZcb8AczM+hA8gE9m8KN3op2hH oJsdXJN/juKuz/IX0LfynhImiuc5BXLZODpopg9/dKr6AO5DRbo9eA+/Tnk/Gabp3M32 tkI9HX8Xfzgr1+RZ8d30CYRYuDbqOlpwz4S6/cLFPpzLykgpt4SgsKyVRhuDvdZU7s4v NAO+0SFtu8dVFDXQeh+Auwyk497u1Pq+RVy+QnuzyxP0dcf8CWnY74eu++KCgV7f6NBm tPhM5ye4nI4QHXHZl0BXKrOGmccM9xxAGF+qOIqP9KaDmawf/AP/lR7OtcjlGuH0ZUil +mlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QI03JfUdAeqx8H20V8QB+drTDnXgJr9KGaylcrY6E98=; b=EJaHPQ7w85mTa/aEWOkIobEKW6dnTSSpqy+trCPmwnZiC6LIrfpi8B4IfakuTxM5IK gGJCS9YXwEw62Y0Vh4ufpAl8tnFdpfcwTYm8SnArUh8CyA7sN4Xz9hwXseyekQ4gycvC sZhsBQY95+IGtVWruEbdHtAVA4E+y3HZU5czAJwxJ9HHPTlYSAUolxqi0bDFk2NtLho9 TXIiV/1Nvcw1k3tznF9MDjxORWNX8ThHjkSF1OD2f7wy1bE8zH7ep+AXBsFwZK+Rodqw 37Sw1vEJGcwAKCuTAUPgM0e0B50gU+OeGwiIyEAcGX+dyigtaErSAErOPrHHTHoTe7IX KRCQ== X-Gm-Message-State: AOAM532nF6Ii1wgBqDtV3HNYBpq4rGF08cYG/z+qntO6NjOJABJBjkmN ajal8uGr26RPDBB1iVPwAnEIww== X-Google-Smtp-Source: ABdhPJzRUrGoqc2gRFrRPbwBQLI+3EviW230fK5qUbXR+5lWN/w2oMhECQzgHSMuyap8rQ2Z9wPpZQ== X-Received: by 2002:adf:e64e:: with SMTP id b14mr7124845wrn.68.1602552868235; Mon, 12 Oct 2020 18:34:28 -0700 (PDT) Received: from localhost.localdomain ([2a02:8084:e84:2480:228:f8ff:fe6f:83a8]) by smtp.gmail.com with ESMTPSA id d23sm24825325wmb.6.2020.10.12.18.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 18:34:27 -0700 (PDT) From: Dmitry Safonov To: linux-kernel@vger.kernel.org Cc: Dmitry Safonov <0x7f454c46@gmail.com>, Dmitry Safonov , Alexander Viro , Andrew Morton , Andy Lutomirski , Brian Geffon , Catalin Marinas , Dan Williams , Dave Jiang , Hugh Dickins , Ingo Molnar , "Kirill A. Shutemov" , Mike Kravetz , Minchan Kim , Russell King , Thomas Bogendoerfer , Thomas Gleixner , Vishal Verma , Vlastimil Babka , Will Deacon , linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 6/6] mm: Forbid splitting special mappings Date: Tue, 13 Oct 2020 02:34:16 +0100 Message-Id: <20201013013416.390574-7-dima@arista.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201013013416.390574-1-dima@arista.com> References: <20201013013416.390574-1-dima@arista.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Don't allow splitting of vm_special_mapping's. It affects vdso/vvar areas. Uprobes have only one page in xol_area so they aren't affected. Those restrictions were enforced by checks in .mremap() callbacks. Restrict resizing with generic .split() callback. Signed-off-by: Dmitry Safonov --- arch/arm/kernel/vdso.c | 9 --------- arch/arm64/kernel/vdso.c | 41 +++------------------------------------ arch/mips/vdso/genvdso.c | 4 ---- arch/s390/kernel/vdso.c | 11 +---------- arch/x86/entry/vdso/vma.c | 17 ---------------- mm/mmap.c | 12 ++++++++++++ 6 files changed, 16 insertions(+), 78 deletions(-) diff --git a/arch/arm/kernel/vdso.c b/arch/arm/kernel/vdso.c index fddd08a6e063..3408269d19c7 100644 --- a/arch/arm/kernel/vdso.c +++ b/arch/arm/kernel/vdso.c @@ -50,15 +50,6 @@ static const struct vm_special_mapping vdso_data_mappi= ng =3D { static int vdso_mremap(const struct vm_special_mapping *sm, struct vm_area_struct *new_vma) { - unsigned long new_size =3D new_vma->vm_end - new_vma->vm_start; - unsigned long vdso_size; - - /* without VVAR page */ - vdso_size =3D (vdso_total_pages - 1) << PAGE_SHIFT; - - if (vdso_size !=3D new_size) - return -EINVAL; - current->mm->context.vdso =3D new_vma->vm_start; =20 return 0; diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index d4202a32abc9..a1a4220a405b 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -82,17 +82,9 @@ static union { } vdso_data_store __page_aligned_data; struct vdso_data *vdso_data =3D vdso_data_store.data; =20 -static int __vdso_remap(enum vdso_abi abi, - const struct vm_special_mapping *sm, - struct vm_area_struct *new_vma) +static int vdso_mremap(const struct vm_special_mapping *sm, + struct vm_area_struct *new_vma) { - unsigned long new_size =3D new_vma->vm_end - new_vma->vm_start; - unsigned long vdso_size =3D vdso_info[abi].vdso_code_end - - vdso_info[abi].vdso_code_start; - - if (vdso_size !=3D new_size) - return -EINVAL; - current->mm->context.vdso =3D (void *)new_vma->vm_start; =20 return 0; @@ -223,17 +215,6 @@ static vm_fault_t vvar_fault(const struct vm_special= _mapping *sm, return vmf_insert_pfn(vma, vmf->address, pfn); } =20 -static int vvar_mremap(const struct vm_special_mapping *sm, - struct vm_area_struct *new_vma) -{ - unsigned long new_size =3D new_vma->vm_end - new_vma->vm_start; - - if (new_size !=3D VVAR_NR_PAGES * PAGE_SIZE) - return -EINVAL; - - return 0; -} - static int __setup_additional_pages(enum vdso_abi abi, struct mm_struct *mm, struct linux_binprm *bprm, @@ -284,14 +265,6 @@ static int __setup_additional_pages(enum vdso_abi ab= i, /* * Create and map the vectors page for AArch32 tasks. */ -#ifdef CONFIG_COMPAT_VDSO -static int aarch32_vdso_mremap(const struct vm_special_mapping *sm, - struct vm_area_struct *new_vma) -{ - return __vdso_remap(VDSO_ABI_AA32, sm, new_vma); -} -#endif /* CONFIG_COMPAT_VDSO */ - enum aarch32_map { AA32_MAP_VECTORS, /* kuser helpers */ #ifdef CONFIG_COMPAT_VDSO @@ -313,11 +286,10 @@ static struct vm_special_mapping aarch32_vdso_maps[= ] =3D { [AA32_MAP_VVAR] =3D { .name =3D "[vvar]", .fault =3D vvar_fault, - .mremap =3D vvar_mremap, }, [AA32_MAP_VDSO] =3D { .name =3D "[vdso]", - .mremap =3D aarch32_vdso_mremap, + .mremap =3D vdso_mremap, }, #endif /* CONFIG_COMPAT_VDSO */ [AA32_MAP_SIGPAGE] =3D { @@ -465,12 +437,6 @@ int aarch32_setup_additional_pages(struct linux_binp= rm *bprm, int uses_interp) } #endif /* CONFIG_COMPAT */ =20 -static int vdso_mremap(const struct vm_special_mapping *sm, - struct vm_area_struct *new_vma) -{ - return __vdso_remap(VDSO_ABI_AA64, sm, new_vma); -} - enum aarch64_map { AA64_MAP_VVAR, AA64_MAP_VDSO, @@ -480,7 +446,6 @@ static struct vm_special_mapping aarch64_vdso_maps[] = __ro_after_init =3D { [AA64_MAP_VVAR] =3D { .name =3D "[vvar]", .fault =3D vvar_fault, - .mremap =3D vvar_mremap, }, [AA64_MAP_VDSO] =3D { .name =3D "[vdso]", diff --git a/arch/mips/vdso/genvdso.c b/arch/mips/vdso/genvdso.c index abb06ae04b40..09e30eb4be86 100644 --- a/arch/mips/vdso/genvdso.c +++ b/arch/mips/vdso/genvdso.c @@ -263,10 +263,6 @@ int main(int argc, char **argv) fprintf(out_file, " const struct vm_special_mapping *sm,\n"); fprintf(out_file, " struct vm_area_struct *new_vma)\n"); fprintf(out_file, "{\n"); - fprintf(out_file, " unsigned long new_size =3D\n"); - fprintf(out_file, " new_vma->vm_end - new_vma->vm_start;\n"); - fprintf(out_file, " if (vdso_image.size !=3D new_size)\n"); - fprintf(out_file, " return -EINVAL;\n"); fprintf(out_file, " current->mm->context.vdso =3D\n"); fprintf(out_file, " (void *)(new_vma->vm_start);\n"); fprintf(out_file, " return 0;\n"); diff --git a/arch/s390/kernel/vdso.c b/arch/s390/kernel/vdso.c index c4baefaa6e34..291ead792d64 100644 --- a/arch/s390/kernel/vdso.c +++ b/arch/s390/kernel/vdso.c @@ -59,17 +59,8 @@ static vm_fault_t vdso_fault(const struct vm_special_m= apping *sm, static int vdso_mremap(const struct vm_special_mapping *sm, struct vm_area_struct *vma) { - unsigned long vdso_pages; - - vdso_pages =3D vdso64_pages; - - if ((vdso_pages << PAGE_SHIFT) !=3D vma->vm_end - vma->vm_start) - return -EINVAL; - - if (WARN_ON_ONCE(current->mm !=3D vma->vm_mm)) - return -EFAULT; - current->mm->context.vdso_base =3D vma->vm_start; + return 0; } =20 diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c index 9185cb1d13b9..0c942b31825d 100644 --- a/arch/x86/entry/vdso/vma.c +++ b/arch/x86/entry/vdso/vma.c @@ -89,30 +89,14 @@ static void vdso_fix_landing(const struct vdso_image = *image, static int vdso_mremap(const struct vm_special_mapping *sm, struct vm_area_struct *new_vma) { - unsigned long new_size =3D new_vma->vm_end - new_vma->vm_start; const struct vdso_image *image =3D current->mm->context.vdso_image; =20 - if (image->size !=3D new_size) - return -EINVAL; - vdso_fix_landing(image, new_vma); current->mm->context.vdso =3D (void __user *)new_vma->vm_start; =20 return 0; } =20 -static int vvar_mremap(const struct vm_special_mapping *sm, - struct vm_area_struct *new_vma) -{ - const struct vdso_image *image =3D new_vma->vm_mm->context.vdso_image; - unsigned long new_size =3D new_vma->vm_end - new_vma->vm_start; - - if (new_size !=3D -image->sym_vvar_start) - return -EINVAL; - - return 0; -} - #ifdef CONFIG_TIME_NS static struct page *find_timens_vvar_page(struct vm_area_struct *vma) { @@ -252,7 +236,6 @@ static const struct vm_special_mapping vdso_mapping =3D= { static const struct vm_special_mapping vvar_mapping =3D { .name =3D "[vvar]", .fault =3D vvar_fault, - .mremap =3D vvar_mremap, }; =20 /* diff --git a/mm/mmap.c b/mm/mmap.c index a62cb3ccafce..41100f6505ff 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3389,6 +3389,17 @@ static int special_mapping_mremap(struct vm_area_s= truct *new_vma, return 0; } =20 +static int special_mapping_split(struct vm_area_struct *vma, unsigned lo= ng addr) +{ + /* + * Forbid splitting special mappings - kernel has expectations over + * the number of pages in mapping. Together with VM_DONTEXPAND + * the size of vma should stay the same over the special mapping's + * lifetime. + */ + return -EINVAL; +} + static const struct vm_operations_struct special_mapping_vmops =3D { .close =3D special_mapping_close, .fault =3D special_mapping_fault, @@ -3396,6 +3407,7 @@ static const struct vm_operations_struct special_ma= pping_vmops =3D { .name =3D special_mapping_name, /* vDSO code relies that VVAR can't be accessed remotely */ .access =3D NULL, + .may_split =3D special_mapping_split, }; =20 static const struct vm_operations_struct legacy_special_mapping_vmops =3D= { --=20 2.28.0