signal.c 65 KB

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