From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751879AbdJYO3I (ORCPT ); Wed, 25 Oct 2017 10:29:08 -0400 Received: from mout.gmx.net ([212.227.17.20]:65526 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750823AbdJYO3F (ORCPT ); Wed, 25 Oct 2017 10:29:05 -0400 Date: Wed, 25 Oct 2017 17:28:59 +0300 From: Marios Titas To: Miklos Szeredi Cc: Jakob Unterwurzacher , linux-fsdevel@vger.kernel.org, Kernel Mailing List Subject: Re: fuse readdirplus skip one entry when interrupted by signal Message-ID: <20171025142815.kgdapqs7ver7kdvj@zeno> References: <20171025093809.GB32700@veci.piliscsaba.szeredi.hu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20171025093809.GB32700@veci.piliscsaba.szeredi.hu> User-Agent: NeoMutt/20170609 (1.8.3) X-Provags-ID: V03:K0:MxugnqTeZUuIT7keZbNbBB4yvysl2IvQCqWXtdoALhc04ltNZV0 EooCbh9k7TJB1nqztvmZWFYVxqkAXyTUuDjX3MMzsft3pCZRNXM01+I/jjtLU2Vm9a8OvoE a5yDyqsdh6egYzA6LzTDXOHdBH4wWsJqAEBWr6Gez0iZ8IMVJkgEBPRW2bAwppvRSuqCl5T eISqFBaO3Inf4W/C9VSpg== X-UI-Out-Filterresults: notjunk:1;V01:K0:+WiK4ZuoC/Y=:HOMf0KyAbsgQMre8fbPDL0 8XiCxRzz+cYtrrJ0dx/FOp6Cww407dnXjVylbN6evWOjs5UA8VRDNrvUHQMYwmyzPNAsTTqvV xqHCYVouOZFJkm1lAMVdNEZ5a7W9yi7uRjwCDNvAtgJgoDeyM+uTR/MokRK2j12rdfa2nESbp OrXv3qcrU21fYRwk5HIdeOcr9TdIfXOF4hNi7jNui0f3uZY3qNZ8hPL3cSuqXG4hrp1x2fEC0 zPiCsoG+N1HBwWdy+tCpyr0XZ9+Me13AfiU72MF48UxyJDtQMvDuGk7TYXPU0OUSZkOMiQZ7O EDrAD0bXQ32oSjFpCWQcaM23oNoL/ikkTHW7uf/X70hlJ0IN5vKUBAVjJRSDqgqY1Zs8FvMxh xF5acuFLbnip1XvAd49r7lFqMxCFX8c5enI+HM93Ak0KJCJeZ3/AfwovujUymcvjY3eHM8Qum Aa40Typ7RfrqRL5airk5sYklw/2a3I0M5gJOyIOBrDzXJ/ESnIQNjBHTNS4uhFboFSnf4XZgM 7LjeCT0v9/fRklI2W7FpqFtkTJSM7bgOFv5qhPpjz9iHiCkyHoRJzHlzuDMFucSqdqr6ZyXfC DnT38Z4jJ9ESCKanapJspOgGDxFLujh1msh0YnEpxpT7MSIvr17h1OcbxHO6kvF9bg8Hn7QDK a2jmSbHzJp8gW5v1wJLkJVTSQdhl8meETVgp/Av9ySkgTWMZ0IRrDoNRdYwjmjsXeuDgmrFnj H+ClZz0NVspcES/mVKcZR3s5HEGNHBYvaNwWzsBX2R1eGGSSNi7DkgK0egdgBf0gno7XkxvXB kEUojoEbZ5h5bP/TzvYoDKkZ7lnUg== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 25, 2017 at 11:38:09AM +0200, Miklos Szeredi wrote: >On Tue, Oct 24, 2017 at 08:10:49PM +0200, Jakob Unterwurzacher wrote: >> A user running a Haskell program [1] noticed a problem with fuse's >> readdirplus: when it is interrupted by a signal, it skips one >> directory entry. >> >> The problem is most apparent with Haskell as it uses >> SIGVTALRM to interrupt it's own green threads. >> >> A minimal reproducer in C, "ls-count.c", is available [2]. The problem >> has been reproduced against libfuse's "passthrough_fh.c", but also against >> gocryptfs, which uses go-fuse instead of libfuse. This suggest >> that the bug is in kernel-space, which also the opinion of libfuse >> upstream [3]. >> >> What "ls-count.c" does is that it loops over readdir while sending itself >> SIGVTALRM. When the count of directory entries changes, it exits: >> >> $ ./ls-count b >> ls-count: counts do not match: 2 vs 1 >> >> strace against ls-count shows that we get one entry, when we should get >> two ("." and ".."): >> >> getdents(3, /* 1 entries */, 32768) = 24 >> --- SIGVTALRM --- >> rt_sigreturn({mask=[]}) = 24 >> getdents(3, /* 0 entries */, 32768) = 0 >> >> The debug output from go-fuse [4] shows what seems to be happening: >> >> Dispatch 548: READDIRPLUS, NodeId: 1. data: {Fh 3 off 0 sz 4096} >> Serialize 548: READDIRPLUS code: OK value: 320 bytes data >> Dispatch 549: READDIRPLUS, NodeId: 1. data: {Fh 3 off 2 sz 4096} >> Serialize 549: READDIRPLUS code: OK value: >> >> The kernel starts reading the directory from "off 0", where it is >> interrupted, and only returns one entry to userspace. Then it continues >> reading at "off 2". Offset 1 is skipped. >> >> I can reliably reproduce this within 1 second against kernel 4.12.5. > >Thanks for the report. The patch below should fix it. > Hi Miklos, Original reporter here ("Haskell user"). I tested your patch and everything works as expected now. Thanks for the prompt response! - Marios >Thanks, >Miklos >--- > >From: Miklos Szeredi >Subject: fuse: fix READDIRPLUS skipping an entry > >A user running a Haskell program noticed a problem with fuse's readdirplus: >when it is interrupted by a signal, it skips one directory entry. > >The reason is that fuse erronously updates ctx->pos after a failed >dir_emit(). > >The issue originates from the patch adding readdirplus support. > >Reported-by: Jakob Unterwurzacher >Signed-off-by: Miklos Szeredi >Fixes: 0b05b18381ee ("fuse: implement NFS-like readdirplus support") >Cc: # v3.9 >--- > fs/fuse/dir.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > >--- a/fs/fuse/dir.c >+++ b/fs/fuse/dir.c >@@ -1308,7 +1308,8 @@ static int parse_dirplusfile(char *buf, > */ > over = !dir_emit(ctx, dirent->name, dirent->namelen, > dirent->ino, dirent->type); >- ctx->pos = dirent->off; >+ if (!over) >+ ctx->pos = dirent->off; > } > > buf += reclen;