Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3812195ybi; Mon, 29 Jul 2019 13:06:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwYl1eyW4NbdrhyTa2m6qwMpRy/fmZhp1chkC5N33Kp2ySc4R5TG6W7Qg7FANhSIWeqBXKA X-Received: by 2002:a63:dd17:: with SMTP id t23mr78336937pgg.295.1564430794954; Mon, 29 Jul 2019 13:06:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430794; cv=none; d=google.com; s=arc-20160816; b=l7vFAHPZUlahwnFazDrP12HvwPRTYcnjK24eINR5Zo5ZRKOFz6Y4og277wTQOq/NQP RvSpHF4c0LoBRAyQLkzdqWjqKYNFr9l28pPhlYIGFERhtnmAbLGGvbE/9lYNxoRiXOLo pxAGYpfKXnKhhgkwtXcNLYVYV0oZVhd16jkRNS7IKwouFGk3PFk6qiswkmYL0yCh1GoT hBt4mYonAejoTSjvQMWB7zRYQY6qYv68OdF4wBzKJW/bMfWuspNAHsz+d2CDwPuSshO3 oHZqrASdQY+0dIPDg4ty8NGXKyx4VbLlG0/dIrofCqgi84J5N5mSsiS4PlNvzmmu4eN7 CV4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fUdO5ZHDwjgpyF53bMPH8tBv1xWKuj4LfdXruL8GJzA=; b=VR12LoZmXeVUha9gvb3DWh5SA1BSZg7kN6CWEr0kc24RCsE392TgG/xRkr0ao0MITw vRPTorulPfh0pbTgY7SGUoVNKWO+8OGUrFxkQXP9FtQGIWtZMWGzhWIhhbc0mg8sv56i eNeCBL6dqHadDtBPe71YhQlOVX5T9eU94ty6R9iJ9uRXVfHZizHb/5TEIpAXOVnVa3Iy 9t1YmOeY/7nt1WCbuLT75BTFUJTkBPviCTfLPk6vKNVgkHcbchzLo4ebZZDL/dMLHQ2f eM253+FfsXiGiYLIiFN4Wrtf7fM/pwm+SYaRQqBPnVvNRuKbLwj+nXwejUrZh4cbSaJi N+kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=g4KsCGiR; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y6si27768948pfl.288.2019.07.29.13.06.20; Mon, 29 Jul 2019 13:06:34 -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=g4KsCGiR; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390371AbfG2UFM (ORCPT + 99 others); Mon, 29 Jul 2019 16:05:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:60534 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389203AbfG2Tn4 (ORCPT ); Mon, 29 Jul 2019 15:43:56 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 591A520C01; Mon, 29 Jul 2019 19:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429435; bh=QlRxDaIWmUxVA6DHWBBI528oV9qu+xRdOM6oOA2tRzw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g4KsCGiRJHyBUSKzY5jGo6+j0TM5ybmuBe/3qvhWHaONbRag3tSylvavJrLonk/Yo 3Gt+5R/sS89DhaPi202AmS8hg4l8cttmIaEnSywToCVLwuDFOageQgbdNPmUbkLG2K iHA2uvqB048i1T9Aj30H4Le1YACZQjMwXl5SfTkc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Konstantin Khlebnikov , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Oleg Nesterov , Michal Hocko , Alexey Dobriyan , Matthew Wilcox , Cyrill Gorcunov , Kirill Tkhai , Al Viro , Roman Gushchin , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 096/113] mm: use down_read_killable for locking mmap_sem in access_remote_vm Date: Mon, 29 Jul 2019 21:23:03 +0200 Message-Id: <20190729190718.502020243@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190655.455345569@linuxfoundation.org> References: <20190729190655.455345569@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 1e426fe28261b03f297992e89da3320b42816f4e ] This function is used by ptrace and proc files like /proc/pid/cmdline and /proc/pid/environ. Access_remote_vm never returns error codes, all errors are ignored and only size of successfully read data is returned. So, if current task was killed we'll simply return 0 (bytes read). Mmap_sem could be locked for a long time or forever if something goes wrong. Using a killable lock permits cleanup of stuck tasks and simplifies investigation. Link: http://lkml.kernel.org/r/156007494202.3335.16782303099589302087.stgit@buzz Signed-off-by: Konstantin Khlebnikov Reviewed-by: Michal Koutný Acked-by: Oleg Nesterov Acked-by: Michal Hocko Cc: Alexey Dobriyan Cc: Matthew Wilcox Cc: Cyrill Gorcunov Cc: Kirill Tkhai Cc: Al Viro Cc: Roman Gushchin Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/memory.c | 4 +++- mm/nommu.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index e0010cb870e0..fb5655b518c9 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4491,7 +4491,9 @@ int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm, void *old_buf = buf; int write = gup_flags & FOLL_WRITE; - down_read(&mm->mmap_sem); + if (down_read_killable(&mm->mmap_sem)) + return 0; + /* ignore errors, just check how much was successfully transferred */ while (len) { int bytes, ret, offset; diff --git a/mm/nommu.c b/mm/nommu.c index e4aac33216ae..1d63ecfc98c5 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -1779,7 +1779,8 @@ int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm, struct vm_area_struct *vma; int write = gup_flags & FOLL_WRITE; - down_read(&mm->mmap_sem); + if (down_read_killable(&mm->mmap_sem)) + return 0; /* the access must start within one of the target process's mappings */ vma = find_vma(mm, addr); -- 2.20.1