signal.c 96 KB

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