Skip to content

Commit c31f91c

Browse files
author
Miklos Szeredi
committed
fuse: don't allow signals to interrupt getdents copying
When getting the directory contents, the entries are first fetched to a kernel buffer, then they are copied to userspace with dir_emit(). This second phase is non-blocking as long as the userspace buffer is not paged out, making it interruptible makes zero sense. Overload d_type as flags, since it only uses 4 bits from 32. Reviewed-by: Bernd Schubert <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent f3cb8bd commit c31f91c

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

fs/fuse/readdir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static bool fuse_emit(struct file *file, struct dir_context *ctx,
120120
fuse_add_dirent_to_cache(file, dirent, ctx->pos);
121121

122122
return dir_emit(ctx, dirent->name, dirent->namelen, dirent->ino,
123-
dirent->type);
123+
dirent->type | FILLDIR_FLAG_NOINTR);
124124
}
125125

126126
static int parse_dirfile(char *buf, size_t nbytes, struct file *file,
@@ -422,7 +422,7 @@ static enum fuse_parse_result fuse_parse_cache(struct fuse_file *ff,
422422
if (ff->readdir.pos == ctx->pos) {
423423
res = FOUND_SOME;
424424
if (!dir_emit(ctx, dirent->name, dirent->namelen,
425-
dirent->ino, dirent->type))
425+
dirent->ino, dirent->type | FILLDIR_FLAG_NOINTR))
426426
return FOUND_ALL;
427427
ctx->pos = dirent->off;
428428
}

fs/readdir.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ static bool filldir(struct dir_context *ctx, const char *name, int namlen,
266266
int reclen = ALIGN(offsetof(struct linux_dirent, d_name) + namlen + 2,
267267
sizeof(long));
268268
int prev_reclen;
269+
unsigned int flags = d_type;
270+
271+
BUILD_BUG_ON(FILLDIR_FLAG_NOINTR & S_DT_MASK);
272+
d_type &= S_DT_MASK;
269273

270274
buf->error = verify_dirent_name(name, namlen);
271275
if (unlikely(buf->error))
@@ -279,7 +283,7 @@ static bool filldir(struct dir_context *ctx, const char *name, int namlen,
279283
return false;
280284
}
281285
prev_reclen = buf->prev_reclen;
282-
if (prev_reclen && signal_pending(current))
286+
if (!(flags & FILLDIR_FLAG_NOINTR) && prev_reclen && signal_pending(current))
283287
return false;
284288
dirent = buf->current_dir;
285289
prev = (void __user *) dirent - prev_reclen;
@@ -351,6 +355,10 @@ static bool filldir64(struct dir_context *ctx, const char *name, int namlen,
351355
int reclen = ALIGN(offsetof(struct linux_dirent64, d_name) + namlen + 1,
352356
sizeof(u64));
353357
int prev_reclen;
358+
unsigned int flags = d_type;
359+
360+
BUILD_BUG_ON(FILLDIR_FLAG_NOINTR & S_DT_MASK);
361+
d_type &= S_DT_MASK;
354362

355363
buf->error = verify_dirent_name(name, namlen);
356364
if (unlikely(buf->error))
@@ -359,7 +367,7 @@ static bool filldir64(struct dir_context *ctx, const char *name, int namlen,
359367
if (reclen > buf->count)
360368
return false;
361369
prev_reclen = buf->prev_reclen;
362-
if (prev_reclen && signal_pending(current))
370+
if (!(flags & FILLDIR_FLAG_NOINTR) && prev_reclen && signal_pending(current))
363371
return false;
364372
dirent = buf->current_dir;
365373
prev = (void __user *)dirent - prev_reclen;
@@ -513,6 +521,10 @@ static bool compat_filldir(struct dir_context *ctx, const char *name, int namlen
513521
int reclen = ALIGN(offsetof(struct compat_linux_dirent, d_name) +
514522
namlen + 2, sizeof(compat_long_t));
515523
int prev_reclen;
524+
unsigned int flags = d_type;
525+
526+
BUILD_BUG_ON(FILLDIR_FLAG_NOINTR & S_DT_MASK);
527+
d_type &= S_DT_MASK;
516528

517529
buf->error = verify_dirent_name(name, namlen);
518530
if (unlikely(buf->error))
@@ -526,7 +538,7 @@ static bool compat_filldir(struct dir_context *ctx, const char *name, int namlen
526538
return false;
527539
}
528540
prev_reclen = buf->prev_reclen;
529-
if (prev_reclen && signal_pending(current))
541+
if (!(flags & FILLDIR_FLAG_NOINTR) && prev_reclen && signal_pending(current))
530542
return false;
531543
dirent = buf->current_dir;
532544
prev = (void __user *) dirent - prev_reclen;

include/linux/fs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,9 @@ struct dir_context {
20732073
loff_t pos;
20742074
};
20752075

2076+
/* If OR-ed with d_type, pending signals are not checked */
2077+
#define FILLDIR_FLAG_NOINTR 0x1000
2078+
20762079
/*
20772080
* These flags let !MMU mmap() govern direct device mapping vs immediate
20782081
* copying more easily for MAP_PRIVATE, especially for ROM filesystems.

0 commit comments

Comments
 (0)