Skip to content

Commit cf9a566

Browse files
Christoph HellwigGreg Ungerer
authored andcommitted
binfmt_flat: make support for old format binaries optional
No need to carry the extra code around, given that systems using flat binaries are generally very resource constrained. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Greg Ungerer <gerg@linux-m68k.org>
1 parent aef0f78 commit cf9a566

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

fs/Kconfig.binfmt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ config BINFMT_FLAT_ARGVP_ENVP_ON_STACK
106106
config BINFMT_FLAT_OLD_ALWAYS_RAM
107107
bool
108108

109+
config BINFMT_FLAT_OLD
110+
bool "Enable support for very old legacy flat binaries"
111+
depends on BINFMT_FLAT
112+
help
113+
Support decade old uClinux FLAT format binaries. Unless you know
114+
you have some of those say N here.
115+
109116
config BINFMT_ZFLAT
110117
bool "Enable ZFLAT support"
111118
depends on BINFMT_FLAT

fs/binfmt_flat.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp)
374374

375375
/****************************************************************************/
376376

377+
#ifdef CONFIG_BINFMT_FLAT_OLD
377378
static void old_reloc(unsigned long rl)
378379
{
379380
static const char *segment[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" };
@@ -411,6 +412,7 @@ static void old_reloc(unsigned long rl)
411412

412413
pr_debug("Relocation became %lx\n", val);
413414
}
415+
#endif /* CONFIG_BINFMT_FLAT_OLD */
414416

415417
/****************************************************************************/
416418

@@ -461,6 +463,7 @@ static int load_flat_file(struct linux_binprm *bprm,
461463
if (flags & FLAT_FLAG_KTRACE)
462464
pr_info("Loading file: %s\n", bprm->filename);
463465

466+
#ifdef CONFIG_BINFMT_FLAT_OLD
464467
if (rev != FLAT_VERSION && rev != OLD_FLAT_VERSION) {
465468
pr_err("bad flat file version 0x%x (supported 0x%lx and 0x%lx)\n",
466469
rev, FLAT_VERSION, OLD_FLAT_VERSION);
@@ -476,6 +479,23 @@ static int load_flat_file(struct linux_binprm *bprm,
476479
goto err;
477480
}
478481

482+
/*
483+
* fix up the flags for the older format, there were all kinds
484+
* of endian hacks, this only works for the simple cases
485+
*/
486+
if (rev == OLD_FLAT_VERSION &&
487+
(flags || IS_ENABLED(CONFIG_BINFMT_FLAT_OLD_ALWAYS_RAM)))
488+
flags = FLAT_FLAG_RAM;
489+
490+
#else /* CONFIG_BINFMT_FLAT_OLD */
491+
if (rev != FLAT_VERSION) {
492+
pr_err("bad flat file version 0x%x (supported 0x%lx)\n",
493+
rev, FLAT_VERSION);
494+
ret = -ENOEXEC;
495+
goto err;
496+
}
497+
#endif /* !CONFIG_BINFMT_FLAT_OLD */
498+
479499
/*
480500
* Make sure the header params are sane.
481501
* 28 bits (256 MB) is way more than reasonable in this case.
@@ -487,14 +507,6 @@ static int load_flat_file(struct linux_binprm *bprm,
487507
goto err;
488508
}
489509

490-
/*
491-
* fix up the flags for the older format, there were all kinds
492-
* of endian hacks, this only works for the simple cases
493-
*/
494-
if (rev == OLD_FLAT_VERSION &&
495-
(flags || IS_ENABLED(CONFIG_BINFMT_FLAT_OLD_ALWAYS_RAM)))
496-
flags = FLAT_FLAG_RAM;
497-
498510
#ifndef CONFIG_BINFMT_ZFLAT
499511
if (flags & (FLAT_FLAG_GZIP|FLAT_FLAG_GZDATA)) {
500512
pr_err("Support for ZFLAT executables is not enabled.\n");
@@ -833,13 +845,15 @@ static int load_flat_file(struct linux_binprm *bprm,
833845
goto err;
834846
}
835847
}
848+
#ifdef CONFIG_BINFMT_FLAT_OLD
836849
} else {
837850
for (i = 0; i < relocs; i++) {
838851
__be32 relval;
839852
if (get_user(relval, reloc + i))
840853
return -EFAULT;
841854
old_reloc(ntohl(relval));
842855
}
856+
#endif /* CONFIG_BINFMT_FLAT_OLD */
843857
}
844858

845859
flush_icache_range(start_code, end_code);

0 commit comments

Comments
 (0)