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_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable 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 1EA4BC433E1 for ; Wed, 26 Aug 2020 15:16:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D87B32075E for ; Wed, 26 Aug 2020 15:16:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="UJqD/t3W" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D87B32075E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 869656B006C; Wed, 26 Aug 2020 11:16:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C7AB6B0070; Wed, 26 Aug 2020 11:16:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DFFB8D0001; Wed, 26 Aug 2020 11:16:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0101.hostedemail.com [216.40.44.101]) by kanga.kvack.org (Postfix) with ESMTP id 58B076B006C for ; Wed, 26 Aug 2020 11:16:19 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 05B21363B for ; Wed, 26 Aug 2020 15:16:19 +0000 (UTC) X-FDA: 77193070878.12.value25_07096bb27065 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id E2C0C1801C9BE for ; Wed, 26 Aug 2020 15:15:40 +0000 (UTC) X-HE-Tag: value25_07096bb27065 X-Filterd-Recvd-Size: 7370 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Wed, 26 Aug 2020 15:15:38 +0000 (UTC) Received: by mail-qt1-f202.google.com with SMTP id r9so1963048qtp.7 for ; Wed, 26 Aug 2020 08:15:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=W92EWp10cYvF5yPv3rgiIaePnIXh3IWgRNGaRIqgcR4=; b=UJqD/t3WSlOOwI6R+bovBLP0sPLAoFd9plz7oxgqCdZWBEXqS068KD0/WN83GUiYro AqMkBXVc1ZQW++VdRzH7wzupdkHlEeE8WdNHPNXIrAtApBfg/kUBE5w1O/QJ4oIRh7tV tb02uam4svDcll5gPdChagNY8GeENR2JwPo3cAmCZl9l0lPaA3lpuWAHtoTTZ/nY0xe3 4n3EawWNVxHzX152yi+B+/xnFeZCesLvBc+9Yf0k6A6nYtvt0Cp/3xSdFHsZ6DIr3vdE P/v6YEhnOufPrYUBJwGNBZiHQ38brTulw+gui8aHniQAc42zBTvr/aWwOPvwZ19EuwvR oVxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=W92EWp10cYvF5yPv3rgiIaePnIXh3IWgRNGaRIqgcR4=; b=YHDlUSa9G7PIzenN8wFjezAmIV9DelwHQDoaZUwMuA6Nt/jZcAPyV/KrgfsafkcUjH hYhRFKWATMxjl5jag1S2JRcO1X91oN4b+SqXKp/w9PwycZjfVU0yH76fR2zQtJzbKHaI BGOkTMuvgLRzYiWhD7fKedSZD6m6mXxpcjuSUuMs4vpnJ89l4gzQULmK1o5GYujq/q2S VVvjPghZNCLDIBVqWZNsfauYh3JPplIm16d3K/87fYLqoMyytrjBbvtAmKmXrKQ6NjOe Bq+QUYWYR+96yG5mVttSHHEBPb7gPJkh2XwNo1Mu4U/T+ymXeMC7hW5OsbqmKBaVceOf M3xg== X-Gm-Message-State: AOAM530bcJTN0n4lDVsQzGva8BRconTtNEXqjMYj6xig4uMM8rZgo7iP qiGI2VfDgDM2EgxtLyA+XsEvFm5s7Q== X-Google-Smtp-Source: ABdhPJy7KDIKhCfICG40CVPo7QPb4NhJBMI2xLLuMFSRNzJ90NFTZ37qbydNf49iDwWC0KeljzXzUWr8og== X-Received: from jannh2.zrh.corp.google.com ([2a00:79e0:1b:201:1a60:24ff:fea6:bf44]) (user=jannh job=sendgmr) by 2002:ad4:46ac:: with SMTP id br12mr14699313qvb.236.1598454937463; Wed, 26 Aug 2020 08:15:37 -0700 (PDT) Date: Wed, 26 Aug 2020 17:14:44 +0200 In-Reply-To: <20200826151448.3404695-1-jannh@google.com> Message-Id: <20200826151448.3404695-2-jannh@google.com> Mime-Version: 1.0 References: <20200826151448.3404695-1-jannh@google.com> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog Subject: [PATCH v4 1/5] binfmt_elf_fdpic: Stop using dump_emit() on user pointers on !MMU From: Jann Horn To: Andrew Morton Cc: Linus Torvalds , Christoph Hellwig , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Alexander Viro , "Eric W . Biederman" , Oleg Nesterov Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: E2C0C1801C9BE X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: dump_emit() is for kernel pointers, and VMAs describe userspace memory. Let's be tidy here and avoid accessing userspace pointers under KERNEL_DS, even if it probably doesn't matter much on !MMU systems - especially given that it looks like we can just use the same get_dump_page() as on MMU if we move it out of the CONFIG_MMU block. One small change we have to make in get_dump_page() is to use __get_user_pages_locked() instead of __get_user_pages(), since the latter doesn't exist on nommu. On mmu builds, __get_user_pages_locked() will just call __get_user_pages() for us. Signed-off-by: Jann Horn --- fs/binfmt_elf_fdpic.c | 8 ------ mm/gup.c | 57 +++++++++++++++++++++---------------------- 2 files changed, 28 insertions(+), 37 deletions(-) diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index 50f845702b92..a53f83830986 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -1529,14 +1529,11 @@ static bool elf_fdpic_dump_segments(struct coredump_params *cprm) struct vm_area_struct *vma; for (vma = current->mm->mmap; vma; vma = vma->vm_next) { -#ifdef CONFIG_MMU unsigned long addr; -#endif if (!maydump(vma, cprm->mm_flags)) continue; -#ifdef CONFIG_MMU for (addr = vma->vm_start; addr < vma->vm_end; addr += PAGE_SIZE) { bool res; @@ -1552,11 +1549,6 @@ static bool elf_fdpic_dump_segments(struct coredump_params *cprm) if (!res) return false; } -#else - if (!dump_emit(cprm, (void *) vma->vm_start, - vma->vm_end - vma->vm_start)) - return false; -#endif } return true; } diff --git a/mm/gup.c b/mm/gup.c index ae096ea7583f..92519e5a44b3 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1495,35 +1495,6 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors) mmap_read_unlock(mm); return ret; /* 0 or negative error code */ } - -/** - * get_dump_page() - pin user page in memory while writing it to core dump - * @addr: user address - * - * Returns struct page pointer of user page pinned for dump, - * to be freed afterwards by put_page(). - * - * Returns NULL on any kind of failure - a hole must then be inserted into - * the corefile, to preserve alignment with its headers; and also returns - * NULL wherever the ZERO_PAGE, or an anonymous pte_none, has been found - - * allowing a hole to be left in the corefile to save diskspace. - * - * Called without mmap_lock, but after all other threads have been killed. - */ -#ifdef CONFIG_ELF_CORE -struct page *get_dump_page(unsigned long addr) -{ - struct vm_area_struct *vma; - struct page *page; - - if (__get_user_pages(current->mm, addr, 1, - FOLL_FORCE | FOLL_DUMP | FOLL_GET, &page, &vma, - NULL) < 1) - return NULL; - flush_cache_page(vma, addr, page_to_pfn(page)); - return page; -} -#endif /* CONFIG_ELF_CORE */ #else /* CONFIG_MMU */ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start, unsigned long nr_pages, struct page **pages, @@ -1569,6 +1540,34 @@ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start, } #endif /* !CONFIG_MMU */ +/** + * get_dump_page() - pin user page in memory while writing it to core dump + * @addr: user address + * + * Returns struct page pointer of user page pinned for dump, + * to be freed afterwards by put_page(). + * + * Returns NULL on any kind of failure - a hole must then be inserted into + * the corefile, to preserve alignment with its headers; and also returns + * NULL wherever the ZERO_PAGE, or an anonymous pte_none, has been found - + * allowing a hole to be left in the corefile to save diskspace. + * + * Called without mmap_lock, but after all other threads have been killed. + */ +#ifdef CONFIG_ELF_CORE +struct page *get_dump_page(unsigned long addr) +{ + struct vm_area_struct *vma; + struct page *page; + + if (__get_user_pages_locked(current->mm, addr, 1, &page, &vma, NULL, + FOLL_FORCE | FOLL_DUMP | FOLL_GET) < 1) + return NULL; + flush_cache_page(vma, addr, page_to_pfn(page)); + return page; +} +#endif /* CONFIG_ELF_CORE */ + #if defined(CONFIG_FS_DAX) || defined (CONFIG_CMA) static bool check_dax_vmas(struct vm_area_struct **vmas, long nr_pages) { -- 2.28.0.297.g1956fa8f8d-goog