fcntl.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. /*
  2. * linux/fs/fcntl.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. */
  6. #include <linux/syscalls.h>
  7. #include <linux/init.h>
  8. #include <linux/mm.h>
  9. #include <linux/fs.h>
  10. #include <linux/file.h>
  11. #include <linux/fdtable.h>
  12. #include <linux/capability.h>
  13. #include <linux/dnotify.h>
  14. #include <linux/slab.h>
  15. #include <linux/module.h>
  16. #include <linux/pipe_fs_i.h>
  17. #include <linux/security.h>
  18. #include <linux/ptrace.h>
  19. #include <linux/signal.h>
  20. #include <linux/rcupdate.h>
  21. #include <linux/pid_namespace.h>
  22. #include <linux/user_namespace.h>
  23. #include <asm/poll.h>
  24. #include <asm/siginfo.h>
  25. #include <asm/uaccess.h>
  26. #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
  27. static int setfl(int fd, struct file * filp, unsigned long arg)
  28. {
  29. struct inode * inode = file_inode(filp);
  30. int error = 0;
  31. /*
  32. * O_APPEND cannot be cleared if the file is marked as append-only
  33. * and the file is open for write.
  34. */
  35. if (((arg ^ filp->f_flags) & O_APPEND) && IS_APPEND(inode))
  36. return -EPERM;
  37. /* O_NOATIME can only be set by the owner or superuser */
  38. if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME))
  39. if (!inode_owner_or_capable(inode))
  40. return -EPERM;
  41. /* required for strict SunOS emulation */
  42. if (O_NONBLOCK != O_NDELAY)
  43. if (arg & O_NDELAY)
  44. arg |= O_NONBLOCK;
  45. if (arg & O_DIRECT) {
  46. if (!filp->f_mapping || !filp->f_mapping->a_ops ||
  47. !filp->f_mapping->a_ops->direct_IO)
  48. return -EINVAL;
  49. }
  50. if (filp->f_op && filp->f_op->check_flags)
  51. error = filp->f_op->check_flags(arg);
  52. if (error)
  53. return error;
  54. /*
  55. * ->fasync() is responsible for setting the FASYNC bit.
  56. */
  57. if (((arg ^ filp->f_flags) & FASYNC) && filp->f_op &&
  58. filp->f_op->fasync) {
  59. error = filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0);
  60. if (error < 0)
  61. goto out;
  62. if (error > 0)
  63. error = 0;
  64. }
  65. spin_lock(&filp->f_lock);
  66. filp->f_flags = (arg & SETFL_MASK) | (filp->f_flags & ~SETFL_MASK);
  67. spin_unlock(&filp->f_lock);
  68. out:
  69. return error;
  70. }
  71. static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
  72. int force)
  73. {
  74. write_lock_irq(&filp->f_owner.lock);
  75. if (force || !filp->f_owner.pid) {
  76. put_pid(filp->f_owner.pid);
  77. filp->f_owner.pid = get_pid(pid);
  78. filp->f_owner.pid_type = type;
  79. if (pid) {
  80. const struct cred *cred = current_cred();
  81. filp->f_owner.uid = cred->uid;
  82. filp->f_owner.euid = cred->euid;
  83. }
  84. }
  85. write_unlock_irq(&filp->f_owner.lock);
  86. }
  87. int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
  88. int force)
  89. {
  90. int err;
  91. err = security_file_set_fowner(filp);
  92. if (err)
  93. return err;
  94. f_modown(filp, pid, type, force);
  95. return 0;
  96. }
  97. EXPORT_SYMBOL(__f_setown);
  98. int f_setown(struct file *filp, unsigned long arg, int force)
  99. {
  100. enum pid_type type;
  101. struct pid *pid;
  102. int who = arg;
  103. int result;
  104. type = PIDTYPE_PID;
  105. if (who < 0) {
  106. type = PIDTYPE_PGID;
  107. who = -who;
  108. }
  109. rcu_read_lock();
  110. pid = find_vpid(who);
  111. result = __f_setown(filp, pid, type, force);
  112. rcu_read_unlock();
  113. return result;
  114. }
  115. EXPORT_SYMBOL(f_setown);
  116. void f_delown(struct file *filp)
  117. {
  118. f_modown(filp, NULL, PIDTYPE_PID, 1);
  119. }
  120. pid_t f_getown(struct file *filp)
  121. {
  122. pid_t pid;
  123. read_lock(&filp->f_owner.lock);
  124. pid = pid_vnr(filp->f_owner.pid);
  125. if (filp->f_owner.pid_type == PIDTYPE_PGID)
  126. pid = -pid;
  127. read_unlock(&filp->f_owner.lock);
  128. return pid;
  129. }
  130. static int f_setown_ex(struct file *filp, unsigned long arg)
  131. {
  132. struct f_owner_ex __user *owner_p = (void __user *)arg;
  133. struct f_owner_ex owner;
  134. struct pid *pid;
  135. int type;
  136. int ret;
  137. ret = copy_from_user(&owner, owner_p, sizeof(owner));
  138. if (ret)
  139. return -EFAULT;
  140. switch (owner.type) {
  141. case F_OWNER_TID:
  142. type = PIDTYPE_MAX;
  143. break;
  144. case F_OWNER_PID:
  145. type = PIDTYPE_PID;
  146. break;
  147. case F_OWNER_PGRP:
  148. type = PIDTYPE_PGID;
  149. break;
  150. default:
  151. return -EINVAL;
  152. }
  153. rcu_read_lock();
  154. pid = find_vpid(owner.pid);
  155. if (owner.pid && !pid)
  156. ret = -ESRCH;
  157. else
  158. ret = __f_setown(filp, pid, type, 1);
  159. rcu_read_unlock();
  160. return ret;
  161. }
  162. static int f_getown_ex(struct file *filp, unsigned long arg)
  163. {
  164. struct f_owner_ex __user *owner_p = (void __user *)arg;
  165. struct f_owner_ex owner;
  166. int ret = 0;
  167. read_lock(&filp->f_owner.lock);
  168. owner.pid = pid_vnr(filp->f_owner.pid);
  169. switch (filp->f_owner.pid_type) {
  170. case PIDTYPE_MAX:
  171. owner.type = F_OWNER_TID;
  172. break;
  173. case PIDTYPE_PID:
  174. owner.type = F_OWNER_PID;
  175. break;
  176. case PIDTYPE_PGID:
  177. owner.type = F_OWNER_PGRP;
  178. break;
  179. default:
  180. WARN_ON(1);
  181. ret = -EINVAL;
  182. break;
  183. }
  184. read_unlock(&filp->f_owner.lock);
  185. if (!ret) {
  186. ret = copy_to_user(owner_p, &owner, sizeof(owner));
  187. if (ret)
  188. ret = -EFAULT;
  189. }
  190. return ret;
  191. }
  192. #ifdef CONFIG_CHECKPOINT_RESTORE
  193. static int f_getowner_uids(struct file *filp, unsigned long arg)
  194. {
  195. struct user_namespace *user_ns = current_user_ns();
  196. uid_t __user *dst = (void __user *)arg;
  197. uid_t src[2];
  198. int err;
  199. read_lock(&filp->f_owner.lock);
  200. src[0] = from_kuid(user_ns, filp->f_owner.uid);
  201. src[1] = from_kuid(user_ns, filp->f_owner.euid);
  202. read_unlock(&filp->f_owner.lock);
  203. err = put_user(src[0], &dst[0]);
  204. err |= put_user(src[1], &dst[1]);
  205. return err;
  206. }
  207. #else
  208. static int f_getowner_uids(struct file *filp, unsigned long arg)
  209. {
  210. return -EINVAL;
  211. }
  212. #endif
  213. static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
  214. struct file *filp)
  215. {
  216. long err = -EINVAL;
  217. switch (cmd) {
  218. case F_DUPFD:
  219. err = f_dupfd(arg, filp, 0);
  220. break;
  221. case F_DUPFD_CLOEXEC:
  222. err = f_dupfd(arg, filp, O_CLOEXEC);
  223. break;
  224. case F_GETFD:
  225. err = get_close_on_exec(fd) ? FD_CLOEXEC : 0;
  226. break;
  227. case F_SETFD:
  228. err = 0;
  229. set_close_on_exec(fd, arg & FD_CLOEXEC);
  230. break;
  231. case F_GETFL:
  232. err = filp->f_flags;
  233. break;
  234. case F_SETFL:
  235. err = setfl(fd, filp, arg);
  236. break;
  237. case F_GETLK:
  238. err = fcntl_getlk(filp, (struct flock __user *) arg);
  239. break;
  240. case F_SETLK:
  241. case F_SETLKW:
  242. err = fcntl_setlk(fd, filp, cmd, (struct flock __user *) arg);
  243. break;
  244. case F_GETOWN:
  245. /*
  246. * XXX If f_owner is a process group, the
  247. * negative return value will get converted
  248. * into an error. Oops. If we keep the
  249. * current syscall conventions, the only way
  250. * to fix this will be in libc.
  251. */
  252. err = f_getown(filp);
  253. force_successful_syscall_return();
  254. break;
  255. case F_SETOWN:
  256. err = f_setown(filp, arg, 1);
  257. break;
  258. case F_GETOWN_EX:
  259. err = f_getown_ex(filp, arg);
  260. break;
  261. case F_SETOWN_EX:
  262. err = f_setown_ex(filp, arg);
  263. break;
  264. case F_GETOWNER_UIDS:
  265. err = f_getowner_uids(filp, arg);
  266. break;
  267. case F_GETSIG:
  268. err = filp->f_owner.signum;
  269. break;
  270. case F_SETSIG:
  271. /* arg == 0 restores default behaviour. */
  272. if (!valid_signal(arg)) {
  273. break;
  274. }
  275. err = 0;
  276. filp->f_owner.signum = arg;
  277. break;
  278. case F_GETLEASE:
  279. err = fcntl_getlease(filp);
  280. break;
  281. case F_SETLEASE:
  282. err = fcntl_setlease(fd, filp, arg);
  283. break;
  284. case F_NOTIFY:
  285. err = fcntl_dirnotify(fd, filp, arg);
  286. break;
  287. case F_SETPIPE_SZ:
  288. case F_GETPIPE_SZ:
  289. err = pipe_fcntl(filp, cmd, arg);
  290. break;
  291. default:
  292. break;
  293. }
  294. return err;
  295. }
  296. static int check_fcntl_cmd(unsigned cmd)
  297. {
  298. switch (cmd) {
  299. case F_DUPFD:
  300. case F_DUPFD_CLOEXEC:
  301. case F_GETFD:
  302. case F_SETFD:
  303. case F_GETFL:
  304. return 1;
  305. }
  306. return 0;
  307. }
  308. SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
  309. {
  310. struct fd f = fdget_raw(fd);
  311. long err = -EBADF;
  312. if (!f.file)
  313. goto out;
  314. if (unlikely(f.file->f_mode & FMODE_PATH)) {
  315. if (!check_fcntl_cmd(cmd))
  316. goto out1;
  317. }
  318. err = security_file_fcntl(f.file, cmd, arg);
  319. if (!err)
  320. err = do_fcntl(fd, cmd, arg, f.file);
  321. out1:
  322. fdput(f);
  323. out:
  324. return err;
  325. }
  326. #if BITS_PER_LONG == 32
  327. SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
  328. unsigned long, arg)
  329. {
  330. struct fd f = fdget_raw(fd);
  331. long err = -EBADF;
  332. if (!f.file)
  333. goto out;
  334. if (unlikely(f.file->f_mode & FMODE_PATH)) {
  335. if (!check_fcntl_cmd(cmd))
  336. goto out1;
  337. }
  338. err = security_file_fcntl(f.file, cmd, arg);
  339. if (err)
  340. goto out1;
  341. switch (cmd) {
  342. case F_GETLK64:
  343. err = fcntl_getlk64(f.file, (struct flock64 __user *) arg);
  344. break;
  345. case F_SETLK64:
  346. case F_SETLKW64:
  347. err = fcntl_setlk64(fd, f.file, cmd,
  348. (struct flock64 __user *) arg);
  349. break;
  350. default:
  351. err = do_fcntl(fd, cmd, arg, f.file);
  352. break;
  353. }
  354. out1:
  355. fdput(f);
  356. out:
  357. return err;
  358. }
  359. #endif
  360. /* Table to convert sigio signal codes into poll band bitmaps */
  361. static const long band_table[NSIGPOLL] = {
  362. POLLIN | POLLRDNORM, /* POLL_IN */
  363. POLLOUT | POLLWRNORM | POLLWRBAND, /* POLL_OUT */
  364. POLLIN | POLLRDNORM | POLLMSG, /* POLL_MSG */
  365. POLLERR, /* POLL_ERR */
  366. POLLPRI | POLLRDBAND, /* POLL_PRI */
  367. POLLHUP | POLLERR /* POLL_HUP */
  368. };
  369. static inline int sigio_perm(struct task_struct *p,
  370. struct fown_struct *fown, int sig)
  371. {
  372. const struct cred *cred;
  373. int ret;
  374. rcu_read_lock();
  375. cred = __task_cred(p);
  376. ret = ((uid_eq(fown->euid, GLOBAL_ROOT_UID) ||
  377. uid_eq(fown->euid, cred->suid) || uid_eq(fown->euid, cred->uid) ||
  378. uid_eq(fown->uid, cred->suid) || uid_eq(fown->uid, cred->uid)) &&
  379. !security_file_send_sigiotask(p, fown, sig));
  380. rcu_read_unlock();
  381. return ret;
  382. }
  383. static void send_sigio_to_task(struct task_struct *p,
  384. struct fown_struct *fown,
  385. int fd, int reason, int group)
  386. {
  387. /*
  388. * F_SETSIG can change ->signum lockless in parallel, make
  389. * sure we read it once and use the same value throughout.
  390. */
  391. int signum = ACCESS_ONCE(fown->signum);
  392. if (!sigio_perm(p, fown, signum))
  393. return;
  394. switch (signum) {
  395. siginfo_t si;
  396. default:
  397. /* Queue a rt signal with the appropriate fd as its
  398. value. We use SI_SIGIO as the source, not
  399. SI_KERNEL, since kernel signals always get
  400. delivered even if we can't queue. Failure to
  401. queue in this case _should_ be reported; we fall
  402. back to SIGIO in that case. --sct */
  403. si.si_signo = signum;
  404. si.si_errno = 0;
  405. si.si_code = reason;
  406. /* Make sure we are called with one of the POLL_*
  407. reasons, otherwise we could leak kernel stack into
  408. userspace. */
  409. BUG_ON((reason & __SI_MASK) != __SI_POLL);
  410. if (reason - POLL_IN >= NSIGPOLL)
  411. si.si_band = ~0L;
  412. else
  413. si.si_band = band_table[reason - POLL_IN];
  414. si.si_fd = fd;
  415. if (!do_send_sig_info(signum, &si, p, group))
  416. break;
  417. /* fall-through: fall back on the old plain SIGIO signal */
  418. case 0:
  419. do_send_sig_info(SIGIO, SEND_SIG_PRIV, p, group);
  420. }
  421. }
  422. void send_sigio(struct fown_struct *fown, int fd, int band)
  423. {
  424. struct task_struct *p;
  425. enum pid_type type;
  426. struct pid *pid;
  427. int group = 1;
  428. read_lock(&fown->lock);
  429. type = fown->pid_type;
  430. if (type == PIDTYPE_MAX) {
  431. group = 0;
  432. type = PIDTYPE_PID;
  433. }
  434. pid = fown->pid;
  435. if (!pid)
  436. goto out_unlock_fown;
  437. read_lock(&tasklist_lock);
  438. do_each_pid_task(pid, type, p) {
  439. send_sigio_to_task(p, fown, fd, band, group);
  440. } while_each_pid_task(pid, type, p);
  441. read_unlock(&tasklist_lock);
  442. out_unlock_fown:
  443. read_unlock(&fown->lock);
  444. }
  445. static void send_sigurg_to_task(struct task_struct *p,
  446. struct fown_struct *fown, int group)
  447. {
  448. if (sigio_perm(p, fown, SIGURG))
  449. do_send_sig_info(SIGURG, SEND_SIG_PRIV, p, group);
  450. }
  451. int send_sigurg(struct fown_struct *fown)
  452. {
  453. struct task_struct *p;
  454. enum pid_type type;
  455. struct pid *pid;
  456. int group = 1;
  457. int ret = 0;
  458. read_lock(&fown->lock);
  459. type = fown->pid_type;
  460. if (type == PIDTYPE_MAX) {
  461. group = 0;
  462. type = PIDTYPE_PID;
  463. }
  464. pid = fown->pid;
  465. if (!pid)
  466. goto out_unlock_fown;
  467. ret = 1;
  468. read_lock(&tasklist_lock);
  469. do_each_pid_task(pid, type, p) {
  470. send_sigurg_to_task(p, fown, group);
  471. } while_each_pid_task(pid, type, p);
  472. read_unlock(&tasklist_lock);
  473. out_unlock_fown:
  474. read_unlock(&fown->lock);
  475. return ret;
  476. }
  477. static DEFINE_SPINLOCK(fasync_lock);
  478. static struct kmem_cache *fasync_cache __read_mostly;
  479. static void fasync_free_rcu(struct rcu_head *head)
  480. {
  481. kmem_cache_free(fasync_cache,
  482. container_of(head, struct fasync_struct, fa_rcu));
  483. }
  484. /*
  485. * Remove a fasync entry. If successfully removed, return
  486. * positive and clear the FASYNC flag. If no entry exists,
  487. * do nothing and return 0.
  488. *
  489. * NOTE! It is very important that the FASYNC flag always
  490. * match the state "is the filp on a fasync list".
  491. *
  492. */
  493. int fasync_remove_entry(struct file *filp, struct fasync_struct **fapp)
  494. {
  495. struct fasync_struct *fa, **fp;
  496. int result = 0;
  497. spin_lock(&filp->f_lock);
  498. spin_lock(&fasync_lock);
  499. for (fp = fapp; (fa = *fp) != NULL; fp = &fa->fa_next) {
  500. if (fa->fa_file != filp)
  501. continue;
  502. spin_lock_irq(&fa->fa_lock);
  503. fa->fa_file = NULL;
  504. spin_unlock_irq(&fa->fa_lock);
  505. *fp = fa->fa_next;
  506. call_rcu(&fa->fa_rcu, fasync_free_rcu);
  507. filp->f_flags &= ~FASYNC;
  508. result = 1;
  509. break;
  510. }
  511. spin_unlock(&fasync_lock);
  512. spin_unlock(&filp->f_lock);
  513. return result;
  514. }
  515. struct fasync_struct *fasync_alloc(void)
  516. {
  517. return kmem_cache_alloc(fasync_cache, GFP_KERNEL);
  518. }
  519. /*
  520. * NOTE! This can be used only for unused fasync entries:
  521. * entries that actually got inserted on the fasync list
  522. * need to be released by rcu - see fasync_remove_entry.
  523. */
  524. void fasync_free(struct fasync_struct *new)
  525. {
  526. kmem_cache_free(fasync_cache, new);
  527. }
  528. /*
  529. * Insert a new entry into the fasync list. Return the pointer to the
  530. * old one if we didn't use the new one.
  531. *
  532. * NOTE! It is very important that the FASYNC flag always
  533. * match the state "is the filp on a fasync list".
  534. */
  535. struct fasync_struct *fasync_insert_entry(int fd, struct file *filp, struct fasync_struct **fapp, struct fasync_struct *new)
  536. {
  537. struct fasync_struct *fa, **fp;
  538. spin_lock(&filp->f_lock);
  539. spin_lock(&fasync_lock);
  540. for (fp = fapp; (fa = *fp) != NULL; fp = &fa->fa_next) {
  541. if (fa->fa_file != filp)
  542. continue;
  543. spin_lock_irq(&fa->fa_lock);
  544. fa->fa_fd = fd;
  545. spin_unlock_irq(&fa->fa_lock);
  546. goto out;
  547. }
  548. spin_lock_init(&new->fa_lock);
  549. new->magic = FASYNC_MAGIC;
  550. new->fa_file = filp;
  551. new->fa_fd = fd;
  552. new->fa_next = *fapp;
  553. rcu_assign_pointer(*fapp, new);
  554. filp->f_flags |= FASYNC;
  555. out:
  556. spin_unlock(&fasync_lock);
  557. spin_unlock(&filp->f_lock);
  558. return fa;
  559. }
  560. /*
  561. * Add a fasync entry. Return negative on error, positive if
  562. * added, and zero if did nothing but change an existing one.
  563. */
  564. static int fasync_add_entry(int fd, struct file *filp, struct fasync_struct **fapp)
  565. {
  566. struct fasync_struct *new;
  567. new = fasync_alloc();
  568. if (!new)
  569. return -ENOMEM;
  570. /*
  571. * fasync_insert_entry() returns the old (update) entry if
  572. * it existed.
  573. *
  574. * So free the (unused) new entry and return 0 to let the
  575. * caller know that we didn't add any new fasync entries.
  576. */
  577. if (fasync_insert_entry(fd, filp, fapp, new)) {
  578. fasync_free(new);
  579. return 0;
  580. }
  581. return 1;
  582. }
  583. /*
  584. * fasync_helper() is used by almost all character device drivers
  585. * to set up the fasync queue, and for regular files by the file
  586. * lease code. It returns negative on error, 0 if it did no changes
  587. * and positive if it added/deleted the entry.
  588. */
  589. int fasync_helper(int fd, struct file * filp, int on, struct fasync_struct **fapp)
  590. {
  591. if (!on)
  592. return fasync_remove_entry(filp, fapp);
  593. return fasync_add_entry(fd, filp, fapp);
  594. }
  595. EXPORT_SYMBOL(fasync_helper);
  596. /*
  597. * rcu_read_lock() is held
  598. */
  599. static void kill_fasync_rcu(struct fasync_struct *fa, int sig, int band)
  600. {
  601. while (fa) {
  602. struct fown_struct *fown;
  603. unsigned long flags;
  604. if (fa->magic != FASYNC_MAGIC) {
  605. printk(KERN_ERR "kill_fasync: bad magic number in "
  606. "fasync_struct!\n");
  607. return;
  608. }
  609. spin_lock_irqsave(&fa->fa_lock, flags);
  610. if (fa->fa_file) {
  611. fown = &fa->fa_file->f_owner;
  612. /* Don't send SIGURG to processes which have not set a
  613. queued signum: SIGURG has its own default signalling
  614. mechanism. */
  615. if (!(sig == SIGURG && fown->signum == 0))
  616. send_sigio(fown, fa->fa_fd, band);
  617. }
  618. spin_unlock_irqrestore(&fa->fa_lock, flags);
  619. fa = rcu_dereference(fa->fa_next);
  620. }
  621. }
  622. void kill_fasync(struct fasync_struct **fp, int sig, int band)
  623. {
  624. /* First a quick test without locking: usually
  625. * the list is empty.
  626. */
  627. if (*fp) {
  628. rcu_read_lock();
  629. kill_fasync_rcu(rcu_dereference(*fp), sig, band);
  630. rcu_read_unlock();
  631. }
  632. }
  633. EXPORT_SYMBOL(kill_fasync);
  634. static int __init fcntl_init(void)
  635. {
  636. /*
  637. * Please add new bits here to ensure allocation uniqueness.
  638. * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY
  639. * is defined as O_NONBLOCK on some platforms and not on others.
  640. */
  641. BUILD_BUG_ON(19 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
  642. O_RDONLY | O_WRONLY | O_RDWR |
  643. O_CREAT | O_EXCL | O_NOCTTY |
  644. O_TRUNC | O_APPEND | /* O_NONBLOCK | */
  645. __O_SYNC | O_DSYNC | FASYNC |
  646. O_DIRECT | O_LARGEFILE | O_DIRECTORY |
  647. O_NOFOLLOW | O_NOATIME | O_CLOEXEC |
  648. __FMODE_EXEC | O_PATH
  649. ));
  650. fasync_cache = kmem_cache_create("fasync_cache",
  651. sizeof(struct fasync_struct), 0, SLAB_PANIC, NULL);
  652. return 0;
  653. }
  654. module_init(fcntl_init)