Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3793969ybi; Mon, 29 Jul 2019 12:45:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqysav/lwKPsx6vaRKKDsrk4C6bdfsD4vID9w93XUZTtiF8mMP4lmKvKNgb7FH8QEm3wLU3t X-Received: by 2002:a17:90a:246f:: with SMTP id h102mr112148037pje.126.1564429513317; Mon, 29 Jul 2019 12:45:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564429513; cv=none; d=google.com; s=arc-20160816; b=W9QXEUilZOcTvTGc7RjgGDV6f5K5KldOUTyrlx5DRdaFzXQ+uMxg90RfkPAULJmO+E 8gbTZXl16wrjnChcYJTFVVN38LOBfVQnyGAy3Z2wjQpKM0DE3iv8nLLLVIQ0OIwrJ8FD VqSHydefxSqyOhMSnPRua6L+oMCrq3GwfR+srANTY7Zvn0s90hp4pKROKhmFEgYzddEb NqU0aLKvkAYDB2NN7zhevG5B2k3KaMVfWkSJX/kWAeEO5wKyqUVCLmVwQmjgxVOR06ho xzOBMGJrfw7z/uR9iop0dPzRZmfUOW55Mt+AZaF3LsAQ7RDQ47d8BIS8cl8yw/fHariP oKJQ== 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=TLsk8er1hEZ5Ks9kNpSbLTGfL+cKPN1W22GTekZZKg0=; b=jnGS5R6XybhXkeWr8kCB18HZvPGuWaw2a3cE6A1OKnukS4Wxh3YECKFjP5DVurL1Fh yZ7Q5cfwmN8nVJJKZeLU/7LfYulXYz77BJrjhWEkUP62ofFrr7R82tyP96zJlVpacY4t BG1PQJ6qAlf7RDKyIo5BcW+7s7R/d4Iw6qV3WfLHFTF/EfEgAm5XWPkU4yeANFKfKKlU /ciONLZOXKI5LyIYpggHjkZN8OR7eaqA2SmOcBjqS8F9foMMdlk79Au3tsdHbBK5KB8R dLGXcREMeVmTsurnGOTC42ceJLcrEVyY3KNVRXYOmuo9joxs4VR5Ueo/1tOg7BdAzHOY J6Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1vy2i3wA; 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 t185si18054337pgb.329.2019.07.29.12.44.57; Mon, 29 Jul 2019 12:45:13 -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=1vy2i3wA; 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 S2389702AbfG2Tnr (ORCPT + 99 others); Mon, 29 Jul 2019 15:43:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:60174 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389168AbfG2Tnn (ORCPT ); Mon, 29 Jul 2019 15:43:43 -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 A9E2621655; Mon, 29 Jul 2019 19:43:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429422; bh=c/1hPGg/6CR6iTEm4wN+3cRAbYNxlzSAfACA9J40vec=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1vy2i3wACVTnkLOaveJG//BgvUe0ZokOqSWwxBbODCOH8G7D6JNASFevNt4xoh8bj 8T8qC1HmGQvs2Zjjw1NLTnkPuHlM2MRA8y/+/gpzZbvwkyX1msVyG84tU9YdapRP1S g9pwu7jb1WnGjdlcUAXZ0cF3R4fmHYOBKg3g/L9E= 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 092/113] proc: use down_read_killable mmap_sem for /proc/pid/map_files Date: Mon, 29 Jul 2019 21:22:59 +0200 Message-Id: <20190729190717.491633878@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 cd9e2bb8271c971d9f37c722be2616c7f8ba0664 ] Do not remain stuck forever if something goes wrong. Using a killable lock permits cleanup of stuck tasks and simplifies investigation. It seems ->d_revalidate() could return any error (except ECHILD) to abort validation and pass error as result of lookup sequence. [akpm@linux-foundation.org: fix proc_map_files_lookup() return value, per Andrei] Link: http://lkml.kernel.org/r/156007493995.3335.9595044802115356911.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/base.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index f999e8bd3771..a7fbda72afeb 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1960,9 +1960,12 @@ static int map_files_d_revalidate(struct dentry *dentry, unsigned int flags) goto out; if (!dname_to_vma_addr(dentry, &vm_start, &vm_end)) { - down_read(&mm->mmap_sem); - exact_vma_exists = !!find_exact_vma(mm, vm_start, vm_end); - up_read(&mm->mmap_sem); + status = down_read_killable(&mm->mmap_sem); + if (!status) { + exact_vma_exists = !!find_exact_vma(mm, vm_start, + vm_end); + up_read(&mm->mmap_sem); + } } mmput(mm); @@ -2008,8 +2011,11 @@ static int map_files_get_link(struct dentry *dentry, struct path *path) if (rc) goto out_mmput; + rc = down_read_killable(&mm->mmap_sem); + if (rc) + goto out_mmput; + rc = -ENOENT; - down_read(&mm->mmap_sem); vma = find_exact_vma(mm, vm_start, vm_end); if (vma && vma->vm_file) { *path = vma->vm_file->f_path; @@ -2105,7 +2111,11 @@ static struct dentry *proc_map_files_lookup(struct inode *dir, if (!mm) goto out_put_task; - down_read(&mm->mmap_sem); + result = ERR_PTR(-EINTR); + if (down_read_killable(&mm->mmap_sem)) + goto out_put_mm; + + result = ERR_PTR(-ENOENT); vma = find_exact_vma(mm, vm_start, vm_end); if (!vma) goto out_no_vma; @@ -2116,6 +2126,7 @@ static struct dentry *proc_map_files_lookup(struct inode *dir, out_no_vma: up_read(&mm->mmap_sem); +out_put_mm: mmput(mm); out_put_task: put_task_struct(task); @@ -2157,7 +2168,12 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx) mm = get_task_mm(task); if (!mm) goto out_put_task; - down_read(&mm->mmap_sem); + + ret = down_read_killable(&mm->mmap_sem); + if (ret) { + mmput(mm); + goto out_put_task; + } nr_files = 0; -- 2.20.1