pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS

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

    
11
diff --git a/fs/fcntl.c b/fs/fcntl.c
2-
index 5598e4d57422..52555e6f5a8b 100644
2+
index 5598e4d57422..43150c2a293e 100644
33
--- a/fs/fcntl.c
44
+++ b/fs/fcntl.c
5-
@@ -18,11 +18,14 @@
5+
@@ -14,6 +14,7 @@
6+
 #include <linux/file.h>
611
 #include <linux/module.h>
712
 #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)
2626
+{
2727
+	struct inode *inode = file_inode(file);
28-
+	loff_t base;
28+
+	loff_t base, start, len;
2929
+
30-
+	if (!fl || !start || !len)
30+
+	switch (whence) {
3431
+		case SEEK_SET:
3532
+			base = 0;
3633
+			break;
3734
+		case SEEK_CUR:
3835
+			base = file->f_pos;
3936
+			break;
4037
+		case SEEK_END:
4138
+			base = i_size_read(inode);
4239
+			break;
4340
+		default:
4441
+			return -EINVAL;
45-
+	}
42+
+       }
4643
+
44+
+	if (check_add_overflow(base, offset, &start))
4747
+	/*
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)
5253
+	 */
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;
5868
+
59-
+	if (*start < 0)
69+
+	if (start < 0)
6070
+		return -EINVAL;
6171
+
62-
+	*len = fl->l_len;
72+
+	range->start = start;
73+
+	range->len = len;
6374
+	return 0;
6475
+}
6576
+
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)
6779
+{
68-
+	loff_t start, len;
80+
+	loff_t len = range->len;
69-
+	int error;
81+
+	loff_t isize;
7082
+
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.
7494
+
7695
+	if (len == 0)
7796
+		return 0;
7897
+
79-
+	return vfs_fallocate(file, 0, start, len);
98+
+	return vfs_fallocate(file, 0, range->start, len);
8099
+}
81100
+
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)
83103
+{
84104
+	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;
88107
+
89-
+	error = flock_to_abs_range(file, fl, &start, &len);
108+
+	if (range->start >= isize)
109+
+		return 0;
92110
+
93-
+	isize = i_size_read(inode);
111+
+	if (range->to_eof)
112+
+		return vfs_truncate(&file->f_path, range->start);
94113
+
95-
+	if (start >= isize)
114+
+	if (check_add_overflow(range->start, range->len, &end))
96-
+		return 0;
115+
+		return -EOVERFLOW;
97116
+
98117
+	/*
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.
103121
+	 */
122+
+	if (end >= isize)
106124
+
107-
+	if (check_add_overflow(start, len, &end))
125+
+	if (range->len == 0)
108-
+		return -EOVERFLOW;
126+
+		return 0;
109127
+
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.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at