Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1449168 > unrolled thread
| Started by | Nicolas Pitre <nicolas.pitre@linaro.org> |
|---|---|
| First post | 2016-07-24 17:40 +0200 |
| Last post | 2016-07-26 03:00 +0200 |
| Articles | 6 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH v5 00/15] allow BFLT executables on systems with a MMU Nicolas Pitre <nicolas.pitre@linaro.org> - 2016-07-24 17:40 +0200
[PATCH v5 09/15] binfmt_flat: use clear_user() rather than memset() to clear .bss Nicolas Pitre <nicolas.pitre@linaro.org> - 2016-07-24 17:40 +0200
[PATCH v5 02/15] binfmt_flat: convert printk invocations to their modern form Nicolas Pitre <nicolas.pitre@linaro.org> - 2016-07-24 17:40 +0200
[PATCH v5 04/15] elf_fdpic_transfer_args_to_stack(): make it generic Nicolas Pitre <nicolas.pitre@linaro.org> - 2016-07-24 17:40 +0200
[PATCH v5 13/15] m68k: fix bFLT executable running on MMU enabled systems Nicolas Pitre <nicolas.pitre@linaro.org> - 2016-07-24 17:40 +0200
Re: [PATCH v5 00/15] allow BFLT executables on systems with a MMU Greg Ungerer <gerg@linux-m68k.org> - 2016-07-26 03:00 +0200
| From | Nicolas Pitre <nicolas.pitre@linaro.org> |
|---|---|
| Date | 2016-07-24 17:40 +0200 |
| Subject | [PATCH v5 00/15] allow BFLT executables on systems with a MMU |
| Message-ID | <rYtFw-19R-9@gated-at.bofh.it> |
This series provides the necessary changes to allow "flat" executable binaries meant for no-MMU systems to actually run on systems with a MMU. Also thrown in are various cleanups to binfmt_flat.c. This can also be found in the following git repo: git://git.linaro.org/people/nicolas.pitre/linux binfmt_flat_with_mmu *Why?* Because developing and testing natively on a large system with lots of RAM makes it so much more convenient to use all the existing profiling tools and debugging facilities that a kernel with lots of RAM can give. And incidentally, those systems with lots of RAM all have a MMU. *Why not use elf_fdpic?* The flat executable format is simple with very small footprint overhead, either in the executables themselves or kernel support. This makes the flat format more suitable than elf_fdpic for very small single user-app embedded systems. And while elf_fdpic binaries can run on MMU systems, flat binaries still couldn't, which just felt wrong. So here it is. The no-MMU support should remain unaffected, confirmed by Greg Ungerer. Tested with MMU on ARM and M68K. Changes since v4: - Isolated architecture specific changes in their own patches for easier review through their own path to mainline. - Added needed m68k register fixup from Greg Ungerer. Changes since v3: - Small cosmetic changes to pr_*(). - Addressed most important checkpatch complaints on the whole source file and patches in this seris. Changes since v2: - Added protection against a corrupted header that could have caused nasty overflows etc. Suggested by Alan Cox. - printk() modernization. Suggested by Greg Ungerer / Geert Uytterhoeven. - Added Greg Ungerer's reviewed-by tag. Changes since v1: - Removed SuperH and Xtensa from the Kconfig rule as they fail to build due to lack of get/put_unaligned_user(). - Clarified some commit logs a bit. diffstat: arch/arm/include/asm/flat.h | 5 +- arch/m68k/include/asm/flat.h | 11 +- arch/m68k/include/asm/processor.h | 2 - fs/Kconfig.binfmt | 3 +- fs/binfmt_elf_fdpic.c | 38 +-- fs/binfmt_flat.c | 525 ++++++++++++++++++-------------- fs/exec.c | 33 ++ include/linux/binfmts.h | 2 + 8 files changed, 345 insertions(+), 274 deletions(-)
[toc] | [next] | [standalone]
| From | Nicolas Pitre <nicolas.pitre@linaro.org> |
|---|---|
| Date | 2016-07-24 17:40 +0200 |
| Subject | [PATCH v5 09/15] binfmt_flat: use clear_user() rather than memset() to clear .bss |
| Message-ID | <rYtFx-19R-35@gated-at.bofh.it> |
| In reply to | #1449168 |
This is needed on systems with a MMU. Signed-off-by: Nicolas Pitre <nico@linaro.org> Reviewed-by: Greg Ungerer <gerg@linux-m68k.org> --- fs/binfmt_flat.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c index 63756ca6a7..92c1530a2c 100644 --- a/fs/binfmt_flat.c +++ b/fs/binfmt_flat.c @@ -795,10 +795,11 @@ static int load_flat_file(struct linux_binprm *bprm, flush_icache_range(start_code, end_code); /* zero the BSS, BRK and stack areas */ - memset((void *)(datapos + data_len), 0, bss_len + - (memp + memp_size - stack_len - /* end brk */ - libinfo->lib_list[id].start_brk) + /* start brk */ - stack_len); + if (clear_user((void __user *)(datapos + data_len), bss_len + + (memp + memp_size - stack_len - /* end brk */ + libinfo->lib_list[id].start_brk) + /* start brk */ + stack_len)) + return -EFAULT; return 0; err: -- 2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Nicolas Pitre <nicolas.pitre@linaro.org> |
|---|---|
| Date | 2016-07-24 17:40 +0200 |
| Subject | [PATCH v5 02/15] binfmt_flat: convert printk invocations to their modern form |
| Message-ID | <rYtFx-19R-41@gated-at.bofh.it> |
| In reply to | #1449168 |
Signed-off-by: Nicolas Pitre <nico@linaro.org>
---
fs/binfmt_flat.c | 118 ++++++++++++++++++++++++-------------------------------
1 file changed, 51 insertions(+), 67 deletions(-)
diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
index 892dba62bf..c3ccdefdea 100644
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -15,6 +15,8 @@
* JAN/99 -- coded full program relocation (gerg@snapgear.com)
*/
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/mm.h>
@@ -40,16 +42,6 @@
/****************************************************************************/
-#if 0
-#define DEBUG 1
-#endif
-
-#ifdef DEBUG
-#define DBG_FLT(a...) printk(a)
-#else
-#define DBG_FLT(a...)
-#endif
-
/*
* User data (data section and bss) needs to be aligned.
* We pick 0x20 here because it is the max value elf2flt has always
@@ -102,8 +94,8 @@ static struct linux_binfmt flat_format = {
static int flat_core_dump(struct coredump_params *cprm)
{
- printk("Process %s:%d received signr %d and should have core dumped\n",
- current->comm, current->pid, cprm->siginfo->si_signo);
+ pr_warn("Process %s:%d received signr %d and should have core dumped\n",
+ current->comm, current->pid, cprm->siginfo->si_signo);
return 1;
}
@@ -186,17 +178,17 @@ static int decompress_exec(
loff_t fpos;
int ret, retval;
- DBG_FLT("decompress_exec(offset=%lx,buf=%p,len=%lx)\n", offset, dst, len);
+ pr_debug("decompress_exec(offset=%lx,buf=%p,len=%lx)\n", offset, dst, len);
memset(&strm, 0, sizeof(strm));
strm.workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
if (strm.workspace == NULL) {
- DBG_FLT("binfmt_flat: no memory for decompress workspace\n");
+ pr_debug("no memory for decompress workspace\n");
return -ENOMEM;
}
buf = kmalloc(LBUFSIZE, GFP_KERNEL);
if (buf == NULL) {
- DBG_FLT("binfmt_flat: no memory for read buffer\n");
+ pr_debug("no memory for read buffer\n");
retval = -ENOMEM;
goto out_free;
}
@@ -214,25 +206,25 @@ static int decompress_exec(
/* Check minimum size -- gzip header */
if (ret < 10) {
- DBG_FLT("binfmt_flat: file too small?\n");
+ pr_debug("file too small?\n");
goto out_free_buf;
}
/* Check gzip magic number */
if ((buf[0] != 037) || ((buf[1] != 0213) && (buf[1] != 0236))) {
- DBG_FLT("binfmt_flat: unknown compression magic?\n");
+ pr_debug("unknown compression magic?\n");
goto out_free_buf;
}
/* Check gzip method */
if (buf[2] != 8) {
- DBG_FLT("binfmt_flat: unknown compression method?\n");
+ pr_debug("unknown compression method?\n");
goto out_free_buf;
}
/* Check gzip flags */
if ((buf[3] & ENCRYPTED) || (buf[3] & CONTINUATION) ||
(buf[3] & RESERVED)) {
- DBG_FLT("binfmt_flat: unknown flags?\n");
+ pr_debug("unknown flags?\n");
goto out_free_buf;
}
@@ -240,7 +232,7 @@ static int decompress_exec(
if (buf[3] & EXTRA_FIELD) {
ret += 2 + buf[10] + (buf[11] << 8);
if (unlikely(ret >= LBUFSIZE)) {
- DBG_FLT("binfmt_flat: buffer overflow (EXTRA)?\n");
+ pr_debug("buffer overflow (EXTRA)?\n");
goto out_free_buf;
}
}
@@ -248,7 +240,7 @@ static int decompress_exec(
while (ret < LBUFSIZE && buf[ret++] != 0)
;
if (unlikely(ret == LBUFSIZE)) {
- DBG_FLT("binfmt_flat: buffer overflow (ORIG_NAME)?\n");
+ pr_debug("buffer overflow (ORIG_NAME)?\n");
goto out_free_buf;
}
}
@@ -256,7 +248,7 @@ static int decompress_exec(
while (ret < LBUFSIZE && buf[ret++] != 0)
;
if (unlikely(ret == LBUFSIZE)) {
- DBG_FLT("binfmt_flat: buffer overflow (COMMENT)?\n");
+ pr_debug("buffer overflow (COMMENT)?\n");
goto out_free_buf;
}
}
@@ -269,7 +261,7 @@ static int decompress_exec(
strm.total_out = 0;
if (zlib_inflateInit2(&strm, -MAX_WBITS) != Z_OK) {
- DBG_FLT("binfmt_flat: zlib init failed?\n");
+ pr_debug("zlib init failed?\n");
goto out_free_buf;
}
@@ -286,7 +278,7 @@ static int decompress_exec(
}
if (ret < 0) {
- DBG_FLT("binfmt_flat: decompression failed (%d), %s\n",
+ pr_debug("decompression failed (%d), %s\n",
ret, strm.msg);
goto out_zlib;
}
@@ -323,24 +315,23 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp)
r &= 0x00ffffff; /* Trim ID off here */
}
if (id >= MAX_SHARED_LIBS) {
- printk("BINFMT_FLAT: reference 0x%lx to shared library %d",
- r, id);
+ pr_err("reference 0x%lx to shared library %d", r, id);
goto failed;
}
if (curid != id) {
if (internalp) {
- printk("BINFMT_FLAT: reloc address 0x%lx not in same module "
- "(%d != %d)", r, curid, id);
+ pr_err("reloc address 0x%lx not in same module "
+ "(%d != %d)", r, curid, id);
goto failed;
} else if (!p->lib_list[id].loaded &&
load_flat_shared_library(id, p) < 0) {
- printk("BINFMT_FLAT: failed to load library %d", id);
+ pr_err("failed to load library %d", id);
goto failed;
}
/* Check versioning information (i.e. time stamps) */
if (p->lib_list[id].build_date && p->lib_list[curid].build_date &&
p->lib_list[curid].build_date < p->lib_list[id].build_date) {
- printk("BINFMT_FLAT: library %d is younger than %d", id, curid);
+ pr_err("library %d is younger than %d", id, curid);
goto failed;
}
}
@@ -354,7 +345,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp)
text_len = p->lib_list[id].text_len;
if (!flat_reloc_valid(r, start_brk - start_data + text_len)) {
- printk("BINFMT_FLAT: reloc outside program 0x%lx (0 - 0x%lx/0x%lx)",
+ pr_err("reloc outside program 0x%lx (0 - 0x%lx/0x%lx)",
r, start_brk-start_data+text_len, text_len);
goto failed;
}
@@ -368,7 +359,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp)
return addr;
failed:
- printk(", killing %s!\n", current->comm);
+ pr_cont(", killing %s!\n", current->comm);
send_sig(SIGSEGV, current, 0);
return RELOC_FAILED;
@@ -378,9 +369,7 @@ failed:
static void old_reloc(unsigned long rl)
{
-#ifdef DEBUG
static const char *segment[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" };
-#endif
flat_v2_reloc_t r;
unsigned long *ptr;
@@ -391,11 +380,9 @@ static void old_reloc(unsigned long rl)
ptr = (unsigned long *) (current->mm->start_data + r.reloc.offset);
#endif
-#ifdef DEBUG
- printk("Relocation of variable at DATASEG+%x "
- "(address %p, currently %lx) into segment %s\n",
- r.reloc.offset, ptr, *ptr, segment[r.reloc.type]);
-#endif
+ pr_debug("Relocation of variable at DATASEG+%x "
+ "(address %p, currently %lx) into segment %s\n",
+ r.reloc.offset, ptr, *ptr, segment[r.reloc.type]);
switch (r.reloc.type) {
case OLD_FLAT_RELOC_TYPE_TEXT:
@@ -408,13 +395,11 @@ static void old_reloc(unsigned long rl)
*ptr += current->mm->end_data;
break;
default:
- printk("BINFMT_FLAT: Unknown relocation type=%x\n", r.reloc.type);
+ pr_err("Unknown relocation type=%x\n", r.reloc.type);
break;
}
-#ifdef DEBUG
- printk("Relocation became %lx\n", *ptr);
-#endif
+ pr_debug("Relocation became %lx\n", *ptr);
}
/****************************************************************************/
@@ -463,20 +448,19 @@ static int load_flat_file(struct linux_binprm *bprm,
}
if (flags & FLAT_FLAG_KTRACE)
- printk("BINFMT_FLAT: Loading file: %s\n", bprm->filename);
+ pr_info("Loading file: %s\n", bprm->filename);
if (rev != FLAT_VERSION && rev != OLD_FLAT_VERSION) {
- printk("BINFMT_FLAT: bad flat file version 0x%x (supported "
- "0x%lx and 0x%lx)\n",
- rev, FLAT_VERSION, OLD_FLAT_VERSION);
+ pr_err("bad flat file version 0x%x (supported 0x%lx and 0x%lx)\n",
+ rev, FLAT_VERSION, OLD_FLAT_VERSION);
ret = -ENOEXEC;
goto err;
}
/* Don't allow old format executables to use shared libraries */
if (rev == OLD_FLAT_VERSION && id != 0) {
- printk("BINFMT_FLAT: shared libraries are not available before rev 0x%lx\n",
- FLAT_VERSION);
+ pr_err("shared libraries are not available before rev 0x%lx\n",
+ FLAT_VERSION);
ret = -ENOEXEC;
goto err;
}
@@ -490,7 +474,7 @@ static int load_flat_file(struct linux_binprm *bprm,
#ifndef CONFIG_BINFMT_ZFLAT
if (flags & (FLAT_FLAG_GZIP|FLAT_FLAG_GZDATA)) {
- printk("Support for ZFLAT executables is not enabled.\n");
+ pr_err("Support for ZFLAT executables is not enabled.\n");
ret = -ENOEXEC;
goto err;
}
@@ -536,7 +520,7 @@ static int load_flat_file(struct linux_binprm *bprm,
* this should give us a ROM ptr, but if it doesn't we don't
* really care
*/
- DBG_FLT("BINFMT_FLAT: ROM mapping of file (we hope)\n");
+ pr_debug("ROM mapping of file (we hope)\n");
textpos = vm_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC,
MAP_PRIVATE|MAP_EXECUTABLE, 0);
@@ -544,7 +528,7 @@ static int load_flat_file(struct linux_binprm *bprm,
ret = textpos;
if (!textpos)
ret = -ENOMEM;
- printk("Unable to mmap process text, errno %d\n", ret);
+ pr_err("Unable to mmap process text, errno %d\n", ret);
goto err;
}
@@ -557,7 +541,7 @@ static int load_flat_file(struct linux_binprm *bprm,
ret = realdatastart;
if (!realdatastart)
ret = -ENOMEM;
- printk("Unable to allocate RAM for process data, "
+ pr_err("Unable to allocate RAM for process data, "
"errno %d\n", ret);
vm_munmap(textpos, text_len);
goto err;
@@ -566,8 +550,8 @@ static int load_flat_file(struct linux_binprm *bprm,
MAX_SHARED_LIBS * sizeof(unsigned long),
FLAT_DATA_ALIGN);
- DBG_FLT("BINFMT_FLAT: Allocated data+bss+stack (%ld bytes): %lx\n",
- data_len + bss_len + stack_len, datapos);
+ pr_debug("Allocated data+bss+stack (%ld bytes): %lx\n",
+ data_len + bss_len + stack_len, datapos);
fpos = ntohl(hdr->data_start);
#ifdef CONFIG_BINFMT_ZFLAT
@@ -582,7 +566,7 @@ static int load_flat_file(struct linux_binprm *bprm,
}
if (IS_ERR_VALUE(result)) {
ret = result;
- printk("Unable to read data+bss, errno %d\n", ret);
+ pr_err("Unable to read data+bss, errno %d\n", ret);
vm_munmap(textpos, text_len);
vm_munmap(realdatastart, len);
goto err;
@@ -603,7 +587,7 @@ static int load_flat_file(struct linux_binprm *bprm,
ret = textpos;
if (!textpos)
ret = -ENOMEM;
- printk("Unable to allocate RAM for process text/data, "
+ pr_err("Unable to allocate RAM for process text/data, "
"errno %d\n", ret);
goto err;
}
@@ -645,7 +629,7 @@ static int load_flat_file(struct linux_binprm *bprm,
}
if (IS_ERR_VALUE(result)) {
ret = result;
- printk("Unable to read code+data+bss, errno %d\n", ret);
+ pr_err("Unable to read code+data+bss, errno %d\n", ret);
vm_munmap(textpos, text_len + data_len + extra +
MAX_SHARED_LIBS * sizeof(unsigned long));
goto err;
@@ -675,12 +659,12 @@ static int load_flat_file(struct linux_binprm *bprm,
}
if (flags & FLAT_FLAG_KTRACE) {
- printk("Mapping is %lx, Entry point is %x, data_start is %x\n",
- textpos, 0x00ffffff&ntohl(hdr->entry), ntohl(hdr->data_start));
- printk("%s %s: TEXT=%lx-%lx DATA=%lx-%lx BSS=%lx-%lx\n",
- id ? "Lib" : "Load", bprm->filename,
- start_code, end_code, datapos, datapos + data_len,
- datapos + data_len, (datapos + data_len + bss_len + 3) & ~3);
+ pr_info("Mapping is %lx, Entry point is %x, data_start is %x\n",
+ textpos, 0x00ffffff&ntohl(hdr->entry), ntohl(hdr->data_start));
+ pr_info("%s %s: TEXT=%lx-%lx DATA=%lx-%lx BSS=%lx-%lx\n",
+ id ? "Lib" : "Load", bprm->filename,
+ start_code, end_code, datapos, datapos + data_len,
+ datapos + data_len, (datapos + data_len + bss_len + 3) & ~3);
}
/* Store the current module values into the global library structure */
@@ -890,7 +874,7 @@ static int load_flat_binary(struct linux_binprm *bprm)
set_binfmt(&flat_format);
p = ((current->mm->context.end_brk + stack_len + 3) & ~3) - 4;
- DBG_FLT("p=%lx\n", p);
+ pr_debug("p=%lx\n", p);
/* copy the arg pages onto the stack, this could be more efficient :-) */
for (i = TOP_OF_ARGS - 1; i >= bprm->p; i--)
@@ -922,8 +906,8 @@ static int load_flat_binary(struct linux_binprm *bprm)
FLAT_PLAT_INIT(regs);
#endif
- DBG_FLT("start_thread(regs=0x%p, entry=0x%lx, start_stack=0x%lx)\n",
- regs, start_addr, current->mm->start_stack);
+ pr_debug("start_thread(regs=0x%p, entry=0x%lx, start_stack=0x%lx)\n",
+ regs, start_addr, current->mm->start_stack);
start_thread(regs, start_addr, current->mm->start_stack);
return 0;
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Nicolas Pitre <nicolas.pitre@linaro.org> |
|---|---|
| Date | 2016-07-24 17:40 +0200 |
| Subject | [PATCH v5 04/15] elf_fdpic_transfer_args_to_stack(): make it generic |
| Message-ID | <rYtFx-19R-37@gated-at.bofh.it> |
| In reply to | #1449168 |
This copying of arguments and environment is common to both NOMMU
binary formats we support. Let's make the elf_fdpic version available
to the flat format as well.
While at it, improve the code a bit not to copy below the actual
data area.
Signed-off-by: Nicolas Pitre <nico@linaro.org>
Reviewed-by: Greg Ungerer <gerg@linux-m68k.org>
---
fs/binfmt_elf_fdpic.c | 38 ++------------------------------------
fs/exec.c | 33 +++++++++++++++++++++++++++++++++
include/linux/binfmts.h | 2 ++
3 files changed, 37 insertions(+), 36 deletions(-)
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index 203589311b..464a972e88 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -67,8 +67,6 @@ static int create_elf_fdpic_tables(struct linux_binprm *, struct mm_struct *,
struct elf_fdpic_params *);
#ifndef CONFIG_MMU
-static int elf_fdpic_transfer_args_to_stack(struct linux_binprm *,
- unsigned long *);
static int elf_fdpic_map_file_constdisp_on_uclinux(struct elf_fdpic_params *,
struct file *,
struct mm_struct *);
@@ -515,8 +513,9 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,
sp = mm->start_stack;
/* stack the program arguments and environment */
- if (elf_fdpic_transfer_args_to_stack(bprm, &sp) < 0)
+ if (transfer_args_to_stack(bprm, &sp) < 0)
return -EFAULT;
+ sp &= ~15;
#endif
/*
@@ -711,39 +710,6 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,
/*****************************************************************************/
/*
- * transfer the program arguments and environment from the holding pages onto
- * the stack
- */
-#ifndef CONFIG_MMU
-static int elf_fdpic_transfer_args_to_stack(struct linux_binprm *bprm,
- unsigned long *_sp)
-{
- unsigned long index, stop, sp;
- char *src;
- int ret = 0;
-
- stop = bprm->p >> PAGE_SHIFT;
- sp = *_sp;
-
- for (index = MAX_ARG_PAGES - 1; index >= stop; index--) {
- src = kmap(bprm->page[index]);
- sp -= PAGE_SIZE;
- if (copy_to_user((void *) sp, src, PAGE_SIZE) != 0)
- ret = -EFAULT;
- kunmap(bprm->page[index]);
- if (ret < 0)
- goto out;
- }
-
- *_sp = (*_sp - (MAX_ARG_PAGES * PAGE_SIZE - bprm->p)) & ~15;
-
-out:
- return ret;
-}
-#endif
-
-/*****************************************************************************/
-/*
* load the appropriate binary image (executable or interpreter) into memory
* - we assume no MMU is available
* - if no other PIC bits are set in params->hdr->e_flags
diff --git a/fs/exec.c b/fs/exec.c
index 887c1c955d..ef0df2f092 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -762,6 +762,39 @@ out_unlock:
}
EXPORT_SYMBOL(setup_arg_pages);
+#else
+
+/*
+ * Transfer the program arguments and environment from the holding pages
+ * onto the stack. The provided stack pointer is adjusted accordingly.
+ */
+int transfer_args_to_stack(struct linux_binprm *bprm,
+ unsigned long *sp_location)
+{
+ unsigned long index, stop, sp;
+ int ret = 0;
+
+ stop = bprm->p >> PAGE_SHIFT;
+ sp = *sp_location;
+
+ for (index = MAX_ARG_PAGES - 1; index >= stop; index--) {
+ unsigned int offset = index == stop ? bprm->p & ~PAGE_MASK : 0;
+ char *src = kmap(bprm->page[index]) + offset;
+ sp -= PAGE_SIZE - offset;
+ if (copy_to_user((void *) sp, src, PAGE_SIZE - offset) != 0)
+ ret = -EFAULT;
+ kunmap(bprm->page[index]);
+ if (ret)
+ goto out;
+ }
+
+ *sp_location = sp;
+
+out:
+ return ret;
+}
+EXPORT_SYMBOL(transfer_args_to_stack);
+
#endif /* CONFIG_MMU */
static struct file *do_open_execat(int fd, struct filename *name, int flags)
diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
index 314b3caa70..1303b570b1 100644
--- a/include/linux/binfmts.h
+++ b/include/linux/binfmts.h
@@ -113,6 +113,8 @@ extern int suid_dumpable;
extern int setup_arg_pages(struct linux_binprm * bprm,
unsigned long stack_top,
int executable_stack);
+extern int transfer_args_to_stack(struct linux_binprm *bprm,
+ unsigned long *sp_location);
extern int bprm_change_interp(char *interp, struct linux_binprm *bprm);
extern int copy_strings_kernel(int argc, const char *const *argv,
struct linux_binprm *bprm);
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Nicolas Pitre <nicolas.pitre@linaro.org> |
|---|---|
| Date | 2016-07-24 17:40 +0200 |
| Subject | [PATCH v5 13/15] m68k: fix bFLT executable running on MMU enabled systems |
| Message-ID | <rYtFx-19R-39@gated-at.bofh.it> |
| In reply to | #1449168 |
From: Greg Ungerer <gerg@linux-m68k.org>
Even after recent changes to support running flat format executables on
MMU enabled systems (by nicolas.pitre@linaro.org) they still failed to
run on m68k/ColdFire MMU enabled systems. On trying to run a flat format
binary the application would immediately crash with a SIGSEGV.
Code to setup the D5 register with the base of the application data
region was only in the non-MMU code path, so it was not being set for
the MMU enabled case. Flat binaries on m68k/ColdFire use this to support
GOT/PIC flat built application code.
Fix this so that D5 is always setup when loading/running a bFLT executable
on m68k systems.
Signed-off-by: Greg Ungerer <gerg@linux-m68k.org>
Signed-off-by: Nicolas Pitre <nico@linaro.org>
---
arch/m68k/include/asm/flat.h | 6 ++++++
arch/m68k/include/asm/processor.h | 2 --
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/arch/m68k/include/asm/flat.h b/arch/m68k/include/asm/flat.h
index f9454b89a5..f46c2f044f 100644
--- a/arch/m68k/include/asm/flat.h
+++ b/arch/m68k/include/asm/flat.h
@@ -18,4 +18,10 @@ static inline int flat_set_persistent(unsigned long relval,
return 0;
}
+#define FLAT_PLAT_INIT(regs) \
+ do { \
+ if (current->mm) \
+ (regs)->d5 = current->mm->start_data; \
+ } while (0)
+
#endif /* __M68KNOMMU_FLAT_H__ */
diff --git a/arch/m68k/include/asm/processor.h b/arch/m68k/include/asm/processor.h
index a6ce2ec8d6..46672d1f4d 100644
--- a/arch/m68k/include/asm/processor.h
+++ b/arch/m68k/include/asm/processor.h
@@ -131,8 +131,6 @@ extern int handle_kernel_fault(struct pt_regs *regs);
do { \
(_regs)->pc = (_pc); \
setframeformat(_regs); \
- if (current->mm) \
- (_regs)->d5 = current->mm->start_data; \
(_regs)->sr &= ~0x2000; \
wrusp(_usp); \
} while(0)
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Greg Ungerer <gerg@linux-m68k.org> |
|---|---|
| Date | 2016-07-26 03:00 +0200 |
| Message-ID | <rYYT0-3wo-3@gated-at.bofh.it> |
| In reply to | #1449168 |
On 25/07/16 01:30, Nicolas Pitre wrote: > This series provides the necessary changes to allow "flat" executable > binaries meant for no-MMU systems to actually run on systems with a MMU. > Also thrown in are various cleanups to binfmt_flat.c. > > This can also be found in the following git repo: > > git://git.linaro.org/people/nicolas.pitre/linux binfmt_flat_with_mmu So everyone is in the loop - I have pulled this into my for-linus branch at https://git.kernel.org/cgit/linux/kernel/git/gerg/m68knommu.git/ , excepting patch 15 (ARM specific changes). My continued testing hasn't found any issues on m68k platforms. I can completely boot up with a no-MMU user space and run on an MMU enabled ColdFire platform). I'll like to consider pushing this to Linus nearer the end of the merge window if no-one has any objections. Regards Greg > *Why?* > > Because developing and testing natively on a large system with lots of > RAM makes it so much more convenient to use all the existing profiling > tools and debugging facilities that a kernel with lots of RAM can give. > And incidentally, those systems with lots of RAM all have a MMU. > > *Why not use elf_fdpic?* > > The flat executable format is simple with very small footprint > overhead, either in the executables themselves or kernel support. > This makes the flat format more suitable than elf_fdpic for very small > single user-app embedded systems. > > And while elf_fdpic binaries can run on MMU systems, flat binaries still > couldn't, which just felt wrong. > > So here it is. The no-MMU support should remain unaffected, confirmed by > Greg Ungerer. Tested with MMU on ARM and M68K. > > Changes since v4: > > - Isolated architecture specific changes in their own patches for easier > review through their own path to mainline. > > - Added needed m68k register fixup from Greg Ungerer. > > Changes since v3: > > - Small cosmetic changes to pr_*(). > > - Addressed most important checkpatch complaints on the whole source file > and patches in this seris. > > Changes since v2: > > - Added protection against a corrupted header that could have caused nasty > overflows etc. Suggested by Alan Cox. > > - printk() modernization. Suggested by Greg Ungerer / Geert Uytterhoeven. > > - Added Greg Ungerer's reviewed-by tag. > > Changes since v1: > > - Removed SuperH and Xtensa from the Kconfig rule as they fail to build > due to lack of get/put_unaligned_user(). > > - Clarified some commit logs a bit. > > diffstat: > > arch/arm/include/asm/flat.h | 5 +- > arch/m68k/include/asm/flat.h | 11 +- > arch/m68k/include/asm/processor.h | 2 - > fs/Kconfig.binfmt | 3 +- > fs/binfmt_elf_fdpic.c | 38 +-- > fs/binfmt_flat.c | 525 ++++++++++++++++++-------------- > fs/exec.c | 33 ++ > include/linux/binfmts.h | 2 + > 8 files changed, 345 insertions(+), 274 deletions(-) >
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web