blob: 4a0aaaf5321790b8984544d966eeaed1dc228d41 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/compat.c
3 *
4 * Kernel compatibililty routines for e.g. 32 bit syscall support
5 * on 64 bit kernels.
6 *
7 * Copyright (C) 2002 Stephen Rothwell, IBM Corporation
8 * Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com)
9 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
10 * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs
Pavel Macheka2531292010-07-18 14:27:13 +020011 * Copyright (C) 2003 Pavel Machek (pavel@ucw.cz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
16 */
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/compat.h>
David Howells9a9947b2005-04-18 10:54:51 -070019#include <linux/nfs4_mount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/syscalls.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090021#include <linux/slab.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080022#include <linux/uaccess.h>
David Howells07f3f05c2006-09-30 20:52:18 +020023#include "internal.h"
David Woodhouse9f729492006-01-18 17:44:05 -080024
David Howells9a9947b2005-04-18 10:54:51 -070025struct compat_nfs_string {
26 compat_uint_t len;
David Howells5fc3e622005-04-27 15:39:03 -070027 compat_uptr_t data;
David Howells9a9947b2005-04-18 10:54:51 -070028};
29
30static inline void compat_nfs_string(struct nfs_string *dst,
31 struct compat_nfs_string *src)
32{
33 dst->data = compat_ptr(src->data);
34 dst->len = src->len;
35}
36
37struct compat_nfs4_mount_data_v1 {
38 compat_int_t version;
39 compat_int_t flags;
40 compat_int_t rsize;
41 compat_int_t wsize;
42 compat_int_t timeo;
43 compat_int_t retrans;
44 compat_int_t acregmin;
45 compat_int_t acregmax;
46 compat_int_t acdirmin;
47 compat_int_t acdirmax;
48 struct compat_nfs_string client_addr;
49 struct compat_nfs_string mnt_path;
50 struct compat_nfs_string hostname;
51 compat_uint_t host_addrlen;
David Howells5fc3e622005-04-27 15:39:03 -070052 compat_uptr_t host_addr;
David Howells9a9947b2005-04-18 10:54:51 -070053 compat_int_t proto;
54 compat_int_t auth_flavourlen;
David Howells5fc3e622005-04-27 15:39:03 -070055 compat_uptr_t auth_flavours;
David Howells9a9947b2005-04-18 10:54:51 -070056};
57
58static int do_nfs4_super_data_conv(void *raw_data)
59{
60 int version = *(compat_uint_t *) raw_data;
61
62 if (version == 1) {
63 struct compat_nfs4_mount_data_v1 *raw = raw_data;
64 struct nfs4_mount_data *real = raw_data;
65
66 /* copy the fields backwards */
67 real->auth_flavours = compat_ptr(raw->auth_flavours);
68 real->auth_flavourlen = raw->auth_flavourlen;
69 real->proto = raw->proto;
70 real->host_addr = compat_ptr(raw->host_addr);
71 real->host_addrlen = raw->host_addrlen;
72 compat_nfs_string(&real->hostname, &raw->hostname);
73 compat_nfs_string(&real->mnt_path, &raw->mnt_path);
74 compat_nfs_string(&real->client_addr, &raw->client_addr);
75 real->acdirmax = raw->acdirmax;
76 real->acdirmin = raw->acdirmin;
77 real->acregmax = raw->acregmax;
78 real->acregmin = raw->acregmin;
79 real->retrans = raw->retrans;
80 real->timeo = raw->timeo;
81 real->wsize = raw->wsize;
82 real->rsize = raw->rsize;
83 real->flags = raw->flags;
84 real->version = raw->version;
85 }
David Howells9a9947b2005-04-18 10:54:51 -070086
87 return 0;
88}
89
David Howells9a9947b2005-04-18 10:54:51 -070090#define NFS4_NAME "nfs4"
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Heiko Carstens932602e2014-03-04 16:07:52 +010092COMPAT_SYSCALL_DEFINE5(mount, const char __user *, dev_name,
93 const char __user *, dir_name,
94 const char __user *, type, compat_ulong_t, flags,
95 const void __user *, data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
Vegard Nossumeca6f532009-09-18 13:05:45 -070097 char *kernel_type;
Al Virob40ef862015-12-14 18:44:44 -050098 void *options;
Vegard Nossumeca6f532009-09-18 13:05:45 -070099 char *kernel_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 int retval;
101
Tim Gardnerb8850d12014-08-28 11:26:03 -0600102 kernel_type = copy_mount_string(type);
103 retval = PTR_ERR(kernel_type);
104 if (IS_ERR(kernel_type))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 goto out;
106
Tim Gardnerb8850d12014-08-28 11:26:03 -0600107 kernel_dev = copy_mount_string(dev_name);
108 retval = PTR_ERR(kernel_dev);
109 if (IS_ERR(kernel_dev))
Seunghun Lee5e6123f2014-09-14 22:15:10 +0900110 goto out1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Al Virob40ef862015-12-14 18:44:44 -0500112 options = copy_mount_options(data);
113 retval = PTR_ERR(options);
114 if (IS_ERR(options))
Seunghun Lee5e6123f2014-09-14 22:15:10 +0900115 goto out2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Al Virob40ef862015-12-14 18:44:44 -0500117 if (kernel_type && options) {
Greg Kroah-Hartmanf0ac2ab2018-06-01 20:35:10 +0200118 if (!strcmp(kernel_type, NFS4_NAME)) {
Al Virob40ef862015-12-14 18:44:44 -0500119 retval = -EINVAL;
120 if (do_nfs4_super_data_conv(options))
Seunghun Lee5e6123f2014-09-14 22:15:10 +0900121 goto out3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 }
123 }
124
Al Virob40ef862015-12-14 18:44:44 -0500125 retval = do_mount(kernel_dev, dir_name, kernel_type, flags, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 out3:
Al Virob40ef862015-12-14 18:44:44 -0500128 kfree(options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 out2:
Seunghun Lee5e6123f2014-09-14 22:15:10 +0900130 kfree(kernel_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 out1:
Vegard Nossumeca6f532009-09-18 13:05:45 -0700132 kfree(kernel_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 out:
134 return retval;
135}