diff mbox

[RFC] coredump: fix incomplete core file created when dump_skip was used last

Message ID CAA3XUr0N_fcOqmSnT2Y=Dz+5uH1YN+qrJ=2-fJrQaHcnu1cQXw@mail.gmail.com
State New
Headers show

Commit Message

vkamensky Oct. 22, 2014, 11:21 p.m. UTC
On 22 October 2014 09:55, Oleg Nesterov <oleg@redhat.com> wrote:
> On 10/21, Victor Kamensky wrote:
>>
>> +static int dump_write_last_byte(struct coredump_params *cprm)
>> +{
>> +     char lastbyte = 0;
>> +     struct file *file = cprm->file;
>> +
>> +     if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
>> +             if (dump_interrupted() ||
>> +                 file->f_op->llseek(file, -1, SEEK_CUR) < 0)
>> +                     return 0;
>> +             if (!dump_emit(cprm, &lastbyte, 1))
>> +                     return 0;
>> +     }
>> +     return 1;
>> +}
>
> Perhaps do_truncate(cprm.file->f_path.dentry, ->f_pos) makes more sense?
>
> and unless I missed something cprm->last_op_status can be avoided, we can
> simply check f_pos != i_size_read() at the end?

Oleg, nice advise! Thanks.

So the whole fix becomes something like this:


May I use your name with Suggested-by tag?

Thanks,
Victor

> Oleg.
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Comments

Oleg Nesterov Oct. 23, 2014, 4:39 p.m. UTC | #1
On 10/22, Victor Kamensky wrote:
>
> --- a/fs/coredump.c
> +++ b/fs/coredump.c
> @@ -664,6 +664,14 @@ void do_coredump(const siginfo_t *siginfo)
>         if (!dump_interrupted()) {
>                 file_start_write(cprm.file);
>                 core_dumped = binfmt->core_dump(&cprm);
> +               /*
> +                * If last operation was dump_skip with llseek, we need to
> +                * truncate file up to f_pos to match expected size.
> +                */
> +               if (!ispipe &&
> +                   (cprm.file->f_pos > i_size_read(file_inode(cprm.file))))
> +                       do_truncate(cprm.file->f_path.dentry,
> +                                   cprm.file->f_pos, 0, cprm.file);
>                 file_end_write(cprm.file);
>         }
>         if (ispipe && core_pipe_limit)
>
> May I use your name with Suggested-by tag?

Sure, thanks ;)

I'd suggest to add a simple helper, but I won't insist. And perhaps the
caller can also check "core_dumped" along with !ispipe, but this is
purely cosmetic.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
diff mbox

Patch

diff --git a/fs/coredump.c b/fs/coredump.c
index a93f7e6..8c17f1d 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -664,6 +664,14 @@  void do_coredump(const siginfo_t *siginfo)
        if (!dump_interrupted()) {
                file_start_write(cprm.file);
                core_dumped = binfmt->core_dump(&cprm);
+               /*
+                * If last operation was dump_skip with llseek, we need to
+                * truncate file up to f_pos to match expected size.
+                */
+               if (!ispipe &&
+                   (cprm.file->f_pos > i_size_read(file_inode(cprm.file))))
+                       do_truncate(cprm.file->f_path.dentry,
+                                   cprm.file->f_pos, 0, cprm.file);
                file_end_write(cprm.file);
        }
        if (ispipe && core_pipe_limit)