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/msg.h> |
| 27 | #include <linux/spinlock.h> |
| 28 | #include <linux/init.h> |
Nadia Derbey | f7bf3df | 2008-04-29 01:00:39 -0700 | [diff] [blame] | 29 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Nadia Derbey | 3e148c7 | 2007-10-18 23:40:54 -0700 | [diff] [blame] | 37 | #include <linux/rwsem.h> |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 38 | #include <linux/nsproxy.h> |
Pavel Emelyanov | ae5e1b2 | 2008-02-08 04:18:22 -0800 | [diff] [blame] | 39 | #include <linux/ipc_namespace.h> |
Ingo Molnar | 5f921ae | 2006-03-26 01:37:17 -0800 | [diff] [blame] | 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <asm/current.h> |
Paul McQuade | 7153e40 | 2014-06-06 14:37:37 -0700 | [diff] [blame] | 42 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include "util.h" |
| 44 | |
Davidlohr Bueso | 4bb6657 | 2014-06-06 14:37:46 -0700 | [diff] [blame] | 45 | /* one msg_receiver structure for each sleeping receiver */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | struct msg_receiver { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 47 | struct list_head r_list; |
| 48 | struct task_struct *r_tsk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 50 | int r_mode; |
| 51 | long r_msgtype; |
| 52 | long r_maxsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 54 | struct msg_msg *r_msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | /* one msg_sender for each sleeping sender */ |
| 58 | struct msg_sender { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 59 | struct list_head list; |
| 60 | struct task_struct *tsk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | #define SEARCH_ANY 1 |
| 64 | #define SEARCH_EQUAL 2 |
| 65 | #define SEARCH_NOTEQUAL 3 |
| 66 | #define SEARCH_LESSEQUAL 4 |
Peter Hurley | 8ac6ed5 | 2013-04-30 19:14:54 -0700 | [diff] [blame] | 67 | #define SEARCH_NUMBER 5 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Pierre Peiffer | ed2ddbf | 2008-02-08 04:18:57 -0800 | [diff] [blame] | 69 | #define msg_ids(ns) ((ns)->ids[IPC_MSG_IDS]) |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 70 | |
Davidlohr Bueso | a5001a0 | 2013-07-08 16:01:15 -0700 | [diff] [blame] | 71 | static inline struct msg_queue *msq_obtain_object(struct ipc_namespace *ns, int id) |
| 72 | { |
Davidlohr Bueso | 55b7ae5 | 2015-06-30 14:58:42 -0700 | [diff] [blame] | 73 | struct kern_ipc_perm *ipcp = ipc_obtain_object_idr(&msg_ids(ns), id); |
Davidlohr Bueso | a5001a0 | 2013-07-08 16:01:15 -0700 | [diff] [blame] | 74 | |
| 75 | if (IS_ERR(ipcp)) |
| 76 | return ERR_CAST(ipcp); |
| 77 | |
| 78 | return container_of(ipcp, struct msg_queue, q_perm); |
| 79 | } |
| 80 | |
| 81 | static inline struct msg_queue *msq_obtain_object_check(struct ipc_namespace *ns, |
| 82 | int id) |
| 83 | { |
| 84 | struct kern_ipc_perm *ipcp = ipc_obtain_object_check(&msg_ids(ns), id); |
| 85 | |
| 86 | if (IS_ERR(ipcp)) |
| 87 | return ERR_CAST(ipcp); |
| 88 | |
| 89 | return container_of(ipcp, struct msg_queue, q_perm); |
| 90 | } |
| 91 | |
Nadia Derbey | 7ca7e56 | 2007-10-18 23:40:48 -0700 | [diff] [blame] | 92 | static inline void msg_rmid(struct ipc_namespace *ns, struct msg_queue *s) |
| 93 | { |
| 94 | ipc_rmid(&msg_ids(ns), &s->q_perm); |
| 95 | } |
| 96 | |
Davidlohr Bueso | 53dad6d | 2013-09-23 17:04:45 -0700 | [diff] [blame] | 97 | static void msg_rcu_free(struct rcu_head *head) |
| 98 | { |
| 99 | struct ipc_rcu *p = container_of(head, struct ipc_rcu, rcu); |
| 100 | struct msg_queue *msq = ipc_rcu_to_struct(p); |
| 101 | |
| 102 | security_msg_queue_free(msq); |
| 103 | ipc_rcu_free(head); |
| 104 | } |
| 105 | |
Nadia Derbey | f4566f0 | 2007-10-18 23:40:53 -0700 | [diff] [blame] | 106 | /** |
| 107 | * newque - Create a new msg queue |
| 108 | * @ns: namespace |
| 109 | * @params: ptr to the structure that contains the key and msgflg |
| 110 | * |
Davidlohr Bueso | d9a605e | 2013-09-11 14:26:24 -0700 | [diff] [blame] | 111 | * Called with msg_ids.rwsem held (writer) |
Nadia Derbey | f4566f0 | 2007-10-18 23:40:53 -0700 | [diff] [blame] | 112 | */ |
Nadia Derbey | 7748dbf | 2007-10-18 23:40:49 -0700 | [diff] [blame] | 113 | static int newque(struct ipc_namespace *ns, struct ipc_params *params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | struct msg_queue *msq; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 116 | int id, retval; |
Nadia Derbey | 7748dbf | 2007-10-18 23:40:49 -0700 | [diff] [blame] | 117 | key_t key = params->key; |
| 118 | int msgflg = params->flg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 120 | msq = ipc_rcu_alloc(sizeof(*msq)); |
| 121 | if (!msq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | return -ENOMEM; |
| 123 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 124 | msq->q_perm.mode = msgflg & S_IRWXUGO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | msq->q_perm.key = key; |
| 126 | |
| 127 | msq->q_perm.security = NULL; |
| 128 | retval = security_msg_queue_alloc(msq); |
| 129 | if (retval) { |
Davidlohr Bueso | 53dad6d | 2013-09-23 17:04:45 -0700 | [diff] [blame] | 130 | ipc_rcu_putref(msq, ipc_rcu_free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | return retval; |
| 132 | } |
| 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | msq->q_stime = msq->q_rtime = 0; |
| 135 | msq->q_ctime = get_seconds(); |
| 136 | msq->q_cbytes = msq->q_qnum = 0; |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 137 | msq->q_qbytes = ns->msg_ctlmnb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | msq->q_lspid = msq->q_lrpid = 0; |
| 139 | INIT_LIST_HEAD(&msq->q_messages); |
| 140 | INIT_LIST_HEAD(&msq->q_receivers); |
| 141 | INIT_LIST_HEAD(&msq->q_senders); |
Nadia Derbey | 7ca7e56 | 2007-10-18 23:40:48 -0700 | [diff] [blame] | 142 | |
Linus Torvalds | b9a5322 | 2015-09-30 12:48:40 -0400 | [diff] [blame] | 143 | /* ipc_addid() locks msq upon success. */ |
| 144 | id = ipc_addid(&msg_ids(ns), &msq->q_perm, ns->msg_ctlmni); |
| 145 | if (id < 0) { |
| 146 | ipc_rcu_putref(msq, msg_rcu_free); |
| 147 | return id; |
| 148 | } |
| 149 | |
Davidlohr Bueso | cf9d5d7 | 2013-07-08 16:01:11 -0700 | [diff] [blame] | 150 | ipc_unlock_object(&msq->q_perm); |
Davidlohr Bueso | dbfcd91 | 2013-07-08 16:01:09 -0700 | [diff] [blame] | 151 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Nadia Derbey | 7ca7e56 | 2007-10-18 23:40:48 -0700 | [diff] [blame] | 153 | return msq->q_perm.id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 156 | 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] | 157 | { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 158 | mss->tsk = current; |
Davidlohr Bueso | f75a2f3 | 2014-06-06 14:37:44 -0700 | [diff] [blame] | 159 | __set_current_state(TASK_INTERRUPTIBLE); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 160 | list_add_tail(&mss->list, &msq->q_senders); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 163 | static inline void ss_del(struct msg_sender *mss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 165 | if (mss->list.next != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | list_del(&mss->list); |
| 167 | } |
| 168 | |
Davidlohr Bueso | e365853 | 2016-10-11 13:54:56 -0700 | [diff] [blame] | 169 | static void ss_wakeup(struct list_head *h, |
Davidlohr Bueso | d0d6a2a | 2016-10-11 13:54:59 -0700 | [diff] [blame^] | 170 | struct wake_q_head *wake_q, bool kill) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
Nikola Pajkovsky | 41239fe | 2013-04-30 19:15:49 -0700 | [diff] [blame] | 172 | struct msg_sender *mss, *t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Nikola Pajkovsky | 41239fe | 2013-04-30 19:15:49 -0700 | [diff] [blame] | 174 | list_for_each_entry_safe(mss, t, h, list) { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 175 | if (kill) |
| 176 | mss->list.next = NULL; |
Davidlohr Bueso | e365853 | 2016-10-11 13:54:56 -0700 | [diff] [blame] | 177 | wake_q_add(wake_q, mss->tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 181 | static void expunge_all(struct msg_queue *msq, int res, |
| 182 | struct wake_q_head *wake_q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | { |
Nikola Pajkovsky | 41239fe | 2013-04-30 19:15:49 -0700 | [diff] [blame] | 184 | struct msg_receiver *msr, *t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Nikola Pajkovsky | 41239fe | 2013-04-30 19:15:49 -0700 | [diff] [blame] | 186 | list_for_each_entry_safe(msr, t, &msq->q_receivers, r_list) { |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 187 | wake_q_add(wake_q, msr->r_tsk); |
| 188 | WRITE_ONCE(msr->r_msg, ERR_PTR(res)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | } |
| 190 | } |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 191 | |
| 192 | /* |
| 193 | * freeque() wakes up waiters on the sender and receiver waiting queue, |
Nadia Derbey | f4566f0 | 2007-10-18 23:40:53 -0700 | [diff] [blame] | 194 | * removes the message queue from message queue ID IDR, and cleans up all the |
| 195 | * messages associated with this queue. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | * |
Davidlohr Bueso | d9a605e | 2013-09-11 14:26:24 -0700 | [diff] [blame] | 197 | * msg_ids.rwsem (writer) and the spinlock for this message queue are held |
| 198 | * before freeque() is called. msg_ids.rwsem remains locked on exit. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | */ |
Pierre Peiffer | 01b8b07 | 2008-02-08 04:18:57 -0800 | [diff] [blame] | 200 | static void freeque(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
Nikola Pajkovsky | 41239fe | 2013-04-30 19:15:49 -0700 | [diff] [blame] | 202 | struct msg_msg *msg, *t; |
Pierre Peiffer | 01b8b07 | 2008-02-08 04:18:57 -0800 | [diff] [blame] | 203 | struct msg_queue *msq = container_of(ipcp, struct msg_queue, q_perm); |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 204 | WAKE_Q(wake_q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 206 | expunge_all(msq, -EIDRM, &wake_q); |
Davidlohr Bueso | d0d6a2a | 2016-10-11 13:54:59 -0700 | [diff] [blame^] | 207 | ss_wakeup(&msq->q_senders, &wake_q, true); |
Nadia Derbey | 7ca7e56 | 2007-10-18 23:40:48 -0700 | [diff] [blame] | 208 | msg_rmid(ns, msq); |
Davidlohr Bueso | 4718787 | 2013-09-11 14:26:25 -0700 | [diff] [blame] | 209 | ipc_unlock_object(&msq->q_perm); |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 210 | wake_up_q(&wake_q); |
Davidlohr Bueso | 4718787 | 2013-09-11 14:26:25 -0700 | [diff] [blame] | 211 | rcu_read_unlock(); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 212 | |
Nikola Pajkovsky | 41239fe | 2013-04-30 19:15:49 -0700 | [diff] [blame] | 213 | list_for_each_entry_safe(msg, t, &msq->q_messages, m_list) { |
Kirill Korotaev | 3ac88a4 | 2007-10-18 23:40:56 -0700 | [diff] [blame] | 214 | atomic_dec(&ns->msg_hdrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | free_msg(msg); |
| 216 | } |
Kirill Korotaev | 3ac88a4 | 2007-10-18 23:40:56 -0700 | [diff] [blame] | 217 | atomic_sub(msq->q_cbytes, &ns->msg_bytes); |
Davidlohr Bueso | 53dad6d | 2013-09-23 17:04:45 -0700 | [diff] [blame] | 218 | ipc_rcu_putref(msq, msg_rcu_free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Nadia Derbey | f4566f0 | 2007-10-18 23:40:53 -0700 | [diff] [blame] | 221 | /* |
Davidlohr Bueso | d9a605e | 2013-09-11 14:26:24 -0700 | [diff] [blame] | 222 | * Called with msg_ids.rwsem and ipcp locked. |
Nadia Derbey | f4566f0 | 2007-10-18 23:40:53 -0700 | [diff] [blame] | 223 | */ |
Nadia Derbey | 03f02c7 | 2007-10-18 23:40:51 -0700 | [diff] [blame] | 224 | static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg) |
Nadia Derbey | 7748dbf | 2007-10-18 23:40:49 -0700 | [diff] [blame] | 225 | { |
Nadia Derbey | 03f02c7 | 2007-10-18 23:40:51 -0700 | [diff] [blame] | 226 | struct msg_queue *msq = container_of(ipcp, struct msg_queue, q_perm); |
| 227 | |
| 228 | return security_msg_queue_associate(msq, msgflg); |
Nadia Derbey | 7748dbf | 2007-10-18 23:40:49 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Heiko Carstens | e48fbb6 | 2009-01-14 14:14:26 +0100 | [diff] [blame] | 231 | SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 233 | struct ipc_namespace *ns; |
Mathias Krause | eb66ec4 | 2014-06-06 14:37:36 -0700 | [diff] [blame] | 234 | static const struct ipc_ops msg_ops = { |
| 235 | .getnew = newque, |
| 236 | .associate = msg_security, |
| 237 | }; |
Nadia Derbey | 7748dbf | 2007-10-18 23:40:49 -0700 | [diff] [blame] | 238 | struct ipc_params msg_params; |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 239 | |
| 240 | ns = current->nsproxy->ipc_ns; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 241 | |
Nadia Derbey | 7748dbf | 2007-10-18 23:40:49 -0700 | [diff] [blame] | 242 | msg_params.key = key; |
| 243 | msg_params.flg = msgflg; |
Nadia Derbey | 7ca7e56 | 2007-10-18 23:40:48 -0700 | [diff] [blame] | 244 | |
Nadia Derbey | 7748dbf | 2007-10-18 23:40:49 -0700 | [diff] [blame] | 245 | return ipcget(ns, &msg_ids(ns), &msg_ops, &msg_params); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 248 | static inline unsigned long |
| 249 | 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] | 250 | { |
Manfred Spraul | 239521f | 2014-01-27 17:07:04 -0800 | [diff] [blame] | 251 | switch (version) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | case IPC_64: |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 253 | return copy_to_user(buf, in, sizeof(*in)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | case IPC_OLD: |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 255 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | struct msqid_ds out; |
| 257 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 258 | memset(&out, 0, sizeof(out)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
| 260 | ipc64_perm_to_ipc_perm(&in->msg_perm, &out.msg_perm); |
| 261 | |
| 262 | out.msg_stime = in->msg_stime; |
| 263 | out.msg_rtime = in->msg_rtime; |
| 264 | out.msg_ctime = in->msg_ctime; |
| 265 | |
Alexey Dobriyan | 4be929b | 2010-05-24 14:33:03 -0700 | [diff] [blame] | 266 | if (in->msg_cbytes > USHRT_MAX) |
| 267 | out.msg_cbytes = USHRT_MAX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | else |
| 269 | out.msg_cbytes = in->msg_cbytes; |
| 270 | out.msg_lcbytes = in->msg_cbytes; |
| 271 | |
Alexey Dobriyan | 4be929b | 2010-05-24 14:33:03 -0700 | [diff] [blame] | 272 | if (in->msg_qnum > USHRT_MAX) |
| 273 | out.msg_qnum = USHRT_MAX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | else |
| 275 | out.msg_qnum = in->msg_qnum; |
| 276 | |
Alexey Dobriyan | 4be929b | 2010-05-24 14:33:03 -0700 | [diff] [blame] | 277 | if (in->msg_qbytes > USHRT_MAX) |
| 278 | out.msg_qbytes = USHRT_MAX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | else |
| 280 | out.msg_qbytes = in->msg_qbytes; |
| 281 | out.msg_lqbytes = in->msg_qbytes; |
| 282 | |
| 283 | out.msg_lspid = in->msg_lspid; |
| 284 | out.msg_lrpid = in->msg_lrpid; |
| 285 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 286 | return copy_to_user(buf, &out, sizeof(out)); |
| 287 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | default: |
| 289 | return -EINVAL; |
| 290 | } |
| 291 | } |
| 292 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 293 | static inline unsigned long |
Pierre Peiffer | 016d713 | 2008-04-29 01:00:50 -0700 | [diff] [blame] | 294 | copy_msqid_from_user(struct msqid64_ds *out, void __user *buf, int version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | { |
Manfred Spraul | 239521f | 2014-01-27 17:07:04 -0800 | [diff] [blame] | 296 | switch (version) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | case IPC_64: |
Pierre Peiffer | 016d713 | 2008-04-29 01:00:50 -0700 | [diff] [blame] | 298 | if (copy_from_user(out, buf, sizeof(*out))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | case IPC_OLD: |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 302 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | struct msqid_ds tbuf_old; |
| 304 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 305 | if (copy_from_user(&tbuf_old, buf, sizeof(tbuf_old))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | return -EFAULT; |
| 307 | |
Manfred Spraul | 239521f | 2014-01-27 17:07:04 -0800 | [diff] [blame] | 308 | out->msg_perm.uid = tbuf_old.msg_perm.uid; |
| 309 | out->msg_perm.gid = tbuf_old.msg_perm.gid; |
| 310 | out->msg_perm.mode = tbuf_old.msg_perm.mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 312 | if (tbuf_old.msg_qbytes == 0) |
Pierre Peiffer | 016d713 | 2008-04-29 01:00:50 -0700 | [diff] [blame] | 313 | out->msg_qbytes = tbuf_old.msg_lqbytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | else |
Pierre Peiffer | 016d713 | 2008-04-29 01:00:50 -0700 | [diff] [blame] | 315 | out->msg_qbytes = tbuf_old.msg_qbytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
| 317 | return 0; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 318 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | default: |
| 320 | return -EINVAL; |
| 321 | } |
| 322 | } |
| 323 | |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 324 | /* |
Davidlohr Bueso | d9a605e | 2013-09-11 14:26:24 -0700 | [diff] [blame] | 325 | * This function handles some msgctl commands which require the rwsem |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 326 | * to be held in write mode. |
Davidlohr Bueso | d9a605e | 2013-09-11 14:26:24 -0700 | [diff] [blame] | 327 | * NOTE: no locks must be held, the rwsem is taken inside this function. |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 328 | */ |
| 329 | static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd, |
| 330 | struct msqid_ds __user *buf, int version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | struct kern_ipc_perm *ipcp; |
Felipe Contreras | f1970c4 | 2009-10-19 01:54:29 +0300 | [diff] [blame] | 333 | struct msqid64_ds uninitialized_var(msqid64); |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 334 | struct msg_queue *msq; |
| 335 | int err; |
| 336 | |
| 337 | if (cmd == IPC_SET) { |
Pierre Peiffer | 016d713 | 2008-04-29 01:00:50 -0700 | [diff] [blame] | 338 | if (copy_msqid_from_user(&msqid64, buf, version)) |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 339 | return -EFAULT; |
| 340 | } |
| 341 | |
Davidlohr Bueso | d9a605e | 2013-09-11 14:26:24 -0700 | [diff] [blame] | 342 | down_write(&msg_ids(ns).rwsem); |
Davidlohr Bueso | 7b4cc5d | 2013-07-08 16:01:12 -0700 | [diff] [blame] | 343 | rcu_read_lock(); |
| 344 | |
Davidlohr Bueso | 15724ec | 2013-07-08 16:01:13 -0700 | [diff] [blame] | 345 | ipcp = ipcctl_pre_down_nolock(ns, &msg_ids(ns), msqid, cmd, |
| 346 | &msqid64.msg_perm, msqid64.msg_qbytes); |
Davidlohr Bueso | 7b4cc5d | 2013-07-08 16:01:12 -0700 | [diff] [blame] | 347 | if (IS_ERR(ipcp)) { |
| 348 | err = PTR_ERR(ipcp); |
Davidlohr Bueso | 7b4cc5d | 2013-07-08 16:01:12 -0700 | [diff] [blame] | 349 | goto out_unlock1; |
| 350 | } |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 351 | |
Pierre Peiffer | a5f75e7 | 2008-04-29 01:00:54 -0700 | [diff] [blame] | 352 | msq = container_of(ipcp, struct msg_queue, q_perm); |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 353 | |
| 354 | err = security_msg_queue_msgctl(msq, cmd); |
| 355 | if (err) |
Davidlohr Bueso | 15724ec | 2013-07-08 16:01:13 -0700 | [diff] [blame] | 356 | goto out_unlock1; |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 357 | |
| 358 | switch (cmd) { |
| 359 | case IPC_RMID: |
Davidlohr Bueso | 15724ec | 2013-07-08 16:01:13 -0700 | [diff] [blame] | 360 | ipc_lock_object(&msq->q_perm); |
Davidlohr Bueso | 7b4cc5d | 2013-07-08 16:01:12 -0700 | [diff] [blame] | 361 | /* freeque unlocks the ipc object and rcu */ |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 362 | freeque(ns, ipcp); |
| 363 | goto out_up; |
| 364 | case IPC_SET: |
Davidlohr Bueso | e365853 | 2016-10-11 13:54:56 -0700 | [diff] [blame] | 365 | { |
| 366 | WAKE_Q(wake_q); |
| 367 | |
Pierre Peiffer | 016d713 | 2008-04-29 01:00:50 -0700 | [diff] [blame] | 368 | if (msqid64.msg_qbytes > ns->msg_ctlmnb && |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 369 | !capable(CAP_SYS_RESOURCE)) { |
| 370 | err = -EPERM; |
Davidlohr Bueso | 15724ec | 2013-07-08 16:01:13 -0700 | [diff] [blame] | 371 | goto out_unlock1; |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Davidlohr Bueso | 15724ec | 2013-07-08 16:01:13 -0700 | [diff] [blame] | 374 | ipc_lock_object(&msq->q_perm); |
Eric W. Biederman | 1efdb69 | 2012-02-07 16:54:11 -0800 | [diff] [blame] | 375 | err = ipc_update_perm(&msqid64.msg_perm, ipcp); |
| 376 | if (err) |
Davidlohr Bueso | 7b4cc5d | 2013-07-08 16:01:12 -0700 | [diff] [blame] | 377 | goto out_unlock0; |
Eric W. Biederman | 1efdb69 | 2012-02-07 16:54:11 -0800 | [diff] [blame] | 378 | |
Pierre Peiffer | 016d713 | 2008-04-29 01:00:50 -0700 | [diff] [blame] | 379 | msq->q_qbytes = msqid64.msg_qbytes; |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 380 | |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 381 | msq->q_ctime = get_seconds(); |
Davidlohr Bueso | e365853 | 2016-10-11 13:54:56 -0700 | [diff] [blame] | 382 | /* |
| 383 | * Sleeping receivers might be excluded by |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 384 | * stricter permissions. |
| 385 | */ |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 386 | expunge_all(msq, -EAGAIN, &wake_q); |
Davidlohr Bueso | e365853 | 2016-10-11 13:54:56 -0700 | [diff] [blame] | 387 | /* |
| 388 | * Sleeping senders might be able to send |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 389 | * due to a larger queue size. |
| 390 | */ |
Davidlohr Bueso | d0d6a2a | 2016-10-11 13:54:59 -0700 | [diff] [blame^] | 391 | ss_wakeup(&msq->q_senders, &wake_q, false); |
Davidlohr Bueso | e365853 | 2016-10-11 13:54:56 -0700 | [diff] [blame] | 392 | ipc_unlock_object(&msq->q_perm); |
| 393 | wake_up_q(&wake_q); |
| 394 | |
| 395 | goto out_unlock1; |
| 396 | } |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 397 | default: |
| 398 | err = -EINVAL; |
Davidlohr Bueso | 15724ec | 2013-07-08 16:01:13 -0700 | [diff] [blame] | 399 | goto out_unlock1; |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 400 | } |
Davidlohr Bueso | 7b4cc5d | 2013-07-08 16:01:12 -0700 | [diff] [blame] | 401 | |
| 402 | out_unlock0: |
| 403 | ipc_unlock_object(&msq->q_perm); |
| 404 | out_unlock1: |
| 405 | rcu_read_unlock(); |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 406 | out_up: |
Davidlohr Bueso | d9a605e | 2013-09-11 14:26:24 -0700 | [diff] [blame] | 407 | up_write(&msg_ids(ns).rwsem); |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 408 | return err; |
| 409 | } |
| 410 | |
Davidlohr Bueso | 2cafed3 | 2013-07-08 16:01:14 -0700 | [diff] [blame] | 411 | static int msgctl_nolock(struct ipc_namespace *ns, int msqid, |
| 412 | int cmd, int version, void __user *buf) |
Pierre Peiffer | a0d092f | 2008-04-29 01:00:48 -0700 | [diff] [blame] | 413 | { |
Davidlohr Bueso | 2cafed3 | 2013-07-08 16:01:14 -0700 | [diff] [blame] | 414 | int err; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 415 | struct msg_queue *msq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
| 417 | switch (cmd) { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 418 | case IPC_INFO: |
| 419 | case MSG_INFO: |
| 420 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | struct msginfo msginfo; |
| 422 | int max_id; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | if (!buf) |
| 425 | return -EFAULT; |
Davidlohr Bueso | 2cafed3 | 2013-07-08 16:01:14 -0700 | [diff] [blame] | 426 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 427 | /* |
| 428 | * We must not return kernel stack data. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | * due to padding, it's not enough |
| 430 | * to set all member fields. |
| 431 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | err = security_msg_queue_msgctl(NULL, cmd); |
| 433 | if (err) |
| 434 | return err; |
| 435 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 436 | memset(&msginfo, 0, sizeof(msginfo)); |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 437 | msginfo.msgmni = ns->msg_ctlmni; |
| 438 | msginfo.msgmax = ns->msg_ctlmax; |
| 439 | msginfo.msgmnb = ns->msg_ctlmnb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | msginfo.msgssz = MSGSSZ; |
| 441 | msginfo.msgseg = MSGSEG; |
Davidlohr Bueso | d9a605e | 2013-09-11 14:26:24 -0700 | [diff] [blame] | 442 | down_read(&msg_ids(ns).rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | if (cmd == MSG_INFO) { |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 444 | msginfo.msgpool = msg_ids(ns).in_use; |
Kirill Korotaev | 3ac88a4 | 2007-10-18 23:40:56 -0700 | [diff] [blame] | 445 | msginfo.msgmap = atomic_read(&ns->msg_hdrs); |
| 446 | msginfo.msgtql = atomic_read(&ns->msg_bytes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | } else { |
| 448 | msginfo.msgmap = MSGMAP; |
| 449 | msginfo.msgpool = MSGPOOL; |
| 450 | msginfo.msgtql = MSGTQL; |
| 451 | } |
Nadia Derbey | 7ca7e56 | 2007-10-18 23:40:48 -0700 | [diff] [blame] | 452 | max_id = ipc_get_maxid(&msg_ids(ns)); |
Davidlohr Bueso | d9a605e | 2013-09-11 14:26:24 -0700 | [diff] [blame] | 453 | up_read(&msg_ids(ns).rwsem); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 454 | if (copy_to_user(buf, &msginfo, sizeof(struct msginfo))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | return -EFAULT; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 456 | return (max_id < 0) ? 0 : max_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } |
Davidlohr Bueso | 2cafed3 | 2013-07-08 16:01:14 -0700 | [diff] [blame] | 458 | |
| 459 | case MSG_STAT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | case IPC_STAT: |
| 461 | { |
| 462 | struct msqid64_ds tbuf; |
| 463 | int success_return; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | if (!buf) |
| 466 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | |
Davidlohr Bueso | ac0ba20 | 2013-07-08 16:01:16 -0700 | [diff] [blame] | 468 | memset(&tbuf, 0, sizeof(tbuf)); |
| 469 | |
| 470 | rcu_read_lock(); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 471 | if (cmd == MSG_STAT) { |
Davidlohr Bueso | ac0ba20 | 2013-07-08 16:01:16 -0700 | [diff] [blame] | 472 | msq = msq_obtain_object(ns, msqid); |
| 473 | if (IS_ERR(msq)) { |
| 474 | err = PTR_ERR(msq); |
| 475 | goto out_unlock; |
| 476 | } |
Nadia Derbey | 7ca7e56 | 2007-10-18 23:40:48 -0700 | [diff] [blame] | 477 | success_return = msq->q_perm.id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | } else { |
Davidlohr Bueso | ac0ba20 | 2013-07-08 16:01:16 -0700 | [diff] [blame] | 479 | msq = msq_obtain_object_check(ns, msqid); |
| 480 | if (IS_ERR(msq)) { |
| 481 | err = PTR_ERR(msq); |
| 482 | goto out_unlock; |
| 483 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | success_return = 0; |
| 485 | } |
Davidlohr Bueso | ac0ba20 | 2013-07-08 16:01:16 -0700 | [diff] [blame] | 486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | err = -EACCES; |
Serge E. Hallyn | b0e7759 | 2011-03-23 16:43:24 -0700 | [diff] [blame] | 488 | if (ipcperms(ns, &msq->q_perm, S_IRUGO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | goto out_unlock; |
| 490 | |
| 491 | err = security_msg_queue_msgctl(msq, cmd); |
| 492 | if (err) |
| 493 | goto out_unlock; |
| 494 | |
| 495 | kernel_to_ipc64_perm(&msq->q_perm, &tbuf.msg_perm); |
| 496 | tbuf.msg_stime = msq->q_stime; |
| 497 | tbuf.msg_rtime = msq->q_rtime; |
| 498 | tbuf.msg_ctime = msq->q_ctime; |
| 499 | tbuf.msg_cbytes = msq->q_cbytes; |
| 500 | tbuf.msg_qnum = msq->q_qnum; |
| 501 | tbuf.msg_qbytes = msq->q_qbytes; |
| 502 | tbuf.msg_lspid = msq->q_lspid; |
| 503 | tbuf.msg_lrpid = msq->q_lrpid; |
Davidlohr Bueso | ac0ba20 | 2013-07-08 16:01:16 -0700 | [diff] [blame] | 504 | rcu_read_unlock(); |
| 505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | if (copy_msqid_to_user(buf, &tbuf, version)) |
| 507 | return -EFAULT; |
| 508 | return success_return; |
| 509 | } |
Davidlohr Bueso | 2cafed3 | 2013-07-08 16:01:14 -0700 | [diff] [blame] | 510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | default: |
Davidlohr Bueso | 2cafed3 | 2013-07-08 16:01:14 -0700 | [diff] [blame] | 512 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Davidlohr Bueso | 2cafed3 | 2013-07-08 16:01:14 -0700 | [diff] [blame] | 515 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | out_unlock: |
Davidlohr Bueso | ac0ba20 | 2013-07-08 16:01:16 -0700 | [diff] [blame] | 517 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | return err; |
| 519 | } |
| 520 | |
Davidlohr Bueso | 2cafed3 | 2013-07-08 16:01:14 -0700 | [diff] [blame] | 521 | SYSCALL_DEFINE3(msgctl, int, msqid, int, cmd, struct msqid_ds __user *, buf) |
| 522 | { |
| 523 | int version; |
| 524 | struct ipc_namespace *ns; |
| 525 | |
| 526 | if (msqid < 0 || cmd < 0) |
| 527 | return -EINVAL; |
| 528 | |
| 529 | version = ipc_parse_version(&cmd); |
| 530 | ns = current->nsproxy->ipc_ns; |
| 531 | |
| 532 | switch (cmd) { |
| 533 | case IPC_INFO: |
| 534 | case MSG_INFO: |
| 535 | case MSG_STAT: /* msqid is an index rather than a msg queue id */ |
| 536 | case IPC_STAT: |
| 537 | return msgctl_nolock(ns, msqid, cmd, version, buf); |
| 538 | case IPC_SET: |
| 539 | case IPC_RMID: |
| 540 | return msgctl_down(ns, msqid, cmd, buf, version); |
| 541 | default: |
| 542 | return -EINVAL; |
| 543 | } |
| 544 | } |
| 545 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 546 | static int testmsg(struct msg_msg *msg, long type, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | { |
Paul McQuade | 46c0a8c | 2014-06-06 14:37:37 -0700 | [diff] [blame] | 548 | switch (mode) { |
| 549 | case SEARCH_ANY: |
| 550 | case SEARCH_NUMBER: |
| 551 | return 1; |
| 552 | case SEARCH_LESSEQUAL: |
| 553 | if (msg->m_type <= type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | return 1; |
Paul McQuade | 46c0a8c | 2014-06-06 14:37:37 -0700 | [diff] [blame] | 555 | break; |
| 556 | case SEARCH_EQUAL: |
| 557 | if (msg->m_type == type) |
| 558 | return 1; |
| 559 | break; |
| 560 | case SEARCH_NOTEQUAL: |
| 561 | if (msg->m_type != type) |
| 562 | return 1; |
| 563 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | } |
| 565 | return 0; |
| 566 | } |
| 567 | |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 568 | static inline int pipelined_send(struct msg_queue *msq, struct msg_msg *msg, |
| 569 | struct wake_q_head *wake_q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | { |
Nikola Pajkovsky | 41239fe | 2013-04-30 19:15:49 -0700 | [diff] [blame] | 571 | struct msg_receiver *msr, *t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
Nikola Pajkovsky | 41239fe | 2013-04-30 19:15:49 -0700 | [diff] [blame] | 573 | list_for_each_entry_safe(msr, t, &msq->q_receivers, r_list) { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 574 | if (testmsg(msg, msr->r_msgtype, msr->r_mode) && |
| 575 | !security_msg_queue_msgrcv(msq, msg, msr->r_tsk, |
| 576 | msr->r_msgtype, msr->r_mode)) { |
| 577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | list_del(&msr->r_list); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 579 | if (msr->r_maxsize < msg->m_ts) { |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 580 | wake_q_add(wake_q, msr->r_tsk); |
| 581 | WRITE_ONCE(msr->r_msg, ERR_PTR(-E2BIG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | } else { |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 583 | msq->q_lrpid = task_pid_vnr(msr->r_tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | msq->q_rtime = get_seconds(); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 585 | |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 586 | wake_q_add(wake_q, msr->r_tsk); |
| 587 | WRITE_ONCE(msr->r_msg, msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | return 1; |
| 589 | } |
| 590 | } |
| 591 | } |
Davidlohr Bueso | ffa571d | 2014-01-27 17:07:10 -0800 | [diff] [blame] | 592 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | return 0; |
| 594 | } |
| 595 | |
suzuki | 651971c | 2006-12-06 20:37:48 -0800 | [diff] [blame] | 596 | long do_msgsnd(int msqid, long mtype, void __user *mtext, |
| 597 | size_t msgsz, int msgflg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | { |
| 599 | struct msg_queue *msq; |
| 600 | struct msg_msg *msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | int err; |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 602 | struct ipc_namespace *ns; |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 603 | WAKE_Q(wake_q); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 604 | |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 605 | ns = current->nsproxy->ipc_ns; |
| 606 | |
| 607 | if (msgsz > ns->msg_ctlmax || (long) msgsz < 0 || msqid < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | if (mtype < 1) |
| 610 | return -EINVAL; |
| 611 | |
suzuki | 651971c | 2006-12-06 20:37:48 -0800 | [diff] [blame] | 612 | msg = load_msg(mtext, msgsz); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 613 | if (IS_ERR(msg)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | return PTR_ERR(msg); |
| 615 | |
| 616 | msg->m_type = mtype; |
| 617 | msg->m_ts = msgsz; |
| 618 | |
Davidlohr Bueso | 3dd1f78 | 2013-07-08 16:01:17 -0700 | [diff] [blame] | 619 | rcu_read_lock(); |
| 620 | msq = msq_obtain_object_check(ns, msqid); |
Nadia Derbey | 023a535 | 2007-10-18 23:40:51 -0700 | [diff] [blame] | 621 | if (IS_ERR(msq)) { |
| 622 | err = PTR_ERR(msq); |
Davidlohr Bueso | 3dd1f78 | 2013-07-08 16:01:17 -0700 | [diff] [blame] | 623 | goto out_unlock1; |
Nadia Derbey | 023a535 | 2007-10-18 23:40:51 -0700 | [diff] [blame] | 624 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
Manfred Spraul | bebcb92 | 2013-09-03 16:00:08 +0200 | [diff] [blame] | 626 | ipc_lock_object(&msq->q_perm); |
| 627 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | for (;;) { |
| 629 | struct msg_sender s; |
| 630 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 631 | err = -EACCES; |
Serge E. Hallyn | b0e7759 | 2011-03-23 16:43:24 -0700 | [diff] [blame] | 632 | if (ipcperms(ns, &msq->q_perm, S_IWUGO)) |
Manfred Spraul | bebcb92 | 2013-09-03 16:00:08 +0200 | [diff] [blame] | 633 | goto out_unlock0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | |
Davidlohr Bueso | 4271b05 | 2013-09-30 13:45:26 -0700 | [diff] [blame] | 635 | /* raced with RMID? */ |
Rafael Aquini | 0f3d2b0 | 2014-01-27 17:07:01 -0800 | [diff] [blame] | 636 | if (!ipc_valid_object(&msq->q_perm)) { |
Davidlohr Bueso | 4271b05 | 2013-09-30 13:45:26 -0700 | [diff] [blame] | 637 | err = -EIDRM; |
| 638 | goto out_unlock0; |
| 639 | } |
| 640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | err = security_msg_queue_msgsnd(msq, msg, msgflg); |
| 642 | if (err) |
Manfred Spraul | bebcb92 | 2013-09-03 16:00:08 +0200 | [diff] [blame] | 643 | goto out_unlock0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 645 | if (msgsz + msq->q_cbytes <= msq->q_qbytes && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | 1 + msq->q_qnum <= msq->q_qbytes) { |
| 647 | break; |
| 648 | } |
| 649 | |
| 650 | /* queue full, wait: */ |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 651 | if (msgflg & IPC_NOWAIT) { |
| 652 | err = -EAGAIN; |
Manfred Spraul | bebcb92 | 2013-09-03 16:00:08 +0200 | [diff] [blame] | 653 | goto out_unlock0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | } |
Davidlohr Bueso | 3dd1f78 | 2013-07-08 16:01:17 -0700 | [diff] [blame] | 655 | |
Davidlohr Bueso | ffa571d | 2014-01-27 17:07:10 -0800 | [diff] [blame] | 656 | /* enqueue the sender and prepare to block */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | ss_add(msq, &s); |
Rik van Riel | 6062a8d | 2013-04-30 19:15:44 -0700 | [diff] [blame] | 658 | |
| 659 | if (!ipc_rcu_getref(msq)) { |
| 660 | err = -EIDRM; |
Davidlohr Bueso | 3dd1f78 | 2013-07-08 16:01:17 -0700 | [diff] [blame] | 661 | goto out_unlock0; |
Rik van Riel | 6062a8d | 2013-04-30 19:15:44 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Davidlohr Bueso | 3dd1f78 | 2013-07-08 16:01:17 -0700 | [diff] [blame] | 664 | ipc_unlock_object(&msq->q_perm); |
| 665 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | schedule(); |
| 667 | |
Davidlohr Bueso | 3dd1f78 | 2013-07-08 16:01:17 -0700 | [diff] [blame] | 668 | rcu_read_lock(); |
| 669 | ipc_lock_object(&msq->q_perm); |
| 670 | |
Fabian Frederick | 9b24fef | 2016-08-02 14:03:07 -0700 | [diff] [blame] | 671 | ipc_rcu_putref(msq, msg_rcu_free); |
Rafael Aquini | 0f3d2b0 | 2014-01-27 17:07:01 -0800 | [diff] [blame] | 672 | /* raced with RMID? */ |
| 673 | if (!ipc_valid_object(&msq->q_perm)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | err = -EIDRM; |
Davidlohr Bueso | 3dd1f78 | 2013-07-08 16:01:17 -0700 | [diff] [blame] | 675 | goto out_unlock0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | } |
| 677 | ss_del(&s); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 678 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | if (signal_pending(current)) { |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 680 | err = -ERESTARTNOHAND; |
Davidlohr Bueso | 3dd1f78 | 2013-07-08 16:01:17 -0700 | [diff] [blame] | 681 | goto out_unlock0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | } |
Davidlohr Bueso | 3dd1f78 | 2013-07-08 16:01:17 -0700 | [diff] [blame] | 683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | } |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 685 | msq->q_lspid = task_tgid_vnr(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | msq->q_stime = get_seconds(); |
| 687 | |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 688 | if (!pipelined_send(msq, msg, &wake_q)) { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 689 | /* no one is waiting for this message, enqueue it */ |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 690 | list_add_tail(&msg->m_list, &msq->q_messages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | msq->q_cbytes += msgsz; |
| 692 | msq->q_qnum++; |
Kirill Korotaev | 3ac88a4 | 2007-10-18 23:40:56 -0700 | [diff] [blame] | 693 | atomic_add(msgsz, &ns->msg_bytes); |
| 694 | atomic_inc(&ns->msg_hdrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | } |
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 | err = 0; |
| 698 | msg = NULL; |
| 699 | |
Davidlohr Bueso | 3dd1f78 | 2013-07-08 16:01:17 -0700 | [diff] [blame] | 700 | out_unlock0: |
| 701 | ipc_unlock_object(&msq->q_perm); |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 702 | wake_up_q(&wake_q); |
Davidlohr Bueso | 3dd1f78 | 2013-07-08 16:01:17 -0700 | [diff] [blame] | 703 | out_unlock1: |
| 704 | rcu_read_unlock(); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 705 | if (msg != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | free_msg(msg); |
| 707 | return err; |
| 708 | } |
| 709 | |
Heiko Carstens | e48fbb6 | 2009-01-14 14:14:26 +0100 | [diff] [blame] | 710 | SYSCALL_DEFINE4(msgsnd, int, msqid, struct msgbuf __user *, msgp, size_t, msgsz, |
| 711 | int, msgflg) |
suzuki | 651971c | 2006-12-06 20:37:48 -0800 | [diff] [blame] | 712 | { |
| 713 | long mtype; |
| 714 | |
| 715 | if (get_user(mtype, &msgp->mtype)) |
| 716 | return -EFAULT; |
| 717 | return do_msgsnd(msqid, mtype, msgp->mtext, msgsz, msgflg); |
| 718 | } |
| 719 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 720 | static inline int convert_mode(long *msgtyp, int msgflg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | { |
Peter Hurley | 8ac6ed5 | 2013-04-30 19:14:54 -0700 | [diff] [blame] | 722 | if (msgflg & MSG_COPY) |
| 723 | return SEARCH_NUMBER; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 724 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | * find message of correct type. |
| 726 | * msgtyp = 0 => get first. |
| 727 | * msgtyp > 0 => get first message of matching type. |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 728 | * msgtyp < 0 => get message with least type must be < abs(msgtype). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | */ |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 730 | if (*msgtyp == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | return SEARCH_ANY; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 732 | if (*msgtyp < 0) { |
| 733 | *msgtyp = -*msgtyp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | return SEARCH_LESSEQUAL; |
| 735 | } |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 736 | if (msgflg & MSG_EXCEPT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | return SEARCH_NOTEQUAL; |
| 738 | return SEARCH_EQUAL; |
| 739 | } |
| 740 | |
Stanislav Kinsbursky | f9dd87f | 2013-01-04 15:34:52 -0800 | [diff] [blame] | 741 | static long do_msg_fill(void __user *dest, struct msg_msg *msg, size_t bufsz) |
| 742 | { |
| 743 | struct msgbuf __user *msgp = dest; |
| 744 | size_t msgsz; |
| 745 | |
| 746 | if (put_user(msg->m_type, &msgp->mtype)) |
| 747 | return -EFAULT; |
| 748 | |
| 749 | msgsz = (bufsz > msg->m_ts) ? msg->m_ts : bufsz; |
| 750 | if (store_msg(msgp->mtext, msg, msgsz)) |
| 751 | return -EFAULT; |
| 752 | return msgsz; |
| 753 | } |
| 754 | |
Stanislav Kinsbursky | 4a674f3 | 2013-01-04 15:34:55 -0800 | [diff] [blame] | 755 | #ifdef CONFIG_CHECKPOINT_RESTORE |
Stanislav Kinsbursky | 3fcfe78 | 2013-01-04 15:35:03 -0800 | [diff] [blame] | 756 | /* |
| 757 | * This function creates new kernel message structure, large enough to store |
| 758 | * bufsz message bytes. |
| 759 | */ |
Peter Hurley | 8ac6ed5 | 2013-04-30 19:14:54 -0700 | [diff] [blame] | 760 | static inline struct msg_msg *prepare_copy(void __user *buf, size_t bufsz) |
Stanislav Kinsbursky | 4a674f3 | 2013-01-04 15:34:55 -0800 | [diff] [blame] | 761 | { |
| 762 | struct msg_msg *copy; |
| 763 | |
Stanislav Kinsbursky | 4a674f3 | 2013-01-04 15:34:55 -0800 | [diff] [blame] | 764 | /* |
| 765 | * Create dummy message to copy real message to. |
| 766 | */ |
| 767 | copy = load_msg(buf, bufsz); |
| 768 | if (!IS_ERR(copy)) |
| 769 | copy->m_ts = bufsz; |
| 770 | return copy; |
| 771 | } |
| 772 | |
Stanislav Kinsbursky | 85398aa | 2013-01-04 15:34:58 -0800 | [diff] [blame] | 773 | static inline void free_copy(struct msg_msg *copy) |
Stanislav Kinsbursky | 4a674f3 | 2013-01-04 15:34:55 -0800 | [diff] [blame] | 774 | { |
Stanislav Kinsbursky | 85398aa | 2013-01-04 15:34:58 -0800 | [diff] [blame] | 775 | if (copy) |
Stanislav Kinsbursky | 4a674f3 | 2013-01-04 15:34:55 -0800 | [diff] [blame] | 776 | free_msg(copy); |
| 777 | } |
| 778 | #else |
Peter Hurley | 8ac6ed5 | 2013-04-30 19:14:54 -0700 | [diff] [blame] | 779 | static inline struct msg_msg *prepare_copy(void __user *buf, size_t bufsz) |
Stanislav Kinsbursky | b30efe2 | 2013-01-04 15:35:00 -0800 | [diff] [blame] | 780 | { |
| 781 | return ERR_PTR(-ENOSYS); |
| 782 | } |
| 783 | |
Stanislav Kinsbursky | 85398aa | 2013-01-04 15:34:58 -0800 | [diff] [blame] | 784 | static inline void free_copy(struct msg_msg *copy) |
| 785 | { |
| 786 | } |
Stanislav Kinsbursky | 4a674f3 | 2013-01-04 15:34:55 -0800 | [diff] [blame] | 787 | #endif |
| 788 | |
Peter Hurley | daaf74c | 2013-04-30 19:15:04 -0700 | [diff] [blame] | 789 | static struct msg_msg *find_msg(struct msg_queue *msq, long *msgtyp, int mode) |
| 790 | { |
Svenning Sørensen | 368ae53 | 2013-08-28 16:35:17 -0700 | [diff] [blame] | 791 | struct msg_msg *msg, *found = NULL; |
Peter Hurley | daaf74c | 2013-04-30 19:15:04 -0700 | [diff] [blame] | 792 | long count = 0; |
| 793 | |
| 794 | list_for_each_entry(msg, &msq->q_messages, m_list) { |
| 795 | if (testmsg(msg, *msgtyp, mode) && |
| 796 | !security_msg_queue_msgrcv(msq, msg, current, |
| 797 | *msgtyp, mode)) { |
| 798 | if (mode == SEARCH_LESSEQUAL && msg->m_type != 1) { |
| 799 | *msgtyp = msg->m_type - 1; |
Svenning Sørensen | 368ae53 | 2013-08-28 16:35:17 -0700 | [diff] [blame] | 800 | found = msg; |
Peter Hurley | daaf74c | 2013-04-30 19:15:04 -0700 | [diff] [blame] | 801 | } else if (mode == SEARCH_NUMBER) { |
| 802 | if (*msgtyp == count) |
| 803 | return msg; |
| 804 | } else |
| 805 | return msg; |
| 806 | count++; |
| 807 | } |
| 808 | } |
| 809 | |
Svenning Sørensen | 368ae53 | 2013-08-28 16:35:17 -0700 | [diff] [blame] | 810 | return found ?: ERR_PTR(-EAGAIN); |
Peter Hurley | daaf74c | 2013-04-30 19:15:04 -0700 | [diff] [blame] | 811 | } |
| 812 | |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 813 | long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp, int msgflg, |
Stanislav Kinsbursky | f9dd87f | 2013-01-04 15:34:52 -0800 | [diff] [blame] | 814 | long (*msg_handler)(void __user *, struct msg_msg *, size_t)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | int mode; |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 817 | struct msg_queue *msq; |
Kirill Korotaev | 1e78693 | 2006-10-02 02:18:21 -0700 | [diff] [blame] | 818 | struct ipc_namespace *ns; |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 819 | struct msg_msg *msg, *copy = NULL; |
Davidlohr Bueso | e365853 | 2016-10-11 13:54:56 -0700 | [diff] [blame] | 820 | WAKE_Q(wake_q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | |
Peter Hurley | 88b9e45 | 2013-03-08 12:43:27 -0800 | [diff] [blame] | 822 | ns = current->nsproxy->ipc_ns; |
| 823 | |
Stanislav Kinsbursky | f9dd87f | 2013-01-04 15:34:52 -0800 | [diff] [blame] | 824 | if (msqid < 0 || (long) bufsz < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | return -EINVAL; |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 826 | |
Stanislav Kinsbursky | 4a674f3 | 2013-01-04 15:34:55 -0800 | [diff] [blame] | 827 | if (msgflg & MSG_COPY) { |
Michael Kerrisk | 4f87dac | 2014-03-10 14:46:07 +0100 | [diff] [blame] | 828 | if ((msgflg & MSG_EXCEPT) || !(msgflg & IPC_NOWAIT)) |
| 829 | return -EINVAL; |
Peter Hurley | 8ac6ed5 | 2013-04-30 19:14:54 -0700 | [diff] [blame] | 830 | copy = prepare_copy(buf, min_t(size_t, bufsz, ns->msg_ctlmax)); |
Stanislav Kinsbursky | 4a674f3 | 2013-01-04 15:34:55 -0800 | [diff] [blame] | 831 | if (IS_ERR(copy)) |
| 832 | return PTR_ERR(copy); |
| 833 | } |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 834 | mode = convert_mode(&msgtyp, msgflg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 836 | rcu_read_lock(); |
| 837 | msq = msq_obtain_object_check(ns, msqid); |
Stanislav Kinsbursky | 4a674f3 | 2013-01-04 15:34:55 -0800 | [diff] [blame] | 838 | if (IS_ERR(msq)) { |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 839 | rcu_read_unlock(); |
Stanislav Kinsbursky | 85398aa | 2013-01-04 15:34:58 -0800 | [diff] [blame] | 840 | free_copy(copy); |
Nadia Derbey | 023a535 | 2007-10-18 23:40:51 -0700 | [diff] [blame] | 841 | return PTR_ERR(msq); |
Stanislav Kinsbursky | 4a674f3 | 2013-01-04 15:34:55 -0800 | [diff] [blame] | 842 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
| 844 | for (;;) { |
| 845 | struct msg_receiver msr_d; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | |
| 847 | msg = ERR_PTR(-EACCES); |
Serge E. Hallyn | b0e7759 | 2011-03-23 16:43:24 -0700 | [diff] [blame] | 848 | if (ipcperms(ns, &msq->q_perm, S_IRUGO)) |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 849 | goto out_unlock1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 851 | ipc_lock_object(&msq->q_perm); |
Davidlohr Bueso | 4271b05 | 2013-09-30 13:45:26 -0700 | [diff] [blame] | 852 | |
| 853 | /* raced with RMID? */ |
Rafael Aquini | 0f3d2b0 | 2014-01-27 17:07:01 -0800 | [diff] [blame] | 854 | if (!ipc_valid_object(&msq->q_perm)) { |
Davidlohr Bueso | 4271b05 | 2013-09-30 13:45:26 -0700 | [diff] [blame] | 855 | msg = ERR_PTR(-EIDRM); |
| 856 | goto out_unlock0; |
| 857 | } |
| 858 | |
Peter Hurley | daaf74c | 2013-04-30 19:15:04 -0700 | [diff] [blame] | 859 | msg = find_msg(msq, &msgtyp, mode); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 860 | if (!IS_ERR(msg)) { |
| 861 | /* |
| 862 | * Found a suitable message. |
| 863 | * Unlink it from the queue. |
| 864 | */ |
Stanislav Kinsbursky | f9dd87f | 2013-01-04 15:34:52 -0800 | [diff] [blame] | 865 | if ((bufsz < msg->m_ts) && !(msgflg & MSG_NOERROR)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | msg = ERR_PTR(-E2BIG); |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 867 | goto out_unlock0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | } |
Stanislav Kinsbursky | 3fcfe78 | 2013-01-04 15:35:03 -0800 | [diff] [blame] | 869 | /* |
| 870 | * If we are copying, then do not unlink message and do |
| 871 | * not update queue parameters. |
| 872 | */ |
Peter Hurley | 852028a | 2013-04-30 19:14:48 -0700 | [diff] [blame] | 873 | if (msgflg & MSG_COPY) { |
| 874 | msg = copy_msg(msg, copy); |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 875 | goto out_unlock0; |
Peter Hurley | 852028a | 2013-04-30 19:14:48 -0700 | [diff] [blame] | 876 | } |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | list_del(&msg->m_list); |
| 879 | msq->q_qnum--; |
| 880 | msq->q_rtime = get_seconds(); |
Pavel Emelyanov | b488893 | 2007-10-18 23:40:14 -0700 | [diff] [blame] | 881 | msq->q_lrpid = task_tgid_vnr(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | msq->q_cbytes -= msg->m_ts; |
Kirill Korotaev | 3ac88a4 | 2007-10-18 23:40:56 -0700 | [diff] [blame] | 883 | atomic_sub(msg->m_ts, &ns->msg_bytes); |
| 884 | atomic_dec(&ns->msg_hdrs); |
Davidlohr Bueso | d0d6a2a | 2016-10-11 13:54:59 -0700 | [diff] [blame^] | 885 | ss_wakeup(&msq->q_senders, &wake_q, false); |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 886 | |
| 887 | goto out_unlock0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | } |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 889 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | /* No message waiting. Wait for a message */ |
| 891 | if (msgflg & IPC_NOWAIT) { |
| 892 | msg = ERR_PTR(-ENOMSG); |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 893 | goto out_unlock0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | } |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 895 | |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 896 | list_add_tail(&msr_d.r_list, &msq->q_receivers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | msr_d.r_tsk = current; |
| 898 | msr_d.r_msgtype = msgtyp; |
| 899 | msr_d.r_mode = mode; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 900 | if (msgflg & MSG_NOERROR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | msr_d.r_maxsize = INT_MAX; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 902 | else |
Stanislav Kinsbursky | f9dd87f | 2013-01-04 15:34:52 -0800 | [diff] [blame] | 903 | msr_d.r_maxsize = bufsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | msr_d.r_msg = ERR_PTR(-EAGAIN); |
Davidlohr Bueso | f75a2f3 | 2014-06-06 14:37:44 -0700 | [diff] [blame] | 905 | __set_current_state(TASK_INTERRUPTIBLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 907 | ipc_unlock_object(&msq->q_perm); |
| 908 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | schedule(); |
| 910 | |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 911 | /* |
| 912 | * Lockless receive, part 1: |
| 913 | * We don't hold a reference to the queue and getting a |
| 914 | * reference would defeat the idea of a lockless operation, |
| 915 | * thus the code relies on rcu to guarantee the existence of |
| 916 | * msq: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | * Prior to destruction, expunge_all(-EIRDM) changes r_msg. |
| 918 | * Thus if r_msg is -EAGAIN, then the queue not yet destroyed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | */ |
| 920 | rcu_read_lock(); |
| 921 | |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 922 | /* |
| 923 | * Lockless receive, part 2: |
| 924 | * The work in pipelined_send() and expunge_all(): |
| 925 | * - Set pointer to message |
| 926 | * - Queue the receiver task for later wakeup |
| 927 | * - Wake up the process after the lock is dropped. |
Davidlohr Bueso | ff35e5e | 2015-06-30 14:58:39 -0700 | [diff] [blame] | 928 | * |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 929 | * Should the process wake up before this wakeup (due to a |
| 930 | * signal) it will either see the message and continue ... |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | */ |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 932 | msg = READ_ONCE(msr_d.r_msg); |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 933 | if (msg != ERR_PTR(-EAGAIN)) |
| 934 | goto out_unlock1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 936 | /* |
| 937 | * ... or see -EAGAIN, acquire the lock to check the message |
| 938 | * again. |
| 939 | */ |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 940 | ipc_lock_object(&msq->q_perm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | |
Sebastian Andrzej Siewior | ee51636 | 2016-10-11 13:54:53 -0700 | [diff] [blame] | 942 | msg = msr_d.r_msg; |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 943 | if (msg != ERR_PTR(-EAGAIN)) |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 944 | goto out_unlock0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | |
| 946 | list_del(&msr_d.r_list); |
| 947 | if (signal_pending(current)) { |
| 948 | msg = ERR_PTR(-ERESTARTNOHAND); |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 949 | goto out_unlock0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | } |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 951 | |
| 952 | ipc_unlock_object(&msq->q_perm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | } |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 954 | |
| 955 | out_unlock0: |
| 956 | ipc_unlock_object(&msq->q_perm); |
Davidlohr Bueso | e365853 | 2016-10-11 13:54:56 -0700 | [diff] [blame] | 957 | wake_up_q(&wake_q); |
Davidlohr Bueso | 41a0d52 | 2013-07-08 16:01:18 -0700 | [diff] [blame] | 958 | out_unlock1: |
| 959 | rcu_read_unlock(); |
Stanislav Kinsbursky | 4a674f3 | 2013-01-04 15:34:55 -0800 | [diff] [blame] | 960 | if (IS_ERR(msg)) { |
Stanislav Kinsbursky | 85398aa | 2013-01-04 15:34:58 -0800 | [diff] [blame] | 961 | free_copy(copy); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 962 | return PTR_ERR(msg); |
Stanislav Kinsbursky | 4a674f3 | 2013-01-04 15:34:55 -0800 | [diff] [blame] | 963 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | |
Stanislav Kinsbursky | f9dd87f | 2013-01-04 15:34:52 -0800 | [diff] [blame] | 965 | bufsz = msg_handler(buf, msg, bufsz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | free_msg(msg); |
Ingo Molnar | 5a06a36 | 2006-07-30 03:04:11 -0700 | [diff] [blame] | 967 | |
Stanislav Kinsbursky | f9dd87f | 2013-01-04 15:34:52 -0800 | [diff] [blame] | 968 | return bufsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | } |
| 970 | |
Heiko Carstens | e48fbb6 | 2009-01-14 14:14:26 +0100 | [diff] [blame] | 971 | SYSCALL_DEFINE5(msgrcv, int, msqid, struct msgbuf __user *, msgp, size_t, msgsz, |
| 972 | long, msgtyp, int, msgflg) |
suzuki | 651971c | 2006-12-06 20:37:48 -0800 | [diff] [blame] | 973 | { |
Stanislav Kinsbursky | f9dd87f | 2013-01-04 15:34:52 -0800 | [diff] [blame] | 974 | return do_msgrcv(msqid, msgp, msgsz, msgtyp, msgflg, do_msg_fill); |
suzuki | 651971c | 2006-12-06 20:37:48 -0800 | [diff] [blame] | 975 | } |
| 976 | |
Davidlohr Bueso | 3440a6b | 2014-06-06 14:37:45 -0700 | [diff] [blame] | 977 | |
| 978 | void msg_init_ns(struct ipc_namespace *ns) |
| 979 | { |
| 980 | ns->msg_ctlmax = MSGMAX; |
| 981 | ns->msg_ctlmnb = MSGMNB; |
Manfred Spraul | 0050ee0 | 2014-12-12 16:58:17 -0800 | [diff] [blame] | 982 | ns->msg_ctlmni = MSGMNI; |
Davidlohr Bueso | 3440a6b | 2014-06-06 14:37:45 -0700 | [diff] [blame] | 983 | |
| 984 | atomic_set(&ns->msg_bytes, 0); |
| 985 | atomic_set(&ns->msg_hdrs, 0); |
| 986 | ipc_init_ids(&ns->ids[IPC_MSG_IDS]); |
| 987 | } |
| 988 | |
| 989 | #ifdef CONFIG_IPC_NS |
| 990 | void msg_exit_ns(struct ipc_namespace *ns) |
| 991 | { |
| 992 | free_ipcs(ns, &msg_ids(ns), freeque); |
| 993 | idr_destroy(&ns->ids[IPC_MSG_IDS].ipcs_idr); |
| 994 | } |
| 995 | #endif |
| 996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | #ifdef CONFIG_PROC_FS |
Mike Waychison | 19b4946 | 2005-09-06 15:17:10 -0700 | [diff] [blame] | 998 | static int sysvipc_msg_proc_show(struct seq_file *s, void *it) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | { |
Eric W. Biederman | 1efdb69 | 2012-02-07 16:54:11 -0800 | [diff] [blame] | 1000 | struct user_namespace *user_ns = seq_user_ns(s); |
Mike Waychison | 19b4946 | 2005-09-06 15:17:10 -0700 | [diff] [blame] | 1001 | struct msg_queue *msq = it; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | |
Joe Perches | 7f032d6 | 2015-04-15 16:17:54 -0700 | [diff] [blame] | 1003 | seq_printf(s, |
| 1004 | "%10d %10d %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %10lu %10lu %10lu\n", |
| 1005 | msq->q_perm.key, |
| 1006 | msq->q_perm.id, |
| 1007 | msq->q_perm.mode, |
| 1008 | msq->q_cbytes, |
| 1009 | msq->q_qnum, |
| 1010 | msq->q_lspid, |
| 1011 | msq->q_lrpid, |
| 1012 | from_kuid_munged(user_ns, msq->q_perm.uid), |
| 1013 | from_kgid_munged(user_ns, msq->q_perm.gid), |
| 1014 | from_kuid_munged(user_ns, msq->q_perm.cuid), |
| 1015 | from_kgid_munged(user_ns, msq->q_perm.cgid), |
| 1016 | msq->q_stime, |
| 1017 | msq->q_rtime, |
| 1018 | msq->q_ctime); |
| 1019 | |
| 1020 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | } |
| 1022 | #endif |
Davidlohr Bueso | 3440a6b | 2014-06-06 14:37:45 -0700 | [diff] [blame] | 1023 | |
| 1024 | void __init msg_init(void) |
| 1025 | { |
| 1026 | msg_init_ns(&init_ipc_ns); |
| 1027 | |
Davidlohr Bueso | 3440a6b | 2014-06-06 14:37:45 -0700 | [diff] [blame] | 1028 | ipc_init_proc_interface("sysvipc/msg", |
| 1029 | " key msqid perms cbytes qnum lspid lrpid uid gid cuid cgid stime rtime ctime\n", |
| 1030 | IPC_MSG_IDS, sysvipc_msg_proc_show); |
| 1031 | } |