From patchwork Fri Sep 29 03:24:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13403633 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7909E743C0 for ; Fri, 29 Sep 2023 03:24:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3069D8D009F; Thu, 28 Sep 2023 23:24:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B5668D0002; Thu, 28 Sep 2023 23:24:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1553C8D009F; Thu, 28 Sep 2023 23:24:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 07D288D0002 for ; Thu, 28 Sep 2023 23:24:41 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C3E0B4108B for ; Fri, 29 Sep 2023 03:24:40 +0000 (UTC) X-FDA: 81288192720.08.4EFDC5D Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf08.hostedemail.com (Postfix) with ESMTP id C2667160007 for ; Fri, 29 Sep 2023 03:24:38 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=HAB+IOsD; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf08.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.177 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695957878; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=q1S2QHXg38kETw2Vrnc3ITAH/+VCqfp/XhwxJe7fVnI=; b=yY1l5lD+AaTnDHtA+I3GcSn+QvLQAz5OFHTxS/ae4OvuGWKwoadwGQeephnr2WzjC/2c2J /Lgm/i2v8sYbYv+4poWQuRnt3APY1BfBgKpXzVpNlLnDipnlVG/nNLJNk0LrSltQoptAd5 24K8rfA2P2CKuqyVDs1uiGzije4z5JM= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=HAB+IOsD; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf08.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.177 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695957878; a=rsa-sha256; cv=none; b=QDECvh4dTR2Wfl3beYjCUi2+mFRbg5IG9Uq0tG+kr6bt2gpTxInU2bSujDe8Cs+sYSQoU9 CoKOCAzhUsHbAQaZZ+WTLy0wfAqL+GxQCAoPEiwpu8fY4dvpcQ0U2XjrLGKvG4BpRUKLjt qXmCrB7pUdg3YPELiSQPhYt3OROv2B0= Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-690ce3c55f1so10758553b3a.0 for ; Thu, 28 Sep 2023 20:24:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695957877; x=1696562677; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q1S2QHXg38kETw2Vrnc3ITAH/+VCqfp/XhwxJe7fVnI=; b=HAB+IOsDuJH/2TAMt/4chgRWB6MBHeiJVwhY3Lk2jZnweEjJIpif9YgTpGzSQ7bc2i YqVCJ+GeIuS3RGwbda5fDSr4xFy1RdkxZY4QMDLXhnHKNQkDHPQ7VyZrEi4ChIV+67uK UpfUZaxFADOrOfOABxwnT1pGE4iSyQY+PJGsQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695957877; x=1696562677; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q1S2QHXg38kETw2Vrnc3ITAH/+VCqfp/XhwxJe7fVnI=; b=YLNX/CTlkM3k6IarKPSFw9gQcZHXMYC/mXg/fKe5yOxUjypOu8SyErIvz5QokBAG6J sDVgbkBA8hBiexjwDVNwsHoXzfTD2VxIofziTy42y8UzhBRnmsBpep4+pGNE13UKemlk K7+crC3KeEkZHJi3o9Z0U23z7zPjH9a/FT0j4HMgO/+3awq3X3qj69l/Eyw254lSciqS yNWMpsYCn8P8Ff56jTZgEcMfU/x9dYP8vA5m1O/B5biUR0RjXrebRlVvYfWZznLG7GzP t8AgRSbc/e2LiUuC30EnipbXm1t9SRkF1tb3hCoDkPIZMxt2nHwFoftMPDq/yj3czDYM 9/SA== X-Gm-Message-State: AOJu0Yym2pMx0aAX3j10ALb1q1AgEnRLvX40TdkS8qbXMas9RgKT9Ku+ IDoYjSgw8LLMm9+f/7AMT7JNKg== X-Google-Smtp-Source: AGHT+IE41fRv5mNKe4vvztkmUzkhz9pAxOvK1Y/IqQsGTpnsnBawSfxRlm726T+ZhHtYQg36mF0ZmA== X-Received: by 2002:a05:6a20:d90b:b0:160:cc73:39ef with SMTP id jd11-20020a056a20d90b00b00160cc7339efmr2588831pzb.48.1695957877520; Thu, 28 Sep 2023 20:24:37 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id g9-20020a170902c38900b001c7373769basm2074161plg.88.2023.09.28.20.24.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 20:24:36 -0700 (PDT) From: Kees Cook To: Eric Biederman Cc: Kees Cook , Sebastian Ott , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Pedro Falcato , Al Viro , Christian Brauner , Andrew Morton , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org Subject: [PATCH v4 1/6] binfmt_elf: Support segments with 0 filesz and misaligned starts Date: Thu, 28 Sep 2023 20:24:29 -0700 Message-Id: <20230929032435.2391507-1-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230929031716.it.155-kees@kernel.org> References: <20230929031716.it.155-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=8056; i=keescook@chromium.org; h=from:subject; bh=17HFsxzRR6qjNPl2OqeDyONMEClWu0Ld8l5K3CgB/PI=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlFkNx9ky4C5SoI1ZcjBN8kT+abWcWJ1uQcH9Lv 1XdD+58PfSJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRZDcQAKCRCJcvTf3G3A Jkq+D/4+ERIwd+j9kCgE3YL8f6BaEPCM1Wy540egTRyd8uxuhJLV/MjU4bGQTq5IzynPij0EVRZ AMX3Kda0AuvJ9/nAqmFqVAPvO0yR68AwteJvc5m7SSBnbNIYr6LAJ4jO+2fBU/rx9GNhwZPe6dB blk7g6mbQXiRAeKTdqGu5bjoYcZTrrQFJj91tUj9OCuNDZEr2lD4iMNVPhZfK6HO97g2NWw11kt UEcNkn69PVA0KRsMgCqWh02zT9JvaZP+ciKiHEDz1aQoPHotcJpFQqEDxUSWkGUQwlkbKrGRaf1 fcPi2kq7GTJiTxXPgxd5o7yWriWxPHNTyhKGXcbmToLSeKJBOkj8NWQIkYlv05UyEUw+gY+0WZw FJ3LNMpBDzrKiUiNWUfal8Watcpz/yp+mjIELKSDFReTXTqLQW49KvqulWYNZHPtbpVVaTmkGGu bKCHrI4wlZo/0Ea4v4V205GrLpUsbdCcsj8CpSpWGlWqb+FWHvo0dQhWmwNQEWqpSA7soBBxKsV 5Ragq8YPGzA2Xl68fzMW7FnyZCLJOeob+5SPgEzYkdiUSqO3L0nZ2V8J5Xyxo3nxEyZ5KfjGyzU 8JgId+qHNCzcdvZSiOJ6nW3Io53wtMH4PaQZLa4PNAB19C3URkhNr/gqkDCFsv4txyd8mlojxjf NlBsHU/1WHut/KA== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Rspamd-Queue-Id: C2667160007 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: yi1e7nzkbf3kn53ry9eff85mra4ucwgi X-HE-Tag: 1695957878-253250 X-HE-Meta: U2FsdGVkX1/JknHqN/Hon3jviZXx446D5xrrFlv/Q0hY7ZMnW6zGpOM8OASURiUgOnx/OjBwN3Jr4gWuktCbYUKKmzsDWQjwiLiTAonmwcj1wiJKPainVzLOKWuu+EvVz4FYrm8ZX2aEZXJAjyxJrjwtIgWRbkSl9HF750B8ZNfzUgzwV+TaqUPg3iqwN7Ox7LxVw1teYvkZRSqiYmDgmVU9uaO2zBOCv1HcVuz+cTiSjsQk7ivHrESvX7NVud9IXWjkMgczyYDvnvpsnPpeMo4vyF8A4xwp0Reeue7J426iFAi2antBrYnaEDerowQ58OULKffmtprgvlZqMySEKrou/kRltbAnVPzeF2lPXDf7sGYqX09v/2VdUhBwE/zEzHtpTwdaLQVHX7qslc1ZDtFdTts8sT/vBpUYy7eBEUFMeDLLATwCzKkUnDmm3LJs1TdbpssJcinvIh9zOmiga6TlPuUx3NRZoouFs8L/9GHwg3lKMWIbA8Y145GpeXAPNVP8i0houdinICnaiKYTM5zQNJ/s8dCHiz01QZrmSB5T5x1TgEPupLYwYu8wu8bF0KeGZPtT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51fg+2/DVh64tGNcUveJuAnW6ZTqAB9jtIePL5v3uX00QhaarXnSDaC3x/oGKaBQWtJchT30OwJSWS4t+MLpTNzz5znrlyi32bguQkv7pxCoAkg++9kyIJUwKxQwgLmQ4OHRqQrWGLa3ZTZrx+fYN9uyjmiy4VwRdtyfsKgoonK+2h9bl1iJ7p4Wt1wQa+kcN5DtaJ 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: From: "Eric W. Biederman" Implement a helper elf_load() that wraps elf_map() and performs all of the necessary work to ensure that when "memsz > filesz" the bytes described by "memsz > filesz" are zeroed. An outstanding issue is if the first segment has filesz 0, and has a randomized location. But that is the same as today. In this change I replaced an open coded padzero() that did not clear all of the way to the end of the page, with padzero() that does. I also stopped checking the return of padzero() as there is at least one known case where testing for failure is the wrong thing to do. It looks like binfmt_elf_fdpic may have the proper set of tests for when error handling can be safely completed. I found a couple of commits in the old history https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git, that look very interesting in understanding this code. commit 39b56d902bf3 ("[PATCH] binfmt_elf: clearing bss may fail") commit c6e2227e4a3e ("[SPARC64]: Missing user access return value checks in fs/binfmt_elf.c and fs/compat.c") commit 5bf3be033f50 ("v2.4.10.1 -> v2.4.10.2") Looking at commit 39b56d902bf3 ("[PATCH] binfmt_elf: clearing bss may fail"): > commit 39b56d902bf35241e7cba6cc30b828ed937175ad > Author: Pavel Machek > Date: Wed Feb 9 22:40:30 2005 -0800 > > [PATCH] binfmt_elf: clearing bss may fail > > So we discover that Borland's Kylix application builder emits weird elf > files which describe a non-writeable bss segment. > > So remove the clear_user() check at the place where we zero out the bss. I > don't _think_ there are any security implications here (plus we've never > checked that clear_user() return value, so whoops if it is a problem). > > Signed-off-by: Pavel Machek > Signed-off-by: Andrew Morton > Signed-off-by: Linus Torvalds It seems pretty clear that binfmt_elf_fdpic with skipping clear_user() for non-writable segments and otherwise calling clear_user(), aka padzero(), and checking it's return code is the right thing to do. I just skipped the error checking as that avoids breaking things. And notably, it looks like Borland's Kylix died in 2005 so it might be safe to just consider read-only segments with memsz > filesz an error. Reported-by: Sebastian Ott Reported-by: Thomas Weißschuh Closes: https://lkml.kernel.org/r/20230914-bss-alloc-v1-1-78de67d2c6dd@weissschuh.net Signed-off-by: "Eric W. Biederman" Link: https://lore.kernel.org/r/87sf71f123.fsf@email.froward.int.ebiederm.org Signed-off-by: Kees Cook --- fs/binfmt_elf.c | 111 +++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 63 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 7b3d2d491407..2a615f476e44 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -110,25 +110,6 @@ static struct linux_binfmt elf_format = { #define BAD_ADDR(x) (unlikely((unsigned long)(x) >= TASK_SIZE)) -static int set_brk(unsigned long start, unsigned long end, int prot) -{ - start = ELF_PAGEALIGN(start); - end = ELF_PAGEALIGN(end); - if (end > start) { - /* - * Map the last of the bss segment. - * If the header is requesting these pages to be - * executable, honour that (ppc32 needs this). - */ - int error = vm_brk_flags(start, end - start, - prot & PROT_EXEC ? VM_EXEC : 0); - if (error) - return error; - } - current->mm->start_brk = current->mm->brk = end; - return 0; -} - /* We need to explicitly zero any fractional pages after the data section (i.e. bss). This would contain the junk from the file that should not @@ -406,6 +387,51 @@ static unsigned long elf_map(struct file *filep, unsigned long addr, return(map_addr); } +static unsigned long elf_load(struct file *filep, unsigned long addr, + const struct elf_phdr *eppnt, int prot, int type, + unsigned long total_size) +{ + unsigned long zero_start, zero_end; + unsigned long map_addr; + + if (eppnt->p_filesz) { + map_addr = elf_map(filep, addr, eppnt, prot, type, total_size); + if (BAD_ADDR(map_addr)) + return map_addr; + if (eppnt->p_memsz > eppnt->p_filesz) { + zero_start = map_addr + ELF_PAGEOFFSET(eppnt->p_vaddr) + + eppnt->p_filesz; + zero_end = map_addr + ELF_PAGEOFFSET(eppnt->p_vaddr) + + eppnt->p_memsz; + + /* Zero the end of the last mapped page */ + padzero(zero_start); + } + } else { + map_addr = zero_start = ELF_PAGESTART(addr); + zero_end = zero_start + ELF_PAGEOFFSET(eppnt->p_vaddr) + + eppnt->p_memsz; + } + if (eppnt->p_memsz > eppnt->p_filesz) { + /* + * Map the last of the segment. + * If the header is requesting these pages to be + * executable, honour that (ppc32 needs this). + */ + int error; + + zero_start = ELF_PAGEALIGN(zero_start); + zero_end = ELF_PAGEALIGN(zero_end); + + error = vm_brk_flags(zero_start, zero_end - zero_start, + prot & PROT_EXEC ? VM_EXEC : 0); + if (error) + map_addr = error; + } + return map_addr; +} + + static unsigned long total_mapping_size(const struct elf_phdr *phdr, int nr) { elf_addr_t min_addr = -1; @@ -829,7 +855,6 @@ static int load_elf_binary(struct linux_binprm *bprm) struct elf_phdr *elf_ppnt, *elf_phdata, *interp_elf_phdata = NULL; struct elf_phdr *elf_property_phdata = NULL; unsigned long elf_bss, elf_brk; - int bss_prot = 0; int retval, i; unsigned long elf_entry; unsigned long e_entry; @@ -1040,33 +1065,6 @@ static int load_elf_binary(struct linux_binprm *bprm) if (elf_ppnt->p_type != PT_LOAD) continue; - if (unlikely (elf_brk > elf_bss)) { - unsigned long nbyte; - - /* There was a PT_LOAD segment with p_memsz > p_filesz - before this one. Map anonymous pages, if needed, - and clear the area. */ - retval = set_brk(elf_bss + load_bias, - elf_brk + load_bias, - bss_prot); - if (retval) - goto out_free_dentry; - nbyte = ELF_PAGEOFFSET(elf_bss); - if (nbyte) { - nbyte = ELF_MIN_ALIGN - nbyte; - if (nbyte > elf_brk - elf_bss) - nbyte = elf_brk - elf_bss; - if (clear_user((void __user *)elf_bss + - load_bias, nbyte)) { - /* - * This bss-zeroing can fail if the ELF - * file specifies odd protections. So - * we don't check the return value - */ - } - } - } - elf_prot = make_prot(elf_ppnt->p_flags, &arch_state, !!interpreter, false); @@ -1162,7 +1160,7 @@ static int load_elf_binary(struct linux_binprm *bprm) } } - error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt, + error = elf_load(bprm->file, load_bias + vaddr, elf_ppnt, elf_prot, elf_flags, total_size); if (BAD_ADDR(error)) { retval = IS_ERR_VALUE(error) ? @@ -1217,10 +1215,8 @@ static int load_elf_binary(struct linux_binprm *bprm) if (end_data < k) end_data = k; k = elf_ppnt->p_vaddr + elf_ppnt->p_memsz; - if (k > elf_brk) { - bss_prot = elf_prot; + if (k > elf_brk) elf_brk = k; - } } e_entry = elf_ex->e_entry + load_bias; @@ -1232,18 +1228,7 @@ static int load_elf_binary(struct linux_binprm *bprm) start_data += load_bias; end_data += load_bias; - /* Calling set_brk effectively mmaps the pages that we need - * for the bss and break sections. We must do this before - * mapping in the interpreter, to make sure it doesn't wind - * up getting placed where the bss needs to go. - */ - retval = set_brk(elf_bss, elf_brk, bss_prot); - if (retval) - goto out_free_dentry; - if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) { - retval = -EFAULT; /* Nobody gets to see this, but.. */ - goto out_free_dentry; - } + current->mm->start_brk = current->mm->brk = ELF_PAGEALIGN(elf_brk); if (interpreter) { elf_entry = load_elf_interp(interp_elf_ex, From patchwork Fri Sep 29 03:24:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13403636 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E48AE743C0 for ; Fri, 29 Sep 2023 03:24:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE10B8D00E4; Thu, 28 Sep 2023 23:24:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B68B98D0002; Thu, 28 Sep 2023 23:24:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9227A8D00E4; Thu, 28 Sep 2023 23:24:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 79C0A8D0002 for ; Thu, 28 Sep 2023 23:24:44 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3874C1210B2 for ; Fri, 29 Sep 2023 03:24:44 +0000 (UTC) X-FDA: 81288192888.21.B43357A Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf10.hostedemail.com (Postfix) with ESMTP id 4D729C0002 for ; Fri, 29 Sep 2023 03:24:42 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=JDBQ5xum; spf=pass (imf10.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.170 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695957882; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oGhwDBPbCWZ00dYqQrvOzcYwuI2lZJAyT/mcJzKB6R4=; b=zy6odpD2rRS97YNbyqpdnjO7kWxRD9X04VsSkBGt0MRq/1M56wYE4PnI/h4wlTkD0vodbv dS0OS5fF/yboT7ZGzvvt0xcD3A4kJS0Lrs2EwFZBUzs3ofGso6GibP6b1DGGqcmOEtVsQb QHlXntAP4DUVV8SWLei+dzYpP8mlahE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695957882; a=rsa-sha256; cv=none; b=IIVPJow8VrL4SrRVnVW/ibfEK71o1Wjcc88oXY0LSgdiE/CndOyzyVBHcvJ7YhqVpj+TN+ aO/Plwh0LJDdTZ3xvwS41tTBBPLQ2q1brQLso4nNzhNXhsavHrnwAqnO4adQaXitTa3fCH Zlr8lwaCYlfJwaCxpktINCZFAK6WBqs= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=JDBQ5xum; spf=pass (imf10.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.170 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-690ba63891dso10738747b3a.2 for ; Thu, 28 Sep 2023 20:24:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695957881; x=1696562681; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oGhwDBPbCWZ00dYqQrvOzcYwuI2lZJAyT/mcJzKB6R4=; b=JDBQ5xumsYZxnqJbzOq2DoVWESqRfCGjfZhN9V1X1xrPc4xS0oosVAE5FYzrtYAvDk qF2Ik0c/Vrx3pTMjNujFAcjJE3j51UmqF+l7F7OyUZlAHBh5x2yGJEHVYr4BmkX4Gs0k sPKKBB4TjjIr8J+toe2K67fscDKH+kPHs91Ew= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695957881; x=1696562681; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oGhwDBPbCWZ00dYqQrvOzcYwuI2lZJAyT/mcJzKB6R4=; b=Nr8yaMlHvGkhfM1Q8tgeVhRfuK0lDPitIV/G/JmCq0YTG5hHa3yDrl2eMPBBhOIx0w N3Dg1b4cZf+a90yqk2zLayAudsVrDsOTA3Wq/85zX2fHUNQKjSOGdaA6nGx9SjvGJ9K5 VftzJEwO3JjUvLr1dHYjeNkscHL8LGVP/c5ROOTZZ6oMfAT5TRJ6AlXRqevMtKRJIZjl xB0GXh4kSA3LEhMAp3T4QXFTCd31TcSxxO+f26HVKV1fl6qF/chTA4WVOrat+0Ua9Aq3 9dK/PvOG3IPdkTKZjVGpqhoyJLI3iVarwDQ+EmGPUNBIUa+tnNA0ZyOkeX0oTb8m2apo ckwQ== X-Gm-Message-State: AOJu0YwOniPcB54liH/3ei7aEkjDljKcuInugguLcDpNbeOi3fj5jdep z4YrZAbIUOE4YRWnSIHgHd9Yng== X-Google-Smtp-Source: AGHT+IEefjdEHzDxwiSxbmO/u6TF6zB5AljlbT04olaKMdKQR8C/b8AJwKo7ESYTNvbBR3eWZ847tQ== X-Received: by 2002:a05:6a00:190e:b0:690:ce30:47ba with SMTP id y14-20020a056a00190e00b00690ce3047bamr2938508pfi.10.1695957881184; Thu, 28 Sep 2023 20:24:41 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id s26-20020aa78d5a000000b00672ea40b8a9sm14427552pfe.170.2023.09.28.20.24.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 20:24:39 -0700 (PDT) From: Kees Cook To: Eric Biederman Cc: Kees Cook , Alexander Viro , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Sebastian Ott , =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= , Pedro Falcato , Andrew Morton , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v4 2/6] binfmt_elf: elf_bss no longer used by load_elf_binary() Date: Thu, 28 Sep 2023 20:24:30 -0700 Message-Id: <20230929032435.2391507-2-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230929031716.it.155-kees@kernel.org> References: <20230929031716.it.155-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1738; i=keescook@chromium.org; h=from:subject; bh=G8gKivjP+bPsGdacm75CduzZVarN6sAt0dfrtCVUjtY=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlFkNx2BuLhX7iIAkgIu+LW3P3r4pxnZlwRaDRf vA/0AICBj2JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRZDcQAKCRCJcvTf3G3A JpKyD/9/zd7E+5U1dJPLc6FAk+4qelFfCB75a77Kwxx0x/dnFrrOEedqqpaOK3ve3TybifJrVjE h8wTDDoxua66DT705EB1I4t9hKVj7ivb1dRVQdU3WehX4HAJzhPWJ7EtDjtX4AeM5D+Hf7hDpz4 hfwpwEYxXXAs73zeYWM19Na85lFwu6nSgf/ttA5F2ewH+beQAvHkMQN6gO9tp95OrFyS1MZdXBI NrkU9qg/ruk3uLO2OsVV6oDaLOu79M+4Kf6narATryoLsN4PLTkC8vQrd2qtvfiFgrJMPpbfCn8 mEteP/5U+mKLFaCYdxhauFlCzaPVAwvY9GsSaOxsm+ilLLoz76BgaZJ3mTlmC1hryS1DfX5TNYm BmEtiulolRPfz4jsO8ynBLlG9W3OMzNzN8tAFwtRv5C9pp0Y+Fp2Q4+kBwt72QGCQLH4GAe0o9t m4EhUZsGXS3t3VJlwU/3NoxBNO9bz5DuQRp5K6qTCwsnbFMQXMIL3xR1Vd0jwfPPrscAtd+3IlT pbesK8GLRSzYSy4YOE92dGY+Av5QlXCA+DMcppAI/si2TTqnM19+SkKDASB7HwxP2YQiCADAV3U 67MufnT9YBLfq2RWMu1o2nR3+x4f5uWbDtEvSPRE7Ki8QD8I5Ldh64XqqxhTjKdmqEPIl7TvgC2 QoH6u6C/JkEFAwQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Rspamd-Queue-Id: 4D729C0002 X-Rspam-User: X-Stat-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7H1gOChJI+slF8VbWAze7ihmQNfo/D8s/3fs/jHrPadxfbJIn5o0m+vzCR+aX3fOas46JEUZr1jFzcxXuMpnHiOqLWMBDnUmL+RdfWc7xo3ZfGbQMQs4GiFFq6R+CsQuK5y3FTOuSfEwePP0N3g+3S+WTXU81jHahkVyobAIccufDOrq5FK+1+WcMd5lm4S/L3mOkX8bpF1ybfW1dQTx6ASnVxjnXknxUbR99cWdvK++vwXWQfURZrhExVbcp2I/V3GIhIxXIl3EGiotGHTGkJgoyn7gJqBlpfNGunLXwwZi/+du3GXYM/iY//ladYmGdzdJpkLnmlS4H/IOeS+j8Rvcuvdz/79xBRjcXPtFNMwbRZ14Ppr13FKyu32UmTHsgd4/P+c51iyP9+r500T9bQqCf64uvdJO8iBD1CAI0KULTYt257LcKgYvm+B9LA4qV+PKVe5Fn22Zf6hBW7H3z8asvZzJdlp2FuLRJsAWrhxVmWaALHr3qunBRzMtbmxksMW/jjwLAV3sqsNbqowyd6x9ARJ66h58sntlseaEMtdK/OkrKwrGsipQAaVdC1r5vMi4gudzrenfy3F2fs6i3lxBVi6U3GensbDZ8qWK2KRu7/yMuzx+cJjyn0R5aTyitL7dNsiiX9Zib+TabYyHDnuoICWexVGDhvZAFshzQcxptJRYiZhoru0L4xXyeybJiio99o1s0D7gm2RK90hiWbnkx2fc0YjTcv9PJo7BZMUP+0WHPEJ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: With the BSS handled generically via the new filesz/memsz mismatch handling logic in elf_load(), elf_bss no longer needs to be tracked. Drop the variable. Cc: Eric Biederman Cc: Alexander Viro Cc: Christian Brauner Cc: linux-fsdevel@vger.kernel.org Cc: linux-mm@kvack.org Suggested-by: Eric Biederman Signed-off-by: Kees Cook --- fs/binfmt_elf.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 2a615f476e44..0214d5a949fc 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -854,7 +854,7 @@ static int load_elf_binary(struct linux_binprm *bprm) unsigned long error; struct elf_phdr *elf_ppnt, *elf_phdata, *interp_elf_phdata = NULL; struct elf_phdr *elf_property_phdata = NULL; - unsigned long elf_bss, elf_brk; + unsigned long elf_brk; int retval, i; unsigned long elf_entry; unsigned long e_entry; @@ -1045,7 +1045,6 @@ static int load_elf_binary(struct linux_binprm *bprm) if (retval < 0) goto out_free_dentry; - elf_bss = 0; elf_brk = 0; start_code = ~0UL; @@ -1208,8 +1207,6 @@ static int load_elf_binary(struct linux_binprm *bprm) k = elf_ppnt->p_vaddr + elf_ppnt->p_filesz; - if (k > elf_bss) - elf_bss = k; if ((elf_ppnt->p_flags & PF_X) && end_code < k) end_code = k; if (end_data < k) @@ -1221,7 +1218,6 @@ static int load_elf_binary(struct linux_binprm *bprm) e_entry = elf_ex->e_entry + load_bias; phdr_addr += load_bias; - elf_bss += load_bias; elf_brk += load_bias; start_code += load_bias; end_code += load_bias; From patchwork Fri Sep 29 03:24:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13403635 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1E4CE743DD for ; Fri, 29 Sep 2023 03:24:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A6038D00E3; Thu, 28 Sep 2023 23:24:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1579E8D0002; Thu, 28 Sep 2023 23:24:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC2B38D00E3; Thu, 28 Sep 2023 23:24:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DC68F8D0002 for ; Thu, 28 Sep 2023 23:24:43 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A19481210AE for ; Fri, 29 Sep 2023 03:24:43 +0000 (UTC) X-FDA: 81288192846.01.3587D9A Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) by imf03.hostedemail.com (Postfix) with ESMTP id C8EEB2000C for ; Fri, 29 Sep 2023 03:24:40 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=EvTRaDks; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf03.hostedemail.com: domain of keescook@chromium.org designates 209.85.222.172 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695957880; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7JCtI6Mw9jLbpCfzTWeYqaol0MCiq7teZQqSoN5bxO4=; b=Dx5EAA5JLQ70+kkm8BOc+IvQt7E6+l1oGKWtbUGf43rZ+ckc9nan1dD5PAIXF8w9YuQGjl HCdRkaKCKhLOZ6LX9sm2XUMLDW7ca3VW0jgPwD+Fdhs/1uhnAuXspkPDgqsRzCi6Yg3iCx SCwruBTKTXLM1Z9AykcIm41x34S0Kf0= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=EvTRaDks; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf03.hostedemail.com: domain of keescook@chromium.org designates 209.85.222.172 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695957880; a=rsa-sha256; cv=none; b=I++OvAZsM0v2cWWD/cA470iACgW1MYQxkK1GbvGk8w0FyED/8HAa8ui809l2qc1Xdgj7r4 XoBi9fS+vPu6BGzoARqqalOQnezIrvL/5AbNg+8fyUWh6tSKr+hTQCMpPqJv/97suZWA4U 36TXBqaz+faasm+9p8VdkXs71lP5Ayg= Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-77575233636so248818785a.2 for ; Thu, 28 Sep 2023 20:24:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695957880; x=1696562680; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7JCtI6Mw9jLbpCfzTWeYqaol0MCiq7teZQqSoN5bxO4=; b=EvTRaDks7UaEIClA0VisDf/7VnmILHUpHYZ2pFxTtYisNTRKcZfrUpLGwvQ8D5oySv naTZDAPfrTuNuRlTeyY1BYA9P1xXb8kvqIW7hCBrETy312Pt+IDOaIGN8x0FKLnDjc5d 3VnRxh91YV0699FQLyT0kkPy2jx5pl89SevQE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695957880; x=1696562680; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7JCtI6Mw9jLbpCfzTWeYqaol0MCiq7teZQqSoN5bxO4=; b=YtejpjqKhknRyYKnyi/n58BoDGnic4WiHFxJOESkWPAwcI2RjiK/Wa/g9sEG98ggD8 hh3e3GJmweVtWpE8K01AHacJXo0vJYIN9TZeISzM/y5RSYqMLa43hWOBLjz4APG3xQ4Q DCKLJL09SM5udxjkP/AJ5RbzbWy7yr2DbChpEVfhBjFLEydA3EtGN8z2l1eqJOdNFRM/ f0lGsUQ3ex+ICVW1mkKF/uEPwseSPlvp/9qnHp4oL95p3jhRT2pYUPC/4BqL8W6HCX9M 54owbfH6TpTkGWGyAyDPCD73EaYImukkO9+XQHAy0zKuhnRCsED1SAUuPog+PwTfVi8g GG+Q== X-Gm-Message-State: AOJu0YwxE6IoaY2uFESMhmjtbc7oBi727yfcTPw68fK1s0ASflACLroE 20WV5R0u0+4S8NNzXY93YvxiOQ== X-Google-Smtp-Source: AGHT+IELcqZMMKb1td/vncjB5sH12I54PHU5TdsvQyhNwOMv+fB/QBhAjEGhxQYK020wITjebfX9sQ== X-Received: by 2002:a05:620a:e9d:b0:772:6443:daf3 with SMTP id w29-20020a05620a0e9d00b007726443daf3mr2738735qkm.66.1695957879917; Thu, 28 Sep 2023 20:24:39 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id du14-20020a056a002b4e00b00690fe1c928esm10256201pfb.91.2023.09.28.20.24.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 20:24:36 -0700 (PDT) From: Kees Cook To: Eric Biederman Cc: Kees Cook , Alexander Viro , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Pedro Falcato , Sebastian Ott , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Andrew Morton , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v4 3/6] binfmt_elf: Use elf_load() for interpreter Date: Thu, 28 Sep 2023 20:24:31 -0700 Message-Id: <20230929032435.2391507-3-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230929031716.it.155-kees@kernel.org> References: <20230929031716.it.155-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2936; i=keescook@chromium.org; h=from:subject; bh=8mN64ZnApkL7mlS3J3j8M/PeeHjiU24xpvEFIwO52Sc=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlFkNyQ5p5E4Tg789OjEFFGvDw6hy8O/CboaqJO +gn/YtsP02JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRZDcgAKCRCJcvTf3G3A JlfrD/0UmFIiwvqM26CPsRIStoMfmoWWLE+1T0+B6VIpoHHYl6fxgrYIk1GMjuaGbD0RwF9QP+t BqcWROGSbE7jtsk5rW33lmv5P4kATjv1E8P0xTh6YLwy/qmxm1iBcqH7A7aIp5rT/ZZxmRWS7z/ KaumFG9s9XzIzz7vNtyCpYAslNBn7Ct0D760d/KdyUyF0tRcwUZGbbqsCSJ3qDlqi9Oh48d8rqr zVrOdBbcoN0GFz2NFhwg1g0iypiVC72gYNSKuCVuYoSflzMWmk+MWWz+KoGHh8QQyufk09tUrRt 7e7QzVJPtxRfKGiVSBnbT7mPxw87BCa7B1z+sX5Sj7D4++z7rbKsnwJGiOeSn9hRsn3zwU/bHKg 2VugFFQ+5/llgN3z58QGPu56dO6ydWYCZeneBcrQoNc1xhZyz8M2IpA5m0iJS719hxg22R2fW1p xaQITu1kMm0y6BxdReD/XHhw3eM0HzXWV9ltG8nLrJXOVz5Ve3z1wcEusMGPOh07NsX6dEfXDJv XYtMF21/+UxnZ3eYxaWMHimE+Qo2DtB694DxSqJhwRK4FB4KUShHOAsbSQTcGSzXCx13gP3vhF0 S8eSoWkYBz90zkFWSPCcyq4F9jfXjVmVgHQgU/leUKWz2vDzeEVdmX04CQNaCQPS6MFWyGJaKml bTMeDeMtwCCfvfQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: C8EEB2000C X-Stat-Signature: 8sh5zfo656pyjxr759k34apnuaojs4if X-Rspam-User: X-HE-Tag: 1695957880-992678 X-HE-Meta: U2FsdGVkX1971UaTy+0KF2Ub9svMj2DP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h0X1aY7dXL2dSqLA5xo/RK0zxdwopWUXe4MmltyAlcbcFyLaU9ABv6O0HqIIzyjsOwOEYXLiQgWR/1Pks395PH4awtXVcuYDsa3oS8iI/0HTdZiNbgu7yDi4SH+RBQNnw1ecFNzW6w/BrkVup7OaaCRkHs/CevrUTWaT676qvESfPf/mn8jSE2XyaELg54Nq8j3Cn94lBD8l+d4+ozVUmq6VtDhi9nygS9u+Lw3qWXDrJBLl7LOzCu7SOKpFmztX1vnip1LcF0v6cjBBXm/dAUuEVJTunw/2vp13z0eN8dcRusXW80F75HcgeJBr0Mh4BUaOX8SjsJwarwQiBcz5tr1hrj0GO9Qao8blRfeEGAkWorcR5zNavZGqAfyzQfKJBYf337ch2DTs0BZHo2U8/IAQW9pjAcErVITIxA0HeEAy72ogj7AkTKbc5/Ty23T3Fu1weO6Nv6YFIfv+OnMNBDweOiDurk31OTXVOU1gGG7E2EP3s72uEPJDJe6RAJiKj6pRF6eCfxkEpHWNceBItkI37IWyw+7XIzRN1IJUIARS1VITSavrjUBJ4VlVstNGlckC2ddbc9KS5LJuPbjGqCHjqplCJKnCDq+hqoHZJPs5qktBvjYhrb5AukwUlOGs7JQ36BSwk/EXGVuG168Pby6xM84lxSg== 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: Handle arbitrary memsz>filesz in interpreter ELF segments, instead of only supporting it in the last segment (which is expected to be the BSS). Cc: Eric Biederman Cc: Alexander Viro Cc: Christian Brauner Cc: linux-fsdevel@vger.kernel.org Cc: linux-mm@kvack.org Reported-by: Pedro Falcato Closes: https://lore.kernel.org/lkml/20221106021657.1145519-1-pedro.falcato@gmail.com/ Signed-off-by: Kees Cook --- fs/binfmt_elf.c | 46 +--------------------------------------------- 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 0214d5a949fc..db47cb802f89 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -622,8 +622,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex, struct elf_phdr *eppnt; unsigned long load_addr = 0; int load_addr_set = 0; - unsigned long last_bss = 0, elf_bss = 0; - int bss_prot = 0; unsigned long error = ~0UL; unsigned long total_size; int i; @@ -660,7 +658,7 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex, else if (no_base && interp_elf_ex->e_type == ET_DYN) load_addr = -vaddr; - map_addr = elf_map(interpreter, load_addr + vaddr, + map_addr = elf_load(interpreter, load_addr + vaddr, eppnt, elf_prot, elf_type, total_size); total_size = 0; error = map_addr; @@ -686,51 +684,9 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex, error = -ENOMEM; goto out; } - - /* - * Find the end of the file mapping for this phdr, and - * keep track of the largest address we see for this. - */ - k = load_addr + eppnt->p_vaddr + eppnt->p_filesz; - if (k > elf_bss) - elf_bss = k; - - /* - * Do the same thing for the memory mapping - between - * elf_bss and last_bss is the bss section. - */ - k = load_addr + eppnt->p_vaddr + eppnt->p_memsz; - if (k > last_bss) { - last_bss = k; - bss_prot = elf_prot; - } } } - /* - * Now fill out the bss section: first pad the last page from - * the file up to the page boundary, and zero it from elf_bss - * up to the end of the page. - */ - if (padzero(elf_bss)) { - error = -EFAULT; - goto out; - } - /* - * Next, align both the file and mem bss up to the page size, - * since this is where elf_bss was just zeroed up to, and where - * last_bss will end after the vm_brk_flags() below. - */ - elf_bss = ELF_PAGEALIGN(elf_bss); - last_bss = ELF_PAGEALIGN(last_bss); - /* Finally, if there is still more bss to allocate, do it. */ - if (last_bss > elf_bss) { - error = vm_brk_flags(elf_bss, last_bss - elf_bss, - bss_prot & PROT_EXEC ? VM_EXEC : 0); - if (error) - goto out; - } - error = load_addr; out: return error; From patchwork Fri Sep 29 03:24:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13403634 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9772DE743DB for ; Fri, 29 Sep 2023 03:24:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 464EA8D00D8; Thu, 28 Sep 2023 23:24:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3ED968D0002; Thu, 28 Sep 2023 23:24:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2673A8D00D8; Thu, 28 Sep 2023 23:24:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 177CF8D0002 for ; Thu, 28 Sep 2023 23:24:43 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DBE541CA4B6 for ; Fri, 29 Sep 2023 03:24:42 +0000 (UTC) X-FDA: 81288192804.23.FC2CE76 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf08.hostedemail.com (Postfix) with ESMTP id EFE26160004 for ; Fri, 29 Sep 2023 03:24:39 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=CBRYFhRU; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf08.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.170 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695957880; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=95+jGh9HzPfjIjeeQbyhCMVgDdqV+t+zi0ml5yOYuB8=; b=CeVzXhjd1XYrLJKeM+uUf62V5D6WTGHR1ZPFCaK+TvELym7NGAEZZxzvDFvh6T5AHE+L14 C5ti7wVWgFBuyIyeB3BCabvdeBoaoLCRgEqr6AP04FZXHliBV+tUKbKYTswPsVt9BtgjNP JzVlY3izrZUFBOceSR4bMrsYJdTDNFQ= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=CBRYFhRU; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf08.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.170 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695957880; a=rsa-sha256; cv=none; b=4BnsB1MdgnBD9pqfQTGpZSWMUzXpOagJEFyq7T2Q3fSdaZUcRSeNRxceE6tabz7ScnwesI C4OiCFhBQ5gbq9/jcc2ZpC26fg2S/jk9UA1Rt/ipBwz/Dt6MEs91OiGm1jZyVr7WeTyPk6 qVmRkvtWQq5d1WqYNZsf9c07sVI0O+M= Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-68fdcc37827so161779b3a.0 for ; Thu, 28 Sep 2023 20:24:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695957879; x=1696562679; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=95+jGh9HzPfjIjeeQbyhCMVgDdqV+t+zi0ml5yOYuB8=; b=CBRYFhRUOHiXqjAXnpymsWaxoXdPfXncahWlw8Ybkjp5lYDaRCSi0/xZ0Ng/xIIK1r wZvUuBqLphQDSNzYfciCMKazMl1ZDgUPlL/5KhU6kkQ7pHA65XET20FBygYMiMdtIuO6 /MJIv+qo/zXCeNLo+Qd3v17XOi4X8F4MLIGC4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695957879; x=1696562679; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=95+jGh9HzPfjIjeeQbyhCMVgDdqV+t+zi0ml5yOYuB8=; b=uIqXRZQWx5IK0xbJbYJCNDpwlIcSN/I29NCJK+sR62gykV4FjMvS2NghHInVGciogl kqG6V5Rw2Mjc15IAY89ndmdOi8BPkN3IbEJgmXCeBhdrH9kdLw9SJfjiOtMEEnq2OwP5 44B63P3OlluR22rFEWq4Kbzwh6l5Zm9vh1sEmlRhnmhxCYJJOPoWGpVmyK4EBoXs6jbp AOFSZpN7dOXo0o54aL5/WXdjz4gs67GXA49ciRY99II3+QsvMgSKdhcVi5zPQQsKROTI e8eUgCt252UwKT4oEqe6u70f/SDx4BGITXzJKK04hnrAbuymKSo4V9wPP6zMKRPu+jmF gRiQ== X-Gm-Message-State: AOJu0Yw8r18IPE/AlO5PW39ZlIGZ31rbu0fTjiS1POt0tZfAMqUIOCyD TXxnVNyZLNrQWTZCJL0MvqVCNQ== X-Google-Smtp-Source: AGHT+IENptQn7XIn+gHi7Xk/Rom3FrwjZlYNl2dbdfUf0uD5PWaNHfgd4GwUs3Rvuj8dtt6Ixw6ezw== X-Received: by 2002:a05:6a20:72a5:b0:153:4ea6:d12e with SMTP id o37-20020a056a2072a500b001534ea6d12emr5304382pzk.17.1695957878823; Thu, 28 Sep 2023 20:24:38 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id b5-20020aa78705000000b0068ff267f094sm3481738pfo.158.2023.09.28.20.24.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 20:24:36 -0700 (PDT) From: Kees Cook To: Eric Biederman Cc: Kees Cook , Alexander Viro , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Sebastian Ott , =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= , Pedro Falcato , Andrew Morton , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v4 4/6] binfmt_elf: Use elf_load() for library Date: Thu, 28 Sep 2023 20:24:32 -0700 Message-Id: <20230929032435.2391507-4-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230929031716.it.155-kees@kernel.org> References: <20230929031716.it.155-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1627; i=keescook@chromium.org; h=from:subject; bh=HDRWJgiZi2B41NjfcoHun/GXVPB8PhMH+K8nRgD/QEY=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlFkNyd7onj53UAnvTrNuqjrOoqdzlhhnL6T0n4 waDipxrCuyJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRZDcgAKCRCJcvTf3G3A JgqhEACQaxzh9TUbPcDbZo8niTtocmDdmljr+QUAo/kUcZsO7WwVGlruTUeAl3DsFH2PvI/7f8q 6Gzf2F516CRNsoFBvkxeJHFWa21p4CjiRwEYH+rdFGIQwe4ZXPrdSrcJhWVB35JNjqR8CK/aRK2 NAJeh7WuuaTnpcDhFmPiXWQuRt1noAczm74SRZU8IZ06ucQ49FNFgl7FPCGA0RLuWRQDEc4zXaQ BQktUi2h0of64YlxMdZfk+SQMGz2lOqO7a3F8Zy9PazbSnHb5k2NrkreHnNxtncdID9uE6SiKy+ JVJ8/BMveYU1W8I+asdhp8xe2CV19g1Qmlq4ZVCoeGxeV9OtFE+c8gjwaTlFdRjzRgfVqvqVmtp OYM3ExS5b6+tEeavoEpUw88foXpj9yoZLMwL8pVfsXc2FYIlPsrtaFfUyacQhttqevffosf/oUf bksChMr+i07cgy1L/yGOx/6wCfvU8HTwH+VMXDpSSowba7S7GbBmvxw9EtoVWjqJAGNdtQ6FvJZ 6SXLe7ag42PtcuMWe8C14GuF1yYIcvu/o/vpy24R3zfZUovoJAGPuns5yKBok4/GV2c31zPoB/p 5ZXXOtl28un+F7p/qF9lnnk6I8GbyO4YgCPqLeXph77PUUZfI4r38oOBt9/p+hKk0yQ+7nD6eH+ 8MpI/toIRLPKXkg== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Rspamd-Queue-Id: EFE26160004 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 8ms4x4jxu4cjxieyk1yo1mexmf98uoaf X-HE-Tag: 1695957879-488806 X-HE-Meta: U2FsdGVkX1+9Hyst2to69+g4wWG+/qtrcg5a/0xTNAk+I3dss+1ziLYQY9G53vnFdHMjEJoKQbu91yWGAnTigzE/G+rjK4lDXXJsNuXwZIxRK6FDcrVFL4fxVD0t9IsUeh1Ds2getL/3vyYErKUlbzEofApEvheWv8pd3QE48+35iQwjVeyqrZD4V7BzycMy3CTTLSLdnvHjnDrQ1o/f9iSz3RIRt8brXXL/yKBriyuXR5aAEuAU4ycQXhN+3q2dGORNTaPS1YK+umDLBUOPpm6hz9gnTrDU/roFKJmtnBk2MfKIk7banLNmWueu+vg31eY2W/agcEBSZBytoJTBozJtgA4rRsS4ty6hzJq/Au9r8kakaUAUk8k3NgdoYGhn4sSjSOHBAskKLdrGzak2pJcFZUta2szRFX0P+9llSJWK0Pp2BbLXn04p1VoctlE7Y7/QP1+A8jG5svBj1Phyvrwpi0pFlKsGKp06pgjV7haWUkyqaN9pTH4FeXESneV4s1v/9j3fDYncp1xguBR3wupgzf/niDlA1ShFPQLR9tJEzboQISNnFFILimJ0xE4Cu3bqM7Lk0R5crmk5p0SUM8gXT4UTm35ypdac2xs9T1QrMDaFHs3nQdCHgapibsu4NLfCr4cr/yL6gejwRxGXrbkgOkFs712SaYov2wzKyicjts5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: 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: While load_elf_library() is a libc5-ism, we can still replace most of its contents with elf_load() as well, further simplifying the code. Cc: Alexander Viro Cc: Christian Brauner Cc: linux-fsdevel@vger.kernel.org Cc: linux-mm@kvack.org Suggested-by: Eric Biederman Signed-off-by: Kees Cook --- fs/binfmt_elf.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index db47cb802f89..f8b4747f87ed 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1351,30 +1351,15 @@ static int load_elf_library(struct file *file) eppnt++; /* Now use mmap to map the library into memory. */ - error = vm_mmap(file, - ELF_PAGESTART(eppnt->p_vaddr), - (eppnt->p_filesz + - ELF_PAGEOFFSET(eppnt->p_vaddr)), + error = elf_load(file, ELF_PAGESTART(eppnt->p_vaddr), + eppnt, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FIXED_NOREPLACE | MAP_PRIVATE, - (eppnt->p_offset - - ELF_PAGEOFFSET(eppnt->p_vaddr))); - if (error != ELF_PAGESTART(eppnt->p_vaddr)) - goto out_free_ph; + 0); - elf_bss = eppnt->p_vaddr + eppnt->p_filesz; - if (padzero(elf_bss)) { - error = -EFAULT; + if (error != ELF_PAGESTART(eppnt->p_vaddr)) goto out_free_ph; - } - len = ELF_PAGEALIGN(eppnt->p_filesz + eppnt->p_vaddr); - bss = ELF_PAGEALIGN(eppnt->p_memsz + eppnt->p_vaddr); - if (bss > len) { - error = vm_brk(len, bss - len); - if (error) - goto out_free_ph; - } error = 0; out_free_ph: From patchwork Fri Sep 29 03:24:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13403638 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BA51E743C0 for ; Fri, 29 Sep 2023 03:24:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4951D8D0002; Thu, 28 Sep 2023 23:24:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4133E8D00E7; Thu, 28 Sep 2023 23:24:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0BAC68D0002; Thu, 28 Sep 2023 23:24:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DC2628D00E5 for ; Thu, 28 Sep 2023 23:24:45 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A7B3B1A02A1 for ; Fri, 29 Sep 2023 03:24:45 +0000 (UTC) X-FDA: 81288192930.14.3B2AABA Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf23.hostedemail.com (Postfix) with ESMTP id 97728140002 for ; Fri, 29 Sep 2023 03:24:43 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="ntBMR/lp"; spf=pass (imf23.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.182 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695957883; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1N2/5RenlXFMtuBqo/+f8Vcn16/Uj2Iw7MwFuqiNorY=; b=LuDKsrXW17wTlDtEr8Icq5+KUdSjy0WBpAQ/zqsUU1AMOXyZhvHvqcrf7MRqKE8kkca0Xk rskM8bxZWkY8q0/4fV436adsSAkXA6deY38s9pOWrLooStdFwEHJRRHF9L4lBH894MrQeF /E5dN+QzfBdQXI97CDyXLXWFOSNp55I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695957883; a=rsa-sha256; cv=none; b=TE8JoJy1lBgupzjqlwrYzww7mOr55i+32dK8bTXbrIiz3sDczXw0Wqsj5lFZOvvCOTaQfm QoprrPgNCU00cgIfHR1D2jZrub3hTvlfF65Rhy0LVgv2ZGu0B0/kFkLT4SHOwJEEG2hsZB 45lY5Hl5gPjrWbIh8nkNComZJbBnv4E= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="ntBMR/lp"; spf=pass (imf23.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.182 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-5859a7d6556so408963a12.0 for ; Thu, 28 Sep 2023 20:24:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695957882; x=1696562682; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1N2/5RenlXFMtuBqo/+f8Vcn16/Uj2Iw7MwFuqiNorY=; b=ntBMR/lp02uGwMNPNU7KfJl07G94oa76TLF+aLe+qtKLfGBIj70zuOmFF8dWWIHBp6 XsjedNkqFCXaWSV7xOUX6Mwl9RKRaIWmurEXC2x1rtAZBcJ42d8SHbx50gKx99hxzI6I vxQQoIBpNbEcAfQsPnWTagbK/F5/aYne5uyAs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695957882; x=1696562682; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1N2/5RenlXFMtuBqo/+f8Vcn16/Uj2Iw7MwFuqiNorY=; b=ZPd0a/IVjSaW2AIZg7y2dhml2os4Gy5pMsFn5gT27cjs/kTeZpWTlvX74kiyQdMOrF bf9i++ztHwXLwjeDfyB+LzYLxNOBSUPJfMy8SLQO1gL8o5WaigAtynh75eCWkgZQQVvK 92DLaey1WSl8VYyijTjESbDnk2COyXkqPPRNEH+sV2NdnT0IR9NBG2KxSa8y84L11p6Y /KOw/UETfgwuVxS7BEnZ9xKYfTNTkiq2lefFhTPhtPazSHOs8Cbd1BUnp9XXijFdYzDs bTWIrLxebz3HNkYf89+p1imibw50zcKnqegxbLXzo0b5VkSAa7ThwlW7Xx2ewGEZaqIU 0cZg== X-Gm-Message-State: AOJu0YysjMRLpU/TxOpVqMVdhNNb2N73S6/MRoSpLZZUj00D5gt4v5fq PAAnWingzLg7cza2+6wmXF+jdA== X-Google-Smtp-Source: AGHT+IFuiY5V1hPcrjWZ+wALbwRJ0bkGU805RDV1GGRAKG36PeI1WQG0N/Q94yXBG5u0guRkQHN2ew== X-Received: by 2002:a05:6a21:6d90:b0:162:d056:9f52 with SMTP id wl16-20020a056a216d9000b00162d0569f52mr2317143pzb.14.1695957882509; Thu, 28 Sep 2023 20:24:42 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id d12-20020a17090a498c00b0026b3ed37ddcsm297774pjh.32.2023.09.28.20.24.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 20:24:39 -0700 (PDT) From: Kees Cook To: Eric Biederman Cc: Kees Cook , Alexander Viro , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Sebastian Ott , =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= , Pedro Falcato , Andrew Morton , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v4 5/6] binfmt_elf: Only report padzero() errors when PROT_WRITE Date: Thu, 28 Sep 2023 20:24:33 -0700 Message-Id: <20230929032435.2391507-5-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230929031716.it.155-kees@kernel.org> References: <20230929031716.it.155-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3206; i=keescook@chromium.org; h=from:subject; bh=jt1fmczJcOormxbVcL/G+gA6YgAS2bIpzH9lxZKP6J8=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlFkNyRwIKy/9+p28ZJ729vcNHK8Gg7yPfE0ByN 6nvj7/qVLeJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRZDcgAKCRCJcvTf3G3A JjvTD/0efjaJu1+PNkM8NRGdk1dsGyZJ0dd4tY+8HW5FWR8J7niOASg788NVSLqFFUmdhaHRjmO Lj56b26Bw9GOyQXHYda5l7wqDTMXm6RIMUYBjTHTuUu3K8IYicpe/vidGvDuun74TWC6gT0TcQS JBtpkVYUzN9Quzlr+hjKY4YwSAMa+50O1SYTdUGqwmckLYkIpbbwVLAo7r/VX4KL73ojipa0uZL U4Z96HcimN4eOgUTJL+Z0t4VxznrtCujhN04154vNUcC1vzmWqEyPkrIaegDJh86UloTxqH/Esa mEVSbpK9HjAWKRRsvhfOPp2btfPm3150XfvwHXXipw4qVDOWOWYhb7tHCVoYriEG/H0nn5qroT1 PIRndidx60sCNBiIR++8QGxeZhVypD2rtBlFMJYxk8hREnuCOUIUakD1s4SmYoqYAa/N6j10yfn USW7wazw7KE0x/SHGyklD7+FJFIHi/dFaGRXo6PdpXd2O8m/Fnh82Px9LxMZldJtVxrwmm2YcUb AIegTgqbd3pR1GCUvhncdf3yEUBwywr6llI4pfc2Bpc4oznxAVKNeJoY5hIrwCbXVKuO54wkBIg dP9Sl+hc6k26DlLVynWraFAeBWkU+QBlgtEZI18h+WBXWKlb9zkdhbKOcrAovas3JG4CcT3Onsb u68NsqyzQBTv3nw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Stat-Signature: fa1jqp53iubdseawtt47braouqj4ynxx X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 97728140002 X-Rspam-User: X-HE-Tag: 1695957883-556633 X-HE-Meta: U2FsdGVkX182hv8webFYmKoWJ+BJyUANBpgH0Y7k5Qh2AQv3sbXwhD6XKbp0PIYVKIBfo/Xdg93jj61YYlY+v73V/6eYImOR0kODuPfvH3Kj9ckr0gWVfGIwqPg3bbBTeHXQa0sU64CrtcBAB6lSQaoikQITBVj9vu2Zovwf81V9e6gJH3/jb6Z5IajVAhEARheGceCeSrPrOc9eY4Q7sh9zUsxDSV1FRNbVOZAbiKFtRnUlmslp2zyaXQx1ZyP0JiXaTKaXw/HhX3CA0MaWrFFkuWpq4lXL7U57ELHi/uETp3N+RLjk+nfCVAhXPL0OYj1vMhpQc2O+sINhtZEKlHjhFc4YxAh75IjErBwcSYy75hz0eqjTtDiBkB2MlFo7/xgEKdcEBqvor7Dz6XcL/AnVSOi288ceRNNIqQQYfxQhyIW3c2+HW5BwjNpO5WayobSQoDeeaUBn+cCgPiJfO094Y3uuxunDjY17MN5zQS2y21jTUIcjZYPXVOINXWCQykkjyQ6+eqiy45xPUA7xgkwFm/qA1PC9WsgDGMk8rWoC3Rq6iafouVCADaHvbp0FavhmDn24fBE4ecC7SI8mlFbeHS4dcBJat0Gdw3xJ9J9LA/4I7DsxdAg2k1FHDXwxHzyvYbJQ/trl7jvbLFYXH2LposbNYr3CQE6otCJ4pEIsp1OplYnBbEREa3hJ9V/qOhaX8mKrA5jI0BHXfwBSGRAufKHqeJP/oTAWTHCMiYyQAO31nymEl7hTzgGbfXukGSqhGCX1Y9t1F73ZNz4VSp81sMLsQwm0wzW4IDRm9JZRM3AIlQYeNj5LYrS3GBy8yUFtjslKQReOghfYRMyWotiDfrCQl3zxn+hZGF58nH/S5jySb5mjqn/puxLa+e5IEAPkt6J/gHo36pv/ku996V3pvDoqznijEbENA5v+L48EOzxxHbKSeT9DBEtvC1Sljux12BkUSYFV2voCBw3 dYIYtHQm L4ufDBkvSll20TbjJMgkCf4jprqACPUIjAiDC3ipIoknSd8f96bun+FS3KhgHt947YguvmqSUpSVHb2FHolJsFxHXoBrOMoAsRpIcykeV0AC9B99jVfM88HC2v514gpsgQXPqU7O3JDE3Pbekk4ctCp0nFyt1EnRZLOAHljdmZcA1KP2IjuaBIGz+vodwdeTImTlTJUK0rpBl7OD/U2kPjaRzmoumaof7OltOD8qgCnGUZRiVkUhmd6D7PoyrRt3au3Mqj4eNhxMOerL/GtL92+GHo00t9oYv8+K2IZ8AqGyO311EtmaetkEPySKffXk30Tmb1XTEwLCwXoBjIKiY1rVjaPhJp4Y7SZ1xEwD33hOAerUkHFp0THenas9yiFA7+WzhXM1ay3OT3uymf/3xh3Al5O48hJFSSGUE5lxh1wyp61sERnSKEH6ISToLEkuTWjNYzwZk4Ol+OrW8IJIwiVnlRj9xWq+XUFOuBiy/7WUxIAf4yVsREJ6HLtmCj3ZfB9uyY8bj3nXbb0vQDO0KCiIqdLTc4z6jYpWTgayK+w1cUMJNz6eAfFTyhGR3p6YJjeUnwoDoAGHLkYLb4MlR5begjw8FvXkG3TDCUkzgmpyNHTIqD6BMHXd0lttCH0zDfMKwkIDAOHk7cTJu+s9mopXePJL6ZtPMs/cT3xEZvo5xBZUKT8CtQy4OduBHWtTyQXPDCBszdKCMYU7EZHbVc983ADpTsNi6tD1gLxixyFSpZ1+VL1+eefz5BzmLSkte/RuJ 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: Errors with padzero() should be caught unless we're expecting a pathological (non-writable) segment. Report -EFAULT only when PROT_WRITE is present. Additionally add some more documentation to padzero(), elf_map(), and elf_load(). Cc: Eric Biederman Cc: Alexander Viro Cc: Christian Brauner Cc: linux-fsdevel@vger.kernel.org Cc: linux-mm@kvack.org Suggested-by: Eric Biederman Signed-off-by: Kees Cook --- fs/binfmt_elf.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index f8b4747f87ed..22027b0a5923 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -110,19 +110,19 @@ static struct linux_binfmt elf_format = { #define BAD_ADDR(x) (unlikely((unsigned long)(x) >= TASK_SIZE)) -/* We need to explicitly zero any fractional pages - after the data section (i.e. bss). This would - contain the junk from the file that should not - be in memory +/* + * We need to explicitly zero any trailing portion of the page that follows + * p_filesz when it ends before the page ends (e.g. bss), otherwise this + * memory will contain the junk from the file that should not be present. */ -static int padzero(unsigned long elf_bss) +static int padzero(unsigned long address) { unsigned long nbyte; - nbyte = ELF_PAGEOFFSET(elf_bss); + nbyte = ELF_PAGEOFFSET(address); if (nbyte) { nbyte = ELF_MIN_ALIGN - nbyte; - if (clear_user((void __user *) elf_bss, nbyte)) + if (clear_user((void __user *)address, nbyte)) return -EFAULT; } return 0; @@ -348,6 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, const struct elfhdr *exec, return 0; } +/* + * Map "eppnt->p_filesz" bytes from "filep" offset "eppnt->p_offset" + * into memory at "addr". (Note that p_filesz is rounded up to the + * next page, so any extra bytes from the file must be wiped.) + */ static unsigned long elf_map(struct file *filep, unsigned long addr, const struct elf_phdr *eppnt, int prot, int type, unsigned long total_size) @@ -387,6 +392,11 @@ static unsigned long elf_map(struct file *filep, unsigned long addr, return(map_addr); } +/* + * Map "eppnt->p_filesz" bytes from "filep" offset "eppnt->p_offset" + * into memory at "addr". Memory from "p_filesz" through "p_memsz" + * rounded up to the next page is zeroed. + */ static unsigned long elf_load(struct file *filep, unsigned long addr, const struct elf_phdr *eppnt, int prot, int type, unsigned long total_size) @@ -404,8 +414,12 @@ static unsigned long elf_load(struct file *filep, unsigned long addr, zero_end = map_addr + ELF_PAGEOFFSET(eppnt->p_vaddr) + eppnt->p_memsz; - /* Zero the end of the last mapped page */ - padzero(zero_start); + /* + * Zero the end of the last mapped page but ignore + * any errors if the segment isn't writable. + */ + if (padzero(zero_start) && (prot & PROT_WRITE)) + return -EFAULT; } } else { map_addr = zero_start = ELF_PAGESTART(addr); From patchwork Fri Sep 29 03:24:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13403637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8532AE743C0 for ; Fri, 29 Sep 2023 03:24:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 217BC8D00E6; Thu, 28 Sep 2023 23:24:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1577F8D00E5; Thu, 28 Sep 2023 23:24:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F12098D00E6; Thu, 28 Sep 2023 23:24:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D6CDC8D0002 for ; Thu, 28 Sep 2023 23:24:45 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B0C50160231 for ; Fri, 29 Sep 2023 03:24:45 +0000 (UTC) X-FDA: 81288192930.19.94B91C0 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by imf02.hostedemail.com (Postfix) with ESMTP id C49DC8000E for ; Fri, 29 Sep 2023 03:24:42 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=ERtiT8cH; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf02.hostedemail.com: domain of keescook@chromium.org designates 209.85.216.52 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695957882; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+wPEhWpvRY896Xnw5Ev1/y00zI5fAQGyVN5RsYugNn8=; b=22YMaVwYV+Ya+Ok2/mx4g964pHgDvH7IyupPGiZZwQPBlnyRMlSTcBUsZpQCRLKgxQk3hc elWQCth2ACshKaW5QvtyC425JTUJIVeWl8HQe2eeZnfn3WaG9ffLwfTKxvP7NY9/z7YmAR KUIRKqzXLTnDla/wucKSXA+MWJ5AE98= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=ERtiT8cH; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf02.hostedemail.com: domain of keescook@chromium.org designates 209.85.216.52 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695957882; a=rsa-sha256; cv=none; b=fwIKFMSq8ufLxvlDMU8SIxIAUBwKWZPYdIWJNLZ8v9gtHLXY29CLwSxBCqUDy3CZYIR7fg 4bH2Kbe08GvubdZJTkaran/UsKXw8eUAcBLYbWJV5pwrswuqs/+syQC5CLDPgeZda965W3 BHlhnXJY97+vG9/SHkbYONucLr2HAV0= Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-2774aa96947so8199146a91.2 for ; Thu, 28 Sep 2023 20:24:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695957881; x=1696562681; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+wPEhWpvRY896Xnw5Ev1/y00zI5fAQGyVN5RsYugNn8=; b=ERtiT8cH0/eQGlDQDt9MVVuC3DsAV+AOsYYmXuIxuV/os//pahTkcGzo2sDg2cqqBt Us2pfQZ/fdkXFZznnbQa/RGRPEDIzvEV1ZDtKNkB1C3uHrv1mYuqu1En07hZJV5X9EYk SaNPA+yWgUkxRaA02NoKL0KuXUyGGJmM3jv8c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695957881; x=1696562681; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+wPEhWpvRY896Xnw5Ev1/y00zI5fAQGyVN5RsYugNn8=; b=AMe8nvks84JkTCqisgV2Ut85xhz5GGqFiGOfpZTD0mrJEbt8G2liAMyAw4U9ogcdVZ dwvGeOYNP5wRUktCR/+WBJOy7NrAGyiogj+lgr0fLSCotg08Z8hfGh7WY7RqmHyo9Y84 uRsWfDme3MaG3sIv5gr9uCi4sBWW7c9ntNzdvujHOxbtRqDdA8YrYUFWUCVNjVfY+I9x FVjEF8bfGbZSARwVCZOPnyFp5SR9RAO+UeQB7ex85VYHGFZFm6R+ohxV5kjqzMoNoUOi PzoC7mjcMB7/hiCxrL0Q2mW0kXXLQ7wlBx9q0AlRg62C7lZg5B139kQBlI39gthQ/nPI HOsw== X-Gm-Message-State: AOJu0YwmbTcXNtQb6YO2zRZ6ZozfViOHMGRFcw9V5mSt5zVpapUgB8PN C9HpuCT4gwJPKD47wEoBY4Jlgg== X-Google-Smtp-Source: AGHT+IGrJvdYK0UubFjOkgcsulZp4Iwd9Tt7tIAbT+bREXfQrb6kahqghubh3CtXHQN6f3Ye2DXCOA== X-Received: by 2002:a17:90a:ba92:b0:267:ffcf:e9e3 with SMTP id t18-20020a17090aba9200b00267ffcfe9e3mr3087478pjr.46.1695957881706; Thu, 28 Sep 2023 20:24:41 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id x15-20020a17090a530f00b0027654d389casm297683pjh.54.2023.09.28.20.24.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 20:24:39 -0700 (PDT) From: Kees Cook To: Eric Biederman Cc: Kees Cook , Andrew Morton , linux-mm@kvack.org, Sebastian Ott , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Pedro Falcato , Al Viro , Christian Brauner , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v4 6/6] mm: Remove unused vm_brk() Date: Thu, 28 Sep 2023 20:24:34 -0700 Message-Id: <20230929032435.2391507-6-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230929031716.it.155-kees@kernel.org> References: <20230929031716.it.155-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2050; i=keescook@chromium.org; h=from:subject; bh=qQgWJ2LfzVKqVSy79Ld0II87Ub3I62svbZlMXS8eqNU=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlFkNyozNMKFDP2i80754Px/+ZY/Cx7wBo4sXmZ GfAFEgqokWJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRZDcgAKCRCJcvTf3G3A JvugEAC1X9CtGDjUrVOsqG0t9TTnzkbAODtZErc43R+VjV7tM+wgC1YoBq1uGKg3kk/39J5ROiJ rUkABHj3UilMN33EplFoDi9bG/ErY91MQttOzzjtGtjVqWIrEJ/Vl9Txp0Lfb8zYFy9NsK/6FUL MtgFp5sk40k0qU96E6p96fB7SzEc44a33CLYYExFKVE2M08Bylw2aJ9Ee0dsno2XN3kwHuLByFf wcJ9XIEkkKA6ek8B7IuLsRGmbigeQnoNgTo87K5bPOqAGNyvV5AaKea9aX90W7XTFl3Mg767UDU QBSQvaLWv+t6WEIH+DBweDTKSOHJsyAOniUBtf5ZYA37xZuqPVJdtHMHNT5eperaA7H3rjw+UUz Jlq6iSEPSQzB/ur6ucWrK0s4O62amvSspv633OZXBOo6liFA9krixvk0n9DDIpK4izJk9sqIro1 JU8Wshi103umj8FDzYRXujBj+g//VNypVJAxw30ltepS01lpNn33UpY/bazcxEBWtzAI6WzksOn OioMLo/fYEk9tr3WtHRgTsp7V0afPDYJ6aOpeBzZjAdyfqtuIfngMDD8ITow2mnQdSypEQ39K9p Rr6tuk/SEYKG3c/cQmyk7L+/cRTRAgeeYxAnZFNKbHqj7DeGYfmOdb6oTSlHNHgU9S+L8PRk5BL FEozwXjpMVEPE4w== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Rspamd-Queue-Id: C49DC8000E X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: juok9is5ufwactxid3nukt6xkkbfff49 X-HE-Tag: 1695957882-299186 X-HE-Meta: U2FsdGVkX19frKtev1DN+qQByfAQ+5vH4LQNYJYzsXLKb8cwUSJEqDM8e17xEeke0uqmAy9b/jDQMW/cxR1COxDQroPIXmp2eP1WT0otgJhGVfK0UX3EDuW/gs6J8YDk+CMjULtJanre3O/nRMV8ABJnOF1yEIIfHRGyrsBMEITpyBg7DGTDSDel9rFx4WvtavJaMjyDmbXmjFLRBr5QOJfRE5ZrpUWljqgRJDI/CJOQdlVLy6Vey5aA4gE43n2MQd42pNVlz7R0UU2pXKCA2lWHy+35Ae+YULvlqu+jii5+9Euolq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kRYjmvaQY3jCt0j0WG92T+peTj8p3JUAPtaAODIiPk/PBa9S9+Ho17i0pnYNRiTH0m44mI89eB+HXxmSHEQL5hYkoiIDCVfzgWF9RSz9EBb4mTUN9rd8yHzu0MiUbH9+3OHce3QIbiqKpC2lPLE5MCwjuaFNgJ9BBm7FKow0RqLCE+hb7evMmjXfbSxN0MH3yrx2k/709xUFh6hwgnvZnQMwpj7GMM1Fa5aHNeaUl/R/fp1hu83o2c+sB7+kxomxqEwbxAiBKs+d8GiuKcXM5X9Gy779C+IZJR9/Q4ZrGHuT9hPsB 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: With fs/binfmt_elf.c fully refactored to use the new elf_load() helper, there are no more users of vm_brk(), so remove it. Cc: Andrew Morton Cc: linux-mm@kvack.org Suggested-by: Eric Biederman Signed-off-by: Kees Cook --- include/linux/mm.h | 3 +-- mm/mmap.c | 6 ------ mm/nommu.c | 5 ----- 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index bf5d0b1b16f4..216dd0c6dcf8 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3308,8 +3308,7 @@ static inline void mm_populate(unsigned long addr, unsigned long len) static inline void mm_populate(unsigned long addr, unsigned long len) {} #endif -/* These take the mm semaphore themselves */ -extern int __must_check vm_brk(unsigned long, unsigned long); +/* This takes the mm semaphore itself */ extern int __must_check vm_brk_flags(unsigned long, unsigned long, unsigned long); extern int vm_munmap(unsigned long, size_t); extern unsigned long __must_check vm_mmap(struct file *, unsigned long, diff --git a/mm/mmap.c b/mm/mmap.c index b56a7f0c9f85..34d2337ace59 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3174,12 +3174,6 @@ int vm_brk_flags(unsigned long addr, unsigned long request, unsigned long flags) } EXPORT_SYMBOL(vm_brk_flags); -int vm_brk(unsigned long addr, unsigned long len) -{ - return vm_brk_flags(addr, len, 0); -} -EXPORT_SYMBOL(vm_brk); - /* Release all mmaps. */ void exit_mmap(struct mm_struct *mm) { diff --git a/mm/nommu.c b/mm/nommu.c index 7f9e9e5a0e12..23c43c208f2b 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -1531,11 +1531,6 @@ void exit_mmap(struct mm_struct *mm) mmap_write_unlock(mm); } -int vm_brk(unsigned long addr, unsigned long len) -{ - return -ENOMEM; -} - /* * expand (or shrink) an existing mapping, potentially moving it at the same * time (controlled by the MREMAP_MAYMOVE flag and available VM space)