Skip to content

Commit

Permalink
ipc: compat: use signed size_t types for msgsnd and msgrcv
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Chris Metcalf <[email protected]>
Acked-by: Catalin Marinas <[email protected]>
Signed-off-by: Will Deacon <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
wildea01 authored and torvalds committed Jul 31, 2012
1 parent b610c04 commit 05ba3f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions include/linux/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
#else
long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp,
size_t msgsz, int msgflg);
compat_ssize_t msgsz, int msgflg);
long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
size_t msgsz, long msgtyp, int msgflg);
compat_ssize_t msgsz, long msgtyp, int msgflg);
long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
#endif
long compat_sys_msgctl(int first, int second, void __user *uptr);
Expand Down
8 changes: 4 additions & 4 deletions ipc/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,21 +373,21 @@ long compat_sys_semctl(int semid, int semnum, int cmd, int arg)
}

long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp,
size_t msgsz, int msgflg)
compat_ssize_t msgsz, int msgflg)
{
compat_long_t mtype;

if (get_user(mtype, &msgp->mtype))
return -EFAULT;
return do_msgsnd(msqid, mtype, msgp->mtext, msgsz, msgflg);
return do_msgsnd(msqid, mtype, msgp->mtext, (ssize_t)msgsz, msgflg);
}

long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
size_t msgsz, long msgtyp, int msgflg)
compat_ssize_t msgsz, long msgtyp, int msgflg)
{
long err, mtype;

err = do_msgrcv(msqid, &mtype, msgp->mtext, msgsz, msgtyp, msgflg);
err = do_msgrcv(msqid, &mtype, msgp->mtext, (ssize_t)msgsz, msgtyp, msgflg);
if (err < 0)
goto out;

Expand Down

0 comments on commit 05ba3f1

Please sign in to comment.