Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1880140rwl; Thu, 30 Mar 2023 02:51:05 -0700 (PDT) X-Google-Smtp-Source: AKy350YnEOr0/1bVIGSsYYn1W9D9SeAV5TZac/3vbIbu0d9b5waAG+thlF26HqizZkwO3v0EVCAX X-Received: by 2002:a17:906:7382:b0:93b:dddf:4be2 with SMTP id f2-20020a170906738200b0093bdddf4be2mr1201771ejl.3.1680169865202; Thu, 30 Mar 2023 02:51:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680169865; cv=none; d=google.com; s=arc-20160816; b=huK7fpNO4QVPRid4v79ogcrvrR4ED1ss76VPfWVlQ9cI3a+jZloXHbZiyKxzk3xpx6 Z8/2bfBe7bzHSSDrFnb3FDPBWBIN+U0qhuH4ciXVhzoYXj8AEvMq3L+uM7GNWba9ABnU 0EChagxZiqNJ1zBvaLUl6OGCXKjwEvMRqv0rcsQqAestbeyuTyh6/KJ4UHjs465bWP90 XRJvtqt+tdYpf8eHO/ibHjddJ37xjX5kk3xQgF1sthJ7IKbfcn4Wm1YET9K8aT34/lPs IeU4QZSjoPM/V8cIWJE5Yfx4j11jDstl/GCPWv0p+F9PuclBsuzW47HUF7CowkAgudCx qdnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=OdosBDolGQNzQB/45PIpdghJGHYdgirOF9Wp82woz8M=; b=zR0qbPJbtx+FF/MFw42KhcjSL9+DuRWEebBAHtOnFmEYre2MazzVYm4QDX5kNN6gX0 6xRkJLU1u40tyykQxJ5z42zMeu4kVue+elrrEV+6XWL3wbgVrGXNNeUj5oZTzKqibz6f x91J/x3C5qXyolt7m3KGiW961J3rOZnblqm69ixY5nzLWSGRkwwdAW0F9xUWjf3+wlL3 q32d1Izwy4Bc6uQcX5KmMfxFDbLCq5nFveM2g968Zbu0gJRHuPJhT4K6xHt4Ug6OTpVI MgzK1LMRYc83Qf9QOX/j31m53MQOMiYPaDmjvDe3e32HcM0Bky82fMY/1mF2SSc+H1kn UUQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="DzY3/3o2"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he31-20020a1709073d9f00b0093a6b7c4e9csi30538873ejc.914.2023.03.30.02.50.39; Thu, 30 Mar 2023 02:51:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="DzY3/3o2"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230420AbjC3JtA (ORCPT + 99 others); Thu, 30 Mar 2023 05:49:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229564AbjC3Jsa (ORCPT ); Thu, 30 Mar 2023 05:48:30 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DBED93D4 for ; Thu, 30 Mar 2023 02:47:34 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id c4so705185pjs.4 for ; Thu, 30 Mar 2023 02:47:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1680169647; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=OdosBDolGQNzQB/45PIpdghJGHYdgirOF9Wp82woz8M=; b=DzY3/3o26OIw7qcpZgeVcNxZuUJ5S5Hh2cq7op2GiHG/qGCmRrKe7/N+OfJAji7oq8 QJPrDLRHfhipXnJ+dBbB4+BuUxhwlHXYHrfSQevBnmY+1/uHTzJd01Pu7e+5XI8LX5rF EAaCmJc0LDsxQhhTCiA03yQHOAGcbec4WI2dU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680169647; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=OdosBDolGQNzQB/45PIpdghJGHYdgirOF9Wp82woz8M=; b=sjGlohAP6LbFlQzEkDJXjzt0w6wD3oBr4GigdX4WBRuaLgUwfyai7VsMEMZQI6c18N dLYBH4a0F3AkKVZBDJfqyoDMJikpcAmbFfeNZ3YtzcHqUzZ+dqzxdCc9uE+ytihQey4U 4n5UWZimzZztjEDjtuH24Hc3TpIq/oPZ8BdV7E9+PrjrTXwKt433pu9Wow5IHJNR36BK 7pGM7qJIojJl61BE0HA0lU22eukr/5/W4UgwvaafEp/zZuFV89MzofRpD5zxqp9eHgHT IU4ghC9paQUf4Z3IYDaH9+0/2wLo2KBWek3J5QLxd0RjPkrxa8tpjfXp/VCgxokz8h+P TjcA== X-Gm-Message-State: AAQBX9dtWgGTGUQtrlWgbLroHJ79cRS6cSznj7mcQwFjjW6DjusncFub VDC3BauNTs6HTEVLMzS7S+cKNCJ/4Y/2iTxMbXChOQ== X-Received: by 2002:a17:90b:3911:b0:23f:9d83:ad76 with SMTP id ob17-20020a17090b391100b0023f9d83ad76mr24207104pjb.23.1680169646772; Thu, 30 Mar 2023 02:47:26 -0700 (PDT) Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com. [209.85.216.49]) by smtp.gmail.com with ESMTPSA id a7-20020a170902ecc700b0019c93ee6902sm24377605plh.109.2023.03.30.02.47.26 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 30 Mar 2023 02:47:26 -0700 (PDT) Received: by mail-pj1-f49.google.com with SMTP id d13so16748964pjh.0 for ; Thu, 30 Mar 2023 02:47:26 -0700 (PDT) X-Received: by 2002:a17:90b:2d82:b0:23b:349d:a159 with SMTP id sj2-20020a17090b2d8200b0023b349da159mr2215812pjb.3.1680169645576; Thu, 30 Mar 2023 02:47:25 -0700 (PDT) MIME-Version: 1.0 References: <20230321-kexec_clang16-v4-0-1340518f98e9@chromium.org> <20230321-kexec_clang16-v4-1-1340518f98e9@chromium.org> In-Reply-To: From: Ricardo Ribalda Date: Thu, 30 Mar 2023 11:47:14 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 1/2] kexec: Support purgatories with .text.hot sections To: Simon Horman Cc: Eric Biederman , linux-kernel@vger.kernel.org, Baoquan He , stable@vger.kernel.org, Ross Zwisler , Philipp Rudo , Steven Rostedt , kexec@lists.infradead.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Simon Thanks for your review! On Thu, 30 Mar 2023 at 09:49, Simon Horman wrote: > > On Mon, Mar 27, 2023 at 05:06:53PM +0200, Ricardo Ribalda wrote: > > Clang16 links the purgatory text in two sections: > > > > [ 1] .text PROGBITS 0000000000000000 00000040 > > 00000000000011a1 0000000000000000 AX 0 0 16 > > [ 2] .rela.text RELA 0000000000000000 00003498 > > 0000000000000648 0000000000000018 I 24 1 8 > > ... > > [17] .text.hot. PROGBITS 0000000000000000 00003220 > > 000000000000020b 0000000000000000 AX 0 0 1 > > [18] .rela.text.hot. RELA 0000000000000000 00004428 > > 0000000000000078 0000000000000018 I 24 17 8 > > > > And both of them have their range [sh_addr ... sh_addr+sh_size] on the > > area pointed by `e_entry`. > > > > This causes that image->start is calculated twice, once for .text and > > another time for .text.hot. The second calculation leaves image->start > > in a random location. > > > > Because of this, the system crashes inmediatly after: > > s/inmediatly/immediately/ > > > > > kexec_core: Starting new kernel > > > > Cc: stable@vger.kernel.org > > Maybe a fixes tag is warranted here. > > > Reviewed-by: Ross Zwisler > > Signed-off-by: Ricardo Ribalda > > --- > > kernel/kexec_file.c | 13 ++++++++++++- > > 1 file changed, 12 insertions(+), 1 deletion(-) > > > > diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c > > index f1a0e4e3fb5c..25a37d8f113a 100644 > > --- a/kernel/kexec_file.c > > +++ b/kernel/kexec_file.c > > @@ -901,10 +901,21 @@ static int kexec_purgatory_setup_sechdrs(struct purgatory_info *pi, > > } > > > > offset = ALIGN(offset, align); > > + > > + /* > > + * Check if the segment contains the entry point, if so, > > + * calculate the value of image->start based on it. > > + * If the compiler has produced more than one .text sections > > nit: s/sections/section/ > > > + * (Eg: .text.hot), they are generally after the main .text > > If this is the general case, then are there cases where this doesn't hold? When looking at this issue, I have only seen .text.hot after .text. But I cannot warantee that future versions of llvm or gcc decide to swap the order. I am going to add a WARN whenever there are two overlapping .text sections so the user has the chance to update their linker script. > > > + * section, and they shall not be used to calculate > > + * image->start. So do not re-calculate image->start if it > > + * is not set to the initial value. > > + */ > > if (sechdrs[i].sh_flags & SHF_EXECINSTR && > > pi->ehdr->e_entry >= sechdrs[i].sh_addr && > > pi->ehdr->e_entry < (sechdrs[i].sh_addr > > - + sechdrs[i].sh_size)) { > > + + sechdrs[i].sh_size) && > > + kbuf->image->start == pi->ehdr->e_entry) { > > kbuf->image->start -= sechdrs[i].sh_addr; > > kbuf->image->start += kbuf->mem + offset; > > } > > > > -- > > 2.40.0.348.gf938b09366-goog-b4-0.11.0-dev-696ae > > > > _______________________________________________ > > kexec mailing list > > kexec@lists.infradead.org > > http://lists.infradead.org/mailman/listinfo/kexec > > -- Ricardo Ribalda