Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4339206ybi; Tue, 30 Jul 2019 00:13:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqyeTxCs0ROf1BM+B4pymMOQk9fUGrG7eO0wSbWnYcgGHbpWoxIFecfp8dUUUY+jQp7bvi3Q X-Received: by 2002:a17:90a:28e4:: with SMTP id f91mr112065981pjd.99.1564470811350; Tue, 30 Jul 2019 00:13:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564470811; cv=none; d=google.com; s=arc-20160816; b=euRsM3HjbcnQ+bnSjXqULvncOFlOydE973R5NcdL8kK/8kLVnc7SxtIHJ5vKq6aXo9 R5nWexe8Jlx3izpe6HdpcLsczT/3vKafHNwSHUh1JM6sEzRiWY72yjv/plBP8zwoaruJ 9BIqTbqhchMKG2V8u45A6Z5JjE8yCbsXLLj97lq6Iy3EufqWuE0Kp6Ol71+84QyX5kE0 uJOc2AabpoGVqkd/HlhtzEyMkUF7m0kzpz5SAtBPEsONW5JPoOR/XiEkx4RhIzorH7sA Ay7SnDEsVJ4nP9fJuY2VBk2sdJE+jtZeOsiGnXAn2gvaesG0ndy0jC7+jMd422UItsV1 Jgzg== 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=u3i4xBhp3HPTH2hOX5GrrFUALDccx44w0a3EDzT+PTc=; b=vWZbIAyIWaXlC+fxYfoYY3gzA3Mauf7UADDq9hWHXUi9mvtAP+k5c1l/sm7HnmVVH1 XpJ8f0F7jXr1wCf35/YLvGGR6Z93zYMxYPnwFlf1iy6yZDT3UkCBbqA/GTQA4LiuKnFZ tXgQ/RuiGqnsEZ0BEXnT89VOjvYBqVyxAy5cbb4g4uD13+bUmUu9Rlp2/DqY5tEDzHA1 sGeu2HOFOnTAgqFM7umafvscy3KYPOyiLVrM4+3J2LeQUd4SUJsw1VGanSbsvoQM+co/ M67g/CPcreQ5tlEr2Zli8TGQLV9u+hVlxx/ukZI4O5k9M8iqOQLTzC1Tp1uaB56yWGxU JwPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VlWJnCDY; 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 f12si25875432plr.211.2019.07.30.00.13.17; Tue, 30 Jul 2019 00:13:31 -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=VlWJnCDY; 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 S2404215AbfG2T6x (ORCPT + 99 others); Mon, 29 Jul 2019 15:58:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:45524 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403816AbfG2TxS (ORCPT ); Mon, 29 Jul 2019 15:53:18 -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 C98CB2171F; Mon, 29 Jul 2019 19:53:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429997; bh=yNRuLvnJl93keGWCDhEdJDmk3b9iv2u3ZP53YRNB+QU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VlWJnCDY01Mu3HSFfclfBncKfGRYlnHE0uAUkltmReFYBT29VVByNeUeQgHfMUiiJ GBkjmErQXHIKU3bIRKrKivP9IYSzJjfy8qLG6+liVTv7Nosymnnny5EdNKkiCiWp1U EmE4cKWRrx20ACqx65D+s+ZTA/DIeHV5TR3Jagbw= 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 5.2 164/215] mm: use down_read_killable for locking mmap_sem in access_remote_vm Date: Mon, 29 Jul 2019 21:22:40 +0200 Message-Id: <20190729190808.252237041@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@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 ddf20bd0c317..9a4401d21e94 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4349,7 +4349,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 d8c02fbe03b5..b2823519f8cd 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -1792,7 +1792,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