Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3802820ybi; Mon, 29 Jul 2019 12:56:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwnd0O1wqAQI5r8ERqpBPTvlm+Y3dA4tHVkHQnFMrMJ5NMEqJ5J4Bl4j2wHjW45X1yNH1LN X-Received: by 2002:a65:4808:: with SMTP id h8mr104695017pgs.22.1564430202364; Mon, 29 Jul 2019 12:56:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430202; cv=none; d=google.com; s=arc-20160816; b=ocZ1pPFDjX6nrWhIeWcvHZoYSAevfdH+5A0Eljb4gpft+ocZafFITHAG4T0wiR4YyO Z3djdGBVzfxyRsUPa5eLXhndcWJfFS4Zaa8SMEPsV0Y/vV09zxg9AxGd74ur+LECqln4 x6fa3Wcth+OsNLNRqSIzzThnG/I+o3Ex9e/lFptvlDK3Z8TK7JsOyKdj4RV2h0k7YdpG PjxJcqb4zRX532nTKdtgttsRriys6/HHRs5O6FebkidwYkHmtJiMopC96jvSsqyds1fB nd77m8eFOaVvgoAO6Wz4suIElG51hfvTQsYQYxunYKzphyQ5QroviI7jlGKFMpby/pys xj5A== 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=nJQ3hXuzdFn7ZC+24qjJLo/YPHUFPJTK+f1f+NHILCU=; b=jy31mMvT/zIyzVnbbwWcYazuUhC60KLYFfXECurYLs0vJXi0HvVfPnWKXXEL6tlS8j si988/gFJ6+tgHFff68Ka4feW1szNyroVFuOErNvJDZZaJlW77fZNG/YqQamHgb2xrp9 UIM/1UGoVdW97JlmtmxovoImsUAgMVjuPfslbCNI5yfcrrHTvh8GaZMdB6u43qOwvQQZ UGEV1ukjccBL7hvP7WigOdltrx1KePLI85/pUQ/JHfBPACBcPbOftZYtuHEDgb1rfXGb nWUExMZixnU8wVgShj/EyBC5SHo48TnMLFfn2JgWBccTNxan/qacNU1KYq7yInDbFVxo 6yJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BFMRHKVb; 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 y63si26544842pgd.403.2019.07.29.12.56.27; Mon, 29 Jul 2019 12:56:42 -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=BFMRHKVb; 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 S2404167AbfG2TzP (ORCPT + 99 others); Mon, 29 Jul 2019 15:55:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:47934 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391036AbfG2TzM (ORCPT ); Mon, 29 Jul 2019 15:55:12 -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 EFE01204EC; Mon, 29 Jul 2019 19:55:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564430111; bh=1RTK4MyWY4DmfoGIIMIHyA483+DSIIqOUIvtChCMhhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BFMRHKVbwPKcblteRqj2hwZRaG9DO618jDjByJ241huDhMhTCFfD0zlX+052anJAl mmDqNgnC1DFtIDrjSu8rjneiHZPK405lU6AtuW7cbeDkV8pZP8TfT4wQCRqcnaIYKw 1mA1yMqsaXbtVyyfR3vF3PvUzeg87wekBa6XOVp8= 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 160/215] proc: use down_read_killable mmap_sem for /proc/pid/map_files Date: Mon, 29 Jul 2019 21:22:36 +0200 Message-Id: <20190729190807.585600663@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 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 255f6754c70d..03517154fe0f 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1962,9 +1962,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); @@ -2010,8 +2013,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; @@ -2107,7 +2113,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; @@ -2118,6 +2128,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); @@ -2160,7 +2171,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