Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/ipc/msg.c |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 3 | * Copyright (C) 1992 Krishna Balasubramanian |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * Removed all the remaining kerneld mess |
| 6 | * Catch the -EFAULT stuff properly |
| 7 | * Use GFP_KERNEL for messages as in 1.2 |
| 8 | * Fixed up the unchecked user space derefs |
| 9 | * Copyright (C) 1998 Alan Cox & Andi Kleen |
| 10 | * |
| 11 | * /proc/sysvipc/msg support (c) 1999 Dragos Acostachioaie <dragos@iname.com> |
| 12 | * |
| 13 | * mostly rewritten, threaded and wake-one semantics added |
| 14 | * MSGMAX limit removed, sysctl's added |
Christian Kujau | 624dffc | 2006-01-15 02:43:54 +0100 | [diff] [blame] | 15 | * (c) 1999 Manfred Spraul <manfred@colorfullife.com> |
Steve Grubb | 073115d | 2006-04-02 17:07:33 -0400 | [diff] [blame] | 16 | * |
| 17 | * support for audit of ipc object properties and permission changes |
| 18 | * Dustin Kirkland <dustin.kirkland@us.ibm.com> |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 19 | * |
| 20 | * namespaces support |
| 21 | * OpenVZ, SWsoft Inc. |
| 22 | * Pavel Emelianov <xemul@openvz.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | */ |
| 24 | |
Randy.Dunlap | c59ede7 | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 25 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/slab.h> |
| 27 | #include <linux/msg.h> |
| 28 | #include <linux/spinlock.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/proc_fs.h> |
| 31 | #include <linux/list.h> |
| 32 | #include <linux/security.h> |
| 33 | #include <linux/sched.h> |
| 34 | #include <linux/syscalls.h> |
| 35 | #include <linux/audit.h> |
Mike Waychison | 19b4946 | 2005-09-06 15:17:10 -0700 | [diff] [blame] | 36 | #include <linux/seq_file.h> |
Ingo Molnar | 5f921ae | 2006-03-26 01:37:17 -0800 | [diff] [blame] | 37 | #include <linux/mutex.h> |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 38 | #include <linux/nsproxy.h> |
Ingo Molnar | 5f921ae | 2006-03-26 01:37:17 -0800 | [diff] [blame] | 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <asm/current.h> |
| 41 | #include <asm/uaccess.h> |
| 42 | #include "util.h" |
| 43 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 44 | /* |
| 45 | * one msg_receiver structure for each sleeping receiver: |
| 46 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | struct msg_receiver { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 48 | struct list_head r_list; |
| 49 | struct task_struct *r_tsk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 51 | int r_mode; |
| 52 | long r_msgtype; |
| 53 | long r_maxsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Linus Torvalds | 80491eb | 2006-11-04 09:55:00 -0800 | [diff] [blame^] | 55 | struct msg_msg *volatile r_msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | /* one msg_sender for each sleeping sender */ |
| 59 | struct msg_sender { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 60 | struct list_head list; |
| 61 | struct task_struct *tsk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | #define SEARCH_ANY 1 |
| 65 | #define SEARCH_EQUAL 2 |
| 66 | #define SEARCH_NOTEQUAL 3 |
| 67 | #define SEARCH_LESSEQUAL 4 |
| 68 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 69 | static atomic_t msg_bytes = ATOMIC_INIT(0); |
| 70 | static atomic_t msg_hdrs = ATOMIC_INIT(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 72 | static struct ipc_ids init_msg_ids; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 74 | #define msg_ids(ns) (*((ns)->ids[IPC_MSG_IDS])) |
| 75 | |
| 76 | #define msg_lock(ns, id) ((struct msg_queue*)ipc_lock(&msg_ids(ns), id)) |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 77 | #define msg_unlock(msq) ipc_unlock(&(msq)->q_perm) |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 78 | #define msg_rmid(ns, id) ((struct msg_queue*)ipc_rmid(&msg_ids(ns), id)) |
| 79 | #define msg_checkid(ns, msq, msgid) \ |
| 80 | ipc_checkid(&msg_ids(ns), &msq->q_perm, msgid) |
| 81 | #define msg_buildid(ns, id, seq) \ |
| 82 | ipc_buildid(&msg_ids(ns), id, seq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 84 | static void freeque (struct ipc_namespace *ns, struct msg_queue *msq, int id); |
| 85 | static int newque (struct ipc_namespace *ns, key_t key, int msgflg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | #ifdef CONFIG_PROC_FS |
Mike Waychison | 19b4946 | 2005-09-06 15:17:10 -0700 | [diff] [blame] | 87 | static int sysvipc_msg_proc_show(struct seq_file *s, void *it); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #endif |
| 89 | |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 90 | static void __ipc_init __msg_init_ns(struct ipc_namespace *ns, struct ipc_ids *ids) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 92 | ns->ids[IPC_MSG_IDS] = ids; |
| 93 | ns->msg_ctlmax = MSGMAX; |
| 94 | ns->msg_ctlmnb = MSGMNB; |
| 95 | ns->msg_ctlmni = MSGMNI; |
| 96 | ipc_init_ids(ids, ns->msg_ctlmni); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 99 | #ifdef CONFIG_IPC_NS |
| 100 | int msg_init_ns(struct ipc_namespace *ns) |
| 101 | { |
| 102 | struct ipc_ids *ids; |
| 103 | |
| 104 | ids = kmalloc(sizeof(struct ipc_ids), GFP_KERNEL); |
| 105 | if (ids == NULL) |
| 106 | return -ENOMEM; |
| 107 | |
| 108 | __msg_init_ns(ns, ids); |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | void msg_exit_ns(struct ipc_namespace *ns) |
| 113 | { |
| 114 | int i; |
| 115 | struct msg_queue *msq; |
| 116 | |
| 117 | mutex_lock(&msg_ids(ns).mutex); |
| 118 | for (i = 0; i <= msg_ids(ns).max_id; i++) { |
| 119 | msq = msg_lock(ns, i); |
| 120 | if (msq == NULL) |
| 121 | continue; |
| 122 | |
| 123 | freeque(ns, msq, i); |
| 124 | } |
| 125 | mutex_unlock(&msg_ids(ns).mutex); |
| 126 | |
Pavel Emelianov | c7e12b8 | 2006-11-02 22:07:03 -0800 | [diff] [blame] | 127 | ipc_fini_ids(ns->ids[IPC_MSG_IDS]); |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 128 | kfree(ns->ids[IPC_MSG_IDS]); |
| 129 | ns->ids[IPC_MSG_IDS] = NULL; |
| 130 | } |
| 131 | #endif |
| 132 | |
| 133 | void __init msg_init(void) |
| 134 | { |
| 135 | __msg_init_ns(&init_ipc_ns, &init_msg_ids); |
| 136 | ipc_init_proc_interface("sysvipc/msg", |
| 137 | " key msqid perms cbytes qnum lspid lrpid uid gid cuid cgid stime rtime ctime\n", |
| 138 | IPC_MSG_IDS, sysvipc_msg_proc_show); |
| 139 | } |
| 140 | |
| 141 | static int newque (struct ipc_namespace *ns, key_t key, int msgflg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | struct msg_queue *msq; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 144 | int id, retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 146 | msq = ipc_rcu_alloc(sizeof(*msq)); |
| 147 | if (!msq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | return -ENOMEM; |
| 149 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 150 | msq->q_perm.mode = msgflg & S_IRWXUGO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | msq->q_perm.key = key; |
| 152 | |
| 153 | msq->q_perm.security = NULL; |
| 154 | retval = security_msg_queue_alloc(msq); |
| 155 | if (retval) { |
| 156 | ipc_rcu_putref(msq); |
| 157 | return retval; |
| 158 | } |
| 159 | |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 160 | id = ipc_addid(&msg_ids(ns), &msq->q_perm, ns->msg_ctlmni); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 161 | if (id == -1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | security_msg_queue_free(msq); |
| 163 | ipc_rcu_putref(msq); |
| 164 | return -ENOSPC; |
| 165 | } |
| 166 | |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 167 | msq->q_id = msg_buildid(ns, id, msq->q_perm.seq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | msq->q_stime = msq->q_rtime = 0; |
| 169 | msq->q_ctime = get_seconds(); |
| 170 | msq->q_cbytes = msq->q_qnum = 0; |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 171 | msq->q_qbytes = ns->msg_ctlmnb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | msq->q_lspid = msq->q_lrpid = 0; |
| 173 | INIT_LIST_HEAD(&msq->q_messages); |
| 174 | INIT_LIST_HEAD(&msq->q_receivers); |
| 175 | INIT_LIST_HEAD(&msq->q_senders); |
| 176 | msg_unlock(msq); |
| 177 | |
Mike Waychison | 19b4946 | 2005-09-06 15:17:10 -0700 | [diff] [blame] | 178 | return msq->q_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 181 | static inline void ss_add(struct msg_queue *msq, struct msg_sender *mss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 183 | mss->tsk = current; |
| 184 | current->state = TASK_INTERRUPTIBLE; |
| 185 | list_add_tail(&mss->list, &msq->q_senders); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 188 | static inline void ss_del(struct msg_sender *mss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 190 | if (mss->list.next != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | list_del(&mss->list); |
| 192 | } |
| 193 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 194 | static void ss_wakeup(struct list_head *h, int kill) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | { |
| 196 | struct list_head *tmp; |
| 197 | |
| 198 | tmp = h->next; |
| 199 | while (tmp != h) { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 200 | struct msg_sender *mss; |
| 201 | |
| 202 | mss = list_entry(tmp, struct msg_sender, list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | tmp = tmp->next; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 204 | if (kill) |
| 205 | mss->list.next = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | wake_up_process(mss->tsk); |
| 207 | } |
| 208 | } |
| 209 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 210 | static void expunge_all(struct msg_queue *msq, int res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { |
| 212 | struct list_head *tmp; |
| 213 | |
| 214 | tmp = msq->q_receivers.next; |
| 215 | while (tmp != &msq->q_receivers) { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 216 | struct msg_receiver *msr; |
| 217 | |
| 218 | msr = list_entry(tmp, struct msg_receiver, r_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | tmp = tmp->next; |
| 220 | msr->r_msg = NULL; |
| 221 | wake_up_process(msr->r_tsk); |
| 222 | smp_mb(); |
| 223 | msr->r_msg = ERR_PTR(res); |
| 224 | } |
| 225 | } |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 226 | |
| 227 | /* |
| 228 | * freeque() wakes up waiters on the sender and receiver waiting queue, |
| 229 | * removes the message queue from message queue ID |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | * array, and cleans up all the messages associated with this queue. |
| 231 | * |
Ingo Molnar | 5f921ae | 2006-03-26 01:37:17 -0800 | [diff] [blame] | 232 | * msg_ids.mutex and the spinlock for this message queue is hold |
| 233 | * before freeque() is called. msg_ids.mutex remains locked on exit. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | */ |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 235 | static void freeque(struct ipc_namespace *ns, struct msg_queue *msq, int id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { |
| 237 | struct list_head *tmp; |
| 238 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 239 | expunge_all(msq, -EIDRM); |
| 240 | ss_wakeup(&msq->q_senders, 1); |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 241 | msq = msg_rmid(ns, id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | msg_unlock(msq); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | tmp = msq->q_messages.next; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 245 | while (tmp != &msq->q_messages) { |
| 246 | struct msg_msg *msg = list_entry(tmp, struct msg_msg, m_list); |
| 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | tmp = tmp->next; |
| 249 | atomic_dec(&msg_hdrs); |
| 250 | free_msg(msg); |
| 251 | } |
| 252 | atomic_sub(msq->q_cbytes, &msg_bytes); |
| 253 | security_msg_queue_free(msq); |
| 254 | ipc_rcu_putref(msq); |
| 255 | } |
| 256 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 257 | asmlinkage long sys_msgget(key_t key, int msgflg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | struct msg_queue *msq; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 260 | int id, ret = -EPERM; |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 261 | struct ipc_namespace *ns; |
| 262 | |
| 263 | ns = current->nsproxy->ipc_ns; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 265 | mutex_lock(&msg_ids(ns).mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | if (key == IPC_PRIVATE) |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 267 | ret = newque(ns, key, msgflg); |
| 268 | else if ((id = ipc_findkey(&msg_ids(ns), key)) == -1) { /* key not used */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | if (!(msgflg & IPC_CREAT)) |
| 270 | ret = -ENOENT; |
| 271 | else |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 272 | ret = newque(ns, key, msgflg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | } else if (msgflg & IPC_CREAT && msgflg & IPC_EXCL) { |
| 274 | ret = -EEXIST; |
| 275 | } else { |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 276 | msq = msg_lock(ns, id); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 277 | BUG_ON(msq == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | if (ipcperms(&msq->q_perm, msgflg)) |
| 279 | ret = -EACCES; |
| 280 | else { |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 281 | int qid = msg_buildid(ns, id, msq->q_perm.seq); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 282 | |
| 283 | ret = security_msg_queue_associate(msq, msgflg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | if (!ret) |
| 285 | ret = qid; |
| 286 | } |
| 287 | msg_unlock(msq); |
| 288 | } |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 289 | mutex_unlock(&msg_ids(ns).mutex); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | return ret; |
| 292 | } |
| 293 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 294 | static inline unsigned long |
| 295 | copy_msqid_to_user(void __user *buf, struct msqid64_ds *in, int version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | { |
| 297 | switch(version) { |
| 298 | case IPC_64: |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 299 | return copy_to_user(buf, in, sizeof(*in)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | case IPC_OLD: |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 301 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | struct msqid_ds out; |
| 303 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 304 | memset(&out, 0, sizeof(out)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
| 306 | ipc64_perm_to_ipc_perm(&in->msg_perm, &out.msg_perm); |
| 307 | |
| 308 | out.msg_stime = in->msg_stime; |
| 309 | out.msg_rtime = in->msg_rtime; |
| 310 | out.msg_ctime = in->msg_ctime; |
| 311 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 312 | if (in->msg_cbytes > USHRT_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | out.msg_cbytes = USHRT_MAX; |
| 314 | else |
| 315 | out.msg_cbytes = in->msg_cbytes; |
| 316 | out.msg_lcbytes = in->msg_cbytes; |
| 317 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 318 | if (in->msg_qnum > USHRT_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | out.msg_qnum = USHRT_MAX; |
| 320 | else |
| 321 | out.msg_qnum = in->msg_qnum; |
| 322 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 323 | if (in->msg_qbytes > USHRT_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | out.msg_qbytes = USHRT_MAX; |
| 325 | else |
| 326 | out.msg_qbytes = in->msg_qbytes; |
| 327 | out.msg_lqbytes = in->msg_qbytes; |
| 328 | |
| 329 | out.msg_lspid = in->msg_lspid; |
| 330 | out.msg_lrpid = in->msg_lrpid; |
| 331 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 332 | return copy_to_user(buf, &out, sizeof(out)); |
| 333 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | default: |
| 335 | return -EINVAL; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | struct msq_setbuf { |
| 340 | unsigned long qbytes; |
| 341 | uid_t uid; |
| 342 | gid_t gid; |
| 343 | mode_t mode; |
| 344 | }; |
| 345 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 346 | static inline unsigned long |
| 347 | copy_msqid_from_user(struct msq_setbuf *out, void __user *buf, int version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | { |
| 349 | switch(version) { |
| 350 | case IPC_64: |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 351 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | struct msqid64_ds tbuf; |
| 353 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 354 | if (copy_from_user(&tbuf, buf, sizeof(tbuf))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | return -EFAULT; |
| 356 | |
| 357 | out->qbytes = tbuf.msg_qbytes; |
| 358 | out->uid = tbuf.msg_perm.uid; |
| 359 | out->gid = tbuf.msg_perm.gid; |
| 360 | out->mode = tbuf.msg_perm.mode; |
| 361 | |
| 362 | return 0; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 363 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | case IPC_OLD: |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 365 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | struct msqid_ds tbuf_old; |
| 367 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 368 | if (copy_from_user(&tbuf_old, buf, sizeof(tbuf_old))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | return -EFAULT; |
| 370 | |
| 371 | out->uid = tbuf_old.msg_perm.uid; |
| 372 | out->gid = tbuf_old.msg_perm.gid; |
| 373 | out->mode = tbuf_old.msg_perm.mode; |
| 374 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 375 | if (tbuf_old.msg_qbytes == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | out->qbytes = tbuf_old.msg_lqbytes; |
| 377 | else |
| 378 | out->qbytes = tbuf_old.msg_qbytes; |
| 379 | |
| 380 | return 0; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 381 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | default: |
| 383 | return -EINVAL; |
| 384 | } |
| 385 | } |
| 386 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 387 | asmlinkage long sys_msgctl(int msqid, int cmd, struct msqid_ds __user *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | struct kern_ipc_perm *ipcp; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 390 | struct msq_setbuf setbuf; |
| 391 | struct msg_queue *msq; |
| 392 | int err, version; |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 393 | struct ipc_namespace *ns; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | if (msqid < 0 || cmd < 0) |
| 396 | return -EINVAL; |
| 397 | |
| 398 | version = ipc_parse_version(&cmd); |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 399 | ns = current->nsproxy->ipc_ns; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
| 401 | switch (cmd) { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 402 | case IPC_INFO: |
| 403 | case MSG_INFO: |
| 404 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | struct msginfo msginfo; |
| 406 | int max_id; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | if (!buf) |
| 409 | return -EFAULT; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 410 | /* |
| 411 | * We must not return kernel stack data. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | * due to padding, it's not enough |
| 413 | * to set all member fields. |
| 414 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | err = security_msg_queue_msgctl(NULL, cmd); |
| 416 | if (err) |
| 417 | return err; |
| 418 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 419 | memset(&msginfo, 0, sizeof(msginfo)); |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 420 | msginfo.msgmni = ns->msg_ctlmni; |
| 421 | msginfo.msgmax = ns->msg_ctlmax; |
| 422 | msginfo.msgmnb = ns->msg_ctlmnb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | msginfo.msgssz = MSGSSZ; |
| 424 | msginfo.msgseg = MSGSEG; |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 425 | mutex_lock(&msg_ids(ns).mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | if (cmd == MSG_INFO) { |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 427 | msginfo.msgpool = msg_ids(ns).in_use; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | msginfo.msgmap = atomic_read(&msg_hdrs); |
| 429 | msginfo.msgtql = atomic_read(&msg_bytes); |
| 430 | } else { |
| 431 | msginfo.msgmap = MSGMAP; |
| 432 | msginfo.msgpool = MSGPOOL; |
| 433 | msginfo.msgtql = MSGTQL; |
| 434 | } |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 435 | max_id = msg_ids(ns).max_id; |
| 436 | mutex_unlock(&msg_ids(ns).mutex); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 437 | if (copy_to_user(buf, &msginfo, sizeof(struct msginfo))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | return -EFAULT; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 439 | return (max_id < 0) ? 0 : max_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | } |
| 441 | case MSG_STAT: |
| 442 | case IPC_STAT: |
| 443 | { |
| 444 | struct msqid64_ds tbuf; |
| 445 | int success_return; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | if (!buf) |
| 448 | return -EFAULT; |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 449 | if (cmd == MSG_STAT && msqid >= msg_ids(ns).entries->size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | return -EINVAL; |
| 451 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 452 | memset(&tbuf, 0, sizeof(tbuf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 454 | msq = msg_lock(ns, msqid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | if (msq == NULL) |
| 456 | return -EINVAL; |
| 457 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 458 | if (cmd == MSG_STAT) { |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 459 | success_return = msg_buildid(ns, msqid, msq->q_perm.seq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | } else { |
| 461 | err = -EIDRM; |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 462 | if (msg_checkid(ns, msq, msqid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | goto out_unlock; |
| 464 | success_return = 0; |
| 465 | } |
| 466 | err = -EACCES; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 467 | if (ipcperms(&msq->q_perm, S_IRUGO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | goto out_unlock; |
| 469 | |
| 470 | err = security_msg_queue_msgctl(msq, cmd); |
| 471 | if (err) |
| 472 | goto out_unlock; |
| 473 | |
| 474 | kernel_to_ipc64_perm(&msq->q_perm, &tbuf.msg_perm); |
| 475 | tbuf.msg_stime = msq->q_stime; |
| 476 | tbuf.msg_rtime = msq->q_rtime; |
| 477 | tbuf.msg_ctime = msq->q_ctime; |
| 478 | tbuf.msg_cbytes = msq->q_cbytes; |
| 479 | tbuf.msg_qnum = msq->q_qnum; |
| 480 | tbuf.msg_qbytes = msq->q_qbytes; |
| 481 | tbuf.msg_lspid = msq->q_lspid; |
| 482 | tbuf.msg_lrpid = msq->q_lrpid; |
| 483 | msg_unlock(msq); |
| 484 | if (copy_msqid_to_user(buf, &tbuf, version)) |
| 485 | return -EFAULT; |
| 486 | return success_return; |
| 487 | } |
| 488 | case IPC_SET: |
| 489 | if (!buf) |
| 490 | return -EFAULT; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 491 | if (copy_msqid_from_user(&setbuf, buf, version)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | break; |
| 494 | case IPC_RMID: |
| 495 | break; |
| 496 | default: |
| 497 | return -EINVAL; |
| 498 | } |
| 499 | |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 500 | mutex_lock(&msg_ids(ns).mutex); |
| 501 | msq = msg_lock(ns, msqid); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 502 | err = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | if (msq == NULL) |
| 504 | goto out_up; |
| 505 | |
| 506 | err = -EIDRM; |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 507 | if (msg_checkid(ns, msq, msqid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | goto out_unlock_up; |
| 509 | ipcp = &msq->q_perm; |
Steve Grubb | 073115d | 2006-04-02 17:07:33 -0400 | [diff] [blame] | 510 | |
| 511 | err = audit_ipc_obj(ipcp); |
| 512 | if (err) |
| 513 | goto out_unlock_up; |
Linda Knippers | ac03221 | 2006-05-16 22:03:48 -0400 | [diff] [blame] | 514 | if (cmd==IPC_SET) { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 515 | err = audit_ipc_set_perm(setbuf.qbytes, setbuf.uid, setbuf.gid, |
| 516 | setbuf.mode); |
Linda Knippers | ac03221 | 2006-05-16 22:03:48 -0400 | [diff] [blame] | 517 | if (err) |
| 518 | goto out_unlock_up; |
| 519 | } |
Steve Grubb | 073115d | 2006-04-02 17:07:33 -0400 | [diff] [blame] | 520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | err = -EPERM; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 522 | if (current->euid != ipcp->cuid && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | current->euid != ipcp->uid && !capable(CAP_SYS_ADMIN)) |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 524 | /* We _could_ check for CAP_CHOWN above, but we don't */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | goto out_unlock_up; |
| 526 | |
| 527 | err = security_msg_queue_msgctl(msq, cmd); |
| 528 | if (err) |
| 529 | goto out_unlock_up; |
| 530 | |
| 531 | switch (cmd) { |
| 532 | case IPC_SET: |
| 533 | { |
| 534 | err = -EPERM; |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 535 | if (setbuf.qbytes > ns->msg_ctlmnb && !capable(CAP_SYS_RESOURCE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | goto out_unlock_up; |
| 537 | |
| 538 | msq->q_qbytes = setbuf.qbytes; |
| 539 | |
| 540 | ipcp->uid = setbuf.uid; |
| 541 | ipcp->gid = setbuf.gid; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 542 | ipcp->mode = (ipcp->mode & ~S_IRWXUGO) | |
| 543 | (S_IRWXUGO & setbuf.mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | msq->q_ctime = get_seconds(); |
| 545 | /* sleeping receivers might be excluded by |
| 546 | * stricter permissions. |
| 547 | */ |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 548 | expunge_all(msq, -EAGAIN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | /* sleeping senders might be able to send |
| 550 | * due to a larger queue size. |
| 551 | */ |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 552 | ss_wakeup(&msq->q_senders, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | msg_unlock(msq); |
| 554 | break; |
| 555 | } |
| 556 | case IPC_RMID: |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 557 | freeque(ns, msq, msqid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | break; |
| 559 | } |
| 560 | err = 0; |
| 561 | out_up: |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 562 | mutex_unlock(&msg_ids(ns).mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | return err; |
| 564 | out_unlock_up: |
| 565 | msg_unlock(msq); |
| 566 | goto out_up; |
| 567 | out_unlock: |
| 568 | msg_unlock(msq); |
| 569 | return err; |
| 570 | } |
| 571 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 572 | static int testmsg(struct msg_msg *msg, long type, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | { |
| 574 | switch(mode) |
| 575 | { |
| 576 | case SEARCH_ANY: |
| 577 | return 1; |
| 578 | case SEARCH_LESSEQUAL: |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 579 | if (msg->m_type <=type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | return 1; |
| 581 | break; |
| 582 | case SEARCH_EQUAL: |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 583 | if (msg->m_type == type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | return 1; |
| 585 | break; |
| 586 | case SEARCH_NOTEQUAL: |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 587 | if (msg->m_type != type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | return 1; |
| 589 | break; |
| 590 | } |
| 591 | return 0; |
| 592 | } |
| 593 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 594 | static inline int pipelined_send(struct msg_queue *msq, struct msg_msg *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 596 | struct list_head *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
| 598 | tmp = msq->q_receivers.next; |
| 599 | while (tmp != &msq->q_receivers) { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 600 | struct msg_receiver *msr; |
| 601 | |
| 602 | msr = list_entry(tmp, struct msg_receiver, r_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | tmp = tmp->next; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 604 | if (testmsg(msg, msr->r_msgtype, msr->r_mode) && |
| 605 | !security_msg_queue_msgrcv(msq, msg, msr->r_tsk, |
| 606 | msr->r_msgtype, msr->r_mode)) { |
| 607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | list_del(&msr->r_list); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 609 | if (msr->r_maxsize < msg->m_ts) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | msr->r_msg = NULL; |
| 611 | wake_up_process(msr->r_tsk); |
| 612 | smp_mb(); |
| 613 | msr->r_msg = ERR_PTR(-E2BIG); |
| 614 | } else { |
| 615 | msr->r_msg = NULL; |
| 616 | msq->q_lrpid = msr->r_tsk->pid; |
| 617 | msq->q_rtime = get_seconds(); |
| 618 | wake_up_process(msr->r_tsk); |
| 619 | smp_mb(); |
| 620 | msr->r_msg = msg; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | return 1; |
| 623 | } |
| 624 | } |
| 625 | } |
| 626 | return 0; |
| 627 | } |
| 628 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 629 | asmlinkage long |
| 630 | sys_msgsnd(int msqid, struct msgbuf __user *msgp, size_t msgsz, int msgflg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | { |
| 632 | struct msg_queue *msq; |
| 633 | struct msg_msg *msg; |
| 634 | long mtype; |
| 635 | int err; |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 636 | struct ipc_namespace *ns; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 637 | |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 638 | ns = current->nsproxy->ipc_ns; |
| 639 | |
| 640 | if (msgsz > ns->msg_ctlmax || (long) msgsz < 0 || msqid < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | return -EINVAL; |
| 642 | if (get_user(mtype, &msgp->mtype)) |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 643 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | if (mtype < 1) |
| 645 | return -EINVAL; |
| 646 | |
| 647 | msg = load_msg(msgp->mtext, msgsz); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 648 | if (IS_ERR(msg)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | return PTR_ERR(msg); |
| 650 | |
| 651 | msg->m_type = mtype; |
| 652 | msg->m_ts = msgsz; |
| 653 | |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 654 | msq = msg_lock(ns, msqid); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 655 | err = -EINVAL; |
| 656 | if (msq == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | goto out_free; |
| 658 | |
| 659 | err= -EIDRM; |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 660 | if (msg_checkid(ns, msq, msqid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | goto out_unlock_free; |
| 662 | |
| 663 | for (;;) { |
| 664 | struct msg_sender s; |
| 665 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 666 | err = -EACCES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | if (ipcperms(&msq->q_perm, S_IWUGO)) |
| 668 | goto out_unlock_free; |
| 669 | |
| 670 | err = security_msg_queue_msgsnd(msq, msg, msgflg); |
| 671 | if (err) |
| 672 | goto out_unlock_free; |
| 673 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 674 | if (msgsz + msq->q_cbytes <= msq->q_qbytes && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | 1 + msq->q_qnum <= msq->q_qbytes) { |
| 676 | break; |
| 677 | } |
| 678 | |
| 679 | /* queue full, wait: */ |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 680 | if (msgflg & IPC_NOWAIT) { |
| 681 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | goto out_unlock_free; |
| 683 | } |
| 684 | ss_add(msq, &s); |
| 685 | ipc_rcu_getref(msq); |
| 686 | msg_unlock(msq); |
| 687 | schedule(); |
| 688 | |
| 689 | ipc_lock_by_ptr(&msq->q_perm); |
| 690 | ipc_rcu_putref(msq); |
| 691 | if (msq->q_perm.deleted) { |
| 692 | err = -EIDRM; |
| 693 | goto out_unlock_free; |
| 694 | } |
| 695 | ss_del(&s); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | if (signal_pending(current)) { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 698 | err = -ERESTARTNOHAND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | goto out_unlock_free; |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | msq->q_lspid = current->tgid; |
| 704 | msq->q_stime = get_seconds(); |
| 705 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 706 | if (!pipelined_send(msq, msg)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | /* noone is waiting for this message, enqueue it */ |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 708 | list_add_tail(&msg->m_list, &msq->q_messages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | msq->q_cbytes += msgsz; |
| 710 | msq->q_qnum++; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 711 | atomic_add(msgsz, &msg_bytes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | atomic_inc(&msg_hdrs); |
| 713 | } |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | err = 0; |
| 716 | msg = NULL; |
| 717 | |
| 718 | out_unlock_free: |
| 719 | msg_unlock(msq); |
| 720 | out_free: |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 721 | if (msg != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | free_msg(msg); |
| 723 | return err; |
| 724 | } |
| 725 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 726 | static inline int convert_mode(long *msgtyp, int msgflg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 728 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | * find message of correct type. |
| 730 | * msgtyp = 0 => get first. |
| 731 | * msgtyp > 0 => get first message of matching type. |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 732 | * msgtyp < 0 => get message with least type must be < abs(msgtype). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | */ |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 734 | if (*msgtyp == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | return SEARCH_ANY; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 736 | if (*msgtyp < 0) { |
| 737 | *msgtyp = -*msgtyp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | return SEARCH_LESSEQUAL; |
| 739 | } |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 740 | if (msgflg & MSG_EXCEPT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | return SEARCH_NOTEQUAL; |
| 742 | return SEARCH_EQUAL; |
| 743 | } |
| 744 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 745 | asmlinkage long sys_msgrcv(int msqid, struct msgbuf __user *msgp, size_t msgsz, |
| 746 | long msgtyp, int msgflg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | { |
| 748 | struct msg_queue *msq; |
| 749 | struct msg_msg *msg; |
| 750 | int mode; |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 751 | struct ipc_namespace *ns; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
| 753 | if (msqid < 0 || (long) msgsz < 0) |
| 754 | return -EINVAL; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 755 | mode = convert_mode(&msgtyp, msgflg); |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 756 | ns = current->nsproxy->ipc_ns; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 758 | msq = msg_lock(ns, msqid); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 759 | if (msq == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | return -EINVAL; |
| 761 | |
| 762 | msg = ERR_PTR(-EIDRM); |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 763 | if (msg_checkid(ns, msq, msqid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | goto out_unlock; |
| 765 | |
| 766 | for (;;) { |
| 767 | struct msg_receiver msr_d; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 768 | struct list_head *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | |
| 770 | msg = ERR_PTR(-EACCES); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 771 | if (ipcperms(&msq->q_perm, S_IRUGO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | goto out_unlock; |
| 773 | |
| 774 | msg = ERR_PTR(-EAGAIN); |
| 775 | tmp = msq->q_messages.next; |
| 776 | while (tmp != &msq->q_messages) { |
| 777 | struct msg_msg *walk_msg; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 778 | |
| 779 | walk_msg = list_entry(tmp, struct msg_msg, m_list); |
| 780 | if (testmsg(walk_msg, msgtyp, mode) && |
| 781 | !security_msg_queue_msgrcv(msq, walk_msg, current, |
| 782 | msgtyp, mode)) { |
| 783 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | msg = walk_msg; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 785 | if (mode == SEARCH_LESSEQUAL && |
| 786 | walk_msg->m_type != 1) { |
| 787 | msg = walk_msg; |
| 788 | msgtyp = walk_msg->m_type - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | } else { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 790 | msg = walk_msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | break; |
| 792 | } |
| 793 | } |
| 794 | tmp = tmp->next; |
| 795 | } |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 796 | if (!IS_ERR(msg)) { |
| 797 | /* |
| 798 | * Found a suitable message. |
| 799 | * Unlink it from the queue. |
| 800 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | if ((msgsz < msg->m_ts) && !(msgflg & MSG_NOERROR)) { |
| 802 | msg = ERR_PTR(-E2BIG); |
| 803 | goto out_unlock; |
| 804 | } |
| 805 | list_del(&msg->m_list); |
| 806 | msq->q_qnum--; |
| 807 | msq->q_rtime = get_seconds(); |
| 808 | msq->q_lrpid = current->tgid; |
| 809 | msq->q_cbytes -= msg->m_ts; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 810 | atomic_sub(msg->m_ts, &msg_bytes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | atomic_dec(&msg_hdrs); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 812 | ss_wakeup(&msq->q_senders, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | msg_unlock(msq); |
| 814 | break; |
| 815 | } |
| 816 | /* No message waiting. Wait for a message */ |
| 817 | if (msgflg & IPC_NOWAIT) { |
| 818 | msg = ERR_PTR(-ENOMSG); |
| 819 | goto out_unlock; |
| 820 | } |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 821 | list_add_tail(&msr_d.r_list, &msq->q_receivers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | msr_d.r_tsk = current; |
| 823 | msr_d.r_msgtype = msgtyp; |
| 824 | msr_d.r_mode = mode; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 825 | if (msgflg & MSG_NOERROR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | msr_d.r_maxsize = INT_MAX; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 827 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | msr_d.r_maxsize = msgsz; |
| 829 | msr_d.r_msg = ERR_PTR(-EAGAIN); |
| 830 | current->state = TASK_INTERRUPTIBLE; |
| 831 | msg_unlock(msq); |
| 832 | |
| 833 | schedule(); |
| 834 | |
| 835 | /* Lockless receive, part 1: |
| 836 | * Disable preemption. We don't hold a reference to the queue |
| 837 | * and getting a reference would defeat the idea of a lockless |
| 838 | * operation, thus the code relies on rcu to guarantee the |
| 839 | * existance of msq: |
| 840 | * Prior to destruction, expunge_all(-EIRDM) changes r_msg. |
| 841 | * Thus if r_msg is -EAGAIN, then the queue not yet destroyed. |
| 842 | * rcu_read_lock() prevents preemption between reading r_msg |
| 843 | * and the spin_lock() inside ipc_lock_by_ptr(). |
| 844 | */ |
| 845 | rcu_read_lock(); |
| 846 | |
| 847 | /* Lockless receive, part 2: |
| 848 | * Wait until pipelined_send or expunge_all are outside of |
| 849 | * wake_up_process(). There is a race with exit(), see |
| 850 | * ipc/mqueue.c for the details. |
| 851 | */ |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 852 | msg = (struct msg_msg*)msr_d.r_msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | while (msg == NULL) { |
| 854 | cpu_relax(); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 855 | msg = (struct msg_msg *)msr_d.r_msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | /* Lockless receive, part 3: |
| 859 | * If there is a message or an error then accept it without |
| 860 | * locking. |
| 861 | */ |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 862 | if (msg != ERR_PTR(-EAGAIN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | rcu_read_unlock(); |
| 864 | break; |
| 865 | } |
| 866 | |
| 867 | /* Lockless receive, part 3: |
| 868 | * Acquire the queue spinlock. |
| 869 | */ |
| 870 | ipc_lock_by_ptr(&msq->q_perm); |
| 871 | rcu_read_unlock(); |
| 872 | |
| 873 | /* Lockless receive, part 4: |
| 874 | * Repeat test after acquiring the spinlock. |
| 875 | */ |
| 876 | msg = (struct msg_msg*)msr_d.r_msg; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 877 | if (msg != ERR_PTR(-EAGAIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | goto out_unlock; |
| 879 | |
| 880 | list_del(&msr_d.r_list); |
| 881 | if (signal_pending(current)) { |
| 882 | msg = ERR_PTR(-ERESTARTNOHAND); |
| 883 | out_unlock: |
| 884 | msg_unlock(msq); |
| 885 | break; |
| 886 | } |
| 887 | } |
| 888 | if (IS_ERR(msg)) |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 889 | return PTR_ERR(msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | |
| 891 | msgsz = (msgsz > msg->m_ts) ? msg->m_ts : msgsz; |
| 892 | if (put_user (msg->m_type, &msgp->mtype) || |
| 893 | store_msg(msgp->mtext, msg, msgsz)) { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 894 | msgsz = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | } |
| 896 | free_msg(msg); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | return msgsz; |
| 899 | } |
| 900 | |
| 901 | #ifdef CONFIG_PROC_FS |
Mike Waychison | 19b4946 | 2005-09-06 15:17:10 -0700 | [diff] [blame] | 902 | static int sysvipc_msg_proc_show(struct seq_file *s, void *it) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | { |
Mike Waychison | 19b4946 | 2005-09-06 15:17:10 -0700 | [diff] [blame] | 904 | struct msg_queue *msq = it; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | |
Mike Waychison | 19b4946 | 2005-09-06 15:17:10 -0700 | [diff] [blame] | 906 | return seq_printf(s, |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 907 | "%10d %10d %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %10lu %10lu %10lu\n", |
| 908 | msq->q_perm.key, |
| 909 | msq->q_id, |
| 910 | msq->q_perm.mode, |
| 911 | msq->q_cbytes, |
| 912 | msq->q_qnum, |
| 913 | msq->q_lspid, |
| 914 | msq->q_lrpid, |
| 915 | msq->q_perm.uid, |
| 916 | msq->q_perm.gid, |
| 917 | msq->q_perm.cuid, |
| 918 | msq->q_perm.cgid, |
| 919 | msq->q_stime, |
| 920 | msq->q_rtime, |
| 921 | msq->q_ctime); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | } |
| 923 | #endif |