From patchwork Wed Oct 22 23:21:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vkamensky X-Patchwork-Id: 39340 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 814E9202DB for ; Wed, 22 Oct 2014 23:22:01 +0000 (UTC) Received: by mail-la0-f69.google.com with SMTP id q1sf2553859lam.0 for ; Wed, 22 Oct 2014 16:22:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mime-version:in-reply-to:references :date:message-id:subject:from:to:cc:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=8pky14RwDp8AYOIB0eJjMq52B168beGQp/77gOpC2LY=; b=I8UdCzNf19FuqQXIj5kGiLY0++EqXHJ5812Iil0iQl5IG8PMc/94UCpN71hozratB3 FlPtROHCONfP15O5i9nI8Ph9S2xbDmxE8U2Fnk0VXENSqYFbZ+7P+LUkn2fsaCpI1bd9 3zewZtJvnc8o8z4zUbC8UCk1pFjtNWKCjNO0RVsqeEUCzOaLJ6Odf0ffU609v61bnGxU sK2hAcBrTM7Kf2932VnHwYieXlNbi4v1g03lTOOZ7kbNpQgcEwrlzy/1c/8j1kbWm8Sz v9VYc7AnvHYr+NbanrkjWXuAzZVXY5q/TA6T8KULr+vIVtJs4KgXLjtZM9M6EcknrcsO zv1g== X-Gm-Message-State: ALoCoQme5g4CnLRHrIZ7ggc0eQyKUrTtiNG7jPfz1H55WpT4GjuhKSK0VB2NclEzwSTVIXm0NLiT X-Received: by 10.194.242.36 with SMTP id wn4mr229771wjc.4.1414020120206; Wed, 22 Oct 2014 16:22:00 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.38 with SMTP id n6ls235056laj.86.gmail; Wed, 22 Oct 2014 16:22:00 -0700 (PDT) X-Received: by 10.152.121.68 with SMTP id li4mr999049lab.77.1414020120015; Wed, 22 Oct 2014 16:22:00 -0700 (PDT) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id ei3si148453lad.84.2014.10.22.16.21.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 22 Oct 2014 16:21:59 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by mail-lb0-f174.google.com with SMTP id p9so3699119lbv.19 for ; Wed, 22 Oct 2014 16:21:59 -0700 (PDT) X-Received: by 10.152.5.38 with SMTP id p6mr1166009lap.44.1414020119875; Wed, 22 Oct 2014 16:21:59 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp168423lbz; Wed, 22 Oct 2014 16:21:59 -0700 (PDT) X-Received: by 10.69.21.33 with SMTP id hh1mr1254860pbd.42.1414020118304; Wed, 22 Oct 2014 16:21:58 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ey5si82297pdb.122.2014.10.22.16.21.57 for ; Wed, 22 Oct 2014 16:21:58 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933609AbaJVXVy (ORCPT + 27 others); Wed, 22 Oct 2014 19:21:54 -0400 Received: from mail-qg0-f44.google.com ([209.85.192.44]:36302 "EHLO mail-qg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933590AbaJVXVv (ORCPT ); Wed, 22 Oct 2014 19:21:51 -0400 Received: by mail-qg0-f44.google.com with SMTP id j5so3335791qga.31 for ; Wed, 22 Oct 2014 16:21:49 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.140.88.70 with SMTP id s64mr1703897qgd.65.1414020109642; Wed, 22 Oct 2014 16:21:49 -0700 (PDT) Received: by 10.229.93.203 with HTTP; Wed, 22 Oct 2014 16:21:49 -0700 (PDT) In-Reply-To: <20141022165530.GA30358@redhat.com> References: <1413932228-27642-1-git-send-email-victor.kamensky@linaro.org> <1413932228-27642-2-git-send-email-victor.kamensky@linaro.org> <20141022165530.GA30358@redhat.com> Date: Wed, 22 Oct 2014 16:21:49 -0700 Message-ID: Subject: Re: [RFC PATCH] coredump: fix incomplete core file created when dump_skip was used last From: Victor Kamensky To: Oleg Nesterov Cc: Alexander Viro , linux-fsdevel@vger.kernel.org, Andrew Morton , Kees Cook , open list Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: victor.kamensky@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On 22 October 2014 09:55, Oleg Nesterov 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/ 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)