Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1088631ybz; Wed, 29 Apr 2020 14:52:03 -0700 (PDT) X-Google-Smtp-Source: APiQypLAC+yYLhRPrKPAMyY5sbmoDqHu+imwkAx0o0CW+JZH9+iChaLkt4uvFfGHwgPZqwn3NB6N X-Received: by 2002:a17:906:f90e:: with SMTP id lc14mr4530110ejb.156.1588197123753; Wed, 29 Apr 2020 14:52:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588197123; cv=none; d=google.com; s=arc-20160816; b=wx0zF+T+gP1pFZ20SnbpOBjl4Fu5GeFoxDHECdXVh96WECB5caDkn2mbb74c+ZDglL L5QuGjWO1Nlfd/5mZcTP271ECR+0GnBIc188B4Hh4TtdcS8w3YNvyEuyh0pfD6KgGpwK S9rZ2lCawliKNayHlyxXl/qABA5MGI4dkoKxlpPdSsPdWVjs4FEcaceUdlHgFkW9z4kN iYP3Ixj48KW2dJtva735FL9J49Fe8+3pZyVW+/aPk8WI4B2E5nlw8zv0mlV4qu2P8Blb ee+jvdb6s5MY6/rNDn+Wr1DoqDM4CBUZZjQ2FPNdfBo/ZNDbS7vIV8Xlwjm/DTZmHiGg Ci2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=X8Ilta2TozKsEzasXrZac28hkMQagz57pEK9xvAhCMU=; b=GB0VBLM1b0LM9UGbVwI5yDcUoawIQufYjK16k4tO572L2TP05tB/R/Lm3Khx3MVxpC 6OH0+gxovRX963ewtAzwFClSNzl8cvaOTqySohdUjGuWr0HRPCxTWwlzuY2OTRICZAHz 0qVHA2z5Jpi/uuQYmfF7xVuB8ZGoljnrsyi9nKSbBDAraR6EsGVmubYAygf3PbaAsf5m xCdbWQluSZrQaBgwMMUUIqzsasn0FCyLGy3vHmV7RZMxvVaqVa3WQk1pDJHmGkapIEOG x5XClcv3PIoDVCeoc5INNsCCET7tHKx69j7Gys1zEPJYZzTAITLMArzQPDFy0P26OrMd vJGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="hq7/1zfU"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ca3si3931480edb.164.2020.04.29.14.51.40; Wed, 29 Apr 2020 14:52:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="hq7/1zfU"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726935AbgD2VuP (ORCPT + 99 others); Wed, 29 Apr 2020 17:50:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727813AbgD2VuN (ORCPT ); Wed, 29 Apr 2020 17:50:13 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2F6CC03C1AE for ; Wed, 29 Apr 2020 14:50:13 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id i13so5176726ybl.13 for ; Wed, 29 Apr 2020 14:50:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=X8Ilta2TozKsEzasXrZac28hkMQagz57pEK9xvAhCMU=; b=hq7/1zfUEsP2iAtt4ZQ4PwzfpMH/LEAjv1O6M4T2kyI5ocMSPyrezh78agwH8E2fzC 5UoVyHnot4yvU3uT3T/gW30svDPED38wwzcwKUzc1ikntjBs+9t1DIScbtC1T7t5gt+O mS6z/RcBXMryw96KRHKWMXSzRFEqU6HnTb477iWgeCgmihZ523VW2z3+tpWL0Olncc0H DbIb3P9b+pQ9ux7Mr0Ope9w48HA1d2qcLTAWT5s9KeaNQb1A3h6o/n0bM6oiKdKbONLG xXvcA9wtEp7X3YvX7oN/lCMYNvQZ5hT+jnRwGzIUoXJDAz6icA6ycOc2YEueJSe+gqSn I33Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=X8Ilta2TozKsEzasXrZac28hkMQagz57pEK9xvAhCMU=; b=aVXjIPZ+wuxE36m884hMaLthf3IGIZ75fcX9XVhMyLu2FTis02TjAH8eLHNLInH14x lldEAlcb6p0StQFycycbFVh9wIuU6q8gwy0blSiRiHSCs8Yk3rtnnU5MeHZ9HYPMxVbz v3yveuOMqlr+pdCpemTwDz6Dmt+jCdktVkG+EVUVRm183MO7AkEWWoi1vABR+a7U7MfI ovhFOntiEs7RZ1G2sXO5nENHerVvzmnflopSB+gOmEkUatp0BAFgmHPfGKcoSpak7jwv pwRH5ux+mqyk6FmOI5VQfNa1NAgPhvlYNA/Wl6lOBRbbwcLw9wv5wS4KCzDOnzKG/Yq6 6Qag== X-Gm-Message-State: AGi0PuYxPpag9WaZ4AvcSegqG0xFkIN3bnUsQsgP2ONm1mvSZhRVZ3kq GIAwKO3GnOf7s/OWNe4hv8AIw+85cQ== X-Received: by 2002:a25:c048:: with SMTP id c69mr565867ybf.169.1588197012786; Wed, 29 Apr 2020 14:50:12 -0700 (PDT) Date: Wed, 29 Apr 2020 23:49:50 +0200 In-Reply-To: <20200429214954.44866-1-jannh@google.com> Message-Id: <20200429214954.44866-2-jannh@google.com> Mime-Version: 1.0 References: <20200429214954.44866-1-jannh@google.com> X-Mailer: git-send-email 2.26.2.526.g744177e7f7-goog Subject: [PATCH v2 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 , Russell King , linux-arm-kernel@lists.infradead.org, Mark Salter , Aurelien Jacquiot , linux-c6x-dev@linux-c6x.org, Yoshinori Sato , Rich Felker , linux-sh@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Jann Horn --- fs/binfmt_elf_fdpic.c | 8 ------ mm/gup.c | 58 +++++++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 37 deletions(-) diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index c62c17a5c34a9..f5b47076fa762 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -1495,14 +1495,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; @@ -1518,11 +1515,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 50681f0286ded..76080c4dbff05 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1490,35 +1490,6 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors) up_read(&mm->mmap_sem); 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_sem, 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, 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 task_struct *tsk, struct mm_struct *mm, unsigned long start, @@ -1565,6 +1536,35 @@ static long __get_user_pages_locked(struct task_struct *tsk, } #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_sem, 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, 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 */ + #if defined(CONFIG_FS_DAX) || defined (CONFIG_CMA) static bool check_dax_vmas(struct vm_area_struct **vmas, long nr_pages) { -- 2.26.2.526.g744177e7f7-goog