Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3276819ybz; Mon, 27 Apr 2020 13:11:03 -0700 (PDT) X-Google-Smtp-Source: APiQypIHZ7lWAgaeCZGALZ3hptjxhrwJoZk3Os4+QkGxAguK7Cl3y1vnhjVcEu+RKhCC2RoYXUD6 X-Received: by 2002:a05:6402:3046:: with SMTP id bu6mr19872199edb.106.1588018262920; Mon, 27 Apr 2020 13:11:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588018262; cv=none; d=google.com; s=arc-20160816; b=EVH9TCk91aj80ePMsPrbgZB2BgQ9xjmkuVS9ppW3CPHvoEHCzywNteZYVdX4dE/5+2 9fz7oQ7d6aWNVXY1WH4mnHWV8sKt92DCEw45kDLW6xszp6xBCGKL5gLaXOmJ/XrYgtFg f8o6ESBDF6c4CElxlSlMPCalIdC5aWZQDRANDEo6A5CGct4pPoI/4zZIPv6thgc2Hmd3 9nnpkIgD2VHo3OOaJdQOvGFSA1ntsyqqWFJc/o9Pp0hwOba9r2p7ZVl4Btqv+j1MzFMX Sg5rRAAug4v2F209jOVZQF/M3w9Z6ZF6yspVkbqiGpIsLs+6dCpMLCzUFQeDViV2iCKT J08w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1+WS1Xhpo5dh5/K2iq/WBTCS2RIT+YVHJWX5t7HhvUg=; b=a7KSISZEPVTKmlkQHfK0dnWC9hb48ZURgHeyw2l4KqBSZV/rWPrwcYN87kK2wIgoPG IN1CiNdRRBizW73NK9N5bICa5WGLIJvOb+yLUGs6aOuDXWLaOm8YW0jAmMKeD+lwhDq/ wPdB5haMdj6MremGC2aGbr/TgxgvVe9+pJnBH7WckL9sOXql+Pa9paNFi5K5frnvh96a ZqZ3ihpb8SGzwSTIAvfROFsxRrsEb5KmdeXoKuc8K2QbqBKHVwaiFgpjRH5KLQwC5Kpg kGM3nUw4LBLgWY/7MpSMavxTS93EBUlQa4Ho1wAqdhNzHjC9OYQqsIY8q/yfEhkMmRNV ouHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=cuHYqPJh; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u19si406609ejt.101.2020.04.27.13.10.39; Mon, 27 Apr 2020 13:11:02 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=cuHYqPJh; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726764AbgD0UG4 (ORCPT + 99 others); Mon, 27 Apr 2020 16:06:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726641AbgD0UGt (ORCPT ); Mon, 27 Apr 2020 16:06:49 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 620EEC0610D5; Mon, 27 Apr 2020 13:06:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=1+WS1Xhpo5dh5/K2iq/WBTCS2RIT+YVHJWX5t7HhvUg=; b=cuHYqPJhmemVEW4g5IZkPvFnAx 4QYYX+TRsj5yeIFpNZRUrX0hYCsMPYxpQIS76eH+vpCmUtBRTO17yNYSw7BBkmBOCngDdqYetZzc1 yrzgSiFidwVjPAbCiPQ6kNIRJjN8jqbl7aLVtrw7oW/gtSjYYw8sMP7MyrjqR2aRDt/L4BBhKJYLn 5fkZh0SVb3uWAP1mQbueLOFgPnyihnXMuSpsstQyPKY/e5P+DMUMfiKW01Pi8v74mXfRki+IZ29MH n+GPb3ZgUnOkng9EL8E/ZJ3GZdxwueolVaKbOR0y2tSUSjyqTN02WNnzXVyTRL9O0RfYzd1zAg4VH hqh8MCRw==; Received: from [2001:4bb8:193:f203:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jTA1W-00018Y-4n; Mon, 27 Apr 2020 20:06:38 +0000 From: Christoph Hellwig To: Andrew Morton , Alexander Viro Cc: Linus Torvalds , Jeremy Kerr , Arnd Bergmann , "Eric W . Biederman" , linuxppc-dev@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] binfmt_elf: remove the set_fs(KERNEL_DS) in elf_core_dump Date: Mon, 27 Apr 2020 22:06:24 +0200 Message-Id: <20200427200626.1622060-5-hch@lst.de> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200427200626.1622060-1-hch@lst.de> References: <20200427200626.1622060-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is no logic in elf_core_dump itself or in the various arch helpers called from it which use uaccess routines on kernel pointers except for the file writes thate are nicely encapsulated by using __kernel_write in dump_emit. Signed-off-by: Christoph Hellwig --- fs/binfmt_elf.c | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index a1f57e20c3cf2..b29b84595b09f 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1355,7 +1355,6 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma, vma->vm_pgoff == 0 && (vma->vm_flags & VM_READ)) { u32 __user *header = (u32 __user *) vma->vm_start; u32 word; - mm_segment_t fs = get_fs(); /* * Doing it this way gets the constant folded by GCC. */ @@ -1368,14 +1367,8 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma, magic.elfmag[EI_MAG1] = ELFMAG1; magic.elfmag[EI_MAG2] = ELFMAG2; magic.elfmag[EI_MAG3] = ELFMAG3; - /* - * Switch to the user "segment" for get_user(), - * then put back what elf_core_dump() had in place. - */ - set_fs(USER_DS); if (unlikely(get_user(word, header))) word = 0; - set_fs(fs); if (word == magic.cmp) return PAGE_SIZE; } @@ -2183,7 +2176,6 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum, static int elf_core_dump(struct coredump_params *cprm) { int has_dumped = 0; - mm_segment_t fs; int segs, i; size_t vma_data_size = 0; struct vm_area_struct *vma, *gate_vma; @@ -2236,9 +2228,6 @@ static int elf_core_dump(struct coredump_params *cprm) has_dumped = 1; - fs = get_fs(); - set_fs(KERNEL_DS); - offset += sizeof(elf); /* Elf header */ offset += segs * sizeof(struct elf_phdr); /* Program headers */ @@ -2250,7 +2239,7 @@ static int elf_core_dump(struct coredump_params *cprm) phdr4note = kmalloc(sizeof(*phdr4note), GFP_KERNEL); if (!phdr4note) - goto end_coredump; + goto cleanup; fill_elf_note_phdr(phdr4note, sz, offset); offset += sz; @@ -2265,7 +2254,7 @@ static int elf_core_dump(struct coredump_params *cprm) vma_filesz = kvmalloc(array_size(sizeof(*vma_filesz), (segs - 1)), GFP_KERNEL); if (!vma_filesz) - goto end_coredump; + goto cleanup; for (i = 0, vma = first_vma(current, gate_vma); vma != NULL; vma = next_vma(vma, gate_vma)) { @@ -2283,17 +2272,17 @@ static int elf_core_dump(struct coredump_params *cprm) if (e_phnum == PN_XNUM) { shdr4extnum = kmalloc(sizeof(*shdr4extnum), GFP_KERNEL); if (!shdr4extnum) - goto end_coredump; + goto cleanup; fill_extnum_info(&elf, shdr4extnum, e_shoff, segs); } offset = dataoff; if (!dump_emit(cprm, &elf, sizeof(elf))) - goto end_coredump; + goto cleanup; if (!dump_emit(cprm, phdr4note, sizeof(*phdr4note))) - goto end_coredump; + goto cleanup; /* Write program headers for segments dump */ for (i = 0, vma = first_vma(current, gate_vma); vma != NULL; @@ -2315,22 +2304,22 @@ static int elf_core_dump(struct coredump_params *cprm) phdr.p_align = ELF_EXEC_PAGESIZE; if (!dump_emit(cprm, &phdr, sizeof(phdr))) - goto end_coredump; + goto cleanup; } if (!elf_core_write_extra_phdrs(cprm, offset)) - goto end_coredump; + goto cleanup; /* write out the notes section */ if (!write_note_info(&info, cprm)) - goto end_coredump; + goto cleanup; if (elf_coredump_extra_notes_write(cprm)) - goto end_coredump; + goto cleanup; /* Align to page */ if (!dump_skip(cprm, dataoff - cprm->pos)) - goto end_coredump; + goto cleanup; for (i = 0, vma = first_vma(current, gate_vma); vma != NULL; vma = next_vma(vma, gate_vma)) { @@ -2352,22 +2341,19 @@ static int elf_core_dump(struct coredump_params *cprm) } else stop = !dump_skip(cprm, PAGE_SIZE); if (stop) - goto end_coredump; + goto cleanup; } } dump_truncate(cprm); if (!elf_core_write_extra_data(cprm)) - goto end_coredump; + goto cleanup; if (e_phnum == PN_XNUM) { if (!dump_emit(cprm, shdr4extnum, sizeof(*shdr4extnum))) - goto end_coredump; + goto cleanup; } -end_coredump: - set_fs(fs); - cleanup: free_note_info(&info); kfree(shdr4extnum); -- 2.26.1