#include <linux/syscalls.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/sched/task.h>
#include <linux/fs.h>
#include <linux/filelock.h>
#include <linux/file.h>
#include <linux/fdtable.h>
#include <linux/capability.h>
#include <linux/dnotify.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/pipe_fs_i.h>
#include <linux/security.h>
#include <linux/ptrace.h>
#include <linux/signal.h>
#include <linux/rcupdate.h>
#include <linux/pid_namespace.h>
#include <linux/user_namespace.h>
#include <linux/memfd.h>
#include <linux/compat.h>
#include <linux/mount.h>
#include <linux/rw_hint.h>
#include <linux/poll.h>
#include <asm/siginfo.h>
#include <linux/uaccess.h>
#define SETFL_MASK …
static int setfl(int fd, struct file * filp, unsigned int arg)
{ … }
static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
int force)
{ … }
void __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
int force)
{ … }
EXPORT_SYMBOL(…);
int f_setown(struct file *filp, int who, int force)
{ … }
EXPORT_SYMBOL(…);
void f_delown(struct file *filp)
{ … }
pid_t f_getown(struct file *filp)
{ … }
static int f_setown_ex(struct file *filp, unsigned long arg)
{ … }
static int f_getown_ex(struct file *filp, unsigned long arg)
{ … }
#ifdef CONFIG_CHECKPOINT_RESTORE
static int f_getowner_uids(struct file *filp, unsigned long arg)
{ … }
#else
static int f_getowner_uids(struct file *filp, unsigned long arg)
{
return -EINVAL;
}
#endif
static bool rw_hint_valid(u64 hint)
{ … }
static long fcntl_get_rw_hint(struct file *file, unsigned int cmd,
unsigned long arg)
{ … }
static long fcntl_set_rw_hint(struct file *file, unsigned int cmd,
unsigned long arg)
{ … }
static long f_dupfd_query(int fd, struct file *filp)
{ … }
static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
struct file *filp)
{ … }
static int check_fcntl_cmd(unsigned cmd)
{ … }
SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
{ … }
#if BITS_PER_LONG == 32
SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
unsigned long, arg)
{
void __user *argp = (void __user *)arg;
struct fd f = fdget_raw(fd);
struct flock64 flock;
long err = -EBADF;
if (!f.file)
goto out;
if (unlikely(f.file->f_mode & FMODE_PATH)) {
if (!check_fcntl_cmd(cmd))
goto out1;
}
err = security_file_fcntl(f.file, cmd, arg);
if (err)
goto out1;
switch (cmd) {
case F_GETLK64:
case F_OFD_GETLK:
err = -EFAULT;
if (copy_from_user(&flock, argp, sizeof(flock)))
break;
err = fcntl_getlk64(f.file, cmd, &flock);
if (!err && copy_to_user(argp, &flock, sizeof(flock)))
err = -EFAULT;
break;
case F_SETLK64:
case F_SETLKW64:
case F_OFD_SETLK:
case F_OFD_SETLKW:
err = -EFAULT;
if (copy_from_user(&flock, argp, sizeof(flock)))
break;
err = fcntl_setlk64(fd, f.file, cmd, &flock);
break;
default:
err = do_fcntl(fd, cmd, arg, f.file);
break;
}
out1:
fdput(f);
out:
return err;
}
#endif
#ifdef CONFIG_COMPAT
#define copy_flock_fields …
static int get_compat_flock(struct flock *kfl, const struct compat_flock __user *ufl)
{ … }
static int get_compat_flock64(struct flock *kfl, const struct compat_flock64 __user *ufl)
{ … }
static int put_compat_flock(const struct flock *kfl, struct compat_flock __user *ufl)
{ … }
static int put_compat_flock64(const struct flock *kfl, struct compat_flock64 __user *ufl)
{ … }
#undef copy_flock_fields
static unsigned int
convert_fcntl_cmd(unsigned int cmd)
{ … }
static int fixup_compat_flock(struct flock *flock)
{ … }
static long do_compat_fcntl64(unsigned int fd, unsigned int cmd,
compat_ulong_t arg)
{ … }
COMPAT_SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
compat_ulong_t, arg)
{ … }
COMPAT_SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd,
compat_ulong_t, arg)
{ … }
#endif
static const __poll_t band_table[NSIGPOLL] = …;
static inline int sigio_perm(struct task_struct *p,
struct fown_struct *fown, int sig)
{ … }
static void send_sigio_to_task(struct task_struct *p,
struct fown_struct *fown,
int fd, int reason, enum pid_type type)
{ … }
void send_sigio(struct fown_struct *fown, int fd, int band)
{ … }
static void send_sigurg_to_task(struct task_struct *p,
struct fown_struct *fown, enum pid_type type)
{ … }
int send_sigurg(struct fown_struct *fown)
{ … }
static DEFINE_SPINLOCK(fasync_lock);
static struct kmem_cache *fasync_cache __ro_after_init;
int fasync_remove_entry(struct file *filp, struct fasync_struct **fapp)
{ … }
struct fasync_struct *fasync_alloc(void)
{ … }
void fasync_free(struct fasync_struct *new)
{ … }
struct fasync_struct *fasync_insert_entry(int fd, struct file *filp, struct fasync_struct **fapp, struct fasync_struct *new)
{ … }
static int fasync_add_entry(int fd, struct file *filp, struct fasync_struct **fapp)
{ … }
int fasync_helper(int fd, struct file * filp, int on, struct fasync_struct **fapp)
{ … }
EXPORT_SYMBOL(…);
static void kill_fasync_rcu(struct fasync_struct *fa, int sig, int band)
{ … }
void kill_fasync(struct fasync_struct **fp, int sig, int band)
{ … }
EXPORT_SYMBOL(…);
static int __init fcntl_init(void)
{ … }
module_init(…) …