Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4326100ybi; Tue, 30 Jul 2019 00:00:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwTTZMMrQs8JVBV6/z+ZM2tGUoKjCniMZKW/ppiEM+gaPtVePOQE2TUNC07PI0I7Woz3zE1 X-Received: by 2002:aa7:9dcd:: with SMTP id g13mr41308337pfq.204.1564470036662; Tue, 30 Jul 2019 00:00:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564470036; cv=none; d=google.com; s=arc-20160816; b=hGGhYneKB4S/AkEJMNZI1oRVWMAkypUSqt2L4WtyJ9S3ptkb56P9sFSVt3GAUbKcam AlEODV1cyJ3jYLp8CZYBY1hHzudhRd66dqq7Nort03fn9K0mxTFVat+sGnSAUr30hFSF 2CSfsQBWKfD+1IHvbDE/VwezabygkvoKR3iJqdfIyqeodFaYTbMjDp/N4L1IMjCdrS6L DxG0TgjLgSFCNgR2Nz2dod9ka2nCWK9qQ49fvL4qVj9CoB+NSHBU9ZPNQfyrTmOCc7Vp sXFAsE4XOfnsMkdj1pV4uA1pILX1tfUGBjZ3zj/XGBYtTekj4MtGtNYjmgqEwmrxZydp hMNQ== 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=x2hQdhRzXVA++iPNTl4hYXLbME50RgsZSE6f5zfWIbg=; b=H81fDTAeNhZlchiawkUWUEJMS9sTHP++R4uXyE+/o09b5zfMrgDuVQaYZdfeTK6xPj qMqGVNJHl34WHmlpbK/Yg6sQjYmJGrc5f3GkUr3AGpt3AlM35/4pMkeIylMpF8sCjW0A ZPPqscl2khSgzSYPIMWLeo1cAn6hu3bCWrTu6fyArl7ID+cZnnIcUCIW6h1+7U0J97gB hYUwyB2X9lFBHVSMJPF0y0SKz6W9n9i+U4hL7lk17y/X2sP43MxNTgJZoM1rA9jkmstG hnTSJXEyWmf0MgkejSQxcD44qmTihDc/cMCdhMpg51VvVuHV5iDMjWzElA5WNFAj8Xpo wf8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=b5cfGN6v; 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 s6si28086796plp.229.2019.07.30.00.00.21; Tue, 30 Jul 2019 00:00:36 -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=b5cfGN6v; 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 S2404192AbfG2TzX (ORCPT + 99 others); Mon, 29 Jul 2019 15:55:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:48084 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404174AbfG2TzT (ORCPT ); Mon, 29 Jul 2019 15:55:19 -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 2D7182054F; Mon, 29 Jul 2019 19:55:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564430118; bh=qcCf5O/iOs6Wit3SOnD5bF/RZv0o6/UwaExth/zT2mc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b5cfGN6vK0pgI1Y8K/wFS6qWkUbuITxaDtLS1aLow2yrC4zwTtsb0Sv9TpPN245sP hgFAsPMz16S7N11SHuJtVba+iU1gZodEQCmU7QzL8mVM6lWWBmSA2XxVe2M6gpjKdX I4gkLH76usxG7cMsxsXoE7XzYUyRNcYiM/0xWbHA= 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 5.2 162/215] proc: use down_read_killable mmap_sem for /proc/pid/maps Date: Mon, 29 Jul 2019 21:22:38 +0200 Message-Id: <20190729190807.925138981@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 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 abcd9513efff..7f84d1477b5b 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 36bf0f2e102e..7907e6419e57 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