From nobody Thu Dec 18 07:54:00 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 364C5C77B6E for ; Fri, 14 Apr 2023 15:26:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230263AbjDNP0d (ORCPT ); Fri, 14 Apr 2023 11:26:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbjDNP0b (ORCPT ); Fri, 14 Apr 2023 11:26:31 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5A3BCD312; Fri, 14 Apr 2023 08:26:03 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9D5C44B3; Fri, 14 Apr 2023 08:25:58 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 52EE23F6C4; Fri, 14 Apr 2023 08:25:12 -0700 (PDT) From: Luca Vizzarro To: linux-kernel@vger.kernel.org Cc: Luca Vizzarro , Alexander Viro , Christian Brauner , Jeff Layton , Chuck Lever , Kevin Brodsky , Vincenzo Frascino , Szabolcs Nagy , "Theodore Ts'o" , David Laight , Mark Rutland , linux-fsdevel@vger.kernel.org, linux-morello@op-lists.linaro.org Subject: [PATCH v2 1/5] fcntl: Cast commands with int args explicitly Date: Fri, 14 Apr 2023 16:24:55 +0100 Message-Id: <20230414152459.816046-2-Luca.Vizzarro@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230414152459.816046-1-Luca.Vizzarro@arm.com> References: <20230414152459.816046-1-Luca.Vizzarro@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" According to the fcntl API specification commands that expect an integer, hence not a pointer, always take an int and not long. In order to avoid access to undefined bits, we should explicitly cast the argument to int. Cc: Alexander Viro Cc: Christian Brauner Cc: Jeff Layton Cc: Chuck Lever Cc: Kevin Brodsky Cc: Vincenzo Frascino Cc: Szabolcs Nagy Cc: "Theodore Ts'o" Cc: David Laight Cc: Mark Rutland Cc: linux-fsdevel@vger.kernel.org Cc: linux-morello@op-lists.linaro.org Signed-off-by: Luca Vizzarro --- fs/fcntl.c | 29 +++++++++++++++-------------- include/linux/fs.h | 2 +- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/fs/fcntl.c b/fs/fcntl.c index b622be119706..e871009f6c88 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -34,7 +34,7 @@ =20 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIM= E) =20 -static int setfl(int fd, struct file * filp, unsigned long arg) +static int setfl(int fd, struct file * filp, unsigned int arg) { struct inode * inode =3D file_inode(filp); int error =3D 0; @@ -112,11 +112,11 @@ void __f_setown(struct file *filp, struct pid *pid, e= num pid_type type, } EXPORT_SYMBOL(__f_setown); =20 -int f_setown(struct file *filp, unsigned long arg, int force) +int f_setown(struct file *filp, int who, int force) { enum pid_type type; struct pid *pid =3D NULL; - int who =3D arg, ret =3D 0; + int ret =3D 0; =20 type =3D PIDTYPE_TGID; if (who < 0) { @@ -317,28 +317,29 @@ static long do_fcntl(int fd, unsigned int cmd, unsign= ed long arg, struct file *filp) { void __user *argp =3D (void __user *)arg; + int argi =3D (int)arg; struct flock flock; long err =3D -EINVAL; =20 switch (cmd) { case F_DUPFD: - err =3D f_dupfd(arg, filp, 0); + err =3D f_dupfd(argi, filp, 0); break; case F_DUPFD_CLOEXEC: - err =3D f_dupfd(arg, filp, O_CLOEXEC); + err =3D f_dupfd(argi, filp, O_CLOEXEC); break; case F_GETFD: err =3D get_close_on_exec(fd) ? FD_CLOEXEC : 0; break; case F_SETFD: err =3D 0; - set_close_on_exec(fd, arg & FD_CLOEXEC); + set_close_on_exec(fd, argi & FD_CLOEXEC); break; case F_GETFL: err =3D filp->f_flags; break; case F_SETFL: - err =3D setfl(fd, filp, arg); + err =3D setfl(fd, filp, argi); break; #if BITS_PER_LONG !=3D 32 /* 32-bit arches must use fcntl64() */ @@ -375,7 +376,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned= long arg, force_successful_syscall_return(); break; case F_SETOWN: - err =3D f_setown(filp, arg, 1); + err =3D f_setown(filp, argi, 1); break; case F_GETOWN_EX: err =3D f_getown_ex(filp, arg); @@ -391,28 +392,28 @@ static long do_fcntl(int fd, unsigned int cmd, unsign= ed long arg, break; case F_SETSIG: /* arg =3D=3D 0 restores default behaviour. */ - if (!valid_signal(arg)) { + if (!valid_signal(argi)) { break; } err =3D 0; - filp->f_owner.signum =3D arg; + filp->f_owner.signum =3D argi; break; case F_GETLEASE: err =3D fcntl_getlease(filp); break; case F_SETLEASE: - err =3D fcntl_setlease(fd, filp, arg); + err =3D fcntl_setlease(fd, filp, argi); break; case F_NOTIFY: - err =3D fcntl_dirnotify(fd, filp, arg); + err =3D fcntl_dirnotify(fd, filp, argi); break; case F_SETPIPE_SZ: case F_GETPIPE_SZ: - err =3D pipe_fcntl(filp, cmd, arg); + err =3D pipe_fcntl(filp, cmd, argi); break; case F_ADD_SEALS: case F_GET_SEALS: - err =3D memfd_fcntl(filp, cmd, arg); + err =3D memfd_fcntl(filp, cmd, argi); break; case F_GET_RW_HINT: case F_SET_RW_HINT: diff --git a/include/linux/fs.h b/include/linux/fs.h index c85916e9f7db..8da79822dbba 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1050,7 +1050,7 @@ extern void fasync_free(struct fasync_struct *); extern void kill_fasync(struct fasync_struct **, int, int); =20 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int= force); -extern int f_setown(struct file *filp, unsigned long arg, int force); +extern int f_setown(struct file *filp, int who, int force); extern void f_delown(struct file *filp); extern pid_t f_getown(struct file *filp); extern int send_sigurg(struct fown_struct *fown); --=20 2.34.1 From nobody Thu Dec 18 07:54:00 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BF21C77B7A for ; Fri, 14 Apr 2023 15:26:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231315AbjDNP0w (ORCPT ); Fri, 14 Apr 2023 11:26:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230365AbjDNP0i (ORCPT ); Fri, 14 Apr 2023 11:26:38 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DEFDCD323; Fri, 14 Apr 2023 08:26:06 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 283E5152B; Fri, 14 Apr 2023 08:26:01 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5D5CF3F6C4; Fri, 14 Apr 2023 08:25:14 -0700 (PDT) From: Luca Vizzarro To: linux-kernel@vger.kernel.org Cc: Luca Vizzarro , Alexander Viro , Christian Brauner , Jeff Layton , Chuck Lever , Trond Myklebust , Anna Schumaker , Kevin Brodsky , Vincenzo Frascino , Szabolcs Nagy , "Theodore Ts'o" , David Laight , Mark Rutland , linux-fsdevel@vger.kernel.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-morello@op-lists.linaro.org Subject: [PATCH v2 2/5] fs: Pass argument to fcntl_setlease as int Date: Fri, 14 Apr 2023 16:24:56 +0100 Message-Id: <20230414152459.816046-3-Luca.Vizzarro@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230414152459.816046-1-Luca.Vizzarro@arm.com> References: <20230414152459.816046-1-Luca.Vizzarro@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Cc: Christian Brauner Cc: Jeff Layton Cc: Chuck Lever Cc: Trond Myklebust Cc: Anna Schumaker Cc: Kevin Brodsky Cc: Vincenzo Frascino Cc: Szabolcs Nagy Cc: "Theodore Ts'o" Cc: David Laight Cc: Mark Rutland 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 --- fs/cifs/cifsfs.c | 2 +- fs/libfs.c | 2 +- fs/locks.c | 20 ++++++++++---------- fs/nfs/nfs4_fs.h | 2 +- fs/nfs/nfs4file.c | 2 +- fs/nfs/nfs4proc.c | 4 ++-- include/linux/filelock.h | 12 ++++++------ include/linux/fs.h | 4 ++-- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index ac9034fce409..ad5b2cfe8320 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -1069,7 +1069,7 @@ static loff_t cifs_llseek(struct file *file, loff_t o= ffset, int whence) } =20 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 diff --git a/fs/libfs.c b/fs/libfs.c index 4eda519c3002..1c451e76560c 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1274,7 +1274,7 @@ EXPORT_SYMBOL(alloc_anon_inode); * All arguments are ignored and it just returns -EINVAL. */ 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) { return -EINVAL; diff --git a/fs/locks.c b/fs/locks.c index df8b26a42524..265b5190db3e 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -438,7 +438,7 @@ static void flock_make_lock(struct file *filp, struct f= ile_lock *fl, int type) fl->fl_end =3D OFFSET_MAX; } =20 -static int assign_type(struct file_lock *fl, long type) +static int assign_type(struct file_lock *fl, int type) { switch (type) { case F_RDLCK: @@ -549,7 +549,7 @@ static const struct lock_manager_operations lease_manag= er_ops =3D { /* * 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) !=3D 0) return -EINVAL; @@ -567,7 +567,7 @@ static int lease_init(struct file *filp, long type, str= uct file_lock *fl) } =20 /* 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 =3D locks_alloc_lock(); int error =3D -ENOMEM; @@ -1666,7 +1666,7 @@ int fcntl_getlease(struct file *filp) * conflict with the lease we're trying to set. */ 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 =3D file_inode(filp); int self_wcount =3D 0, self_rcount =3D 0; @@ -1701,7 +1701,7 @@ check_conflicting_open(struct file *filp, const long = arg, int flags) } =20 static int -generic_add_lease(struct file *filp, long arg, struct file_lock **flp, voi= d **priv) +generic_add_lease(struct file *filp, int arg, struct file_lock **flp, void= **priv) { struct file_lock *fl, *my_fl =3D NULL, *lease; struct inode *inode =3D file_inode(filp); @@ -1859,7 +1859,7 @@ static int generic_delete_lease(struct file *filp, vo= id *owner) * The (input) flp->fl_lmops->lm_break function is required * 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) { struct inode *inode =3D file_inode(filp); @@ -1906,7 +1906,7 @@ lease_notifier_chain_init(void) } =20 static inline void -setlease_notifier(long arg, struct file_lock *lease) +setlease_notifier(int arg, struct file_lock *lease) { if (arg !=3D F_UNLCK) srcu_notifier_call_chain(&lease_notifier_chain, arg, lease); @@ -1942,7 +1942,7 @@ EXPORT_SYMBOL_GPL(lease_unregister_notifier); * may be NULL if the lm_setup operation doesn't require it. */ 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) setlease_notifier(arg, *lease); @@ -1953,7 +1953,7 @@ vfs_setlease(struct file *filp, long arg, struct file= _lock **lease, void **priv) } EXPORT_SYMBOL_GPL(vfs_setlease); =20 -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 fasync_struct *new; @@ -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 * 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 =3D=3D F_UNLCK) return vfs_setlease(filp, F_UNLCK, NULL, (void **)&filp); diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h index 4c9f8bd866ab..47c5c1f86d66 100644 --- a/fs/nfs/nfs4_fs.h +++ b/fs/nfs/nfs4_fs.h @@ -328,7 +328,7 @@ extern int update_open_stateid(struct nfs4_state *state, const nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, 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); extern int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo); diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index 2563ed8580f3..26c2d3539d75 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -438,7 +438,7 @@ void nfs42_ssc_unregister_ops(void) } #endif /* CONFIG_NFS_V4_2 */ =20 -static int nfs4_setlease(struct file *file, long arg, struct file_lock **l= ease, +static int nfs4_setlease(struct file *file, int arg, struct file_lock **le= ase, void **priv) { return nfs4_proc_setlease(file, arg, lease, priv); diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 5607b1e2b821..ba59ad558209 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -7559,7 +7559,7 @@ static int nfs4_delete_lease(struct file *file, void = **priv) return generic_setlease(file, F_UNLCK, NULL, priv); } =20 -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 **l= ease, void **priv) { struct inode *inode =3D file_inode(file); @@ -7577,7 +7577,7 @@ static int nfs4_add_lease(struct file *file, long arg= , struct file_lock **lease, return -EAGAIN; } =20 -int nfs4_proc_setlease(struct file *file, long arg, struct file_lock **lea= se, +int nfs4_proc_setlease(struct file *file, int arg, struct file_lock **leas= e, void **priv) { switch (arg) { diff --git a/include/linux/filelock.h b/include/linux/filelock.h index efcdd1631d9b..95e868e09e29 100644 --- a/include/linux/filelock.h +++ b/include/linux/filelock.h @@ -144,7 +144,7 @@ int fcntl_setlk64(unsigned int, struct file *, unsigned= int, struct flock64 *); #endif =20 -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); =20 /* fs/locks.c */ @@ -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 __break_lease(struct inode *inode, unsigned int flags, unsigned int ty= pe); void lease_get_mtime(struct inode *, struct timespec64 *time); -int generic_setlease(struct file *, long, struct file_lock **, void **priv= ); -int vfs_setlease(struct file *, long, struct file_lock **, void **); +int generic_setlease(struct file *, int, struct file_lock **, void **priv); +int vfs_setlease(struct file *, int, struct file_lock **, void **); int lease_modify(struct file_lock *, int, struct list_head *); =20 struct notifier_block; @@ -213,7 +213,7 @@ static inline int fcntl_setlk64(unsigned int fd, struct= file *file, return -EACCES; } #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 a= rg) { return -EINVAL; } @@ -306,13 +306,13 @@ static inline void lease_get_mtime(struct inode *inod= e, return; } =20 -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) { return -EINVAL; } =20 -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) { return -EINVAL; diff --git a/include/linux/fs.h b/include/linux/fs.h index 8da79822dbba..0c9367980636 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1779,7 +1779,7 @@ struct file_operations { int (*flock) (struct file *, int, struct file_lock *); 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); - 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, loff_t len); void (*show_fdinfo)(struct seq_file *m, struct file *f); @@ -2914,7 +2914,7 @@ extern int simple_write_begin(struct file *file, stru= ct address_space *mapping, extern const struct address_space_operations ram_aops; extern int always_delete_dentry(const struct dentry *); extern struct inode *alloc_anon_inode(struct super_block *); -extern int simple_nosetlease(struct file *, long, struct file_lock **, voi= d **); +extern int simple_nosetlease(struct file *, int, struct file_lock **, void= **); extern const struct dentry_operations simple_dentry_operations; =20 extern struct dentry *simple_lookup(struct inode *, struct dentry *, unsig= ned int flags); --=20 2.34.1 From nobody Thu Dec 18 07:54:00 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD86BC77B6E for ; Fri, 14 Apr 2023 15:26:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230247AbjDNP0z (ORCPT ); Fri, 14 Apr 2023 11:26:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230392AbjDNP0l (ORCPT ); Fri, 14 Apr 2023 11:26:41 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ACF75D338; Fri, 14 Apr 2023 08:26:07 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2F0001713; Fri, 14 Apr 2023 08:26:03 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DAC573F6C4; Fri, 14 Apr 2023 08:25:16 -0700 (PDT) From: Luca Vizzarro To: linux-kernel@vger.kernel.org Cc: Luca Vizzarro , Alexander Viro , Christian Brauner , Jeff Layton , Chuck Lever , Kevin Brodsky , Vincenzo Frascino , Szabolcs Nagy , "Theodore Ts'o" , David Laight , Mark Rutland , linux-fsdevel@vger.kernel.org, linux-morello@op-lists.linaro.org Subject: [PATCH v2 3/5] pipe: Pass argument of pipe_fcntl as int Date: Fri, 14 Apr 2023 16:24:57 +0100 Message-Id: <20230414152459.816046-4-Luca.Vizzarro@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230414152459.816046-1-Luca.Vizzarro@arm.com> References: <20230414152459.816046-1-Luca.Vizzarro@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The interface for fcntl expects the argument passed for the command F_SETPIPE_SZ 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 Cc: Christian Brauner Cc: Jeff Layton Cc: Chuck Lever Cc: Kevin Brodsky Cc: Vincenzo Frascino Cc: Szabolcs Nagy Cc: "Theodore Ts'o" Cc: David Laight Cc: Mark Rutland Cc: linux-fsdevel@vger.kernel.org Cc: linux-morello@op-lists.linaro.org Signed-off-by: Luca Vizzarro --- fs/pipe.c | 6 +++--- include/linux/pipe_fs_i.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/pipe.c b/fs/pipe.c index 42c7ff41c2db..5b718342105f 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -1231,7 +1231,7 @@ const struct file_operations pipefifo_fops =3D { * Currently we rely on the pipe array holding a power-of-2 number * of pages. Returns 0 on error. */ -unsigned int round_pipe_size(unsigned long size) +unsigned int round_pipe_size(unsigned int size) { if (size > (1U << 31)) return 0; @@ -1314,7 +1314,7 @@ int pipe_resize_ring(struct pipe_inode_info *pipe, un= signed int nr_slots) * Allocate a new array of pipe buffers and copy the info over. Returns the * pipe size if successful, or return -ERROR on error. */ -static long pipe_set_size(struct pipe_inode_info *pipe, unsigned long arg) +static long pipe_set_size(struct pipe_inode_info *pipe, unsigned int arg) { unsigned long user_bufs; unsigned int nr_slots, size; @@ -1382,7 +1382,7 @@ struct pipe_inode_info *get_pipe_info(struct file *fi= le, bool for_splice) return pipe; } =20 -long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg) +long pipe_fcntl(struct file *file, unsigned int cmd, unsigned int arg) { struct pipe_inode_info *pipe; long ret; diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h index d2c3f16cf6b1..033d77f0c568 100644 --- a/include/linux/pipe_fs_i.h +++ b/include/linux/pipe_fs_i.h @@ -273,10 +273,10 @@ bool pipe_is_unprivileged_user(void); #ifdef CONFIG_WATCH_QUEUE int pipe_resize_ring(struct pipe_inode_info *pipe, unsigned int nr_slots); #endif -long pipe_fcntl(struct file *, unsigned int, unsigned long arg); +long pipe_fcntl(struct file *, unsigned int, unsigned int arg); struct pipe_inode_info *get_pipe_info(struct file *file, bool for_splice); =20 int create_pipe_files(struct file **, int); -unsigned int round_pipe_size(unsigned long size); +unsigned int round_pipe_size(unsigned int size); =20 #endif --=20 2.34.1 From nobody Thu Dec 18 07:54:00 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4BCBC77B72 for ; Fri, 14 Apr 2023 15:26:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231329AbjDNP05 (ORCPT ); Fri, 14 Apr 2023 11:26:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229932AbjDNP0m (ORCPT ); Fri, 14 Apr 2023 11:26:42 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 68D7BCC26; Fri, 14 Apr 2023 08:26:10 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6F7DD1756; Fri, 14 Apr 2023 08:26:05 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E1DE73F6C4; Fri, 14 Apr 2023 08:25:18 -0700 (PDT) From: Luca Vizzarro To: linux-kernel@vger.kernel.org Cc: Luca Vizzarro , Andrew Morton , Alexander Viro , Christian Brauner , Jeff Layton , Chuck Lever , Kevin Brodsky , Vincenzo Frascino , Szabolcs Nagy , "Theodore Ts'o" , David Laight , Mark Rutland , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-morello@op-lists.linaro.org Subject: [PATCH v2 4/5] memfd: Pass argument of memfd_fcntl as int Date: Fri, 14 Apr 2023 16:24:58 +0100 Message-Id: <20230414152459.816046-5-Luca.Vizzarro@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230414152459.816046-1-Luca.Vizzarro@arm.com> References: <20230414152459.816046-1-Luca.Vizzarro@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The interface for fcntl expects the argument passed for the command F_ADD_SEALS 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. This commit changes the signature of all the related and helper functions so that they treat the argument as int instead of long. Cc: Andrew Morton Cc: Alexander Viro Cc: Christian Brauner Cc: Jeff Layton Cc: Chuck Lever Cc: Kevin Brodsky Cc: Vincenzo Frascino Cc: Szabolcs Nagy Cc: "Theodore Ts'o" Cc: David Laight Cc: Mark Rutland Cc: linux-fsdevel@vger.kernel.org Cc: linux-mm@kvack.org Cc: linux-morello@op-lists.linaro.org Signed-off-by: Luca Vizzarro --- include/linux/memfd.h | 4 ++-- mm/memfd.c | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/include/linux/memfd.h b/include/linux/memfd.h index 4f1600413f91..e7abf6fa4c52 100644 --- a/include/linux/memfd.h +++ b/include/linux/memfd.h @@ -5,9 +5,9 @@ #include =20 #ifdef CONFIG_MEMFD_CREATE -extern long memfd_fcntl(struct file *file, unsigned int cmd, unsigned long= arg); +extern long memfd_fcntl(struct file *file, unsigned int cmd, unsigned int = arg); #else -static inline long memfd_fcntl(struct file *f, unsigned int c, unsigned lo= ng a) +static inline long memfd_fcntl(struct file *f, unsigned int c, unsigned in= t a) { return -EINVAL; } diff --git a/mm/memfd.c b/mm/memfd.c index a0a7a37e8177..69b90c31d38c 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -243,16 +243,12 @@ static int memfd_get_seals(struct file *file) return seals ? *seals : -EINVAL; } =20 -long memfd_fcntl(struct file *file, unsigned int cmd, unsigned long arg) +long memfd_fcntl(struct file *file, unsigned int cmd, unsigned int arg) { long error; =20 switch (cmd) { case F_ADD_SEALS: - /* disallow upper 32bit */ - if (arg > UINT_MAX) - return -EINVAL; - error =3D memfd_add_seals(file, arg); break; case F_GET_SEALS: --=20 2.34.1 From nobody Thu Dec 18 07:54:00 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34C1DC77B6E for ; Fri, 14 Apr 2023 15:27:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231287AbjDNP1T (ORCPT ); Fri, 14 Apr 2023 11:27:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231236AbjDNP1D (ORCPT ); Fri, 14 Apr 2023 11:27:03 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F0073CC39; Fri, 14 Apr 2023 08:26:32 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B11A41758; Fri, 14 Apr 2023 08:26:07 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2F1813F6C4; Fri, 14 Apr 2023 08:25:21 -0700 (PDT) From: Luca Vizzarro To: linux-kernel@vger.kernel.org Cc: Luca Vizzarro , Jan Kara , Amir Goldstein , Alexander Viro , Christian Brauner , Jeff Layton , Chuck Lever , Kevin Brodsky , Vincenzo Frascino , Szabolcs Nagy , "Theodore Ts'o" , David Laight , Mark Rutland , linux-fsdevel@vger.kernel.org, linux-morello@op-lists.linaro.org Subject: [PATCH v2 5/5] dnotify: Pass argument of fcntl_dirnotify as int Date: Fri, 14 Apr 2023 16:24:59 +0100 Message-Id: <20230414152459.816046-6-Luca.Vizzarro@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230414152459.816046-1-Luca.Vizzarro@arm.com> References: <20230414152459.816046-1-Luca.Vizzarro@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The interface for fcntl expects the argument passed for the command F_DIRNOTIFY 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: Jan Kara Cc: Amir Goldstein Cc: Alexander Viro Cc: Christian Brauner Cc: Jeff Layton Cc: Chuck Lever Cc: Kevin Brodsky Cc: Vincenzo Frascino Cc: Szabolcs Nagy Cc: "Theodore Ts'o" Cc: David Laight Cc: Mark Rutland Cc: linux-fsdevel@vger.kernel.org Cc: linux-morello@op-lists.linaro.org Acked-by: Jan Kara Signed-off-by: Luca Vizzarro --- fs/notify/dnotify/dnotify.c | 4 ++-- include/linux/dnotify.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c index 190aa717fa32..ebdcc25df0f7 100644 --- a/fs/notify/dnotify/dnotify.c +++ b/fs/notify/dnotify/dnotify.c @@ -199,7 +199,7 @@ void dnotify_flush(struct file *filp, fl_owner_t id) } =20 /* this conversion is done only at watch creation */ -static __u32 convert_arg(unsigned long arg) +static __u32 convert_arg(unsigned int arg) { __u32 new_mask =3D FS_EVENT_ON_CHILD; =20 @@ -258,7 +258,7 @@ static int attach_dn(struct dnotify_struct *dn, struct = dnotify_mark *dn_mark, * up here. Allocate both a mark for fsnotify to add and a dnotify_struct= to be * attached to the fsnotify_mark. */ -int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg) +int fcntl_dirnotify(int fd, struct file *filp, unsigned int arg) { struct dnotify_mark *new_dn_mark, *dn_mark; struct fsnotify_mark *new_fsn_mark, *fsn_mark; diff --git a/include/linux/dnotify.h b/include/linux/dnotify.h index b1d26f9f1c9f..9f183a679277 100644 --- a/include/linux/dnotify.h +++ b/include/linux/dnotify.h @@ -30,7 +30,7 @@ struct dnotify_struct { FS_MOVED_FROM | FS_MOVED_TO) =20 extern void dnotify_flush(struct file *, fl_owner_t); -extern int fcntl_dirnotify(int, struct file *, unsigned long); +extern int fcntl_dirnotify(int, struct file *, unsigned int); =20 #else =20 @@ -38,7 +38,7 @@ static inline void dnotify_flush(struct file *filp, fl_ow= ner_t id) { } =20 -static inline int fcntl_dirnotify(int fd, struct file *filp, unsigned long= arg) +static inline int fcntl_dirnotify(int fd, struct file *filp, unsigned int = arg) { return -EINVAL; } --=20 2.34.1