diff options
| author | Siddharth Chintamaneni <sidchintamaneni@gmail.com> | 2026-10-31 23:00:48 -0700 |
|---|---|---|
| committer | Christian Brauner <brauner@kernel.org> | 2026-11-05 22:48:19 +0100 |
| commit | 7a5783cfac71b3c12e7fb1c2894dd4538d57d513 (patch) | |
| tree | b02d49dc332b9f23f1e029f13238ced4d9e45a19 /include/linux/stackprotector.h | |
| parent | ee8323fdc827c580425644db605a4be776cace57 (diff) | |
fs: reject negative offsets for SEEK_DATA and SEEK_HOLE in default_llseek()
In default_llseek(), the range checks for SEEK_DATA and SEEK_HOLE compare
the signed loff_t offset directly against inode->i_size:
if (offset >= inode->i_size) {
retval = -ENXIO;
goto out;
}
When a negative offset is supplied to SEEK_HOLE (e.g. lseek(fd, -10,
SEEK_HOLE) on a sysctl file in /proc/sys), the signed comparison evaluates
to false and execution proceeds to:
offset = inode->i_size;
This overwrites the negative offset with a non-negative value before the
final `if (offset >= 0 || unsigned_offsets(file))` check, causing
default_llseek() to update file->f_pos and return inode->i_size instead of
failing with -ENXIO. Similarly, for SEEK_DATA on a file with
FOP_UNSIGNED_OFFSET, a negative offset bypasses the range check and
succeeds via unsigned_offsets(file).
Read the inode size once via i_size_read(inode) after acquiring the inode
lock and compare (unsigned long long)offset >= eof for both SEEK_DATA and
SEEK_HOLE, matching must_set_pos().
Fixes: 982d816581ee ("fs: add SEEK_HOLE and SEEK_DATA flags")
Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
Link: https://patch.msgid.link/20261101060049.81441-2-sidchintamaneni@gmail.com
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Diffstat (limited to 'include/linux/stackprotector.h')
0 files changed, 0 insertions, 0 deletions
