Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp130479rdb; Wed, 29 Nov 2023 23:45:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IGsfSndapOd2Wuoh/YXB1rs1hCbbdwr/Gffy4D09KG5O2lH37s/HsFpljxjeD1DBl/nty+P X-Received: by 2002:a05:6358:948f:b0:16e:3c1a:b2d2 with SMTP id i15-20020a056358948f00b0016e3c1ab2d2mr14485908rwb.26.1701330325321; Wed, 29 Nov 2023 23:45:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701330325; cv=none; d=google.com; s=arc-20160816; b=SpaDvPz8FrArXWPZHGJklL5hIfRY6VBFU3V1buMCioCDR+EoJhzq/jzYXIrT/zbhlj 9d8OMD/kYcDqs5FaLTiNQ0uD6c16iP7oEGSI7YrpOVvCPBhbLnYsbwetsw1B1xSoeKfb CJBoDhC6hpXw4ElPGUME+qrF35snudV4rzbRyEn6rWw2jbc0KfcHVig1tBQxwDmdmcQR yyvEfBCMikGCm4oZbu7aohgSfTuPeUmbZcmXC90E/wxDz8xfo2Xlnn2nqblVJWwCGBky xhlqjkbmI8g2lYlnNbDgcK4W3nNZG2I/R5QYlfPNz7K7Hs3kAv93fc83GTgGjRyjAscc qUzw== 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=kFX81jkgr22XnPLJhetZKt46F/xnkz4cCCAQykO/SFc=; fh=jvjTt7uibnf2eMis2SZPrfWWjD4QySFNd/y3SV02B1k=; b=Dx/v5uwGJbwSMY5i6Pict96uJV0EDwzI9ff3Aw0mNIjgFWXyyTMhPGcRTWfrvIbaps CGfPIGX5gTn0g+xUZAIFJtRvyFH7hW06mvNFIyyWLU4qaCICoCfD+Wpvv4usq5CJrQ33 E/8VWuo4/rdObt73W7adsXGNXygNYQPLMuDnitzFz9avU3TL2RJxkXO2wBjtQ1rsi943 hKH35x9IU2kCvsgYPF0FPCTlAUCRqMj7LOpUKFZ0EcOtzG2Twg5rXq/j5+dsXe7knXjF wBxHhBFLB4GourEljwnY5MV940XCA77QxEkzg6n9ywJZBqG9hPvhBHmhj1Y6l/vD5xcA lhBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XyVIkhwz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id h63-20020a636c42000000b005c624c6c8c0si716557pgc.536.2023.11.29.23.45.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 23:45:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XyVIkhwz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 4806D8087242; Wed, 29 Nov 2023 23:45:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229694AbjK3Hoz (ORCPT + 99 others); Thu, 30 Nov 2023 02:44:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231687AbjK3Hoy (ORCPT ); Thu, 30 Nov 2023 02:44:54 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D964D6C for ; Wed, 29 Nov 2023 23:44:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701330299; 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=kFX81jkgr22XnPLJhetZKt46F/xnkz4cCCAQykO/SFc=; b=XyVIkhwzl+zGAxLTEjzT3p1UETgjn0DwdeHUjPXRBdq8z9LL0B8l041jaHQpG8IKBRxrQt zF8Y+L3tsVebLSKBiyyt+LeEV6PrXCOgIQEzpyUoV7Cg4l2jZxspr98E+v1/aScW1lG7Px hDefYpjQL15tdJh8lY3V9GOxiFTfDnA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-417-AHfMViECMDaF78Bs7fn4Uw-1; Thu, 30 Nov 2023 02:44:56 -0500 X-MC-Unique: AHfMViECMDaF78Bs7fn4Uw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CD3E6185A781; Thu, 30 Nov 2023 07:44:55 +0000 (UTC) Received: from localhost (unknown [10.72.113.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D7468C1596F; Thu, 30 Nov 2023 07:44:44 +0000 (UTC) Date: Thu, 30 Nov 2023 15:44:41 +0800 From: Baoquan He To: fuqiang wang Cc: Vivek Goyal , Dave Young , kexec@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] kexec: avoid out of bounds in crash_exclude_mem_range() Message-ID: References: <20231127025641.62210-1-fuqiang.wang@easystack.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231127025641.62210-1-fuqiang.wang@easystack.cn> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 29 Nov 2023 23:45:11 -0800 (PST) On 11/27/23 at 10:56am, fuqiang wang wrote: > When the split happened, judge whether mem->nr_ranges is equal to > mem->max_nr_ranges. If it is true, return -ENOMEM. > > The advantage of doing this is that it can avoid array bounds caused by > some bugs. E.g., Before commit 4831be702b95 ("arm64/kexec: Fix missing > extra range for crashkres_low."), reserve both high and low memories for > the crashkernel may cause out of bounds. > > On the other hand, move this code before the split to ensure that the > array will not be changed when return error. If out of array boundary is caused, means the laoding failed, whether the out of boundary happened or not. I don't see how this code change makes sense. Do I miss anything? Thanks Baoquan > > Signed-off-by: fuqiang wang > --- > kernel/crash_core.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/kernel/crash_core.c b/kernel/crash_core.c > index efe87d501c8c..ffdc246cf425 100644 > --- a/kernel/crash_core.c > +++ b/kernel/crash_core.c > @@ -611,6 +611,9 @@ int crash_exclude_mem_range(struct crash_mem *mem, > } > > if (p_start > start && p_end < end) { > + /* Split happened */ > + if (mem->nr_ranges == mem->max_nr_ranges) > + return -ENOMEM; > /* Split original range */ > mem->ranges[i].end = p_start - 1; > temp_range.start = p_end + 1; > @@ -626,9 +629,6 @@ int crash_exclude_mem_range(struct crash_mem *mem, > if (!temp_range.end) > return 0; > > - /* Split happened */ > - if (i == mem->max_nr_ranges - 1) > - return -ENOMEM; > > /* Location where new range should go */ > j = i + 1; > -- > 2.42.0 > > > _______________________________________________ > kexec mailing list > kexec@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/kexec >