summaryrefslogtreecommitdiffstats
path: root/fs/binfmt_flat.c
diff options
context:
space:
mode:
authorNicolas Pitre <nicolas.pitre@linaro.org>2016-07-24 11:30:16 -0400
committerGreg Ungerer <gerg@linux-m68k.org>2016-07-25 02:51:37 -0400
commit4adbb6ac4b807e2f3f07887cf2a925fa012a7825 (patch)
tree96e88133ad4d88af99b2f599a59af83b8bad957b /fs/binfmt_flat.c
parent13c3f50c914e6a51d11e1aba4a85c2223e197e13 (diff)
binfmt_flat: convert printk invocations to their modern form
Signed-off-by: Nicolas Pitre <nico@linaro.org> Signed-off-by: Greg Ungerer <gerg@linux-m68k.org>
Diffstat (limited to 'fs/binfmt_flat.c')
-rw-r--r--fs/binfmt_flat.c118
1 files changed, 51 insertions, 67 deletions
diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
index 892dba62bf2e..c3ccdefdeac2 100644
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -15,6 +15,8 @@
15 * JAN/99 -- coded full program relocation (gerg@snapgear.com) 15 * JAN/99 -- coded full program relocation (gerg@snapgear.com)
16 */ 16 */
17 17
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
18#include <linux/kernel.h> 20#include <linux/kernel.h>
19#include <linux/sched.h> 21#include <linux/sched.h>
20#include <linux/mm.h> 22#include <linux/mm.h>
@@ -40,16 +42,6 @@
40 42
41/****************************************************************************/ 43/****************************************************************************/
42 44
43#if 0
44#define DEBUG 1
45#endif
46
47#ifdef DEBUG
48#define DBG_FLT(a...) printk(a)
49#else
50#define DBG_FLT(a...)
51#endif
52
53/* 45/*
54 * User data (data section and bss) needs to be aligned. 46 * User data (data section and bss) needs to be aligned.
55 * We pick 0x20 here because it is the max value elf2flt has always 47 * We pick 0x20 here because it is the max value elf2flt has always
@@ -102,8 +94,8 @@ static struct linux_binfmt flat_format = {
102 94
103static int flat_core_dump(struct coredump_params *cprm) 95static int flat_core_dump(struct coredump_params *cprm)
104{ 96{
105 printk("Process %s:%d received signr %d and should have core dumped\n", 97 pr_warn("Process %s:%d received signr %d and should have core dumped\n",
106 current->comm, current->pid, cprm->siginfo->si_signo); 98 current->comm, current->pid, cprm->siginfo->si_signo);
107 return 1; 99 return 1;
108} 100}
109 101
@@ -186,17 +178,17 @@ static int decompress_exec(
186 loff_t fpos; 178 loff_t fpos;
187 int ret, retval; 179 int ret, retval;
188 180
189 DBG_FLT("decompress_exec(offset=%lx,buf=%p,len=%lx)\n", offset, dst, len); 181 pr_debug("decompress_exec(offset=%lx,buf=%p,len=%lx)\n", offset, dst, len);
190 182
191 memset(&strm, 0, sizeof(strm)); 183 memset(&strm, 0, sizeof(strm));
192 strm.workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL); 184 strm.workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
193 if (strm.workspace == NULL) { 185 if (strm.workspace == NULL) {
194 DBG_FLT("binfmt_flat: no memory for decompress workspace\n"); 186 pr_debug("no memory for decompress workspace\n");
195 return -ENOMEM; 187 return -ENOMEM;
196 } 188 }
197 buf = kmalloc(LBUFSIZE, GFP_KERNEL); 189 buf = kmalloc(LBUFSIZE, GFP_KERNEL);
198 if (buf == NULL) { 190 if (buf == NULL) {
199 DBG_FLT("binfmt_flat: no memory for read buffer\n"); 191 pr_debug("no memory for read buffer\n");
200 retval = -ENOMEM; 192 retval = -ENOMEM;
201 goto out_free; 193 goto out_free;
202 } 194 }
@@ -214,25 +206,25 @@ static int decompress_exec(
214 206
215 /* Check minimum size -- gzip header */ 207 /* Check minimum size -- gzip header */
216 if (ret < 10) { 208 if (ret < 10) {
217 DBG_FLT("binfmt_flat: file too small?\n"); 209 pr_debug("file too small?\n");
218 goto out_free_buf; 210 goto out_free_buf;
219 } 211 }
220 212
221 /* Check gzip magic number */ 213 /* Check gzip magic number */
222 if ((buf[0] != 037) || ((buf[1] != 0213) && (buf[1] != 0236))) { 214 if ((buf[0] != 037) || ((buf[1] != 0213) && (buf[1] != 0236))) {
223 DBG_FLT("binfmt_flat: unknown compression magic?\n"); 215 pr_debug("unknown compression magic?\n");
224 goto out_free_buf; 216 goto out_free_buf;
225 } 217 }
226 218
227 /* Check gzip method */ 219 /* Check gzip method */
228 if (buf[2] != 8) { 220 if (buf[2] != 8) {
229 DBG_FLT("binfmt_flat: unknown compression method?\n"); 221 pr_debug("unknown compression method?\n");
230 goto out_free_buf; 222 goto out_free_buf;
231 } 223 }
232 /* Check gzip flags */ 224 /* Check gzip flags */
233 if ((buf[3] & ENCRYPTED) || (buf[3] & CONTINUATION) || 225 if ((buf[3] & ENCRYPTED) || (buf[3] & CONTINUATION) ||
234 (buf[3] & RESERVED)) { 226 (buf[3] & RESERVED)) {
235 DBG_FLT("binfmt_flat: unknown flags?\n"); 227 pr_debug("unknown flags?\n");
236 goto out_free_buf; 228 goto out_free_buf;
237 } 229 }
238 230
@@ -240,7 +232,7 @@ static int decompress_exec(
240 if (buf[3] & EXTRA_FIELD) { 232 if (buf[3] & EXTRA_FIELD) {
241 ret += 2 + buf[10] + (buf[11] << 8); 233 ret += 2 + buf[10] + (buf[11] << 8);
242 if (unlikely(ret >= LBUFSIZE)) { 234 if (unlikely(ret >= LBUFSIZE)) {
243 DBG_FLT("binfmt_flat: buffer overflow (EXTRA)?\n"); 235 pr_debug("buffer overflow (EXTRA)?\n");
244 goto out_free_buf; 236 goto out_free_buf;
245 } 237 }
246 } 238 }
@@ -248,7 +240,7 @@ static int decompress_exec(
248 while (ret < LBUFSIZE && buf[ret++] != 0) 240 while (ret < LBUFSIZE && buf[ret++] != 0)
249 ; 241 ;
250 if (unlikely(ret == LBUFSIZE)) { 242 if (unlikely(ret == LBUFSIZE)) {
251 DBG_FLT("binfmt_flat: buffer overflow (ORIG_NAME)?\n"); 243 pr_debug("buffer overflow (ORIG_NAME)?\n");
252 goto out_free_buf; 244 goto out_free_buf;
253 } 245 }
254 } 246 }
@@ -256,7 +248,7 @@ static int decompress_exec(
256 while (ret < LBUFSIZE && buf[ret++] != 0) 248 while (ret < LBUFSIZE && buf[ret++] != 0)
257 ; 249 ;
258 if (unlikely(ret == LBUFSIZE)) { 250 if (unlikely(ret == LBUFSIZE)) {
259 DBG_FLT("binfmt_flat: buffer overflow (COMMENT)?\n"); 251 pr_debug("buffer overflow (COMMENT)?\n");
260 goto out_free_buf; 252 goto out_free_buf;
261 } 253 }
262 } 254 }
@@ -269,7 +261,7 @@ static int decompress_exec(
269 strm.total_out = 0; 261 strm.total_out = 0;
270 262
271 if (zlib_inflateInit2(&strm, -MAX_WBITS) != Z_OK) { 263 if (zlib_inflateInit2(&strm, -MAX_WBITS) != Z_OK) {
272 DBG_FLT("binfmt_flat: zlib init failed?\n"); 264 pr_debug("zlib init failed?\n");
273 goto out_free_buf; 265 goto out_free_buf;
274 } 266 }
275 267
@@ -286,7 +278,7 @@ static int decompress_exec(
286 } 278 }
287 279
288 if (ret < 0) { 280 if (ret < 0) {
289 DBG_FLT("binfmt_flat: decompression failed (%d), %s\n", 281 pr_debug("decompression failed (%d), %s\n",
290 ret, strm.msg); 282 ret, strm.msg);
291 goto out_zlib; 283 goto out_zlib;
292 } 284 }
@@ -323,24 +315,23 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp)
323 r &= 0x00ffffff; /* Trim ID off here */ 315 r &= 0x00ffffff; /* Trim ID off here */
324 } 316 }
325 if (id >= MAX_SHARED_LIBS) { 317 if (id >= MAX_SHARED_LIBS) {
326 printk("BINFMT_FLAT: reference 0x%lx to shared library %d", 318 pr_err("reference 0x%lx to shared library %d", r, id);
327 r, id);
328 goto failed; 319 goto failed;
329 } 320 }
330 if (curid != id) { 321 if (curid != id) {
331 if (internalp) { 322 if (internalp) {
332 printk("BINFMT_FLAT: reloc address 0x%lx not in same module " 323 pr_err("reloc address 0x%lx not in same module "
333 "(%d != %d)", r, curid, id); 324 "(%d != %d)", r, curid, id);
334 goto failed; 325 goto failed;
335 } else if (!p->lib_list[id].loaded && 326 } else if (!p->lib_list[id].loaded &&
336 load_flat_shared_library(id, p) < 0) { 327 load_flat_shared_library(id, p) < 0) {
337 printk("BINFMT_FLAT: failed to load library %d", id); 328 pr_err("failed to load library %d", id);
338 goto failed; 329 goto failed;
339 } 330 }
340 /* Check versioning information (i.e. time stamps) */ 331 /* Check versioning information (i.e. time stamps) */
341 if (p->lib_list[id].build_date && p->lib_list[curid].build_date && 332 if (p->lib_list[id].build_date && p->lib_list[curid].build_date &&
342 p->lib_list[curid].build_date < p->lib_list[id].build_date) { 333 p->lib_list[curid].build_date < p->lib_list[id].build_date) {
343 printk("BINFMT_FLAT: library %d is younger than %d", id, curid); 334 pr_err("library %d is younger than %d", id, curid);
344 goto failed; 335 goto failed;
345 } 336 }
346 } 337 }
@@ -354,7 +345,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp)
354 text_len = p->lib_list[id].text_len; 345 text_len = p->lib_list[id].text_len;
355 346
356 if (!flat_reloc_valid(r, start_brk - start_data + text_len)) { 347 if (!flat_reloc_valid(r, start_brk - start_data + text_len)) {
357 printk("BINFMT_FLAT: reloc outside program 0x%lx (0 - 0x%lx/0x%lx)", 348 pr_err("reloc outside program 0x%lx (0 - 0x%lx/0x%lx)",
358 r, start_brk-start_data+text_len, text_len); 349 r, start_brk-start_data+text_len, text_len);
359 goto failed; 350 goto failed;
360 } 351 }
@@ -368,7 +359,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp)
368 return addr; 359 return addr;
369 360
370failed: 361failed:
371 printk(", killing %s!\n", current->comm); 362 pr_cont(", killing %s!\n", current->comm);
372 send_sig(SIGSEGV, current, 0); 363 send_sig(SIGSEGV, current, 0);
373 364
374 return RELOC_FAILED; 365 return RELOC_FAILED;
@@ -378,9 +369,7 @@ failed:
378 369
379static void old_reloc(unsigned long rl) 370static void old_reloc(unsigned long rl)
380{ 371{
381#ifdef DEBUG
382 static const char *segment[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" }; 372 static const char *segment[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" };
383#endif
384 flat_v2_reloc_t r; 373 flat_v2_reloc_t r;
385 unsigned long *ptr; 374 unsigned long *ptr;
386 375
@@ -391,11 +380,9 @@ static void old_reloc(unsigned long rl)
391 ptr = (unsigned long *) (current->mm->start_data + r.reloc.offset); 380 ptr = (unsigned long *) (current->mm->start_data + r.reloc.offset);
392#endif 381#endif
393 382
394#ifdef DEBUG 383 pr_debug("Relocation of variable at DATASEG+%x "
395 printk("Relocation of variable at DATASEG+%x " 384 "(address %p, currently %lx) into segment %s\n",
396 "(address %p, currently %lx) into segment %s\n", 385 r.reloc.offset, ptr, *ptr, segment[r.reloc.type]);
397 r.reloc.offset, ptr, *ptr, segment[r.reloc.type]);
398#endif
399 386
400 switch (r.reloc.type) { 387 switch (r.reloc.type) {
401 case OLD_FLAT_RELOC_TYPE_TEXT: 388 case OLD_FLAT_RELOC_TYPE_TEXT:
@@ -408,13 +395,11 @@ static void old_reloc(unsigned long rl)
408 *ptr += current->mm->end_data; 395 *ptr += current->mm->end_data;
409 break; 396 break;
410 default: 397 default:
411 printk("BINFMT_FLAT: Unknown relocation type=%x\n", r.reloc.type); 398 pr_err("Unknown relocation type=%x\n", r.reloc.type);
412 break; 399 break;
413 } 400 }
414 401
415#ifdef DEBUG 402 pr_debug("Relocation became %lx\n", *ptr);
416 printk("Relocation became %lx\n", *ptr);
417#endif
418} 403}
419 404
420/****************************************************************************/ 405/****************************************************************************/
@@ -463,20 +448,19 @@ static int load_flat_file(struct linux_binprm *bprm,
463 } 448 }
464 449
465 if (flags & FLAT_FLAG_KTRACE) 450 if (flags & FLAT_FLAG_KTRACE)
466 printk("BINFMT_FLAT: Loading file: %s\n", bprm->filename); 451 pr_info("Loading file: %s\n", bprm->filename);
467 452
468 if (rev != FLAT_VERSION && rev != OLD_FLAT_VERSION) { 453 if (rev != FLAT_VERSION && rev != OLD_FLAT_VERSION) {
469 printk("BINFMT_FLAT: bad flat file version 0x%x (supported " 454 pr_err("bad flat file version 0x%x (supported 0x%lx and 0x%lx)\n",
470 "0x%lx and 0x%lx)\n", 455 rev, FLAT_VERSION, OLD_FLAT_VERSION);
471 rev, FLAT_VERSION, OLD_FLAT_VERSION);
472 ret = -ENOEXEC; 456 ret = -ENOEXEC;
473 goto err; 457 goto err;
474 } 458 }
475 459
476 /* Don't allow old format executables to use shared libraries */ 460 /* Don't allow old format executables to use shared libraries */
477 if (rev == OLD_FLAT_VERSION && id != 0) { 461 if (rev == OLD_FLAT_VERSION && id != 0) {
478 printk("BINFMT_FLAT: shared libraries are not available before rev 0x%lx\n", 462 pr_err("shared libraries are not available before rev 0x%lx\n",
479 FLAT_VERSION); 463 FLAT_VERSION);
480 ret = -ENOEXEC; 464 ret = -ENOEXEC;
481 goto err; 465 goto err;
482 } 466 }
@@ -490,7 +474,7 @@ static int load_flat_file(struct linux_binprm *bprm,
490 474
491#ifndef CONFIG_BINFMT_ZFLAT 475#ifndef CONFIG_BINFMT_ZFLAT
492 if (flags & (FLAT_FLAG_GZIP|FLAT_FLAG_GZDATA)) { 476 if (flags & (FLAT_FLAG_GZIP|FLAT_FLAG_GZDATA)) {
493 printk("Support for ZFLAT executables is not enabled.\n"); 477 pr_err("Support for ZFLAT executables is not enabled.\n");
494 ret = -ENOEXEC; 478 ret = -ENOEXEC;
495 goto err; 479 goto err;
496 } 480 }
@@ -536,7 +520,7 @@ static int load_flat_file(struct linux_binprm *bprm,
536 * this should give us a ROM ptr, but if it doesn't we don't 520 * this should give us a ROM ptr, but if it doesn't we don't
537 * really care 521 * really care
538 */ 522 */
539 DBG_FLT("BINFMT_FLAT: ROM mapping of file (we hope)\n"); 523 pr_debug("ROM mapping of file (we hope)\n");
540 524
541 textpos = vm_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC, 525 textpos = vm_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC,
542 MAP_PRIVATE|MAP_EXECUTABLE, 0); 526 MAP_PRIVATE|MAP_EXECUTABLE, 0);
@@ -544,7 +528,7 @@ static int load_flat_file(struct linux_binprm *bprm,
544 ret = textpos; 528 ret = textpos;
545 if (!textpos) 529 if (!textpos)
546 ret = -ENOMEM; 530 ret = -ENOMEM;
547 printk("Unable to mmap process text, errno %d\n", ret); 531 pr_err("Unable to mmap process text, errno %d\n", ret);
548 goto err; 532 goto err;
549 } 533 }
550 534
@@ -557,7 +541,7 @@ static int load_flat_file(struct linux_binprm *bprm,
557 ret = realdatastart; 541 ret = realdatastart;
558 if (!realdatastart) 542 if (!realdatastart)
559 ret = -ENOMEM; 543 ret = -ENOMEM;
560 printk("Unable to allocate RAM for process data, " 544 pr_err("Unable to allocate RAM for process data, "
561 "errno %d\n", ret); 545 "errno %d\n", ret);
562 vm_munmap(textpos, text_len); 546 vm_munmap(textpos, text_len);
563 goto err; 547 goto err;
@@ -566,8 +550,8 @@ static int load_flat_file(struct linux_binprm *bprm,
566 MAX_SHARED_LIBS * sizeof(unsigned long), 550 MAX_SHARED_LIBS * sizeof(unsigned long),
567 FLAT_DATA_ALIGN); 551 FLAT_DATA_ALIGN);
568 552
569 DBG_FLT("BINFMT_FLAT: Allocated data+bss+stack (%ld bytes): %lx\n", 553 pr_debug("Allocated data+bss+stack (%ld bytes): %lx\n",
570 data_len + bss_len + stack_len, datapos); 554 data_len + bss_len + stack_len, datapos);
571 555
572 fpos = ntohl(hdr->data_start); 556 fpos = ntohl(hdr->data_start);
573#ifdef CONFIG_BINFMT_ZFLAT 557#ifdef CONFIG_BINFMT_ZFLAT
@@ -582,7 +566,7 @@ static int load_flat_file(struct linux_binprm *bprm,
582 } 566 }
583 if (IS_ERR_VALUE(result)) { 567 if (IS_ERR_VALUE(result)) {
584 ret = result; 568 ret = result;
585 printk("Unable to read data+bss, errno %d\n", ret); 569 pr_err("Unable to read data+bss, errno %d\n", ret);
586 vm_munmap(textpos, text_len); 570 vm_munmap(textpos, text_len);
587 vm_munmap(realdatastart, len); 571 vm_munmap(realdatastart, len);
588 goto err; 572 goto err;
@@ -603,7 +587,7 @@ static int load_flat_file(struct linux_binprm *bprm,
603 ret = textpos; 587 ret = textpos;
604 if (!textpos) 588 if (!textpos)
605 ret = -ENOMEM; 589 ret = -ENOMEM;
606 printk("Unable to allocate RAM for process text/data, " 590 pr_err("Unable to allocate RAM for process text/data, "
607 "errno %d\n", ret); 591 "errno %d\n", ret);
608 goto err; 592 goto err;
609 } 593 }
@@ -645,7 +629,7 @@ static int load_flat_file(struct linux_binprm *bprm,
645 } 629 }
646 if (IS_ERR_VALUE(result)) { 630 if (IS_ERR_VALUE(result)) {
647 ret = result; 631 ret = result;
648 printk("Unable to read code+data+bss, errno %d\n", ret); 632 pr_err("Unable to read code+data+bss, errno %d\n", ret);
649 vm_munmap(textpos, text_len + data_len + extra + 633 vm_munmap(textpos, text_len + data_len + extra +
650 MAX_SHARED_LIBS * sizeof(unsigned long)); 634 MAX_SHARED_LIBS * sizeof(unsigned long));
651 goto err; 635 goto err;
@@ -675,12 +659,12 @@ static int load_flat_file(struct linux_binprm *bprm,
675 } 659 }
676 660
677 if (flags & FLAT_FLAG_KTRACE) { 661 if (flags & FLAT_FLAG_KTRACE) {
678 printk("Mapping is %lx, Entry point is %x, data_start is %x\n", 662 pr_info("Mapping is %lx, Entry point is %x, data_start is %x\n",
679 textpos, 0x00ffffff&ntohl(hdr->entry), ntohl(hdr->data_start)); 663 textpos, 0x00ffffff&ntohl(hdr->entry), ntohl(hdr->data_start));
680 printk("%s %s: TEXT=%lx-%lx DATA=%lx-%lx BSS=%lx-%lx\n", 664 pr_info("%s %s: TEXT=%lx-%lx DATA=%lx-%lx BSS=%lx-%lx\n",
681 id ? "Lib" : "Load", bprm->filename, 665 id ? "Lib" : "Load", bprm->filename,
682 start_code, end_code, datapos, datapos + data_len, 666 start_code, end_code, datapos, datapos + data_len,
683 datapos + data_len, (datapos + data_len + bss_len + 3) & ~3); 667 datapos + data_len, (datapos + data_len + bss_len + 3) & ~3);
684 } 668 }
685 669
686 /* Store the current module values into the global library structure */ 670 /* Store the current module values into the global library structure */
@@ -890,7 +874,7 @@ static int load_flat_binary(struct linux_binprm *bprm)
890 set_binfmt(&flat_format); 874 set_binfmt(&flat_format);
891 875
892 p = ((current->mm->context.end_brk + stack_len + 3) & ~3) - 4; 876 p = ((current->mm->context.end_brk + stack_len + 3) & ~3) - 4;
893 DBG_FLT("p=%lx\n", p); 877 pr_debug("p=%lx\n", p);
894 878
895 /* copy the arg pages onto the stack, this could be more efficient :-) */ 879 /* copy the arg pages onto the stack, this could be more efficient :-) */
896 for (i = TOP_OF_ARGS - 1; i >= bprm->p; i--) 880 for (i = TOP_OF_ARGS - 1; i >= bprm->p; i--)
@@ -922,8 +906,8 @@ static int load_flat_binary(struct linux_binprm *bprm)
922 FLAT_PLAT_INIT(regs); 906 FLAT_PLAT_INIT(regs);
923#endif 907#endif
924 908
925 DBG_FLT("start_thread(regs=0x%p, entry=0x%lx, start_stack=0x%lx)\n", 909 pr_debug("start_thread(regs=0x%p, entry=0x%lx, start_stack=0x%lx)\n",
926 regs, start_addr, current->mm->start_stack); 910 regs, start_addr, current->mm->start_stack);
927 start_thread(regs, start_addr, current->mm->start_stack); 911 start_thread(regs, start_addr, current->mm->start_stack);
928 912
929 return 0; 913 return 0;