Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2041472iof; Tue, 7 Jun 2022 17:53:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzm8H6fBxESu+SfSrLUiTb44TNSuk9OD3ZrQSv3nII8ZHzZtnKME7TsMmGeb+5kjoKaEX4c X-Received: by 2002:a17:90b:17c7:b0:1e8:5136:c32a with SMTP id me7-20020a17090b17c700b001e85136c32amr22964276pjb.43.1654649639702; Tue, 07 Jun 2022 17:53:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654649639; cv=none; d=google.com; s=arc-20160816; b=R3gQ+bCtL0CWrCg/m4q0ao9pGjoUTrXtd7Ab6/Y2Y9ENhHvwlROJr/vLzLMGEj0Zuk zf1CZzHt2WkLlHiVoReZMJV/NHFDOYXG+BppSrMbmZuuK2d0FKAbUdyjcDE8/4gqMnzA NX/bAl2af8B0b3z4Ab4CGJP2Ks4yDJ8slSdKkg0dtk1SqtTxlfZ5kg5dncjl7QnObCdq 0WnVRnEcLOtwRGh+4apOHrM3KCOEIKI+m0yfTGqKXPDIC5+rofyWJHey+UEZbREPpoVF cdkHMJ1eWVAcDNy+jdILRob/BTAqw9LAfn8k8P1fF5QbIn5rAaksMWi+JdX5tI2f0IBk eBoQ== 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=UkNsdE3B6C69qG7xj8QZJZKYTbkZOuyj1Q7mTmi6Dgc=; b=DPI5pNGgWl1X6isqgsEle1KfLTQwB9ne0+gr0dmLUIWRATEPKEwVopO1RjeIaZ+f9C z593L+OoLlOmkA+bN+D9vvTWyzOXqq2dy8tTeoMHT1sJ3sb+gbGBKyvB1YUkqnEgUmGW 6EbCwDfCPzqJEhoN0a7BdPIWZEPCDXJv5stFfm7jd8dEGNNMCDLPHtKWRPXvfEMk5dI+ r4wGFEWIb6c6aDi62kW8H9rqoTHUMrALc2oVh88JAtEF1+tnXulkPatwPoh3VMdiiY1n Qi5DZPmfU2Oc2H+nnIZzqzY8pNUQ+iTVKvE6xQpCP1FW3rlQoFNaCLXHWQ/R/OXFT3H4 CNVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b="Z/Kh8Wh2"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 19-20020a631753000000b003f9f41da8casi26452615pgx.14.2022.06.07.17.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 17:53:59 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b="Z/Kh8Wh2"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E16372258BA; Tue, 7 Jun 2022 17:50:41 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344741AbiFGQC5 (ORCPT + 99 others); Tue, 7 Jun 2022 12:02:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344745AbiFGQCr (ORCPT ); Tue, 7 Jun 2022 12:02:47 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7039B2C110 for ; Tue, 7 Jun 2022 09:02:44 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id x62so23598830ede.10 for ; Tue, 07 Jun 2022 09:02:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UkNsdE3B6C69qG7xj8QZJZKYTbkZOuyj1Q7mTmi6Dgc=; b=Z/Kh8Wh2nk+fd9Wk7zMUsNy3u2A1+k+peW4JYUIvcwhU56kfjQa4aZM/G+o+jAXFpO 4z8lDsEwFBXRJBOhkTVcTzl6qWlzuO0yEKeKnd8z1aWwSd0cQ1SKGRJmxN6H5nc1i75K PwGb7QkspkiCB4E43I7emWiHXjLal25L7diUV8BPhBWHM2AWa/UQ+dCj+5TF5JrqAtQM LIbUjLa0q+m8BO7BFawZokeLzqgZbOHJ+8qhfqHSWbDt1ibejZlygPmxYsagvyfnxx/i SLboHlhJTnEWT9RJnfql4AY1RyqF1HibWdcPVi96zWrqlFzPwP/60EU9eQtkm9+DrGvH EHaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UkNsdE3B6C69qG7xj8QZJZKYTbkZOuyj1Q7mTmi6Dgc=; b=46nn3p+A5V6m25mkLypeS2DcGY5BOUncE7jd6dRo+Qdh/b9gZ8Iwhs9vL+QjiM+Ffg ro3gd3y7rDPtjv266MS01HXubVHf+pH+xaEyISu70Q342ZoprxUd684lPKoPQun5zGgF 2MRX/EiKVzW3GwvQRWiVG1KcweBVh5dQ53PMKn2Dn7meibqc0MTPZxT4AoN0dovxoWDF j9/RCMlW1sEjwH0r0PUzm/7lBtSnNP++XA+eI2omxZ+KPL2mhfQDQdVR2BsY0Jk+racV A1/GkXEuAj49c9wtvWovxFzocR0C8g+ITJCqrez81L8xIA8qciJ0Ct+Mg3PuTiLu91lI rQbw== X-Gm-Message-State: AOAM530FgQyeDJUGd59yyCVEHlB8NR8S1fIC+Ue+6e0bpFVRh59m+jjn siQTaIF9FXSfueQ2CnZHhCBsycaRjoZ8kMCur4XW+A== X-Received: by 2002:a05:6402:34c2:b0:42f:79c0:334b with SMTP id w2-20020a05640234c200b0042f79c0334bmr25329803edc.88.1654617762674; Tue, 07 Jun 2022 09:02:42 -0700 (PDT) MIME-Version: 1.0 References: <20220527025535.3953665-1-pasha.tatashin@soleen.com> <20220527025535.3953665-3-pasha.tatashin@soleen.com> In-Reply-To: From: Pasha Tatashin Date: Tue, 7 Jun 2022 12:02:04 -0400 Message-ID: Subject: Re: [PATCH v2 2/2] kexec_file: Increase maximum file size to 4G To: Baoquan He Cc: Sasha Levin , "Eric W. Biederman" , rburanyi@google.com, Greg Thelen , viro@zeniv.linux.org.uk, kexec mailing list , linux-fsdevel@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Sun, Jun 5, 2022 at 10:56 PM Baoquan He wrote: > > On 05/27/22 at 02:55am, Pasha Tatashin wrote: > > In some case initrd can be large. For example, it could be a netboot > > image loaded by u-root, that is kexec'ing into it. > > > > The maximum size of initrd is arbitrary set to 2G. Also, the limit is > > not very obvious because it is hidden behind a generic INT_MAX macro. > > > > Theoretically, we could make it LONG_MAX, but it is safer to keep it > > sane, and just increase it to 4G. > > Do we need to care about 32bit system where initramfs could be larger > than 2G? On 32bit system, SSIZE_MAX is still 2G, right? Yes, on 32-bit SSIZE_MAX is still 2G, so we are safe to keep 32-bit systems run exactly as today. #define KEXEC_FILE_SIZE_MAX min_t(s64, 4LL << 30, SSIZE_MAX) Is meant to protect against running over the 2G limit on 32-bit systems. > > Another concern is if 2G is enough. If we can foresee it might need be > enlarged again in a near future, LONG_MAX certainly is not a good > value, but a little bigger multiple of 2G can be better? This little series enables increasing the max value above 2G, but still keeps it within a sane size i.e. 4G, If 4G seems too small, I can change it to 8G or 16G instead of 4G. Thanks, Pasha > > > > > Increase the size to 4G, and make it obvious by having a new macro > > that specifies the maximum file size supported by kexec_file_load() > > syscall: KEXEC_FILE_SIZE_MAX. > > > > Signed-off-by: Pasha Tatashin > > --- > > kernel/kexec_file.c | 10 +++++++--- > > 1 file changed, 7 insertions(+), 3 deletions(-) > > > > diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c > > index 8347fc158d2b..f00cf70d82b9 100644 > > --- a/kernel/kexec_file.c > > +++ b/kernel/kexec_file.c > > @@ -31,6 +31,9 @@ > > > > static int kexec_calculate_store_digests(struct kimage *image); > > > > +/* Maximum size in bytes for kernel/initrd files. */ > > +#define KEXEC_FILE_SIZE_MAX min_t(s64, 4LL << 30, SSIZE_MAX) > > + > > /* > > * Currently this is the only default function that is exported as some > > * architectures need it to do additional handlings. > > @@ -223,11 +226,12 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, > > const char __user *cmdline_ptr, > > unsigned long cmdline_len, unsigned flags) > > { > > - int ret; > > + ssize_t ret; > > void *ldata; > > > > ret = kernel_read_file_from_fd(kernel_fd, 0, &image->kernel_buf, > > - INT_MAX, NULL, READING_KEXEC_IMAGE); > > + KEXEC_FILE_SIZE_MAX, NULL, > > + READING_KEXEC_IMAGE); > > if (ret < 0) > > return ret; > > image->kernel_buf_len = ret; > > @@ -247,7 +251,7 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, > > /* It is possible that there no initramfs is being loaded */ > > if (!(flags & KEXEC_FILE_NO_INITRAMFS)) { > > ret = kernel_read_file_from_fd(initrd_fd, 0, &image->initrd_buf, > > - INT_MAX, NULL, > > + KEXEC_FILE_SIZE_MAX, NULL, > > READING_KEXEC_INITRAMFS); > > if (ret < 0) > > goto out; > > -- > > 2.36.1.124.g0e6072fb45-goog > > >