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=-9.7 required=3.0 tests=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 E4671C43603 for ; Wed, 11 Dec 2019 18:48:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7D4D6206A5 for ; Wed, 11 Dec 2019 18:48:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7D4D6206A5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B505E6B3366; Wed, 11 Dec 2019 13:48:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A16916B3369; Wed, 11 Dec 2019 13:48:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88F316B3367; Wed, 11 Dec 2019 13:48:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0146.hostedemail.com [216.40.44.146]) by kanga.kvack.org (Postfix) with ESMTP id 732B76B3363 for ; Wed, 11 Dec 2019 13:48:51 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 44B0C4DA6 for ; Wed, 11 Dec 2019 18:48:51 +0000 (UTC) X-FDA: 76253747262.03.elbow41_1304887174d42 X-HE-Tag: elbow41_1304887174d42 X-Filterd-Recvd-Size: 3710 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Wed, 11 Dec 2019 18:48:50 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 48A84147A; Wed, 11 Dec 2019 10:41:04 -0800 (PST) Received: from arrakis.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D3D583F6CF; Wed, 11 Dec 2019 10:41:02 -0800 (PST) From: Catalin Marinas To: linux-arm-kernel@lists.infradead.org Cc: Will Deacon , Marc Zyngier , Vincenzo Frascino , Szabolcs Nagy , Richard Earnshaw , Kevin Brodsky , Andrey Konovalov , linux-mm@kvack.org, linux-arch@vger.kernel.org Subject: [PATCH 16/22] mm: Introduce arch_validate_flags() Date: Wed, 11 Dec 2019 18:40:21 +0000 Message-Id: <20191211184027.20130-17-catalin.marinas@arm.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191211184027.20130-1-catalin.marinas@arm.com> References: <20191211184027.20130-1-catalin.marinas@arm.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: Similarly to arch_validate_prot() called from do_mprotect_pkey(), an architecture may need to sanity-check the new vm_flags. Define a dummy function always returning true. In addition to do_mprotect_pkey(), also invoke it from mmap_region() prior to updating vma->vm_page_prot to allow the architecture code to veto potentially inconsistent vm_flags. Signed-off-by: Catalin Marinas --- include/linux/mman.h | 13 +++++++++++++ mm/mmap.c | 9 +++++++++ mm/mprotect.c | 8 ++++++++ 3 files changed, 30 insertions(+) diff --git a/include/linux/mman.h b/include/linux/mman.h index c53b194c11a1..686fa6c98ce7 100644 --- a/include/linux/mman.h +++ b/include/linux/mman.h @@ -103,6 +103,19 @@ static inline bool arch_validate_prot(unsigned long = prot, unsigned long addr) #define arch_validate_prot arch_validate_prot #endif =20 +#ifndef arch_validate_flags +/* + * This is called from mprotect() with the updated vma->vm_flags. + * + * Returns true if the VM_* flags are valid. + */ +static inline bool arch_validate_flags(unsigned long flags) +{ + return true; +} +#define arch_validate_flags arch_validate_flags +#endif + /* * Optimisation macro. It is equivalent to: * (x & bit1) ? bit2 : 0 diff --git a/mm/mmap.c b/mm/mmap.c index 9c648524e4dc..433355c5bdf1 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1804,6 +1804,15 @@ unsigned long mmap_region(struct file *file, unsig= ned long addr, vma_set_anonymous(vma); } =20 + /* Allow architectures to sanity-check the vm_flags */ + if (!arch_validate_flags(vma->vm_flags)) { + error =3D -EINVAL; + if (file) + goto unmap_and_free_vma; + else + goto free_vma; + } + vma_link(mm, vma, prev, rb_link, rb_parent); /* Once vma denies write, undo our temporary denial count */ if (file) { diff --git a/mm/mprotect.c b/mm/mprotect.c index 7a8e84f86831..787b071bcbfd 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -543,6 +543,14 @@ static int do_mprotect_pkey(unsigned long start, siz= e_t len, goto out; } =20 + /* + * Allow architectures to sanity-check the new flags. + */ + if (!arch_validate_flags(newflags)) { + error =3D -EINVAL; + goto out; + } + error =3D security_file_mprotect(vma, reqprot, prot); if (error) goto out;