mqueue.c 30 KB

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