mqueue.c 31 KB

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