From: Kees Cook <keescook@chromium.org>
To: Jiri Kosina <jikos@kernel.org>
Cc: Kees Cook <keescook@chromium.org>,
y0un9n132@gmail.com, Geert Uytterhoeven <geert@linux-m68k.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
Eric Biederman <ebiederm@xmission.com>,
Christophe Leroy <christophe.leroy@csgroup.eu>,
linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>,
Peter Zijlstra <peterz@infradead.org>,
Qi Zheng <zhengqi.arch@bytedance.com>,
Alexandre Ghiti <alexghiti@rivosinc.com>,
Josh Poimboeuf <jpoimboe@kernel.org>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Rick Edgecombe <rick.p.edgecombe@intel.com>,
Brian Gerst <brgerst@gmail.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Tony Battersby <tonyb@cybernetics.com>,
linux-kernel@vger.kernel.org, x86@kernel.org,
linux-hardening@vger.kernel.org
Subject: [PATCH 2/2] binfmt_elf: Leave a gap between .bss and brk
Date: Fri, 16 Feb 2024 22:25:44 -0800 [thread overview]
Message-ID: <20240217062545.1631668-2-keescook@chromium.org> (raw)
In-Reply-To: <20240217062035.work.493-kees@kernel.org>
Currently the brk starts its randomization immediately after .bss,
which means there is a chance that when the random offset is 0, linear
overflows from .bss can reach into the brk area. Leave at least a single
page gap between .bss and brk (when it has not already been explicitly
relocated into the mmap range).
Reported-by: y0un9n132@gmail.com
Closes: https://lore.kernel.org/linux-hardening/CA+2EKTVLvc8hDZc+2Yhwmus=dzOUG5E4gV7ayCbu0MPJTZzWkw@mail.gmail.com/
Signed-off-by: Kees Cook <keescook@chromium.org>
---
Cc: Jiri Kosina <jikos@kernel.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-mm@kvack.org
---
fs/binfmt_elf.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 5397b552fbeb..7862962f7a85 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1262,6 +1262,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
if (IS_ENABLED(CONFIG_ARCH_HAS_ELF_RANDOMIZE) &&
elf_ex->e_type == ET_DYN && !interpreter) {
mm->brk = mm->start_brk = ELF_ET_DYN_BASE;
+ } else {
+ /* Otherwise leave a gap between .bss and brk. */
+ mm->brk = mm->start_brk = mm->brk + PAGE_SIZE;
}
mm->brk = mm->start_brk = arch_randomize_brk(mm);
--
2.34.1
next prev parent reply other threads:[~2024-02-17 6:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-17 6:25 [PATCH 0/2] Adjust brk randomness Kees Cook
2024-02-17 6:25 ` [PATCH 1/2] x86: Increase brk randomness entropy on x86_64 Kees Cook
2024-02-26 10:39 ` Jiri Kosina
2024-02-17 6:25 ` Kees Cook [this message]
2024-04-24 19:20 ` (subset) [PATCH 2/2] binfmt_elf: Leave a gap between .bss and brk Kees Cook
2024-02-18 0:25 ` [PATCH 0/2] Adjust brk randomness H. Peter Anvin
2024-02-18 1:25 ` Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240217062545.1631668-2-keescook@chromium.org \
--to=keescook@chromium.org \
--cc=alexghiti@rivosinc.com \
--cc=bhelgaas@google.com \
--cc=bp@alien8.de \
--cc=brauner@kernel.org \
--cc=brgerst@gmail.com \
--cc=christophe.leroy@csgroup.eu \
--cc=dave.hansen@linux.intel.com \
--cc=ebiederm@xmission.com \
--cc=geert@linux-m68k.org \
--cc=hpa@zytor.com \
--cc=jack@suse.cz \
--cc=jikos@kernel.org \
--cc=jpoimboe@kernel.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rick.p.edgecombe@intel.com \
--cc=tglx@linutronix.de \
--cc=tonyb@cybernetics.com \
--cc=viro@zeniv.linux.org.uk \
--cc=x86@kernel.org \
--cc=y0un9n132@gmail.com \
--cc=zhengqi.arch@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).