Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1088725ybz; Wed, 29 Apr 2020 14:52:10 -0700 (PDT) X-Google-Smtp-Source: APiQypIT4dSosHwY1cPytUhj097jgKLYB7Ea3hDL7qSiQ60O/P9UPTG1fGxnIk1/onVfcsgE44Qt X-Received: by 2002:aa7:c306:: with SMTP id l6mr59886edq.356.1588197130133; Wed, 29 Apr 2020 14:52:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588197130; cv=none; d=google.com; s=arc-20160816; b=nYHMv7Nb7haVlY11fT1w5vgrRmc4Rx9ETXVbYW9Q6YvODEm1K2OWTbluZyf0+47amk lZ/8OIfKE2ltSM+eDXSEco/nxtYp2c7yOedSbNKVo/k0Np9pjyOy8pcUg2c5BBJthPw9 A2ZlndqhSsgQJthunrABnco7me7MhVcNnLafVr7bZhsPV4gbHuhnwQSJQzom44D0aoLN go41+KiSewMvnwdbn9PAZ8sHueXPzTffrpLZbAtAj3UYKePWezk9a4a/2Se7e67IInv8 c3Zxis2C7EyStAB48XjAQFj3Dyu+FgTT9zz68vKab0RAiQUgZZ08NuIlFv7g1cquX1T8 hmBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=JqiR2vOdqFfBqjhyMGJp8d/qL3dB8+X/PfK7MWBosOQ=; b=h9/tM423tXx+s7glHBFF+hyGVRcmCHr0Ko36XehdWKEq4jJd1c9kc5KxcriRhbN6qD Lq0KD8Nkdip1VaOGjhUoeVHVC6G1finTiQ2f4eb1oGgvj2xS1MBilDSv+b0/TilUtMS1 +wjWrklT/P0F4TeI3FOlJHiNeDi+fzP0zzzJs7F0yeU3YmY7MNXivcMx86LaNkkK8Vhb /bfVw2sx68pTZeqlO8LEpgphDiwTe4oMpT/vesRKXgjhWSbdB15quB7AYBoswZVTFDNM 9y8XS8zfCeIcsktVVugCX3frEIZ+lrwyWZpkxAmFeq1Gxbqywo+gCBdRRoMfwAU95Qfx Us9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=aiXVr9LW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d15si4523641ejj.253.2020.04.29.14.51.47; Wed, 29 Apr 2020 14:52:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=aiXVr9LW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727827AbgD2VuU (ORCPT + 99 others); Wed, 29 Apr 2020 17:50:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727813AbgD2VuR (ORCPT ); Wed, 29 Apr 2020 17:50:17 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16FB2C03C1AE for ; Wed, 29 Apr 2020 14:50:17 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id d35so4471242qtc.20 for ; Wed, 29 Apr 2020 14:50:17 -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=JqiR2vOdqFfBqjhyMGJp8d/qL3dB8+X/PfK7MWBosOQ=; b=aiXVr9LW0+RfYp/BGKCZwf2eFb8u9bW41qbryYBrMOTMAxizbTvkyUsj2hMqoewXVA EbenkI3pjlj6j3Jz6v58GVbjLsRucPnyBIwyrf/cQxI7QYwEK5k1uOps+KFUBQSyYzSq 4ScWZwqWRdd/I9EOQCike+A/g8LgBL08ZkugaoTqx2zKcpO0yY7MZeP+Y4VZXfi2opO+ u0ixT5IVpYsz33tv0SuE/w161GkFjCv2PC0mWH6RqlvaBsCA3Nae7CGPq+IMF6tcDpg/ xDEfx6+SvCzPkM2Gw22E+XqkcpxanCcgz9Szd+JSjxTdcGi6OboSgHQ79epRcTxfLjBk yKJA== 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=JqiR2vOdqFfBqjhyMGJp8d/qL3dB8+X/PfK7MWBosOQ=; b=duRXNEZTlkSv4MtBnBF7mAJaLOeZ+cetsTOa2oibd/hcoB2xUb5yDKyRjpHnX3s9Go Xm6nuUqAk/6lfgp4dljGWVGzJOs6ZmRycdzyKSB5B/CSbjQlv2HAeSP9CkHUFOeORurz cCtBbxdOnHmemsyZ39+ABIYkBVHW3bqRYnBDi3S6mWAc+YA62RJspIfu2flDQEsb7hmC hCb4/wTlmVVRtHnwR54CUP6nWvF9HRt9iEpxwM4Az+QC9NSoqci0ojEWYk/81e4nz87c pncE5UU8hXu2nDavUqdOEqzEg4lZfmgQ5sPA6o1gNdu+COAKF0Fep5gZyJuj3vV3/1s7 l9wg== X-Gm-Message-State: AGi0PuZyhWbpl9BokZ2N1Ptfyw4ZjXL1IPdxgKs15x30j31clzor70sX MEU50Qm6WQlk/J9GWCQ10g+0rp2OUQ== X-Received: by 2002:ad4:49d3:: with SMTP id j19mr34024184qvy.78.1588197016281; Wed, 29 Apr 2020 14:50:16 -0700 (PDT) Date: Wed, 29 Apr 2020 23:49:51 +0200 In-Reply-To: <20200429214954.44866-1-jannh@google.com> Message-Id: <20200429214954.44866-3-jannh@google.com> Mime-Version: 1.0 References: <20200429214954.44866-1-jannh@google.com> X-Mailer: git-send-email 2.26.2.526.g744177e7f7-goog Subject: [PATCH v2 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 , Russell King , linux-arm-kernel@lists.infradead.org, Mark Salter , Aurelien Jacquiot , linux-c6x-dev@linux-c6x.org, Yoshinori Sato , Rich Felker , linux-sh@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 408418e6aa131..d6fcc36a7db1f 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -823,17 +823,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); -- 2.26.2.526.g744177e7f7-goog