signal.c 82 KB

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