From patchwork Tue Aug 18 06:12:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jann Horn X-Patchwork-Id: 11720039 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1D645138C for ; Tue, 18 Aug 2020 06:12:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D513E2075E for ; Tue, 18 Aug 2020 06:12:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mJkEz75f" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D513E2075E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E59798D0003; Tue, 18 Aug 2020 02:12:55 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E30778D0001; Tue, 18 Aug 2020 02:12:55 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D46498D0003; Tue, 18 Aug 2020 02:12:55 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0123.hostedemail.com [216.40.44.123]) by kanga.kvack.org (Postfix) with ESMTP id BEE5A8D0001 for ; Tue, 18 Aug 2020 02:12:55 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 845988245571 for ; Tue, 18 Aug 2020 06:12:55 +0000 (UTC) X-FDA: 77162671110.07.blow79_1d0e52d2701d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 4EF821803F9A7 for ; Tue, 18 Aug 2020 06:12:55 +0000 (UTC) X-Spam-Summary: 1,0,0,35721025cc9e2728,d41d8cd98f00b204,3zxe7xwukcdybsffzyggydw.ugedafmp-eecnsuc.gjy@flex--jannh.bounces.google.com,,RULES_HIT:41:69:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3152:3352:3865:3867:3868:3872:3874:4321:5007:6261:6653:7903:9969:10004:10400:11658:11914:12043:12296:12297:12555:12895:13069:13311:13357:14096:14097:14181:14394:14659:14721:21080:21444:21627:21990:30054,0,RBL:209.85.218.74:@flex--jannh.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04ygc8rjfbgjsqiuwgeqma17j9quhopmh9stjrzsgx6no5der1j4eaxgo3aoeom.wgjyyf9s81oicmxw3kn9basdjncwmu8fpwonkqsknjxejhfx8ox3xijqbbx891k.w-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: blow79_1d0e52d2701d X-Filterd-Recvd-Size: 4003 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Tue, 18 Aug 2020 06:12:54 +0000 (UTC) Received: by mail-ej1-f74.google.com with SMTP id e22so6386502ejx.18 for ; Mon, 17 Aug 2020 23:12:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=GSVoeZY4VtJncRCsBDOJV6iGFCXNH029JG2AgbxMzIw=; b=mJkEz75fkVHT8du8gdQBjaw6pE2ldFlA4jAPMSL2QbrZWXnfCVbN0C+c08ERHBXu6g C2fnjAZnH5RpJUIy5bISJjpd5WjqtYLOVKzqSpZEUfB9oMJdSN28QzPbF9Nlo8946/Fj oMh5GZo83yuAfd3Li5R2BToVuUri/UWMuEmqmPuoHlnAFltI6gltdTVRb4pk9SMR8r3s VxGDiC/Qdhttg9SXgox69qIlULfK8Md8HEGzpeXVfTvQr/JMHA9T5dT2KQ+7AwF2YMXd KtyAFJ/QUHW796NNlto8dQliaZ6uR4Jj68ysPjJBEx1Nd/tzEky2FMVHrzXQJZ+L4CxF tGAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=GSVoeZY4VtJncRCsBDOJV6iGFCXNH029JG2AgbxMzIw=; b=tUsHxWYAW2Buk97diN0R6oQsJfM9tTnrduC4RJGTkJrpu4qzppn/xMuZ5i7QP3VQsK o9iB3g2PrbTom6q8wnAawyeAXo+zlQmUR9zzZxWD+AhI3eTg4UHVx0HzwiE++8M2orG3 3mrphvdO9+MS5F9XOUkYwCzbJksQrNnpFQOXa12S5KWfjcUQpLFY5yYhUhXgdkBf4JnS TZx19bOH/RlwANcAI4LiAbFtMk/P2AhPgDN9+4cGDR125cK2gWHeymwuXkcDPbhmBu0s Tq8xozZetFkjyN9LUpADH4YLT1gz/CEHdPf4XN2kJf9eURR2WSP5JSL5LQtx7sPyJRVj 4Dew== X-Gm-Message-State: AOAM533RDUgOGTRTPJRETBirh9vyV1VyMaLmZx9yLmvEqwx/qvTZ1tv9 AQSqRpPtQj/Oi8ZLC/dQaqLqSxMXRw== X-Google-Smtp-Source: ABdhPJw8kbNtK89Z+bGnNpE12khmVpUyK5YNskcMYl1yh5qw2UP1aNNDhMVoCYncY9CyFubOVCb/FD841g== X-Received: by 2002:a50:d2c7:: with SMTP id q7mr17620488edg.61.1597731173685; Mon, 17 Aug 2020 23:12:53 -0700 (PDT) Date: Tue, 18 Aug 2020 08:12:36 +0200 In-Reply-To: <20200818061239.29091-1-jannh@google.com> Message-Id: <20200818061239.29091-3-jannh@google.com> Mime-Version: 1.0 References: <20200818061239.29091-1-jannh@google.com> X-Mailer: git-send-email 2.28.0.220.ged08abb693-goog Subject: [PATCH v3 2/5] coredump: Let dump_emit() bail out on short writes From: Jann Horn To: Andrew Morton Cc: Linus Torvalds , Christoph Hellwig , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Alexander Viro , "Eric W . Biederman" , Oleg Nesterov X-Rspamd-Queue-Id: 4EF821803F9A7 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: dump_emit() has a retry loop, but there seems to be no way for that retry logic to actually be used; and it was also buggy, writing the same data repeatedly after a short write. Let's just bail out on a short write. Suggested-by: Linus Torvalds Signed-off-by: Jann Horn --- fs/coredump.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index 76e7c10edfc0..5e24c06092c9 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -840,17 +840,17 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr) ssize_t n; if (cprm->written + nr > cprm->limit) return 0; - while (nr) { - if (dump_interrupted()) - return 0; - n = __kernel_write(file, addr, nr, &pos); - if (n <= 0) - return 0; - file->f_pos = pos; - cprm->written += n; - cprm->pos += n; - nr -= n; - } + + + if (dump_interrupted()) + return 0; + n = __kernel_write(file, addr, nr, &pos); + if (n != nr) + return 0; + file->f_pos = pos; + cprm->written += n; + cprm->pos += n; + return 1; } EXPORT_SYMBOL(dump_emit);