Skip to contentSkip to conversation

fsnotify: preserve 64-bit pre-content ranges

PATCH In review Avi Weiss 2 participants 2 messages Oct 15 – Oct 21

Subsystems (3)
lore
Share & tools
lore

Avi Weiss

author
#0 lore raw

PATCH 1/1 fsnotify: preserve 64-bit pre-content ranges

vfs_fallocate() and remap_verify_area() pass 64-bit lengths to fsnotify_file_area_perm(), which truncates them to size_t on 32-bit systems.

Use 64 bit (unsigned) types throughout the entire pre-content notification chain to keep the full range. The userspace range field is already 64-bits.

Fixes 9740d17162de ("fsnotify: pass optional file access range in pre-content event")

---
Tested on a 32-bit x86 kernel in QEMU with ext4 and FAN_CLASS_PRE_CONTENT / FAN_PRE_ACCESS with regular (4KB), boundary, near-boundary, and beyond boundary counts.

requested count before with the fix

          4096      4096           4096
    4294967295         0     4294967296
    4294967296         0     4294967296
    4294971392      4096     4294971392
fs/notify/fanotify/fanotify.h +1 -1
index 3710543dbf827..225919d7347bf 100644
@@ -441,7 +441,7 @@ struct fanotify_perm_event {
 	struct fanotify_event fae;
 	struct path path;
 	loff_t pos;			/* FANOTIFY_NO_RANGE if unavailable */
-	size_t count;
+	u64 count;
 	u32 response;			/* userspace answer to the event */
 	unsigned short state;		/* state of the event */
 	unsigned short watchdog_cnt;	/* already scanned by watchdog? */
fs/notify/fsnotify.c +1 -1
index 7e2f330fd2837..8657bb94dfa8b 100644
@@ -157,7 +157,7 @@ static inline __u32 fsnotify_object_watched(struct inode *inode, __u32 mnt_mask,
 
 /* Report pre-content event with optional range info */
 int fsnotify_pre_content(const struct path *path, const loff_t *ppos,
-			 size_t count)
+			 u64 count)
 {
 	struct file_range range;
 
include/linux/fsnotify.h +2 -2
index bda798bc67bc5..a4a29b3650080 100644
@@ -135,7 +135,7 @@ int fsnotify_open_perm_and_set_mode(struct file *file);
  * fsnotify_file_area_perm - permission hook before access to file range
  */
 static inline int fsnotify_file_area_perm(struct file *file, int perm_mask,
-					  const loff_t *ppos, size_t count)
+					  const loff_t *ppos, u64 count)
 {
 	/*
 	 * filesystem may be modified in the context of permission events
@@ -213,7 +213,7 @@ static inline int fsnotify_open_perm_and_set_mode(struct file *file)
 }
 
 static inline int fsnotify_file_area_perm(struct file *file, int perm_mask,
-					  const loff_t *ppos, size_t count)
+					  const loff_t *ppos, u64 count)
 {
 	return 0;
 }
include/linux/fsnotify_backend.h +3 -3
index 618eed4d6d724..a25ae4ed879c7 100644
@@ -323,7 +323,7 @@ struct fs_error_report {
 struct file_range {
 	const struct path *path;
 	loff_t pos;
-	size_t count;
+	u64 count;
 };
 
 static inline const struct path *file_range_path(const struct file_range *range)
@@ -945,12 +945,12 @@ static inline void fsnotify_init_event(struct fsnotify_event *event)
 	INIT_LIST_HEAD(&event->list);
 }
 int fsnotify_pre_content(const struct path *path, const loff_t *ppos,
-			 size_t count);
+			 u64 count);
 
 #else
 
 static inline int fsnotify_pre_content(const struct path *path,
-				       const loff_t *ppos, size_t count)
+				       const loff_t *ppos, u64 count)
 {
 	return 0;
 }

base-commit: 045958acaa75205b31578cb22c4345e28dd2e4bf

Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 10 lines · Avi Weiss

vfs_fallocate() and remap_verify_area() pass 64-bit lengths to fsnotify_file_area_perm(), which truncates them to size_t on 32-bit systems.

Use 64 bit (unsigned) types throughout the entire pre-content notification chain to keep the full range. The userspace range field is already 64-bits.

Fixes 9740d17162de ("fsnotify: pass optional file access range in pre-content event")

Thanks. I've added the patch to my tree.

Honza

Quoted 92 lines

---
Tested on a 32-bit x86 kernel in QEMU with ext4 and FAN_CLASS_PRE_CONTENT / FAN_PRE_ACCESS with regular (4KB), boundary, near-boundary, and beyond boundary counts.

requested count before with the fix

          4096      4096           4096
    4294967295         0     4294967296
    4294967296         0     4294967296
    4294971392      4096     4294971392
fs/notify/fanotify/fanotify.h +1 -1
index 3710543dbf827..225919d7347bf 100644
@@ -441,7 +441,7 @@ struct fanotify_perm_event {
 	struct fanotify_event fae;
 	struct path path;
 	loff_t pos;			/* FANOTIFY_NO_RANGE if unavailable */
-	size_t count;
+	u64 count;
 	u32 response;			/* userspace answer to the event */
 	unsigned short state;		/* state of the event */
 	unsigned short watchdog_cnt;	/* already scanned by watchdog? */
fs/notify/fsnotify.c +1 -1
index 7e2f330fd2837..8657bb94dfa8b 100644
@@ -157,7 +157,7 @@ static inline __u32 fsnotify_object_watched(struct inode *inode, __u32 mnt_mask,
 
 /* Report pre-content event with optional range info */
 int fsnotify_pre_content(const struct path *path, const loff_t *ppos,
-			 size_t count)
+			 u64 count)
 {
 	struct file_range range;
 
include/linux/fsnotify.h +2 -2
index bda798bc67bc5..a4a29b3650080 100644
@@ -135,7 +135,7 @@ int fsnotify_open_perm_and_set_mode(struct file *file);
  * fsnotify_file_area_perm - permission hook before access to file range
  */
 static inline int fsnotify_file_area_perm(struct file *file, int perm_mask,
-					  const loff_t *ppos, size_t count)
+					  const loff_t *ppos, u64 count)
 {
 	/*
 	 * filesystem may be modified in the context of permission events
@@ -213,7 +213,7 @@ static inline int fsnotify_open_perm_and_set_mode(struct file *file)
 }
 
 static inline int fsnotify_file_area_perm(struct file *file, int perm_mask,
-					  const loff_t *ppos, size_t count)
+					  const loff_t *ppos, u64 count)
 {
 	return 0;
 }
include/linux/fsnotify_backend.h +3 -3
index 618eed4d6d724..a25ae4ed879c7 100644
@@ -323,7 +323,7 @@ struct fs_error_report {
 struct file_range {
 	const struct path *path;
 	loff_t pos;
-	size_t count;
+	u64 count;
 };
 
 static inline const struct path *file_range_path(const struct file_range *range)
@@ -945,12 +945,12 @@ static inline void fsnotify_init_event(struct fsnotify_event *event)
 	INIT_LIST_HEAD(&event->list);
 }
 int fsnotify_pre_content(const struct path *path, const loff_t *ppos,
-			 size_t count);
+			 u64 count);
 
 #else
 
 static inline int fsnotify_pre_content(const struct path *path,
-				       const loff_t *ppos, size_t count)
+				       const loff_t *ppos, u64 count)
 {
 	return 0;
 }

base-commit: 045958acaa75205b31578cb22c4345e28dd2e4bf

Signature · 1 line
2.43.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR