Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 42852
b: refs/heads/master
c: 651971c
h: refs/heads/master
v: v3
  • Loading branch information
suzuki authored and Linus Torvalds committed Dec 7, 2006
1 parent 4de3da9 commit 0aacb82
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 28 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 19e5d9c0d2194b4b47189cbec2921cbf72b0bd1c
refs/heads/master: 651971cb7242e8f6d7ebd153e69bd271cb731223
6 changes: 6 additions & 0 deletions trunk/include/linux/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ struct msg_queue {
struct list_head q_senders;
};

/* Helper routines for sys_msgsnd and sys_msgrcv */
extern long do_msgsnd(int msqid, long mtype, void __user *mtext,
size_t msgsz, int msgflg);
extern long do_msgrcv(int msqid, long *pmtype, void __user *mtext,
size_t msgsz, long msgtyp, int msgflg);

#endif /* __KERNEL__ */

#endif /* _LINUX_MSG_H */
23 changes: 7 additions & 16 deletions trunk/ipc/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ struct compat_shm_info {

extern int sem_ctls[];
#define sc_semopm (sem_ctls[2])
#define MAXBUF (64*1024)

static inline int compat_ipc_parse_version(int *cmd)
{
Expand Down Expand Up @@ -307,35 +306,30 @@ long compat_sys_semctl(int first, int second, int third, void __user *uptr)

long compat_sys_msgsnd(int first, int second, int third, void __user *uptr)
{
struct msgbuf __user *p;
struct compat_msgbuf __user *up = uptr;
long type;

if (first < 0)
return -EINVAL;
if (second < 0 || (second >= MAXBUF - sizeof(struct msgbuf)))
if (second < 0)
return -EINVAL;

p = compat_alloc_user_space(second + sizeof(struct msgbuf));
if (get_user(type, &up->mtype) ||
put_user(type, &p->mtype) ||
copy_in_user(p->mtext, up->mtext, second))
if (get_user(type, &up->mtype))
return -EFAULT;

return sys_msgsnd(first, p, second, third);
return do_msgsnd(first, type, up->mtext, second, third);
}

long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
int version, void __user *uptr)
{
struct msgbuf __user *p;
struct compat_msgbuf __user *up;
long type;
int err;

if (first < 0)
return -EINVAL;
if (second < 0 || (second >= MAXBUF - sizeof(struct msgbuf)))
if (second < 0)
return -EINVAL;

if (!version) {
Expand All @@ -349,14 +343,11 @@ long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
uptr = compat_ptr(ipck.msgp);
msgtyp = ipck.msgtyp;
}
p = compat_alloc_user_space(second + sizeof(struct msgbuf));
err = sys_msgrcv(first, p, second, msgtyp, third);
up = uptr;
err = do_msgrcv(first, &type, up->mtext, second, msgtyp, third);
if (err < 0)
goto out;
up = uptr;
if (get_user(type, &p->mtype) ||
put_user(type, &up->mtype) ||
copy_in_user(up->mtext, p->mtext, err))
if (put_user(type, &up->mtype))
err = -EFAULT;
out:
return err;
Expand Down
44 changes: 33 additions & 11 deletions trunk/ipc/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,25 +626,22 @@ static inline int pipelined_send(struct msg_queue *msq, struct msg_msg *msg)
return 0;
}

asmlinkage long
sys_msgsnd(int msqid, struct msgbuf __user *msgp, size_t msgsz, int msgflg)
long do_msgsnd(int msqid, long mtype, void __user *mtext,
size_t msgsz, int msgflg)
{
struct msg_queue *msq;
struct msg_msg *msg;
long mtype;
int err;
struct ipc_namespace *ns;

ns = current->nsproxy->ipc_ns;

if (msgsz > ns->msg_ctlmax || (long) msgsz < 0 || msqid < 0)
return -EINVAL;
if (get_user(mtype, &msgp->mtype))
return -EFAULT;
if (mtype < 1)
return -EINVAL;

msg = load_msg(msgp->mtext, msgsz);
msg = load_msg(mtext, msgsz);
if (IS_ERR(msg))
return PTR_ERR(msg);

Expand Down Expand Up @@ -723,6 +720,16 @@ sys_msgsnd(int msqid, struct msgbuf __user *msgp, size_t msgsz, int msgflg)
return err;
}

asmlinkage long
sys_msgsnd(int msqid, struct msgbuf __user *msgp, size_t msgsz, int msgflg)
{
long mtype;

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

static inline int convert_mode(long *msgtyp, int msgflg)
{
/*
Expand All @@ -742,8 +749,8 @@ static inline int convert_mode(long *msgtyp, int msgflg)
return SEARCH_EQUAL;
}

asmlinkage long sys_msgrcv(int msqid, struct msgbuf __user *msgp, size_t msgsz,
long msgtyp, int msgflg)
long do_msgrcv(int msqid, long *pmtype, void __user *mtext,
size_t msgsz, long msgtyp, int msgflg)
{
struct msg_queue *msq;
struct msg_msg *msg;
Expand Down Expand Up @@ -889,15 +896,30 @@ asmlinkage long sys_msgrcv(int msqid, struct msgbuf __user *msgp, size_t msgsz,
return PTR_ERR(msg);

msgsz = (msgsz > msg->m_ts) ? msg->m_ts : msgsz;
if (put_user (msg->m_type, &msgp->mtype) ||
store_msg(msgp->mtext, msg, msgsz)) {
*pmtype = msg->m_type;
if (store_msg(mtext, msg, msgsz))
msgsz = -EFAULT;
}

free_msg(msg);

return msgsz;
}

asmlinkage long sys_msgrcv(int msqid, struct msgbuf __user *msgp, size_t msgsz,
long msgtyp, int msgflg)
{
long err, mtype;

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

if (put_user(mtype, &msgp->mtype))
err = -EFAULT;
out:
return err;
}

#ifdef CONFIG_PROC_FS
static int sysvipc_msg_proc_show(struct seq_file *s, void *it)
{
Expand Down

0 comments on commit 0aacb82

Please sign in to comment.