Commit ed5f17f6 authored by Luca Vizzarro's avatar Luca Vizzarro Committed by Christian Brauner

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: default avatarLuca Vizzarro <Luca.Vizzarro@arm.com>
Message-Id: <20230414152459.816046-3-Luca.Vizzarro@arm.com>
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent bccb5c39
...@@ -1269,7 +1269,7 @@ EXPORT_SYMBOL(alloc_anon_inode); ...@@ -1269,7 +1269,7 @@ EXPORT_SYMBOL(alloc_anon_inode);
* All arguments are ignored and it just returns -EINVAL. * All arguments are ignored and it just returns -EINVAL.
*/ */
int int
simple_nosetlease(struct file *filp, long arg, struct file_lock **flp, simple_nosetlease(struct file *filp, int arg, struct file_lock **flp,
void **priv) void **priv)
{ {
return -EINVAL; return -EINVAL;
......
...@@ -438,7 +438,7 @@ static void flock_make_lock(struct file *filp, struct file_lock *fl, int type) ...@@ -438,7 +438,7 @@ static void flock_make_lock(struct file *filp, struct file_lock *fl, int type)
fl->fl_end = OFFSET_MAX; fl->fl_end = OFFSET_MAX;
} }
static int assign_type(struct file_lock *fl, long type) static int assign_type(struct file_lock *fl, int type)
{ {
switch (type) { switch (type) {
case F_RDLCK: case F_RDLCK:
...@@ -549,7 +549,7 @@ static const struct lock_manager_operations lease_manager_ops = { ...@@ -549,7 +549,7 @@ static const struct lock_manager_operations lease_manager_ops = {
/* /*
* Initialize a lease, use the default lock manager operations * Initialize a lease, use the default lock manager operations
*/ */
static int lease_init(struct file *filp, long type, struct file_lock *fl) static int lease_init(struct file *filp, int type, struct file_lock *fl)
{ {
if (assign_type(fl, type) != 0) if (assign_type(fl, type) != 0)
return -EINVAL; return -EINVAL;
...@@ -567,7 +567,7 @@ static int lease_init(struct file *filp, long type, struct file_lock *fl) ...@@ -567,7 +567,7 @@ static int lease_init(struct file *filp, long type, struct file_lock *fl)
} }
/* Allocate a file_lock initialised to this type of lease */ /* Allocate a file_lock initialised to this type of lease */
static struct file_lock *lease_alloc(struct file *filp, long type) static struct file_lock *lease_alloc(struct file *filp, int type)
{ {
struct file_lock *fl = locks_alloc_lock(); struct file_lock *fl = locks_alloc_lock();
int error = -ENOMEM; int error = -ENOMEM;
...@@ -1666,7 +1666,7 @@ int fcntl_getlease(struct file *filp) ...@@ -1666,7 +1666,7 @@ int fcntl_getlease(struct file *filp)
* conflict with the lease we're trying to set. * conflict with the lease we're trying to set.
*/ */
static int static int
check_conflicting_open(struct file *filp, const long arg, int flags) check_conflicting_open(struct file *filp, const int arg, int flags)
{ {
struct inode *inode = file_inode(filp); struct inode *inode = file_inode(filp);
int self_wcount = 0, self_rcount = 0; int self_wcount = 0, self_rcount = 0;
...@@ -1701,7 +1701,7 @@ check_conflicting_open(struct file *filp, const long arg, int flags) ...@@ -1701,7 +1701,7 @@ check_conflicting_open(struct file *filp, const long arg, int flags)
} }
static int static int
generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **priv) generic_add_lease(struct file *filp, int arg, struct file_lock **flp, void **priv)
{ {
struct file_lock *fl, *my_fl = NULL, *lease; struct file_lock *fl, *my_fl = NULL, *lease;
struct inode *inode = file_inode(filp); struct inode *inode = file_inode(filp);
...@@ -1859,7 +1859,7 @@ static int generic_delete_lease(struct file *filp, void *owner) ...@@ -1859,7 +1859,7 @@ static int generic_delete_lease(struct file *filp, void *owner)
* The (input) flp->fl_lmops->lm_break function is required * The (input) flp->fl_lmops->lm_break function is required
* by break_lease(). * by break_lease().
*/ */
int generic_setlease(struct file *filp, long arg, struct file_lock **flp, int generic_setlease(struct file *filp, int arg, struct file_lock **flp,
void **priv) void **priv)
{ {
struct inode *inode = file_inode(filp); struct inode *inode = file_inode(filp);
...@@ -1906,7 +1906,7 @@ lease_notifier_chain_init(void) ...@@ -1906,7 +1906,7 @@ lease_notifier_chain_init(void)
} }
static inline void static inline void
setlease_notifier(long arg, struct file_lock *lease) setlease_notifier(int arg, struct file_lock *lease)
{ {
if (arg != F_UNLCK) if (arg != F_UNLCK)
srcu_notifier_call_chain(&lease_notifier_chain, arg, lease); srcu_notifier_call_chain(&lease_notifier_chain, arg, lease);
...@@ -1942,7 +1942,7 @@ EXPORT_SYMBOL_GPL(lease_unregister_notifier); ...@@ -1942,7 +1942,7 @@ EXPORT_SYMBOL_GPL(lease_unregister_notifier);
* may be NULL if the lm_setup operation doesn't require it. * may be NULL if the lm_setup operation doesn't require it.
*/ */
int int
vfs_setlease(struct file *filp, long arg, struct file_lock **lease, void **priv) vfs_setlease(struct file *filp, int arg, struct file_lock **lease, void **priv)
{ {
if (lease) if (lease)
setlease_notifier(arg, *lease); setlease_notifier(arg, *lease);
...@@ -1953,7 +1953,7 @@ vfs_setlease(struct file *filp, long arg, struct file_lock **lease, void **priv) ...@@ -1953,7 +1953,7 @@ vfs_setlease(struct file *filp, long arg, struct file_lock **lease, void **priv)
} }
EXPORT_SYMBOL_GPL(vfs_setlease); EXPORT_SYMBOL_GPL(vfs_setlease);
static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg) static int do_fcntl_add_lease(unsigned int fd, struct file *filp, int arg)
{ {
struct file_lock *fl; struct file_lock *fl;
struct fasync_struct *new; struct fasync_struct *new;
...@@ -1988,7 +1988,7 @@ static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg) ...@@ -1988,7 +1988,7 @@ static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg)
* Note that you also need to call %F_SETSIG to * Note that you also need to call %F_SETSIG to
* receive a signal when the lease is broken. * receive a signal when the lease is broken.
*/ */
int fcntl_setlease(unsigned int fd, struct file *filp, long arg) int fcntl_setlease(unsigned int fd, struct file *filp, int arg)
{ {
if (arg == F_UNLCK) if (arg == F_UNLCK)
return vfs_setlease(filp, F_UNLCK, NULL, (void **)&filp); return vfs_setlease(filp, F_UNLCK, NULL, (void **)&filp);
......
...@@ -328,7 +328,7 @@ extern int update_open_stateid(struct nfs4_state *state, ...@@ -328,7 +328,7 @@ extern int update_open_stateid(struct nfs4_state *state,
const nfs4_stateid *open_stateid, const nfs4_stateid *open_stateid,
const nfs4_stateid *deleg_stateid, const nfs4_stateid *deleg_stateid,
fmode_t fmode); fmode_t fmode);
extern int nfs4_proc_setlease(struct file *file, long arg, extern int nfs4_proc_setlease(struct file *file, int arg,
struct file_lock **lease, void **priv); struct file_lock **lease, void **priv);
extern int nfs4_proc_get_lease_time(struct nfs_client *clp, extern int nfs4_proc_get_lease_time(struct nfs_client *clp,
struct nfs_fsinfo *fsinfo); struct nfs_fsinfo *fsinfo);
......
...@@ -438,7 +438,7 @@ void nfs42_ssc_unregister_ops(void) ...@@ -438,7 +438,7 @@ void nfs42_ssc_unregister_ops(void)
} }
#endif /* CONFIG_NFS_V4_2 */ #endif /* CONFIG_NFS_V4_2 */
static int nfs4_setlease(struct file *file, long arg, struct file_lock **lease, static int nfs4_setlease(struct file *file, int arg, struct file_lock **lease,
void **priv) void **priv)
{ {
return nfs4_proc_setlease(file, arg, lease, priv); return nfs4_proc_setlease(file, arg, lease, priv);
......
...@@ -7573,7 +7573,7 @@ static int nfs4_delete_lease(struct file *file, void **priv) ...@@ -7573,7 +7573,7 @@ static int nfs4_delete_lease(struct file *file, void **priv)
return generic_setlease(file, F_UNLCK, NULL, priv); return generic_setlease(file, F_UNLCK, NULL, priv);
} }
static int nfs4_add_lease(struct file *file, long arg, struct file_lock **lease, static int nfs4_add_lease(struct file *file, int arg, struct file_lock **lease,
void **priv) void **priv)
{ {
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
...@@ -7591,7 +7591,7 @@ static int nfs4_add_lease(struct file *file, long arg, struct file_lock **lease, ...@@ -7591,7 +7591,7 @@ static int nfs4_add_lease(struct file *file, long arg, struct file_lock **lease,
return -EAGAIN; return -EAGAIN;
} }
int nfs4_proc_setlease(struct file *file, long arg, struct file_lock **lease, int nfs4_proc_setlease(struct file *file, int arg, struct file_lock **lease,
void **priv) void **priv)
{ {
switch (arg) { switch (arg) {
......
...@@ -1077,7 +1077,7 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int whence) ...@@ -1077,7 +1077,7 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int whence)
} }
static int static int
cifs_setlease(struct file *file, long arg, struct file_lock **lease, void **priv) cifs_setlease(struct file *file, int arg, struct file_lock **lease, void **priv)
{ {
/* /*
* Note that this is called by vfs setlease with i_lock held to * Note that this is called by vfs setlease with i_lock held to
......
...@@ -144,7 +144,7 @@ int fcntl_setlk64(unsigned int, struct file *, unsigned int, ...@@ -144,7 +144,7 @@ int fcntl_setlk64(unsigned int, struct file *, unsigned int,
struct flock64 *); struct flock64 *);
#endif #endif
int fcntl_setlease(unsigned int fd, struct file *filp, long arg); int fcntl_setlease(unsigned int fd, struct file *filp, int arg);
int fcntl_getlease(struct file *filp); int fcntl_getlease(struct file *filp);
/* fs/locks.c */ /* fs/locks.c */
...@@ -167,8 +167,8 @@ bool vfs_inode_has_locks(struct inode *inode); ...@@ -167,8 +167,8 @@ bool vfs_inode_has_locks(struct inode *inode);
int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl); int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl);
int __break_lease(struct inode *inode, unsigned int flags, unsigned int type); int __break_lease(struct inode *inode, unsigned int flags, unsigned int type);
void lease_get_mtime(struct inode *, struct timespec64 *time); void lease_get_mtime(struct inode *, struct timespec64 *time);
int generic_setlease(struct file *, long, struct file_lock **, void **priv); int generic_setlease(struct file *, int, struct file_lock **, void **priv);
int vfs_setlease(struct file *, long, struct file_lock **, void **); int vfs_setlease(struct file *, int, struct file_lock **, void **);
int lease_modify(struct file_lock *, int, struct list_head *); int lease_modify(struct file_lock *, int, struct list_head *);
struct notifier_block; struct notifier_block;
...@@ -213,7 +213,7 @@ static inline int fcntl_setlk64(unsigned int fd, struct file *file, ...@@ -213,7 +213,7 @@ static inline int fcntl_setlk64(unsigned int fd, struct file *file,
return -EACCES; return -EACCES;
} }
#endif #endif
static inline int fcntl_setlease(unsigned int fd, struct file *filp, long arg) static inline int fcntl_setlease(unsigned int fd, struct file *filp, int arg)
{ {
return -EINVAL; return -EINVAL;
} }
...@@ -306,13 +306,13 @@ static inline void lease_get_mtime(struct inode *inode, ...@@ -306,13 +306,13 @@ static inline void lease_get_mtime(struct inode *inode,
return; return;
} }
static inline int generic_setlease(struct file *filp, long arg, static inline int generic_setlease(struct file *filp, int arg,
struct file_lock **flp, void **priv) struct file_lock **flp, void **priv)
{ {
return -EINVAL; return -EINVAL;
} }
static inline int vfs_setlease(struct file *filp, long arg, static inline int vfs_setlease(struct file *filp, int arg,
struct file_lock **lease, void **priv) struct file_lock **lease, void **priv)
{ {
return -EINVAL; return -EINVAL;
......
...@@ -1799,7 +1799,7 @@ struct file_operations { ...@@ -1799,7 +1799,7 @@ struct file_operations {
ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int); ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int); ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
void (*splice_eof)(struct file *file); void (*splice_eof)(struct file *file);
int (*setlease)(struct file *, long, struct file_lock **, void **); int (*setlease)(struct file *, int, struct file_lock **, void **);
long (*fallocate)(struct file *file, int mode, loff_t offset, long (*fallocate)(struct file *file, int mode, loff_t offset,
loff_t len); loff_t len);
void (*show_fdinfo)(struct seq_file *m, struct file *f); void (*show_fdinfo)(struct seq_file *m, struct file *f);
...@@ -2950,7 +2950,7 @@ extern int simple_write_begin(struct file *file, struct address_space *mapping, ...@@ -2950,7 +2950,7 @@ extern int simple_write_begin(struct file *file, struct address_space *mapping,
extern const struct address_space_operations ram_aops; extern const struct address_space_operations ram_aops;
extern int always_delete_dentry(const struct dentry *); extern int always_delete_dentry(const struct dentry *);
extern struct inode *alloc_anon_inode(struct super_block *); extern struct inode *alloc_anon_inode(struct super_block *);
extern int simple_nosetlease(struct file *, long, struct file_lock **, void **); extern int simple_nosetlease(struct file *, int, struct file_lock **, void **);
extern const struct dentry_operations simple_dentry_operations; extern const struct dentry_operations simple_dentry_operations;
extern struct dentry *simple_lookup(struct inode *, struct dentry *, unsigned int flags); extern struct dentry *simple_lookup(struct inode *, struct dentry *, unsigned int flags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment