Blame view
ipc/msg.c
29.9 KB
b24413180 License cleanup: ... |
1 |
// SPDX-License-Identifier: GPL-2.0 |
1da177e4c Linux-2.6.12-rc2 |
2 3 |
/* * linux/ipc/msg.c |
5a06a363e [PATCH] ipc/msg.c... |
4 |
* Copyright (C) 1992 Krishna Balasubramanian |
1da177e4c Linux-2.6.12-rc2 |
5 6 7 8 9 10 11 12 13 14 15 |
* * Removed all the remaining kerneld mess * Catch the -EFAULT stuff properly * Use GFP_KERNEL for messages as in 1.2 * Fixed up the unchecked user space derefs * Copyright (C) 1998 Alan Cox & Andi Kleen * * /proc/sysvipc/msg support (c) 1999 Dragos Acostachioaie <dragos@iname.com> * * mostly rewritten, threaded and wake-one semantics added * MSGMAX limit removed, sysctl's added |
624dffcbc correct email add... |
16 |
* (c) 1999 Manfred Spraul <manfred@colorfullife.com> |
073115d6b [PATCH] Rework of... |
17 18 19 |
* * support for audit of ipc object properties and permission changes * Dustin Kirkland <dustin.kirkland@us.ibm.com> |
1e7869373 [PATCH] IPC names... |
20 21 22 23 |
* * namespaces support * OpenVZ, SWsoft Inc. * Pavel Emelianov <xemul@openvz.org> |
1da177e4c Linux-2.6.12-rc2 |
24 |
*/ |
c59ede7b7 [PATCH] move capa... |
25 |
#include <linux/capability.h> |
1da177e4c Linux-2.6.12-rc2 |
26 27 28 |
#include <linux/msg.h> #include <linux/spinlock.h> #include <linux/init.h> |
f7bf3df8b ipc: scale msgmni... |
29 |
#include <linux/mm.h> |
1da177e4c Linux-2.6.12-rc2 |
30 31 32 |
#include <linux/proc_fs.h> #include <linux/list.h> #include <linux/security.h> |
84f001e15 sched/headers: Pr... |
33 |
#include <linux/sched/wake_q.h> |
1da177e4c Linux-2.6.12-rc2 |
34 35 |
#include <linux/syscalls.h> #include <linux/audit.h> |
19b4946ca [PATCH] ipc: conv... |
36 |
#include <linux/seq_file.h> |
3e148c799 fix idr_find() lo... |
37 |
#include <linux/rwsem.h> |
1e7869373 [PATCH] IPC names... |
38 |
#include <linux/nsproxy.h> |
ae5e1b22f namespaces: move ... |
39 |
#include <linux/ipc_namespace.h> |
0eb71a9da rhashtable: split... |
40 |
#include <linux/rhashtable.h> |
5f921ae96 [PATCH] sem2mutex... |
41 |
|
1da177e4c Linux-2.6.12-rc2 |
42 |
#include <asm/current.h> |
7153e4027 ipc, kernel: use ... |
43 |
#include <linux/uaccess.h> |
1da177e4c Linux-2.6.12-rc2 |
44 |
#include "util.h" |
34b56df92 msg: Move struct ... |
45 46 47 48 49 50 51 52 53 |
/* one msq_queue structure for each present queue on the system */ struct msg_queue { struct kern_ipc_perm q_perm; time64_t q_stime; /* last msgsnd time */ time64_t q_rtime; /* last msgrcv time */ time64_t q_ctime; /* last change time */ unsigned long q_cbytes; /* current number of bytes on queue */ unsigned long q_qnum; /* number of messages in queue */ unsigned long q_qbytes; /* max number of bytes on queue */ |
39a4940ea ipc/msg: Fix msgc... |
54 55 |
struct pid *q_lspid; /* pid of last msgsnd */ struct pid *q_lrpid; /* last receive pid */ |
34b56df92 msg: Move struct ... |
56 57 58 59 60 |
struct list_head q_messages; struct list_head q_receivers; struct list_head q_senders; } __randomize_layout; |
4bb6657dd ipc,msg: document... |
61 |
/* one msg_receiver structure for each sleeping receiver */ |
1da177e4c Linux-2.6.12-rc2 |
62 |
struct msg_receiver { |
5a06a363e [PATCH] ipc/msg.c... |
63 64 |
struct list_head r_list; struct task_struct *r_tsk; |
1da177e4c Linux-2.6.12-rc2 |
65 |
|
5a06a363e [PATCH] ipc/msg.c... |
66 67 68 |
int r_mode; long r_msgtype; long r_maxsize; |
1da177e4c Linux-2.6.12-rc2 |
69 |
|
ee51636ca ipc/msg: implemen... |
70 |
struct msg_msg *r_msg; |
1da177e4c Linux-2.6.12-rc2 |
71 72 73 74 |
}; /* one msg_sender for each sleeping sender */ struct msg_sender { |
5a06a363e [PATCH] ipc/msg.c... |
75 76 |
struct list_head list; struct task_struct *tsk; |
ed27f9122 ipc/msg: avoid wa... |
77 |
size_t msgsz; |
1da177e4c Linux-2.6.12-rc2 |
78 79 80 81 82 83 |
}; #define SEARCH_ANY 1 #define SEARCH_EQUAL 2 #define SEARCH_NOTEQUAL 3 #define SEARCH_LESSEQUAL 4 |
8ac6ed585 ipc: implement MS... |
84 |
#define SEARCH_NUMBER 5 |
1da177e4c Linux-2.6.12-rc2 |
85 |
|
ed2ddbf88 IPC: make struct ... |
86 |
#define msg_ids(ns) ((ns)->ids[IPC_MSG_IDS]) |
1da177e4c Linux-2.6.12-rc2 |
87 |
|
a5001a0d9 ipc,msg: introduc... |
88 89 |
static inline struct msg_queue *msq_obtain_object(struct ipc_namespace *ns, int id) { |
55b7ae501 ipc: rename ipc_o... |
90 |
struct kern_ipc_perm *ipcp = ipc_obtain_object_idr(&msg_ids(ns), id); |
a5001a0d9 ipc,msg: introduc... |
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
if (IS_ERR(ipcp)) return ERR_CAST(ipcp); return container_of(ipcp, struct msg_queue, q_perm); } static inline struct msg_queue *msq_obtain_object_check(struct ipc_namespace *ns, int id) { struct kern_ipc_perm *ipcp = ipc_obtain_object_check(&msg_ids(ns), id); if (IS_ERR(ipcp)) return ERR_CAST(ipcp); return container_of(ipcp, struct msg_queue, q_perm); } |
7ca7e564e ipc: store ipcs i... |
108 109 110 111 |
static inline void msg_rmid(struct ipc_namespace *ns, struct msg_queue *s) { ipc_rmid(&msg_ids(ns), &s->q_perm); } |
53dad6d3a ipc: fix race wit... |
112 113 |
static void msg_rcu_free(struct rcu_head *head) { |
dba4cdd39 ipc: merge ipc_rc... |
114 115 |
struct kern_ipc_perm *p = container_of(head, struct kern_ipc_perm, rcu); struct msg_queue *msq = container_of(p, struct msg_queue, q_perm); |
53dad6d3a ipc: fix race wit... |
116 |
|
d8c6e8543 msg/security: Pas... |
117 |
security_msg_queue_free(&msq->q_perm); |
fb259c310 ipc/msg: remove s... |
118 |
kvfree(msq); |
52f908904 ipc/msg: avoid ip... |
119 |
} |
f4566f048 ipc: fix wrong co... |
120 121 122 123 124 |
/** * newque - Create a new msg queue * @ns: namespace * @params: ptr to the structure that contains the key and msgflg * |
d9a605e40 ipc: rename ids->... |
125 |
* Called with msg_ids.rwsem held (writer) |
f4566f048 ipc: fix wrong co... |
126 |
*/ |
7748dbfaa ipc: unify the sy... |
127 |
static int newque(struct ipc_namespace *ns, struct ipc_params *params) |
1da177e4c Linux-2.6.12-rc2 |
128 |
{ |
1da177e4c Linux-2.6.12-rc2 |
129 |
struct msg_queue *msq; |
51c23b7b7 ipc/msg.c: avoid ... |
130 |
int retval; |
7748dbfaa ipc: unify the sy... |
131 132 |
key_t key = params->key; int msgflg = params->flg; |
1da177e4c Linux-2.6.12-rc2 |
133 |
|
fb259c310 ipc/msg: remove s... |
134 135 |
msq = kvmalloc(sizeof(*msq), GFP_KERNEL); if (unlikely(!msq)) |
1da177e4c Linux-2.6.12-rc2 |
136 |
return -ENOMEM; |
5a06a363e [PATCH] ipc/msg.c... |
137 |
msq->q_perm.mode = msgflg & S_IRWXUGO; |
1da177e4c Linux-2.6.12-rc2 |
138 139 140 |
msq->q_perm.key = key; msq->q_perm.security = NULL; |
d8c6e8543 msg/security: Pas... |
141 |
retval = security_msg_queue_alloc(&msq->q_perm); |
1da177e4c Linux-2.6.12-rc2 |
142 |
if (retval) { |
fb259c310 ipc/msg: remove s... |
143 |
kvfree(msq); |
1da177e4c Linux-2.6.12-rc2 |
144 145 |
return retval; } |
1da177e4c Linux-2.6.12-rc2 |
146 |
msq->q_stime = msq->q_rtime = 0; |
50578ea97 ipc: msg: Make ms... |
147 |
msq->q_ctime = ktime_get_real_seconds(); |
1da177e4c Linux-2.6.12-rc2 |
148 |
msq->q_cbytes = msq->q_qnum = 0; |
1e7869373 [PATCH] IPC names... |
149 |
msq->q_qbytes = ns->msg_ctlmnb; |
39a4940ea ipc/msg: Fix msgc... |
150 |
msq->q_lspid = msq->q_lrpid = NULL; |
1da177e4c Linux-2.6.12-rc2 |
151 152 153 |
INIT_LIST_HEAD(&msq->q_messages); INIT_LIST_HEAD(&msq->q_receivers); INIT_LIST_HEAD(&msq->q_senders); |
7ca7e564e ipc: store ipcs i... |
154 |
|
b9a532277 Initialize msg/sh... |
155 |
/* ipc_addid() locks msq upon success. */ |
51c23b7b7 ipc/msg.c: avoid ... |
156 157 |
retval = ipc_addid(&msg_ids(ns), &msq->q_perm, ns->msg_ctlmni); if (retval < 0) { |
39cfffd77 ipc/util.c: use i... |
158 |
ipc_rcu_putref(&msq->q_perm, msg_rcu_free); |
51c23b7b7 ipc/msg.c: avoid ... |
159 |
return retval; |
b9a532277 Initialize msg/sh... |
160 |
} |
cf9d5d78d ipc: close open c... |
161 |
ipc_unlock_object(&msq->q_perm); |
dbfcd91f0 ipc: move rcu loc... |
162 |
rcu_read_unlock(); |
1da177e4c Linux-2.6.12-rc2 |
163 |
|
7ca7e564e ipc: store ipcs i... |
164 |
return msq->q_perm.id; |
1da177e4c Linux-2.6.12-rc2 |
165 |
} |
ed27f9122 ipc/msg: avoid wa... |
166 167 168 169 170 171 172 173 |
static inline bool msg_fits_inqueue(struct msg_queue *msq, size_t msgsz) { return msgsz + msq->q_cbytes <= msq->q_qbytes && 1 + msq->q_qnum <= msq->q_qbytes; } static inline void ss_add(struct msg_queue *msq, struct msg_sender *mss, size_t msgsz) |
1da177e4c Linux-2.6.12-rc2 |
174 |
{ |
5a06a363e [PATCH] ipc/msg.c... |
175 |
mss->tsk = current; |
ed27f9122 ipc/msg: avoid wa... |
176 |
mss->msgsz = msgsz; |
f75a2f358 ipc,msg: use curr... |
177 |
__set_current_state(TASK_INTERRUPTIBLE); |
5a06a363e [PATCH] ipc/msg.c... |
178 |
list_add_tail(&mss->list, &msq->q_senders); |
1da177e4c Linux-2.6.12-rc2 |
179 |
} |
5a06a363e [PATCH] ipc/msg.c... |
180 |
static inline void ss_del(struct msg_sender *mss) |
1da177e4c Linux-2.6.12-rc2 |
181 |
{ |
ed27f9122 ipc/msg: avoid wa... |
182 |
if (mss->list.next) |
1da177e4c Linux-2.6.12-rc2 |
183 184 |
list_del(&mss->list); } |
ed27f9122 ipc/msg: avoid wa... |
185 |
static void ss_wakeup(struct msg_queue *msq, |
d0d6a2a95 ipc/msg: make ss_... |
186 |
struct wake_q_head *wake_q, bool kill) |
1da177e4c Linux-2.6.12-rc2 |
187 |
{ |
41239fe82 ipc/msg.c: use li... |
188 |
struct msg_sender *mss, *t; |
ed27f9122 ipc/msg: avoid wa... |
189 190 |
struct task_struct *stop_tsk = NULL; struct list_head *h = &msq->q_senders; |
1da177e4c Linux-2.6.12-rc2 |
191 |
|
41239fe82 ipc/msg.c: use li... |
192 |
list_for_each_entry_safe(mss, t, h, list) { |
5a06a363e [PATCH] ipc/msg.c... |
193 194 |
if (kill) mss->list.next = NULL; |
ed27f9122 ipc/msg: avoid wa... |
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
/* * Stop at the first task we don't wakeup, * we've already iterated the original * sender queue. */ else if (stop_tsk == mss->tsk) break; /* * We are not in an EIDRM scenario here, therefore * verify that we really need to wakeup the task. * To maintain current semantics and wakeup order, * move the sender to the tail on behalf of the * blocked task. */ else if (!msg_fits_inqueue(msq, mss->msgsz)) { if (!stop_tsk) stop_tsk = mss->tsk; list_move_tail(&mss->list, &msq->q_senders); continue; } |
e3658538b ipc/msg: batch qu... |
217 |
wake_q_add(wake_q, mss->tsk); |
1da177e4c Linux-2.6.12-rc2 |
218 219 |
} } |
ee51636ca ipc/msg: implemen... |
220 221 |
static void expunge_all(struct msg_queue *msq, int res, struct wake_q_head *wake_q) |
1da177e4c Linux-2.6.12-rc2 |
222 |
{ |
41239fe82 ipc/msg.c: use li... |
223 |
struct msg_receiver *msr, *t; |
5a06a363e [PATCH] ipc/msg.c... |
224 |
|
41239fe82 ipc/msg.c: use li... |
225 |
list_for_each_entry_safe(msr, t, &msq->q_receivers, r_list) { |
ee51636ca ipc/msg: implemen... |
226 227 |
wake_q_add(wake_q, msr->r_tsk); WRITE_ONCE(msr->r_msg, ERR_PTR(res)); |
1da177e4c Linux-2.6.12-rc2 |
228 229 |
} } |
5a06a363e [PATCH] ipc/msg.c... |
230 231 232 |
/* * freeque() wakes up waiters on the sender and receiver waiting queue, |
f4566f048 ipc: fix wrong co... |
233 234 |
* removes the message queue from message queue ID IDR, and cleans up all the * messages associated with this queue. |
1da177e4c Linux-2.6.12-rc2 |
235 |
* |
d9a605e40 ipc: rename ids->... |
236 237 |
* msg_ids.rwsem (writer) and the spinlock for this message queue are held * before freeque() is called. msg_ids.rwsem remains locked on exit. |
1da177e4c Linux-2.6.12-rc2 |
238 |
*/ |
01b8b07a5 IPC: consolidate ... |
239 |
static void freeque(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp) |
1da177e4c Linux-2.6.12-rc2 |
240 |
{ |
41239fe82 ipc/msg.c: use li... |
241 |
struct msg_msg *msg, *t; |
01b8b07a5 IPC: consolidate ... |
242 |
struct msg_queue *msq = container_of(ipcp, struct msg_queue, q_perm); |
194a6b5b9 sched/wake_q: Ren... |
243 |
DEFINE_WAKE_Q(wake_q); |
1da177e4c Linux-2.6.12-rc2 |
244 |
|
ee51636ca ipc/msg: implemen... |
245 |
expunge_all(msq, -EIDRM, &wake_q); |
ed27f9122 ipc/msg: avoid wa... |
246 |
ss_wakeup(msq, &wake_q, true); |
7ca7e564e ipc: store ipcs i... |
247 |
msg_rmid(ns, msq); |
4718787d1 ipc,msg: drop msg... |
248 |
ipc_unlock_object(&msq->q_perm); |
ee51636ca ipc/msg: implemen... |
249 |
wake_up_q(&wake_q); |
4718787d1 ipc,msg: drop msg... |
250 |
rcu_read_unlock(); |
5a06a363e [PATCH] ipc/msg.c... |
251 |
|
41239fe82 ipc/msg.c: use li... |
252 |
list_for_each_entry_safe(msg, t, &msq->q_messages, m_list) { |
3ac88a41f virtualization of... |
253 |
atomic_dec(&ns->msg_hdrs); |
1da177e4c Linux-2.6.12-rc2 |
254 255 |
free_msg(msg); } |
3ac88a41f virtualization of... |
256 |
atomic_sub(msq->q_cbytes, &ns->msg_bytes); |
39a4940ea ipc/msg: Fix msgc... |
257 258 |
ipc_update_pid(&msq->q_lspid, NULL); ipc_update_pid(&msq->q_lrpid, NULL); |
dba4cdd39 ipc: merge ipc_rc... |
259 |
ipc_rcu_putref(&msq->q_perm, msg_rcu_free); |
1da177e4c Linux-2.6.12-rc2 |
260 |
} |
3d65661a4 ipc: add msgget s... |
261 |
long ksys_msgget(key_t key, int msgflg) |
1da177e4c Linux-2.6.12-rc2 |
262 |
{ |
1e7869373 [PATCH] IPC names... |
263 |
struct ipc_namespace *ns; |
eb66ec44f ipc: constify ipc... |
264 265 |
static const struct ipc_ops msg_ops = { .getnew = newque, |
50ab44b1c ipc: Directly cal... |
266 |
.associate = security_msg_queue_associate, |
eb66ec44f ipc: constify ipc... |
267 |
}; |
7748dbfaa ipc: unify the sy... |
268 |
struct ipc_params msg_params; |
1e7869373 [PATCH] IPC names... |
269 270 |
ns = current->nsproxy->ipc_ns; |
7ca7e564e ipc: store ipcs i... |
271 |
|
7748dbfaa ipc: unify the sy... |
272 273 |
msg_params.key = key; msg_params.flg = msgflg; |
5a06a363e [PATCH] ipc/msg.c... |
274 |
|
7748dbfaa ipc: unify the sy... |
275 |
return ipcget(ns, &msg_ids(ns), &msg_ops, &msg_params); |
1da177e4c Linux-2.6.12-rc2 |
276 |
} |
3d65661a4 ipc: add msgget s... |
277 278 279 280 |
SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg) { return ksys_msgget(key, msgflg); } |
5a06a363e [PATCH] ipc/msg.c... |
281 282 |
static inline unsigned long copy_msqid_to_user(void __user *buf, struct msqid64_ds *in, int version) |
1da177e4c Linux-2.6.12-rc2 |
283 |
{ |
239521f31 ipc: whitespace c... |
284 |
switch (version) { |
1da177e4c Linux-2.6.12-rc2 |
285 |
case IPC_64: |
5a06a363e [PATCH] ipc/msg.c... |
286 |
return copy_to_user(buf, in, sizeof(*in)); |
1da177e4c Linux-2.6.12-rc2 |
287 |
case IPC_OLD: |
5a06a363e [PATCH] ipc/msg.c... |
288 |
{ |
1da177e4c Linux-2.6.12-rc2 |
289 |
struct msqid_ds out; |
5a06a363e [PATCH] ipc/msg.c... |
290 |
memset(&out, 0, sizeof(out)); |
1da177e4c Linux-2.6.12-rc2 |
291 292 293 294 295 296 |
ipc64_perm_to_ipc_perm(&in->msg_perm, &out.msg_perm); out.msg_stime = in->msg_stime; out.msg_rtime = in->msg_rtime; out.msg_ctime = in->msg_ctime; |
4be929be3 kernel-wide: repl... |
297 298 |
if (in->msg_cbytes > USHRT_MAX) out.msg_cbytes = USHRT_MAX; |
1da177e4c Linux-2.6.12-rc2 |
299 300 301 |
else out.msg_cbytes = in->msg_cbytes; out.msg_lcbytes = in->msg_cbytes; |
4be929be3 kernel-wide: repl... |
302 303 |
if (in->msg_qnum > USHRT_MAX) out.msg_qnum = USHRT_MAX; |
1da177e4c Linux-2.6.12-rc2 |
304 305 |
else out.msg_qnum = in->msg_qnum; |
4be929be3 kernel-wide: repl... |
306 307 |
if (in->msg_qbytes > USHRT_MAX) out.msg_qbytes = USHRT_MAX; |
1da177e4c Linux-2.6.12-rc2 |
308 309 310 311 312 313 |
else out.msg_qbytes = in->msg_qbytes; out.msg_lqbytes = in->msg_qbytes; out.msg_lspid = in->msg_lspid; out.msg_lrpid = in->msg_lrpid; |
5a06a363e [PATCH] ipc/msg.c... |
314 315 |
return copy_to_user(buf, &out, sizeof(out)); } |
1da177e4c Linux-2.6.12-rc2 |
316 317 318 319 |
default: return -EINVAL; } } |
5a06a363e [PATCH] ipc/msg.c... |
320 |
static inline unsigned long |
016d7132f IPC: get rid of t... |
321 |
copy_msqid_from_user(struct msqid64_ds *out, void __user *buf, int version) |
1da177e4c Linux-2.6.12-rc2 |
322 |
{ |
239521f31 ipc: whitespace c... |
323 |
switch (version) { |
1da177e4c Linux-2.6.12-rc2 |
324 |
case IPC_64: |
016d7132f IPC: get rid of t... |
325 |
if (copy_from_user(out, buf, sizeof(*out))) |
1da177e4c Linux-2.6.12-rc2 |
326 |
return -EFAULT; |
1da177e4c Linux-2.6.12-rc2 |
327 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
328 |
case IPC_OLD: |
5a06a363e [PATCH] ipc/msg.c... |
329 |
{ |
1da177e4c Linux-2.6.12-rc2 |
330 |
struct msqid_ds tbuf_old; |
5a06a363e [PATCH] ipc/msg.c... |
331 |
if (copy_from_user(&tbuf_old, buf, sizeof(tbuf_old))) |
1da177e4c Linux-2.6.12-rc2 |
332 |
return -EFAULT; |
239521f31 ipc: whitespace c... |
333 334 335 |
out->msg_perm.uid = tbuf_old.msg_perm.uid; out->msg_perm.gid = tbuf_old.msg_perm.gid; out->msg_perm.mode = tbuf_old.msg_perm.mode; |
1da177e4c Linux-2.6.12-rc2 |
336 |
|
5a06a363e [PATCH] ipc/msg.c... |
337 |
if (tbuf_old.msg_qbytes == 0) |
016d7132f IPC: get rid of t... |
338 |
out->msg_qbytes = tbuf_old.msg_lqbytes; |
1da177e4c Linux-2.6.12-rc2 |
339 |
else |
016d7132f IPC: get rid of t... |
340 |
out->msg_qbytes = tbuf_old.msg_qbytes; |
1da177e4c Linux-2.6.12-rc2 |
341 342 |
return 0; |
5a06a363e [PATCH] ipc/msg.c... |
343 |
} |
1da177e4c Linux-2.6.12-rc2 |
344 345 346 347 |
default: return -EINVAL; } } |
a0d092fc2 IPC/message queue... |
348 |
/* |
d9a605e40 ipc: rename ids->... |
349 |
* This function handles some msgctl commands which require the rwsem |
a0d092fc2 IPC/message queue... |
350 |
* to be held in write mode. |
d9a605e40 ipc: rename ids->... |
351 |
* NOTE: no locks must be held, the rwsem is taken inside this function. |
a0d092fc2 IPC/message queue... |
352 353 |
*/ static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd, |
156d9ed12 msgctl(): split t... |
354 |
struct msqid64_ds *msqid64) |
1da177e4c Linux-2.6.12-rc2 |
355 |
{ |
1da177e4c Linux-2.6.12-rc2 |
356 |
struct kern_ipc_perm *ipcp; |
a0d092fc2 IPC/message queue... |
357 358 |
struct msg_queue *msq; int err; |
d9a605e40 ipc: rename ids->... |
359 |
down_write(&msg_ids(ns).rwsem); |
7b4cc5d84 ipc: move locking... |
360 |
rcu_read_lock(); |
4241c1a30 ipc: rename ipcct... |
361 |
ipcp = ipcctl_obtain_check(ns, &msg_ids(ns), msqid, cmd, |
156d9ed12 msgctl(): split t... |
362 |
&msqid64->msg_perm, msqid64->msg_qbytes); |
7b4cc5d84 ipc: move locking... |
363 364 |
if (IS_ERR(ipcp)) { err = PTR_ERR(ipcp); |
7b4cc5d84 ipc: move locking... |
365 366 |
goto out_unlock1; } |
a0d092fc2 IPC/message queue... |
367 |
|
a5f75e7f2 IPC: consolidate ... |
368 |
msq = container_of(ipcp, struct msg_queue, q_perm); |
a0d092fc2 IPC/message queue... |
369 |
|
d8c6e8543 msg/security: Pas... |
370 |
err = security_msg_queue_msgctl(&msq->q_perm, cmd); |
a0d092fc2 IPC/message queue... |
371 |
if (err) |
15724ecb7 ipc,msg: shorten ... |
372 |
goto out_unlock1; |
a0d092fc2 IPC/message queue... |
373 374 375 |
switch (cmd) { case IPC_RMID: |
15724ecb7 ipc,msg: shorten ... |
376 |
ipc_lock_object(&msq->q_perm); |
7b4cc5d84 ipc: move locking... |
377 |
/* freeque unlocks the ipc object and rcu */ |
a0d092fc2 IPC/message queue... |
378 379 380 |
freeque(ns, ipcp); goto out_up; case IPC_SET: |
e3658538b ipc/msg: batch qu... |
381 |
{ |
194a6b5b9 sched/wake_q: Ren... |
382 |
DEFINE_WAKE_Q(wake_q); |
e3658538b ipc/msg: batch qu... |
383 |
|
156d9ed12 msgctl(): split t... |
384 |
if (msqid64->msg_qbytes > ns->msg_ctlmnb && |
a0d092fc2 IPC/message queue... |
385 386 |
!capable(CAP_SYS_RESOURCE)) { err = -EPERM; |
15724ecb7 ipc,msg: shorten ... |
387 |
goto out_unlock1; |
a0d092fc2 IPC/message queue... |
388 |
} |
15724ecb7 ipc,msg: shorten ... |
389 |
ipc_lock_object(&msq->q_perm); |
156d9ed12 msgctl(): split t... |
390 |
err = ipc_update_perm(&msqid64->msg_perm, ipcp); |
1efdb69b0 userns: Convert i... |
391 |
if (err) |
7b4cc5d84 ipc: move locking... |
392 |
goto out_unlock0; |
1efdb69b0 userns: Convert i... |
393 |
|
156d9ed12 msgctl(): split t... |
394 |
msq->q_qbytes = msqid64->msg_qbytes; |
a0d092fc2 IPC/message queue... |
395 |
|
50578ea97 ipc: msg: Make ms... |
396 |
msq->q_ctime = ktime_get_real_seconds(); |
e3658538b ipc/msg: batch qu... |
397 398 |
/* * Sleeping receivers might be excluded by |
a0d092fc2 IPC/message queue... |
399 400 |
* stricter permissions. */ |
ee51636ca ipc/msg: implemen... |
401 |
expunge_all(msq, -EAGAIN, &wake_q); |
e3658538b ipc/msg: batch qu... |
402 403 |
/* * Sleeping senders might be able to send |
a0d092fc2 IPC/message queue... |
404 405 |
* due to a larger queue size. */ |
ed27f9122 ipc/msg: avoid wa... |
406 |
ss_wakeup(msq, &wake_q, false); |
e3658538b ipc/msg: batch qu... |
407 408 409 410 411 |
ipc_unlock_object(&msq->q_perm); wake_up_q(&wake_q); goto out_unlock1; } |
a0d092fc2 IPC/message queue... |
412 413 |
default: err = -EINVAL; |
15724ecb7 ipc,msg: shorten ... |
414 |
goto out_unlock1; |
a0d092fc2 IPC/message queue... |
415 |
} |
7b4cc5d84 ipc: move locking... |
416 417 418 419 420 |
out_unlock0: ipc_unlock_object(&msq->q_perm); out_unlock1: rcu_read_unlock(); |
a0d092fc2 IPC/message queue... |
421 |
out_up: |
d9a605e40 ipc: rename ids->... |
422 |
up_write(&msg_ids(ns).rwsem); |
a0d092fc2 IPC/message queue... |
423 424 |
return err; } |
156d9ed12 msgctl(): split t... |
425 426 |
static int msgctl_info(struct ipc_namespace *ns, int msqid, int cmd, struct msginfo *msginfo) |
a0d092fc2 IPC/message queue... |
427 |
{ |
2cafed30f ipc,msg: introduc... |
428 |
int err; |
27c331a17 ipc/util.c: furth... |
429 |
int max_idx; |
1da177e4c Linux-2.6.12-rc2 |
430 |
|
156d9ed12 msgctl(): split t... |
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
/* * We must not return kernel stack data. * due to padding, it's not enough * to set all member fields. */ err = security_msg_queue_msgctl(NULL, cmd); if (err) return err; memset(msginfo, 0, sizeof(*msginfo)); msginfo->msgmni = ns->msg_ctlmni; msginfo->msgmax = ns->msg_ctlmax; msginfo->msgmnb = ns->msg_ctlmnb; msginfo->msgssz = MSGSSZ; msginfo->msgseg = MSGSEG; down_read(&msg_ids(ns).rwsem); if (cmd == MSG_INFO) { msginfo->msgpool = msg_ids(ns).in_use; msginfo->msgmap = atomic_read(&ns->msg_hdrs); msginfo->msgtql = atomic_read(&ns->msg_bytes); } else { msginfo->msgmap = MSGMAP; msginfo->msgpool = MSGPOOL; msginfo->msgtql = MSGTQL; |
1da177e4c Linux-2.6.12-rc2 |
455 |
} |
27c331a17 ipc/util.c: furth... |
456 |
max_idx = ipc_get_maxidx(&msg_ids(ns)); |
156d9ed12 msgctl(): split t... |
457 |
up_read(&msg_ids(ns).rwsem); |
27c331a17 ipc/util.c: furth... |
458 |
return (max_idx < 0) ? 0 : max_idx; |
156d9ed12 msgctl(): split t... |
459 |
} |
2cafed30f ipc,msg: introduc... |
460 |
|
156d9ed12 msgctl(): split t... |
461 462 463 |
static int msgctl_stat(struct ipc_namespace *ns, int msqid, int cmd, struct msqid64_ds *p) { |
156d9ed12 msgctl(): split t... |
464 |
struct msg_queue *msq; |
87ad4b0d8 ipc: fix ipc data... |
465 |
int err; |
ac0ba20ea ipc,msg: make msg... |
466 |
|
156d9ed12 msgctl(): split t... |
467 |
memset(p, 0, sizeof(*p)); |
ac0ba20ea ipc,msg: make msg... |
468 |
|
156d9ed12 msgctl(): split t... |
469 |
rcu_read_lock(); |
23c8cec8c ipc/msg: introduc... |
470 |
if (cmd == MSG_STAT || cmd == MSG_STAT_ANY) { |
156d9ed12 msgctl(): split t... |
471 472 473 |
msq = msq_obtain_object(ns, msqid); if (IS_ERR(msq)) { err = PTR_ERR(msq); |
1da177e4c Linux-2.6.12-rc2 |
474 |
goto out_unlock; |
1da177e4c Linux-2.6.12-rc2 |
475 |
} |
23c8cec8c ipc/msg: introduc... |
476 |
} else { /* IPC_STAT */ |
156d9ed12 msgctl(): split t... |
477 478 479 |
msq = msq_obtain_object_check(ns, msqid); if (IS_ERR(msq)) { err = PTR_ERR(msq); |
1da177e4c Linux-2.6.12-rc2 |
480 |
goto out_unlock; |
156d9ed12 msgctl(): split t... |
481 |
} |
156d9ed12 msgctl(): split t... |
482 |
} |
1da177e4c Linux-2.6.12-rc2 |
483 |
|
23c8cec8c ipc/msg: introduc... |
484 485 486 487 488 489 490 491 |
/* see comment for SHM_STAT_ANY */ if (cmd == MSG_STAT_ANY) audit_ipc_obj(&msq->q_perm); else { err = -EACCES; if (ipcperms(ns, &msq->q_perm, S_IRUGO)) goto out_unlock; } |
ac0ba20ea ipc,msg: make msg... |
492 |
|
d8c6e8543 msg/security: Pas... |
493 |
err = security_msg_queue_msgctl(&msq->q_perm, cmd); |
156d9ed12 msgctl(): split t... |
494 495 |
if (err) goto out_unlock; |
87ad4b0d8 ipc: fix ipc data... |
496 497 498 499 500 501 502 |
ipc_lock_object(&msq->q_perm); if (!ipc_valid_object(&msq->q_perm)) { ipc_unlock_object(&msq->q_perm); err = -EIDRM; goto out_unlock; } |
156d9ed12 msgctl(): split t... |
503 504 505 506 |
kernel_to_ipc64_perm(&msq->q_perm, &p->msg_perm); p->msg_stime = msq->q_stime; p->msg_rtime = msq->q_rtime; p->msg_ctime = msq->q_ctime; |
c2ab975c3 y2038: ipc: Repor... |
507 508 509 510 511 |
#ifndef CONFIG_64BIT p->msg_stime_high = msq->q_stime >> 32; p->msg_rtime_high = msq->q_rtime >> 32; p->msg_ctime_high = msq->q_ctime >> 32; #endif |
156d9ed12 msgctl(): split t... |
512 513 514 |
p->msg_cbytes = msq->q_cbytes; p->msg_qnum = msq->q_qnum; p->msg_qbytes = msq->q_qbytes; |
39a4940ea ipc/msg: Fix msgc... |
515 516 |
p->msg_lspid = pid_vnr(msq->q_lspid); p->msg_lrpid = pid_vnr(msq->q_lrpid); |
2cafed30f ipc,msg: introduc... |
517 |
|
615c999cd ipc: compute kern... |
518 519 520 521 522 523 524 525 526 527 528 529 530 |
if (cmd == IPC_STAT) { /* * As defined in SUS: * Return 0 on success */ err = 0; } else { /* * MSG_STAT and MSG_STAT_ANY (both Linux specific) * Return the full id, including the sequence number */ err = msq->q_perm.id; } |
1da177e4c Linux-2.6.12-rc2 |
531 |
|
615c999cd ipc: compute kern... |
532 |
ipc_unlock_object(&msq->q_perm); |
1da177e4c Linux-2.6.12-rc2 |
533 |
out_unlock: |
ac0ba20ea ipc,msg: make msg... |
534 |
rcu_read_unlock(); |
1da177e4c Linux-2.6.12-rc2 |
535 536 |
return err; } |
e340db564 ipc: add msgctl s... |
537 |
long ksys_msgctl(int msqid, int cmd, struct msqid_ds __user *buf) |
2cafed30f ipc,msg: introduc... |
538 539 540 |
{ int version; struct ipc_namespace *ns; |
156d9ed12 msgctl(): split t... |
541 542 |
struct msqid64_ds msqid64; int err; |
2cafed30f ipc,msg: introduc... |
543 544 545 546 547 548 549 550 551 |
if (msqid < 0 || cmd < 0) return -EINVAL; version = ipc_parse_version(&cmd); ns = current->nsproxy->ipc_ns; switch (cmd) { case IPC_INFO: |
156d9ed12 msgctl(): split t... |
552 553 554 555 556 557 558 559 560 |
case MSG_INFO: { struct msginfo msginfo; err = msgctl_info(ns, msqid, cmd, &msginfo); if (err < 0) return err; if (copy_to_user(buf, &msginfo, sizeof(struct msginfo))) err = -EFAULT; return err; } |
2cafed30f ipc,msg: introduc... |
561 |
case MSG_STAT: /* msqid is an index rather than a msg queue id */ |
23c8cec8c ipc/msg: introduc... |
562 |
case MSG_STAT_ANY: |
2cafed30f ipc,msg: introduc... |
563 |
case IPC_STAT: |
156d9ed12 msgctl(): split t... |
564 565 566 567 568 569 |
err = msgctl_stat(ns, msqid, cmd, &msqid64); if (err < 0) return err; if (copy_msqid_to_user(buf, &msqid64, version)) err = -EFAULT; return err; |
2cafed30f ipc,msg: introduc... |
570 |
case IPC_SET: |
156d9ed12 msgctl(): split t... |
571 572 573 |
if (copy_msqid_from_user(&msqid64, buf, version)) return -EFAULT; /* fallthru */ |
2cafed30f ipc,msg: introduc... |
574 |
case IPC_RMID: |
156d9ed12 msgctl(): split t... |
575 |
return msgctl_down(ns, msqid, cmd, &msqid64); |
2cafed30f ipc,msg: introduc... |
576 577 578 579 |
default: return -EINVAL; } } |
e340db564 ipc: add msgctl s... |
580 581 582 583 |
SYSCALL_DEFINE3(msgctl, int, msqid, int, cmd, struct msqid_ds __user *, buf) { return ksys_msgctl(msqid, cmd, buf); } |
469391684 msgctl(): move co... |
584 585 586 587 588 589 |
#ifdef CONFIG_COMPAT struct compat_msqid_ds { struct compat_ipc_perm msg_perm; compat_uptr_t msg_first; compat_uptr_t msg_last; |
9afc5eee6 y2038: globally r... |
590 591 592 |
old_time32_t msg_stime; old_time32_t msg_rtime; old_time32_t msg_ctime; |
469391684 msgctl(): move co... |
593 594 595 596 597 598 599 600 601 602 603 604 605 606 |
compat_ulong_t msg_lcbytes; compat_ulong_t msg_lqbytes; unsigned short msg_cbytes; unsigned short msg_qnum; unsigned short msg_qbytes; compat_ipc_pid_t msg_lspid; compat_ipc_pid_t msg_lrpid; }; static int copy_compat_msqid_from_user(struct msqid64_ds *out, void __user *buf, int version) { memset(out, 0, sizeof(*out)); if (version == IPC_64) { |
6aa211e8c fix address space... |
607 |
struct compat_msqid64_ds __user *p = buf; |
28327fae6 ipc: make use of ... |
608 |
if (get_compat_ipc64_perm(&out->msg_perm, &p->msg_perm)) |
469391684 msgctl(): move co... |
609 |
return -EFAULT; |
469391684 msgctl(): move co... |
610 611 612 |
if (get_user(out->msg_qbytes, &p->msg_qbytes)) return -EFAULT; } else { |
6aa211e8c fix address space... |
613 |
struct compat_msqid_ds __user *p = buf; |
28327fae6 ipc: make use of ... |
614 |
if (get_compat_ipc_perm(&out->msg_perm, &p->msg_perm)) |
469391684 msgctl(): move co... |
615 |
return -EFAULT; |
469391684 msgctl(): move co... |
616 617 618 619 620 621 622 623 624 625 626 627 |
if (get_user(out->msg_qbytes, &p->msg_qbytes)) return -EFAULT; } return 0; } static int copy_compat_msqid_to_user(void __user *buf, struct msqid64_ds *in, int version) { if (version == IPC_64) { struct compat_msqid64_ds v; memset(&v, 0, sizeof(v)); |
28327fae6 ipc: make use of ... |
628 |
to_compat_ipc64_perm(&v.msg_perm, &in->msg_perm); |
c2ab975c3 y2038: ipc: Repor... |
629 630 631 632 633 634 |
v.msg_stime = lower_32_bits(in->msg_stime); v.msg_stime_high = upper_32_bits(in->msg_stime); v.msg_rtime = lower_32_bits(in->msg_rtime); v.msg_rtime_high = upper_32_bits(in->msg_rtime); v.msg_ctime = lower_32_bits(in->msg_ctime); v.msg_ctime_high = upper_32_bits(in->msg_ctime); |
469391684 msgctl(): move co... |
635 636 637 638 639 640 641 642 643 |
v.msg_cbytes = in->msg_cbytes; v.msg_qnum = in->msg_qnum; v.msg_qbytes = in->msg_qbytes; v.msg_lspid = in->msg_lspid; v.msg_lrpid = in->msg_lrpid; return copy_to_user(buf, &v, sizeof(v)); } else { struct compat_msqid_ds v; memset(&v, 0, sizeof(v)); |
28327fae6 ipc: make use of ... |
644 |
to_compat_ipc_perm(&v.msg_perm, &in->msg_perm); |
469391684 msgctl(): move co... |
645 646 647 648 649 650 651 652 653 654 655 |
v.msg_stime = in->msg_stime; v.msg_rtime = in->msg_rtime; v.msg_ctime = in->msg_ctime; v.msg_cbytes = in->msg_cbytes; v.msg_qnum = in->msg_qnum; v.msg_qbytes = in->msg_qbytes; v.msg_lspid = in->msg_lspid; v.msg_lrpid = in->msg_lrpid; return copy_to_user(buf, &v, sizeof(v)); } } |
e340db564 ipc: add msgctl s... |
656 |
long compat_ksys_msgctl(int msqid, int cmd, void __user *uptr) |
469391684 msgctl(): move co... |
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
{ struct ipc_namespace *ns; int err; struct msqid64_ds msqid64; int version = compat_ipc_parse_version(&cmd); ns = current->nsproxy->ipc_ns; if (msqid < 0 || cmd < 0) return -EINVAL; switch (cmd & (~IPC_64)) { case IPC_INFO: case MSG_INFO: { struct msginfo msginfo; err = msgctl_info(ns, msqid, cmd, &msginfo); if (err < 0) return err; if (copy_to_user(uptr, &msginfo, sizeof(struct msginfo))) err = -EFAULT; return err; } case IPC_STAT: case MSG_STAT: |
23c8cec8c ipc/msg: introduc... |
681 |
case MSG_STAT_ANY: |
469391684 msgctl(): move co... |
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 |
err = msgctl_stat(ns, msqid, cmd, &msqid64); if (err < 0) return err; if (copy_compat_msqid_to_user(uptr, &msqid64, version)) err = -EFAULT; return err; case IPC_SET: if (copy_compat_msqid_from_user(&msqid64, uptr, version)) return -EFAULT; /* fallthru */ case IPC_RMID: return msgctl_down(ns, msqid, cmd, &msqid64); default: return -EINVAL; } } |
e340db564 ipc: add msgctl s... |
698 699 700 701 702 |
COMPAT_SYSCALL_DEFINE3(msgctl, int, msqid, int, cmd, void __user *, uptr) { return compat_ksys_msgctl(msqid, cmd, uptr); } |
469391684 msgctl(): move co... |
703 |
#endif |
5a06a363e [PATCH] ipc/msg.c... |
704 |
static int testmsg(struct msg_msg *msg, long type, int mode) |
1da177e4c Linux-2.6.12-rc2 |
705 |
{ |
46c0a8ca3 ipc, kernel: clea... |
706 707 708 709 710 711 712 713 714 715 |
switch (mode) { case SEARCH_ANY: case SEARCH_NUMBER: return 1; case SEARCH_LESSEQUAL: if (msg->m_type <= type) return 1; break; case SEARCH_EQUAL: if (msg->m_type == type) |
1da177e4c Linux-2.6.12-rc2 |
716 |
return 1; |
46c0a8ca3 ipc, kernel: clea... |
717 718 719 720 721 |
break; case SEARCH_NOTEQUAL: if (msg->m_type != type) return 1; break; |
1da177e4c Linux-2.6.12-rc2 |
722 723 724 |
} return 0; } |
ee51636ca ipc/msg: implemen... |
725 726 |
static inline int pipelined_send(struct msg_queue *msq, struct msg_msg *msg, struct wake_q_head *wake_q) |
1da177e4c Linux-2.6.12-rc2 |
727 |
{ |
41239fe82 ipc/msg.c: use li... |
728 |
struct msg_receiver *msr, *t; |
5a06a363e [PATCH] ipc/msg.c... |
729 |
|
41239fe82 ipc/msg.c: use li... |
730 |
list_for_each_entry_safe(msr, t, &msq->q_receivers, r_list) { |
5a06a363e [PATCH] ipc/msg.c... |
731 |
if (testmsg(msg, msr->r_msgtype, msr->r_mode) && |
d8c6e8543 msg/security: Pas... |
732 |
!security_msg_queue_msgrcv(&msq->q_perm, msg, msr->r_tsk, |
5a06a363e [PATCH] ipc/msg.c... |
733 |
msr->r_msgtype, msr->r_mode)) { |
1da177e4c Linux-2.6.12-rc2 |
734 |
list_del(&msr->r_list); |
5a06a363e [PATCH] ipc/msg.c... |
735 |
if (msr->r_maxsize < msg->m_ts) { |
ee51636ca ipc/msg: implemen... |
736 737 |
wake_q_add(wake_q, msr->r_tsk); WRITE_ONCE(msr->r_msg, ERR_PTR(-E2BIG)); |
1da177e4c Linux-2.6.12-rc2 |
738 |
} else { |
39a4940ea ipc/msg: Fix msgc... |
739 |
ipc_update_pid(&msq->q_lrpid, task_pid(msr->r_tsk)); |
2a70b7879 y2038: ipc: Use k... |
740 |
msq->q_rtime = ktime_get_real_seconds(); |
5a06a363e [PATCH] ipc/msg.c... |
741 |
|
ee51636ca ipc/msg: implemen... |
742 743 |
wake_q_add(wake_q, msr->r_tsk); WRITE_ONCE(msr->r_msg, msg); |
1da177e4c Linux-2.6.12-rc2 |
744 745 746 747 |
return 1; } } } |
ffa571daf ipc,msg: document... |
748 |
|
1da177e4c Linux-2.6.12-rc2 |
749 750 |
return 0; } |
9b1404c24 msgrcv(2), msgsnd... |
751 |
static long do_msgsnd(int msqid, long mtype, void __user *mtext, |
651971cb7 [PATCH] Fix the s... |
752 |
size_t msgsz, int msgflg) |
1da177e4c Linux-2.6.12-rc2 |
753 754 755 |
{ struct msg_queue *msq; struct msg_msg *msg; |
1da177e4c Linux-2.6.12-rc2 |
756 |
int err; |
1e7869373 [PATCH] IPC names... |
757 |
struct ipc_namespace *ns; |
194a6b5b9 sched/wake_q: Ren... |
758 |
DEFINE_WAKE_Q(wake_q); |
1e7869373 [PATCH] IPC names... |
759 760 |
ns = current->nsproxy->ipc_ns; |
5a06a363e [PATCH] ipc/msg.c... |
761 |
|
1e7869373 [PATCH] IPC names... |
762 |
if (msgsz > ns->msg_ctlmax || (long) msgsz < 0 || msqid < 0) |
1da177e4c Linux-2.6.12-rc2 |
763 |
return -EINVAL; |
1da177e4c Linux-2.6.12-rc2 |
764 765 |
if (mtype < 1) return -EINVAL; |
651971cb7 [PATCH] Fix the s... |
766 |
msg = load_msg(mtext, msgsz); |
5a06a363e [PATCH] ipc/msg.c... |
767 |
if (IS_ERR(msg)) |
1da177e4c Linux-2.6.12-rc2 |
768 769 770 771 |
return PTR_ERR(msg); msg->m_type = mtype; msg->m_ts = msgsz; |
3dd1f784e ipc,msg: shorten ... |
772 773 |
rcu_read_lock(); msq = msq_obtain_object_check(ns, msqid); |
023a53557 ipc: integrate ip... |
774 775 |
if (IS_ERR(msq)) { err = PTR_ERR(msq); |
3dd1f784e ipc,msg: shorten ... |
776 |
goto out_unlock1; |
023a53557 ipc: integrate ip... |
777 |
} |
1da177e4c Linux-2.6.12-rc2 |
778 |
|
bebcb928c ipc/msg.c: Fix lo... |
779 |
ipc_lock_object(&msq->q_perm); |
1da177e4c Linux-2.6.12-rc2 |
780 781 |
for (;;) { struct msg_sender s; |
5a06a363e [PATCH] ipc/msg.c... |
782 |
err = -EACCES; |
b0e77598f userns: user name... |
783 |
if (ipcperms(ns, &msq->q_perm, S_IWUGO)) |
bebcb928c ipc/msg.c: Fix lo... |
784 |
goto out_unlock0; |
1da177e4c Linux-2.6.12-rc2 |
785 |
|
4271b05a2 ipc,msg: prevent ... |
786 |
/* raced with RMID? */ |
0f3d2b013 ipc: introduce ip... |
787 |
if (!ipc_valid_object(&msq->q_perm)) { |
4271b05a2 ipc,msg: prevent ... |
788 789 790 |
err = -EIDRM; goto out_unlock0; } |
d8c6e8543 msg/security: Pas... |
791 |
err = security_msg_queue_msgsnd(&msq->q_perm, msg, msgflg); |
1da177e4c Linux-2.6.12-rc2 |
792 |
if (err) |
bebcb928c ipc/msg.c: Fix lo... |
793 |
goto out_unlock0; |
1da177e4c Linux-2.6.12-rc2 |
794 |
|
ed27f9122 ipc/msg: avoid wa... |
795 |
if (msg_fits_inqueue(msq, msgsz)) |
1da177e4c Linux-2.6.12-rc2 |
796 |
break; |
1da177e4c Linux-2.6.12-rc2 |
797 798 |
/* queue full, wait: */ |
5a06a363e [PATCH] ipc/msg.c... |
799 800 |
if (msgflg & IPC_NOWAIT) { err = -EAGAIN; |
bebcb928c ipc/msg.c: Fix lo... |
801 |
goto out_unlock0; |
1da177e4c Linux-2.6.12-rc2 |
802 |
} |
3dd1f784e ipc,msg: shorten ... |
803 |
|
ffa571daf ipc,msg: document... |
804 |
/* enqueue the sender and prepare to block */ |
ed27f9122 ipc/msg: avoid wa... |
805 |
ss_add(msq, &s, msgsz); |
6062a8dc0 ipc,sem: fine gra... |
806 |
|
dba4cdd39 ipc: merge ipc_rc... |
807 |
if (!ipc_rcu_getref(&msq->q_perm)) { |
6062a8dc0 ipc,sem: fine gra... |
808 |
err = -EIDRM; |
3dd1f784e ipc,msg: shorten ... |
809 |
goto out_unlock0; |
6062a8dc0 ipc,sem: fine gra... |
810 |
} |
3dd1f784e ipc,msg: shorten ... |
811 812 |
ipc_unlock_object(&msq->q_perm); rcu_read_unlock(); |
1da177e4c Linux-2.6.12-rc2 |
813 |
schedule(); |
3dd1f784e ipc,msg: shorten ... |
814 815 |
rcu_read_lock(); ipc_lock_object(&msq->q_perm); |
dba4cdd39 ipc: merge ipc_rc... |
816 |
ipc_rcu_putref(&msq->q_perm, msg_rcu_free); |
0f3d2b013 ipc: introduce ip... |
817 818 |
/* raced with RMID? */ if (!ipc_valid_object(&msq->q_perm)) { |
1da177e4c Linux-2.6.12-rc2 |
819 |
err = -EIDRM; |
3dd1f784e ipc,msg: shorten ... |
820 |
goto out_unlock0; |
1da177e4c Linux-2.6.12-rc2 |
821 822 |
} ss_del(&s); |
5a06a363e [PATCH] ipc/msg.c... |
823 |
|
1da177e4c Linux-2.6.12-rc2 |
824 |
if (signal_pending(current)) { |
5a06a363e [PATCH] ipc/msg.c... |
825 |
err = -ERESTARTNOHAND; |
3dd1f784e ipc,msg: shorten ... |
826 |
goto out_unlock0; |
1da177e4c Linux-2.6.12-rc2 |
827 |
} |
3dd1f784e ipc,msg: shorten ... |
828 |
|
1da177e4c Linux-2.6.12-rc2 |
829 |
} |
ed27f9122 ipc/msg: avoid wa... |
830 |
|
39a4940ea ipc/msg: Fix msgc... |
831 |
ipc_update_pid(&msq->q_lspid, task_tgid(current)); |
2a70b7879 y2038: ipc: Use k... |
832 |
msq->q_stime = ktime_get_real_seconds(); |
1da177e4c Linux-2.6.12-rc2 |
833 |
|
ee51636ca ipc/msg: implemen... |
834 |
if (!pipelined_send(msq, msg, &wake_q)) { |
25985edce Fix common misspe... |
835 |
/* no one is waiting for this message, enqueue it */ |
5a06a363e [PATCH] ipc/msg.c... |
836 |
list_add_tail(&msg->m_list, &msq->q_messages); |
1da177e4c Linux-2.6.12-rc2 |
837 838 |
msq->q_cbytes += msgsz; msq->q_qnum++; |
3ac88a41f virtualization of... |
839 840 |
atomic_add(msgsz, &ns->msg_bytes); atomic_inc(&ns->msg_hdrs); |
1da177e4c Linux-2.6.12-rc2 |
841 |
} |
5a06a363e [PATCH] ipc/msg.c... |
842 |
|
1da177e4c Linux-2.6.12-rc2 |
843 844 |
err = 0; msg = NULL; |
3dd1f784e ipc,msg: shorten ... |
845 846 |
out_unlock0: ipc_unlock_object(&msq->q_perm); |
ee51636ca ipc/msg: implemen... |
847 |
wake_up_q(&wake_q); |
3dd1f784e ipc,msg: shorten ... |
848 849 |
out_unlock1: rcu_read_unlock(); |
5a06a363e [PATCH] ipc/msg.c... |
850 |
if (msg != NULL) |
1da177e4c Linux-2.6.12-rc2 |
851 852 853 |
free_msg(msg); return err; } |
31c213f21 ipc: add msgsnd s... |
854 855 |
long ksys_msgsnd(int msqid, struct msgbuf __user *msgp, size_t msgsz, int msgflg) |
651971cb7 [PATCH] Fix the s... |
856 857 858 859 860 861 862 |
{ long mtype; if (get_user(mtype, &msgp->mtype)) return -EFAULT; return do_msgsnd(msqid, mtype, msgp->mtext, msgsz, msgflg); } |
31c213f21 ipc: add msgsnd s... |
863 864 865 866 867 |
SYSCALL_DEFINE4(msgsnd, int, msqid, struct msgbuf __user *, msgp, size_t, msgsz, int, msgflg) { return ksys_msgsnd(msqid, msgp, msgsz, msgflg); } |
9b1404c24 msgrcv(2), msgsnd... |
868 869 870 871 872 873 |
#ifdef CONFIG_COMPAT struct compat_msgbuf { compat_long_t mtype; char mtext[1]; }; |
31c213f21 ipc: add msgsnd s... |
874 875 |
long compat_ksys_msgsnd(int msqid, compat_uptr_t msgp, compat_ssize_t msgsz, int msgflg) |
9b1404c24 msgrcv(2), msgsnd... |
876 877 878 879 880 881 882 883 |
{ struct compat_msgbuf __user *up = compat_ptr(msgp); compat_long_t mtype; if (get_user(mtype, &up->mtype)) return -EFAULT; return do_msgsnd(msqid, mtype, up->mtext, (ssize_t)msgsz, msgflg); } |
31c213f21 ipc: add msgsnd s... |
884 885 886 887 888 889 |
COMPAT_SYSCALL_DEFINE4(msgsnd, int, msqid, compat_uptr_t, msgp, compat_ssize_t, msgsz, int, msgflg) { return compat_ksys_msgsnd(msqid, msgp, msgsz, msgflg); } |
9b1404c24 msgrcv(2), msgsnd... |
890 |
#endif |
5a06a363e [PATCH] ipc/msg.c... |
891 |
static inline int convert_mode(long *msgtyp, int msgflg) |
1da177e4c Linux-2.6.12-rc2 |
892 |
{ |
8ac6ed585 ipc: implement MS... |
893 894 |
if (msgflg & MSG_COPY) return SEARCH_NUMBER; |
5a06a363e [PATCH] ipc/msg.c... |
895 |
/* |
1da177e4c Linux-2.6.12-rc2 |
896 897 898 |
* find message of correct type. * msgtyp = 0 => get first. * msgtyp > 0 => get first message of matching type. |
5a06a363e [PATCH] ipc/msg.c... |
899 |
* msgtyp < 0 => get message with least type must be < abs(msgtype). |
1da177e4c Linux-2.6.12-rc2 |
900 |
*/ |
5a06a363e [PATCH] ipc/msg.c... |
901 |
if (*msgtyp == 0) |
1da177e4c Linux-2.6.12-rc2 |
902 |
return SEARCH_ANY; |
5a06a363e [PATCH] ipc/msg.c... |
903 |
if (*msgtyp < 0) { |
999898355 ipc: msg, make ms... |
904 905 906 907 |
if (*msgtyp == LONG_MIN) /* -LONG_MIN is undefined */ *msgtyp = LONG_MAX; else *msgtyp = -*msgtyp; |
1da177e4c Linux-2.6.12-rc2 |
908 909 |
return SEARCH_LESSEQUAL; } |
5a06a363e [PATCH] ipc/msg.c... |
910 |
if (msgflg & MSG_EXCEPT) |
1da177e4c Linux-2.6.12-rc2 |
911 912 913 |
return SEARCH_NOTEQUAL; return SEARCH_EQUAL; } |
f9dd87f47 ipc: message queu... |
914 915 916 917 918 919 920 921 922 923 924 925 926 |
static long do_msg_fill(void __user *dest, struct msg_msg *msg, size_t bufsz) { struct msgbuf __user *msgp = dest; size_t msgsz; if (put_user(msg->m_type, &msgp->mtype)) return -EFAULT; msgsz = (bufsz > msg->m_ts) ? msg->m_ts : bufsz; if (store_msg(msgp->mtext, msg, msgsz)) return -EFAULT; return msgsz; } |
4a674f34b ipc: introduce me... |
927 |
#ifdef CONFIG_CHECKPOINT_RESTORE |
3fcfe7865 ipc: add more com... |
928 929 930 931 |
/* * This function creates new kernel message structure, large enough to store * bufsz message bytes. */ |
8ac6ed585 ipc: implement MS... |
932 |
static inline struct msg_msg *prepare_copy(void __user *buf, size_t bufsz) |
4a674f34b ipc: introduce me... |
933 934 |
{ struct msg_msg *copy; |
4a674f34b ipc: introduce me... |
935 936 937 938 939 940 941 942 |
/* * Create dummy message to copy real message to. */ copy = load_msg(buf, bufsz); if (!IS_ERR(copy)) copy->m_ts = bufsz; return copy; } |
85398aa8d ipc: simplify fre... |
943 |
static inline void free_copy(struct msg_msg *copy) |
4a674f34b ipc: introduce me... |
944 |
{ |
85398aa8d ipc: simplify fre... |
945 |
if (copy) |
4a674f34b ipc: introduce me... |
946 947 948 |
free_msg(copy); } #else |
8ac6ed585 ipc: implement MS... |
949 |
static inline struct msg_msg *prepare_copy(void __user *buf, size_t bufsz) |
b30efe277 ipc: convert prep... |
950 951 952 |
{ return ERR_PTR(-ENOSYS); } |
85398aa8d ipc: simplify fre... |
953 954 955 |
static inline void free_copy(struct msg_msg *copy) { } |
4a674f34b ipc: introduce me... |
956 |
#endif |
daaf74cf0 ipc: refactor msg... |
957 958 |
static struct msg_msg *find_msg(struct msg_queue *msq, long *msgtyp, int mode) { |
368ae537e IPC: bugfix for m... |
959 |
struct msg_msg *msg, *found = NULL; |
daaf74cf0 ipc: refactor msg... |
960 961 962 963 |
long count = 0; list_for_each_entry(msg, &msq->q_messages, m_list) { if (testmsg(msg, *msgtyp, mode) && |
d8c6e8543 msg/security: Pas... |
964 |
!security_msg_queue_msgrcv(&msq->q_perm, msg, current, |
daaf74cf0 ipc: refactor msg... |
965 966 967 |
*msgtyp, mode)) { if (mode == SEARCH_LESSEQUAL && msg->m_type != 1) { *msgtyp = msg->m_type - 1; |
368ae537e IPC: bugfix for m... |
968 |
found = msg; |
daaf74cf0 ipc: refactor msg... |
969 970 971 972 973 974 975 976 |
} else if (mode == SEARCH_NUMBER) { if (*msgtyp == count) return msg; } else return msg; count++; } } |
368ae537e IPC: bugfix for m... |
977 |
return found ?: ERR_PTR(-EAGAIN); |
daaf74cf0 ipc: refactor msg... |
978 |
} |
9b1404c24 msgrcv(2), msgsnd... |
979 |
static long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp, int msgflg, |
f9dd87f47 ipc: message queu... |
980 |
long (*msg_handler)(void __user *, struct msg_msg *, size_t)) |
1da177e4c Linux-2.6.12-rc2 |
981 |
{ |
1da177e4c Linux-2.6.12-rc2 |
982 |
int mode; |
41a0d523d ipc,msg: shorten ... |
983 |
struct msg_queue *msq; |
1e7869373 [PATCH] IPC names... |
984 |
struct ipc_namespace *ns; |
41a0d523d ipc,msg: shorten ... |
985 |
struct msg_msg *msg, *copy = NULL; |
194a6b5b9 sched/wake_q: Ren... |
986 |
DEFINE_WAKE_Q(wake_q); |
1da177e4c Linux-2.6.12-rc2 |
987 |
|
88b9e456b ipc: don't alloca... |
988 |
ns = current->nsproxy->ipc_ns; |
f9dd87f47 ipc: message queu... |
989 |
if (msqid < 0 || (long) bufsz < 0) |
1da177e4c Linux-2.6.12-rc2 |
990 |
return -EINVAL; |
41a0d523d ipc,msg: shorten ... |
991 |
|
4a674f34b ipc: introduce me... |
992 |
if (msgflg & MSG_COPY) { |
4f87dac38 ipc: Fix 2 bugs i... |
993 994 |
if ((msgflg & MSG_EXCEPT) || !(msgflg & IPC_NOWAIT)) return -EINVAL; |
8ac6ed585 ipc: implement MS... |
995 |
copy = prepare_copy(buf, min_t(size_t, bufsz, ns->msg_ctlmax)); |
4a674f34b ipc: introduce me... |
996 997 998 |
if (IS_ERR(copy)) return PTR_ERR(copy); } |
5a06a363e [PATCH] ipc/msg.c... |
999 |
mode = convert_mode(&msgtyp, msgflg); |
1da177e4c Linux-2.6.12-rc2 |
1000 |
|
41a0d523d ipc,msg: shorten ... |
1001 1002 |
rcu_read_lock(); msq = msq_obtain_object_check(ns, msqid); |
4a674f34b ipc: introduce me... |
1003 |
if (IS_ERR(msq)) { |
41a0d523d ipc,msg: shorten ... |
1004 |
rcu_read_unlock(); |
85398aa8d ipc: simplify fre... |
1005 |
free_copy(copy); |
023a53557 ipc: integrate ip... |
1006 |
return PTR_ERR(msq); |
4a674f34b ipc: introduce me... |
1007 |
} |
1da177e4c Linux-2.6.12-rc2 |
1008 1009 1010 |
for (;;) { struct msg_receiver msr_d; |
1da177e4c Linux-2.6.12-rc2 |
1011 1012 |
msg = ERR_PTR(-EACCES); |
b0e77598f userns: user name... |
1013 |
if (ipcperms(ns, &msq->q_perm, S_IRUGO)) |
41a0d523d ipc,msg: shorten ... |
1014 |
goto out_unlock1; |
1da177e4c Linux-2.6.12-rc2 |
1015 |
|
41a0d523d ipc,msg: shorten ... |
1016 |
ipc_lock_object(&msq->q_perm); |
4271b05a2 ipc,msg: prevent ... |
1017 1018 |
/* raced with RMID? */ |
0f3d2b013 ipc: introduce ip... |
1019 |
if (!ipc_valid_object(&msq->q_perm)) { |
4271b05a2 ipc,msg: prevent ... |
1020 1021 1022 |
msg = ERR_PTR(-EIDRM); goto out_unlock0; } |
daaf74cf0 ipc: refactor msg... |
1023 |
msg = find_msg(msq, &msgtyp, mode); |
5a06a363e [PATCH] ipc/msg.c... |
1024 1025 1026 1027 1028 |
if (!IS_ERR(msg)) { /* * Found a suitable message. * Unlink it from the queue. */ |
f9dd87f47 ipc: message queu... |
1029 |
if ((bufsz < msg->m_ts) && !(msgflg & MSG_NOERROR)) { |
1da177e4c Linux-2.6.12-rc2 |
1030 |
msg = ERR_PTR(-E2BIG); |
41a0d523d ipc,msg: shorten ... |
1031 |
goto out_unlock0; |
1da177e4c Linux-2.6.12-rc2 |
1032 |
} |
3fcfe7865 ipc: add more com... |
1033 1034 1035 1036 |
/* * If we are copying, then do not unlink message and do * not update queue parameters. */ |
852028af8 ipc: remove msg h... |
1037 1038 |
if (msgflg & MSG_COPY) { msg = copy_msg(msg, copy); |
41a0d523d ipc,msg: shorten ... |
1039 |
goto out_unlock0; |
852028af8 ipc: remove msg h... |
1040 |
} |
41a0d523d ipc,msg: shorten ... |
1041 |
|
1da177e4c Linux-2.6.12-rc2 |
1042 1043 |
list_del(&msg->m_list); msq->q_qnum--; |
2a70b7879 y2038: ipc: Use k... |
1044 |
msq->q_rtime = ktime_get_real_seconds(); |
39a4940ea ipc/msg: Fix msgc... |
1045 |
ipc_update_pid(&msq->q_lrpid, task_tgid(current)); |
1da177e4c Linux-2.6.12-rc2 |
1046 |
msq->q_cbytes -= msg->m_ts; |
3ac88a41f virtualization of... |
1047 1048 |
atomic_sub(msg->m_ts, &ns->msg_bytes); atomic_dec(&ns->msg_hdrs); |
ed27f9122 ipc/msg: avoid wa... |
1049 |
ss_wakeup(msq, &wake_q, false); |
41a0d523d ipc,msg: shorten ... |
1050 1051 |
goto out_unlock0; |
1da177e4c Linux-2.6.12-rc2 |
1052 |
} |
41a0d523d ipc,msg: shorten ... |
1053 |
|
1da177e4c Linux-2.6.12-rc2 |
1054 1055 1056 |
/* No message waiting. Wait for a message */ if (msgflg & IPC_NOWAIT) { msg = ERR_PTR(-ENOMSG); |
41a0d523d ipc,msg: shorten ... |
1057 |
goto out_unlock0; |
1da177e4c Linux-2.6.12-rc2 |
1058 |
} |
41a0d523d ipc,msg: shorten ... |
1059 |
|
5a06a363e [PATCH] ipc/msg.c... |
1060 |
list_add_tail(&msr_d.r_list, &msq->q_receivers); |
1da177e4c Linux-2.6.12-rc2 |
1061 1062 1063 |
msr_d.r_tsk = current; msr_d.r_msgtype = msgtyp; msr_d.r_mode = mode; |
5a06a363e [PATCH] ipc/msg.c... |
1064 |
if (msgflg & MSG_NOERROR) |
1da177e4c Linux-2.6.12-rc2 |
1065 |
msr_d.r_maxsize = INT_MAX; |
5a06a363e [PATCH] ipc/msg.c... |
1066 |
else |
f9dd87f47 ipc: message queu... |
1067 |
msr_d.r_maxsize = bufsz; |
1da177e4c Linux-2.6.12-rc2 |
1068 |
msr_d.r_msg = ERR_PTR(-EAGAIN); |
f75a2f358 ipc,msg: use curr... |
1069 |
__set_current_state(TASK_INTERRUPTIBLE); |
1da177e4c Linux-2.6.12-rc2 |
1070 |
|
41a0d523d ipc,msg: shorten ... |
1071 1072 |
ipc_unlock_object(&msq->q_perm); rcu_read_unlock(); |
1da177e4c Linux-2.6.12-rc2 |
1073 |
schedule(); |
ee51636ca ipc/msg: implemen... |
1074 1075 1076 1077 1078 1079 |
/* * Lockless receive, part 1: * We don't hold a reference to the queue and getting a * reference would defeat the idea of a lockless operation, * thus the code relies on rcu to guarantee the existence of * msq: |
1da177e4c Linux-2.6.12-rc2 |
1080 1081 |
* Prior to destruction, expunge_all(-EIRDM) changes r_msg. * Thus if r_msg is -EAGAIN, then the queue not yet destroyed. |
1da177e4c Linux-2.6.12-rc2 |
1082 1083 |
*/ rcu_read_lock(); |
ee51636ca ipc/msg: implemen... |
1084 1085 1086 1087 1088 1089 |
/* * Lockless receive, part 2: * The work in pipelined_send() and expunge_all(): * - Set pointer to message * - Queue the receiver task for later wakeup * - Wake up the process after the lock is dropped. |
ff35e5ef8 ipc,msg: provide ... |
1090 |
* |
ee51636ca ipc/msg: implemen... |
1091 1092 |
* Should the process wake up before this wakeup (due to a * signal) it will either see the message and continue ... |
1da177e4c Linux-2.6.12-rc2 |
1093 |
*/ |
ee51636ca ipc/msg: implemen... |
1094 |
msg = READ_ONCE(msr_d.r_msg); |
41a0d523d ipc,msg: shorten ... |
1095 1096 |
if (msg != ERR_PTR(-EAGAIN)) goto out_unlock1; |
1da177e4c Linux-2.6.12-rc2 |
1097 |
|
ee51636ca ipc/msg: implemen... |
1098 1099 1100 1101 |
/* * ... or see -EAGAIN, acquire the lock to check the message * again. */ |
41a0d523d ipc,msg: shorten ... |
1102 |
ipc_lock_object(&msq->q_perm); |
1da177e4c Linux-2.6.12-rc2 |
1103 |
|
ee51636ca ipc/msg: implemen... |
1104 |
msg = msr_d.r_msg; |
5a06a363e [PATCH] ipc/msg.c... |
1105 |
if (msg != ERR_PTR(-EAGAIN)) |
41a0d523d ipc,msg: shorten ... |
1106 |
goto out_unlock0; |
1da177e4c Linux-2.6.12-rc2 |
1107 1108 1109 1110 |
list_del(&msr_d.r_list); if (signal_pending(current)) { msg = ERR_PTR(-ERESTARTNOHAND); |
41a0d523d ipc,msg: shorten ... |
1111 |
goto out_unlock0; |
1da177e4c Linux-2.6.12-rc2 |
1112 |
} |
41a0d523d ipc,msg: shorten ... |
1113 1114 |
ipc_unlock_object(&msq->q_perm); |
1da177e4c Linux-2.6.12-rc2 |
1115 |
} |
41a0d523d ipc,msg: shorten ... |
1116 1117 1118 |
out_unlock0: ipc_unlock_object(&msq->q_perm); |
e3658538b ipc/msg: batch qu... |
1119 |
wake_up_q(&wake_q); |
41a0d523d ipc,msg: shorten ... |
1120 1121 |
out_unlock1: rcu_read_unlock(); |
4a674f34b ipc: introduce me... |
1122 |
if (IS_ERR(msg)) { |
85398aa8d ipc: simplify fre... |
1123 |
free_copy(copy); |
5a06a363e [PATCH] ipc/msg.c... |
1124 |
return PTR_ERR(msg); |
4a674f34b ipc: introduce me... |
1125 |
} |
1da177e4c Linux-2.6.12-rc2 |
1126 |
|
f9dd87f47 ipc: message queu... |
1127 |
bufsz = msg_handler(buf, msg, bufsz); |
1da177e4c Linux-2.6.12-rc2 |
1128 |
free_msg(msg); |
5a06a363e [PATCH] ipc/msg.c... |
1129 |
|
f9dd87f47 ipc: message queu... |
1130 |
return bufsz; |
1da177e4c Linux-2.6.12-rc2 |
1131 |
} |
078faac9e ipc: add msgrcv s... |
1132 1133 1134 1135 1136 |
long ksys_msgrcv(int msqid, struct msgbuf __user *msgp, size_t msgsz, long msgtyp, int msgflg) { return do_msgrcv(msqid, msgp, msgsz, msgtyp, msgflg, do_msg_fill); } |
e48fbb699 [CVE-2009-0029] S... |
1137 1138 |
SYSCALL_DEFINE5(msgrcv, int, msqid, struct msgbuf __user *, msgp, size_t, msgsz, long, msgtyp, int, msgflg) |
651971cb7 [PATCH] Fix the s... |
1139 |
{ |
078faac9e ipc: add msgrcv s... |
1140 |
return ksys_msgrcv(msqid, msgp, msgsz, msgtyp, msgflg); |
651971cb7 [PATCH] Fix the s... |
1141 |
} |
9b1404c24 msgrcv(2), msgsnd... |
1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 |
#ifdef CONFIG_COMPAT static long compat_do_msg_fill(void __user *dest, struct msg_msg *msg, size_t bufsz) { struct compat_msgbuf __user *msgp = dest; size_t msgsz; if (put_user(msg->m_type, &msgp->mtype)) return -EFAULT; msgsz = (bufsz > msg->m_ts) ? msg->m_ts : bufsz; if (store_msg(msgp->mtext, msg, msgsz)) return -EFAULT; return msgsz; } |
078faac9e ipc: add msgrcv s... |
1156 1157 |
long compat_ksys_msgrcv(int msqid, compat_uptr_t msgp, compat_ssize_t msgsz, compat_long_t msgtyp, int msgflg) |
9b1404c24 msgrcv(2), msgsnd... |
1158 1159 1160 1161 |
{ return do_msgrcv(msqid, compat_ptr(msgp), (ssize_t)msgsz, (long)msgtyp, msgflg, compat_do_msg_fill); } |
078faac9e ipc: add msgrcv s... |
1162 1163 1164 1165 1166 1167 1168 |
COMPAT_SYSCALL_DEFINE5(msgrcv, int, msqid, compat_uptr_t, msgp, compat_ssize_t, msgsz, compat_long_t, msgtyp, int, msgflg) { return compat_ksys_msgrcv(msqid, msgp, msgsz, msgtyp, msgflg); } |
9b1404c24 msgrcv(2), msgsnd... |
1169 |
#endif |
3440a6bd1 ipc,msg: move som... |
1170 |
|
eae04d25a ipc: simplify ipc... |
1171 |
void msg_init_ns(struct ipc_namespace *ns) |
3440a6bd1 ipc,msg: move som... |
1172 1173 1174 |
{ ns->msg_ctlmax = MSGMAX; ns->msg_ctlmnb = MSGMNB; |
0050ee059 ipc/msg: increase... |
1175 |
ns->msg_ctlmni = MSGMNI; |
3440a6bd1 ipc,msg: move som... |
1176 1177 1178 |
atomic_set(&ns->msg_bytes, 0); atomic_set(&ns->msg_hdrs, 0); |
eae04d25a ipc: simplify ipc... |
1179 |
ipc_init_ids(&ns->ids[IPC_MSG_IDS]); |
3440a6bd1 ipc,msg: move som... |
1180 1181 1182 1183 1184 1185 1186 |
} #ifdef CONFIG_IPC_NS void msg_exit_ns(struct ipc_namespace *ns) { free_ipcs(ns, &msg_ids(ns), freeque); idr_destroy(&ns->ids[IPC_MSG_IDS].ipcs_idr); |
0cfb6aee7 ipc: optimize sem... |
1187 |
rhashtable_destroy(&ns->ids[IPC_MSG_IDS].key_ht); |
3440a6bd1 ipc,msg: move som... |
1188 1189 |
} #endif |
1da177e4c Linux-2.6.12-rc2 |
1190 |
#ifdef CONFIG_PROC_FS |
19b4946ca [PATCH] ipc: conv... |
1191 |
static int sysvipc_msg_proc_show(struct seq_file *s, void *it) |
1da177e4c Linux-2.6.12-rc2 |
1192 |
{ |
39a4940ea ipc/msg: Fix msgc... |
1193 |
struct pid_namespace *pid_ns = ipc_seq_pid_ns(s); |
1efdb69b0 userns: Convert i... |
1194 |
struct user_namespace *user_ns = seq_user_ns(s); |
ade9f91b3 ipc: add missing ... |
1195 1196 |
struct kern_ipc_perm *ipcp = it; struct msg_queue *msq = container_of(ipcp, struct msg_queue, q_perm); |
19b4946ca [PATCH] ipc: conv... |
1197 |
|
7f032d6ef ipc: remove use o... |
1198 |
seq_printf(s, |
50578ea97 ipc: msg: Make ms... |
1199 1200 |
"%10d %10d %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %10llu %10llu %10llu ", |
7f032d6ef ipc: remove use o... |
1201 1202 1203 1204 1205 |
msq->q_perm.key, msq->q_perm.id, msq->q_perm.mode, msq->q_cbytes, msq->q_qnum, |
39a4940ea ipc/msg: Fix msgc... |
1206 1207 |
pid_nr_ns(msq->q_lspid, pid_ns), pid_nr_ns(msq->q_lrpid, pid_ns), |
7f032d6ef ipc: remove use o... |
1208 1209 1210 1211 1212 1213 1214 1215 1216 |
from_kuid_munged(user_ns, msq->q_perm.uid), from_kgid_munged(user_ns, msq->q_perm.gid), from_kuid_munged(user_ns, msq->q_perm.cuid), from_kgid_munged(user_ns, msq->q_perm.cgid), msq->q_stime, msq->q_rtime, msq->q_ctime); return 0; |
1da177e4c Linux-2.6.12-rc2 |
1217 1218 |
} #endif |
3440a6bd1 ipc,msg: move som... |
1219 |
|
eae04d25a ipc: simplify ipc... |
1220 |
void __init msg_init(void) |
3440a6bd1 ipc,msg: move som... |
1221 |
{ |
eae04d25a ipc: simplify ipc... |
1222 |
msg_init_ns(&init_ipc_ns); |
3440a6bd1 ipc,msg: move som... |
1223 |
|
3440a6bd1 ipc,msg: move som... |
1224 1225 1226 1227 1228 |
ipc_init_proc_interface("sysvipc/msg", " key msqid perms cbytes qnum lspid lrpid uid gid cuid cgid stime rtime ctime ", IPC_MSG_IDS, sysvipc_msg_proc_show); } |