Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp301752yba; Wed, 15 May 2019 01:23:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqyfZAbHXt+LJf7cwXxPIMpFFr1OqHbEygYDjl/LVf4gZ6CNz7Eq6DDV99kZTFFXcThJDdI4 X-Received: by 2002:a63:cf:: with SMTP id 198mr41479315pga.228.1557908636941; Wed, 15 May 2019 01:23:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557908636; cv=none; d=google.com; s=arc-20160816; b=TqnhSyk/Gx4zFiBPbCtabZBWrGzlwQc8FOM2HZaIzYn+EY3ZaKG9/tt/SVzeUGOZBf nE6f91Zx4LpPHZ2xm5aOGI+DZpJZPnKC5r2noxB1qtZ9vvhahu2aa+uX2N/ApQOWO/2E wmP/YhV2m25vju2fh3nlyZoCOgAqiQz0eMkkbRTGbMdn+wBjJCKqW40G1hKfO2cYt+xB GPnGWh2mFYZR1mbCLuyAvfeiW4u7OTXiY4i1buB5WfiOtm3qG7J8slIdLSgmWET1FlRD 8Igm1L+J90cwO7zpChtWozTTqUwQ3FMCN/LBPmqTHZ/P6PzdaSfvqfscMRmMc5hsbmAp 63Cw== 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:message-id:date:to:from:subject:dkim-signature; bh=rH/t30KXMBGr4dF0FJuUrEPHJpTL3NQhSuLj3xwva+0=; b=PMkNjRfTEL0JcBQA+7YgZJSSLGQ5r4YAGZkbzf1b0aHO90yOOEUvghYb04DR2JkHmL k+uoTMpjhsCDMULI9XXDpvz1ZNOVwjdPCR8EFqNCoRWJuaDhlp5EfQBlWR1TP3y2dZyq u/4R+C6nNiyGaMa1rnP3S59GaM1UIYjKPwZEl0zWXOUC4i446/87fOy18PlBkX7fBX3w Pz/hAge/TSxw4KDgLfSO1TLNrqgpJsH+bIEMsczL4yl4W5oP+eQbUGRQUmf59Gu33cip 9UEDhRPw42O7tbBmg/VMtf53OKjRXnEOorkwju2eFbZvAm/wEcS9OIlTOG+18wwGK5Mk 6K5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=fHGe8418; 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=yandex-team.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1si1219761pgq.173.2019.05.15.01.23.41; Wed, 15 May 2019 01:23:56 -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=@yandex-team.ru header.s=default header.b=fHGe8418; 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=yandex-team.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725966AbfEOIVX (ORCPT + 99 others); Wed, 15 May 2019 04:21:23 -0400 Received: from forwardcorp1o.mail.yandex.net ([95.108.205.193]:56004 "EHLO forwardcorp1o.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725871AbfEOIVW (ORCPT ); Wed, 15 May 2019 04:21:22 -0400 Received: from mxbackcorp1o.mail.yandex.net (mxbackcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::301]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id A784B2E147B; Wed, 15 May 2019 11:21:19 +0300 (MSK) Received: from smtpcorp1p.mail.yandex.net (smtpcorp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:10]) by mxbackcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id DwA5FsojOl-LJ0GRkIN; Wed, 15 May 2019 11:21:19 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1557908479; bh=rH/t30KXMBGr4dF0FJuUrEPHJpTL3NQhSuLj3xwva+0=; h=Message-ID:Date:To:From:Subject; b=fHGe8418tN46yDfQFsQ6wSmHFaUCKDn9hk25OB75c5F8CZaDVuzJE3eqbZhBq6oTD KIU4i3rNGp8X6ahgcORt5JIudN3gzYuTn/Q8xJy2ex/jLMfmHd5kABXrLZg/WNLYXo n7e5PNwGicPSEkyRzqIMK5WMjAeFBYiNWrHhO/lE= Authentication-Results: mxbackcorp1o.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:ed19:3833:7ce1:2324]) by smtpcorp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id fxC6AkQBIj-LJd0oVGu; Wed, 15 May 2019 11:21:19 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) Subject: [PATCH] mm: use down_read_killable for locking mmap_sem in access_remote_vm From: Konstantin Khlebnikov To: linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org, Oleg Nesterov Date: Wed, 15 May 2019 11:21:18 +0300 Message-ID: <155790847881.2798.7160461383704600177.stgit@buzz> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This function is used by ptrace and proc files like /proc/pid/cmdline and /proc/pid/environ. Return 0 (bytes read) if current task is killed. Mmap_sem could be locked for a long time or forever if something wrong. Signed-off-by: Konstantin Khlebnikov --- 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 96f1d473c89a..2e6846d09023 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4348,7 +4348,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 b492fd1fcf9f..cad8fb34088f 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -1791,7 +1791,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);