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=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 2C183C3A5A9 for ; Mon, 4 May 2020 11:09:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 117852073B for ; Mon, 4 May 2020 11:09:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728311AbgEDLJl (ORCPT ); Mon, 4 May 2020 07:09:41 -0400 Received: from mailhub.9livesdata.com ([194.181.36.210]:44402 "EHLO mailhub.9livesdata.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727786AbgEDLJl (ORCPT ); Mon, 4 May 2020 07:09:41 -0400 X-Greylist: delayed 552 seconds by postgrey-1.27 at vger.kernel.org; Mon, 04 May 2020 07:09:39 EDT Received: from [192.168.6.101] (icore-01 [192.168.6.101]) by mailhub.9livesdata.com (Postfix) with ESMTP id 241653465BD9; Mon, 4 May 2020 13:00:21 +0200 (CEST) From: Krzysztof Rusek Subject: fuse_notify_inval_inode() may be ineffective when getattr request is in progress To: Miklos Szeredi , linux-fsdevel@vger.kernel.org Message-ID: <846ae13f-acd9-9791-3f1b-855e4945012a@9livesdata.com> Date: Mon, 4 May 2020 13:00:21 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------52CD8B03056B0F92CAC5F765" Content-Language: en-US Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This is a multi-part message in MIME format. --------------52CD8B03056B0F92CAC5F765 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hello, I'm working on a user-space file system implementation utilizing fuse kernel module (and libfuse user-space library). This file system implementation provides a custom ioctl operation that uses fuse_lowlevel_notify_inval_inode() function (which translates to fuse_notify_inval_inode() in kernel) to notify the kernel that the file was changed by the ioctl. However, under certain circumstances, fuse_notify_inval_inode() call is ineffective, resulting in incorrect file attributes being cached by the kernel. The problem occurs when ioctl() is executed in parallel with getattr(). I noticed this problem on RedHat 7.7 (3.10.0-1062.el7.x86_64), but I believe mainline kernel is affected as well. I think there is a bug in the way fuse_notify_inval_inode() invalidates file attributes. If getattr() started before fuse_notify_inval_inode() was called, then the attributes returned by user-space process may be out of date, and should not be cached. But fuse_notify_inval_inode() only clears attribute validity time, which does not prevent getattr() result from being cached. More precisely, this bug occurs in the following scenario: 1. kernel starts handling ioctl 2. file system process receives ioctl request 3. kernel starts handling getattr 4. file system process receives getattr request 5. file system process executes getattr 6. file system process executes ioctl, changing file state 7. file system process invokes fuse_lowlevel_notify_inval_inode(), which invalidates file attributes in kernel 8. file system process sends ioctl reply, ioctl handling ends 9. file system process sends getattr reply, attributes are incorrectly cached in the kernel (Note that this scenario assumes that file system implementation is multi-threaded, therefore allowing ioctl() and getattr() to be handled in parallel.) I'm attaching an archive with a reproduction test for this problem. The archive contains a README file explaining how to compile/run it. By the way, to avoid a somehow similar race when write() is executed in parallel with getattr(), there is a special FUSE_I_SIZE_UNSTABLE bit set for the duration of write() operation. Best regards, Krzysztof Rusek --------------52CD8B03056B0F92CAC5F765 Content-Type: application/gzip; name="fusebug.tar.gz" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="fusebug.tar.gz" H4sIABX1r14AA+0a/XPTypFf7b9iCUMiGduxnMSewYRXBgL1TEiYJJS+tm/0ZOkUa6IPVx9A KPnfu7t3+rJjh0cbmGm1MzjS3d7uar/v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