fcntl.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  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 = filp->f_path.dentry->d_inode;
  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, FD_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 file *filp;
  311. int fput_needed;
  312. long err = -EBADF;
  313. filp = fget_raw_light(fd, &fput_needed);
  314. if (!filp)
  315. goto out;
  316. if (unlikely(filp->f_mode & FMODE_PATH)) {
  317. if (!check_fcntl_cmd(cmd))
  318. goto out1;
  319. }
  320. err = security_file_fcntl(filp, cmd, arg);
  321. if (!err)
  322. err = do_fcntl(fd, cmd, arg, filp);
  323. out1:
  324. fput_light(filp, fput_needed);
  325. out:
  326. return err;
  327. }
  328. #if BITS_PER_LONG == 32
  329. SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
  330. unsigned long, arg)
  331. {
  332. struct file * filp;
  333. long err = -EBADF;
  334. int fput_needed;
  335. filp = fget_raw_light(fd, &fput_needed);
  336. if (!filp)
  337. goto out;
  338. if (unlikely(filp->f_mode & FMODE_PATH)) {
  339. if (!check_fcntl_cmd(cmd))
  340. goto out1;
  341. }
  342. err = security_file_fcntl(filp, cmd, arg);
  343. if (err)
  344. goto out1;
  345. switch (cmd) {
  346. case F_GETLK64:
  347. err = fcntl_getlk64(filp, (struct flock64 __user *) arg);
  348. break;
  349. case F_SETLK64:
  350. case F_SETLKW64:
  351. err = fcntl_setlk64(fd, filp, cmd,
  352. (struct flock64 __user *) arg);
  353. break;
  354. default:
  355. err = do_fcntl(fd, cmd, arg, filp);
  356. break;
  357. }
  358. out1:
  359. fput_light(filp, fput_needed);
  360. out:
  361. return err;
  362. }
  363. #endif
  364. /* Table to convert sigio signal codes into poll band bitmaps */
  365. static const long band_table[NSIGPOLL] = {
  366. POLLIN | POLLRDNORM, /* POLL_IN */
  367. POLLOUT | POLLWRNORM | POLLWRBAND, /* POLL_OUT */
  368. POLLIN | POLLRDNORM | POLLMSG, /* POLL_MSG */
  369. POLLERR, /* POLL_ERR */
  370. POLLPRI | POLLRDBAND, /* POLL_PRI */
  371. POLLHUP | POLLERR /* POLL_HUP */
  372. };
  373. static inline int sigio_perm(struct task_struct *p,
  374. struct fown_struct *fown, int sig)
  375. {
  376. const struct cred *cred;
  377. int ret;
  378. rcu_read_lock();
  379. cred = __task_cred(p);
  380. ret = ((uid_eq(fown->euid, GLOBAL_ROOT_UID) ||
  381. uid_eq(fown->euid, cred->suid) || uid_eq(fown->euid, cred->uid) ||
  382. uid_eq(fown->uid, cred->suid) || uid_eq(fown->uid, cred->uid)) &&
  383. !security_file_send_sigiotask(p, fown, sig));
  384. rcu_read_unlock();
  385. return ret;
  386. }
  387. static void send_sigio_to_task(struct task_struct *p,
  388. struct fown_struct *fown,
  389. int fd, int reason, int group)
  390. {
  391. /*
  392. * F_SETSIG can change ->signum lockless in parallel, make
  393. * sure we read it once and use the same value throughout.
  394. */
  395. int signum = ACCESS_ONCE(fown->signum);
  396. if (!sigio_perm(p, fown, signum))
  397. return;
  398. switch (signum) {
  399. siginfo_t si;
  400. default:
  401. /* Queue a rt signal with the appropriate fd as its
  402. value. We use SI_SIGIO as the source, not
  403. SI_KERNEL, since kernel signals always get
  404. delivered even if we can't queue. Failure to
  405. queue in this case _should_ be reported; we fall
  406. back to SIGIO in that case. --sct */
  407. si.si_signo = signum;
  408. si.si_errno = 0;
  409. si.si_code = reason;
  410. /* Make sure we are called with one of the POLL_*
  411. reasons, otherwise we could leak kernel stack into
  412. userspace. */
  413. BUG_ON((reason & __SI_MASK) != __SI_POLL);
  414. if (reason - POLL_IN >= NSIGPOLL)
  415. si.si_band = ~0L;
  416. else
  417. si.si_band = band_table[reason - POLL_IN];
  418. si.si_fd = fd;
  419. if (!do_send_sig_info(signum, &si, p, group))
  420. break;
  421. /* fall-through: fall back on the old plain SIGIO signal */
  422. case 0:
  423. do_send_sig_info(SIGIO, SEND_SIG_PRIV, p, group);
  424. }
  425. }
  426. void send_sigio(struct fown_struct *fown, int fd, int band)
  427. {
  428. struct task_struct *p;
  429. enum pid_type type;
  430. struct pid *pid;
  431. int group = 1;
  432. read_lock(&fown->lock);
  433. type = fown->pid_type;
  434. if (type == PIDTYPE_MAX) {
  435. group = 0;
  436. type = PIDTYPE_PID;
  437. }
  438. pid = fown->pid;
  439. if (!pid)
  440. goto out_unlock_fown;
  441. read_lock(&tasklist_lock);
  442. do_each_pid_task(pid, type, p) {
  443. send_sigio_to_task(p, fown, fd, band, group);
  444. } while_each_pid_task(pid, type, p);
  445. read_unlock(&tasklist_lock);
  446. out_unlock_fown:
  447. read_unlock(&fown->lock);
  448. }
  449. static void send_sigurg_to_task(struct task_struct *p,
  450. struct fown_struct *fown, int group)
  451. {
  452. if (sigio_perm(p, fown, SIGURG))
  453. do_send_sig_info(SIGURG, SEND_SIG_PRIV, p, group);
  454. }
  455. int send_sigurg(struct fown_struct *fown)
  456. {
  457. struct task_struct *p;
  458. enum pid_type type;
  459. struct pid *pid;
  460. int group = 1;
  461. int ret = 0;
  462. read_lock(&fown->lock);
  463. type = fown->pid_type;
  464. if (type == PIDTYPE_MAX) {
  465. group = 0;
  466. type = PIDTYPE_PID;
  467. }
  468. pid = fown->pid;
  469. if (!pid)
  470. goto out_unlock_fown;
  471. ret = 1;
  472. read_lock(&tasklist_lock);
  473. do_each_pid_task(pid, type, p) {
  474. send_sigurg_to_task(p, fown, group);
  475. } while_each_pid_task(pid, type, p);
  476. read_unlock(&tasklist_lock);
  477. out_unlock_fown:
  478. read_unlock(&fown->lock);
  479. return ret;
  480. }
  481. static DEFINE_SPINLOCK(fasync_lock);
  482. static struct kmem_cache *fasync_cache __read_mostly;
  483. static void fasync_free_rcu(struct rcu_head *head)
  484. {
  485. kmem_cache_free(fasync_cache,
  486. container_of(head, struct fasync_struct, fa_rcu));
  487. }
  488. /*
  489. * Remove a fasync entry. If successfully removed, return
  490. * positive and clear the FASYNC flag. If no entry exists,
  491. * do nothing and return 0.
  492. *
  493. * NOTE! It is very important that the FASYNC flag always
  494. * match the state "is the filp on a fasync list".
  495. *
  496. */
  497. int fasync_remove_entry(struct file *filp, struct fasync_struct **fapp)
  498. {
  499. struct fasync_struct *fa, **fp;
  500. int result = 0;
  501. spin_lock(&filp->f_lock);
  502. spin_lock(&fasync_lock);
  503. for (fp = fapp; (fa = *fp) != NULL; fp = &fa->fa_next) {
  504. if (fa->fa_file != filp)
  505. continue;
  506. spin_lock_irq(&fa->fa_lock);
  507. fa->fa_file = NULL;
  508. spin_unlock_irq(&fa->fa_lock);
  509. *fp = fa->fa_next;
  510. call_rcu(&fa->fa_rcu, fasync_free_rcu);
  511. filp->f_flags &= ~FASYNC;
  512. result = 1;
  513. break;
  514. }
  515. spin_unlock(&fasync_lock);
  516. spin_unlock(&filp->f_lock);
  517. return result;
  518. }
  519. struct fasync_struct *fasync_alloc(void)
  520. {
  521. return kmem_cache_alloc(fasync_cache, GFP_KERNEL);
  522. }
  523. /*
  524. * NOTE! This can be used only for unused fasync entries:
  525. * entries that actually got inserted on the fasync list
  526. * need to be released by rcu - see fasync_remove_entry.
  527. */
  528. void fasync_free(struct fasync_struct *new)
  529. {
  530. kmem_cache_free(fasync_cache, new);
  531. }
  532. /*
  533. * Insert a new entry into the fasync list. Return the pointer to the
  534. * old one if we didn't use the new one.
  535. *
  536. * NOTE! It is very important that the FASYNC flag always
  537. * match the state "is the filp on a fasync list".
  538. */
  539. struct fasync_struct *fasync_insert_entry(int fd, struct file *filp, struct fasync_struct **fapp, struct fasync_struct *new)
  540. {
  541. struct fasync_struct *fa, **fp;
  542. spin_lock(&filp->f_lock);
  543. spin_lock(&fasync_lock);
  544. for (fp = fapp; (fa = *fp) != NULL; fp = &fa->fa_next) {
  545. if (fa->fa_file != filp)
  546. continue;
  547. spin_lock_irq(&fa->fa_lock);
  548. fa->fa_fd = fd;
  549. spin_unlock_irq(&fa->fa_lock);
  550. goto out;
  551. }
  552. spin_lock_init(&new->fa_lock);
  553. new->magic = FASYNC_MAGIC;
  554. new->fa_file = filp;
  555. new->fa_fd = fd;
  556. new->fa_next = *fapp;
  557. rcu_assign_pointer(*fapp, new);
  558. filp->f_flags |= FASYNC;
  559. out:
  560. spin_unlock(&fasync_lock);
  561. spin_unlock(&filp->f_lock);
  562. return fa;
  563. }
  564. /*
  565. * Add a fasync entry. Return negative on error, positive if
  566. * added, and zero if did nothing but change an existing one.
  567. */
  568. static int fasync_add_entry(int fd, struct file *filp, struct fasync_struct **fapp)
  569. {
  570. struct fasync_struct *new;
  571. new = fasync_alloc();
  572. if (!new)
  573. return -ENOMEM;
  574. /*
  575. * fasync_insert_entry() returns the old (update) entry if
  576. * it existed.
  577. *
  578. * So free the (unused) new entry and return 0 to let the
  579. * caller know that we didn't add any new fasync entries.
  580. */
  581. if (fasync_insert_entry(fd, filp, fapp, new)) {
  582. fasync_free(new);
  583. return 0;
  584. }
  585. return 1;
  586. }
  587. /*
  588. * fasync_helper() is used by almost all character device drivers
  589. * to set up the fasync queue, and for regular files by the file
  590. * lease code. It returns negative on error, 0 if it did no changes
  591. * and positive if it added/deleted the entry.
  592. */
  593. int fasync_helper(int fd, struct file * filp, int on, struct fasync_struct **fapp)
  594. {
  595. if (!on)
  596. return fasync_remove_entry(filp, fapp);
  597. return fasync_add_entry(fd, filp, fapp);
  598. }
  599. EXPORT_SYMBOL(fasync_helper);
  600. /*
  601. * rcu_read_lock() is held
  602. */
  603. static void kill_fasync_rcu(struct fasync_struct *fa, int sig, int band)
  604. {
  605. while (fa) {
  606. struct fown_struct *fown;
  607. unsigned long flags;
  608. if (fa->magic != FASYNC_MAGIC) {
  609. printk(KERN_ERR "kill_fasync: bad magic number in "
  610. "fasync_struct!\n");
  611. return;
  612. }
  613. spin_lock_irqsave(&fa->fa_lock, flags);
  614. if (fa->fa_file) {
  615. fown = &fa->fa_file->f_owner;
  616. /* Don't send SIGURG to processes which have not set a
  617. queued signum: SIGURG has its own default signalling
  618. mechanism. */
  619. if (!(sig == SIGURG && fown->signum == 0))
  620. send_sigio(fown, fa->fa_fd, band);
  621. }
  622. spin_unlock_irqrestore(&fa->fa_lock, flags);
  623. fa = rcu_dereference(fa->fa_next);
  624. }
  625. }
  626. void kill_fasync(struct fasync_struct **fp, int sig, int band)
  627. {
  628. /* First a quick test without locking: usually
  629. * the list is empty.
  630. */
  631. if (*fp) {
  632. rcu_read_lock();
  633. kill_fasync_rcu(rcu_dereference(*fp), sig, band);
  634. rcu_read_unlock();
  635. }
  636. }
  637. EXPORT_SYMBOL(kill_fasync);
  638. static int __init fcntl_init(void)
  639. {
  640. /*
  641. * Please add new bits here to ensure allocation uniqueness.
  642. * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY
  643. * is defined as O_NONBLOCK on some platforms and not on others.
  644. */
  645. BUILD_BUG_ON(19 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
  646. O_RDONLY | O_WRONLY | O_RDWR |
  647. O_CREAT | O_EXCL | O_NOCTTY |
  648. O_TRUNC | O_APPEND | /* O_NONBLOCK | */
  649. __O_SYNC | O_DSYNC | FASYNC |
  650. O_DIRECT | O_LARGEFILE | O_DIRECTORY |
  651. O_NOFOLLOW | O_NOATIME | O_CLOEXEC |
  652. __FMODE_EXEC | O_PATH
  653. ));
  654. fasync_cache = kmem_cache_create("fasync_cache",
  655. sizeof(struct fasync_struct), 0, SLAB_PANIC, NULL);
  656. return 0;
  657. }
  658. module_init(fcntl_init)