Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937469AbdCJNhG (ORCPT ); Fri, 10 Mar 2017 08:37:06 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:43647 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934339AbdCJLw2 (ORCPT ); Fri, 10 Mar 2017 06:52:28 -0500 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Christoph Hellwig" , "Linus Torvalds" , "Al Viro" , "Michal Hocko" , "Tetsuo Handa" Date: Fri, 10 Mar 2017 11:46:23 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 274/370] mm, fs: check for fatal signals in do_generic_file_read() In-Reply-To: X-SA-Exim-Connect-IP: 82.70.136.246 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1350 Lines: 41 3.16.42-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Michal Hocko commit 5abf186a30a89d5b9c18a6bf93a2c192c9fd52f6 upstream. do_generic_file_read() can be told to perform a large request from userspace. If the system is under OOM and the reading task is the OOM victim then it has an access to memory reserves and finishing the full request can lead to the full memory depletion which is dangerous. Make sure we rather go with a short read and allow the killed task to terminate. Link: http://lkml.kernel.org/r/20170201092706.9966-3-mhocko@kernel.org Signed-off-by: Michal Hocko Reviewed-by: Christoph Hellwig Cc: Tetsuo Handa Cc: Al Viro Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Ben Hutchings --- mm/filemap.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1482,6 +1482,11 @@ static ssize_t do_generic_file_read(stru cond_resched(); find_page: + if (fatal_signal_pending(current)) { + error = -EINTR; + goto out; + } + page = find_get_page(mapping, index); if (!page) { page_cache_sync_readahead(mapping,