Skip to content

Commit e6c1baa

Browse files
author
Al Viro
committed
convert the rest of binfmt_elf_fdpic to dump_emit()
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 13046ec commit e6c1baa

1 file changed

Lines changed: 31 additions & 79 deletions

File tree

‎fs/binfmt_elf_fdpic.c‎

Lines changed: 31 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,35 +1267,23 @@ static int notesize(struct memelfnote *en)
12671267

12681268
/* #define DEBUG */
12691269

1270-
#define DUMP_WRITE(addr, nr, foffset) \
1271-
do { if (!dump_write(file, (addr), (nr))) return 0; *foffset += (nr); } while(0)
1272-
1273-
static int alignfile(struct file *file, loff_t *foffset)
1270+
static int alignfile(struct coredump_params *cprm)
12741271
{
12751272
static const char buf[4] = { 0, };
1276-
DUMP_WRITE(buf, roundup(*foffset, 4) - *foffset, foffset);
1277-
return 1;
1273+
return dump_emit(cprm, buf, roundup(cprm->written, 4) - cprm->written);
12781274
}
12791275

1280-
static int writenote(struct memelfnote *men, struct file *file,
1281-
loff_t *foffset)
1276+
static int writenote(struct memelfnote *men, struct coredump_params *cprm)
12821277
{
12831278
struct elf_note en;
12841279
en.n_namesz = strlen(men->name) + 1;
12851280
en.n_descsz = men->datasz;
12861281
en.n_type = men->type;
12871282

1288-
DUMP_WRITE(&en, sizeof(en), foffset);
1289-
DUMP_WRITE(men->name, en.n_namesz, foffset);
1290-
if (!alignfile(file, foffset))
1291-
return 0;
1292-
DUMP_WRITE(men->data, men->datasz, foffset);
1293-
if (!alignfile(file, foffset))
1294-
return 0;
1295-
1296-
return 1;
1283+
return dump_emit(cprm, &en, sizeof(en)) &&
1284+
dump_emit(cprm, men->name, en.n_namesz) && alignfile(cprm) &&
1285+
dump_emit(cprm, men->data, men->datasz) && alignfile(cprm);
12971286
}
1298-
#undef DUMP_WRITE
12991287

