All of lore.kernel.org
 help / color / mirror / Atom feed
From: "tip-bot2 for Mike Galbraith" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Mike Galbraith <efault@gmx.de>, Borislav Petkov <bp@suse.de>,
	Dave Young <dyoung@redhat.com>, <stable@vger.kernel.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: x86/urgent] x86/crash: Fix crash_setup_memmap_entries() out-of-bounds access
Date: Tue, 20 Apr 2021 18:00:42 -0000	[thread overview]
Message-ID: <161894164234.29796.8745971840518585404.tip-bot2@tip-bot2> (raw)
In-Reply-To: <725fa3dc1da2737f0f6188a1a9701bead257ea9d.camel@gmx.de>

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     5849cdf8c120e3979c57d34be55b92d90a77a47e
Gitweb:        https://git.kernel.org/tip/5849cdf8c120e3979c57d34be55b92d90a77a47e
Author:        Mike Galbraith <efault@gmx.de>
AuthorDate:    Fri, 16 Apr 2021 14:02:07 +02:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Tue, 20 Apr 2021 17:32:46 +02:00

x86/crash: Fix crash_setup_memmap_entries() out-of-bounds access

Commit in Fixes: added support for kexec-ing a kernel on panic using a
new system call. As part of it, it does prepare a memory map for the new
kernel.

However, while doing so, it wrongly accesses memory it has not
allocated: it accesses the first element of the cmem->ranges[] array in
memmap_exclude_ranges() but it has not allocated the memory for it in
crash_setup_memmap_entries(). As KASAN reports:

  BUG: KASAN: vmalloc-out-of-bounds in crash_setup_memmap_entries+0x17e/0x3a0
  Write of size 8 at addr ffffc90000426008 by task kexec/1187

  (gdb) list *crash_setup_memmap_entries+0x17e
  0xffffffff8107cafe is in crash_setup_memmap_entries (arch/x86/kernel/crash.c:322).
  317                                      unsigned long long mend)
  318     {
  319             unsigned long start, end;
  320
  321             cmem->ranges[0].start = mstart;
  322             cmem->ranges[0].end = mend;
  323             cmem->nr_ranges = 1;
  324
  325             /* Exclude elf header region */
  326             start = image->arch.elf_load_addr;
  (gdb)

Make sure the ranges array becomes a single element allocated.

 [ bp: Write a proper commit message. ]

Fixes: dd5f726076cc ("kexec: support for kexec on panic using new system call")
Signed-off-by: Mike Galbraith <efault@gmx.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Dave Young <dyoung@redhat.com>
Cc: <stable@vger.kernel.org>
Link: https://lkml.kernel.org/r/725fa3dc1da2737f0f6188a1a9701bead257ea9d.camel@gmx.de
---
 arch/x86/kernel/crash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index a8f3af2..b1deacb 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -337,7 +337,7 @@ int crash_setup_memmap_entries(struct kimage *image, struct boot_params *params)
 	struct crash_memmap_data cmd;
 	struct crash_mem *cmem;
 
-	cmem = vzalloc(sizeof(struct crash_mem));
+	cmem = vzalloc(struct_size(cmem, ranges, 1));
 	if (!cmem)
 		return -ENOMEM;
 

      parent reply	other threads:[~2021-04-20 18:00 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-15 17:56 x86/crash: fix crash_setup_memmap_entries() out-of-bounds access Mike Galbraith
2021-04-16 11:07 ` Dave Young
2021-04-16 11:07   ` Dave Young
2021-04-16 11:28   ` Mike Galbraith
2021-04-16 11:28     ` Mike Galbraith
2021-04-16 11:47     ` Dave Young
2021-04-16 11:47       ` Dave Young
2021-04-16 12:02       ` [patch] " Mike Galbraith
2021-04-16 12:02         ` Mike Galbraith
2021-04-16 12:16         ` Borislav Petkov
2021-04-16 12:16           ` Borislav Petkov
2021-04-16 13:16           ` Mike Galbraith
2021-04-16 13:16             ` Mike Galbraith
2021-04-16 14:44             ` Borislav Petkov
2021-04-16 14:44               ` Borislav Petkov
2021-04-16 15:13               ` Mike Galbraith
2021-04-16 15:13                 ` Mike Galbraith
2021-04-16 21:44                 ` Thomas Gleixner
2021-04-16 21:44                   ` Thomas Gleixner
2021-04-17  0:05                   ` Mike Galbraith
2021-04-17  0:05                     ` Mike Galbraith
2021-04-19  8:52                     ` Borislav Petkov
2021-04-19  8:52                       ` Borislav Petkov
2021-04-19  9:37                       ` DaveYoung
2021-04-19  9:37                         ` DaveYoung
2021-04-20 18:00         ` tip-bot2 for Mike Galbraith [this message]

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=161894164234.29796.8745971840518585404.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=bp@suse.de \
    --cc=dyoung@redhat.com \
    --cc=efault@gmx.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=x86@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.