* fuse readdirplus skip one entry when interrupted by signal
@ 2017-10-24 18:10 Jakob Unterwurzacher
2017-10-25 9:38 ` Miklos Szeredi
0 siblings, 1 reply; 4+ messages in thread
From: Jakob Unterwurzacher @ 2017-10-24 18:10 UTC (permalink / raw)
To: linux-fsdevel, Kernel Mailing List, Miklos Szeredi
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.
Best regards,
Jakob
[1] https://github.com/hanwen/go-fuse/issues/191
[2]
https://gist.githubusercontent.com/rfjakob/79581292a037ae7cb068067cb6207ef8/raw/f71494a291cfded8a96d02c3f0ee2983457591cc/ls-count.c
[3] https://github.com/libfuse/libfuse/issues/214
[4] gocryptfs -fg -fusedebug -nosyslog
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: fuse readdirplus skip one entry when interrupted by signal 2017-10-24 18:10 fuse readdirplus skip one entry when interrupted by signal Jakob Unterwurzacher @ 2017-10-25 9:38 ` Miklos Szeredi 2017-10-25 14:28 ` Marios Titas 0 siblings, 1 reply; 4+ messages in thread From: Miklos Szeredi @ 2017-10-25 9:38 UTC (permalink / raw) To: Jakob Unterwurzacher; +Cc: linux-fsdevel, Kernel Mailing List 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. Thanks, Miklos --- From: Miklos Szeredi <mszeredi@redhat.com> 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 <jakobunt@gmail.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Fixes: 0b05b18381ee ("fuse: implement NFS-like readdirplus support") Cc: <stable@vger.kernel.org> # 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; ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: fuse readdirplus skip one entry when interrupted by signal 2017-10-25 9:38 ` Miklos Szeredi @ 2017-10-25 14:28 ` Marios Titas 2017-10-25 14:32 ` Miklos Szeredi 0 siblings, 1 reply; 4+ messages in thread From: Marios Titas @ 2017-10-25 14:28 UTC (permalink / raw) To: Miklos Szeredi; +Cc: Jakob Unterwurzacher, linux-fsdevel, Kernel Mailing List 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 <mszeredi@redhat.com> >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 <jakobunt@gmail.com> >Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> >Fixes: 0b05b18381ee ("fuse: implement NFS-like readdirplus support") >Cc: <stable@vger.kernel.org> # 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; ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: fuse readdirplus skip one entry when interrupted by signal 2017-10-25 14:28 ` Marios Titas @ 2017-10-25 14:32 ` Miklos Szeredi 0 siblings, 0 replies; 4+ messages in thread From: Miklos Szeredi @ 2017-10-25 14:32 UTC (permalink / raw) To: Marios Titas; +Cc: Jakob Unterwurzacher, linux-fsdevel, Kernel Mailing List On Wed, Oct 25, 2017 at 4:28 PM, Marios Titas <redneb@gmx.com> wrote: > Original reporter here ("Haskell user"). I tested your patch and everything > works as expected now. Thanks for the prompt response! Thanks for the report and testing. Thanks, Miklos ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-10-25 14:33 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-10-24 18:10 fuse readdirplus skip one entry when interrupted by signal Jakob Unterwurzacher 2017-10-25 9:38 ` Miklos Szeredi 2017-10-25 14:28 ` Marios Titas 2017-10-25 14:32 ` Miklos Szeredi
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
Powered by JetHome