Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2288477pxb; Mon, 19 Apr 2021 01:55:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZzCbh2E9khzySlcDd0Ht9QuGkDNn21WAnEonS6ZPCts17gXwl9OnKPmUD2ergFUQO7mcv X-Received: by 2002:a05:6402:51cd:: with SMTP id r13mr24296616edd.116.1618822544837; Mon, 19 Apr 2021 01:55:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618822544; cv=none; d=google.com; s=arc-20160816; b=YgkdmKYnsncQ6w+E4qDN8dxxr/4VqwzTjGXSn2RH3eCR2qTQIh+DNVZm/lGknUz1N3 AKt7Qw8+STkWY1YrgHFFF0AUWNpf1bFxWzMz1yltf6UkKIdeK5CF8ekBnUjRn5uioEmt XoeyFD6zlUuq2hk7TMZ2oN77vhmXMZgrxbweEJI2KHisWi3STDBxIxOaD59wNDJezOM8 NdZS22XBG7u/dCLS3XUn2aRJr3HmpkQwCtpCj7jKkomTDrEDvqp0tzvR7qmBTNL1Lqmh HFa4CNhbOU6oWr4CTwtUgYa+j1g63rYYyJSMVdT+ZsUe00QTaj1EyLTiRTCqwoUpq/pK VYVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=pIRHdRe7xh1N3mcqJIAiHV5Yi+DTFrurrKgsh6oP2fE=; b=heX6WhFEqM8QONP13irbndFmwwAc+E0ELq7x7AQ81UC6B+ml3oLEvq+CdQEcobrkiQ vTl3Y1tGDLDXUKS9qmP8xRYc0E36NcvnC1Wiijs1Nw0EqdMntfI8BEswTFYZF0U4CeqA PuwiSi+j1XZ191qIt/7Shy7SjbKFOkZXe6gTYEZlG3rQ+fuwNIniIiuNhdI+/P6k6Z8T 9+q7ivu+IqqWdlgA1vgEySltUOb4z70ah57xRG3sA0WTD4vPHW0Q1lgwCHaU89Ea8OkS HzRAM4UEMLFjp4st0X3OoN7AHIBS96lxSmwKJfzNb0bTqSNhNlKOevKCJvvEOHGjzv+P ZsRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=EOX9+qvS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z26si12988185ejc.46.2021.04.19.01.55.21; Mon, 19 Apr 2021 01:55:44 -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=pass header.i=@alien8.de header.s=dkim header.b=EOX9+qvS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238373AbhDSIwk (ORCPT + 99 others); Mon, 19 Apr 2021 04:52:40 -0400 Received: from mail.skyhub.de ([5.9.137.197]:55788 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238348AbhDSIwj (ORCPT ); Mon, 19 Apr 2021 04:52:39 -0400 Received: from zn.tnic (p200300ec2f0781008a798ef43e130bd8.dip0.t-ipconnect.de [IPv6:2003:ec:2f07:8100:8a79:8ef4:3e13:bd8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id BDDE21EC0283; Mon, 19 Apr 2021 10:52:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1618822326; h=from:from: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:in-reply-to:in-reply-to: references:references; bh=pIRHdRe7xh1N3mcqJIAiHV5Yi+DTFrurrKgsh6oP2fE=; b=EOX9+qvSZvUg4c2a34QBv4obzkJAatIKKGKVwdORwXKnBMIDLA2ukAfoYNijPXuMd6tdIn yVZxR8tHampThblJJfGAaPygt2F+bSFSETzy+2uTEUPOKQWNfGA0KKn4190P54hdwb72Jl fu2mr91AbT2HQo6f02DhHdD/53Lim88= Date: Mon, 19 Apr 2021 10:52:02 +0200 From: Borislav Petkov To: Mike Galbraith Cc: Thomas Gleixner , LKML , DaveYoung , Baoquan He , kexec@lists.infradead.org, x86@kernel.org, Andrew Morton Subject: Re: [patch] x86/crash: fix crash_setup_memmap_entries() out-of-bounds access Message-ID: <20210419085202.GB9093@zn.tnic> References: <20210416110701.GA3835@dhcp-128-65.nay.redhat.com> <063a63ddea914ac654cbe9a1d1d6c76986af7882.camel@gmx.de> <20210416114708.GB79779@dhcp-128-65.nay.redhat.com> <725fa3dc1da2737f0f6188a1a9701bead257ea9d.camel@gmx.de> <20210416121636.GA22348@zn.tnic> <20210416144459.GB22348@zn.tnic> <7826c19ecd583700f56d2db33360e8032e812ecf.camel@gmx.de> <87sg3puco5.ffs@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Here's an attempt to explain what this fixes: --- From: Mike Galbraith Date: Fri, 16 Apr 2021 14:02:07 +0200 Subject: [PATCH] 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 Signed-off-by: Borislav Petkov 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 a8f3af257e26..b1deacbeb266 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; -- 2.29.2 -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette