mqueue.c 31 KB

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