Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1945887ima; Thu, 25 Oct 2018 07:23:52 -0700 (PDT) X-Google-Smtp-Source: AJdET5f/L79QfgPS1j3VFAvpqnkq0oIRbgMs0Tr//uCD0o/pY7mTLhb/m4skqa+BldPQQ7HE8jQg X-Received: by 2002:a62:d046:: with SMTP id p67-v6mr1825447pfg.147.1540477432334; Thu, 25 Oct 2018 07:23:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540477432; cv=none; d=google.com; s=arc-20160816; b=OilmQr0wMD/2aZYB795EcK/uRZ4qkVLOB6WUpoghDRygCM4WbRyqpzBCPTtsjKn9uN jIawr+f5DY/UWYz7j6Og7rtg1dZdioCTumraz8Y9wcbP+iq6go5Yt8C37fxxi3FTNsaI Fd8qbJjX1N7HwCPS2gj1VCgR+hZsfx9L23UyeAtlM7C8DR5m7+PrOsHdWaOhqikUOBAI 8oeKxsiulswaMmj4091zx16bJo7g6tqIf8wIoaDq9Qh9brXgJ3gzZSh8sBfXLA87ycr1 pYhFy0vuLFPCHPmgPJQVodLGGjxyb6NUM1HqdRhNDOVTFv7AIYLPtdbuGrvSL468YmGD wy4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=NX1/GJXkYaAvTS59VImEeGH2WVqJRaM3wsIrJnS5uTw=; b=U6qxV6zPDcxH1VIhqsEV1WdBnxd6sOKFeWulQgZfEnVxwtKLbGAfnD7HgIvUAQZ3Zh NjzQsHZFNos5Jf8wI4Q33nxcIz+tiz/dkyc/rMIk36aphcpRL0RxRkJjTFggsL6+PyTw b1qSezXiswa3gSBXWeDkLTtb607sch0NdLwnH1c/h2NsgzTH9/RTRFH9Gzq+hHqvs2mZ BcFlzqqemzJ/e+2nyIwSlS2jU1WdrrMRZ8xbspg0bqmK8x9G7e7XciuTVlJsN6V1YqNG yl1Rrclw9DtEWdKR4YnLpQFHmbPv/dZoQJdCH2Ou79KMjx9mnvY1W9I91QkYGLOpqt/S d7aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="pRxcD/m5"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w6-v6si8543157pgw.316.2018.10.25.07.23.09; Thu, 25 Oct 2018 07:23:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="pRxcD/m5"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730448AbeJYWyM (ORCPT + 99 others); Thu, 25 Oct 2018 18:54:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:37032 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731391AbeJYWyL (ORCPT ); Thu, 25 Oct 2018 18:54:11 -0400 Received: from sasha-vm.mshome.net (unknown [167.98.65.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DB6D42085B; Thu, 25 Oct 2018 14:21:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1540477272; bh=LDnqU9y6u5AkUf9DaBOz4xz8IE9//HU2VBkgwDdvbw0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pRxcD/m5cYPeX9iEU1tXuzuAEaAVBbXO7uB7FxDJaAGhBtFp5tVt1WPMhuKedeou8 w787Q5vJMNJdyiRezQTmPBJCb2jmeWDWMV4CXHyeKt95WpHfJRJAX/lWJolxpfZ2ih AIR5s55rvc7bi5fYYtK4fPIVJkQ30tO5dL+PQ+Kg= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jan Kara , Al Viro , Sasha Levin Subject: [PATCH AUTOSEL 3.18 89/98] vfs: Make sendfile(2) killable even better Date: Thu, 25 Oct 2018 10:18:44 -0400 Message-Id: <20181025141853.214051-89-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025141853.214051-1-sashal@kernel.org> References: <20181025141853.214051-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Kara [ Upstream commit c725bfce7968009756ed2836a8cd7ba4dc163011 ] Commit 296291cdd162 (mm: make sendfile(2) killable) fixed an issue where sendfile(2) was doing a lot of tiny writes into a filesystem and thus was unkillable for a long time. However sendfile(2) can be (mis)used to issue lots of writes into arbitrary file descriptor such as evenfd or similar special file descriptors which never hit the standard filesystem write path and thus are still unkillable. E.g. the following example from Dmitry burns CPU for ~16s on my test system without possibility to be killed: int r1 = eventfd(0, 0); int r2 = memfd_create("", 0); unsigned long n = 1<<30; fallocate(r2, 0, 0, n); sendfile(r1, r2, 0, n); There are actually quite a few tests for pending signals in sendfile code however we data to write is always available none of them seems to trigger. So fix the problem by adding a test for pending signal into splice_from_pipe_next() also before the loop waiting for pipe buffers to be available. This should fix all the lockup issues with sendfile of the do-ton-of-tiny-writes nature. CC: stable@vger.kernel.org Reported-by: Dmitry Vyukov Signed-off-by: Jan Kara Signed-off-by: Al Viro Signed-off-by: Sasha Levin --- fs/splice.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/splice.c b/fs/splice.c index cf0cb768a1a7..852194d3ce4a 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -809,6 +809,13 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des */ static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd) { + /* + * Check for signal early to make process killable when there are + * always buffers available + */ + if (signal_pending(current)) + return -ERESTARTSYS; + while (!pipe->nrbufs) { if (!pipe->writers) return 0; -- 2.17.1