signal.c 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623
  1. /*
  2. * linux/kernel/signal.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. *
  6. * 1997-11-02 Modified for POSIX.1b signals by Richard Henderson
  7. *
  8. * 2003-06-02 Jim Houston - Concurrent Computer Corp.
  9. * Changes to use preallocated sigqueue structures
  10. * to allow signals to be sent reliably.
  11. */
  12. #include <linux/slab.h>
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/sched.h>
  16. #include <linux/fs.h>
  17. #include <linux/tty.h>
  18. #include <linux/binfmts.h>
  19. #include <linux/security.h>
  20. #include <linux/syscalls.h>
  21. #include <linux/ptrace.h>
  22. #include <linux/signal.h>
  23. #include <linux/signalfd.h>
  24. #include <linux/tracehook.h>
  25. #include <linux/capability.h>
  26. #include <linux/freezer.h>
  27. #include <linux/pid_namespace.h>
  28. #include <linux/nsproxy.h>
  29. #include <trace/sched.h>
  30. #include <asm/param.h>
  31. #include <asm/uaccess.h>
  32. #include <asm/unistd.h>
  33. #include <asm/siginfo.h>
  34. #include "audit.h" /* audit_signal_info() */
  35. /*
  36. * SLAB caches for signal bits.
  37. */
  38. static struct kmem_cache *sigqueue_cachep;
  39. DEFINE_TRACE(sched_signal_send);
  40. static void __user *sig_handler(struct task_struct *t, int sig)
  41. {
  42. return t->sighand->action[sig - 1].sa.sa_handler;
  43. }
  44. static int sig_handler_ignored(void __user *handler, int sig)
  45. {
  46. /* Is it explicitly or implicitly ignored? */
  47. return handler == SIG_IGN ||
  48. (handler == SIG_DFL && sig_kernel_ignore(sig));
  49. }
  50. static int sig_ignored(struct task_struct *t, int sig)
  51. {
  52. void __user *handler;
  53. /*
  54. * Blocked signals are never ignored, since the
  55. * signal handler may change by the time it is
  56. * unblocked.
  57. */
  58. if (sigismember(&t->blocked, sig) || sigismember(&t->real_blocked, sig))
  59. return 0;
  60. handler = sig_handler(t, sig);
  61. if (!sig_handler_ignored(handler, sig))
  62. return 0;
  63. /*
  64. * Tracers may want to know about even ignored signals.
  65. */
  66. return !tracehook_consider_ignored_signal(t, sig, handler);
  67. }
  68. /*
  69. * Re-calculate pending state from the set of locally pending
  70. * signals, globally pending signals, and blocked signals.
  71. */
  72. static inline int has_pending_signals(sigset_t *signal, sigset_t *blocked)
  73. {
  74. unsigned long ready;
  75. long i;
  76. switch (_NSIG_WORDS) {
  77. default:
  78. for (i = _NSIG_WORDS, ready = 0; --i >= 0 ;)
  79. ready |= signal->sig[i] &~ blocked->sig[i];
  80. break;
  81. case 4: ready = signal->sig[3] &~ blocked->sig[3];
  82. ready |= signal->sig[2] &~ blocked->sig[2];
  83. ready |= signal->sig[1] &~ blocked->sig[1];
  84. ready |= signal->sig[0] &~ blocked->sig[0];
  85. break;
  86. case 2: ready = signal->sig[1] &~ blocked->sig[1];
  87. ready |= signal->sig[0] &~ blocked->sig[0];
  88. break;
  89. case 1: ready = signal->sig[0] &~ blocked->sig[0];
  90. }
  91. return ready != 0;
  92. }
  93. #define PENDING(p,b) has_pending_signals(&(p)->signal, (b))
  94. static int recalc_sigpending_tsk(struct task_struct *t)
  95. {
  96. if (t->signal->group_stop_count > 0 ||
  97. PENDING(&t->pending, &t->blocked) ||
  98. PENDING(&t->signal->shared_pending, &t->blocked)) {
  99. set_tsk_thread_flag(t, TIF_SIGPENDING);
  100. return 1;
  101. }
  102. /*
  103. * We must never clear the flag in another thread, or in current
  104. * when it's possible the current syscall is returning -ERESTART*.
  105. * So we don't clear it here, and only callers who know they should do.
  106. */
  107. return 0;
  108. }
  109. /*
  110. * After recalculating TIF_SIGPENDING, we need to make sure the task wakes up.
  111. * This is superfluous when called on current, the wakeup is a harmless no-op.
  112. */
  113. void recalc_sigpending_and_wake(struct task_struct *t)
  114. {
  115. if (recalc_sigpending_tsk(t))
  116. signal_wake_up(t, 0);
  117. }
  118. void recalc_sigpending(void)
  119. {
  120. if (unlikely(tracehook_force_sigpending()))
  121. set_thread_flag(TIF_SIGPENDING);
  122. else if (!recalc_sigpending_tsk(current) && !freezing(current))
  123. clear_thread_flag(TIF_SIGPENDING);
  124. }
  125. /* Given the mask, find the first available signal that should be serviced. */
  126. int next_signal(struct sigpending *pending, sigset_t *mask)
  127. {
  128. unsigned long i, *s, *m, x;
  129. int sig = 0;
  130. s = pending->signal.sig;
  131. m = mask->sig;
  132. switch (_NSIG_WORDS) {
  133. default:
  134. for (i = 0; i < _NSIG_WORDS; ++i, ++s, ++m)
  135. if ((x = *s &~ *m) != 0) {
  136. sig = ffz(~x) + i*_NSIG_BPW + 1;
  137. break;
  138. }
  139. break;
  140. case 2: if ((x = s[0] &~ m[0]) != 0)
  141. sig = 1;
  142. else if ((x = s[1] &~ m[1]) != 0)
  143. sig = _NSIG_BPW + 1;
  144. else
  145. break;
  146. sig += ffz(~x);
  147. break;
  148. case 1: if ((x = *s &~ *m) != 0)
  149. sig = ffz(~x) + 1;
  150. break;
  151. }
  152. return sig;
  153. }
  154. /*
  155. * allocate a new signal queue record
  156. * - this may be called without locks if and only if t == current, otherwise an
  157. * appopriate lock must be held to stop the target task from exiting
  158. */
  159. static struct sigqueue *__sigqueue_alloc(struct task_struct *t, gfp_t flags,
  160. int override_rlimit)
  161. {
  162. struct sigqueue *q = NULL;
  163. struct user_struct *user;
  164. /*
  165. * We won't get problems with the target's UID changing under us
  166. * because changing it requires RCU be used, and if t != current, the
  167. * caller must be holding the RCU readlock (by way of a spinlock) and
  168. * we use RCU protection here
  169. */
  170. user = get_uid(__task_cred(t)->user);
  171. atomic_inc(&user->sigpending);
  172. if (override_rlimit ||
  173. atomic_read(&user->sigpending) <=
  174. t->signal->rlim[RLIMIT_SIGPENDING].rlim_cur)
  175. q = kmem_cache_alloc(sigqueue_cachep, flags);
  176. if (unlikely(q == NULL)) {
  177. atomic_dec(&user->sigpending);
  178. free_uid(user);
  179. } else {
  180. INIT_LIST_HEAD(&q->list);
  181. q->flags = 0;
  182. q->user = user;
  183. }
  184. return q;
  185. }
  186. static void __sigqueue_free(struct sigqueue *q)
  187. {
  188. if (q->flags & SIGQUEUE_PREALLOC)
  189. return;
  190. atomic_dec(&q->user->sigpending);
  191. free_uid(q->user);
  192. kmem_cache_free(sigqueue_cachep, q);
  193. }
  194. void flush_sigqueue(struct sigpending *queue)
  195. {
  196. struct sigqueue *q;
  197. sigemptyset(&queue->signal);
  198. while (!list_empty(&queue->list)) {
  199. q = list_entry(queue->list.next, struct sigqueue , list);
  200. list_del_init(&q->list);
  201. __sigqueue_free(q);
  202. }
  203. }
  204. /*
  205. * Flush all pending signals for a task.
  206. */
  207. void flush_signals(struct task_struct *t)
  208. {
  209. unsigned long flags;
  210. spin_lock_irqsave(&t->sighand->siglock, flags);
  211. clear_tsk_thread_flag(t, TIF_SIGPENDING);
  212. flush_sigqueue(&t->pending);
  213. flush_sigqueue(&t->signal->shared_pending);
  214. spin_unlock_irqrestore(&t->sighand->siglock, flags);
  215. }
  216. static void __flush_itimer_signals(struct sigpending *pending)
  217. {
  218. sigset_t signal, retain;
  219. struct sigqueue *q, *n;
  220. signal = pending->signal;
  221. sigemptyset(&retain);
  222. list_for_each_entry_safe(q, n, &pending->list, list) {
  223. int sig = q->info.si_signo;
  224. if (likely(q->info.si_code != SI_TIMER)) {
  225. sigaddset(&retain, sig);
  226. } else {
  227. sigdelset(&signal, sig);
  228. list_del_init(&q->list);
  229. __sigqueue_free(q);
  230. }
  231. }
  232. sigorsets(&pending->signal, &signal, &retain);
  233. }
  234. void flush_itimer_signals(void)
  235. {
  236. struct task_struct *tsk = current;
  237. unsigned long flags;
  238. spin_lock_irqsave(&tsk->sighand->siglock, flags);
  239. __flush_itimer_signals(&tsk->pending);
  240. __flush_itimer_signals(&tsk->signal->shared_pending);
  241. spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
  242. }
  243. void ignore_signals(struct task_struct *t)
  244. {
  245. int i;
  246. for (i = 0; i < _NSIG; ++i)
  247. t->sighand->action[i].sa.sa_handler = SIG_IGN;
  248. flush_signals(t);
  249. }
  250. /*
  251. * Flush all handlers for a task.
  252. */
  253. void
  254. flush_signal_handlers(struct task_struct *t, int force_default)
  255. {
  256. int i;
  257. struct k_sigaction *ka = &t->sighand->action[0];
  258. for (i = _NSIG ; i != 0 ; i--) {
  259. if (force_default || ka->sa.sa_handler != SIG_IGN)
  260. ka->sa.sa_handler = SIG_DFL;
  261. ka->sa.sa_flags = 0;
  262. sigemptyset(&ka->sa.sa_mask);
  263. ka++;
  264. }
  265. }
  266. int unhandled_signal(struct task_struct *tsk, int sig)
  267. {
  268. void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
  269. if (is_global_init(tsk))
  270. return 1;
  271. if (handler != SIG_IGN && handler != SIG_DFL)
  272. return 0;
  273. return !tracehook_consider_fatal_signal(tsk, sig, handler);
  274. }
  275. /* Notify the system that a driver wants to block all signals for this
  276. * process, and wants to be notified if any signals at all were to be
  277. * sent/acted upon. If the notifier routine returns non-zero, then the
  278. * signal will be acted upon after all. If the notifier routine returns 0,
  279. * then then signal will be blocked. Only one block per process is
  280. * allowed. priv is a pointer to private data that the notifier routine
  281. * can use to determine if the signal should be blocked or not. */
  282. void
  283. block_all_signals(int (*notifier)(void *priv), void *priv, sigset_t *mask)
  284. {
  285. unsigned long flags;
  286. spin_lock_irqsave(&current->sighand->siglock, flags);
  287. current->notifier_mask = mask;
  288. current->notifier_data = priv;
  289. current->notifier = notifier;
  290. spin_unlock_irqrestore(&current->sighand->siglock, flags);
  291. }
  292. /* Notify the system that blocking has ended. */
  293. void
  294. unblock_all_signals(void)
  295. {
  296. unsigned long flags;
  297. spin_lock_irqsave(&current->sighand->siglock, flags);
  298. current->notifier = NULL;
  299. current->notifier_data = NULL;
  300. recalc_sigpending();
  301. spin_unlock_irqrestore(&current->sighand->siglock, flags);
  302. }
  303. static void collect_signal(int sig, struct sigpending *list, siginfo_t *info)
  304. {
  305. struct sigqueue *q, *first = NULL;
  306. /*
  307. * Collect the siginfo appropriate to this signal. Check if
  308. * there is another siginfo for the same signal.
  309. */
  310. list_for_each_entry(q, &list->list, list) {
  311. if (q->info.si_signo == sig) {
  312. if (first)
  313. goto still_pending;
  314. first = q;
  315. }
  316. }
  317. sigdelset(&list->signal, sig);
  318. if (first) {
  319. still_pending:
  320. list_del_init(&first->list);
  321. copy_siginfo(info, &first->info);
  322. __sigqueue_free(first);
  323. } else {
  324. /* Ok, it wasn't in the queue. This must be
  325. a fast-pathed signal or we must have been
  326. out of queue space. So zero out the info.
  327. */
  328. info->si_signo = sig;
  329. info->si_errno = 0;
  330. info->si_code = 0;
  331. info->si_pid = 0;
  332. info->si_uid = 0;
  333. }
  334. }
  335. static int __dequeue_signal(struct sigpending *pending, sigset_t *mask,
  336. siginfo_t *info)
  337. {
  338. int sig = next_signal(pending, mask);
  339. if (sig) {
  340. if (current->notifier) {
  341. if (sigismember(current->notifier_mask, sig)) {
  342. if (!(current->notifier)(current->notifier_data)) {
  343. clear_thread_flag(TIF_SIGPENDING);
  344. return 0;
  345. }
  346. }
  347. }
  348. collect_signal(sig, pending, info);
  349. }
  350. return sig;
  351. }
  352. /*
  353. * Dequeue a signal and return the element to the caller, which is
  354. * expected to free it.
  355. *
  356. * All callers have to hold the siglock.
  357. */
  358. int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
  359. {
  360. int signr;
  361. /* We only dequeue private signals from ourselves, we don't let
  362. * signalfd steal them
  363. */
  364. signr = __dequeue_signal(&tsk->pending, mask, info);
  365. if (!signr) {
  366. signr = __dequeue_signal(&tsk->signal->shared_pending,
  367. mask, info);
  368. /*
  369. * itimer signal ?
  370. *
  371. * itimers are process shared and we restart periodic
  372. * itimers in the signal delivery path to prevent DoS
  373. * attacks in the high resolution timer case. This is
  374. * compliant with the old way of self restarting
  375. * itimers, as the SIGALRM is a legacy signal and only
  376. * queued once. Changing the restart behaviour to
  377. * restart the timer in the signal dequeue path is
  378. * reducing the timer noise on heavy loaded !highres
  379. * systems too.
  380. */
  381. if (unlikely(signr == SIGALRM)) {
  382. struct hrtimer *tmr = &tsk->signal->real_timer;
  383. if (!hrtimer_is_queued(tmr) &&
  384. tsk->signal->it_real_incr.tv64 != 0) {
  385. hrtimer_forward(tmr, tmr->base->get_time(),
  386. tsk->signal->it_real_incr);
  387. hrtimer_restart(tmr);
  388. }
  389. }
  390. }
  391. recalc_sigpending();
  392. if (!signr)
  393. return 0;
  394. if (unlikely(sig_kernel_stop(signr))) {
  395. /*
  396. * Set a marker that we have dequeued a stop signal. Our
  397. * caller might release the siglock and then the pending
  398. * stop signal it is about to process is no longer in the
  399. * pending bitmasks, but must still be cleared by a SIGCONT
  400. * (and overruled by a SIGKILL). So those cases clear this
  401. * shared flag after we've set it. Note that this flag may
  402. * remain set after the signal we return is ignored or
  403. * handled. That doesn't matter because its only purpose
  404. * is to alert stop-signal processing code when another
  405. * processor has come along and cleared the flag.
  406. */
  407. tsk->signal->flags |= SIGNAL_STOP_DEQUEUED;
  408. }
  409. if ((info->si_code & __SI_MASK) == __SI_TIMER && info->si_sys_private) {
  410. /*
  411. * Release the siglock to ensure proper locking order
  412. * of timer locks outside of siglocks. Note, we leave
  413. * irqs disabled here, since the posix-timers code is
  414. * about to disable them again anyway.
  415. */
  416. spin_unlock(&tsk->sighand->siglock);
  417. do_schedule_next_timer(info);
  418. spin_lock(&tsk->sighand->siglock);
  419. }
  420. return signr;
  421. }
  422. /*
  423. * Tell a process that it has a new active signal..
  424. *
  425. * NOTE! we rely on the previous spin_lock to
  426. * lock interrupts for us! We can only be called with
  427. * "siglock" held, and the local interrupt must
  428. * have been disabled when that got acquired!
  429. *
  430. * No need to set need_resched since signal event passing
  431. * goes through ->blocked
  432. */
  433. void signal_wake_up(struct task_struct *t, int resume)
  434. {
  435. unsigned int mask;
  436. set_tsk_thread_flag(t, TIF_SIGPENDING);
  437. /*
  438. * For SIGKILL, we want to wake it up in the stopped/traced/killable
  439. * case. We don't check t->state here because there is a race with it
  440. * executing another processor and just now entering stopped state.
  441. * By using wake_up_state, we ensure the process will wake up and
  442. * handle its death signal.
  443. */
  444. mask = TASK_INTERRUPTIBLE;
  445. if (resume)
  446. mask |= TASK_WAKEKILL;
  447. if (!wake_up_state(t, mask))
  448. kick_process(t);
  449. }
  450. /*
  451. * Remove signals in mask from the pending set and queue.
  452. * Returns 1 if any signals were found.
  453. *
  454. * All callers must be holding the siglock.
  455. *
  456. * This version takes a sigset mask and looks at all signals,
  457. * not just those in the first mask word.
  458. */
  459. static int rm_from_queue_full(sigset_t *mask, struct sigpending *s)
  460. {
  461. struct sigqueue *q, *n;
  462. sigset_t m;
  463. sigandsets(&m, mask, &s->signal);
  464. if (sigisemptyset(&m))
  465. return 0;
  466. signandsets(&s->signal, &s->signal, mask);
  467. list_for_each_entry_safe(q, n, &s->list, list) {
  468. if (sigismember(mask, q->info.si_signo)) {
  469. list_del_init(&q->list);
  470. __sigqueue_free(q);
  471. }
  472. }
  473. return 1;
  474. }
  475. /*
  476. * Remove signals in mask from the pending set and queue.
  477. * Returns 1 if any signals were found.
  478. *
  479. * All callers must be holding the siglock.
  480. */
  481. static int rm_from_queue(unsigned long mask, struct sigpending *s)
  482. {
  483. struct sigqueue *q, *n;
  484. if (!sigtestsetmask(&s->signal, mask))
  485. return 0;
  486. sigdelsetmask(&s->signal, mask);
  487. list_for_each_entry_safe(q, n, &s->list, list) {
  488. if (q->info.si_signo < SIGRTMIN &&
  489. (mask & sigmask(q->info.si_signo))) {
  490. list_del_init(&q->list);
  491. __sigqueue_free(q);
  492. }
  493. }
  494. return 1;
  495. }
  496. /*
  497. * Bad permissions for sending the signal
  498. * - the caller must hold at least the RCU read lock
  499. */
  500. static int check_kill_permission(int sig, struct siginfo *info,
  501. struct task_struct *t)
  502. {
  503. const struct cred *cred = current_cred(), *tcred;
  504. struct pid *sid;
  505. int error;
  506. if (!valid_signal(sig))
  507. return -EINVAL;
  508. if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
  509. return 0;
  510. error = audit_signal_info(sig, t); /* Let audit system see the signal */
  511. if (error)
  512. return error;
  513. tcred = __task_cred(t);
  514. if ((cred->euid ^ tcred->suid) &&
  515. (cred->euid ^ tcred->uid) &&
  516. (cred->uid ^ tcred->suid) &&
  517. (cred->uid ^ tcred->uid) &&
  518. !capable(CAP_KILL)) {
  519. switch (sig) {
  520. case SIGCONT:
  521. sid = task_session(t);
  522. /*
  523. * We don't return the error if sid == NULL. The
  524. * task was unhashed, the caller must notice this.
  525. */
  526. if (!sid || sid == task_session(current))
  527. break;
  528. default:
  529. return -EPERM;
  530. }
  531. }
  532. return security_task_kill(t, info, sig, 0);
  533. }
  534. /*
  535. * Handle magic process-wide effects of stop/continue signals. Unlike
  536. * the signal actions, these happen immediately at signal-generation
  537. * time regardless of blocking, ignoring, or handling. This does the
  538. * actual continuing for SIGCONT, but not the actual stopping for stop
  539. * signals. The process stop is done as a signal action for SIG_DFL.
  540. *
  541. * Returns true if the signal should be actually delivered, otherwise
  542. * it should be dropped.
  543. */
  544. static int prepare_signal(int sig, struct task_struct *p)
  545. {
  546. struct signal_struct *signal = p->signal;
  547. struct task_struct *t;
  548. if (unlikely(signal->flags & SIGNAL_GROUP_EXIT)) {
  549. /*
  550. * The process is in the middle of dying, nothing to do.
  551. */
  552. } else if (sig_kernel_stop(sig)) {
  553. /*
  554. * This is a stop signal. Remove SIGCONT from all queues.
  555. */
  556. rm_from_queue(sigmask(SIGCONT), &signal->shared_pending);
  557. t = p;
  558. do {
  559. rm_from_queue(sigmask(SIGCONT), &t->pending);
  560. } while_each_thread(p, t);
  561. } else if (sig == SIGCONT) {
  562. unsigned int why;
  563. /*
  564. * Remove all stop signals from all queues,
  565. * and wake all threads.
  566. */
  567. rm_from_queue(SIG_KERNEL_STOP_MASK, &signal->shared_pending);
  568. t = p;
  569. do {
  570. unsigned int state;
  571. rm_from_queue(SIG_KERNEL_STOP_MASK, &t->pending);
  572. /*
  573. * If there is a handler for SIGCONT, we must make
  574. * sure that no thread returns to user mode before
  575. * we post the signal, in case it was the only
  576. * thread eligible to run the signal handler--then
  577. * it must not do anything between resuming and
  578. * running the handler. With the TIF_SIGPENDING
  579. * flag set, the thread will pause and acquire the
  580. * siglock that we hold now and until we've queued
  581. * the pending signal.
  582. *
  583. * Wake up the stopped thread _after_ setting
  584. * TIF_SIGPENDING
  585. */
  586. state = __TASK_STOPPED;
  587. if (sig_user_defined(t, SIGCONT) && !sigismember(&t->blocked, SIGCONT)) {
  588. set_tsk_thread_flag(t, TIF_SIGPENDING);
  589. state |= TASK_INTERRUPTIBLE;
  590. }
  591. wake_up_state(t, state);
  592. } while_each_thread(p, t);
  593. /*
  594. * Notify the parent with CLD_CONTINUED if we were stopped.
  595. *
  596. * If we were in the middle of a group stop, we pretend it
  597. * was already finished, and then continued. Since SIGCHLD
  598. * doesn't queue we report only CLD_STOPPED, as if the next
  599. * CLD_CONTINUED was dropped.
  600. */
  601. why = 0;
  602. if (signal->flags & SIGNAL_STOP_STOPPED)
  603. why |= SIGNAL_CLD_CONTINUED;
  604. else if (signal->group_stop_count)
  605. why |= SIGNAL_CLD_STOPPED;
  606. if (why) {
  607. /*
  608. * The first thread which returns from finish_stop()
  609. * will take ->siglock, notice SIGNAL_CLD_MASK, and
  610. * notify its parent. See get_signal_to_deliver().
  611. */
  612. signal->flags = why | SIGNAL_STOP_CONTINUED;
  613. signal->group_stop_count = 0;
  614. signal->group_exit_code = 0;
  615. } else {
  616. /*
  617. * We are not stopped, but there could be a stop
  618. * signal in the middle of being processed after
  619. * being removed from the queue. Clear that too.
  620. */
  621. signal->flags &= ~SIGNAL_STOP_DEQUEUED;
  622. }
  623. }
  624. return !sig_ignored(p, sig);
  625. }
  626. /*
  627. * Test if P wants to take SIG. After we've checked all threads with this,
  628. * it's equivalent to finding no threads not blocking SIG. Any threads not
  629. * blocking SIG were ruled out because they are not running and already
  630. * have pending signals. Such threads will dequeue from the shared queue
  631. * as soon as they're available, so putting the signal on the shared queue
  632. * will be equivalent to sending it to one such thread.
  633. */
  634. static inline int wants_signal(int sig, struct task_struct *p)
  635. {
  636. if (sigismember(&p->blocked, sig))
  637. return 0;
  638. if (p->flags & PF_EXITING)
  639. return 0;
  640. if (sig == SIGKILL)
  641. return 1;
  642. if (task_is_stopped_or_traced(p))
  643. return 0;
  644. return task_curr(p) || !signal_pending(p);
  645. }
  646. static void complete_signal(int sig, struct task_struct *p, int group)
  647. {
  648. struct signal_struct *signal = p->signal;
  649. struct task_struct *t;
  650. /*
  651. * Now find a thread we can wake up to take the signal off the queue.
  652. *
  653. * If the main thread wants the signal, it gets first crack.
  654. * Probably the least surprising to the average bear.
  655. */
  656. if (wants_signal(sig, p))
  657. t = p;
  658. else if (!group || thread_group_empty(p))
  659. /*
  660. * There is just one thread and it does not need to be woken.
  661. * It will dequeue unblocked signals before it runs again.
  662. */
  663. return;
  664. else {
  665. /*
  666. * Otherwise try to find a suitable thread.
  667. */
  668. t = signal->curr_target;
  669. while (!wants_signal(sig, t)) {
  670. t = next_thread(t);
  671. if (t == signal->curr_target)
  672. /*
  673. * No thread needs to be woken.
  674. * Any eligible threads will see
  675. * the signal in the queue soon.
  676. */
  677. return;
  678. }
  679. signal->curr_target = t;
  680. }
  681. /*
  682. * Found a killable thread. If the signal will be fatal,
  683. * then start taking the whole group down immediately.
  684. */
  685. if (sig_fatal(p, sig) &&
  686. !(signal->flags & (SIGNAL_UNKILLABLE | SIGNAL_GROUP_EXIT)) &&
  687. !sigismember(&t->real_blocked, sig) &&
  688. (sig == SIGKILL ||
  689. !tracehook_consider_fatal_signal(t, sig, SIG_DFL))) {
  690. /*
  691. * This signal will be fatal to the whole group.
  692. */
  693. if (!sig_kernel_coredump(sig)) {
  694. /*
  695. * Start a group exit and wake everybody up.
  696. * This way we don't have other threads
  697. * running and doing things after a slower
  698. * thread has the fatal signal pending.
  699. */
  700. signal->flags = SIGNAL_GROUP_EXIT;
  701. signal->group_exit_code = sig;
  702. signal->group_stop_count = 0;
  703. t = p;
  704. do {
  705. sigaddset(&t->pending.signal, SIGKILL);
  706. signal_wake_up(t, 1);
  707. } while_each_thread(p, t);
  708. return;
  709. }
  710. }
  711. /*
  712. * The signal is already in the shared-pending queue.
  713. * Tell the chosen thread to wake up and dequeue it.
  714. */
  715. signal_wake_up(t, sig == SIGKILL);
  716. return;
  717. }
  718. static inline int legacy_queue(struct sigpending *signals, int sig)
  719. {
  720. return (sig < SIGRTMIN) && sigismember(&signals->signal, sig);
  721. }
  722. static int send_signal(int sig, struct siginfo *info, struct task_struct *t,
  723. int group)
  724. {
  725. struct sigpending *pending;
  726. struct sigqueue *q;
  727. trace_sched_signal_send(sig, t);
  728. assert_spin_locked(&t->sighand->siglock);
  729. if (!prepare_signal(sig, t))
  730. return 0;
  731. pending = group ? &t->signal->shared_pending : &t->pending;
  732. /*
  733. * Short-circuit ignored signals and support queuing
  734. * exactly one non-rt signal, so that we can get more
  735. * detailed information about the cause of the signal.
  736. */
  737. if (legacy_queue(pending, sig))
  738. return 0;
  739. /*
  740. * fast-pathed signals for kernel-internal things like SIGSTOP
  741. * or SIGKILL.
  742. */
  743. if (info == SEND_SIG_FORCED)
  744. goto out_set;
  745. /* Real-time signals must be queued if sent by sigqueue, or
  746. some other real-time mechanism. It is implementation
  747. defined whether kill() does so. We attempt to do so, on
  748. the principle of least surprise, but since kill is not
  749. allowed to fail with EAGAIN when low on memory we just
  750. make sure at least one signal gets delivered and don't
  751. pass on the info struct. */
  752. q = __sigqueue_alloc(t, GFP_ATOMIC, (sig < SIGRTMIN &&
  753. (is_si_special(info) ||
  754. info->si_code >= 0)));
  755. if (q) {
  756. list_add_tail(&q->list, &pending->list);
  757. switch ((unsigned long) info) {
  758. case (unsigned long) SEND_SIG_NOINFO:
  759. q->info.si_signo = sig;
  760. q->info.si_errno = 0;
  761. q->info.si_code = SI_USER;
  762. q->info.si_pid = task_tgid_nr_ns(current,
  763. task_active_pid_ns(t));
  764. q->info.si_uid = current_uid();
  765. break;
  766. case (unsigned long) SEND_SIG_PRIV:
  767. q->info.si_signo = sig;
  768. q->info.si_errno = 0;
  769. q->info.si_code = SI_KERNEL;
  770. q->info.si_pid = 0;
  771. q->info.si_uid = 0;
  772. break;
  773. default:
  774. copy_siginfo(&q->info, info);
  775. break;
  776. }
  777. } else if (!is_si_special(info)) {
  778. if (sig >= SIGRTMIN && info->si_code != SI_USER)
  779. /*
  780. * Queue overflow, abort. We may abort if the signal was rt
  781. * and sent by user using something other than kill().
  782. */
  783. return -EAGAIN;
  784. }
  785. out_set:
  786. signalfd_notify(t, sig);
  787. sigaddset(&pending->signal, sig);
  788. complete_signal(sig, t, group);
  789. return 0;
  790. }
  791. int print_fatal_signals;
  792. static void print_fatal_signal(struct pt_regs *regs, int signr)
  793. {
  794. printk("%s/%d: potentially unexpected fatal signal %d.\n",
  795. current->comm, task_pid_nr(current), signr);
  796. #if defined(__i386__) && !defined(__arch_um__)
  797. printk("code at %08lx: ", regs->ip);
  798. {
  799. int i;
  800. for (i = 0; i < 16; i++) {
  801. unsigned char insn;
  802. __get_user(insn, (unsigned char *)(regs->ip + i));
  803. printk("%02x ", insn);
  804. }
  805. }
  806. #endif
  807. printk("\n");
  808. show_regs(regs);
  809. }
  810. static int __init setup_print_fatal_signals(char *str)
  811. {
  812. get_option (&str, &print_fatal_signals);
  813. return 1;
  814. }
  815. __setup("print-fatal-signals=", setup_print_fatal_signals);
  816. int
  817. __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
  818. {
  819. return send_signal(sig, info, p, 1);
  820. }
  821. static int
  822. specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  823. {
  824. return send_signal(sig, info, t, 0);
  825. }
  826. /*
  827. * Force a signal that the process can't ignore: if necessary
  828. * we unblock the signal and change any SIG_IGN to SIG_DFL.
  829. *
  830. * Note: If we unblock the signal, we always reset it to SIG_DFL,
  831. * since we do not want to have a signal handler that was blocked
  832. * be invoked when user space had explicitly blocked it.
  833. *
  834. * We don't want to have recursive SIGSEGV's etc, for example,
  835. * that is why we also clear SIGNAL_UNKILLABLE.
  836. */
  837. int
  838. force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  839. {
  840. unsigned long int flags;
  841. int ret, blocked, ignored;
  842. struct k_sigaction *action;
  843. spin_lock_irqsave(&t->sighand->siglock, flags);
  844. action = &t->sighand->action[sig-1];
  845. ignored = action->sa.sa_handler == SIG_IGN;
  846. blocked = sigismember(&t->blocked, sig);
  847. if (blocked || ignored) {
  848. action->sa.sa_handler = SIG_DFL;
  849. if (blocked) {
  850. sigdelset(&t->blocked, sig);
  851. recalc_sigpending_and_wake(t);
  852. }
  853. }
  854. if (action->sa.sa_handler == SIG_DFL)
  855. t->signal->flags &= ~SIGNAL_UNKILLABLE;
  856. ret = specific_send_sig_info(sig, info, t);
  857. spin_unlock_irqrestore(&t->sighand->siglock, flags);
  858. return ret;
  859. }
  860. void
  861. force_sig_specific(int sig, struct task_struct *t)
  862. {
  863. force_sig_info(sig, SEND_SIG_FORCED, t);
  864. }
  865. /*
  866. * Nuke all other threads in the group.
  867. */
  868. void zap_other_threads(struct task_struct *p)
  869. {
  870. struct task_struct *t;
  871. p->signal->group_stop_count = 0;
  872. for (t = next_thread(p); t != p; t = next_thread(t)) {
  873. /*
  874. * Don't bother with already dead threads
  875. */
  876. if (t->exit_state)
  877. continue;
  878. /* SIGKILL will be handled before any pending SIGSTOP */
  879. sigaddset(&t->pending.signal, SIGKILL);
  880. signal_wake_up(t, 1);
  881. }
  882. }
  883. int __fatal_signal_pending(struct task_struct *tsk)
  884. {
  885. return sigismember(&tsk->pending.signal, SIGKILL);
  886. }
  887. EXPORT_SYMBOL(__fatal_signal_pending);
  888. struct sighand_struct *lock_task_sighand(struct task_struct *tsk, unsigned long *flags)
  889. {
  890. struct sighand_struct *sighand;
  891. rcu_read_lock();
  892. for (;;) {
  893. sighand = rcu_dereference(tsk->sighand);
  894. if (unlikely(sighand == NULL))
  895. break;
  896. spin_lock_irqsave(&sighand->siglock, *flags);
  897. if (likely(sighand == tsk->sighand))
  898. break;
  899. spin_unlock_irqrestore(&sighand->siglock, *flags);
  900. }
  901. rcu_read_unlock();
  902. return sighand;
  903. }
  904. /*
  905. * send signal info to all the members of a group
  906. * - the caller must hold the RCU read lock at least
  907. */
  908. int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
  909. {
  910. unsigned long flags;
  911. int ret;
  912. ret = check_kill_permission(sig, info, p);
  913. if (!ret && sig) {
  914. ret = -ESRCH;
  915. if (lock_task_sighand(p, &flags)) {
  916. ret = __group_send_sig_info(sig, info, p);
  917. unlock_task_sighand(p, &flags);
  918. }
  919. }
  920. return ret;
  921. }
  922. /*
  923. * __kill_pgrp_info() sends a signal to a process group: this is what the tty
  924. * control characters do (^C, ^Z etc)
  925. * - the caller must hold at least a readlock on tasklist_lock
  926. */
  927. int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp)
  928. {
  929. struct task_struct *p = NULL;
  930. int retval, success;
  931. success = 0;
  932. retval = -ESRCH;
  933. do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
  934. int err = group_send_sig_info(sig, info, p);
  935. success |= !err;
  936. retval = err;
  937. } while_each_pid_task(pgrp, PIDTYPE_PGID, p);
  938. return success ? 0 : retval;
  939. }
  940. int kill_pid_info(int sig, struct siginfo *info, struct pid *pid)
  941. {
  942. int error = -ESRCH;
  943. struct task_struct *p;
  944. rcu_read_lock();
  945. retry:
  946. p = pid_task(pid, PIDTYPE_PID);
  947. if (p) {
  948. error = group_send_sig_info(sig, info, p);
  949. if (unlikely(error == -ESRCH))
  950. /*
  951. * The task was unhashed in between, try again.
  952. * If it is dead, pid_task() will return NULL,
  953. * if we race with de_thread() it will find the
  954. * new leader.
  955. */
  956. goto retry;
  957. }
  958. rcu_read_unlock();
  959. return error;
  960. }
  961. int
  962. kill_proc_info(int sig, struct siginfo *info, pid_t pid)
  963. {
  964. int error;
  965. rcu_read_lock();
  966. error = kill_pid_info(sig, info, find_vpid(pid));
  967. rcu_read_unlock();
  968. return error;
  969. }
  970. /* like kill_pid_info(), but doesn't use uid/euid of "current" */
  971. int kill_pid_info_as_uid(int sig, struct siginfo *info, struct pid *pid,
  972. uid_t uid, uid_t euid, u32 secid)
  973. {
  974. int ret = -EINVAL;
  975. struct task_struct *p;
  976. const struct cred *pcred;
  977. if (!valid_signal(sig))
  978. return ret;
  979. read_lock(&tasklist_lock);
  980. p = pid_task(pid, PIDTYPE_PID);
  981. if (!p) {
  982. ret = -ESRCH;
  983. goto out_unlock;
  984. }
  985. pcred = __task_cred(p);
  986. if ((info == SEND_SIG_NOINFO ||
  987. (!is_si_special(info) && SI_FROMUSER(info))) &&
  988. euid != pcred->suid && euid != pcred->uid &&
  989. uid != pcred->suid && uid != pcred->uid) {
  990. ret = -EPERM;
  991. goto out_unlock;
  992. }
  993. ret = security_task_kill(p, info, sig, secid);
  994. if (ret)
  995. goto out_unlock;
  996. if (sig && p->sighand) {
  997. unsigned long flags;
  998. spin_lock_irqsave(&p->sighand->siglock, flags);
  999. ret = __group_send_sig_info(sig, info, p);
  1000. spin_unlock_irqrestore(&p->sighand->siglock, flags);
  1001. }
  1002. out_unlock:
  1003. read_unlock(&tasklist_lock);
  1004. return ret;
  1005. }
  1006. EXPORT_SYMBOL_GPL(kill_pid_info_as_uid);
  1007. /*
  1008. * kill_something_info() interprets pid in interesting ways just like kill(2).
  1009. *
  1010. * POSIX specifies that kill(-1,sig) is unspecified, but what we have
  1011. * is probably wrong. Should make it like BSD or SYSV.
  1012. */
  1013. static int kill_something_info(int sig, struct siginfo *info, pid_t pid)
  1014. {
  1015. int ret;
  1016. if (pid > 0) {
  1017. rcu_read_lock();
  1018. ret = kill_pid_info(sig, info, find_vpid(pid));
  1019. rcu_read_unlock();
  1020. return ret;
  1021. }
  1022. read_lock(&tasklist_lock);
  1023. if (pid != -1) {
  1024. ret = __kill_pgrp_info(sig, info,
  1025. pid ? find_vpid(-pid) : task_pgrp(current));
  1026. } else {
  1027. int retval = 0, count = 0;
  1028. struct task_struct * p;
  1029. for_each_process(p) {
  1030. if (task_pid_vnr(p) > 1 &&
  1031. !same_thread_group(p, current)) {
  1032. int err = group_send_sig_info(sig, info, p);
  1033. ++count;
  1034. if (err != -EPERM)
  1035. retval = err;
  1036. }
  1037. }
  1038. ret = count ? retval : -ESRCH;
  1039. }
  1040. read_unlock(&tasklist_lock);
  1041. return ret;
  1042. }
  1043. /*
  1044. * These are for backward compatibility with the rest of the kernel source.
  1045. */
  1046. /*
  1047. * The caller must ensure the task can't exit.
  1048. */
  1049. int
  1050. send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
  1051. {
  1052. int ret;
  1053. unsigned long flags;
  1054. /*
  1055. * Make sure legacy kernel users don't send in bad values
  1056. * (normal paths check this in check_kill_permission).
  1057. */
  1058. if (!valid_signal(sig))
  1059. return -EINVAL;
  1060. spin_lock_irqsave(&p->sighand->siglock, flags);
  1061. ret = specific_send_sig_info(sig, info, p);
  1062. spin_unlock_irqrestore(&p->sighand->siglock, flags);
  1063. return ret;
  1064. }
  1065. #define __si_special(priv) \
  1066. ((priv) ? SEND_SIG_PRIV : SEND_SIG_NOINFO)
  1067. int
  1068. send_sig(int sig, struct task_struct *p, int priv)
  1069. {
  1070. return send_sig_info(sig, __si_special(priv), p);
  1071. }
  1072. void
  1073. force_sig(int sig, struct task_struct *p)
  1074. {
  1075. force_sig_info(sig, SEND_SIG_PRIV, p);
  1076. }
  1077. /*
  1078. * When things go south during signal handling, we
  1079. * will force a SIGSEGV. And if the signal that caused
  1080. * the problem was already a SIGSEGV, we'll want to
  1081. * make sure we don't even try to deliver the signal..
  1082. */
  1083. int
  1084. force_sigsegv(int sig, struct task_struct *p)
  1085. {
  1086. if (sig == SIGSEGV) {
  1087. unsigned long flags;
  1088. spin_lock_irqsave(&p->sighand->siglock, flags);
  1089. p->sighand->action[sig - 1].sa.sa_handler = SIG_DFL;
  1090. spin_unlock_irqrestore(&p->sighand->siglock, flags);
  1091. }
  1092. force_sig(SIGSEGV, p);
  1093. return 0;
  1094. }
  1095. int kill_pgrp(struct pid *pid, int sig, int priv)
  1096. {
  1097. int ret;
  1098. read_lock(&tasklist_lock);
  1099. ret = __kill_pgrp_info(sig, __si_special(priv), pid);
  1100. read_unlock(&tasklist_lock);
  1101. return ret;
  1102. }
  1103. EXPORT_SYMBOL(kill_pgrp);
  1104. int kill_pid(struct pid *pid, int sig, int priv)
  1105. {
  1106. return kill_pid_info(sig, __si_special(priv), pid);
  1107. }
  1108. EXPORT_SYMBOL(kill_pid);
  1109. /*
  1110. * These functions support sending signals using preallocated sigqueue
  1111. * structures. This is needed "because realtime applications cannot
  1112. * afford to lose notifications of asynchronous events, like timer
  1113. * expirations or I/O completions". In the case of Posix Timers
  1114. * we allocate the sigqueue structure from the timer_create. If this
  1115. * allocation fails we are able to report the failure to the application
  1116. * with an EAGAIN error.
  1117. */
  1118. struct sigqueue *sigqueue_alloc(void)
  1119. {
  1120. struct sigqueue *q;
  1121. if ((q = __sigqueue_alloc(current, GFP_KERNEL, 0)))
  1122. q->flags |= SIGQUEUE_PREALLOC;
  1123. return(q);
  1124. }
  1125. void sigqueue_free(struct sigqueue *q)
  1126. {
  1127. unsigned long flags;
  1128. spinlock_t *lock = &current->sighand->siglock;
  1129. BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
  1130. /*
  1131. * We must hold ->siglock while testing q->list
  1132. * to serialize with collect_signal() or with
  1133. * __exit_signal()->flush_sigqueue().
  1134. */
  1135. spin_lock_irqsave(lock, flags);
  1136. q->flags &= ~SIGQUEUE_PREALLOC;
  1137. /*
  1138. * If it is queued it will be freed when dequeued,
  1139. * like the "regular" sigqueue.
  1140. */
  1141. if (!list_empty(&q->list))
  1142. q = NULL;
  1143. spin_unlock_irqrestore(lock, flags);
  1144. if (q)
  1145. __sigqueue_free(q);
  1146. }
  1147. int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group)
  1148. {
  1149. int sig = q->info.si_signo;
  1150. struct sigpending *pending;
  1151. unsigned long flags;
  1152. int ret;
  1153. BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
  1154. ret = -1;
  1155. if (!likely(lock_task_sighand(t, &flags)))
  1156. goto ret;
  1157. ret = 1; /* the signal is ignored */
  1158. if (!prepare_signal(sig, t))
  1159. goto out;
  1160. ret = 0;
  1161. if (unlikely(!list_empty(&q->list))) {
  1162. /*
  1163. * If an SI_TIMER entry is already queue just increment
  1164. * the overrun count.
  1165. */
  1166. BUG_ON(q->info.si_code != SI_TIMER);
  1167. q->info.si_overrun++;
  1168. goto out;
  1169. }
  1170. q->info.si_overrun = 0;
  1171. signalfd_notify(t, sig);
  1172. pending = group ? &t->signal->shared_pending : &t->pending;
  1173. list_add_tail(&q->list, &pending->list);
  1174. sigaddset(&pending->signal, sig);
  1175. complete_signal(sig, t, group);
  1176. out:
  1177. unlock_task_sighand(t, &flags);
  1178. ret:
  1179. return ret;
  1180. }
  1181. /*
  1182. * Wake up any threads in the parent blocked in wait* syscalls.
  1183. */
  1184. static inline void __wake_up_parent(struct task_struct *p,
  1185. struct task_struct *parent)
  1186. {
  1187. wake_up_interruptible_sync(&parent->signal->wait_chldexit);
  1188. }
  1189. /*
  1190. * Let a parent know about the death of a child.
  1191. * For a stopped/continued status change, use do_notify_parent_cldstop instead.
  1192. *
  1193. * Returns -1 if our parent ignored us and so we've switched to
  1194. * self-reaping, or else @sig.
  1195. */
  1196. int do_notify_parent(struct task_struct *tsk, int sig)
  1197. {
  1198. struct siginfo info;
  1199. unsigned long flags;
  1200. struct sighand_struct *psig;
  1201. struct task_cputime cputime;
  1202. int ret = sig;
  1203. BUG_ON(sig == -1);
  1204. /* do_notify_parent_cldstop should have been called instead. */
  1205. BUG_ON(task_is_stopped_or_traced(tsk));
  1206. BUG_ON(!tsk->ptrace &&
  1207. (tsk->group_leader != tsk || !thread_group_empty(tsk)));
  1208. info.si_signo = sig;
  1209. info.si_errno = 0;
  1210. /*
  1211. * we are under tasklist_lock here so our parent is tied to
  1212. * us and cannot exit and release its namespace.
  1213. *
  1214. * the only it can is to switch its nsproxy with sys_unshare,
  1215. * bu uncharing pid namespaces is not allowed, so we'll always
  1216. * see relevant namespace
  1217. *
  1218. * write_lock() currently calls preempt_disable() which is the
  1219. * same as rcu_read_lock(), but according to Oleg, this is not
  1220. * correct to rely on this
  1221. */
  1222. rcu_read_lock();
  1223. info.si_pid = task_pid_nr_ns(tsk, tsk->parent->nsproxy->pid_ns);
  1224. info.si_uid = __task_cred(tsk)->uid;
  1225. rcu_read_unlock();
  1226. thread_group_cputime(tsk, &cputime);
  1227. info.si_utime = cputime_to_jiffies(cputime.utime);
  1228. info.si_stime = cputime_to_jiffies(cputime.stime);
  1229. info.si_status = tsk->exit_code & 0x7f;
  1230. if (tsk->exit_code & 0x80)
  1231. info.si_code = CLD_DUMPED;
  1232. else if (tsk->exit_code & 0x7f)
  1233. info.si_code = CLD_KILLED;
  1234. else {
  1235. info.si_code = CLD_EXITED;
  1236. info.si_status = tsk->exit_code >> 8;
  1237. }
  1238. psig = tsk->parent->sighand;
  1239. spin_lock_irqsave(&psig->siglock, flags);
  1240. if (!tsk->ptrace && sig == SIGCHLD &&
  1241. (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN ||
  1242. (psig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT))) {
  1243. /*
  1244. * We are exiting and our parent doesn't care. POSIX.1
  1245. * defines special semantics for setting SIGCHLD to SIG_IGN
  1246. * or setting the SA_NOCLDWAIT flag: we should be reaped
  1247. * automatically and not left for our parent's wait4 call.
  1248. * Rather than having the parent do it as a magic kind of
  1249. * signal handler, we just set this to tell do_exit that we
  1250. * can be cleaned up without becoming a zombie. Note that
  1251. * we still call __wake_up_parent in this case, because a
  1252. * blocked sys_wait4 might now return -ECHILD.
  1253. *
  1254. * Whether we send SIGCHLD or not for SA_NOCLDWAIT
  1255. * is implementation-defined: we do (if you don't want
  1256. * it, just use SIG_IGN instead).
  1257. */
  1258. ret = tsk->exit_signal = -1;
  1259. if (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN)
  1260. sig = -1;
  1261. }
  1262. if (valid_signal(sig) && sig > 0)
  1263. __group_send_sig_info(sig, &info, tsk->parent);
  1264. __wake_up_parent(tsk, tsk->parent);
  1265. spin_unlock_irqrestore(&psig->siglock, flags);
  1266. return ret;
  1267. }
  1268. static void do_notify_parent_cldstop(struct task_struct *tsk, int why)
  1269. {
  1270. struct siginfo info;
  1271. unsigned long flags;
  1272. struct task_struct *parent;
  1273. struct sighand_struct *sighand;
  1274. if (tsk->ptrace & PT_PTRACED)
  1275. parent = tsk->parent;
  1276. else {
  1277. tsk = tsk->group_leader;
  1278. parent = tsk->real_parent;
  1279. }
  1280. info.si_signo = SIGCHLD;
  1281. info.si_errno = 0;
  1282. /*
  1283. * see comment in do_notify_parent() abot the following 3 lines
  1284. */
  1285. rcu_read_lock();
  1286. info.si_pid = task_pid_nr_ns(tsk, tsk->parent->nsproxy->pid_ns);
  1287. info.si_uid = __task_cred(tsk)->uid;
  1288. rcu_read_unlock();
  1289. info.si_utime = cputime_to_clock_t(tsk->utime);
  1290. info.si_stime = cputime_to_clock_t(tsk->stime);
  1291. info.si_code = why;
  1292. switch (why) {
  1293. case CLD_CONTINUED:
  1294. info.si_status = SIGCONT;
  1295. break;
  1296. case CLD_STOPPED:
  1297. info.si_status = tsk->signal->group_exit_code & 0x7f;
  1298. break;
  1299. case CLD_TRAPPED:
  1300. info.si_status = tsk->exit_code & 0x7f;
  1301. break;
  1302. default:
  1303. BUG();
  1304. }
  1305. sighand = parent->sighand;
  1306. spin_lock_irqsave(&sighand->siglock, flags);
  1307. if (sighand->action[SIGCHLD-1].sa.sa_handler != SIG_IGN &&
  1308. !(sighand->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDSTOP))
  1309. __group_send_sig_info(SIGCHLD, &info, parent);
  1310. /*
  1311. * Even if SIGCHLD is not generated, we must wake up wait4 calls.
  1312. */
  1313. __wake_up_parent(tsk, parent);
  1314. spin_unlock_irqrestore(&sighand->siglock, flags);
  1315. }
  1316. static inline int may_ptrace_stop(void)
  1317. {
  1318. if (!likely(current->ptrace & PT_PTRACED))
  1319. return 0;
  1320. /*
  1321. * Are we in the middle of do_coredump?
  1322. * If so and our tracer is also part of the coredump stopping
  1323. * is a deadlock situation, and pointless because our tracer
  1324. * is dead so don't allow us to stop.
  1325. * If SIGKILL was already sent before the caller unlocked
  1326. * ->siglock we must see ->core_state != NULL. Otherwise it
  1327. * is safe to enter schedule().
  1328. */
  1329. if (unlikely(current->mm->core_state) &&
  1330. unlikely(current->mm == current->parent->mm))
  1331. return 0;
  1332. return 1;
  1333. }
  1334. /*
  1335. * Return nonzero if there is a SIGKILL that should be waking us up.
  1336. * Called with the siglock held.
  1337. */
  1338. static int sigkill_pending(struct task_struct *tsk)
  1339. {
  1340. return sigismember(&tsk->pending.signal, SIGKILL) ||
  1341. sigismember(&tsk->signal->shared_pending.signal, SIGKILL);
  1342. }
  1343. /*
  1344. * This must be called with current->sighand->siglock held.
  1345. *
  1346. * This should be the path for all ptrace stops.
  1347. * We always set current->last_siginfo while stopped here.
  1348. * That makes it a way to test a stopped process for
  1349. * being ptrace-stopped vs being job-control-stopped.
  1350. *
  1351. * If we actually decide not to stop at all because the tracer
  1352. * is gone, we keep current->exit_code unless clear_code.
  1353. */
  1354. static void ptrace_stop(int exit_code, int clear_code, siginfo_t *info)
  1355. {
  1356. if (arch_ptrace_stop_needed(exit_code, info)) {
  1357. /*
  1358. * The arch code has something special to do before a
  1359. * ptrace stop. This is allowed to block, e.g. for faults
  1360. * on user stack pages. We can't keep the siglock while
  1361. * calling arch_ptrace_stop, so we must release it now.
  1362. * To preserve proper semantics, we must do this before
  1363. * any signal bookkeeping like checking group_stop_count.
  1364. * Meanwhile, a SIGKILL could come in before we retake the
  1365. * siglock. That must prevent us from sleeping in TASK_TRACED.
  1366. * So after regaining the lock, we must check for SIGKILL.
  1367. */
  1368. spin_unlock_irq(&current->sighand->siglock);
  1369. arch_ptrace_stop(exit_code, info);
  1370. spin_lock_irq(&current->sighand->siglock);
  1371. if (sigkill_pending(current))
  1372. return;
  1373. }
  1374. /*
  1375. * If there is a group stop in progress,
  1376. * we must participate in the bookkeeping.
  1377. */
  1378. if (current->signal->group_stop_count > 0)
  1379. --current->signal->group_stop_count;
  1380. current->last_siginfo = info;
  1381. current->exit_code = exit_code;
  1382. /* Let the debugger run. */
  1383. __set_current_state(TASK_TRACED);
  1384. spin_unlock_irq(&current->sighand->siglock);
  1385. read_lock(&tasklist_lock);
  1386. if (may_ptrace_stop()) {
  1387. do_notify_parent_cldstop(current, CLD_TRAPPED);
  1388. read_unlock(&tasklist_lock);
  1389. schedule();
  1390. } else {
  1391. /*
  1392. * By the time we got the lock, our tracer went away.
  1393. * Don't drop the lock yet, another tracer may come.
  1394. */
  1395. __set_current_state(TASK_RUNNING);
  1396. if (clear_code)
  1397. current->exit_code = 0;
  1398. read_unlock(&tasklist_lock);
  1399. }
  1400. /*
  1401. * While in TASK_TRACED, we were considered "frozen enough".
  1402. * Now that we woke up, it's crucial if we're supposed to be
  1403. * frozen that we freeze now before running anything substantial.
  1404. */
  1405. try_to_freeze();
  1406. /*
  1407. * We are back. Now reacquire the siglock before touching
  1408. * last_siginfo, so that we are sure to have synchronized with
  1409. * any signal-sending on another CPU that wants to examine it.
  1410. */
  1411. spin_lock_irq(&current->sighand->siglock);
  1412. current->last_siginfo = NULL;
  1413. /*
  1414. * Queued signals ignored us while we were stopped for tracing.
  1415. * So check for any that we should take before resuming user mode.
  1416. * This sets TIF_SIGPENDING, but never clears it.
  1417. */
  1418. recalc_sigpending_tsk(current);
  1419. }
  1420. void ptrace_notify(int exit_code)
  1421. {
  1422. siginfo_t info;
  1423. BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
  1424. memset(&info, 0, sizeof info);
  1425. info.si_signo = SIGTRAP;
  1426. info.si_code = exit_code;
  1427. info.si_pid = task_pid_vnr(current);
  1428. info.si_uid = current_uid();
  1429. /* Let the debugger run. */
  1430. spin_lock_irq(&current->sighand->siglock);
  1431. ptrace_stop(exit_code, 1, &info);
  1432. spin_unlock_irq(&current->sighand->siglock);
  1433. }
  1434. static void
  1435. finish_stop(int stop_count)
  1436. {
  1437. /*
  1438. * If there are no other threads in the group, or if there is
  1439. * a group stop in progress and we are the last to stop,
  1440. * report to the parent. When ptraced, every thread reports itself.
  1441. */
  1442. if (tracehook_notify_jctl(stop_count == 0, CLD_STOPPED)) {
  1443. read_lock(&tasklist_lock);
  1444. do_notify_parent_cldstop(current, CLD_STOPPED);
  1445. read_unlock(&tasklist_lock);
  1446. }
  1447. do {
  1448. schedule();
  1449. } while (try_to_freeze());
  1450. /*
  1451. * Now we don't run again until continued.
  1452. */
  1453. current->exit_code = 0;
  1454. }
  1455. /*
  1456. * This performs the stopping for SIGSTOP and other stop signals.
  1457. * We have to stop all threads in the thread group.
  1458. * Returns nonzero if we've actually stopped and released the siglock.
  1459. * Returns zero if we didn't stop and still hold the siglock.
  1460. */
  1461. static int do_signal_stop(int signr)
  1462. {
  1463. struct signal_struct *sig = current->signal;
  1464. int stop_count;
  1465. if (sig->group_stop_count > 0) {
  1466. /*
  1467. * There is a group stop in progress. We don't need to
  1468. * start another one.
  1469. */
  1470. stop_count = --sig->group_stop_count;
  1471. } else {
  1472. struct task_struct *t;
  1473. if (!likely(sig->flags & SIGNAL_STOP_DEQUEUED) ||
  1474. unlikely(signal_group_exit(sig)))
  1475. return 0;
  1476. /*
  1477. * There is no group stop already in progress.
  1478. * We must initiate one now.
  1479. */
  1480. sig->group_exit_code = signr;
  1481. stop_count = 0;
  1482. for (t = next_thread(current); t != current; t = next_thread(t))
  1483. /*
  1484. * Setting state to TASK_STOPPED for a group
  1485. * stop is always done with the siglock held,
  1486. * so this check has no races.
  1487. */
  1488. if (!(t->flags & PF_EXITING) &&
  1489. !task_is_stopped_or_traced(t)) {
  1490. stop_count++;
  1491. signal_wake_up(t, 0);
  1492. }
  1493. sig->group_stop_count = stop_count;
  1494. }
  1495. if (stop_count == 0)
  1496. sig->flags = SIGNAL_STOP_STOPPED;
  1497. current->exit_code = sig->group_exit_code;
  1498. __set_current_state(TASK_STOPPED);
  1499. spin_unlock_irq(&current->sighand->siglock);
  1500. finish_stop(stop_count);
  1501. return 1;
  1502. }
  1503. static int ptrace_signal(int signr, siginfo_t *info,
  1504. struct pt_regs *regs, void *cookie)
  1505. {
  1506. if (!(current->ptrace & PT_PTRACED))
  1507. return signr;
  1508. ptrace_signal_deliver(regs, cookie);
  1509. /* Let the debugger run. */
  1510. ptrace_stop(signr, 0, info);
  1511. /* We're back. Did the debugger cancel the sig? */
  1512. signr = current->exit_code;
  1513. if (signr == 0)
  1514. return signr;
  1515. current->exit_code = 0;
  1516. /* Update the siginfo structure if the signal has
  1517. changed. If the debugger wanted something
  1518. specific in the siginfo structure then it should
  1519. have updated *info via PTRACE_SETSIGINFO. */
  1520. if (signr != info->si_signo) {
  1521. info->si_signo = signr;
  1522. info->si_errno = 0;
  1523. info->si_code = SI_USER;
  1524. info->si_pid = task_pid_vnr(current->parent);
  1525. info->si_uid = task_uid(current->parent);
  1526. }
  1527. /* If the (new) signal is now blocked, requeue it. */
  1528. if (sigismember(&current->blocked, signr)) {
  1529. specific_send_sig_info(signr, info, current);
  1530. signr = 0;
  1531. }
  1532. return signr;
  1533. }
  1534. int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka,
  1535. struct pt_regs *regs, void *cookie)
  1536. {
  1537. struct sighand_struct *sighand = current->sighand;
  1538. struct signal_struct *signal = current->signal;
  1539. int signr;
  1540. relock:
  1541. /*
  1542. * We'll jump back here after any time we were stopped in TASK_STOPPED.
  1543. * While in TASK_STOPPED, we were considered "frozen enough".
  1544. * Now that we woke up, it's crucial if we're supposed to be
  1545. * frozen that we freeze now before running anything substantial.
  1546. */
  1547. try_to_freeze();
  1548. spin_lock_irq(&sighand->siglock);
  1549. /*
  1550. * Every stopped thread goes here after wakeup. Check to see if
  1551. * we should notify the parent, prepare_signal(SIGCONT) encodes
  1552. * the CLD_ si_code into SIGNAL_CLD_MASK bits.
  1553. */
  1554. if (unlikely(signal->flags & SIGNAL_CLD_MASK)) {
  1555. int why = (signal->flags & SIGNAL_STOP_CONTINUED)
  1556. ? CLD_CONTINUED : CLD_STOPPED;
  1557. signal->flags &= ~SIGNAL_CLD_MASK;
  1558. spin_unlock_irq(&sighand->siglock);
  1559. if (unlikely(!tracehook_notify_jctl(1, why)))
  1560. goto relock;
  1561. read_lock(&tasklist_lock);
  1562. do_notify_parent_cldstop(current->group_leader, why);
  1563. read_unlock(&tasklist_lock);
  1564. goto relock;
  1565. }
  1566. for (;;) {
  1567. struct k_sigaction *ka;
  1568. if (unlikely(signal->group_stop_count > 0) &&
  1569. do_signal_stop(0))
  1570. goto relock;
  1571. /*
  1572. * Tracing can induce an artifical signal and choose sigaction.
  1573. * The return value in @signr determines the default action,
  1574. * but @info->si_signo is the signal number we will report.
  1575. */
  1576. signr = tracehook_get_signal(current, regs, info, return_ka);
  1577. if (unlikely(signr < 0))
  1578. goto relock;
  1579. if (unlikely(signr != 0))
  1580. ka = return_ka;
  1581. else {
  1582. signr = dequeue_signal(current, &current->blocked,
  1583. info);
  1584. if (!signr)
  1585. break; /* will return 0 */
  1586. if (signr != SIGKILL) {
  1587. signr = ptrace_signal(signr, info,
  1588. regs, cookie);
  1589. if (!signr)
  1590. continue;
  1591. }
  1592. ka = &sighand->action[signr-1];
  1593. }
  1594. if (ka->sa.sa_handler == SIG_IGN) /* Do nothing. */
  1595. continue;
  1596. if (ka->sa.sa_handler != SIG_DFL) {
  1597. /* Run the handler. */
  1598. *return_ka = *ka;
  1599. if (ka->sa.sa_flags & SA_ONESHOT)
  1600. ka->sa.sa_handler = SIG_DFL;
  1601. break; /* will return non-zero "signr" value */
  1602. }
  1603. /*
  1604. * Now we are doing the default action for this signal.
  1605. */
  1606. if (sig_kernel_ignore(signr)) /* Default is nothing. */
  1607. continue;
  1608. /*
  1609. * Global init gets no signals it doesn't want.
  1610. */
  1611. if (unlikely(signal->flags & SIGNAL_UNKILLABLE) &&
  1612. !signal_group_exit(signal))
  1613. continue;
  1614. if (sig_kernel_stop(signr)) {
  1615. /*
  1616. * The default action is to stop all threads in
  1617. * the thread group. The job control signals
  1618. * do nothing in an orphaned pgrp, but SIGSTOP
  1619. * always works. Note that siglock needs to be
  1620. * dropped during the call to is_orphaned_pgrp()
  1621. * because of lock ordering with tasklist_lock.
  1622. * This allows an intervening SIGCONT to be posted.
  1623. * We need to check for that and bail out if necessary.
  1624. */
  1625. if (signr != SIGSTOP) {
  1626. spin_unlock_irq(&sighand->siglock);
  1627. /* signals can be posted during this window */
  1628. if (is_current_pgrp_orphaned())
  1629. goto relock;
  1630. spin_lock_irq(&sighand->siglock);
  1631. }
  1632. if (likely(do_signal_stop(info->si_signo))) {
  1633. /* It released the siglock. */
  1634. goto relock;
  1635. }
  1636. /*
  1637. * We didn't actually stop, due to a race
  1638. * with SIGCONT or something like that.
  1639. */
  1640. continue;
  1641. }
  1642. spin_unlock_irq(&sighand->siglock);
  1643. /*
  1644. * Anything else is fatal, maybe with a core dump.
  1645. */
  1646. current->flags |= PF_SIGNALED;
  1647. if (sig_kernel_coredump(signr)) {
  1648. if (print_fatal_signals)
  1649. print_fatal_signal(regs, info->si_signo);
  1650. /*
  1651. * If it was able to dump core, this kills all
  1652. * other threads in the group and synchronizes with
  1653. * their demise. If we lost the race with another
  1654. * thread getting here, it set group_exit_code
  1655. * first and our do_group_exit call below will use
  1656. * that value and ignore the one we pass it.
  1657. */
  1658. do_coredump(info->si_signo, info->si_signo, regs);
  1659. }
  1660. /*
  1661. * Death signals, no core dump.
  1662. */
  1663. do_group_exit(info->si_signo);
  1664. /* NOTREACHED */
  1665. }
  1666. spin_unlock_irq(&sighand->siglock);
  1667. return signr;
  1668. }
  1669. void exit_signals(struct task_struct *tsk)
  1670. {
  1671. int group_stop = 0;
  1672. struct task_struct *t;
  1673. if (thread_group_empty(tsk) || signal_group_exit(tsk->signal)) {
  1674. tsk->flags |= PF_EXITING;
  1675. return;
  1676. }
  1677. spin_lock_irq(&tsk->sighand->siglock);
  1678. /*
  1679. * From now this task is not visible for group-wide signals,
  1680. * see wants_signal(), do_signal_stop().
  1681. */
  1682. tsk->flags |= PF_EXITING;
  1683. if (!signal_pending(tsk))
  1684. goto out;
  1685. /* It could be that __group_complete_signal() choose us to
  1686. * notify about group-wide signal. Another thread should be
  1687. * woken now to take the signal since we will not.
  1688. */
  1689. for (t = tsk; (t = next_thread(t)) != tsk; )
  1690. if (!signal_pending(t) && !(t->flags & PF_EXITING))
  1691. recalc_sigpending_and_wake(t);
  1692. if (unlikely(tsk->signal->group_stop_count) &&
  1693. !--tsk->signal->group_stop_count) {
  1694. tsk->signal->flags = SIGNAL_STOP_STOPPED;
  1695. group_stop = 1;
  1696. }
  1697. out:
  1698. spin_unlock_irq(&tsk->sighand->siglock);
  1699. if (unlikely(group_stop) && tracehook_notify_jctl(1, CLD_STOPPED)) {
  1700. read_lock(&tasklist_lock);
  1701. do_notify_parent_cldstop(tsk, CLD_STOPPED);
  1702. read_unlock(&tasklist_lock);
  1703. }
  1704. }
  1705. EXPORT_SYMBOL(recalc_sigpending);
  1706. EXPORT_SYMBOL_GPL(dequeue_signal);
  1707. EXPORT_SYMBOL(flush_signals);
  1708. EXPORT_SYMBOL(force_sig);
  1709. EXPORT_SYMBOL(send_sig);
  1710. EXPORT_SYMBOL(send_sig_info);
  1711. EXPORT_SYMBOL(sigprocmask);
  1712. EXPORT_SYMBOL(block_all_signals);
  1713. EXPORT_SYMBOL(unblock_all_signals);
  1714. /*
  1715. * System call entry points.
  1716. */
  1717. asmlinkage long sys_restart_syscall(void)
  1718. {
  1719. struct restart_block *restart = &current_thread_info()->restart_block;
  1720. return restart->fn(restart);
  1721. }
  1722. long do_no_restart_syscall(struct restart_block *param)
  1723. {
  1724. return -EINTR;
  1725. }
  1726. /*
  1727. * We don't need to get the kernel lock - this is all local to this
  1728. * particular thread.. (and that's good, because this is _heavily_
  1729. * used by various programs)
  1730. */
  1731. /*
  1732. * This is also useful for kernel threads that want to temporarily
  1733. * (or permanently) block certain signals.
  1734. *
  1735. * NOTE! Unlike the user-mode sys_sigprocmask(), the kernel
  1736. * interface happily blocks "unblockable" signals like SIGKILL
  1737. * and friends.
  1738. */
  1739. int sigprocmask(int how, sigset_t *set, sigset_t *oldset)
  1740. {
  1741. int error;
  1742. spin_lock_irq(&current->sighand->siglock);
  1743. if (oldset)
  1744. *oldset = current->blocked;
  1745. error = 0;
  1746. switch (how) {
  1747. case SIG_BLOCK:
  1748. sigorsets(&current->blocked, &current->blocked, set);
  1749. break;
  1750. case SIG_UNBLOCK:
  1751. signandsets(&current->blocked, &current->blocked, set);
  1752. break;
  1753. case SIG_SETMASK:
  1754. current->blocked = *set;
  1755. break;
  1756. default:
  1757. error = -EINVAL;
  1758. }
  1759. recalc_sigpending();
  1760. spin_unlock_irq(&current->sighand->siglock);
  1761. return error;
  1762. }
  1763. asmlinkage long
  1764. sys_rt_sigprocmask(int how, sigset_t __user *set, sigset_t __user *oset, size_t sigsetsize)
  1765. {
  1766. int error = -EINVAL;
  1767. sigset_t old_set, new_set;
  1768. /* XXX: Don't preclude handling different sized sigset_t's. */
  1769. if (sigsetsize != sizeof(sigset_t))
  1770. goto out;
  1771. if (set) {
  1772. error = -EFAULT;
  1773. if (copy_from_user(&new_set, set, sizeof(*set)))
  1774. goto out;
  1775. sigdelsetmask(&new_set, sigmask(SIGKILL)|sigmask(SIGSTOP));
  1776. error = sigprocmask(how, &new_set, &old_set);
  1777. if (error)
  1778. goto out;
  1779. if (oset)
  1780. goto set_old;
  1781. } else if (oset) {
  1782. spin_lock_irq(&current->sighand->siglock);
  1783. old_set = current->blocked;
  1784. spin_unlock_irq(&current->sighand->siglock);
  1785. set_old:
  1786. error = -EFAULT;
  1787. if (copy_to_user(oset, &old_set, sizeof(*oset)))
  1788. goto out;
  1789. }
  1790. error = 0;
  1791. out:
  1792. return error;
  1793. }
  1794. long do_sigpending(void __user *set, unsigned long sigsetsize)
  1795. {
  1796. long error = -EINVAL;
  1797. sigset_t pending;
  1798. if (sigsetsize > sizeof(sigset_t))
  1799. goto out;
  1800. spin_lock_irq(&current->sighand->siglock);
  1801. sigorsets(&pending, &current->pending.signal,
  1802. &current->signal->shared_pending.signal);
  1803. spin_unlock_irq(&current->sighand->siglock);
  1804. /* Outside the lock because only this thread touches it. */
  1805. sigandsets(&pending, &current->blocked, &pending);
  1806. error = -EFAULT;
  1807. if (!copy_to_user(set, &pending, sigsetsize))
  1808. error = 0;
  1809. out:
  1810. return error;
  1811. }
  1812. asmlinkage long
  1813. sys_rt_sigpending(sigset_t __user *set, size_t sigsetsize)
  1814. {
  1815. return do_sigpending(set, sigsetsize);
  1816. }
  1817. #ifndef HAVE_ARCH_COPY_SIGINFO_TO_USER
  1818. int copy_siginfo_to_user(siginfo_t __user *to, siginfo_t *from)
  1819. {
  1820. int err;
  1821. if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t)))
  1822. return -EFAULT;
  1823. if (from->si_code < 0)
  1824. return __copy_to_user(to, from, sizeof(siginfo_t))
  1825. ? -EFAULT : 0;
  1826. /*
  1827. * If you change siginfo_t structure, please be sure
  1828. * this code is fixed accordingly.
  1829. * Please remember to update the signalfd_copyinfo() function
  1830. * inside fs/signalfd.c too, in case siginfo_t changes.
  1831. * It should never copy any pad contained in the structure
  1832. * to avoid security leaks, but must copy the generic
  1833. * 3 ints plus the relevant union member.
  1834. */
  1835. err = __put_user(from->si_signo, &to->si_signo);
  1836. err |= __put_user(from->si_errno, &to->si_errno);
  1837. err |= __put_user((short)from->si_code, &to->si_code);
  1838. switch (from->si_code & __SI_MASK) {
  1839. case __SI_KILL:
  1840. err |= __put_user(from->si_pid, &to->si_pid);
  1841. err |= __put_user(from->si_uid, &to->si_uid);
  1842. break;
  1843. case __SI_TIMER:
  1844. err |= __put_user(from->si_tid, &to->si_tid);
  1845. err |= __put_user(from->si_overrun, &to->si_overrun);
  1846. err |= __put_user(from->si_ptr, &to->si_ptr);
  1847. break;
  1848. case __SI_POLL:
  1849. err |= __put_user(from->si_band, &to->si_band);
  1850. err |= __put_user(from->si_fd, &to->si_fd);
  1851. break;
  1852. case __SI_FAULT:
  1853. err |= __put_user(from->si_addr, &to->si_addr);
  1854. #ifdef __ARCH_SI_TRAPNO
  1855. err |= __put_user(from->si_trapno, &to->si_trapno);
  1856. #endif
  1857. break;
  1858. case __SI_CHLD:
  1859. err |= __put_user(from->si_pid, &to->si_pid);
  1860. err |= __put_user(from->si_uid, &to->si_uid);
  1861. err |= __put_user(from->si_status, &to->si_status);
  1862. err |= __put_user(from->si_utime, &to->si_utime);
  1863. err |= __put_user(from->si_stime, &to->si_stime);
  1864. break;
  1865. case __SI_RT: /* This is not generated by the kernel as of now. */
  1866. case __SI_MESGQ: /* But this is */
  1867. err |= __put_user(from->si_pid, &to->si_pid);
  1868. err |= __put_user(from->si_uid, &to->si_uid);
  1869. err |= __put_user(from->si_ptr, &to->si_ptr);
  1870. break;
  1871. default: /* this is just in case for now ... */
  1872. err |= __put_user(from->si_pid, &to->si_pid);
  1873. err |= __put_user(from->si_uid, &to->si_uid);
  1874. break;
  1875. }
  1876. return err;
  1877. }
  1878. #endif
  1879. asmlinkage long
  1880. sys_rt_sigtimedwait(const sigset_t __user *uthese,
  1881. siginfo_t __user *uinfo,
  1882. const struct timespec __user *uts,
  1883. size_t sigsetsize)
  1884. {
  1885. int ret, sig;
  1886. sigset_t these;
  1887. struct timespec ts;
  1888. siginfo_t info;
  1889. long timeout = 0;
  1890. /* XXX: Don't preclude handling different sized sigset_t's. */
  1891. if (sigsetsize != sizeof(sigset_t))
  1892. return -EINVAL;
  1893. if (copy_from_user(&these, uthese, sizeof(these)))
  1894. return -EFAULT;
  1895. /*
  1896. * Invert the set of allowed signals to get those we
  1897. * want to block.
  1898. */
  1899. sigdelsetmask(&these, sigmask(SIGKILL)|sigmask(SIGSTOP));
  1900. signotset(&these);
  1901. if (uts) {
  1902. if (copy_from_user(&ts, uts, sizeof(ts)))
  1903. return -EFAULT;
  1904. if (ts.tv_nsec >= 1000000000L || ts.tv_nsec < 0
  1905. || ts.tv_sec < 0)
  1906. return -EINVAL;
  1907. }
  1908. spin_lock_irq(&current->sighand->siglock);
  1909. sig = dequeue_signal(current, &these, &info);
  1910. if (!sig) {
  1911. timeout = MAX_SCHEDULE_TIMEOUT;
  1912. if (uts)
  1913. timeout = (timespec_to_jiffies(&ts)
  1914. + (ts.tv_sec || ts.tv_nsec));
  1915. if (timeout) {
  1916. /* None ready -- temporarily unblock those we're
  1917. * interested while we are sleeping in so that we'll
  1918. * be awakened when they arrive. */
  1919. current->real_blocked = current->blocked;
  1920. sigandsets(&current->blocked, &current->blocked, &these);
  1921. recalc_sigpending();
  1922. spin_unlock_irq(&current->sighand->siglock);
  1923. timeout = schedule_timeout_interruptible(timeout);
  1924. spin_lock_irq(&current->sighand->siglock);
  1925. sig = dequeue_signal(current, &these, &info);
  1926. current->blocked = current->real_blocked;
  1927. siginitset(&current->real_blocked, 0);
  1928. recalc_sigpending();
  1929. }
  1930. }
  1931. spin_unlock_irq(&current->sighand->siglock);
  1932. if (sig) {
  1933. ret = sig;
  1934. if (uinfo) {
  1935. if (copy_siginfo_to_user(uinfo, &info))
  1936. ret = -EFAULT;
  1937. }
  1938. } else {
  1939. ret = -EAGAIN;
  1940. if (timeout)
  1941. ret = -EINTR;
  1942. }
  1943. return ret;
  1944. }
  1945. asmlinkage long
  1946. sys_kill(pid_t pid, int sig)
  1947. {
  1948. struct siginfo info;
  1949. info.si_signo = sig;
  1950. info.si_errno = 0;
  1951. info.si_code = SI_USER;
  1952. info.si_pid = task_tgid_vnr(current);
  1953. info.si_uid = current_uid();
  1954. return kill_something_info(sig, &info, pid);
  1955. }
  1956. static int do_tkill(pid_t tgid, pid_t pid, int sig)
  1957. {
  1958. int error;
  1959. struct siginfo info;
  1960. struct task_struct *p;
  1961. unsigned long flags;
  1962. error = -ESRCH;
  1963. info.si_signo = sig;
  1964. info.si_errno = 0;
  1965. info.si_code = SI_TKILL;
  1966. info.si_pid = task_tgid_vnr(current);
  1967. info.si_uid = current_uid();
  1968. rcu_read_lock();
  1969. p = find_task_by_vpid(pid);
  1970. if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
  1971. error = check_kill_permission(sig, &info, p);
  1972. /*
  1973. * The null signal is a permissions and process existence
  1974. * probe. No signal is actually delivered.
  1975. *
  1976. * If lock_task_sighand() fails we pretend the task dies
  1977. * after receiving the signal. The window is tiny, and the
  1978. * signal is private anyway.
  1979. */
  1980. if (!error && sig && lock_task_sighand(p, &flags)) {
  1981. error = specific_send_sig_info(sig, &info, p);
  1982. unlock_task_sighand(p, &flags);
  1983. }
  1984. }
  1985. rcu_read_unlock();
  1986. return error;
  1987. }
  1988. /**
  1989. * sys_tgkill - send signal to one specific thread
  1990. * @tgid: the thread group ID of the thread
  1991. * @pid: the PID of the thread
  1992. * @sig: signal to be sent
  1993. *
  1994. * This syscall also checks the @tgid and returns -ESRCH even if the PID
  1995. * exists but it's not belonging to the target process anymore. This
  1996. * method solves the problem of threads exiting and PIDs getting reused.
  1997. */
  1998. asmlinkage long sys_tgkill(pid_t tgid, pid_t pid, int sig)
  1999. {
  2000. /* This is only valid for single tasks */
  2001. if (pid <= 0 || tgid <= 0)
  2002. return -EINVAL;
  2003. return do_tkill(tgid, pid, sig);
  2004. }
  2005. /*
  2006. * Send a signal to only one task, even if it's a CLONE_THREAD task.
  2007. */
  2008. asmlinkage long
  2009. sys_tkill(pid_t pid, int sig)
  2010. {
  2011. /* This is only valid for single tasks */
  2012. if (pid <= 0)
  2013. return -EINVAL;
  2014. return do_tkill(0, pid, sig);
  2015. }
  2016. asmlinkage long
  2017. sys_rt_sigqueueinfo(pid_t pid, int sig, siginfo_t __user *uinfo)
  2018. {
  2019. siginfo_t info;
  2020. if (copy_from_user(&info, uinfo, sizeof(siginfo_t)))
  2021. return -EFAULT;
  2022. /* Not even root can pretend to send signals from the kernel.
  2023. Nor can they impersonate a kill(), which adds source info. */
  2024. if (info.si_code >= 0)
  2025. return -EPERM;
  2026. info.si_signo = sig;
  2027. /* POSIX.1b doesn't mention process groups. */
  2028. return kill_proc_info(sig, &info, pid);
  2029. }
  2030. int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact)
  2031. {
  2032. struct task_struct *t = current;
  2033. struct k_sigaction *k;
  2034. sigset_t mask;
  2035. if (!valid_signal(sig) || sig < 1 || (act && sig_kernel_only(sig)))
  2036. return -EINVAL;
  2037. k = &t->sighand->action[sig-1];
  2038. spin_lock_irq(&current->sighand->siglock);
  2039. if (oact)
  2040. *oact = *k;
  2041. if (act) {
  2042. sigdelsetmask(&act->sa.sa_mask,
  2043. sigmask(SIGKILL) | sigmask(SIGSTOP));
  2044. *k = *act;
  2045. /*
  2046. * POSIX 3.3.1.3:
  2047. * "Setting a signal action to SIG_IGN for a signal that is
  2048. * pending shall cause the pending signal to be discarded,
  2049. * whether or not it is blocked."
  2050. *
  2051. * "Setting a signal action to SIG_DFL for a signal that is
  2052. * pending and whose default action is to ignore the signal
  2053. * (for example, SIGCHLD), shall cause the pending signal to
  2054. * be discarded, whether or not it is blocked"
  2055. */
  2056. if (sig_handler_ignored(sig_handler(t, sig), sig)) {
  2057. sigemptyset(&mask);
  2058. sigaddset(&mask, sig);
  2059. rm_from_queue_full(&mask, &t->signal->shared_pending);
  2060. do {
  2061. rm_from_queue_full(&mask, &t->pending);
  2062. t = next_thread(t);
  2063. } while (t != current);
  2064. }
  2065. }
  2066. spin_unlock_irq(&current->sighand->siglock);
  2067. return 0;
  2068. }
  2069. int
  2070. do_sigaltstack (const stack_t __user *uss, stack_t __user *uoss, unsigned long sp)
  2071. {
  2072. stack_t oss;
  2073. int error;
  2074. if (uoss) {
  2075. oss.ss_sp = (void __user *) current->sas_ss_sp;
  2076. oss.ss_size = current->sas_ss_size;
  2077. oss.ss_flags = sas_ss_flags(sp);
  2078. }
  2079. if (uss) {
  2080. void __user *ss_sp;
  2081. size_t ss_size;
  2082. int ss_flags;
  2083. error = -EFAULT;
  2084. if (!access_ok(VERIFY_READ, uss, sizeof(*uss))
  2085. || __get_user(ss_sp, &uss->ss_sp)
  2086. || __get_user(ss_flags, &uss->ss_flags)
  2087. || __get_user(ss_size, &uss->ss_size))
  2088. goto out;
  2089. error = -EPERM;
  2090. if (on_sig_stack(sp))
  2091. goto out;
  2092. error = -EINVAL;
  2093. /*
  2094. *
  2095. * Note - this code used to test ss_flags incorrectly
  2096. * old code may have been written using ss_flags==0
  2097. * to mean ss_flags==SS_ONSTACK (as this was the only
  2098. * way that worked) - this fix preserves that older
  2099. * mechanism
  2100. */
  2101. if (ss_flags != SS_DISABLE && ss_flags != SS_ONSTACK && ss_flags != 0)
  2102. goto out;
  2103. if (ss_flags == SS_DISABLE) {
  2104. ss_size = 0;
  2105. ss_sp = NULL;
  2106. } else {
  2107. error = -ENOMEM;
  2108. if (ss_size < MINSIGSTKSZ)
  2109. goto out;
  2110. }
  2111. current->sas_ss_sp = (unsigned long) ss_sp;
  2112. current->sas_ss_size = ss_size;
  2113. }
  2114. if (uoss) {
  2115. error = -EFAULT;
  2116. if (copy_to_user(uoss, &oss, sizeof(oss)))
  2117. goto out;
  2118. }
  2119. error = 0;
  2120. out:
  2121. return error;
  2122. }
  2123. #ifdef __ARCH_WANT_SYS_SIGPENDING
  2124. SYSCALL_DEFINE1(sigpending, old_sigset_t __user *, set)
  2125. {
  2126. return do_sigpending(set, sizeof(*set));
  2127. }
  2128. #endif
  2129. #ifdef __ARCH_WANT_SYS_SIGPROCMASK
  2130. /* Some platforms have their own version with special arguments others
  2131. support only sys_rt_sigprocmask. */
  2132. SYSCALL_DEFINE3(sigprocmask, int, how, old_sigset_t __user *, set,
  2133. old_sigset_t __user *, oset)
  2134. {
  2135. int error;
  2136. old_sigset_t old_set, new_set;
  2137. if (set) {
  2138. error = -EFAULT;
  2139. if (copy_from_user(&new_set, set, sizeof(*set)))
  2140. goto out;
  2141. new_set &= ~(sigmask(SIGKILL) | sigmask(SIGSTOP));
  2142. spin_lock_irq(&current->sighand->siglock);
  2143. old_set = current->blocked.sig[0];
  2144. error = 0;
  2145. switch (how) {
  2146. default:
  2147. error = -EINVAL;
  2148. break;
  2149. case SIG_BLOCK:
  2150. sigaddsetmask(&current->blocked, new_set);
  2151. break;
  2152. case SIG_UNBLOCK:
  2153. sigdelsetmask(&current->blocked, new_set);
  2154. break;
  2155. case SIG_SETMASK:
  2156. current->blocked.sig[0] = new_set;
  2157. break;
  2158. }
  2159. recalc_sigpending();
  2160. spin_unlock_irq(&current->sighand->siglock);
  2161. if (error)
  2162. goto out;
  2163. if (oset)
  2164. goto set_old;
  2165. } else if (oset) {
  2166. old_set = current->blocked.sig[0];
  2167. set_old:
  2168. error = -EFAULT;
  2169. if (copy_to_user(oset, &old_set, sizeof(*oset)))
  2170. goto out;
  2171. }
  2172. error = 0;
  2173. out:
  2174. return error;
  2175. }
  2176. #endif /* __ARCH_WANT_SYS_SIGPROCMASK */
  2177. #ifdef __ARCH_WANT_SYS_RT_SIGACTION
  2178. asmlinkage long
  2179. sys_rt_sigaction(int sig,
  2180. const struct sigaction __user *act,
  2181. struct sigaction __user *oact,
  2182. size_t sigsetsize)
  2183. {
  2184. struct k_sigaction new_sa, old_sa;
  2185. int ret = -EINVAL;
  2186. /* XXX: Don't preclude handling different sized sigset_t's. */
  2187. if (sigsetsize != sizeof(sigset_t))
  2188. goto out;
  2189. if (act) {
  2190. if (copy_from_user(&new_sa.sa, act, sizeof(new_sa.sa)))
  2191. return -EFAULT;
  2192. }
  2193. ret = do_sigaction(sig, act ? &new_sa : NULL, oact ? &old_sa : NULL);
  2194. if (!ret && oact) {
  2195. if (copy_to_user(oact, &old_sa.sa, sizeof(old_sa.sa)))
  2196. return -EFAULT;
  2197. }
  2198. out:
  2199. return ret;
  2200. }
  2201. #endif /* __ARCH_WANT_SYS_RT_SIGACTION */
  2202. #ifdef __ARCH_WANT_SYS_SGETMASK
  2203. /*
  2204. * For backwards compatibility. Functionality superseded by sigprocmask.
  2205. */
  2206. asmlinkage long
  2207. sys_sgetmask(void)
  2208. {
  2209. /* SMP safe */
  2210. return current->blocked.sig[0];
  2211. }
  2212. asmlinkage long
  2213. sys_ssetmask(int newmask)
  2214. {
  2215. int old;
  2216. spin_lock_irq(&current->sighand->siglock);
  2217. old = current->blocked.sig[0];
  2218. siginitset(&current->blocked, newmask & ~(sigmask(SIGKILL)|
  2219. sigmask(SIGSTOP)));
  2220. recalc_sigpending();
  2221. spin_unlock_irq(&current->sighand->siglock);
  2222. return old;
  2223. }
  2224. #endif /* __ARCH_WANT_SGETMASK */
  2225. #ifdef __ARCH_WANT_SYS_SIGNAL
  2226. /*
  2227. * For backwards compatibility. Functionality superseded by sigaction.
  2228. */
  2229. asmlinkage long
  2230. sys_signal(int sig, __sighandler_t handler)
  2231. {
  2232. struct k_sigaction new_sa, old_sa;
  2233. int ret;
  2234. new_sa.sa.sa_handler = handler;
  2235. new_sa.sa.sa_flags = SA_ONESHOT | SA_NOMASK;
  2236. sigemptyset(&new_sa.sa.sa_mask);
  2237. ret = do_sigaction(sig, &new_sa, &old_sa);
  2238. return ret ? ret : (unsigned long)old_sa.sa.sa_handler;
  2239. }
  2240. #endif /* __ARCH_WANT_SYS_SIGNAL */
  2241. #ifdef __ARCH_WANT_SYS_PAUSE
  2242. asmlinkage long
  2243. sys_pause(void)
  2244. {
  2245. current->state = TASK_INTERRUPTIBLE;
  2246. schedule();
  2247. return -ERESTARTNOHAND;
  2248. }
  2249. #endif
  2250. #ifdef __ARCH_WANT_SYS_RT_SIGSUSPEND
  2251. asmlinkage long sys_rt_sigsuspend(sigset_t __user *unewset, size_t sigsetsize)
  2252. {
  2253. sigset_t newset;
  2254. /* XXX: Don't preclude handling different sized sigset_t's. */
  2255. if (sigsetsize != sizeof(sigset_t))
  2256. return -EINVAL;
  2257. if (copy_from_user(&newset, unewset, sizeof(newset)))
  2258. return -EFAULT;
  2259. sigdelsetmask(&newset, sigmask(SIGKILL)|sigmask(SIGSTOP));
  2260. spin_lock_irq(&current->sighand->siglock);
  2261. current->saved_sigmask = current->blocked;
  2262. current->blocked = newset;
  2263. recalc_sigpending();
  2264. spin_unlock_irq(&current->sighand->siglock);
  2265. current->state = TASK_INTERRUPTIBLE;
  2266. schedule();
  2267. set_restore_sigmask();
  2268. return -ERESTARTNOHAND;
  2269. }
  2270. #endif /* __ARCH_WANT_SYS_RT_SIGSUSPEND */
  2271. __attribute__((weak)) const char *arch_vma_name(struct vm_area_struct *vma)
  2272. {
  2273. return NULL;
  2274. }
  2275. void __init signals_init(void)
  2276. {
  2277. sigqueue_cachep = KMEM_CACHE(sigqueue, SLAB_PANIC);
  2278. }