Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3795144ybi; Mon, 29 Jul 2019 12:46:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqyZu1MJl6WDuSurSIGF4eaMvT7T8U8W1MK53ksVgogErrEy6MprjIt6oVe1dAzVQUQTsy0O X-Received: by 2002:a63:484d:: with SMTP id x13mr105197726pgk.122.1564429594270; Mon, 29 Jul 2019 12:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564429594; cv=none; d=google.com; s=arc-20160816; b=fGR56RFiJmxlPMG60CRaY82SDa6WDXgcaVuBcNEIOJ8Hnpp7ReosH7lH4AOvhSbzYR WH9sdqRp707DdoGZwJzVqMYPlSJHyEHA8YVcQYzhN9biJTN1QtpQCiD9XBrKgK0xM6o/ VFNHIBFw741MNQnoItkCs54lUVyM5JbPczXt5yzdZOpqtC+ECamiy4xmvh0r47zL0zjH jiIAAYZjxNOunp815ngobrzINpQXJ2XRHg5g1eQvTeQekuk/qF7RsqJE1fnxMUv4uQKN yaV66w1UEy3yt2/bFC//Hjlkr/HOT7s21qHk/O2TmzTmY5jpRVeHX4dTNV/IEjtncEck 1QAQ== 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=E/e+FxtYITOrbUF8u9RaIc+w00esQgozZDqA1GCAiyg=; b=fFWqFRgb4iHisx9MRBDmSGUbTMjE8q1lVuI2iM/u/Vr7HPVP/qyotaXeb1lw7Y1Sk8 vtbAiERvPNq9RcC0/qxCoQhSDV30XLVud1wFSFu6XJ4OHgkGMO7OPvaeW3qC3RNwUnrC iLl5J3+7OpOsXMRJ5VlkL1U/zqKzQe10VwiyMM4DC+FrCXoW4EOCEVbv9nYrV8JVPfCM wPqxzGdjr0RTyn3udoSjStq5BaBE0U73ixvBciqSH0oWiAeOizxFhlQG2OnxYjfJfpEB TaStgpv3J/6FLurL2EgBuIXqHZfxMKwlVEQM7aeBrUHCaX9oPMcOg6vPBGPGRxcxG4Fy DHsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Oq/EV3SY"; 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 s12si25803829plp.63.2019.07.29.12.46.18; Mon, 29 Jul 2019 12:46: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="Oq/EV3SY"; 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 S2389447AbfG2Tn6 (ORCPT + 99 others); Mon, 29 Jul 2019 15:43:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:60362 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389703AbfG2Tnt (ORCPT ); Mon, 29 Jul 2019 15:43:49 -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 0CB6B2054F; Mon, 29 Jul 2019 19:43:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429428; bh=a6lC2IY5cl8rBIt09mHAn0ZYddmAartBKkgpZCHNYjw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Oq/EV3SYPZquawfSP023vTXBz205a0NtCPlH1vrIet6ukhotzYjttMWAThJvJsv/p 6zhjz7khuv8VGOGV5xUdkt6uPG1plLHngakW3vn0gjnjNIgmYJhTMuFTb/67G9KEon 1kTPWuFJPbc7ZFezH75A+4VcUckEMUWxK3QZuluc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Konstantin Khlebnikov , Roman Gushchin , Cyrill Gorcunov , Kirill Tkhai , Michal Hocko , Alexey Dobriyan , Al Viro , Matthew Wilcox , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Oleg Nesterov , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 094/113] proc: use down_read_killable mmap_sem for /proc/pid/maps Date: Mon, 29 Jul 2019 21:23:01 +0200 Message-Id: <20190729190717.991622786@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 8a713e7df3352b8d9392476e9cf29e4e185dac32 ] Do not remain stuck forever if something goes wrong. Using a killable lock permits cleanup of stuck tasks and simplifies investigation. This function is also used for /proc/pid/smaps. Link: http://lkml.kernel.org/r/156007493160.3335.14447544314127417266.stgit@buzz Signed-off-by: Konstantin Khlebnikov Reviewed-by: Roman Gushchin Reviewed-by: Cyrill Gorcunov Reviewed-by: Kirill Tkhai Acked-by: Michal Hocko Cc: Alexey Dobriyan Cc: Al Viro Cc: Matthew Wilcox Cc: Michal Koutný Cc: Oleg Nesterov Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/proc/task_mmu.c | 6 +++++- fs/proc/task_nommu.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 195fbbaf77d4..71aba44c4fa6 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -166,7 +166,11 @@ static void *m_start(struct seq_file *m, loff_t *ppos) if (!mm || !mmget_not_zero(mm)) return NULL; - down_read(&mm->mmap_sem); + if (down_read_killable(&mm->mmap_sem)) { + mmput(mm); + return ERR_PTR(-EINTR); + } + hold_task_mempolicy(priv); priv->tail_vma = get_gate_vma(mm); diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c index 0b63d68dedb2..5161894a6d62 100644 --- a/fs/proc/task_nommu.c +++ b/fs/proc/task_nommu.c @@ -211,7 +211,11 @@ static void *m_start(struct seq_file *m, loff_t *pos) if (!mm || !mmget_not_zero(mm)) return NULL; - down_read(&mm->mmap_sem); + if (down_read_killable(&mm->mmap_sem)) { + mmput(mm); + return ERR_PTR(-EINTR); + } + /* start from the Nth VMA */ for (p = rb_first(&mm->mm_rb); p; p = rb_next(p)) if (n-- == 0) -- 2.20.1