Skip to content

Commit

Permalink
memfd: pass argument of memfd_fcntl as int
Browse files Browse the repository at this point in the history
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.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Luca Vizzarro <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: Christian Brauner <[email protected]>
Cc: Jeff Layton <[email protected]>
Cc: Chuck Lever <[email protected]>
Cc: Kevin Brodsky <[email protected]>
Cc: Vincenzo Frascino <[email protected]>
Cc: Szabolcs Nagy <[email protected]>
Cc: "Theodore Ts'o" <[email protected]>
Cc: David Laight <[email protected]>
Cc: Mark Rutland <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
Sevenarth authored and akpm00 committed Apr 18, 2023
1 parent 7f63cf2 commit f7b8f70
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 2 additions & 2 deletions include/linux/memfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <linux/file.h>

#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 long a)
static inline long memfd_fcntl(struct file *f, unsigned int c, unsigned int a)
{
return -EINVAL;
}
Expand Down
6 changes: 1 addition & 5 deletions mm/memfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,12 @@ static int memfd_get_seals(struct file *file)
return seals ? *seals : -EINVAL;
}

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;

switch (cmd) {
case F_ADD_SEALS:
/* disallow upper 32bit */
if (arg > UINT_MAX)
return -EINVAL;

error = memfd_add_seals(file, arg);
break;
case F_GET_SEALS:
Expand Down

0 comments on commit f7b8f70

Please sign in to comment.