Skip to content

Commit

Permalink
fs: change sys_truncate length parameter type
Browse files Browse the repository at this point in the history
For this system call user space passes a signed long length parameter,
while the kernel side takes an unsigned long parameter and converts it
later to signed long again.

This has led to bugs in compat wrappers see e.g.  dd90bbd "powerpc: Add
compat_sys_truncate".  The s390 compat wrapper for this functions is
broken as well since it also performs zero extension instead of sign
extension for the length parameter.

In addition if hpa comes up with an automated way of generating
compat wrappers it would generate a wrong one here.

So change the length parameter from unsigned long to long.

Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Heiko Carstens authored and Linus Torvalds committed Sep 23, 2009
1 parent a6e995a commit 4fd8da8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 2 additions & 3 deletions fs/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,9 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
return error;
}

SYSCALL_DEFINE2(truncate, const char __user *, path, unsigned long, length)
SYSCALL_DEFINE2(truncate, const char __user *, path, long, length)
{
/* on 32-bit boxen it will cut the range 2^31--2^32-1 off */
return do_sys_truncate(path, (long)length);
return do_sys_truncate(path, length);
}

static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
Expand Down
3 changes: 1 addition & 2 deletions include/linux/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,7 @@ asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
void __user *data);
asmlinkage long sys_umount(char __user *name, int flags);
asmlinkage long sys_oldumount(char __user *name);
asmlinkage long sys_truncate(const char __user *path,
unsigned long length);
asmlinkage long sys_truncate(const char __user *path, long length);
asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
asmlinkage long sys_stat(char __user *filename,
struct __old_kernel_stat __user *statbuf);
Expand Down

0 comments on commit 4fd8da8

Please sign in to comment.