lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 10 Nov 2022 22:13:20 -0800
From:   Kees Cook <keescook@...omium.org>
To:     Pedro Falcato <pedro.falcato@...il.com>
Cc:     Kees Cook <keescook@...omium.org>, Rich Felker <dalias@...c.org>,
        Fangrui Song <maskray@...gle.com>,
        Alexander Viro <viro@...iv.linux.org.uk>,
        Eric Biederman <ebiederm@...ssion.com>,
        linux-fsdevel@...r.kernel.org, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org, linux-hardening@...r.kernel.org
Subject: [PATCH v2] binfmt_elf: Allow .bss in any interp PT_LOAD

Traditionally, only the final PT_LOAD for load_elf_interp() supported
having p_memsz > p_filesz. Recently, lld's construction of musl's
libc.so on PowerPC64 started having two PT_LOAD program headers with
p_memsz > p_filesz.

As the least invasive change possible, check for p_memsz > p_filesz for
each PT_LOAD in load_elf_interp.

Reported-by: Rich Felker <dalias@...c.org>
Link: https://maskray.me/blog/2022-11-05-lld-musl-powerpc64
Cc: Pedro Falcato <pedro.falcato@...il.com>
Cc: Fangrui Song <maskray@...gle.com>
Cc: Alexander Viro <viro@...iv.linux.org.uk>
Cc: Eric Biederman <ebiederm@...ssion.com>
Cc: linux-fsdevel@...r.kernel.org
Cc: linux-mm@...ck.org
Signed-off-by: Kees Cook <keescook@...omium.org>
---
v2: I realized we need to retain the final padding call.
v1: https://lore.kernel.org/linux-hardening/20221111055747.never.202-kees@kernel.org/
---
 fs/binfmt_elf.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 528e2ac8931f..0a24bbbef1d6 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -673,15 +673,25 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
 				last_bss = k;
 				bss_prot = elf_prot;
 			}
+
+			/*
+			 * Clear any p_memsz > p_filesz area up to the end
+			 * of the page to wipe anything left over from the
+			 * loaded file contents.
+			 */
+			if (last_bss > elf_bss && padzero(elf_bss))
+				error = -EFAULT;
+				goto out;
+			}
 		}
 	}
 
 	/*
-	 * 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.
+	 * Finally, 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 this did
+	 * not already happen with the last PT_LOAD.
 	 */
-	if (padzero(elf_bss)) {
+	if (last_bss == elf_bss && padzero(elf_bss)) {
 		error = -EFAULT;
 		goto out;
 	}
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