Commit 22230cd2 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'compat.mount' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull compat mount cleanups from Al Viro:
 "The last remnants of mount(2) compat buried by Christoph.

  Buried into NFS, that is.

  Generally I'm less enthusiastic about "let's use in_compat_syscall()
  deep in call chain" kind of approach than Christoph seems to be, but
  in this case it's warranted - that had been an NFS-specific wart,
  hopefully not to be repeated in any other filesystems (read: any new
  filesystem introducing non-text mount options will get NAKed even if
  it doesn't mess the layout up).

  IOW, not worth trying to grow an infrastructure that would avoid that
  use of in_compat_syscall()..."

* 'compat.mount' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  fs: remove compat_sys_mount
  fs,nfs: lift compat nfs4 mount data handling into the nfs code
  nfs: simplify nfs4_parse_monolithic
parents e18afa5b 028abd92
...@@ -53,7 +53,7 @@ __SYSCALL(__NR_lseek, compat_sys_lseek) ...@@ -53,7 +53,7 @@ __SYSCALL(__NR_lseek, compat_sys_lseek)
#define __NR_getpid 20 #define __NR_getpid 20
__SYSCALL(__NR_getpid, sys_getpid) __SYSCALL(__NR_getpid, sys_getpid)
#define __NR_mount 21 #define __NR_mount 21
__SYSCALL(__NR_mount, compat_sys_mount) __SYSCALL(__NR_mount, sys_mount)
/* 22 was sys_umount */ /* 22 was sys_umount */
__SYSCALL(22, sys_ni_syscall) __SYSCALL(22, sys_ni_syscall)
#define __NR_setuid 23 #define __NR_setuid 23
......
...@@ -167,7 +167,7 @@ ...@@ -167,7 +167,7 @@
157 n32 sync sys_sync 157 n32 sync sys_sync
158 n32 acct sys_acct 158 n32 acct sys_acct
159 n32 settimeofday compat_sys_settimeofday 159 n32 settimeofday compat_sys_settimeofday
160 n32 mount compat_sys_mount 160 n32 mount sys_mount
161 n32 umount2 sys_umount 161 n32 umount2 sys_umount
162 n32 swapon sys_swapon 162 n32 swapon sys_swapon
163 n32 swapoff sys_swapoff 163 n32 swapoff sys_swapoff
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
18 o32 unused18 sys_ni_syscall 18 o32 unused18 sys_ni_syscall
19 o32 lseek sys_lseek 19 o32 lseek sys_lseek
20 o32 getpid sys_getpid 20 o32 getpid sys_getpid
21 o32 mount sys_mount compat_sys_mount 21 o32 mount sys_mount
22 o32 umount sys_oldumount 22 o32 umount sys_oldumount
23 o32 setuid sys_setuid 23 o32 setuid sys_setuid
24 o32 getuid sys_getuid 24 o32 getuid sys_getuid
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
18 common stat sys_newstat compat_sys_newstat 18 common stat sys_newstat compat_sys_newstat
19 common lseek sys_lseek compat_sys_lseek 19 common lseek sys_lseek compat_sys_lseek
20 common getpid sys_getpid 20 common getpid sys_getpid
21 common mount sys_mount compat_sys_mount 21 common mount sys_mount
22 common bind sys_bind 22 common bind sys_bind
23 common setuid sys_setuid 23 common setuid sys_setuid
24 common getuid sys_getuid 24 common getuid sys_getuid
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
18 spu oldstat sys_ni_syscall 18 spu oldstat sys_ni_syscall
19 common lseek sys_lseek compat_sys_lseek 19 common lseek sys_lseek compat_sys_lseek
20 common getpid sys_getpid 20 common getpid sys_getpid
21 nospu mount sys_mount compat_sys_mount 21 nospu mount sys_mount
22 32 umount sys_oldumount 22 32 umount sys_oldumount
22 64 umount sys_ni_syscall 22 64 umount sys_ni_syscall
22 spu umount sys_ni_syscall 22 spu umount sys_ni_syscall
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
16 32 lchown - sys_lchown16 16 32 lchown - sys_lchown16
19 common lseek sys_lseek compat_sys_lseek 19 common lseek sys_lseek compat_sys_lseek
20 common getpid sys_getpid sys_getpid 20 common getpid sys_getpid sys_getpid
21 common mount sys_mount compat_sys_mount 21 common mount sys_mount sys_mount
22 common umount sys_oldumount sys_oldumount 22 common umount sys_oldumount sys_oldumount
23 32 setuid - sys_setuid16 23 32 setuid - sys_setuid16
24 32 getuid - sys_getuid16 24 32 getuid - sys_getuid16
......
...@@ -201,7 +201,7 @@ ...@@ -201,7 +201,7 @@
164 64 utrap_install sys_utrap_install 164 64 utrap_install sys_utrap_install
165 common quotactl sys_quotactl 165 common quotactl sys_quotactl
166 common set_tid_address sys_set_tid_address 166 common set_tid_address sys_set_tid_address
167 common mount sys_mount compat_sys_mount 167 common mount sys_mount
168 common ustat sys_ustat compat_sys_ustat 168 common ustat sys_ustat compat_sys_ustat
169 common setxattr sys_setxattr 169 common setxattr sys_setxattr
170 common lsetxattr sys_lsetxattr 170 common lsetxattr sys_lsetxattr
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
18 i386 oldstat sys_stat 18 i386 oldstat sys_stat
19 i386 lseek sys_lseek compat_sys_lseek 19 i386 lseek sys_lseek compat_sys_lseek
20 i386 getpid sys_getpid 20 i386 getpid sys_getpid
21 i386 mount sys_mount compat_sys_mount 21 i386 mount sys_mount
22 i386 umount sys_oldumount 22 i386 umount sys_oldumount
23 i386 setuid sys_setuid16 23 i386 setuid sys_setuid16
24 i386 getuid sys_getuid16 24 i386 getuid sys_getuid16
......
...@@ -37,7 +37,6 @@ obj-$(CONFIG_FS_DAX) += dax.o ...@@ -37,7 +37,6 @@ obj-$(CONFIG_FS_DAX) += dax.o
obj-$(CONFIG_FS_ENCRYPTION) += crypto/ obj-$(CONFIG_FS_ENCRYPTION) += crypto/
obj-$(CONFIG_FS_VERITY) += verity/ obj-$(CONFIG_FS_VERITY) += verity/
obj-$(CONFIG_FILE_LOCKING) += locks.o obj-$(CONFIG_FILE_LOCKING) += locks.o
obj-$(CONFIG_COMPAT) += compat.o
obj-$(CONFIG_BINFMT_AOUT) += binfmt_aout.o obj-$(CONFIG_BINFMT_AOUT) += binfmt_aout.o
obj-$(CONFIG_BINFMT_EM86) += binfmt_em86.o obj-$(CONFIG_BINFMT_EM86) += binfmt_em86.o
obj-$(CONFIG_BINFMT_MISC) += binfmt_misc.o obj-$(CONFIG_BINFMT_MISC) += binfmt_misc.o
......
// SPDX-License-Identifier: GPL-2.0-only
/*
* linux/fs/compat.c
*
* Kernel compatibililty routines for e.g. 32 bit syscall support
* on 64 bit kernels.
*
* Copyright (C) 2002 Stephen Rothwell, IBM Corporation
* Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com)
* Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
* Copyright (C) 2001,2002 Andi Kleen, SuSE Labs
* Copyright (C) 2003 Pavel Machek (pavel@ucw.cz)
*/
#include <linux/compat.h>
#include <linux/nfs4_mount.h>
#include <linux/syscalls.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include "internal.h"
struct compat_nfs_string {
compat_uint_t len;
compat_uptr_t data;
};
static inline void compat_nfs_string(struct nfs_string *dst,
struct compat_nfs_string *src)
{
dst->data = compat_ptr(src->data);
dst->len = src->len;
}
struct compat_nfs4_mount_data_v1 {
compat_int_t version;
compat_int_t flags;
compat_int_t rsize;
compat_int_t wsize;
compat_int_t timeo;
compat_int_t retrans;
compat_int_t acregmin;
compat_int_t acregmax;
compat_int_t acdirmin;
compat_int_t acdirmax;
struct compat_nfs_string client_addr;
struct compat_nfs_string mnt_path;
struct compat_nfs_string hostname;
compat_uint_t host_addrlen;
compat_uptr_t host_addr;
compat_int_t proto;
compat_int_t auth_flavourlen;
compat_uptr_t auth_flavours;
};
static int do_nfs4_super_data_conv(void *raw_data)
{
int version = *(compat_uint_t *) raw_data;
if (version == 1) {
struct compat_nfs4_mount_data_v1 *raw = raw_data;
struct nfs4_mount_data *real = raw_data;
/* copy the fields backwards */
real->auth_flavours = compat_ptr(raw->auth_flavours);
real->auth_flavourlen = raw->auth_flavourlen;
real->proto = raw->proto;
real->host_addr = compat_ptr(raw->host_addr);
real->host_addrlen = raw->host_addrlen;
compat_nfs_string(&real->hostname, &raw->hostname);
compat_nfs_string(&real->mnt_path, &raw->mnt_path);
compat_nfs_string(&real->client_addr, &raw->client_addr);
real->acdirmax = raw->acdirmax;
real->acdirmin = raw->acdirmin;
real->acregmax = raw->acregmax;
real->acregmin = raw->acregmin;
real->retrans = raw->retrans;
real->timeo = raw->timeo;
real->wsize = raw->wsize;
real->rsize = raw->rsize;
real->flags = raw->flags;
real->version = raw->version;
}
return 0;
}
#define NFS4_NAME "nfs4"
COMPAT_SYSCALL_DEFINE5(mount, const char __user *, dev_name,
const char __user *, dir_name,
const char __user *, type, compat_ulong_t, flags,
const void __user *, data)
{
char *kernel_type;
void *options;
char *kernel_dev;
int retval;
kernel_type = copy_mount_string(type);
retval = PTR_ERR(kernel_type);
if (IS_ERR(kernel_type))
goto out;
kernel_dev = copy_mount_string(dev_name);
retval = PTR_ERR(kernel_dev);
if (IS_ERR(kernel_dev))
goto out1;
options = copy_mount_options(data);
retval = PTR_ERR(options);
if (IS_ERR(options))
goto out2;
if (kernel_type && options) {
if (!strcmp(kernel_type, NFS4_NAME)) {
retval = -EINVAL;
if (do_nfs4_super_data_conv(options))
goto out3;
}
}
retval = do_mount(kernel_dev, dir_name, kernel_type, flags, options);
out3:
kfree(options);
out2:
kfree(kernel_dev);
out1:
kfree(kernel_type);
out:
return retval;
}
...@@ -82,9 +82,6 @@ int may_linkat(struct path *link); ...@@ -82,9 +82,6 @@ int may_linkat(struct path *link);
/* /*
* namespace.c * namespace.c
*/ */
extern void *copy_mount_options(const void __user *);
extern char *copy_mount_string(const void __user *);
extern struct vfsmount *lookup_mnt(const struct path *); extern struct vfsmount *lookup_mnt(const struct path *);
extern int finish_automount(struct vfsmount *, struct path *); extern int finish_automount(struct vfsmount *, struct path *);
......
...@@ -3072,7 +3072,7 @@ static void shrink_submounts(struct mount *mnt) ...@@ -3072,7 +3072,7 @@ static void shrink_submounts(struct mount *mnt)
} }
} }
void *copy_mount_options(const void __user * data) static void *copy_mount_options(const void __user * data)
{ {
char *copy; char *copy;
unsigned left, offset; unsigned left, offset;
...@@ -3108,7 +3108,7 @@ void *copy_mount_options(const void __user * data) ...@@ -3108,7 +3108,7 @@ void *copy_mount_options(const void __user * data)
return copy; return copy;
} }
char *copy_mount_string(const void __user *data) static char *copy_mount_string(const void __user *data)
{ {
return data ? strndup_user(data, PATH_MAX) : NULL; return data ? strndup_user(data, PATH_MAX) : NULL;
} }
......
...@@ -1039,6 +1039,65 @@ static int nfs23_parse_monolithic(struct fs_context *fc, ...@@ -1039,6 +1039,65 @@ static int nfs23_parse_monolithic(struct fs_context *fc,
} }
#if IS_ENABLED(CONFIG_NFS_V4) #if IS_ENABLED(CONFIG_NFS_V4)
struct compat_nfs_string {
compat_uint_t len;
compat_uptr_t data;
};
static inline void compat_nfs_string(struct nfs_string *dst,
struct compat_nfs_string *src)
{
dst->data = compat_ptr(src->data);
dst->len = src->len;
}
struct compat_nfs4_mount_data_v1 {
compat_int_t version;
compat_int_t flags;
compat_int_t rsize;
compat_int_t wsize;
compat_int_t timeo;
compat_int_t retrans;
compat_int_t acregmin;
compat_int_t acregmax;
compat_int_t acdirmin;
compat_int_t acdirmax;
struct compat_nfs_string client_addr;
struct compat_nfs_string mnt_path;
struct compat_nfs_string hostname;
compat_uint_t host_addrlen;
compat_uptr_t host_addr;
compat_int_t proto;
compat_int_t auth_flavourlen;
compat_uptr_t auth_flavours;
};
static void nfs4_compat_mount_data_conv(struct nfs4_mount_data *data)
{
struct compat_nfs4_mount_data_v1 *compat =
(struct compat_nfs4_mount_data_v1 *)data;
/* copy the fields backwards */
data->auth_flavours = compat_ptr(compat->auth_flavours);
data->auth_flavourlen = compat->auth_flavourlen;
data->proto = compat->proto;
data->host_addr = compat_ptr(compat->host_addr);
data->host_addrlen = compat->host_addrlen;
compat_nfs_string(&data->hostname, &compat->hostname);
compat_nfs_string(&data->mnt_path, &compat->mnt_path);
compat_nfs_string(&data->client_addr, &compat->client_addr);
data->acdirmax = compat->acdirmax;
data->acdirmin = compat->acdirmin;
data->acregmax = compat->acregmax;
data->acregmin = compat->acregmin;
data->retrans = compat->retrans;
data->timeo = compat->timeo;
data->wsize = compat->wsize;
data->rsize = compat->rsize;
data->flags = compat->flags;
data->version = compat->version;
}
/* /*
* Validate NFSv4 mount options * Validate NFSv4 mount options
*/ */
...@@ -1049,89 +1108,83 @@ static int nfs4_parse_monolithic(struct fs_context *fc, ...@@ -1049,89 +1108,83 @@ static int nfs4_parse_monolithic(struct fs_context *fc,
struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address; struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address;
char *c; char *c;
if (data == NULL) if (!data) {
goto out_no_data; if (is_remount_fc(fc))
goto done;
return nfs_invalf(fc,
"NFS4: mount program didn't pass any mount data");
}
ctx->version = 4; ctx->version = 4;
switch (data->version) { if (data->version != 1)
case 1: return generic_parse_monolithic(fc, data);
if (data->host_addrlen > sizeof(ctx->nfs_server.address))
goto out_no_address;
if (data->host_addrlen == 0)
goto out_no_address;
ctx->nfs_server.addrlen = data->host_addrlen;
if (copy_from_user(sap, data->host_addr, data->host_addrlen))
return -EFAULT;
if (!nfs_verify_server_address(sap))
goto out_no_address;
ctx->nfs_server.port = ntohs(((struct sockaddr_in *)sap)->sin_port);
if (data->auth_flavourlen) {
rpc_authflavor_t pseudoflavor;
if (data->auth_flavourlen > 1)
goto out_inval_auth;
if (copy_from_user(&pseudoflavor,
data->auth_flavours,
sizeof(pseudoflavor)))
return -EFAULT;
ctx->selected_flavor = pseudoflavor;
} else
ctx->selected_flavor = RPC_AUTH_UNIX;
c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
if (IS_ERR(c))
return PTR_ERR(c);
ctx->nfs_server.hostname = c;
c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN); if (in_compat_syscall())
if (IS_ERR(c)) nfs4_compat_mount_data_conv(data);
return PTR_ERR(c);
ctx->nfs_server.export_path = c;
dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
c = strndup_user(data->client_addr.data, 16); if (data->host_addrlen > sizeof(ctx->nfs_server.address))
if (IS_ERR(c)) goto out_no_address;
return PTR_ERR(c); if (data->host_addrlen == 0)
ctx->client_address = c; goto out_no_address;
ctx->nfs_server.addrlen = data->host_addrlen;
/* if (copy_from_user(sap, data->host_addr, data->host_addrlen))
* Translate to nfs_fs_context, which nfs_fill_super return -EFAULT;
* can deal with. if (!nfs_verify_server_address(sap))
*/ goto out_no_address;
ctx->nfs_server.port = ntohs(((struct sockaddr_in *)sap)->sin_port);
ctx->flags = data->flags & NFS4_MOUNT_FLAGMASK; if (data->auth_flavourlen) {
ctx->rsize = data->rsize; rpc_authflavor_t pseudoflavor;
ctx->wsize = data->wsize;
ctx->timeo = data->timeo;
ctx->retrans = data->retrans;
ctx->acregmin = data->acregmin;
ctx->acregmax = data->acregmax;
ctx->acdirmin = data->acdirmin;
ctx->acdirmax = data->acdirmax;
ctx->nfs_server.protocol = data->proto;
nfs_validate_transport_protocol(ctx);
if (ctx->nfs_server.protocol == XPRT_TRANSPORT_UDP)
goto out_invalid_transport_udp;
break; if (data->auth_flavourlen > 1)
default: goto out_inval_auth;
goto generic; if (copy_from_user(&pseudoflavor, data->auth_flavours,
sizeof(pseudoflavor)))
return -EFAULT;
ctx->selected_flavor = pseudoflavor;
} else {
ctx->selected_flavor = RPC_AUTH_UNIX;
} }
c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
if (IS_ERR(c))
return PTR_ERR(c);
ctx->nfs_server.hostname = c;
c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
if (IS_ERR(c))
return PTR_ERR(c);
ctx->nfs_server.export_path = c;
dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
c = strndup_user(data->client_addr.data, 16);
if (IS_ERR(c))
return PTR_ERR(c);
ctx->client_address = c;
/*
* Translate to nfs_fs_context, which nfs_fill_super
* can deal with.
*/
ctx->flags = data->flags & NFS4_MOUNT_FLAGMASK;
ctx->rsize = data->rsize;
ctx->wsize = data->wsize;
ctx->timeo = data->timeo;
ctx->retrans = data->retrans;
ctx->acregmin = data->acregmin;
ctx->acregmax = data->acregmax;
ctx->acdirmin = data->acdirmin;
ctx->acdirmax = data->acdirmax;
ctx->nfs_server.protocol = data->proto;
nfs_validate_transport_protocol(ctx);
if (ctx->nfs_server.protocol == XPRT_TRANSPORT_UDP)
goto out_invalid_transport_udp;
done:
ctx->skip_reconfig_option_check = true; ctx->skip_reconfig_option_check = true;
return 0; return 0;
generic:
return generic_parse_monolithic(fc, data);
out_no_data:
if (is_remount_fc(fc)) {
ctx->skip_reconfig_option_check = true;
return 0;
}
return nfs_invalf(fc, "NFS4: mount program didn't pass any mount data");
out_inval_auth: out_inval_auth:
return nfs_invalf(fc, "NFS4: Invalid number of RPC auth flavours %d", return nfs_invalf(fc, "NFS4: Invalid number of RPC auth flavours %d",
data->auth_flavourlen); data->auth_flavourlen);
......
...@@ -516,12 +516,6 @@ asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd, ...@@ -516,12 +516,6 @@ asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd,
asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd, asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
compat_ulong_t arg); compat_ulong_t arg);
/* fs/namespace.c */
asmlinkage long compat_sys_mount(const char __user *dev_name,
const char __user *dir_name,
const char __user *type, compat_ulong_t flags,
const void __user *data);
/* fs/open.c */ /* fs/open.c */
asmlinkage long compat_sys_statfs(const char __user *pathname, asmlinkage long compat_sys_statfs(const char __user *pathname,
struct compat_statfs __user *buf); struct compat_statfs __user *buf);
......
...@@ -140,7 +140,7 @@ __SYSCALL(__NR_renameat, sys_renameat) ...@@ -140,7 +140,7 @@ __SYSCALL(__NR_renameat, sys_renameat)
#define __NR_umount2 39 #define __NR_umount2 39
__SYSCALL(__NR_umount2, sys_umount) __SYSCALL(__NR_umount2, sys_umount)
#define __NR_mount 40 #define __NR_mount 40
__SC_COMP(__NR_mount, sys_mount, compat_sys_mount) __SYSCALL(__NR_mount, sys_mount)
#define __NR_pivot_root 41 #define __NR_pivot_root 41
__SYSCALL(__NR_pivot_root, sys_pivot_root) __SYSCALL(__NR_pivot_root, sys_pivot_root)
......
...@@ -140,7 +140,7 @@ __SYSCALL(__NR_renameat, sys_renameat) ...@@ -140,7 +140,7 @@ __SYSCALL(__NR_renameat, sys_renameat)
#define __NR_umount2 39 #define __NR_umount2 39
__SYSCALL(__NR_umount2, sys_umount) __SYSCALL(__NR_umount2, sys_umount)
#define __NR_mount 40 #define __NR_mount 40
__SC_COMP(__NR_mount, sys_mount, compat_sys_mount) __SYSCALL(__NR_mount, sys_mount)
#define __NR_pivot_root 41 #define __NR_pivot_root 41
__SYSCALL(__NR_pivot_root, sys_pivot_root) __SYSCALL(__NR_pivot_root, sys_pivot_root)
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
18 spu oldstat sys_ni_syscall 18 spu oldstat sys_ni_syscall
19 common lseek sys_lseek compat_sys_lseek 19 common lseek sys_lseek compat_sys_lseek
20 common getpid sys_getpid 20 common getpid sys_getpid
21 nospu mount sys_mount compat_sys_mount 21 nospu mount sys_mount
22 32 umount sys_oldumount 22 32 umount sys_oldumount
22 64 umount sys_ni_syscall 22 64 umount sys_ni_syscall
22 spu umount sys_ni_syscall 22 spu umount sys_ni_syscall
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
16 32 lchown - compat_sys_s390_lchown16 16 32 lchown - compat_sys_s390_lchown16
19 common lseek sys_lseek compat_sys_lseek 19 common lseek sys_lseek compat_sys_lseek
20 common getpid sys_getpid sys_getpid 20 common getpid sys_getpid sys_getpid
21 common mount sys_mount compat_sys_mount 21 common mount sys_mount
22 common umount sys_oldumount compat_sys_oldumount 22 common umount sys_oldumount compat_sys_oldumount
23 32 setuid - compat_sys_s390_setuid16 23 32 setuid - compat_sys_s390_setuid16
24 32 getuid - compat_sys_s390_getuid16 24 32 getuid - compat_sys_s390_getuid16
......
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