1 From: Marcio Barbosa <mbarbosa@sinenomine.net>
2 Date: Thu, 16 Nov 2017 17:24:03 -0500
3 Subject: afs: fix kernel_write / kernel_read arguments
5 The order / content of the arguments passed to kernel_write and
6 kernel_read are not right. As a result, the kernel will panic if one of
7 the functions in question is called.
9 [kaduk@mit.edu: include configure check for multiple kernel_read()
10 variants, per linux commits bdd1d2d3d251c65b74ac4493e08db18971c09240
11 and e13ec939e96b13e664bb6cee361cc976a0ee621a]
15 Change-Id: I4753dee61f1b986bbe6a12b5568d1a8db30c65f8
16 Reviewed-on: https://gerrit.openafs.org/12769
17 Tested-by: BuildBot <buildbot@rampaginggeek.com>
18 Tested-by: Marcio Brito Barbosa <mbarbosa@sinenomine.net>
19 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
22 src/afs/LINUX/osi_compat.h | 8 ++++++++
23 src/cf/linux-test4.m4 | 12 ++++++++++++
24 3 files changed, 21 insertions(+)
26 diff --git a/acinclude.m4 b/acinclude.m4
27 index 94b9436..ebfa0cb 100644
30 @@ -1134,6 +1134,7 @@ case $AFS_SYSNAME in *_linux* | *_umlinux*)
31 LINUX_DOP_D_REVALIDATE_TAKES_UNSIGNED
32 LINUX_IOP_LOOKUP_TAKES_UNSIGNED
33 LINUX_D_INVALIDATE_IS_VOID
34 + LINUX_KERNEL_READ_OFFSET_IS_LAST
36 dnl If we are guaranteed that keyrings will work - that is
37 dnl a) The kernel has keyrings enabled
38 diff --git a/src/afs/LINUX/osi_compat.h b/src/afs/LINUX/osi_compat.h
39 index 9871535..78be496 100644
40 --- a/src/afs/LINUX/osi_compat.h
41 +++ b/src/afs/LINUX/osi_compat.h
42 @@ -606,7 +606,11 @@ afs_file_read(struct file *filp, char __user *buf, size_t len, loff_t *pos)
43 #if defined(HAVE_LINUX___VFS_WRITE)
44 return __vfs_read(filp, buf, len, pos);
45 #elif defined(HAVE_LINUX_KERNEL_WRITE)
46 +# if defined(LINUX_KERNEL_READ_OFFSET_IS_LAST)
47 return kernel_read(filp, buf, len, pos);
49 + return kernel_read(filp, *pos, buf, len);
52 return filp->f_op->read(filp, buf, len, pos);
54 @@ -618,7 +622,11 @@ afs_file_write(struct file *filp, char __user *buf, size_t len, loff_t *pos)
55 #if defined(HAVE_LINUX___VFS_WRITE)
56 return __vfs_write(filp, buf, len, pos);
57 #elif defined(HAVE_LINUX_KERNEL_WRITE)
58 +# if defined(LINUX_KERNEL_READ_OFFSET_IS_LAST)
59 return kernel_write(filp, buf, len, pos);
61 + return kernel_write(filp, buf, len, *pos);
64 return filp->f_op->write(filp, buf, len, pos);
66 diff --git a/src/cf/linux-test4.m4 b/src/cf/linux-test4.m4
67 index 46323ed..5a4615f 100644
68 --- a/src/cf/linux-test4.m4
69 +++ b/src/cf/linux-test4.m4
70 @@ -824,3 +824,15 @@ AC_DEFUN([LINUX_D_INVALIDATE_IS_VOID], [
71 [define if your d_invalidate returns void],
75 +AC_DEFUN([LINUX_KERNEL_READ_OFFSET_IS_LAST], [
76 + AC_CHECK_LINUX_BUILD([whether offset is the last argument to kernel_read],
77 + [ac_cv_linux_func_kernel_read_offset_is_last],
78 + [#include <linux/fs.h>],
80 + ssize_t kernel_read(struct file *, void *, size_t, loff_t *);
82 + [KERNEL_READ_OFFSET_IS_LAST],
83 + [define if your kernel_read has offset as the last argument],