Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp223842pxb; Fri, 16 Apr 2021 04:09:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlQdChYc3MrNf4vODBKm3BTCNmBD29m+ACspBmwQk3B596jsQoEp/lWSD3XDJ1tV2a1ZwO X-Received: by 2002:aa7:9806:0:b029:253:e613:4ada with SMTP id e6-20020aa798060000b0290253e6134adamr7422737pfl.65.1618571396476; Fri, 16 Apr 2021 04:09:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618571396; cv=none; d=google.com; s=arc-20160816; b=CC+l6tSYrY5yF9sj6k99OVExo7OEQdc2rRMbz1rJ373AQeTPT5gOrAp6cimYec7dgh REj/du8jnK5tl59QiVsNFltmjMjIHCVSibIj3IHEt9DGeEQjLBhDIqYnzBBbve0YEUVA E+osXdDDbZXoTpVVwJgu3hUEhGRIgqaTAVWW4mEVmeuF2su2LPsFrSHLmRZ4uO0jP8sE 4x6QzYxQr7SuR3urV21Eynheks8QKgEFgn8HCxEiA+2IiE4TtSwVFHXuspS8nX7se84w LFveLPF31tOsKy4dFyWOblgA0v5+sO15SK1L8i1K5GjyxG9h6c1AgNk+YJmYgIO56gSu 0/mw== 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=nHPAeuJEveCP4Fc1NFrF0y8J4SMSH0qhebL+YdyGc54=; b=DWl78h4msv0AROuSfkKTaGSQqRRh6snQLzROOP9cLaD8awCratnEO+vuSGLJCRzNDT lantEOR1UN8rYKMRX9pcARiaDBpK9hYBANnM/l+vgah3L16QFBjbSzIy1YkbnBdVO0I5 8QVRnnWTVdMdXTsFgwxBAfp0Ha785USnytudF4KujdRTnLAtvmV4Py5EWJda/BAk6VeS LmCMq0hviD+9ZzFg42Guqp8lWWEbZAAWj7UyhaCcE25fSNWU4LBV3JafwxgkY/yXrDY4 0wnabTTBaKcctDwL75BJAUdbDgwl59wfI7Ew2WA0g6mptGsv57ZLyBxfRjQ4Wngt2m6G 97rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hs2KVe0E; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kk9si6087189pjb.125.2021.04.16.04.09.43; Fri, 16 Apr 2021 04:09:56 -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=@redhat.com header.s=mimecast20190719 header.b=hs2KVe0E; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241770AbhDPLHh (ORCPT + 99 others); Fri, 16 Apr 2021 07:07:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31471 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237997AbhDPLHf (ORCPT ); Fri, 16 Apr 2021 07:07:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618571230; 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: in-reply-to:in-reply-to:references:references; bh=nHPAeuJEveCP4Fc1NFrF0y8J4SMSH0qhebL+YdyGc54=; b=hs2KVe0ErjmlUC7e9lnOzIb1clqo1J0cr2JNT0AKAzhRbQGQtGUmNTq4Yee9GXpSuWCH56 CPcnMavFdaTdxUDI3v5kutiWP8N/EZVmUaVRyUfk9gCrUiuYnUHTfnpzEMLlkQhKCCPYbB 5n4TR/JmFcEtzTU1wuFeJU8t7ZbVEDk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-587-DgoPjzdyORO5kVrtif4suA-1; Fri, 16 Apr 2021 07:07:08 -0400 X-MC-Unique: DgoPjzdyORO5kVrtif4suA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8BB7F8030A1; Fri, 16 Apr 2021 11:07:07 +0000 (UTC) Received: from dhcp-128-65.nay.redhat.com (ovpn-12-55.pek2.redhat.com [10.72.12.55]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 52F361C4; Fri, 16 Apr 2021 11:07:04 +0000 (UTC) Date: Fri, 16 Apr 2021 19:07:01 +0800 From: Dave Young To: Mike Galbraith Cc: LKML , Baoquan He , kexec@lists.infradead.org Subject: Re: x86/crash: fix crash_setup_memmap_entries() out-of-bounds access Message-ID: <20210416110701.GA3835@dhcp-128-65.nay.redhat.com> References: <9efaad2ba042b8791cbe8c3e7cad491fe05e06eb.camel@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9efaad2ba042b8791cbe8c3e7cad491fe05e06eb.camel@gmx.de> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mike, Thanks for the patch! I suggest always cc kexec list for kexec/kdump patches. On 04/15/21 at 07:56pm, Mike Galbraith wrote: > x86/crash: fix crash_setup_memmap_entries() KASAN vmalloc-out-of-bounds gripe > > [ 15.428011] BUG: KASAN: vmalloc-out-of-bounds in crash_setup_memmap_entries+0x17e/0x3a0 > [ 15.428018] 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) > > We're excluding two ranges, allocate the scratch space we need to do that. I think 1 range should be fine, have you tested 1? The code is just excluding the elf header space which will be loaded first before anything else so I assume it will be just at the start of the crashkernel resource region. Thus [a b] after exclude the start part will be [c b]. But I have not read the code for long time, maybe I need to double check. But anyway 2 would be good since the code is obscure we can easily miss it in the future. See how other people think. > > Signed-off-by: Mike Galbraith > --- > arch/x86/kernel/crash.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > --- a/arch/x86/kernel/crash.c > +++ b/arch/x86/kernel/crash.c > @@ -337,7 +337,7 @@ int crash_setup_memmap_entries(struct ki > struct crash_memmap_data cmd; > struct crash_mem *cmem; > > - cmem = vzalloc(sizeof(struct crash_mem)); > + cmem = vzalloc(sizeof(struct crash_mem)+(2*sizeof(struct crash_mem_range))); Thanks for the patch, can you try below? vzalloc(struct_size(cmem, ranges, 2)); > if (!cmem) > return -ENOMEM; > > Thanks Dave