Skip to content

Commit e25bd6c

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull vfs fix from Al Viro: "Fix for 3.15 breakage of fcntl64() in arm OABI compat. -stable fodder" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: [PATCH] arm: fix handling of F_OFD_... in oabi_fcntl64()
2 parents 1e60508 + 76cc404 commit e25bd6c

File tree

1 file changed

+37
-36
lines changed

1 file changed

+37
-36
lines changed

arch/arm/kernel/sys_oabi-compat.c

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -193,55 +193,56 @@ struct oabi_flock64 {
193193
pid_t l_pid;
194194
} __attribute__ ((packed,aligned(4)));
195195

196-
asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd,
196+
static long do_locks(unsigned int fd, unsigned int cmd,
197197
unsigned long arg)
198198
{
199-
struct oabi_flock64 user;
200199
struct flock64 kernel;
201-
mm_segment_t fs = USER_DS; /* initialized to kill a warning */
202-
unsigned long local_arg = arg;
203-
int ret;
200+
struct oabi_flock64 user;
201+
mm_segment_t fs;
202+
long ret;
203+
204+
if (copy_from_user(&user, (struct oabi_flock64 __user *)arg,
205+
sizeof(user)))
206+
return -EFAULT;
207+
kernel.l_type = user.l_type;
208+
kernel.l_whence = user.l_whence;
209+
kernel.l_start = user.l_start;
210+
kernel.l_len = user.l_len;
211+
kernel.l_pid = user.l_pid;
212+
213+
fs = get_fs();
214+
set_fs(KERNEL_DS);
215+
ret = sys_fcntl64(fd, cmd, (unsigned long)&kernel);
216+
set_fs(fs);
217+
218+
if (!ret && (cmd == F_GETLK64 || cmd == F_OFD_GETLK)) {
219+
user.l_type = kernel.l_type;
220+
user.l_whence = kernel.l_whence;
221+
user.l_start = kernel.l_start;
222+
user.l_len = kernel.l_len;
223+
user.l_pid = kernel.l_pid;
224+
if (copy_to_user((struct oabi_flock64 __user *)arg,
225+
&user, sizeof(user)))
226+
ret = -EFAULT;
227+
}
228+
return ret;
229+
}
204230

231+
asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd,
232+
unsigned long arg)
233+
{
205234
switch (cmd) {
206235
case F_OFD_GETLK:
207236
case F_OFD_SETLK:
208237
case F_OFD_SETLKW:
209238
case F_GETLK64:
210239
case F_SETLK64:
211240
case F_SETLKW64:
212-
if (copy_from_user(&user, (struct oabi_flock64 __user *)arg,
213-
sizeof(user)))
214-
return -EFAULT;
215-
kernel.l_type = user.l_type;
216-
kernel.l_whence = user.l_whence;
217-
kernel.l_start = user.l_start;
218-
kernel.l_len = user.l_len;
219-
kernel.l_pid = user.l_pid;
220-
local_arg = (unsigned long)&kernel;
221-
fs = get_fs();
222-
set_fs(KERNEL_DS);
223-
}
224-
225-
ret = sys_fcntl64(fd, cmd, local_arg);
241+
return do_locks(fd, cmd, arg);
226242

227-
switch (cmd) {
228-
case F_GETLK64:
229-
if (!ret) {
230-
user.l_type = kernel.l_type;
231-
user.l_whence = kernel.l_whence;
232-
user.l_start = kernel.l_start;
233-
user.l_len = kernel.l_len;
234-
user.l_pid = kernel.l_pid;
235-
if (copy_to_user((struct oabi_flock64 __user *)arg,
236-
&user, sizeof(user)))
237-
ret = -EFAULT;
238-
}
239-
case F_SETLK64:
240-
case F_SETLKW64:
241-
set_fs(fs);
243+
default:
244+
return sys_fcntl64(fd, cmd, arg);
242245
}
243-
244-
return ret;
245246
}
246247

247248
struct oabi_epoll_event {

0 commit comments

Comments
 (0)