From patchwork Mon Apr 11 18:15:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 8804961 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4980BC0553 for ; Mon, 11 Apr 2016 18:16:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6101920166 for ; Mon, 11 Apr 2016 18:16:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5CA4E2013A for ; Mon, 11 Apr 2016 18:16:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754117AbcDKSQf (ORCPT ); Mon, 11 Apr 2016 14:16:35 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:36318 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754405AbcDKSQH (ORCPT ); Mon, 11 Apr 2016 14:16:07 -0400 Received: by mail-pa0-f45.google.com with SMTP id bx7so109690352pad.3 for ; Mon, 11 Apr 2016 11:16:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=NKooYk9x3exkazUHf4zAoadEqKL6Xy5+WIjgx7ih6oU=; b=r2gf/XUckUMriGGm8DyoijRtsuqRZnavoy+vu7bMuh0jx7YzKqR1frg29XyZZfvnFL rjDWDlBT995FYNH2PrfozeoehkKMrNf1EVpxWnq5Jk7z5dDJuZs4IIfzQ0gcsbQhp+J4 n5eu6gazI//Z7e0IeRvAwoHoNE+Bt4RwnNqkVUwkJRyAagOpvVKhCQW15DwtVOickAFd DMhH+MKUzWAmP3h0TzKzIxPqnLQMKp0D5mhOtHrEM/11n2l9smVm8+AT4Sz8rTGmAzKr BNXfeDj33Hu93k8gHfEqYEwcSBhobT2S0jWKZW19K6V/vAG2LVaSyfZ4rU0gNuerDyGp 7bXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=NKooYk9x3exkazUHf4zAoadEqKL6Xy5+WIjgx7ih6oU=; b=UBKZIrYqKnouM52OgudJngA44KqfPOctOdNOKCtpo1GSnl2zTlh9gTWz7RXINbd6y2 gwfIQATDVhiqVTmSu4ONy0UIrnaPo5JyD8xjsyAdLQdDzBpOpRHXZ65YTrvZzA9Qpg1i hlFiwwX3CQ+NCWmW0cE/xS7+edYm034q/GKZvQwukQnf2TVxRenMq7AT2a5HBybptZZr 5yVfBagvVlMw9cFdhXZnsKijpzkJHrKKdEk71kU2qf2bCAhvnNFNAwIBfPHAC0byN7Qo Z+WHlWmz5b2CVURHM4ewQ4qEZPZ6gHvu3zw/yQfD+RU0gUTbRKKlmexeQqqWyWGwJhqx bQtQ== X-Gm-Message-State: AOPr4FVKIsTCxB3cQ6zGbRbcEcISbJC3JSqwZet1ALmMjkxOWgBAKB1EfFe/xTUwmOhHq1gq X-Received: by 10.66.149.36 with SMTP id tx4mr19795406pab.64.1460398567106; Mon, 11 Apr 2016 11:16:07 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::b:2b53]) by smtp.gmail.com with ESMTPSA id u64sm37724709pfa.86.2016.04.11.11.16.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Apr 2016 11:16:06 -0700 (PDT) From: Omar Sandoval X-Google-Original-From: Omar Sandoval To: Al Viro Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Omar Sandoval Subject: [PATCH v2 2/2] coredump: only charge written data against RLIMIT_CORE Date: Mon, 11 Apr 2016 11:15:56 -0700 Message-Id: <36e748cf9ab3181f6e325850cab7aabb758dd026.1460397009.git.osandov@fb.com> X-Mailer: git-send-email 2.8.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval Commit 9b56d54380ad ("dump_skip(): dump_seek() replacement taking coredump_params") introduced a regression with regard to RLIMIT_CORE. Previously, when a core dump was sparse, only the data that was actually written out would count against the limit. Now, the sparse ranges are also included, which leads to truncated core dumps when the actual disk usage is still well below the limit. Restore the old behavior by only counting what gets emitted and ignoring what gets skipped. --- fs/coredump.c | 5 ++--- include/linux/binfmts.h | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index 9db0c514438e..492c2db25dc9 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -782,7 +782,7 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr) struct file *file = cprm->file; loff_t pos = file->f_pos; ssize_t n; - if (pos + nr > cprm->limit) + if (cprm->written + nr > cprm->limit) return 0; while (nr) { if (dump_interrupted()) @@ -791,6 +791,7 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr) if (n <= 0) return 0; file->f_pos = pos; + cprm->written += n; nr -= n; } return 1; @@ -802,8 +803,6 @@ int dump_skip(struct coredump_params *cprm, size_t nr) static char zeroes[PAGE_SIZE]; struct file *file = cprm->file; if (file->f_op->llseek && file->f_op->llseek != no_llseek) { - if (file->f_pos + nr > cprm->limit) - return 0; if (dump_interrupted() || file->f_op->llseek(file, nr, SEEK_CUR) < 0) return 0; diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h index 39c6d6e1234e..576e4639ca60 100644 --- a/include/linux/binfmts.h +++ b/include/linux/binfmts.h @@ -64,6 +64,7 @@ struct coredump_params { struct file *file; unsigned long limit; unsigned long mm_flags; + loff_t written; }; /*