signal.c 66 KB

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