13001288
static inline void fill_elf_fdpic_header(struct elfhdr *elf, int segs)
13011289
{
@@ -1500,66 +1488,40 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
15001488
/*
15011489
* dump the segments for an MMU process
15021490
*/
1503-
#ifdef CONFIG_MMU
1504-
static int elf_fdpic_dump_segments(struct file *file, size_t *size,
1505-
unsigned long *limit, unsigned long mm_flags)
1491+
static bool elf_fdpic_dump_segments(struct coredump_params *cprm)
15061492
{
15071493
struct vm_area_struct *vma;
1508-
int err = 0;
15091494

15101495
for (vma = current->mm->mmap; vma; vma = vma->vm_next) {
15111496
unsigned long addr;
15121497

1513-
if (!maydump(vma, mm_flags))
1498+
if (!maydump(vma, cprm->mm_flags))
15141499
continue;
15151500

1501+
#ifdef CONFIG_MMU
15161502
for (addr = vma->vm_start; addr < vma->vm_end;
15171503
addr += PAGE_SIZE) {
1504+
bool res;
15181505
struct page *page = get_dump_page(addr);
15191506
if (page) {
15201507
void *kaddr = kmap(page);
1521-
*size += PAGE_SIZE;
1522-
if (*size > *limit)
1523-
err = -EFBIG;
1524-
else if (!dump_write(file, kaddr, PAGE_SIZE))
1525-
err = -EIO;
1508+
res = dump_emit(cprm, kaddr, PAGE_SIZE);
15261509
kunmap(page);
15271510
page_cache_release(page);
1528-
} else if (!dump_seek(file, PAGE_SIZE))
1529-
err = -EFBIG;
1530-
if (err)
1531-
goto out;
1511+
} else {
1512+
res = dump_seek(file, PAGE_SIZE);
1513+
}
1514+
if (!res)
1515+
return false;
15321516
}
1533-
}
1534-
out:
1535-
return err;
1536-
}
1537-
#endif
1538-
1539-
/*
1540-
* dump the segments for a NOMMU process
1541-
*/
1542-
#ifndef CONFIG_MMU
1543-
static int elf_fdpic_dump_segments(struct file *file, size_t *size,
1544-
unsigned long *limit, unsigned long mm_flags)
1545-
{
1546-
struct vm_area_struct *vma;
1547-
1548-
for (vma = current->mm->mmap; vma; vma = vma->vm_next) {
1549-
if (!maydump(vma, mm_flags))
1550-
continue;
1551-
1552-
if ((*size += PAGE_SIZE) > *limit)
1553-
return -EFBIG;
1554-
1555-
if (!dump_write(file, (void *) vma->vm_start,
1517+
#else
1518+
if (!dump_emit(cprm, (void *) vma->vm_start,
15561519
vma->vm_end - vma->vm_start))
1557-
return -EIO;
1520+
return false;
1521+
#endif
15581522
}
1559-
1560-
return 0;
1523+
return true;
15611524
}
1562-
#endif
15631525

15641526
static size_t elf_core_vma_data_size(unsigned long mm_flags)
15651527
{
@@ -1755,13 +1717,10 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
17551717

17561718
offset = dataoff;
17571719

1758-
size += sizeof(*elf);
1759-
if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
1720+
if (!dump_emit(cprm, elf, sizeof(*elf)))
17601721
goto end_coredump;
17611722

1762-
size += sizeof(*phdr4note);
1763-
if (size > cprm->limit
1764-
|| !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
1723+
if (!dump_emit(cprm, phdr4note, sizeof(*phdr4note)))
17651724
goto end_coredump;
17661725

17671726
/* write program headers for segments dump */
@@ -1785,20 +1744,18 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
17851744
phdr.p_flags |= PF_X;
17861745
phdr.p_align = ELF_EXEC_PAGESIZE;
17871746

1788-
size += sizeof(phdr);
1789-
if (size > cprm->limit
1790-
|| !dump_write(cprm->file, &phdr, sizeof(phdr)))
1747+
if (!dump_emit(cprm, &phdr, sizeof(phdr)))
17911748
goto end_coredump;
17921749
}
17931750

1794-
cprm->written = size;
17951751
if (!elf_core_write_extra_phdrs(cprm, offset))
17961752
goto end_coredump;
17971753

17981754
size = cprm->written;
1755+
cprm->written = foffset;
17991756
/* write out the notes section */
18001757
for (i = 0; i < numnote; i++)
1801-
if (!writenote(notes + i, cprm->file, &foffset))
1758+
if (!writenote(notes + i, cprm))
18021759
goto end_coredump;
18031760

18041761
/* write out the thread status notes section */
@@ -1807,27 +1764,22 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
18071764
list_entry(t, struct elf_thread_status, list);
18081765

18091766
for (i = 0; i < tmp->num_notes; i++)
1810-
if (!writenote(&tmp->notes[i], cprm->file, &foffset))
1767+
if (!writenote(&tmp->notes[i], cprm))
18111768
goto end_coredump;
18121769
}
18131770

1814-
if (!dump_seek(cprm->file, dataoff - foffset))
1771+
if (!dump_seek(cprm->file, dataoff - cprm->written))
18151772
goto end_coredump;
18161773

1817-
if (elf_fdpic_dump_segments(cprm->file, &size, &cprm->limit,
1818-
cprm->mm_flags) < 0)
1774+
cprm->written = size;
1775+
if (!elf_fdpic_dump_segments(cprm))
18191776
goto end_coredump;
18201777

1821-
cprm->written = size;
18221778
if (!elf_core_write_extra_data(cprm))
18231779
goto end_coredump;
1824-
size = cprm->written;
18251780

18261781
if (e_phnum == PN_XNUM) {
1827-
size += sizeof(*shdr4extnum);
1828-
if (size > cprm->limit
1829-
|| !dump_write(cprm->file, shdr4extnum,
1830-
sizeof(*shdr4extnum)))
1782+
if (!dump_emit(cprm, shdr4extnum, sizeof(*shdr4extnum)))
18311783
goto end_coredump;
18321784
}
18331785

0 commit comments

Comments
 (0)