Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ipc: compat: use signed size_t types for msgsnd and msgrcv

The msgsnd and msgrcv system calls use size_t to represent the size of the
message being transferred. POSIX states that values of msgsz greater than
SSIZE_MAX cause the result to be implementation-defined. On Linux, this
equates to returning -EINVAL if (long) msgsz < 0.

For compat tasks where !CONFIG_ARCH_WANT_OLD_COMPAT_IPC and compat_size_t
is smaller than size_t, negative size values passed from userspace will be
interpreted as positive values by do_msg{rcv,snd} and will fail to exit
early with -EINVAL.

This patch changes the compat prototypes for msg{rcv,snd} so that the
message size is represented as a compat_ssize_t, which we cast to the
native ssize_t type for the core IPC code.

Cc: Arnd Bergmann <arnd@arndb.de>
Acked-by: Chris Metcalf <cmetcalf@tilera.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Will Deacon and committed by
Linus Torvalds
05ba3f1a b610c04c

+6 -6
+2 -2
include/linux/compat.h
··· 266 266 #else 267 267 long compat_sys_semctl(int semid, int semnum, int cmd, int arg); 268 268 long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp, 269 - size_t msgsz, int msgflg); 269 + compat_ssize_t msgsz, int msgflg); 270 270 long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp, 271 - size_t msgsz, long msgtyp, int msgflg); 271 + compat_ssize_t msgsz, long msgtyp, int msgflg); 272 272 long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg); 273 273 #endif 274 274 long compat_sys_msgctl(int first, int second, void __user *uptr);
+4 -4
ipc/compat.c
··· 373 373 } 374 374 375 375 long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp, 376 - size_t msgsz, int msgflg) 376 + compat_ssize_t msgsz, int msgflg) 377 377 { 378 378 compat_long_t mtype; 379 379 380 380 if (get_user(mtype, &msgp->mtype)) 381 381 return -EFAULT; 382 - return do_msgsnd(msqid, mtype, msgp->mtext, msgsz, msgflg); 382 + return do_msgsnd(msqid, mtype, msgp->mtext, (ssize_t)msgsz, msgflg); 383 383 } 384 384 385 385 long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp, 386 - size_t msgsz, long msgtyp, int msgflg) 386 + compat_ssize_t msgsz, long msgtyp, int msgflg) 387 387 { 388 388 long err, mtype; 389 389 390 - err = do_msgrcv(msqid, &mtype, msgp->mtext, msgsz, msgtyp, msgflg); 390 + err = do_msgrcv(msqid, &mtype, msgp->mtext, (ssize_t)msgsz, msgtyp, msgflg); 391 391 if (err < 0) 392 392 goto out; 393 393