From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57260C43381 for ; Wed, 20 Mar 2019 13:46:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 255CA2184E for ; Wed, 20 Mar 2019 13:46:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AgPJ4myB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727239AbfCTNqd (ORCPT ); Wed, 20 Mar 2019 09:46:33 -0400 Received: from mail-yw1-f49.google.com ([209.85.161.49]:42114 "EHLO mail-yw1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726065AbfCTNqd (ORCPT ); Wed, 20 Mar 2019 09:46:33 -0400 Received: by mail-yw1-f49.google.com with SMTP id e76so1987977ywa.9 for ; Wed, 20 Mar 2019 06:46:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Pa7piluUPHzQsTajM8rWVtxhJDzB6TOo+WDtu/BINFQ=; b=AgPJ4myBjqBmaOIpevffIRiy4+s0Is+Jzc40mPgNN+cJStk9wc7LdlT9Z9MelzBHSb 3IYdcs09ZXXj0/fRrYBh6K5uWlMq0pUQzYtZ/hmutZ+i37Bf3FD/WxGT4LX3+8J7cPpg xD1Z+oaEAycYCR0cGSpvRMqFNX2DxDdg9k2RmLzTpmnChaXiTbv7l7C4j0UGAHaz9D8E /XIiqII8rBMtfbhzmwlwO6pAFpEjab+K1o7AaivCMs6KSY39yC6KZb1Kud+BSrmTUMSf 9nw4zMl35GUWNYIuMqgKs//cvUrfKCc5BTqQ9n5gTvs+MEJgJoRAi9npKB2NxXKuN5fn 15LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Pa7piluUPHzQsTajM8rWVtxhJDzB6TOo+WDtu/BINFQ=; b=PLpN+q6o3GsA0vsjAoNMZhlcoI7y8DiPmq2RDhjWhVNXyWy8dhCL8Dq8ulF+GtMoVb sVtdCJS2uy8oPGOw8gj1EiBrcW1y91KAjaxkC798ReXPjdQ2WMLHIZdKXVYK2iCMRdPr Mqsdos6WM1nKr4woX4m8k1vWaRojBlu7O4FXIYDvDaNZ4tUsvPqQfA2MH7Z4SEgnbHtt KiZRWPhSEMlXA4/uLxICA58Bv7uVP+EeyMNBisBtd0L4KzGukPzkp7ZbgpUfHWw6mrab zG/JGGuAkhqHOGadOzMkhdMi3flMc+herB8kmIYlZVe2rMy6Odu/fqnVSzMxVtOfu9qH n9ag== X-Gm-Message-State: APjAAAV+/duEYE5Ga0Eamb/deI2ezYbfMhCOp5YD0tDTz+in4ut4jGSY SspYCqO3GsiCMFj8sZIj6w8GPKCKz3uO5/4FPuk= X-Google-Smtp-Source: APXvYqy4FNR/IannMPKapt98BzgzM2sw6mLCW0Nek1I74QSTCB7ZhbtSY3FRVUFT0DI/Y7L8rFXzAXCzpQhbZFe5R1Y= X-Received: by 2002:a0d:ff82:: with SMTP id p124mr6982965ywf.409.1553089592234; Wed, 20 Mar 2019 06:46:32 -0700 (PDT) MIME-Version: 1.0 References: <20190320131642.GE9485@quack2.suse.cz> In-Reply-To: <20190320131642.GE9485@quack2.suse.cz> From: Amir Goldstein Date: Wed, 20 Mar 2019 15:46:20 +0200 Message-ID: Subject: Re: fanotify permission events on virtual filesystem To: Jan Kara Cc: linux-fsdevel , mhocko@suse.cz, Al Viro Content-Type: text/plain; charset="UTF-8" Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Wed, Mar 20, 2019 at 3:16 PM Jan Kara wrote: > > Hello, > > recently, one of our customers has reported a deadlock with fanotify. The > analysis has shown that a process has put (likely by mistake) FAN_OPEN_PERM > mark on /proc and / filesystem. That resulted in a deadlock like follows: > > process 1: process 2: process 3: > open("/proc/process 2/maps") > - blocks waiting for response to > FAN_OPEN_PERM event > > exec(2) > __do_execve_file() > - grabs current->signal->cred_guard_mutex > do_open_execat() > - blocks waiting for response to > FAN_OPEN_PERM event > > reads fanotify event > generated by process 1 > create_fd() > dentry_open() > proc_maps_open() > blocks on > cred_guard_mutex of process 2. > > Now this is not the only case where you can setup fanotify permissions > events so that your listener deadlocks but I'd argue that this case is > especially nasty and it is unrealistic to expect from userspace that it > would be able to implement fanotify listener in such a way that is > deadlock-free for proc filesystem since the lock dependencies there are > very different. So how about we just forbid placing marks with fanotify > permission events on proc? Any other virtual filesystem we should exclude? > I bet if we forbid placing marks on /proc, some apps would break. I always though that allowing O_PATH in event_f_flags can make sense for some apps. What if instead of forbiding marks of /proc, we would force those marks to use O_PATH for fd creation. Some of the functionality will remain. Apps are less likely to break. Deadlocks will be less likely, although maybe still possible. Note that the new FAN_REPORT_FID listener already excludes marking most virtual filesystems for lack of s_export_op. Thanks, Amir.