Difference between
modified post ad545ecd0 by Anonymous on Tue 30th Jun 2026 12:23
original post 16e45d1 by Anonymous on Wed 24th Jun 2026 16:37
Download diff
Show
old version |
new version |
both versions
| 1 | 1 | diff --git a/fs/fcntl.c b/fs/fcntl.c | |
| 2 | - | index 5598e4d57422..52555e6f5a8b 100644 | |
| 2 | + | index 5598e4d57422..43150c2a293e 100644 | |
| 3 | 3 | --- a/fs/fcntl.c | |
| 4 | 4 | +++ b/fs/fcntl.c | |
| 5 | - | @@ -18,11 +18,14 @@ | |
| 5 | + | @@ -14,6 +14,7 @@ | |
| 6 | + | #include <linux/file.h> | |
| 6 | 11 | #include <linux/module.h> | |
| 7 | 12 | #include <linux/pipe_fs_i.h> | |
| 8 | - | #include <linux/security.h> | |
| 13 | + | @@ -36,6 +37,217 @@ | |
| 9 | - | +#include <linux/falloc.h> | |
| 14 | + | ||
| 10 | - | #include <linux/ptrace.h> | |
| 15 | + | #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME) | |
| 11 | - | #include <linux/signal.h> | |
| 16 | + | ||
| 12 | - | #include <linux/rcupdate.h> | |
| 17 | + | +struct fcntl_space_range { | |
| 13 | - | #include <linux/pid_namespace.h> | |
| 18 | + | + loff_t start; | |
| 14 | - | #include <linux/user_namespace.h> | |
| 19 | + | + loff_t len; | |
| 15 | - | +#include <linux/fsnotify.h> | |
| 20 | + | + bool to_eof; | |
| 16 | - | +#include <linux/mnt_idmapping.h> | |
| 21 | + | +}; | |
| 17 | - | #include <linux/memfd.h> | |
| 22 | + | + | |
| 18 | - | #include <linux/compat.h> | |
| 23 | + | +static int fcntl_space_resolve_range(struct file *file, int whence, | |
| 19 | - | #include <linux/mount.h> | |
| 24 | + | + loff_t offset, loff_t flen, | |
| 20 | - | @@ -36,6 +39,122 @@ | |
| 25 | + | + struct fcntl_space_range *range) | |
| 26 | 26 | +{ | |
| 27 | 27 | + struct inode *inode = file_inode(file); | |
| 28 | - | + loff_t base; | |
| 28 | + | + loff_t base, start, len; | |
| 29 | 29 | + | |
| 30 | - | + if (!fl || !start || !len) | |
| 30 | + | + switch (whence) { | |
| 34 | 31 | + case SEEK_SET: | |
| 35 | 32 | + base = 0; | |
| 36 | 33 | + break; | |
| 37 | 34 | + case SEEK_CUR: | |
| 38 | 35 | + base = file->f_pos; | |
| 39 | 36 | + break; | |
| 40 | 37 | + case SEEK_END: | |
| 41 | 38 | + base = i_size_read(inode); | |
| 42 | 39 | + break; | |
| 43 | 40 | + default: | |
| 44 | 41 | + return -EINVAL; | |
| 45 | - | + } | |
| 42 | + | + } | |
| 46 | 43 | + | |
| 44 | + | + if (check_add_overflow(base, offset, &start)) | |
| 47 | 47 | + /* | |
| 48 | - | + * Keep the implementation simple: | |
| 48 | + | + * Match POSIX byte-range convention: | |
| 49 | - | + * l_len > 0 : fixed byte range | |
| 49 | + | + * | |
| 50 | - | + * l_len == 0: [start, EOF) | |
| 50 | + | + * flen > 0: [start, start + flen) | |
| 51 | - | + * l_len < 0 : reject for now | |
| 51 | + | + * flen == 0: [start, EOF) | |
| 52 | + | + * flen < 0: [start + flen, start) | |
| 52 | 53 | + */ | |
| 53 | - | + if (fl->l_len < 0) | |
| 54 | + | + if (flen < 0) { | |
| 54 | - | + return -EINVAL; | |
| 55 | + | + if (check_add_overflow(start, flen, &start)) | |
| 55 | - | + | |
| 56 | + | + return -EOVERFLOW; | |
| 56 | - | + if (check_add_overflow(base, (loff_t)fl->l_start, start)) | |
| 57 | + | + if (flen == LLONG_MIN) | |
| 57 | - | + return -EOVERFLOW; | |
| 58 | + | + return -EOVERFLOW; | |
| 59 | + | + len = -flen; | |
| 58 | 68 | + | |
| 59 | - | + if (*start < 0) | |
| 69 | + | + if (start < 0) | |
| 60 | 70 | + return -EINVAL; | |
| 61 | 71 | + | |
| 62 | - | + *len = fl->l_len; | |
| 72 | + | + range->start = start; | |
| 73 | + | + range->len = len; | |
| 63 | 74 | + return 0; | |
| 64 | 75 | +} | |
| 65 | 76 | + | |
| 66 | - | +static int do_fcntl_allocsp(struct file *file, struct flock *fl) | |
| 77 | + | +static int fcntl_space_alloc(struct file *file, | |
| 78 | + | + const struct fcntl_space_range *range) | |
| 67 | 79 | +{ | |
| 68 | - | + loff_t start, len; | |
| 80 | + | + loff_t len = range->len; | |
| 69 | - | + int error; | |
| 81 | + | + loff_t isize; | |
| 70 | 82 | + | |
| 71 | - | + error = flock_to_abs_range(file, fl, &start, &len); | |
| 83 | + | + /* | |
| 72 | - | + if (error) | |
| 84 | + | + * For |len == 0|, allocate from start to current EOF. | |
| 73 | - | + return error; | |
| 85 | + | + * If start is beyond EOF, this is an empty range and therefore a | |
| 86 | + | + * no-op. | |
| 74 | 94 | + | |
| 76 | 95 | + if (len == 0) | |
| 77 | 96 | + return 0; | |
| 78 | 97 | + | |
| 79 | - | + return vfs_fallocate(file, 0, start, len); | |
| 98 | + | + return vfs_fallocate(file, 0, range->start, len); | |
| 80 | 99 | +} | |
| 81 | 100 | + | |
| 82 | - | +static int do_fcntl_freesp(struct file *file, struct flock *fl) | |
| 101 | + | +static int fcntl_space_free(struct file *file, | |
| 102 | + | + const struct fcntl_space_range *range) | |
| 83 | 103 | +{ | |
| 84 | 104 | + struct inode *inode = file_inode(file); | |
| 85 | - | + struct mnt_idmap *idmap = file_mnt_idmap(file); | |
| 105 | + | + loff_t isize = i_size_read(inode); | |
| 86 | - | + loff_t start, len, isize, end; | |
| 106 | + | + loff_t end; | |
| 88 | 107 | + | |
| 89 | - | + error = flock_to_abs_range(file, fl, &start, &len); | |
| 108 | + | + if (range->start >= isize) | |
| 109 | + | + return 0; | |
| 92 | 110 | + | |
| 93 | - | + isize = i_size_read(inode); | |
| 111 | + | + if (range->to_eof) | |
| 112 | + | + return vfs_truncate(&file->f_path, range->start); | |
| 94 | 113 | + | |
| 95 | - | + if (start >= isize) | |
| 114 | + | + if (check_add_overflow(range->start, range->len, &end)) | |
| 96 | - | + return 0; | |
| 115 | + | + return -EOVERFLOW; | |
| 97 | 116 | + | |
| 98 | 117 | + /* | |
| 99 | - | + * { Solaris, FreeBSD, SUPER/UX, ... }-style |l_len == 0| means | |
| 118 | + | + * Freeing through EOF must shrink the file. Hole punching keeps | |
| 100 | - | + * "from start to EOF". | |
| 119 | + | + * |i_size| unchanged, which is not the desired |F_FREESP| tail | |
| 101 | - | + * Linux hole punching keeps |i_size| unchanged, so use truncate | |
| 120 | + | + * behavior. | |
| 103 | 121 | + */ | |
| 122 | + | + if (end >= isize) | |
| 106 | 124 | + | |
| 107 | - | + if (check_add_overflow(start, len, &end)) | |
| 125 | + | + if (range->len == 0) | |
| 108 | - | + return -EOVERFLOW; | |
| 126 | + | + return 0; | |
| 109 | 127 | + | |
| 128 | + | + return vfs_fallocate(file, |
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
nrubsig.kpaste.net RSS