History

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

Pull compat quotactl cleanups from Al Viro: "More Christoph's compat cleanups: quotactl(2)" * 'work.quota-compat' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: quota: simplify the quotactl compat handling compat: add a compat_need_64bit_alignment_fixup() helper compat: lift compat_s64 and compat_u64 to <asm-generic/compat.h>

Linus Torvalds committed 6 years ago

Commit e18afa52 parents 85ed13e 80bdad317 files · +113 −159Browse files

Unified · Split

17 files
  1. arch/arm64/include/asm/compat.h +0 −2
  2. arch/mips/include/asm/compat.h +0 −2
  3. arch/parisc/include/asm/compat.h +0 −2
  4. arch/powerpc/include/asm/compat.h +0 −2
  5. arch/s390/include/asm/compat.h +0 −2
  6. arch/sparc/include/asm/compat.h +1 −2
  7. arch/x86/entry/syscalls/syscall_32.tbl +1 −1
  8. arch/x86/include/asm/compat.h +1 −2
  9. fs/quota/Kconfig +0 −5
  10. fs/quota/Makefile +0 −1
  11. fs/quota/compat.c +0 −120
  12. fs/quota/compat.h +34 −0
  13. fs/quota/quota.c +59 −14
  14. include/asm-generic/compat.h +8 −0
  15. include/linux/compat.h +9 −0
  16. include/linux/quotaops.h +0 −3
  17. kernel/sys_ni.c +0 −1
