mqueue.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308
  1. /*
  2. * POSIX message queues filesystem for Linux.
  3. *
  4. * Copyright (C) 2003,2004 Krzysztof Benedyczak (golbi@mat.uni.torun.pl)
  5. * Michal Wronski (michal.wronski@gmail.com)
  6. *
  7. * Spinlocks: Mohamed Abbas (abbas.mohamed@intel.com)
  8. * Lockless receive & send, fd based notify:
  9. * Manfred Spraul (manfred@colorfullife.com)
  10. *
  11. * Audit: George Wilson (ltcgcw@us.ibm.com)
  12. *
  13. * This file is released under the GPL.
  14. */
  15. #include <linux/capability.h>
  16. #include <linux/init.h>
  17. #include <linux/pagemap.h>
  18. #include <linux/file.h>
  19. #include <linux/mount.h>
  20. #include <linux/namei.h>
  21. #include <linux/sysctl.h>
  22. #include <linux/poll.h>
  23. #include <linux/mqueue.h>
  24. #include <linux/msg.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/netlink.h>
  27. #include <linux/syscalls.h>
  28. #include <linux/audit.h>
  29. #include <linux/signal.h>
  30. #include <linux/mutex.h>
  31. #include <linux/nsproxy.h>
  32. #include <linux/pid.h>
  33. #include <linux/ipc_namespace.h>
  34. #include <linux/user_namespace.h>
  35. #include <linux/slab.h>
  36. #include <net/sock.h>
  37. #include "util.h"
  38. #define MQUEUE_MAGIC 0x19800202
  39. #define DIRENT_SIZE 20
  40. #define FILENT_SIZE 80
  41. #define SEND 0
  42. #define RECV 1
  43. #define STATE_NONE 0
  44. #define STATE_PENDING 1
  45. #define STATE_READY 2
  46. struct ext_wait_queue { /* queue of sleeping tasks */
  47. struct task_struct *task;
  48. struct list_head list;
  49. struct msg_msg *msg; /* ptr of loaded message */
  50. int state; /* one of STATE_* values */
  51. };
  52. struct mqueue_inode_info {
  53. spinlock_t lock;
  54. struct inode vfs_inode;
  55. wait_queue_head_t wait_q;
  56. struct msg_msg **messages;
  57. struct mq_attr attr;
  58. struct sigevent notify;
  59. struct pid* notify_owner;
  60. struct user_namespace *notify_user_ns;
  61. struct user_struct *user; /* user who created, for accounting */
  62. struct sock *notify_sock;
  63. struct sk_buff *notify_cookie;
  64. /* for tasks waiting for free space and messages, respectively */
  65. struct ext_wait_queue e_wait_q[2];
  66. unsigned long qsize; /* size of queue in memory (sum of all msgs) */
  67. };
  68. static const struct inode_operations mqueue_dir_inode_operations;
  69. static const struct file_operations mqueue_file_operations;
  70. static const struct super_operations mqueue_super_ops;
  71. static void remove_notification(struct mqueue_inode_info *info);
  72. static struct kmem_cache *mqueue_inode_cachep;
  73. static struct ctl_table_header * mq_sysctl_table;
  74. static inline struct mqueue_inode_info *MQUEUE_I(struct inode *inode)
  75. {
  76. return container_of(inode, struct mqueue_inode_info, vfs_inode);
  77. }
  78. /*
  79. * This routine should be called with the mq_lock held.
  80. */
  81. static inline struct ipc_namespace *__get_ns_from_inode(struct inode *inode)
  82. {
  83. return get_ipc_ns(inode->i_sb->s_fs_info);
  84. }
  85. static struct ipc_namespace *get_ns_from_inode(struct inode *inode)
  86. {
  87. struct ipc_namespace *ns;
  88. spin_lock(&mq_lock);
  89. ns = __get_ns_from_inode(inode);
  90. spin_unlock(&mq_lock);
  91. return ns;
  92. }
  93. static struct inode *mqueue_get_inode(struct super_block *sb,
  94. struct ipc_namespace *ipc_ns, umode_t mode,
  95. struct mq_attr *attr)
  96. {
  97. struct user_struct *u = current_user();
  98. struct inode *inode;
  99. int ret = -ENOMEM;
  100. inode = new_inode(sb);
  101. if (!inode)
  102. goto err;
  103. inode->i_ino = get_next_ino();
  104. inode->i_mode = mode;
  105. inode->i_uid = current_fsuid();
  106. inode->i_gid = current_fsgid();
  107. inode->i_mtime = inode->i_ctime = inode->i_atime = CURRENT_TIME;
  108. if (S_ISREG(mode)) {
  109. struct mqueue_inode_info *info;
  110. unsigned long mq_bytes, mq_msg_tblsz;
  111. inode->i_fop = &mqueue_file_operations;
  112. inode->i_size = FILENT_SIZE;
  113. /* mqueue specific info */
  114. info = MQUEUE_I(inode);
  115. spin_lock_init(&info->lock);
  116. init_waitqueue_head(&info->wait_q);
  117. INIT_LIST_HEAD(&info->e_wait_q[0].list);
  118. INIT_LIST_HEAD(&info->e_wait_q[1].list);
  119. info->notify_owner = NULL;
  120. info->notify_user_ns = NULL;
  121. info->qsize = 0;
  122. info->user = NULL; /* set when all is ok */
  123. memset(&info->attr, 0, sizeof(info->attr));
  124. info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
  125. info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
  126. if (attr) {
  127. info->attr.mq_maxmsg = attr->mq_maxmsg;
  128. info->attr.mq_msgsize = attr->mq_msgsize;
  129. }
  130. mq_msg_tblsz = info->attr.mq_maxmsg * sizeof(struct msg_msg *);
  131. info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
  132. if (!info->messages)
  133. goto out_inode;
  134. mq_bytes = (mq_msg_tblsz +
  135. (info->attr.mq_maxmsg * info->attr.mq_msgsize));
  136. spin_lock(&mq_lock);
  137. if (u->mq_bytes + mq_bytes < u->mq_bytes ||
  138. u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
  139. spin_unlock(&mq_lock);
  140. /* mqueue_evict_inode() releases info->messages */
  141. ret = -EMFILE;
  142. goto out_inode;
  143. }
  144. u->mq_bytes += mq_bytes;
  145. spin_unlock(&mq_lock);
  146. /* all is ok */
  147. info->user = get_uid(u);
  148. } else if (S_ISDIR(mode)) {
  149. inc_nlink(inode);
  150. /* Some things misbehave if size == 0 on a directory */
  151. inode->i_size = 2 * DIRENT_SIZE;
  152. inode->i_op = &mqueue_dir_inode_operations;
  153. inode->i_fop = &simple_dir_operations;
  154. }
  155. return inode;
  156. out_inode:
  157. iput(inode);
  158. err:
  159. return ERR_PTR(ret);
  160. }
  161. static int mqueue_fill_super(struct super_block *sb, void *data, int silent)
  162. {
  163. struct inode *inode;
  164. struct ipc_namespace *ns = data;
  165. sb->s_blocksize = PAGE_CACHE_SIZE;
  166. sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
  167. sb->s_magic = MQUEUE_MAGIC;
  168. sb->s_op = &mqueue_super_ops;
  169. inode = mqueue_get_inode(sb, ns, S_IFDIR | S_ISVTX | S_IRWXUGO, NULL);
  170. if (IS_ERR(inode))
  171. return PTR_ERR(inode);
  172. sb->s_root = d_make_root(inode);
  173. if (!sb->s_root)
  174. return -ENOMEM;
  175. return 0;
  176. }
  177. static struct dentry *mqueue_mount(struct file_system_type *fs_type,
  178. int flags, const char *dev_name,
  179. void *data)
  180. {
  181. if (!(flags & MS_KERNMOUNT))
  182. data = current->nsproxy->ipc_ns;
  183. return mount_ns(fs_type, flags, data, mqueue_fill_super);
  184. }
  185. static void init_once(void *foo)
  186. {
  187. struct mqueue_inode_info *p = (struct mqueue_inode_info *) foo;
  188. inode_init_once(&p->vfs_inode);
  189. }
  190. static struct inode *mqueue_alloc_inode(struct super_block *sb)
  191. {
  192. struct mqueue_inode_info *ei;
  193. ei = kmem_cache_alloc(mqueue_inode_cachep, GFP_KERNEL);
  194. if (!ei)
  195. return NULL;
  196. return &ei->vfs_inode;
  197. }
  198. static void mqueue_i_callback(struct rcu_head *head)
  199. {
  200. struct inode *inode = container_of(head, struct inode, i_rcu);
  201. kmem_cache_free(mqueue_inode_cachep, MQUEUE_I(inode));
  202. }
  203. static void mqueue_destroy_inode(struct inode *inode)
  204. {
  205. call_rcu(&inode->i_rcu, mqueue_i_callback);
  206. }
  207. static void mqueue_evict_inode(struct inode *inode)
  208. {
  209. struct mqueue_inode_info *info;
  210. struct user_struct *user;
  211. unsigned long mq_bytes;
  212. int i;
  213. struct ipc_namespace *ipc_ns;
  214. clear_inode(inode);
  215. if (S_ISDIR(inode->i_mode))
  216. return;
  217. ipc_ns = get_ns_from_inode(inode);
  218. info = MQUEUE_I(inode);
  219. spin_lock(&info->lock);
  220. for (i = 0; i < info->attr.mq_curmsgs; i++)
  221. free_msg(info->messages[i]);
  222. kfree(info->messages);
  223. spin_unlock(&info->lock);
  224. /* Total amount of bytes accounted for the mqueue */
  225. mq_bytes = info->attr.mq_maxmsg * (sizeof(struct msg_msg *)
  226. + info->attr.mq_msgsize);
  227. user = info->user;
  228. if (user) {
  229. spin_lock(&mq_lock);
  230. user->mq_bytes -= mq_bytes;
  231. /*
  232. * get_ns_from_inode() ensures that the
  233. * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
  234. * to which we now hold a reference, or it is NULL.
  235. * We can't put it here under mq_lock, though.
  236. */
  237. if (ipc_ns)
  238. ipc_ns->mq_queues_count--;
  239. spin_unlock(&mq_lock);
  240. free_uid(user);
  241. }
  242. if (ipc_ns)
  243. put_ipc_ns(ipc_ns);
  244. }
  245. static int mqueue_create(struct inode *dir, struct dentry *dentry,
  246. umode_t mode, struct nameidata *nd)
  247. {
  248. struct inode *inode;
  249. struct mq_attr *attr = dentry->d_fsdata;
  250. int error;
  251. struct ipc_namespace *ipc_ns;
  252. spin_lock(&mq_lock);
  253. ipc_ns = __get_ns_from_inode(dir);
  254. if (!ipc_ns) {
  255. error = -EACCES;
  256. goto out_unlock;
  257. }
  258. if (ipc_ns->mq_queues_count >= ipc_ns->mq_queues_max &&
  259. !capable(CAP_SYS_RESOURCE)) {
  260. error = -ENOSPC;
  261. goto out_unlock;
  262. }
  263. ipc_ns->mq_queues_count++;
  264. spin_unlock(&mq_lock);
  265. inode = mqueue_get_inode(dir->i_sb, ipc_ns, mode, attr);
  266. if (IS_ERR(inode)) {
  267. error = PTR_ERR(inode);
  268. spin_lock(&mq_lock);
  269. ipc_ns->mq_queues_count--;
  270. goto out_unlock;
  271. }
  272. put_ipc_ns(ipc_ns);
  273. dir->i_size += DIRENT_SIZE;
  274. dir->i_ctime = dir->i_mtime = dir->i_atime = CURRENT_TIME;
  275. d_instantiate(dentry, inode);
  276. dget(dentry);
  277. return 0;
  278. out_unlock:
  279. spin_unlock(&mq_lock);
  280. if (ipc_ns)
  281. put_ipc_ns(ipc_ns);
  282. return error;
  283. }
  284. static int mqueue_unlink(struct inode *dir, struct dentry *dentry)
  285. {
  286. struct inode *inode = dentry->d_inode;
  287. dir->i_ctime = dir->i_mtime = dir->i_atime = CURRENT_TIME;
  288. dir->i_size -= DIRENT_SIZE;
  289. drop_nlink(inode);
  290. dput(dentry);
  291. return 0;
  292. }
  293. /*
  294. * This is routine for system read from queue file.
  295. * To avoid mess with doing here some sort of mq_receive we allow
  296. * to read only queue size & notification info (the only values
  297. * that are interesting from user point of view and aren't accessible
  298. * through std routines)
  299. */
  300. static ssize_t mqueue_read_file(struct file *filp, char __user *u_data,
  301. size_t count, loff_t *off)
  302. {
  303. struct mqueue_inode_info *info = MQUEUE_I(filp->f_path.dentry->d_inode);
  304. char buffer[FILENT_SIZE];
  305. ssize_t ret;
  306. spin_lock(&info->lock);
  307. snprintf(buffer, sizeof(buffer),
  308. "QSIZE:%-10lu NOTIFY:%-5d SIGNO:%-5d NOTIFY_PID:%-6d\n",
  309. info->qsize,
  310. info->notify_owner ? info->notify.sigev_notify : 0,
  311. (info->notify_owner &&
  312. info->notify.sigev_notify == SIGEV_SIGNAL) ?
  313. info->notify.sigev_signo : 0,
  314. pid_vnr(info->notify_owner));
  315. spin_unlock(&info->lock);
  316. buffer[sizeof(buffer)-1] = '\0';
  317. ret = simple_read_from_buffer(u_data, count, off, buffer,
  318. strlen(buffer));
  319. if (ret <= 0)
  320. return ret;
  321. filp->f_path.dentry->d_inode->i_atime = filp->f_path.dentry->d_inode->i_ctime = CURRENT_TIME;
  322. return ret;
  323. }
  324. static int mqueue_flush_file(struct file *filp, fl_owner_t id)
  325. {
  326. struct mqueue_inode_info *info = MQUEUE_I(filp->f_path.dentry->d_inode);
  327. spin_lock(&info->lock);
  328. if (task_tgid(current) == info->notify_owner)
  329. remove_notification(info);
  330. spin_unlock(&info->lock);
  331. return 0;
  332. }
  333. static unsigned int mqueue_poll_file(struct file *filp, struct poll_table_struct *poll_tab)
  334. {
  335. struct mqueue_inode_info *info = MQUEUE_I(filp->f_path.dentry->d_inode);
  336. int retval = 0;
  337. poll_wait(filp, &info->wait_q, poll_tab);
  338. spin_lock(&info->lock);
  339. if (info->attr.mq_curmsgs)
  340. retval = POLLIN | POLLRDNORM;
  341. if (info->attr.mq_curmsgs < info->attr.mq_maxmsg)
  342. retval |= POLLOUT | POLLWRNORM;
  343. spin_unlock(&info->lock);
  344. return retval;
  345. }
  346. /* Adds current to info->e_wait_q[sr] before element with smaller prio */
  347. static void wq_add(struct mqueue_inode_info *info, int sr,
  348. struct ext_wait_queue *ewp)
  349. {
  350. struct ext_wait_queue *walk;
  351. ewp->task = current;
  352. list_for_each_entry(walk, &info->e_wait_q[sr].list, list) {
  353. if (walk->task->static_prio <= current->static_prio) {
  354. list_add_tail(&ewp->list, &walk->list);
  355. return;
  356. }
  357. }
  358. list_add_tail(&ewp->list, &info->e_wait_q[sr].list);
  359. }
  360. /*
  361. * Puts current task to sleep. Caller must hold queue lock. After return
  362. * lock isn't held.
  363. * sr: SEND or RECV
  364. */
  365. static int wq_sleep(struct mqueue_inode_info *info, int sr,
  366. ktime_t *timeout, struct ext_wait_queue *ewp)
  367. {
  368. int retval;
  369. signed long time;
  370. wq_add(info, sr, ewp);
  371. for (;;) {
  372. set_current_state(TASK_INTERRUPTIBLE);
  373. spin_unlock(&info->lock);
  374. time = schedule_hrtimeout_range_clock(timeout, 0,
  375. HRTIMER_MODE_ABS, CLOCK_REALTIME);
  376. while (ewp->state == STATE_PENDING)
  377. cpu_relax();
  378. if (ewp->state == STATE_READY) {
  379. retval = 0;
  380. goto out;
  381. }
  382. spin_lock(&info->lock);
  383. if (ewp->state == STATE_READY) {
  384. retval = 0;
  385. goto out_unlock;
  386. }
  387. if (signal_pending(current)) {
  388. retval = -ERESTARTSYS;
  389. break;
  390. }
  391. if (time == 0) {
  392. retval = -ETIMEDOUT;
  393. break;
  394. }
  395. }
  396. list_del(&ewp->list);
  397. out_unlock:
  398. spin_unlock(&info->lock);
  399. out:
  400. return retval;
  401. }
  402. /*
  403. * Returns waiting task that should be serviced first or NULL if none exists
  404. */
  405. static struct ext_wait_queue *wq_get_first_waiter(
  406. struct mqueue_inode_info *info, int sr)
  407. {
  408. struct list_head *ptr;
  409. ptr = info->e_wait_q[sr].list.prev;
  410. if (ptr == &info->e_wait_q[sr].list)
  411. return NULL;
  412. return list_entry(ptr, struct ext_wait_queue, list);
  413. }
  414. /* Auxiliary functions to manipulate messages' list */
  415. static void msg_insert(struct msg_msg *ptr, struct mqueue_inode_info *info)
  416. {
  417. int k;
  418. k = info->attr.mq_curmsgs - 1;
  419. while (k >= 0 && info->messages[k]->m_type >= ptr->m_type) {
  420. info->messages[k + 1] = info->messages[k];
  421. k--;
  422. }
  423. info->attr.mq_curmsgs++;
  424. info->qsize += ptr->m_ts;
  425. info->messages[k + 1] = ptr;
  426. }
  427. static inline struct msg_msg *msg_get(struct mqueue_inode_info *info)
  428. {
  429. info->qsize -= info->messages[--info->attr.mq_curmsgs]->m_ts;
  430. return info->messages[info->attr.mq_curmsgs];
  431. }
  432. static inline void set_cookie(struct sk_buff *skb, char code)
  433. {
  434. ((char*)skb->data)[NOTIFY_COOKIE_LEN-1] = code;
  435. }
  436. /*
  437. * The next function is only to split too long sys_mq_timedsend
  438. */
  439. static void __do_notify(struct mqueue_inode_info *info)
  440. {
  441. /* notification
  442. * invoked when there is registered process and there isn't process
  443. * waiting synchronously for message AND state of queue changed from
  444. * empty to not empty. Here we are sure that no one is waiting
  445. * synchronously. */
  446. if (info->notify_owner &&
  447. info->attr.mq_curmsgs == 1) {
  448. struct siginfo sig_i;
  449. switch (info->notify.sigev_notify) {
  450. case SIGEV_NONE:
  451. break;
  452. case SIGEV_SIGNAL:
  453. /* sends signal */
  454. sig_i.si_signo = info->notify.sigev_signo;
  455. sig_i.si_errno = 0;
  456. sig_i.si_code = SI_MESGQ;
  457. sig_i.si_value = info->notify.sigev_value;
  458. /* map current pid/uid into info->owner's namespaces */
  459. rcu_read_lock();
  460. sig_i.si_pid = task_tgid_nr_ns(current,
  461. ns_of_pid(info->notify_owner));
  462. sig_i.si_uid = from_kuid_munged(info->notify_user_ns, current_uid());
  463. rcu_read_unlock();
  464. kill_pid_info(info->notify.sigev_signo,
  465. &sig_i, info->notify_owner);
  466. break;
  467. case SIGEV_THREAD:
  468. set_cookie(info->notify_cookie, NOTIFY_WOKENUP);
  469. netlink_sendskb(info->notify_sock, info->notify_cookie);
  470. break;
  471. }
  472. /* after notification unregisters process */
  473. put_pid(info->notify_owner);
  474. put_user_ns(info->notify_user_ns);
  475. info->notify_owner = NULL;
  476. info->notify_user_ns = NULL;
  477. }
  478. wake_up(&info->wait_q);
  479. }
  480. static int prepare_timeout(const struct timespec __user *u_abs_timeout,
  481. ktime_t *expires, struct timespec *ts)
  482. {
  483. if (copy_from_user(ts, u_abs_timeout, sizeof(struct timespec)))
  484. return -EFAULT;
  485. if (!timespec_valid(ts))
  486. return -EINVAL;
  487. *expires = timespec_to_ktime(*ts);
  488. return 0;
  489. }
  490. static void remove_notification(struct mqueue_inode_info *info)
  491. {
  492. if (info->notify_owner != NULL &&
  493. info->notify.sigev_notify == SIGEV_THREAD) {
  494. set_cookie(info->notify_cookie, NOTIFY_REMOVED);
  495. netlink_sendskb(info->notify_sock, info->notify_cookie);
  496. }
  497. put_pid(info->notify_owner);
  498. put_user_ns(info->notify_user_ns);
  499. info->notify_owner = NULL;
  500. info->notify_user_ns = NULL;
  501. }
  502. static int mq_attr_ok(struct ipc_namespace *ipc_ns, struct mq_attr *attr)
  503. {
  504. if (attr->mq_maxmsg <= 0 || attr->mq_msgsize <= 0)
  505. return 0;
  506. if (capable(CAP_SYS_RESOURCE)) {
  507. if (attr->mq_maxmsg > HARD_MSGMAX)
  508. return 0;
  509. } else {
  510. if (attr->mq_maxmsg > ipc_ns->mq_msg_max ||
  511. attr->mq_msgsize > ipc_ns->mq_msgsize_max)
  512. return 0;
  513. }
  514. /* check for overflow */
  515. if (attr->mq_msgsize > ULONG_MAX/attr->mq_maxmsg)
  516. return 0;
  517. if ((unsigned long)(attr->mq_maxmsg * (attr->mq_msgsize
  518. + sizeof (struct msg_msg *))) <
  519. (unsigned long)(attr->mq_maxmsg * attr->mq_msgsize))
  520. return 0;
  521. return 1;
  522. }
  523. /*
  524. * Invoked when creating a new queue via sys_mq_open
  525. */
  526. static struct file *do_create(struct ipc_namespace *ipc_ns, struct dentry *dir,
  527. struct dentry *dentry, int oflag, umode_t mode,
  528. struct mq_attr *attr)
  529. {
  530. const struct cred *cred = current_cred();
  531. struct file *result;
  532. int ret;
  533. if (attr) {
  534. if (!mq_attr_ok(ipc_ns, attr)) {
  535. ret = -EINVAL;
  536. goto out;
  537. }
  538. /* store for use during create */
  539. dentry->d_fsdata = attr;
  540. }
  541. mode &= ~current_umask();
  542. ret = mnt_want_write(ipc_ns->mq_mnt);
  543. if (ret)
  544. goto out;
  545. ret = vfs_create(dir->d_inode, dentry, mode, NULL);
  546. dentry->d_fsdata = NULL;
  547. if (ret)
  548. goto out_drop_write;
  549. result = dentry_open(dentry, ipc_ns->mq_mnt, oflag, cred);
  550. /*
  551. * dentry_open() took a persistent mnt_want_write(),
  552. * so we can now drop this one.
  553. */
  554. mnt_drop_write(ipc_ns->mq_mnt);
  555. return result;
  556. out_drop_write:
  557. mnt_drop_write(ipc_ns->mq_mnt);
  558. out:
  559. dput(dentry);
  560. mntput(ipc_ns->mq_mnt);
  561. return ERR_PTR(ret);
  562. }
  563. /* Opens existing queue */
  564. static struct file *do_open(struct ipc_namespace *ipc_ns,
  565. struct dentry *dentry, int oflag)
  566. {
  567. int ret;
  568. const struct cred *cred = current_cred();
  569. static const int oflag2acc[O_ACCMODE] = { MAY_READ, MAY_WRITE,
  570. MAY_READ | MAY_WRITE };
  571. if ((oflag & O_ACCMODE) == (O_RDWR | O_WRONLY)) {
  572. ret = -EINVAL;
  573. goto err;
  574. }
  575. if (inode_permission(dentry->d_inode, oflag2acc[oflag & O_ACCMODE])) {
  576. ret = -EACCES;
  577. goto err;
  578. }
  579. return dentry_open(dentry, ipc_ns->mq_mnt, oflag, cred);
  580. err:
  581. dput(dentry);
  582. mntput(ipc_ns->mq_mnt);
  583. return ERR_PTR(ret);
  584. }
  585. SYSCALL_DEFINE4(mq_open, const char __user *, u_name, int, oflag, umode_t, mode,
  586. struct mq_attr __user *, u_attr)
  587. {
  588. struct dentry *dentry;
  589. struct file *filp;
  590. char *name;
  591. struct mq_attr attr;
  592. int fd, error;
  593. struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
  594. if (u_attr && copy_from_user(&attr, u_attr, sizeof(struct mq_attr)))
  595. return -EFAULT;
  596. audit_mq_open(oflag, mode, u_attr ? &attr : NULL);
  597. if (IS_ERR(name = getname(u_name)))
  598. return PTR_ERR(name);
  599. fd = get_unused_fd_flags(O_CLOEXEC);
  600. if (fd < 0)
  601. goto out_putname;
  602. mutex_lock(&ipc_ns->mq_mnt->mnt_root->d_inode->i_mutex);
  603. dentry = lookup_one_len(name, ipc_ns->mq_mnt->mnt_root, strlen(name));
  604. if (IS_ERR(dentry)) {
  605. error = PTR_ERR(dentry);
  606. goto out_putfd;
  607. }
  608. mntget(ipc_ns->mq_mnt);
  609. if (oflag & O_CREAT) {
  610. if (dentry->d_inode) { /* entry already exists */
  611. audit_inode(name, dentry);
  612. if (oflag & O_EXCL) {
  613. error = -EEXIST;
  614. goto out;
  615. }
  616. filp = do_open(ipc_ns, dentry, oflag);
  617. } else {
  618. filp = do_create(ipc_ns, ipc_ns->mq_mnt->mnt_root,
  619. dentry, oflag, mode,
  620. u_attr ? &attr : NULL);
  621. }
  622. } else {
  623. if (!dentry->d_inode) {
  624. error = -ENOENT;
  625. goto out;
  626. }
  627. audit_inode(name, dentry);
  628. filp = do_open(ipc_ns, dentry, oflag);
  629. }
  630. if (IS_ERR(filp)) {
  631. error = PTR_ERR(filp);
  632. goto out_putfd;
  633. }
  634. fd_install(fd, filp);
  635. goto out_upsem;
  636. out:
  637. dput(dentry);
  638. mntput(ipc_ns->mq_mnt);
  639. out_putfd:
  640. put_unused_fd(fd);
  641. fd = error;
  642. out_upsem:
  643. mutex_unlock(&ipc_ns->mq_mnt->mnt_root->d_inode->i_mutex);
  644. out_putname:
  645. putname(name);
  646. return fd;
  647. }
  648. SYSCALL_DEFINE1(mq_unlink, const char __user *, u_name)
  649. {
  650. int err;
  651. char *name;
  652. struct dentry *dentry;
  653. struct inode *inode = NULL;
  654. struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
  655. name = getname(u_name);
  656. if (IS_ERR(name))
  657. return PTR_ERR(name);
  658. mutex_lock_nested(&ipc_ns->mq_mnt->mnt_root->d_inode->i_mutex,
  659. I_MUTEX_PARENT);
  660. dentry = lookup_one_len(name, ipc_ns->mq_mnt->mnt_root, strlen(name));
  661. if (IS_ERR(dentry)) {
  662. err = PTR_ERR(dentry);
  663. goto out_unlock;
  664. }
  665. if (!dentry->d_inode) {
  666. err = -ENOENT;
  667. goto out_err;
  668. }
  669. inode = dentry->d_inode;
  670. if (inode)
  671. ihold(inode);
  672. err = mnt_want_write(ipc_ns->mq_mnt);
  673. if (err)
  674. goto out_err;
  675. err = vfs_unlink(dentry->d_parent->d_inode, dentry);
  676. mnt_drop_write(ipc_ns->mq_mnt);
  677. out_err:
  678. dput(dentry);
  679. out_unlock:
  680. mutex_unlock(&ipc_ns->mq_mnt->mnt_root->d_inode->i_mutex);
  681. putname(name);
  682. if (inode)
  683. iput(inode);
  684. return err;
  685. }
  686. /* Pipelined send and receive functions.
  687. *
  688. * If a receiver finds no waiting message, then it registers itself in the
  689. * list of waiting receivers. A sender checks that list before adding the new
  690. * message into the message array. If there is a waiting receiver, then it
  691. * bypasses the message array and directly hands the message over to the
  692. * receiver.
  693. * The receiver accepts the message and returns without grabbing the queue
  694. * spinlock. Therefore an intermediate STATE_PENDING state and memory barriers
  695. * are necessary. The same algorithm is used for sysv semaphores, see
  696. * ipc/sem.c for more details.
  697. *
  698. * The same algorithm is used for senders.
  699. */
  700. /* pipelined_send() - send a message directly to the task waiting in
  701. * sys_mq_timedreceive() (without inserting message into a queue).
  702. */
  703. static inline void pipelined_send(struct mqueue_inode_info *info,
  704. struct msg_msg *message,
  705. struct ext_wait_queue *receiver)
  706. {
  707. receiver->msg = message;
  708. list_del(&receiver->list);
  709. receiver->state = STATE_PENDING;
  710. wake_up_process(receiver->task);
  711. smp_wmb();
  712. receiver->state = STATE_READY;
  713. }
  714. /* pipelined_receive() - if there is task waiting in sys_mq_timedsend()
  715. * gets its message and put to the queue (we have one free place for sure). */
  716. static inline void pipelined_receive(struct mqueue_inode_info *info)
  717. {
  718. struct ext_wait_queue *sender = wq_get_first_waiter(info, SEND);
  719. if (!sender) {
  720. /* for poll */
  721. wake_up_interruptible(&info->wait_q);
  722. return;
  723. }
  724. msg_insert(sender->msg, info);
  725. list_del(&sender->list);
  726. sender->state = STATE_PENDING;
  727. wake_up_process(sender->task);
  728. smp_wmb();
  729. sender->state = STATE_READY;
  730. }
  731. SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char __user *, u_msg_ptr,
  732. size_t, msg_len, unsigned int, msg_prio,
  733. const struct timespec __user *, u_abs_timeout)
  734. {
  735. struct file *filp;
  736. struct inode *inode;
  737. struct ext_wait_queue wait;
  738. struct ext_wait_queue *receiver;
  739. struct msg_msg *msg_ptr;
  740. struct mqueue_inode_info *info;
  741. ktime_t expires, *timeout = NULL;
  742. struct timespec ts;
  743. int ret;
  744. if (u_abs_timeout) {
  745. int res = prepare_timeout(u_abs_timeout, &expires, &ts);
  746. if (res)
  747. return res;
  748. timeout = &expires;
  749. }
  750. if (unlikely(msg_prio >= (unsigned long) MQ_PRIO_MAX))
  751. return -EINVAL;
  752. audit_mq_sendrecv(mqdes, msg_len, msg_prio, timeout ? &ts : NULL);
  753. filp = fget(mqdes);
  754. if (unlikely(!filp)) {
  755. ret = -EBADF;
  756. goto out;
  757. }
  758. inode = filp->f_path.dentry->d_inode;
  759. if (unlikely(filp->f_op != &mqueue_file_operations)) {
  760. ret = -EBADF;
  761. goto out_fput;
  762. }
  763. info = MQUEUE_I(inode);
  764. audit_inode(NULL, filp->f_path.dentry);
  765. if (unlikely(!(filp->f_mode & FMODE_WRITE))) {
  766. ret = -EBADF;
  767. goto out_fput;
  768. }
  769. if (unlikely(msg_len > info->attr.mq_msgsize)) {
  770. ret = -EMSGSIZE;
  771. goto out_fput;
  772. }
  773. /* First try to allocate memory, before doing anything with
  774. * existing queues. */
  775. msg_ptr = load_msg(u_msg_ptr, msg_len);
  776. if (IS_ERR(msg_ptr)) {
  777. ret = PTR_ERR(msg_ptr);
  778. goto out_fput;
  779. }
  780. msg_ptr->m_ts = msg_len;
  781. msg_ptr->m_type = msg_prio;
  782. spin_lock(&info->lock);
  783. if (info->attr.mq_curmsgs == info->attr.mq_maxmsg) {
  784. if (filp->f_flags & O_NONBLOCK) {
  785. spin_unlock(&info->lock);
  786. ret = -EAGAIN;
  787. } else {
  788. wait.task = current;
  789. wait.msg = (void *) msg_ptr;
  790. wait.state = STATE_NONE;
  791. ret = wq_sleep(info, SEND, timeout, &wait);
  792. }
  793. if (ret < 0)
  794. free_msg(msg_ptr);
  795. } else {
  796. receiver = wq_get_first_waiter(info, RECV);
  797. if (receiver) {
  798. pipelined_send(info, msg_ptr, receiver);
  799. } else {
  800. /* adds message to the queue */
  801. msg_insert(msg_ptr, info);
  802. __do_notify(info);
  803. }
  804. inode->i_atime = inode->i_mtime = inode->i_ctime =
  805. CURRENT_TIME;
  806. spin_unlock(&info->lock);
  807. ret = 0;
  808. }
  809. out_fput:
  810. fput(filp);
  811. out:
  812. return ret;
  813. }
  814. SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes, char __user *, u_msg_ptr,
  815. size_t, msg_len, unsigned int __user *, u_msg_prio,
  816. const struct timespec __user *, u_abs_timeout)
  817. {
  818. ssize_t ret;
  819. struct msg_msg *msg_ptr;
  820. struct file *filp;
  821. struct inode *inode;
  822. struct mqueue_inode_info *info;
  823. struct ext_wait_queue wait;
  824. ktime_t expires, *timeout = NULL;
  825. struct timespec ts;
  826. if (u_abs_timeout) {
  827. int res = prepare_timeout(u_abs_timeout, &expires, &ts);
  828. if (res)
  829. return res;
  830. timeout = &expires;
  831. }
  832. audit_mq_sendrecv(mqdes, msg_len, 0, timeout ? &ts : NULL);
  833. filp = fget(mqdes);
  834. if (unlikely(!filp)) {
  835. ret = -EBADF;
  836. goto out;
  837. }
  838. inode = filp->f_path.dentry->d_inode;
  839. if (unlikely(filp->f_op != &mqueue_file_operations)) {
  840. ret = -EBADF;
  841. goto out_fput;
  842. }
  843. info = MQUEUE_I(inode);
  844. audit_inode(NULL, filp->f_path.dentry);
  845. if (unlikely(!(filp->f_mode & FMODE_READ))) {
  846. ret = -EBADF;
  847. goto out_fput;
  848. }
  849. /* checks if buffer is big enough */
  850. if (unlikely(msg_len < info->attr.mq_msgsize)) {
  851. ret = -EMSGSIZE;
  852. goto out_fput;
  853. }
  854. spin_lock(&info->lock);
  855. if (info->attr.mq_curmsgs == 0) {
  856. if (filp->f_flags & O_NONBLOCK) {
  857. spin_unlock(&info->lock);
  858. ret = -EAGAIN;
  859. } else {
  860. wait.task = current;
  861. wait.state = STATE_NONE;
  862. ret = wq_sleep(info, RECV, timeout, &wait);
  863. msg_ptr = wait.msg;
  864. }
  865. } else {
  866. msg_ptr = msg_get(info);
  867. inode->i_atime = inode->i_mtime = inode->i_ctime =
  868. CURRENT_TIME;
  869. /* There is now free space in queue. */
  870. pipelined_receive(info);
  871. spin_unlock(&info->lock);
  872. ret = 0;
  873. }
  874. if (ret == 0) {
  875. ret = msg_ptr->m_ts;
  876. if ((u_msg_prio && put_user(msg_ptr->m_type, u_msg_prio)) ||
  877. store_msg(u_msg_ptr, msg_ptr, msg_ptr->m_ts)) {
  878. ret = -EFAULT;
  879. }
  880. free_msg(msg_ptr);
  881. }
  882. out_fput:
  883. fput(filp);
  884. out:
  885. return ret;
  886. }
  887. /*
  888. * Notes: the case when user wants us to deregister (with NULL as pointer)
  889. * and he isn't currently owner of notification, will be silently discarded.
  890. * It isn't explicitly defined in the POSIX.
  891. */
  892. SYSCALL_DEFINE2(mq_notify, mqd_t, mqdes,
  893. const struct sigevent __user *, u_notification)
  894. {
  895. int ret;
  896. struct file *filp;
  897. struct sock *sock;
  898. struct inode *inode;
  899. struct sigevent notification;
  900. struct mqueue_inode_info *info;
  901. struct sk_buff *nc;
  902. if (u_notification) {
  903. if (copy_from_user(&notification, u_notification,
  904. sizeof(struct sigevent)))
  905. return -EFAULT;
  906. }
  907. audit_mq_notify(mqdes, u_notification ? &notification : NULL);
  908. nc = NULL;
  909. sock = NULL;
  910. if (u_notification != NULL) {
  911. if (unlikely(notification.sigev_notify != SIGEV_NONE &&
  912. notification.sigev_notify != SIGEV_SIGNAL &&
  913. notification.sigev_notify != SIGEV_THREAD))
  914. return -EINVAL;
  915. if (notification.sigev_notify == SIGEV_SIGNAL &&
  916. !valid_signal(notification.sigev_signo)) {
  917. return -EINVAL;
  918. }
  919. if (notification.sigev_notify == SIGEV_THREAD) {
  920. long timeo;
  921. /* create the notify skb */
  922. nc = alloc_skb(NOTIFY_COOKIE_LEN, GFP_KERNEL);
  923. if (!nc) {
  924. ret = -ENOMEM;
  925. goto out;
  926. }
  927. if (copy_from_user(nc->data,
  928. notification.sigev_value.sival_ptr,
  929. NOTIFY_COOKIE_LEN)) {
  930. ret = -EFAULT;
  931. goto out;
  932. }
  933. /* TODO: add a header? */
  934. skb_put(nc, NOTIFY_COOKIE_LEN);
  935. /* and attach it to the socket */
  936. retry:
  937. filp = fget(notification.sigev_signo);
  938. if (!filp) {
  939. ret = -EBADF;
  940. goto out;
  941. }
  942. sock = netlink_getsockbyfilp(filp);
  943. fput(filp);
  944. if (IS_ERR(sock)) {
  945. ret = PTR_ERR(sock);
  946. sock = NULL;
  947. goto out;
  948. }
  949. timeo = MAX_SCHEDULE_TIMEOUT;
  950. ret = netlink_attachskb(sock, nc, &timeo, NULL);
  951. if (ret == 1)
  952. goto retry;
  953. if (ret) {
  954. sock = NULL;
  955. nc = NULL;
  956. goto out;
  957. }
  958. }
  959. }
  960. filp = fget(mqdes);
  961. if (!filp) {
  962. ret = -EBADF;
  963. goto out;
  964. }
  965. inode = filp->f_path.dentry->d_inode;
  966. if (unlikely(filp->f_op != &mqueue_file_operations)) {
  967. ret = -EBADF;
  968. goto out_fput;
  969. }
  970. info = MQUEUE_I(inode);
  971. ret = 0;
  972. spin_lock(&info->lock);
  973. if (u_notification == NULL) {
  974. if (info->notify_owner == task_tgid(current)) {
  975. remove_notification(info);
  976. inode->i_atime = inode->i_ctime = CURRENT_TIME;
  977. }
  978. } else if (info->notify_owner != NULL) {
  979. ret = -EBUSY;
  980. } else {
  981. switch (notification.sigev_notify) {
  982. case SIGEV_NONE:
  983. info->notify.sigev_notify = SIGEV_NONE;
  984. break;
  985. case SIGEV_THREAD:
  986. info->notify_sock = sock;
  987. info->notify_cookie = nc;
  988. sock = NULL;
  989. nc = NULL;
  990. info->notify.sigev_notify = SIGEV_THREAD;
  991. break;
  992. case SIGEV_SIGNAL:
  993. info->notify.sigev_signo = notification.sigev_signo;
  994. info->notify.sigev_value = notification.sigev_value;
  995. info->notify.sigev_notify = SIGEV_SIGNAL;
  996. break;
  997. }
  998. info->notify_owner = get_pid(task_tgid(current));
  999. info->notify_user_ns = get_user_ns(current_user_ns());
  1000. inode->i_atime = inode->i_ctime = CURRENT_TIME;
  1001. }
  1002. spin_unlock(&info->lock);
  1003. out_fput:
  1004. fput(filp);
  1005. out:
  1006. if (sock) {
  1007. netlink_detachskb(sock, nc);
  1008. } else if (nc) {
  1009. dev_kfree_skb(nc);
  1010. }
  1011. return ret;
  1012. }
  1013. SYSCALL_DEFINE3(mq_getsetattr, mqd_t, mqdes,
  1014. const struct mq_attr __user *, u_mqstat,
  1015. struct mq_attr __user *, u_omqstat)
  1016. {
  1017. int ret;
  1018. struct mq_attr mqstat, omqstat;
  1019. struct file *filp;
  1020. struct inode *inode;
  1021. struct mqueue_inode_info *info;
  1022. if (u_mqstat != NULL) {
  1023. if (copy_from_user(&mqstat, u_mqstat, sizeof(struct mq_attr)))
  1024. return -EFAULT;
  1025. if (mqstat.mq_flags & (~O_NONBLOCK))
  1026. return -EINVAL;
  1027. }
  1028. filp = fget(mqdes);
  1029. if (!filp) {
  1030. ret = -EBADF;
  1031. goto out;
  1032. }
  1033. inode = filp->f_path.dentry->d_inode;
  1034. if (unlikely(filp->f_op != &mqueue_file_operations)) {
  1035. ret = -EBADF;
  1036. goto out_fput;
  1037. }
  1038. info = MQUEUE_I(inode);
  1039. spin_lock(&info->lock);
  1040. omqstat = info->attr;
  1041. omqstat.mq_flags = filp->f_flags & O_NONBLOCK;
  1042. if (u_mqstat) {
  1043. audit_mq_getsetattr(mqdes, &mqstat);
  1044. spin_lock(&filp->f_lock);
  1045. if (mqstat.mq_flags & O_NONBLOCK)
  1046. filp->f_flags |= O_NONBLOCK;
  1047. else
  1048. filp->f_flags &= ~O_NONBLOCK;
  1049. spin_unlock(&filp->f_lock);
  1050. inode->i_atime = inode->i_ctime = CURRENT_TIME;
  1051. }
  1052. spin_unlock(&info->lock);
  1053. ret = 0;
  1054. if (u_omqstat != NULL && copy_to_user(u_omqstat, &omqstat,
  1055. sizeof(struct mq_attr)))
  1056. ret = -EFAULT;
  1057. out_fput:
  1058. fput(filp);
  1059. out:
  1060. return ret;
  1061. }
  1062. static const struct inode_operations mqueue_dir_inode_operations = {
  1063. .lookup = simple_lookup,
  1064. .create = mqueue_create,
  1065. .unlink = mqueue_unlink,
  1066. };
  1067. static const struct file_operations mqueue_file_operations = {
  1068. .flush = mqueue_flush_file,
  1069. .poll = mqueue_poll_file,
  1070. .read = mqueue_read_file,
  1071. .llseek = default_llseek,
  1072. };
  1073. static const struct super_operations mqueue_super_ops = {
  1074. .alloc_inode = mqueue_alloc_inode,
  1075. .destroy_inode = mqueue_destroy_inode,
  1076. .evict_inode = mqueue_evict_inode,
  1077. .statfs = simple_statfs,
  1078. };
  1079. static struct file_system_type mqueue_fs_type = {
  1080. .name = "mqueue",
  1081. .mount = mqueue_mount,
  1082. .kill_sb = kill_litter_super,
  1083. };
  1084. int mq_init_ns(struct ipc_namespace *ns)
  1085. {
  1086. ns->mq_queues_count = 0;
  1087. ns->mq_queues_max = DFLT_QUEUESMAX;
  1088. ns->mq_msg_max = DFLT_MSGMAX;
  1089. ns->mq_msgsize_max = DFLT_MSGSIZEMAX;
  1090. ns->mq_mnt = kern_mount_data(&mqueue_fs_type, ns);
  1091. if (IS_ERR(ns->mq_mnt)) {
  1092. int err = PTR_ERR(ns->mq_mnt);
  1093. ns->mq_mnt = NULL;
  1094. return err;
  1095. }
  1096. return 0;
  1097. }
  1098. void mq_clear_sbinfo(struct ipc_namespace *ns)
  1099. {
  1100. ns->mq_mnt->mnt_sb->s_fs_info = NULL;
  1101. }
  1102. void mq_put_mnt(struct ipc_namespace *ns)
  1103. {
  1104. kern_unmount(ns->mq_mnt);
  1105. }
  1106. static int __init init_mqueue_fs(void)
  1107. {
  1108. int error;
  1109. mqueue_inode_cachep = kmem_cache_create("mqueue_inode_cache",
  1110. sizeof(struct mqueue_inode_info), 0,
  1111. SLAB_HWCACHE_ALIGN, init_once);
  1112. if (mqueue_inode_cachep == NULL)
  1113. return -ENOMEM;
  1114. /* ignore failures - they are not fatal */
  1115. mq_sysctl_table = mq_register_sysctl_table();
  1116. error = register_filesystem(&mqueue_fs_type);
  1117. if (error)
  1118. goto out_sysctl;
  1119. spin_lock_init(&mq_lock);
  1120. error = mq_init_ns(&init_ipc_ns);
  1121. if (error)
  1122. goto out_filesystem;
  1123. return 0;
  1124. out_filesystem:
  1125. unregister_filesystem(&mqueue_fs_type);
  1126. out_sysctl:
  1127. if (mq_sysctl_table)
  1128. unregister_sysctl_table(mq_sysctl_table);
  1129. kmem_cache_destroy(mqueue_inode_cachep);
  1130. return error;
  1131. }
  1132. __initcall(init_mqueue_fs);