From patchwork Wed May 11 22:16:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9075281 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 A4D45BF29F for ; Wed, 11 May 2016 22:17:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BD6DB2017D for ; Wed, 11 May 2016 22:17:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DB8C82012B for ; Wed, 11 May 2016 22:17:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752500AbcEKWQy (ORCPT ); Wed, 11 May 2016 18:16:54 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:33694 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752558AbcEKWQw (ORCPT ); Wed, 11 May 2016 18:16:52 -0400 Received: by mail-pa0-f49.google.com with SMTP id xk12so22175924pac.0 for ; Wed, 11 May 2016 15:16:52 -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=tuF78hX5hQikfTNTddIAi+FzA0bGJSuLvFzmB3/nvfk=; b=A9T+f12hUvv+gxd0ruCQoj9LQ+NqWKw7FYx7CntFeLJWenPp/UYb2alETK/mr8yyxZ 0p0CTz14Eh244Ohipd4bDz/i0zhEAyM4qrRutOx1yWZgxg7G4JbZJSYq7xNysF0vJY7b ZCvMqAYM8pD81einnbz7TgHTcH0xfFQD9407faH/MkaAtLvg3ubA+bNjG2cX7GSSva64 GlrJKGStoMCOjU+c0ROLWo5SbP+u0corgNkgepAgEzOP3e8BG+Voz5guvvnkKS15ISbE GO0p1swxYh1RgWmijjopa/0wyfKAuPnZKNKmXrGdFTOMUQzE2HPzERUrUkgAL7t9qnqS 3Yug== 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=tuF78hX5hQikfTNTddIAi+FzA0bGJSuLvFzmB3/nvfk=; b=Bw//r2g+az0p5W4D9kC29hTpeT16B7WL+u6dDzZ/jiy9Fji4PrgSA29887GYp8CZfv umh7I97cOGmPHwnkEMzf3j08SYf1CGNxQUnE5hKoP15bMkC8fGEQkaCztSut/tkz3hhJ aoy3OQorzt5h2jmcbdICJI6fcvAaSnUeDW2epUt7O8nMnHDoC2pZtV4vHFN4vOuk6eSb QuEWuHNjlUgbTUwlNXbMrdo/9T6LVJAzmriRMu8SL6V+WoQDvkmrOL/Ig7b0JhxMwU3B +9w3sWEEPwfLvwnEF+boVhmj4kZNO84KeJCTGsNiUEtXt1uFhX/oWBnHm0jw416k3nT6 Q1yg== X-Gm-Message-State: AOPr4FWkpXatkII4yayx+5JmLjeh6VJ/i0BqXz1REO5e2rVOgTS7r/SaBCqW3+Os9fPE/tsv X-Received: by 10.66.189.65 with SMTP id gg1mr8598326pac.148.1463005011578; Wed, 11 May 2016 15:16:51 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::e:4bd]) by smtp.gmail.com with ESMTPSA id we8sm14579867pac.29.2016.05.11.15.16.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 May 2016 15:16:51 -0700 (PDT) From: Omar Sandoval X-Google-Original-From: Omar Sandoval To: Al Viro , Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Omar Sandoval Subject: [PATCH RESEND v3 2/2] coredump: only charge written data against RLIMIT_CORE Date: Wed, 11 May 2016 15:16:37 -0700 Message-Id: <36e748cf9ab3181f6e325850cab7aabb758dd026.1463004510.git.osandov@fb.com> X-Mailer: git-send-email 2.8.2 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=-8.2 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. Signed-off-by: Omar Sandoval --- 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; }; /*