Skip to content

Commit dd90bbd

Browse files
committed
powerpc: Add compat_sys_truncate
The truncate syscall has a signed long parameter, so when using a 32- bit userspace with a 64-bit kernel the argument is zero-extended instead of sign-extended. Adding the compat_sys_truncate function fixes the issue. This was noticed during an LSB truncate test failure. The test was checking for the correct error number set when truncate is called with a length of -1. The test can be found at: http://bzr.linuxfoundation.org/lsb/devel/runtime-test?cmd=inventory;rev=stewb%40linux-foundation.org-20090626205411-sfb23cc0tjj7jzgm;path=modules/vsx-pcts/tset/POSIX.os/files/truncate/ BenH: Added compat_sys_ftruncate() as well, same issue. Signed-off-by: Chase Douglas <cndougla@linux.vnet.ibm.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
1 parent c79b297 commit dd90bbd

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎arch/powerpc/include/asm/systbl.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ SYSCALL(reboot)
9595
SYSX(sys_ni_syscall,compat_sys_old_readdir,sys_old_readdir)
9696
SYSCALL_SPU(mmap)
9797
SYSCALL_SPU(munmap)
98-
SYSCALL_SPU(truncate)
99-
SYSCALL_SPU(ftruncate)
98+
COMPAT_SYS_SPU(truncate)
99+
COMPAT_SYS_SPU(ftruncate)
100100
SYSCALL_SPU(fchmod)
101101
SYSCALL_SPU(fchown)
102102
COMPAT_SYS_SPU(getpriority)

‎arch/powerpc/kernel/sys_ppc32.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,18 @@ off_t ppc32_lseek(unsigned int fd, u32 offset, unsigned int origin)
343343
return sys_lseek(fd, (int)offset, origin);
344344
}
345345

346+
long compat_sys_truncate(const char __user * path, u32 length)
347+
{
348+
/* sign extend length */
349+
return sys_truncate(path, (int)length);
350+
}
351+
352+
long compat_sys_ftruncate(int fd, u32 length)
353+
{
354+
/* sign extend length */
355+
return sys_ftruncate(fd, (int)length);
356+
}
357+
346358
/* Note: it is necessary to treat bufsiz as an unsigned int,
347359
* with the corresponding cast to a signed int to insure that the
348360
* proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)

0 commit comments

Comments
 (0)