Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs: Pass argument to fcntl_setlease as int

The interface for fcntl expects the argument passed for the command
F_SETLEASE to be of type int. The current code wrongly treats it as
a long. In order to avoid access to undefined bits, we should explicitly
cast the argument to int.

Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Chuck Lever <chuck.lever@oracle.com>
Cc: Trond Myklebust <trond.myklebust@hammerspace.com>
Cc: Anna Schumaker <anna@kernel.org>
Cc: Kevin Brodsky <Kevin.Brodsky@arm.com>
Cc: Vincenzo Frascino <Vincenzo.Frascino@arm.com>
Cc: Szabolcs Nagy <Szabolcs.Nagy@arm.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: David Laight <David.Laight@ACULAB.com>
Cc: Mark Rutland <Mark.Rutland@arm.com>
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-cifs@vger.kernel.org
Cc: linux-nfs@vger.kernel.org
Cc: linux-morello@op-lists.linaro.org
Signed-off-by: Luca Vizzarro <Luca.Vizzarro@arm.com>
Message-Id: <20230414152459.816046-3-Luca.Vizzarro@arm.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Luca Vizzarro and committed by
Christian Brauner
ed5f17f6 bccb5c39

+24 -24
+1 -1
fs/libfs.c
··· 1269 1269 * All arguments are ignored and it just returns -EINVAL. 1270 1270 */ 1271 1271 int 1272 - simple_nosetlease(struct file *filp, long arg, struct file_lock **flp, 1272 + simple_nosetlease(struct file *filp, int arg, struct file_lock **flp, 1273 1273 void **priv) 1274 1274 { 1275 1275 return -EINVAL;
+10 -10
fs/locks.c
··· 438 438 fl->fl_end = OFFSET_MAX; 439 439 } 440 440 441 - static int assign_type(struct file_lock *fl, long type) 441 + static int assign_type(struct file_lock *fl, int type) 442 442 { 443 443 switch (type) { 444 444 case F_RDLCK: ··· 549 549 /* 550 550 * Initialize a lease, use the default lock manager operations 551 551 */ 552 - static int lease_init(struct file *filp, long type, struct file_lock *fl) 552 + static int lease_init(struct file *filp, int type, struct file_lock *fl) 553 553 { 554 554 if (assign_type(fl, type) != 0) 555 555 return -EINVAL; ··· 567 567 } 568 568 569 569 /* Allocate a file_lock initialised to this type of lease */ 570 - static struct file_lock *lease_alloc(struct file *filp, long type) 570 + static struct file_lock *lease_alloc(struct file *filp, int type) 571 571 { 572 572 struct file_lock *fl = locks_alloc_lock(); 573 573 int error = -ENOMEM; ··· 1666 1666 * conflict with the lease we're trying to set. 1667 1667 */ 1668 1668 static int 1669 - check_conflicting_open(struct file *filp, const long arg, int flags) 1669 + check_conflicting_open(struct file *filp, const int arg, int flags) 1670 1670 { 1671 1671 struct inode *inode = file_inode(filp); 1672 1672 int self_wcount = 0, self_rcount = 0; ··· 1701 1701 } 1702 1702 1703 1703 static int 1704 - generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **priv) 1704 + generic_add_lease(struct file *filp, int arg, struct file_lock **flp, void **priv) 1705 1705 { 1706 1706 struct file_lock *fl, *my_fl = NULL, *lease; 1707 1707 struct inode *inode = file_inode(filp); ··· 1859 1859 * The (input) flp->fl_lmops->lm_break function is required 1860 1860 * by break_lease(). 1861 1861 */ 1862 - int generic_setlease(struct file *filp, long arg, struct file_lock **flp, 1862 + int generic_setlease(struct file *filp, int arg, struct file_lock **flp, 1863 1863 void **priv) 1864 1864 { 1865 1865 struct inode *inode = file_inode(filp); ··· 1906 1906 } 1907 1907 1908 1908 static inline void 1909 - setlease_notifier(long arg, struct file_lock *lease) 1909 + setlease_notifier(int arg, struct file_lock *lease) 1910 1910 { 1911 1911 if (arg != F_UNLCK) 1912 1912 srcu_notifier_call_chain(&lease_notifier_chain, arg, lease); ··· 1942 1942 * may be NULL if the lm_setup operation doesn't require it. 1943 1943 */ 1944 1944 int 1945 - vfs_setlease(struct file *filp, long arg, struct file_lock **lease, void **priv) 1945 + vfs_setlease(struct file *filp, int arg, struct file_lock **lease, void **priv) 1946 1946 { 1947 1947 if (lease) 1948 1948 setlease_notifier(arg, *lease); ··· 1953 1953 } 1954 1954 EXPORT_SYMBOL_GPL(vfs_setlease); 1955 1955 1956 - static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg) 1956 + static int do_fcntl_add_lease(unsigned int fd, struct file *filp, int arg) 1957 1957 { 1958 1958 struct file_lock *fl; 1959 1959 struct fasync_struct *new; ··· 1988 1988 * Note that you also need to call %F_SETSIG to 1989 1989 * receive a signal when the lease is broken. 1990 1990 */ 1991 - int fcntl_setlease(unsigned int fd, struct file *filp, long arg) 1991 + int fcntl_setlease(unsigned int fd, struct file *filp, int arg) 1992 1992 { 1993 1993 if (arg == F_UNLCK) 1994 1994 return vfs_setlease(filp, F_UNLCK, NULL, (void **)&filp);
+1 -1
fs/nfs/nfs4_fs.h
··· 328 328 const nfs4_stateid *open_stateid, 329 329 const nfs4_stateid *deleg_stateid, 330 330 fmode_t fmode); 331 - extern int nfs4_proc_setlease(struct file *file, long arg, 331 + extern int nfs4_proc_setlease(struct file *file, int arg, 332 332 struct file_lock **lease, void **priv); 333 333 extern int nfs4_proc_get_lease_time(struct nfs_client *clp, 334 334 struct nfs_fsinfo *fsinfo);
+1 -1
fs/nfs/nfs4file.c
··· 438 438 } 439 439 #endif /* CONFIG_NFS_V4_2 */ 440 440 441 - static int nfs4_setlease(struct file *file, long arg, struct file_lock **lease, 441 + static int nfs4_setlease(struct file *file, int arg, struct file_lock **lease, 442 442 void **priv) 443 443 { 444 444 return nfs4_proc_setlease(file, arg, lease, priv);
+2 -2
fs/nfs/nfs4proc.c
··· 7573 7573 return generic_setlease(file, F_UNLCK, NULL, priv); 7574 7574 } 7575 7575 7576 - static int nfs4_add_lease(struct file *file, long arg, struct file_lock **lease, 7576 + static int nfs4_add_lease(struct file *file, int arg, struct file_lock **lease, 7577 7577 void **priv) 7578 7578 { 7579 7579 struct inode *inode = file_inode(file); ··· 7591 7591 return -EAGAIN; 7592 7592 } 7593 7593 7594 - int nfs4_proc_setlease(struct file *file, long arg, struct file_lock **lease, 7594 + int nfs4_proc_setlease(struct file *file, int arg, struct file_lock **lease, 7595 7595 void **priv) 7596 7596 { 7597 7597 switch (arg) {
+1 -1
fs/smb/client/cifsfs.c
··· 1077 1077 } 1078 1078 1079 1079 static int 1080 - cifs_setlease(struct file *file, long arg, struct file_lock **lease, void **priv) 1080 + cifs_setlease(struct file *file, int arg, struct file_lock **lease, void **priv) 1081 1081 { 1082 1082 /* 1083 1083 * Note that this is called by vfs setlease with i_lock held to
+6 -6
include/linux/filelock.h
··· 144 144 struct flock64 *); 145 145 #endif 146 146 147 - int fcntl_setlease(unsigned int fd, struct file *filp, long arg); 147 + int fcntl_setlease(unsigned int fd, struct file *filp, int arg); 148 148 int fcntl_getlease(struct file *filp); 149 149 150 150 /* fs/locks.c */ ··· 167 167 int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl); 168 168 int __break_lease(struct inode *inode, unsigned int flags, unsigned int type); 169 169 void lease_get_mtime(struct inode *, struct timespec64 *time); 170 - int generic_setlease(struct file *, long, struct file_lock **, void **priv); 171 - int vfs_setlease(struct file *, long, struct file_lock **, void **); 170 + int generic_setlease(struct file *, int, struct file_lock **, void **priv); 171 + int vfs_setlease(struct file *, int, struct file_lock **, void **); 172 172 int lease_modify(struct file_lock *, int, struct list_head *); 173 173 174 174 struct notifier_block; ··· 213 213 return -EACCES; 214 214 } 215 215 #endif 216 - static inline int fcntl_setlease(unsigned int fd, struct file *filp, long arg) 216 + static inline int fcntl_setlease(unsigned int fd, struct file *filp, int arg) 217 217 { 218 218 return -EINVAL; 219 219 } ··· 306 306 return; 307 307 } 308 308 309 - static inline int generic_setlease(struct file *filp, long arg, 309 + static inline int generic_setlease(struct file *filp, int arg, 310 310 struct file_lock **flp, void **priv) 311 311 { 312 312 return -EINVAL; 313 313 } 314 314 315 - static inline int vfs_setlease(struct file *filp, long arg, 315 + static inline int vfs_setlease(struct file *filp, int arg, 316 316 struct file_lock **lease, void **priv) 317 317 { 318 318 return -EINVAL;
+2 -2
include/linux/fs.h
··· 1799 1799 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int); 1800 1800 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int); 1801 1801 void (*splice_eof)(struct file *file); 1802 - int (*setlease)(struct file *, long, struct file_lock **, void **); 1802 + int (*setlease)(struct file *, int, struct file_lock **, void **); 1803 1803 long (*fallocate)(struct file *file, int mode, loff_t offset, 1804 1804 loff_t len); 1805 1805 void (*show_fdinfo)(struct seq_file *m, struct file *f); ··· 2950 2950 extern const struct address_space_operations ram_aops; 2951 2951 extern int always_delete_dentry(const struct dentry *); 2952 2952 extern struct inode *alloc_anon_inode(struct super_block *); 2953 - extern int simple_nosetlease(struct file *, long, struct file_lock **, void **); 2953 + extern int simple_nosetlease(struct file *, int, struct file_lock **, void **); 2954 2954 extern const struct dentry_operations simple_dentry_operations; 2955 2955 2956 2956 extern struct dentry *simple_lookup(struct inode *, struct dentry *, unsigned int flags);