arch/arm64/include/asm/compat.h+0−2
@@ -35,8 +35,6 @@ typedef s32 compat_nlink_t; · 34 unmodified lines
3535 typedef u16 compat_ipc_pid_t;
3636 typedef u32 compat_caddr_t;
3737 typedef __kernel_fsid_t compat_fsid_t;
38−typedef s64 compat_s64;
39−typedef u64 compat_u64;
4038
4139 struct compat_stat {
4240 #ifdef __AARCH64EB__
arch/mips/include/asm/compat.h+0−2
@@ -26,8 +26,6 @@ typedef s32 compat_caddr_t; · 25 unmodified lines
2626 typedef struct {
2727 s32 val[2];
2828 } compat_fsid_t;
29−typedef s64 compat_s64;
30−typedef u64 compat_u64;
3129
3230 struct compat_stat {
3331 compat_dev_t st_dev;
arch/parisc/include/asm/compat.h+0−2
@@ -22,8 +22,6 @@ typedef u32 compat_dev_t; · 21 unmodified lines
2222 typedef u16 compat_nlink_t;
2323 typedef u16 compat_ipc_pid_t;
2424 typedef u32 compat_caddr_t;
25−typedef s64 compat_s64;
26−typedef u64 compat_u64;
2725
2826 struct compat_stat {
2927 compat_dev_t st_dev; /* dev_t is 32 bits on parisc */
arch/powerpc/include/asm/compat.h+0−2
@@ -27,8 +27,6 @@ typedef s16 compat_nlink_t; · 26 unmodified lines
2727 typedef u16 compat_ipc_pid_t;
2828 typedef u32 compat_caddr_t;
2929 typedef __kernel_fsid_t compat_fsid_t;
30−typedef s64 compat_s64;
31−typedef u64 compat_u64;
3230
3331 struct compat_stat {
3432 compat_dev_t st_dev;
arch/s390/include/asm/compat.h+0−2
@@ -63,8 +63,6 @@ typedef u16 compat_nlink_t; · 62 unmodified lines
6363 typedef u16 compat_ipc_pid_t;
6464 typedef u32 compat_caddr_t;
6565 typedef __kernel_fsid_t compat_fsid_t;
66−typedef s64 compat_s64;
67−typedef u64 compat_u64;
6866
6967 typedef struct {
7068 u32 mask;
arch/sparc/include/asm/compat.h+1−2
@@ -21,8 +21,7 @@ typedef s16 compat_nlink_t; · 20 unmodified lines
2121 typedef u16 compat_ipc_pid_t;
2222 typedef u32 compat_caddr_t;
2323 typedef __kernel_fsid_t compat_fsid_t;
24−typedef s64 compat_s64;
25−typedef u64 compat_u64;
24+
2625 struct compat_stat {
2726 compat_dev_t st_dev;
2827 compat_ino_t st_ino;
arch/x86/entry/syscalls/syscall_32.tbl+1−1
@@ -142,7 +142,7 @@ · 141 unmodified lines
142142 128 i386 init_module sys_init_module
143143 129 i386 delete_module sys_delete_module
144144 130 i386 get_kernel_syms
145−131 i386 quotactl sys_quotactl compat_sys_quotactl32
145+131 i386 quotactl sys_quotactl
146146 132 i386 getpgid sys_getpgid
147147 133 i386 fchdir sys_fchdir
148148 134 i386 bdflush sys_bdflush
arch/x86/include/asm/compat.h+1−2
@@ -27,8 +27,6 @@ typedef u16 compat_nlink_t; · 26 unmodified lines
2727 typedef u16 compat_ipc_pid_t;
2828 typedef u32 compat_caddr_t;
2929 typedef __kernel_fsid_t compat_fsid_t;
30−typedef s64 __attribute__((aligned(4))) compat_s64;
31−typedef u64 __attribute__((aligned(4))) compat_u64;
3230
3331 struct compat_stat {
3432 compat_dev_t st_dev;
@@ -211,6 +209,7 @@ static inline bool in_compat_syscall(void) · 176 unmodified lines
211209 return in_32bit_syscall();
212210 }
213211 #define in_compat_syscall in_compat_syscall /* override the generic impl */
212+#define compat_need_64bit_alignment_fixup in_ia32_syscall
214213 #endif
215214
216215 struct compat_siginfo;
fs/quota/Kconfig+0−5
@@ -70,8 +70,3 @@ config QFMT_V2 · 69 unmodified lines
7070 config QUOTACTL
7171 bool
7272 default n
73−
74−config QUOTACTL_COMPAT
75− bool
76− depends on QUOTACTL && COMPAT_FOR_U64_ALIGNMENT
77− default y
fs/quota/Makefile+0−1
@@ -4,5 +4,4 @@ obj-$(CONFIG_QFMT_V1) += quota_v1.o · 3 unmodified lines
44 obj-$(CONFIG_QFMT_V2) += quota_v2.o
55 obj-$(CONFIG_QUOTA_TREE) += quota_tree.o
66 obj-$(CONFIG_QUOTACTL) += quota.o kqid.o
7−obj-$(CONFIG_QUOTACTL_COMPAT) += compat.o
87 obj-$(CONFIG_QUOTA_NETLINK_INTERFACE) += netlink.o
fs/quota/compat.c+0−120
@@ -1,120 +0,0 @@
1−// SPDX-License-Identifier: GPL-2.0
2−
3−#include <linux/syscalls.h>
4−#include <linux/compat.h>
5−#include <linux/quotaops.h>
6−
7−/*
8− * This code works only for 32 bit quota tools over 64 bit OS (x86_64, ia64)
9− * and is necessary due to alignment problems.
10− */
11−struct compat_if_dqblk {
12− compat_u64 dqb_bhardlimit;
13− compat_u64 dqb_bsoftlimit;
14− compat_u64 dqb_curspace;
15− compat_u64 dqb_ihardlimit;
16− compat_u64 dqb_isoftlimit;
17− compat_u64 dqb_curinodes;
18− compat_u64 dqb_btime;
19− compat_u64 dqb_itime;
20− compat_uint_t dqb_valid;
21−};
22−
23−/* XFS structures */
24−struct compat_fs_qfilestat {
25− compat_u64 dqb_bhardlimit;
26− compat_u64 qfs_nblks;
27− compat_uint_t qfs_nextents;
28−};
29−
30−struct compat_fs_quota_stat {
31− __s8 qs_version;
32− __u16 qs_flags;
33− __s8 qs_pad;
34− struct compat_fs_qfilestat qs_uquota;
35− struct compat_fs_qfilestat qs_gquota;
36− compat_uint_t qs_incoredqs;
37− compat_int_t qs_btimelimit;
38− compat_int_t qs_itimelimit;
39− compat_int_t qs_rtbtimelimit;
40− __u16 qs_bwarnlimit;
41− __u16 qs_iwarnlimit;
42−};
43−
44−COMPAT_SYSCALL_DEFINE4(quotactl32, unsigned int, cmd,
45− const char __user *, special, qid_t, id,
46− void __user *, addr)
47−{
48− unsigned int cmds;
49− struct if_dqblk __user *dqblk;
50− struct compat_if_dqblk __user *compat_dqblk;
51− struct fs_quota_stat __user *fsqstat;
52− struct compat_fs_quota_stat __user *compat_fsqstat;
53− compat_uint_t data;
54− u16 xdata;
55− long ret;
56−
57− cmds = cmd >> SUBCMDSHIFT;
58−
59− switch (cmds) {
60− case Q_GETQUOTA:
61− dqblk = compat_alloc_user_space(sizeof(struct if_dqblk));
62− compat_dqblk = addr;
63− ret = kernel_quotactl(cmd, special, id, dqblk);
64− if (ret)
65− break;
66− if (copy_in_user(compat_dqblk, dqblk, sizeof(*compat_dqblk)) ||
67− get_user(data, &dqblk->dqb_valid) ||
68− put_user(data, &compat_dqblk->dqb_valid))
69− ret = -EFAULT;
70− break;
71− case Q_SETQUOTA:
72− dqblk = compat_alloc_user_space(sizeof(struct if_dqblk));
73− compat_dqblk = addr;
74− ret = -EFAULT;
75− if (copy_in_user(dqblk, compat_dqblk, sizeof(*compat_dqblk)) ||
76− get_user(data, &compat_dqblk->dqb_valid) ||
77− put_user(data, &dqblk->dqb_valid))
78− break;
79− ret = kernel_quotactl(cmd, special, id, dqblk);
80− break;
81− case Q_XGETQSTAT:
82− fsqstat = compat_alloc_user_space(sizeof(struct fs_quota_stat));
83− compat_fsqstat = addr;
84− ret = kernel_quotactl(cmd, special, id, fsqstat);
85− if (ret)
86− break;
87− ret = -EFAULT;
88− /* Copying qs_version, qs_flags, qs_pad */
89− if (copy_in_user(compat_fsqstat, fsqstat,
90− offsetof(struct compat_fs_quota_stat, qs_uquota)))
91− break;
92− /* Copying qs_uquota */
93− if (copy_in_user(&compat_fsqstat->qs_uquota,
94− &fsqstat->qs_uquota,
95− sizeof(compat_fsqstat->qs_uquota)) ||
96− get_user(data, &fsqstat->qs_uquota.qfs_nextents) ||
97− put_user(data, &compat_fsqstat->qs_uquota.qfs_nextents))
98− break;
99− /* Copying qs_gquota */
100− if (copy_in_user(&compat_fsqstat->qs_gquota,
101− &fsqstat->qs_gquota,
102− sizeof(compat_fsqstat->qs_gquota)) ||
103− get_user(data, &fsqstat->qs_gquota.qfs_nextents) ||
104− put_user(data, &compat_fsqstat->qs_gquota.qfs_nextents))
105− break;
106− /* Copying the rest */
107− if (copy_in_user(&compat_fsqstat->qs_incoredqs,
108− &fsqstat->qs_incoredqs,
109− sizeof(struct compat_fs_quota_stat) -
110− offsetof(struct compat_fs_quota_stat, qs_incoredqs)) ||
111− get_user(xdata, &fsqstat->qs_iwarnlimit) ||
112− put_user(xdata, &compat_fsqstat->qs_iwarnlimit))
113− break;
114− ret = 0;
115− break;
116− default:
117− ret = kernel_quotactl(cmd, special, id, addr);
118− }
119− return ret;
120−}
fs/quota/compat.h+34−0
@@ -0,0 +1,34 @@
1+// SPDX-License-Identifier: GPL-2.0
2+#include <linux/compat.h>
3+
4+struct compat_if_dqblk {
5+ compat_u64 dqb_bhardlimit;
6+ compat_u64 dqb_bsoftlimit;
7+ compat_u64 dqb_curspace;
8+ compat_u64 dqb_ihardlimit;
9+ compat_u64 dqb_isoftlimit;
10+ compat_u64 dqb_curinodes;
11+ compat_u64 dqb_btime;
12+ compat_u64 dqb_itime;
13+ compat_uint_t dqb_valid;
14+};
15+
16+struct compat_fs_qfilestat {
17+ compat_u64 dqb_bhardlimit;
18+ compat_u64 qfs_nblks;
19+ compat_uint_t qfs_nextents;
20+};
21+
22+struct compat_fs_quota_stat {
23+ __s8 qs_version;
24+ __u16 qs_flags;
25+ __s8 qs_pad;
26+ struct compat_fs_qfilestat qs_uquota;
27+ struct compat_fs_qfilestat qs_gquota;
28+ compat_uint_t qs_incoredqs;
29+ compat_int_t qs_btimelimit;
30+ compat_int_t qs_itimelimit;
31+ compat_int_t qs_rtbtimelimit;
32+ __u16 qs_bwarnlimit;
33+ __u16 qs_iwarnlimit;
34+};
fs/quota/quota.c+59−14
@@ -19,6 +19,7 @@ · 18 unmodified lines
1919 #include <linux/types.h>
2020 #include <linux/writeback.h>
2121 #include <linux/nospec.h>
22+#include "compat.h"
2223
2324 static int check_quotactl_permission(struct super_block *sb, int type, int cmd,
2425 qid_t id)
@@ -211,8 +212,18 @@ static int quota_getquota(struct super_block *sb, int type, qid_t id, · 186 unmodified lines
211212 if (ret)
212213 return ret;
213214 copy_to_if_dqblk(&idq, &fdq);
214− if (copy_to_user(addr, &idq, sizeof(idq)))
215− return -EFAULT;
215+
216+ if (compat_need_64bit_alignment_fixup()) {
217+ struct compat_if_dqblk __user *compat_dqblk = addr;
218+
219+ if (copy_to_user(compat_dqblk, &idq, sizeof(*compat_dqblk)))
220+ return -EFAULT;
221+ if (put_user(idq.dqb_valid, &compat_dqblk->dqb_valid))
222+ return -EFAULT;
223+ } else {
224+ if (copy_to_user(addr, &idq, sizeof(idq)))
225+ return -EFAULT;
226+ }
216227 return 0;
217228 }
218229
@@ -277,8 +288,16 @@ static int quota_setquota(struct super_block *sb, int type, qid_t id, · 58 unmodified lines
277288 struct if_dqblk idq;
278289 struct kqid qid;
279290
280− if (copy_from_user(&idq, addr, sizeof(idq)))
281− return -EFAULT;
291+ if (compat_need_64bit_alignment_fixup()) {
292+ struct compat_if_dqblk __user *compat_dqblk = addr;
293+
294+ if (copy_from_user(&idq, compat_dqblk, sizeof(*compat_dqblk)) ||
295+ get_user(idq.dqb_valid, &compat_dqblk->dqb_valid))
296+ return -EFAULT;
297+ } else {
298+ if (copy_from_user(&idq, addr, sizeof(idq)))
299+ return -EFAULT;
300+ }
282301 if (!sb->s_qcop->set_dqblk)
283302 return -ENOSYS;
284303 qid = make_kqid(current_user_ns(), type, id);
@@ -382,6 +401,33 @@ static int quota_getstate(struct super_block *sb, int type, · 97 unmodified lines
382401 return 0;
383402 }
384403
404+static int compat_copy_fs_qfilestat(struct compat_fs_qfilestat __user *to,
405+ struct fs_qfilestat *from)
406+{
407+ if (copy_to_user(to, from, sizeof(*to)) ||
408+ put_user(from->qfs_nextents, &to->qfs_nextents))
409+ return -EFAULT;
410+ return 0;
411+}
412+
413+static int compat_copy_fs_quota_stat(struct compat_fs_quota_stat __user *to,
414+ struct fs_quota_stat *from)
415+{
416+ if (put_user(from->qs_version, &to->qs_version) ||
417+ put_user(from->qs_flags, &to->qs_flags) ||
418+ put_user(from->qs_pad, &to->qs_pad) ||
419+ compat_copy_fs_qfilestat(&to->qs_uquota, &from->qs_uquota) ||
420+ compat_copy_fs_qfilestat(&to->qs_gquota, &from->qs_gquota) ||
421+ put_user(from->qs_incoredqs, &to->qs_incoredqs) ||
422+ put_user(from->qs_btimelimit, &to->qs_btimelimit) ||
423+ put_user(from->qs_itimelimit, &to->qs_itimelimit) ||
424+ put_user(from->qs_rtbtimelimit, &to->qs_rtbtimelimit) ||
425+ put_user(from->qs_bwarnlimit, &to->qs_bwarnlimit) ||
426+ put_user(from->qs_iwarnlimit, &to->qs_iwarnlimit))
427+ return -EFAULT;
428+ return 0;
429+}
430+
385431 static int quota_getxstate(struct super_block *sb, int type, void __user *addr)
386432 {
387433 struct fs_quota_stat fqs;
@@ -390,9 +436,14 @@ static int quota_getxstate(struct super_block *sb, int type, void __user *addr) · 2 unmodified lines
390436 if (!sb->s_qcop->get_state)
391437 return -ENOSYS;
392438 ret = quota_getstate(sb, type, &fqs);
393− if (!ret && copy_to_user(addr, &fqs, sizeof(fqs)))
439+ if (ret)
440+ return ret;
441+
442+ if (compat_need_64bit_alignment_fixup())
443+ return compat_copy_fs_quota_stat(addr, &fqs);
444+ if (copy_to_user(addr, &fqs, sizeof(fqs)))
394445 return -EFAULT;
395− return ret;
446+ return 0;
396447 }
397448
398449 static int quota_getstatev(struct super_block *sb, int type,
@@ -816,8 +867,8 @@ static struct super_block *quotactl_block(const char __user *special, int cmd) · 417 unmodified lines
816867 * calls. Maybe we need to add the process quotas etc. in the future,
817868 * but we probably should use rlimits for that.
818869 */
819−int kernel_quotactl(unsigned int cmd, const char __user *special,
820− qid_t id, void __user *addr)
870+SYSCALL_DEFINE4(quotactl, unsigned int, cmd, const char __user *, special,
871+ qid_t, id, void __user *, addr)
821872 {
822873 uint cmds, type;
823874 struct super_block *sb = NULL;
@@ -871,9 +922,3 @@ out: · 47 unmodified lines
871922 path_put(pathp);
872923 return ret;
873924 }
874−
875−SYSCALL_DEFINE4(quotactl, unsigned int, cmd, const char __user *, special,
876− qid_t, id, void __user *, addr)
877−{
878− return kernel_quotactl(cmd, special, id, addr);
879−}
include/asm-generic/compat.h+8−0
@@ -22,4 +22,12 @@ typedef u32 compat_ulong_t; · 21 unmodified lines
2222 typedef u32 compat_uptr_t;
2323 typedef u32 compat_aio_context_t;
2424
25+#ifdef CONFIG_COMPAT_FOR_U64_ALIGNMENT
26+typedef s64 __attribute__((aligned(4))) compat_s64;
27+typedef u64 __attribute__((aligned(4))) compat_u64;
28+#else
29+typedef s64 compat_s64;
30+typedef u64 compat_u64;
31+#endif
32+
2533 #endif
include/linux/compat.h+9−0
@@ -910,6 +910,15 @@ static inline bool in_compat_syscall(void) { return false; } · 909 unmodified lines
910910
911911 #endif /* CONFIG_COMPAT */
912912
913+/*
914+ * Some legacy ABIs like the i386 one use less than natural alignment for 64-bit
915+ * types, and will need special compat treatment for that. Most architectures
916+ * don't need that special handling even for compat syscalls.
917+ */
918+#ifndef compat_need_64bit_alignment_fixup
919+#define compat_need_64bit_alignment_fixup() false
920+#endif
921+
913922 /*
914923 * A pointer passed in from user mode. This should not
915924 * be used for syscall parameters, just declare them
include/linux/quotaops.h+0−3
@@ -27,9 +27,6 @@ static inline bool is_quota_modification(struct inode *inode, struct iattr *ia) · 26 unmodified lines
2727 (ia->ia_valid & ATTR_GID && !gid_eq(ia->ia_gid, inode->i_gid));
2828 }
2929
30−int kernel_quotactl(unsigned int cmd, const char __user *special,
31− qid_t id, void __user *addr);
32−
3330 #if defined(CONFIG_QUOTA)
3431
3532 #define quota_error(sb, fmt, args...) \
kernel/sys_ni.c+0−1
@@ -369,7 +369,6 @@ COND_SYSCALL_COMPAT(fanotify_mark); · 368 unmodified lines
369369 /* x86 */
370370 COND_SYSCALL(vm86old);
371371 COND_SYSCALL(modify_ldt);
372−COND_SYSCALL_COMPAT(quotactl32);
373372 COND_SYSCALL(vm86);
374373 COND_SYSCALL(kexec_file_load);
375374