Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp847791pxb; Fri, 16 Apr 2021 21:53:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypZchmqliDodPz+q5xhqUXYWevwt60w6pbZ+B+rukGrEBLEzWeUHRp9xjl85eWBo2cG6mv X-Received: by 2002:a17:906:6882:: with SMTP id n2mr11581177ejr.50.1618635208749; Fri, 16 Apr 2021 21:53:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618635208; cv=none; d=google.com; s=arc-20160816; b=hz9dZtaNmeWBTkjG1THbC43fvrm3rAFmiNisQaFGfyHr0Mz3sFsPWEep/HTmut3zOJ YANNkE4NYmJbWMZOi+WTTAIUv2xqwWyQZxEOTNIMmHte1aoW+TePEcrI8tZQ8p1i5huZ 3i42EkJ7dUcVx3fjg3jzhZ59JqTJTlAr7Fx43yCN4aQQ3czIcYuueJznMlo84WfvL/D1 i0Z88TL3iNPS4dk/GfZVHMjw0Eez3iH/cTP7tcFdss8MhW7/EK4sxQjfe3sHvkOQ1Ba5 qhsyUQxsvEZZgwMlkBr/zH3awFnK7n3Il7K/cT27Db+RW3ZynHx+x64GyEWfEjAk1Alh uTlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=QRWqXlrbMIubQMDOxB7EvLPJpCHxS4gSFuGLDnX8F9U=; b=tnlOrL2tXAk+l5tJ6B5UgltzroDmmStSmKIH6sqmIDCmrAoc3R+pvK/z+Yy3uvIuF1 bIKQYoUOZ7nECuQCk5dAhfi2yipoh7WNmbgEQ1+PDBbpu+55+o3g3nGMHf8CLevk9ZvL d89eSUrAzmoKMLlwY1w1c1e5nleq38rHVYDupHf+4YhuEANf0z7td0pmK1T9Miq/r4+w WUfXIOyxD3yBpFg9foxDxqIL/4QkrB4Yyzp4xr0fYqbvEzeEtTzacbwLuNK0z6qn9lh8 2qwWFHqybB7L+haWXTDbrPlJQTtFRZ20qNFsdrC8WLYjN08X1w6AjwxThsdxVle1gODQ e6AQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m19si7237146edd.340.2021.04.16.21.53.04; Fri, 16 Apr 2021 21:53:28 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229629AbhDQEwi (ORCPT + 99 others); Sat, 17 Apr 2021 00:52:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:53032 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbhDQEwf (ORCPT ); Sat, 17 Apr 2021 00:52:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9EB4860FE8; Sat, 17 Apr 2021 04:52:07 +0000 (UTC) Subject: Re: [PATCH v4 1/2] binfmt_flat: allow not offsetting data start To: Damien Le Moal , uclinux-dev@uclinux.org, Palmer Dabbelt , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Anup Patel , Christoph Hellwig References: <20210417011009.54569-1-damien.lemoal@wdc.com> <20210417011009.54569-2-damien.lemoal@wdc.com> From: Greg Ungerer Message-ID: <5227b984-f415-98b5-dae8-0cf84a71bb46@linux-m68k.org> Date: Sat, 17 Apr 2021 14:52:05 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <20210417011009.54569-2-damien.lemoal@wdc.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/4/21 11:10 am, Damien Le Moal wrote: > Commit 2217b9826246 ("binfmt_flat: revert "binfmt_flat: don't offset > the data start"") restored offsetting the start of the data section by > a number of words defined by MAX_SHARED_LIBS. As a result, since > MAX_SHARED_LIBS is never 0, a gap between the text and data sections > always exists. For architectures which cannot support a such gap > between the text and data sections (e.g. riscv nommu), flat binary > programs cannot be executed. > > To allow an architecture to request no data start offset to allow for > contiguous text and data sections for binaries flagged with > FLAT_FLAG_RAM, introduce the new config option > CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET. Using this new option, the > macro DATA_START_OFFSET_WORDS is conditionally defined in binfmt_flat.c > to MAX_SHARED_LIBS for architectures tolerating or needing the data > start offset (CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET disabled case) > and to 0 when CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET is enabled. > DATA_START_OFFSET_WORDS is used in load_flat_file() to calculate the > data section length and start position. > > Signed-off-by: Damien Le Moal > --- > fs/Kconfig.binfmt | 3 +++ > fs/binfmt_flat.c | 19 ++++++++++++++----- > 2 files changed, 17 insertions(+), 5 deletions(-) > > diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt > index c6f1c8c1934e..06fb7a93a1bd 100644 > --- a/fs/Kconfig.binfmt > +++ b/fs/Kconfig.binfmt > @@ -112,6 +112,9 @@ config BINFMT_FLAT_ARGVP_ENVP_ON_STACK > config BINFMT_FLAT_OLD_ALWAYS_RAM > bool > > +config BINFMT_FLAT_NO_DATA_START_OFFSET > + bool > + > config BINFMT_FLAT_OLD > bool "Enable support for very old legacy flat binaries" > depends on BINFMT_FLAT > diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c > index b9c658e0548e..1dc68dfba3e0 100644 > --- a/fs/binfmt_flat.c > +++ b/fs/binfmt_flat.c > @@ -74,6 +74,12 @@ > #define MAX_SHARED_LIBS (1) > #endif > > +#ifdef CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET > +#define DATA_START_OFFSET_WORDS (0) > +#else > +#define DATA_START_OFFSET_WORDS (MAX_SHARED_LIBS) > +#endif > + > struct lib_info { > struct { > unsigned long start_code; /* Start of text segment */ > @@ -560,6 +566,7 @@ static int load_flat_file(struct linux_binprm *bprm, > * it all together. > */ > if (!IS_ENABLED(CONFIG_MMU) && !(flags & (FLAT_FLAG_RAM|FLAT_FLAG_GZIP))) { > + Random white space change... Don't worry about re-spinning though, I will just edit this chunk out. > /* > * this should give us a ROM ptr, but if it doesn't we don't > * really care > @@ -576,7 +583,8 @@ static int load_flat_file(struct linux_binprm *bprm, > goto err; > } > > - len = data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long); > + len = data_len + extra + > + DATA_START_OFFSET_WORDS * sizeof(unsigned long); > len = PAGE_ALIGN(len); > realdatastart = vm_mmap(NULL, 0, len, > PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, 0); > @@ -591,7 +599,7 @@ static int load_flat_file(struct linux_binprm *bprm, > goto err; > } > datapos = ALIGN(realdatastart + > - MAX_SHARED_LIBS * sizeof(unsigned long), > + DATA_START_OFFSET_WORDS * sizeof(unsigned long), > FLAT_DATA_ALIGN); > > pr_debug("Allocated data+bss+stack (%u bytes): %lx\n", > @@ -622,7 +630,8 @@ static int load_flat_file(struct linux_binprm *bprm, > memp_size = len; > } else { > > - len = text_len + data_len + extra + MAX_SHARED_LIBS * sizeof(u32); > + len = text_len + data_len + extra + > + DATA_START_OFFSET_WORDS * sizeof(u32); > len = PAGE_ALIGN(len); > textpos = vm_mmap(NULL, 0, len, > PROT_READ | PROT_EXEC | PROT_WRITE, MAP_PRIVATE, 0); > @@ -638,7 +647,7 @@ static int load_flat_file(struct linux_binprm *bprm, > > realdatastart = textpos + ntohl(hdr->data_start); > datapos = ALIGN(realdatastart + > - MAX_SHARED_LIBS * sizeof(u32), > + DATA_START_OFFSET_WORDS * sizeof(u32), > FLAT_DATA_ALIGN); > > reloc = (__be32 __user *) > @@ -714,7 +723,7 @@ static int load_flat_file(struct linux_binprm *bprm, > ret = result; > pr_err("Unable to read code+data+bss, errno %d\n", ret); > vm_munmap(textpos, text_len + data_len + extra + > - MAX_SHARED_LIBS * sizeof(u32)); > + DATA_START_OFFSET_WORDS * sizeof(u32)); > goto err; > } > } > Thanks, otherwise looks good. Acked-by: Greg Ungerer I will push this into my m68knommu tree, for-next branch. I just carry the flat format changes in that tree now to make my life easier. Regards Greg