base.c 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233
  1. /*
  2. * linux/fs/proc/base.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. *
  6. * proc base directory handling functions
  7. *
  8. * 1999, Al Viro. Rewritten. Now it covers the whole per-process part.
  9. * Instead of using magical inumbers to determine the kind of object
  10. * we allocate and fill in-core inodes upon lookup. They don't even
  11. * go into icache. We cache the reference to task_struct upon lookup too.
  12. * Eventually it should become a filesystem in its own. We don't use the
  13. * rest of procfs anymore.
  14. *
  15. *
  16. * Changelog:
  17. * 17-Jan-2005
  18. * Allan Bezerra
  19. * Bruna Moreira <bruna.moreira@indt.org.br>
  20. * Edjard Mota <edjard.mota@indt.org.br>
  21. * Ilias Biris <ilias.biris@indt.org.br>
  22. * Mauricio Lin <mauricio.lin@indt.org.br>
  23. *
  24. * Embedded Linux Lab - 10LE Instituto Nokia de Tecnologia - INdT
  25. *
  26. * A new process specific entry (smaps) included in /proc. It shows the
  27. * size of rss for each memory area. The maps entry lacks information
  28. * about physical memory size (rss) for each mapped file, i.e.,
  29. * rss information for executables and library files.
  30. * This additional information is useful for any tools that need to know
  31. * about physical memory consumption for a process specific library.
  32. *
  33. * Changelog:
  34. * 21-Feb-2005
  35. * Embedded Linux Lab - 10LE Instituto Nokia de Tecnologia - INdT
  36. * Pud inclusion in the page table walking.
  37. *
  38. * ChangeLog:
  39. * 10-Mar-2005
  40. * 10LE Instituto Nokia de Tecnologia - INdT:
  41. * A better way to walks through the page table as suggested by Hugh Dickins.
  42. *
  43. * Simo Piiroinen <simo.piiroinen@nokia.com>:
  44. * Smaps information related to shared, private, clean and dirty pages.
  45. *
  46. * Paul Mundt <paul.mundt@nokia.com>:
  47. * Overall revision about smaps.
  48. */
  49. #include <asm/uaccess.h>
  50. #include <linux/errno.h>
  51. #include <linux/time.h>
  52. #include <linux/proc_fs.h>
  53. #include <linux/stat.h>
  54. #include <linux/task_io_accounting_ops.h>
  55. #include <linux/init.h>
  56. #include <linux/capability.h>
  57. #include <linux/file.h>
  58. #include <linux/fdtable.h>
  59. #include <linux/string.h>
  60. #include <linux/seq_file.h>
  61. #include <linux/namei.h>
  62. #include <linux/mnt_namespace.h>
  63. #include <linux/mm.h>
  64. #include <linux/swap.h>
  65. #include <linux/rcupdate.h>
  66. #include <linux/kallsyms.h>
  67. #include <linux/stacktrace.h>
  68. #include <linux/resource.h>
  69. #include <linux/module.h>
  70. #include <linux/mount.h>
  71. #include <linux/security.h>
  72. #include <linux/ptrace.h>
  73. #include <linux/tracehook.h>
  74. #include <linux/printk.h>
  75. #include <linux/cgroup.h>
  76. #include <linux/cpuset.h>
  77. #include <linux/audit.h>
  78. #include <linux/poll.h>
  79. #include <linux/nsproxy.h>
  80. #include <linux/oom.h>
  81. #include <linux/elf.h>
  82. #include <linux/pid_namespace.h>
  83. #include <linux/user_namespace.h>
  84. #include <linux/fs_struct.h>
  85. #include <linux/slab.h>
  86. #include <linux/flex_array.h>
  87. #ifdef CONFIG_HARDWALL
  88. #include <asm/hardwall.h>
  89. #endif
  90. #include <trace/events/oom.h>
  91. #include "internal.h"
  92. #include "fd.h"
  93. /* NOTE:
  94. * Implementing inode permission operations in /proc is almost
  95. * certainly an error. Permission checks need to happen during
  96. * each system call not at open time. The reason is that most of
  97. * what we wish to check for permissions in /proc varies at runtime.
  98. *
  99. * The classic example of a problem is opening file descriptors
  100. * in /proc for a task before it execs a suid executable.
  101. */
  102. struct pid_entry {
  103. char *name;
  104. int len;
  105. umode_t mode;
  106. const struct inode_operations *iop;
  107. const struct file_operations *fop;
  108. union proc_op op;
  109. };
  110. #define NOD(NAME, MODE, IOP, FOP, OP) { \
  111. .name = (NAME), \
  112. .len = sizeof(NAME) - 1, \
  113. .mode = MODE, \
  114. .iop = IOP, \
  115. .fop = FOP, \
  116. .op = OP, \
  117. }
  118. #define DIR(NAME, MODE, iops, fops) \
  119. NOD(NAME, (S_IFDIR|(MODE)), &iops, &fops, {} )
  120. #define LNK(NAME, get_link) \
  121. NOD(NAME, (S_IFLNK|S_IRWXUGO), \
  122. &proc_pid_link_inode_operations, NULL, \
  123. { .proc_get_link = get_link } )
  124. #define REG(NAME, MODE, fops) \
  125. NOD(NAME, (S_IFREG|(MODE)), NULL, &fops, {})
  126. #define INF(NAME, MODE, read) \
  127. NOD(NAME, (S_IFREG|(MODE)), \
  128. NULL, &proc_info_file_operations, \
  129. { .proc_read = read } )
  130. #define ONE(NAME, MODE, show) \
  131. NOD(NAME, (S_IFREG|(MODE)), \
  132. NULL, &proc_single_file_operations, \
  133. { .proc_show = show } )
  134. /*
  135. * Count the number of hardlinks for the pid_entry table, excluding the .
  136. * and .. links.
  137. */
  138. static unsigned int pid_entry_count_dirs(const struct pid_entry *entries,
  139. unsigned int n)
  140. {
  141. unsigned int i;
  142. unsigned int count;
  143. count = 0;
  144. for (i = 0; i < n; ++i) {
  145. if (S_ISDIR(entries[i].mode))
  146. ++count;
  147. }
  148. return count;
  149. }
  150. static int get_task_root(struct task_struct *task, struct path *root)
  151. {
  152. int result = -ENOENT;
  153. task_lock(task);
  154. if (task->fs) {
  155. get_fs_root(task->fs, root);
  156. result = 0;
  157. }
  158. task_unlock(task);
  159. return result;
  160. }
  161. static int proc_cwd_link(struct dentry *dentry, struct path *path)
  162. {
  163. struct task_struct *task = get_proc_task(dentry->d_inode);
  164. int result = -ENOENT;
  165. if (task) {
  166. task_lock(task);
  167. if (task->fs) {
  168. get_fs_pwd(task->fs, path);
  169. result = 0;
  170. }
  171. task_unlock(task);
  172. put_task_struct(task);
  173. }
  174. return result;
  175. }
  176. static int proc_root_link(struct dentry *dentry, struct path *path)
  177. {
  178. struct task_struct *task = get_proc_task(dentry->d_inode);
  179. int result = -ENOENT;
  180. if (task) {
  181. result = get_task_root(task, path);
  182. put_task_struct(task);
  183. }
  184. return result;
  185. }
  186. static int proc_pid_cmdline(struct task_struct *task, char * buffer)
  187. {
  188. int res = 0;
  189. unsigned int len;
  190. struct mm_struct *mm = get_task_mm(task);
  191. if (!mm)
  192. goto out;
  193. if (!mm->arg_end)
  194. goto out_mm; /* Shh! No looking before we're done */
  195. len = mm->arg_end - mm->arg_start;
  196. if (len > PAGE_SIZE)
  197. len = PAGE_SIZE;
  198. res = access_process_vm(task, mm->arg_start, buffer, len, 0);
  199. // If the nul at the end of args has been overwritten, then
  200. // assume application is using setproctitle(3).
  201. if (res > 0 && buffer[res-1] != '\0' && len < PAGE_SIZE) {
  202. len = strnlen(buffer, res);
  203. if (len < res) {
  204. res = len;
  205. } else {
  206. len = mm->env_end - mm->env_start;
  207. if (len > PAGE_SIZE - res)
  208. len = PAGE_SIZE - res;
  209. res += access_process_vm(task, mm->env_start, buffer+res, len, 0);
  210. res = strnlen(buffer, res);
  211. }
  212. }
  213. out_mm:
  214. mmput(mm);
  215. out:
  216. return res;
  217. }
  218. static int proc_pid_auxv(struct task_struct *task, char *buffer)
  219. {
  220. struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
  221. int res = PTR_ERR(mm);
  222. if (mm && !IS_ERR(mm)) {
  223. unsigned int nwords = 0;
  224. do {
  225. nwords += 2;
  226. } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
  227. res = nwords * sizeof(mm->saved_auxv[0]);
  228. if (res > PAGE_SIZE)
  229. res = PAGE_SIZE;
  230. memcpy(buffer, mm->saved_auxv, res);
  231. mmput(mm);
  232. }
  233. return res;
  234. }
  235. #ifdef CONFIG_KALLSYMS
  236. /*
  237. * Provides a wchan file via kallsyms in a proper one-value-per-file format.
  238. * Returns the resolved symbol. If that fails, simply return the address.
  239. */
  240. static int proc_pid_wchan(struct task_struct *task, char *buffer)
  241. {
  242. unsigned long wchan;
  243. char symname[KSYM_NAME_LEN];
  244. wchan = get_wchan(task);
  245. if (lookup_symbol_name(wchan, symname) < 0)
  246. if (!ptrace_may_access(task, PTRACE_MODE_READ))
  247. return 0;
  248. else
  249. return sprintf(buffer, "%lu", wchan);
  250. else
  251. return sprintf(buffer, "%s", symname);
  252. }
  253. #endif /* CONFIG_KALLSYMS */
  254. static int lock_trace(struct task_struct *task)
  255. {
  256. int err = mutex_lock_killable(&task->signal->cred_guard_mutex);
  257. if (err)
  258. return err;
  259. if (!ptrace_may_access(task, PTRACE_MODE_ATTACH)) {
  260. mutex_unlock(&task->signal->cred_guard_mutex);
  261. return -EPERM;
  262. }
  263. return 0;
  264. }
  265. static void unlock_trace(struct task_struct *task)
  266. {
  267. mutex_unlock(&task->signal->cred_guard_mutex);
  268. }
  269. #ifdef CONFIG_STACKTRACE
  270. #define MAX_STACK_TRACE_DEPTH 64
  271. static int proc_pid_stack(struct seq_file *m, struct pid_namespace *ns,
  272. struct pid *pid, struct task_struct *task)
  273. {
  274. struct stack_trace trace;
  275. unsigned long *entries;
  276. int err;
  277. int i;
  278. entries = kmalloc(MAX_STACK_TRACE_DEPTH * sizeof(*entries), GFP_KERNEL);
  279. if (!entries)
  280. return -ENOMEM;
  281. trace.nr_entries = 0;
  282. trace.max_entries = MAX_STACK_TRACE_DEPTH;
  283. trace.entries = entries;
  284. trace.skip = 0;
  285. err = lock_trace(task);
  286. if (!err) {
  287. save_stack_trace_tsk(task, &trace);
  288. for (i = 0; i < trace.nr_entries; i++) {
  289. seq_printf(m, "[<%pK>] %pS\n",
  290. (void *)entries[i], (void *)entries[i]);
  291. }
  292. unlock_trace(task);
  293. }
  294. kfree(entries);
  295. return err;
  296. }
  297. #endif
  298. #ifdef CONFIG_SCHEDSTATS
  299. /*
  300. * Provides /proc/PID/schedstat
  301. */
  302. static int proc_pid_schedstat(struct task_struct *task, char *buffer)
  303. {
  304. return sprintf(buffer, "%llu %llu %lu\n",
  305. (unsigned long long)task->se.sum_exec_runtime,
  306. (unsigned long long)task->sched_info.run_delay,
  307. task->sched_info.pcount);
  308. }
  309. #endif
  310. #ifdef CONFIG_LATENCYTOP
  311. static int lstats_show_proc(struct seq_file *m, void *v)
  312. {
  313. int i;
  314. struct inode *inode = m->private;
  315. struct task_struct *task = get_proc_task(inode);
  316. if (!task)
  317. return -ESRCH;
  318. seq_puts(m, "Latency Top version : v0.1\n");
  319. for (i = 0; i < 32; i++) {
  320. struct latency_record *lr = &task->latency_record[i];
  321. if (lr->backtrace[0]) {
  322. int q;
  323. seq_printf(m, "%i %li %li",
  324. lr->count, lr->time, lr->max);
  325. for (q = 0; q < LT_BACKTRACEDEPTH; q++) {
  326. unsigned long bt = lr->backtrace[q];
  327. if (!bt)
  328. break;
  329. if (bt == ULONG_MAX)
  330. break;
  331. seq_printf(m, " %ps", (void *)bt);
  332. }
  333. seq_putc(m, '\n');
  334. }
  335. }
  336. put_task_struct(task);
  337. return 0;
  338. }
  339. static int lstats_open(struct inode *inode, struct file *file)
  340. {
  341. return single_open(file, lstats_show_proc, inode);
  342. }
  343. static ssize_t lstats_write(struct file *file, const char __user *buf,
  344. size_t count, loff_t *offs)
  345. {
  346. struct task_struct *task = get_proc_task(file_inode(file));
  347. if (!task)
  348. return -ESRCH;
  349. clear_all_latency_tracing(task);
  350. put_task_struct(task);
  351. return count;
  352. }
  353. static const struct file_operations proc_lstats_operations = {
  354. .open = lstats_open,
  355. .read = seq_read,
  356. .write = lstats_write,
  357. .llseek = seq_lseek,
  358. .release = single_release,
  359. };
  360. #endif
  361. #ifdef CONFIG_CGROUPS
  362. static int cgroup_open(struct inode *inode, struct file *file)
  363. {
  364. struct pid *pid = PROC_I(inode)->pid;
  365. return single_open(file, proc_cgroup_show, pid);
  366. }
  367. static const struct file_operations proc_cgroup_operations = {
  368. .open = cgroup_open,
  369. .read = seq_read,
  370. .llseek = seq_lseek,
  371. .release = single_release,
  372. };
  373. #endif
  374. #ifdef CONFIG_PROC_PID_CPUSET
  375. static int cpuset_open(struct inode *inode, struct file *file)
  376. {
  377. struct pid *pid = PROC_I(inode)->pid;
  378. return single_open(file, proc_cpuset_show, pid);
  379. }
  380. static const struct file_operations proc_cpuset_operations = {
  381. .open = cpuset_open,
  382. .read = seq_read,
  383. .llseek = seq_lseek,
  384. .release = single_release,
  385. };
  386. #endif
  387. static int proc_oom_score(struct task_struct *task, char *buffer)
  388. {
  389. unsigned long totalpages = totalram_pages + total_swap_pages;
  390. unsigned long points = 0;
  391. read_lock(&tasklist_lock);
  392. if (pid_alive(task))
  393. points = oom_badness(task, NULL, NULL, totalpages) *
  394. 1000 / totalpages;
  395. read_unlock(&tasklist_lock);
  396. return sprintf(buffer, "%lu\n", points);
  397. }
  398. struct limit_names {
  399. char *name;
  400. char *unit;
  401. };
  402. static const struct limit_names lnames[RLIM_NLIMITS] = {
  403. [RLIMIT_CPU] = {"Max cpu time", "seconds"},
  404. [RLIMIT_FSIZE] = {"Max file size", "bytes"},
  405. [RLIMIT_DATA] = {"Max data size", "bytes"},
  406. [RLIMIT_STACK] = {"Max stack size", "bytes"},
  407. [RLIMIT_CORE] = {"Max core file size", "bytes"},
  408. [RLIMIT_RSS] = {"Max resident set", "bytes"},
  409. [RLIMIT_NPROC] = {"Max processes", "processes"},
  410. [RLIMIT_NOFILE] = {"Max open files", "files"},
  411. [RLIMIT_MEMLOCK] = {"Max locked memory", "bytes"},
  412. [RLIMIT_AS] = {"Max address space", "bytes"},
  413. [RLIMIT_LOCKS] = {"Max file locks", "locks"},
  414. [RLIMIT_SIGPENDING] = {"Max pending signals", "signals"},
  415. [RLIMIT_MSGQUEUE] = {"Max msgqueue size", "bytes"},
  416. [RLIMIT_NICE] = {"Max nice priority", NULL},
  417. [RLIMIT_RTPRIO] = {"Max realtime priority", NULL},
  418. [RLIMIT_RTTIME] = {"Max realtime timeout", "us"},
  419. };
  420. /* Display limits for a process */
  421. static int proc_pid_limits(struct task_struct *task, char *buffer)
  422. {
  423. unsigned int i;
  424. int count = 0;
  425. unsigned long flags;
  426. char *bufptr = buffer;
  427. struct rlimit rlim[RLIM_NLIMITS];
  428. if (!lock_task_sighand(task, &flags))
  429. return 0;
  430. memcpy(rlim, task->signal->rlim, sizeof(struct rlimit) * RLIM_NLIMITS);
  431. unlock_task_sighand(task, &flags);
  432. /*
  433. * print the file header
  434. */
  435. count += sprintf(&bufptr[count], "%-25s %-20s %-20s %-10s\n",
  436. "Limit", "Soft Limit", "Hard Limit", "Units");
  437. for (i = 0; i < RLIM_NLIMITS; i++) {
  438. if (rlim[i].rlim_cur == RLIM_INFINITY)
  439. count += sprintf(&bufptr[count], "%-25s %-20s ",
  440. lnames[i].name, "unlimited");
  441. else
  442. count += sprintf(&bufptr[count], "%-25s %-20lu ",
  443. lnames[i].name, rlim[i].rlim_cur);
  444. if (rlim[i].rlim_max == RLIM_INFINITY)
  445. count += sprintf(&bufptr[count], "%-20s ", "unlimited");
  446. else
  447. count += sprintf(&bufptr[count], "%-20lu ",
  448. rlim[i].rlim_max);
  449. if (lnames[i].unit)
  450. count += sprintf(&bufptr[count], "%-10s\n",
  451. lnames[i].unit);
  452. else
  453. count += sprintf(&bufptr[count], "\n");
  454. }
  455. return count;
  456. }
  457. #ifdef CONFIG_HAVE_ARCH_TRACEHOOK
  458. static int proc_pid_syscall(struct task_struct *task, char *buffer)
  459. {
  460. long nr;
  461. unsigned long args[6], sp, pc;
  462. int res = lock_trace(task);
  463. if (res)
  464. return res;
  465. if (task_current_syscall(task, &nr, args, 6, &sp, &pc))
  466. res = sprintf(buffer, "running\n");
  467. else if (nr < 0)
  468. res = sprintf(buffer, "%ld 0x%lx 0x%lx\n", nr, sp, pc);
  469. else
  470. res = sprintf(buffer,
  471. "%ld 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n",
  472. nr,
  473. args[0], args[1], args[2], args[3], args[4], args[5],
  474. sp, pc);
  475. unlock_trace(task);
  476. return res;
  477. }
  478. #endif /* CONFIG_HAVE_ARCH_TRACEHOOK */
  479. /************************************************************************/
  480. /* Here the fs part begins */
  481. /************************************************************************/
  482. /* permission checks */
  483. static int proc_fd_access_allowed(struct inode *inode)
  484. {
  485. struct task_struct *task;
  486. int allowed = 0;
  487. /* Allow access to a task's file descriptors if it is us or we
  488. * may use ptrace attach to the process and find out that
  489. * information.
  490. */
  491. task = get_proc_task(inode);
  492. if (task) {
  493. allowed = ptrace_may_access(task, PTRACE_MODE_READ);
  494. put_task_struct(task);
  495. }
  496. return allowed;
  497. }
  498. int proc_setattr(struct dentry *dentry, struct iattr *attr)
  499. {
  500. int error;
  501. struct inode *inode = dentry->d_inode;
  502. if (attr->ia_valid & ATTR_MODE)
  503. return -EPERM;
  504. error = inode_change_ok(inode, attr);
  505. if (error)
  506. return error;
  507. setattr_copy(inode, attr);
  508. mark_inode_dirty(inode);
  509. return 0;
  510. }
  511. /*
  512. * May current process learn task's sched/cmdline info (for hide_pid_min=1)
  513. * or euid/egid (for hide_pid_min=2)?
  514. */
  515. static bool has_pid_permissions(struct pid_namespace *pid,
  516. struct task_struct *task,
  517. int hide_pid_min)
  518. {
  519. if (pid->hide_pid < hide_pid_min)
  520. return true;
  521. if (in_group_p(pid->pid_gid))
  522. return true;
  523. return ptrace_may_access(task, PTRACE_MODE_READ);
  524. }
  525. static int proc_pid_permission(struct inode *inode, int mask)
  526. {
  527. struct pid_namespace *pid = inode->i_sb->s_fs_info;
  528. struct task_struct *task;
  529. bool has_perms;
  530. task = get_proc_task(inode);
  531. if (!task)
  532. return -ESRCH;
  533. has_perms = has_pid_permissions(pid, task, 1);
  534. put_task_struct(task);
  535. if (!has_perms) {
  536. if (pid->hide_pid == 2) {
  537. /*
  538. * Let's make getdents(), stat(), and open()
  539. * consistent with each other. If a process
  540. * may not stat() a file, it shouldn't be seen
  541. * in procfs at all.
  542. */
  543. return -ENOENT;
  544. }
  545. return -EPERM;
  546. }
  547. return generic_permission(inode, mask);
  548. }
  549. static const struct inode_operations proc_def_inode_operations = {
  550. .setattr = proc_setattr,
  551. };
  552. #define PROC_BLOCK_SIZE (3*1024) /* 4K page size but our output routines use some slack for overruns */
  553. static ssize_t proc_info_read(struct file * file, char __user * buf,
  554. size_t count, loff_t *ppos)
  555. {
  556. struct inode * inode = file_inode(file);
  557. unsigned long page;
  558. ssize_t length;
  559. struct task_struct *task = get_proc_task(inode);
  560. length = -ESRCH;
  561. if (!task)
  562. goto out_no_task;
  563. if (count > PROC_BLOCK_SIZE)
  564. count = PROC_BLOCK_SIZE;
  565. length = -ENOMEM;
  566. if (!(page = __get_free_page(GFP_TEMPORARY)))
  567. goto out;
  568. length = PROC_I(inode)->op.proc_read(task, (char*)page);
  569. if (length >= 0)
  570. length = simple_read_from_buffer(buf, count, ppos, (char *)page, length);
  571. free_page(page);
  572. out:
  573. put_task_struct(task);
  574. out_no_task:
  575. return length;
  576. }
  577. static const struct file_operations proc_info_file_operations = {
  578. .read = proc_info_read,
  579. .llseek = generic_file_llseek,
  580. };
  581. static int proc_single_show(struct seq_file *m, void *v)
  582. {
  583. struct inode *inode = m->private;
  584. struct pid_namespace *ns;
  585. struct pid *pid;
  586. struct task_struct *task;
  587. int ret;
  588. ns = inode->i_sb->s_fs_info;
  589. pid = proc_pid(inode);
  590. task = get_pid_task(pid, PIDTYPE_PID);
  591. if (!task)
  592. return -ESRCH;
  593. ret = PROC_I(inode)->op.proc_show(m, ns, pid, task);
  594. put_task_struct(task);
  595. return ret;
  596. }
  597. static int proc_single_open(struct inode *inode, struct file *filp)
  598. {
  599. return single_open(filp, proc_single_show, inode);
  600. }
  601. static const struct file_operations proc_single_file_operations = {
  602. .open = proc_single_open,
  603. .read = seq_read,
  604. .llseek = seq_lseek,
  605. .release = single_release,
  606. };
  607. static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
  608. {
  609. struct task_struct *task = get_proc_task(file_inode(file));
  610. struct mm_struct *mm;
  611. if (!task)
  612. return -ESRCH;
  613. mm = mm_access(task, mode);
  614. put_task_struct(task);
  615. if (IS_ERR(mm))
  616. return PTR_ERR(mm);
  617. if (mm) {
  618. /* ensure this mm_struct can't be freed */
  619. atomic_inc(&mm->mm_count);
  620. /* but do not pin its memory */
  621. mmput(mm);
  622. }
  623. file->private_data = mm;
  624. return 0;
  625. }
  626. static int mem_open(struct inode *inode, struct file *file)
  627. {
  628. int ret = __mem_open(inode, file, PTRACE_MODE_ATTACH);
  629. /* OK to pass negative loff_t, we can catch out-of-range */
  630. file->f_mode |= FMODE_UNSIGNED_OFFSET;
  631. return ret;
  632. }
  633. static ssize_t mem_rw(struct file *file, char __user *buf,
  634. size_t count, loff_t *ppos, int write)
  635. {
  636. struct mm_struct *mm = file->private_data;
  637. unsigned long addr = *ppos;
  638. ssize_t copied;
  639. char *page;
  640. if (!mm)
  641. return 0;
  642. page = (char *)__get_free_page(GFP_TEMPORARY);
  643. if (!page)
  644. return -ENOMEM;
  645. copied = 0;
  646. if (!atomic_inc_not_zero(&mm->mm_users))
  647. goto free;
  648. while (count > 0) {
  649. int this_len = min_t(int, count, PAGE_SIZE);
  650. if (write && copy_from_user(page, buf, this_len)) {
  651. copied = -EFAULT;
  652. break;
  653. }
  654. this_len = access_remote_vm(mm, addr, page, this_len, write);
  655. if (!this_len) {
  656. if (!copied)
  657. copied = -EIO;
  658. break;
  659. }
  660. if (!write && copy_to_user(buf, page, this_len)) {
  661. copied = -EFAULT;
  662. break;
  663. }
  664. buf += this_len;
  665. addr += this_len;
  666. copied += this_len;
  667. count -= this_len;
  668. }
  669. *ppos = addr;
  670. mmput(mm);
  671. free:
  672. free_page((unsigned long) page);
  673. return copied;
  674. }
  675. static ssize_t mem_read(struct file *file, char __user *buf,
  676. size_t count, loff_t *ppos)
  677. {
  678. return mem_rw(file, buf, count, ppos, 0);
  679. }
  680. static ssize_t mem_write(struct file *file, const char __user *buf,
  681. size_t count, loff_t *ppos)
  682. {
  683. return mem_rw(file, (char __user*)buf, count, ppos, 1);
  684. }
  685. loff_t mem_lseek(struct file *file, loff_t offset, int orig)
  686. {
  687. switch (orig) {
  688. case 0:
  689. file->f_pos = offset;
  690. break;
  691. case 1:
  692. file->f_pos += offset;
  693. break;
  694. default:
  695. return -EINVAL;
  696. }
  697. force_successful_syscall_return();
  698. return file->f_pos;
  699. }
  700. static int mem_release(struct inode *inode, struct file *file)
  701. {
  702. struct mm_struct *mm = file->private_data;
  703. if (mm)
  704. mmdrop(mm);
  705. return 0;
  706. }
  707. static const struct file_operations proc_mem_operations = {
  708. .llseek = mem_lseek,
  709. .read = mem_read,
  710. .write = mem_write,
  711. .open = mem_open,
  712. .release = mem_release,
  713. };
  714. static int environ_open(struct inode *inode, struct file *file)
  715. {
  716. return __mem_open(inode, file, PTRACE_MODE_READ);
  717. }
  718. static ssize_t environ_read(struct file *file, char __user *buf,
  719. size_t count, loff_t *ppos)
  720. {
  721. char *page;
  722. unsigned long src = *ppos;
  723. int ret = 0;
  724. struct mm_struct *mm = file->private_data;
  725. if (!mm)
  726. return 0;
  727. page = (char *)__get_free_page(GFP_TEMPORARY);
  728. if (!page)
  729. return -ENOMEM;
  730. ret = 0;
  731. if (!atomic_inc_not_zero(&mm->mm_users))
  732. goto free;
  733. while (count > 0) {
  734. size_t this_len, max_len;
  735. int retval;
  736. if (src >= (mm->env_end - mm->env_start))
  737. break;
  738. this_len = mm->env_end - (mm->env_start + src);
  739. max_len = min_t(size_t, PAGE_SIZE, count);
  740. this_len = min(max_len, this_len);
  741. retval = access_remote_vm(mm, (mm->env_start + src),
  742. page, this_len, 0);
  743. if (retval <= 0) {
  744. ret = retval;
  745. break;
  746. }
  747. if (copy_to_user(buf, page, retval)) {
  748. ret = -EFAULT;
  749. break;
  750. }
  751. ret += retval;
  752. src += retval;
  753. buf += retval;
  754. count -= retval;
  755. }
  756. *ppos = src;
  757. mmput(mm);
  758. free:
  759. free_page((unsigned long) page);
  760. return ret;
  761. }
  762. static const struct file_operations proc_environ_operations = {
  763. .open = environ_open,
  764. .read = environ_read,
  765. .llseek = generic_file_llseek,
  766. .release = mem_release,
  767. };
  768. static ssize_t oom_adj_read(struct file *file, char __user *buf, size_t count,
  769. loff_t *ppos)
  770. {
  771. struct task_struct *task = get_proc_task(file_inode(file));
  772. char buffer[PROC_NUMBUF];
  773. int oom_adj = OOM_ADJUST_MIN;
  774. size_t len;
  775. unsigned long flags;
  776. if (!task)
  777. return -ESRCH;
  778. if (lock_task_sighand(task, &flags)) {
  779. if (task->signal->oom_score_adj == OOM_SCORE_ADJ_MAX)
  780. oom_adj = OOM_ADJUST_MAX;
  781. else
  782. oom_adj = (task->signal->oom_score_adj * -OOM_DISABLE) /
  783. OOM_SCORE_ADJ_MAX;
  784. unlock_task_sighand(task, &flags);
  785. }
  786. put_task_struct(task);
  787. len = snprintf(buffer, sizeof(buffer), "%d\n", oom_adj);
  788. return simple_read_from_buffer(buf, count, ppos, buffer, len);
  789. }
  790. static ssize_t oom_adj_write(struct file *file, const char __user *buf,
  791. size_t count, loff_t *ppos)
  792. {
  793. struct task_struct *task;
  794. char buffer[PROC_NUMBUF];
  795. int oom_adj;
  796. unsigned long flags;
  797. int err;
  798. memset(buffer, 0, sizeof(buffer));
  799. if (count > sizeof(buffer) - 1)
  800. count = sizeof(buffer) - 1;
  801. if (copy_from_user(buffer, buf, count)) {
  802. err = -EFAULT;
  803. goto out;
  804. }
  805. err = kstrtoint(strstrip(buffer), 0, &oom_adj);
  806. if (err)
  807. goto out;
  808. if ((oom_adj < OOM_ADJUST_MIN || oom_adj > OOM_ADJUST_MAX) &&
  809. oom_adj != OOM_DISABLE) {
  810. err = -EINVAL;
  811. goto out;
  812. }
  813. task = get_proc_task(file_inode(file));
  814. if (!task) {
  815. err = -ESRCH;
  816. goto out;
  817. }
  818. task_lock(task);
  819. if (!task->mm) {
  820. err = -EINVAL;
  821. goto err_task_lock;
  822. }
  823. if (!lock_task_sighand(task, &flags)) {
  824. err = -ESRCH;
  825. goto err_task_lock;
  826. }
  827. /*
  828. * Scale /proc/pid/oom_score_adj appropriately ensuring that a maximum
  829. * value is always attainable.
  830. */
  831. if (oom_adj == OOM_ADJUST_MAX)
  832. oom_adj = OOM_SCORE_ADJ_MAX;
  833. else
  834. oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
  835. if (oom_adj < task->signal->oom_score_adj &&
  836. !capable(CAP_SYS_RESOURCE)) {
  837. err = -EACCES;
  838. goto err_sighand;
  839. }
  840. /*
  841. * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
  842. * /proc/pid/oom_score_adj instead.
  843. */
  844. pr_warn_once("%s (%d): /proc/%d/oom_adj is deprecated, please use /proc/%d/oom_score_adj instead.\n",
  845. current->comm, task_pid_nr(current), task_pid_nr(task),
  846. task_pid_nr(task));
  847. task->signal->oom_score_adj = oom_adj;
  848. trace_oom_score_adj_update(task);
  849. err_sighand:
  850. unlock_task_sighand(task, &flags);
  851. err_task_lock:
  852. task_unlock(task);
  853. put_task_struct(task);
  854. out:
  855. return err < 0 ? err : count;
  856. }
  857. static const struct file_operations proc_oom_adj_operations = {
  858. .read = oom_adj_read,
  859. .write = oom_adj_write,
  860. .llseek = generic_file_llseek,
  861. };
  862. static ssize_t oom_score_adj_read(struct file *file, char __user *buf,
  863. size_t count, loff_t *ppos)
  864. {
  865. struct task_struct *task = get_proc_task(file_inode(file));
  866. char buffer[PROC_NUMBUF];
  867. short oom_score_adj = OOM_SCORE_ADJ_MIN;
  868. unsigned long flags;
  869. size_t len;
  870. if (!task)
  871. return -ESRCH;
  872. if (lock_task_sighand(task, &flags)) {
  873. oom_score_adj = task->signal->oom_score_adj;
  874. unlock_task_sighand(task, &flags);
  875. }
  876. put_task_struct(task);
  877. len = snprintf(buffer, sizeof(buffer), "%hd\n", oom_score_adj);
  878. return simple_read_from_buffer(buf, count, ppos, buffer, len);
  879. }
  880. static ssize_t oom_score_adj_write(struct file *file, const char __user *buf,
  881. size_t count, loff_t *ppos)
  882. {
  883. struct task_struct *task;
  884. char buffer[PROC_NUMBUF];
  885. unsigned long flags;
  886. int oom_score_adj;
  887. int err;
  888. memset(buffer, 0, sizeof(buffer));
  889. if (count > sizeof(buffer) - 1)
  890. count = sizeof(buffer) - 1;
  891. if (copy_from_user(buffer, buf, count)) {
  892. err = -EFAULT;
  893. goto out;
  894. }
  895. err = kstrtoint(strstrip(buffer), 0, &oom_score_adj);
  896. if (err)
  897. goto out;
  898. if (oom_score_adj < OOM_SCORE_ADJ_MIN ||
  899. oom_score_adj > OOM_SCORE_ADJ_MAX) {
  900. err = -EINVAL;
  901. goto out;
  902. }
  903. task = get_proc_task(file_inode(file));
  904. if (!task) {
  905. err = -ESRCH;
  906. goto out;
  907. }
  908. task_lock(task);
  909. if (!task->mm) {
  910. err = -EINVAL;
  911. goto err_task_lock;
  912. }
  913. if (!lock_task_sighand(task, &flags)) {
  914. err = -ESRCH;
  915. goto err_task_lock;
  916. }
  917. if ((short)oom_score_adj < task->signal->oom_score_adj_min &&
  918. !capable(CAP_SYS_RESOURCE)) {
  919. err = -EACCES;
  920. goto err_sighand;
  921. }
  922. task->signal->oom_score_adj = (short)oom_score_adj;
  923. if (has_capability_noaudit(current, CAP_SYS_RESOURCE))
  924. task->signal->oom_score_adj_min = (short)oom_score_adj;
  925. trace_oom_score_adj_update(task);
  926. err_sighand:
  927. unlock_task_sighand(task, &flags);
  928. err_task_lock:
  929. task_unlock(task);
  930. put_task_struct(task);
  931. out:
  932. return err < 0 ? err : count;
  933. }
  934. static const struct file_operations proc_oom_score_adj_operations = {
  935. .read = oom_score_adj_read,
  936. .write = oom_score_adj_write,
  937. .llseek = default_llseek,
  938. };
  939. #ifdef CONFIG_AUDITSYSCALL
  940. #define TMPBUFLEN 21
  941. static ssize_t proc_loginuid_read(struct file * file, char __user * buf,
  942. size_t count, loff_t *ppos)
  943. {
  944. struct inode * inode = file_inode(file);
  945. struct task_struct *task = get_proc_task(inode);
  946. ssize_t length;
  947. char tmpbuf[TMPBUFLEN];
  948. if (!task)
  949. return -ESRCH;
  950. length = scnprintf(tmpbuf, TMPBUFLEN, "%u",
  951. from_kuid(file->f_cred->user_ns,
  952. audit_get_loginuid(task)));
  953. put_task_struct(task);
  954. return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
  955. }
  956. static ssize_t proc_loginuid_write(struct file * file, const char __user * buf,
  957. size_t count, loff_t *ppos)
  958. {
  959. struct inode * inode = file_inode(file);
  960. char *page, *tmp;
  961. ssize_t length;
  962. uid_t loginuid;
  963. kuid_t kloginuid;
  964. rcu_read_lock();
  965. if (current != pid_task(proc_pid(inode), PIDTYPE_PID)) {
  966. rcu_read_unlock();
  967. return -EPERM;
  968. }
  969. rcu_read_unlock();
  970. if (count >= PAGE_SIZE)
  971. count = PAGE_SIZE - 1;
  972. if (*ppos != 0) {
  973. /* No partial writes. */
  974. return -EINVAL;
  975. }
  976. page = (char*)__get_free_page(GFP_TEMPORARY);
  977. if (!page)
  978. return -ENOMEM;
  979. length = -EFAULT;
  980. if (copy_from_user(page, buf, count))
  981. goto out_free_page;
  982. page[count] = '\0';
  983. loginuid = simple_strtoul(page, &tmp, 10);
  984. if (tmp == page) {
  985. length = -EINVAL;
  986. goto out_free_page;
  987. }
  988. kloginuid = make_kuid(file->f_cred->user_ns, loginuid);
  989. if (!uid_valid(kloginuid)) {
  990. length = -EINVAL;
  991. goto out_free_page;
  992. }
  993. length = audit_set_loginuid(kloginuid);
  994. if (likely(length == 0))
  995. length = count;
  996. out_free_page:
  997. free_page((unsigned long) page);
  998. return length;
  999. }
  1000. static const struct file_operations proc_loginuid_operations = {
  1001. .read = proc_loginuid_read,
  1002. .write = proc_loginuid_write,
  1003. .llseek = generic_file_llseek,
  1004. };
  1005. static ssize_t proc_sessionid_read(struct file * file, char __user * buf,
  1006. size_t count, loff_t *ppos)
  1007. {
  1008. struct inode * inode = file_inode(file);
  1009. struct task_struct *task = get_proc_task(inode);
  1010. ssize_t length;
  1011. char tmpbuf[TMPBUFLEN];
  1012. if (!task)
  1013. return -ESRCH;
  1014. length = scnprintf(tmpbuf, TMPBUFLEN, "%u",
  1015. audit_get_sessionid(task));
  1016. put_task_struct(task);
  1017. return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
  1018. }
  1019. static const struct file_operations proc_sessionid_operations = {
  1020. .read = proc_sessionid_read,
  1021. .llseek = generic_file_llseek,
  1022. };
  1023. #endif
  1024. #ifdef CONFIG_FAULT_INJECTION
  1025. static ssize_t proc_fault_inject_read(struct file * file, char __user * buf,
  1026. size_t count, loff_t *ppos)
  1027. {
  1028. struct task_struct *task = get_proc_task(file_inode(file));
  1029. char buffer[PROC_NUMBUF];
  1030. size_t len;
  1031. int make_it_fail;
  1032. if (!task)
  1033. return -ESRCH;
  1034. make_it_fail = task->make_it_fail;
  1035. put_task_struct(task);
  1036. len = snprintf(buffer, sizeof(buffer), "%i\n", make_it_fail);
  1037. return simple_read_from_buffer(buf, count, ppos, buffer, len);
  1038. }
  1039. static ssize_t proc_fault_inject_write(struct file * file,
  1040. const char __user * buf, size_t count, loff_t *ppos)
  1041. {
  1042. struct task_struct *task;
  1043. char buffer[PROC_NUMBUF], *end;
  1044. int make_it_fail;
  1045. if (!capable(CAP_SYS_RESOURCE))
  1046. return -EPERM;
  1047. memset(buffer, 0, sizeof(buffer));
  1048. if (count > sizeof(buffer) - 1)
  1049. count = sizeof(buffer) - 1;
  1050. if (copy_from_user(buffer, buf, count))
  1051. return -EFAULT;
  1052. make_it_fail = simple_strtol(strstrip(buffer), &end, 0);
  1053. if (*end)
  1054. return -EINVAL;
  1055. task = get_proc_task(file_inode(file));
  1056. if (!task)
  1057. return -ESRCH;
  1058. task->make_it_fail = make_it_fail;
  1059. put_task_struct(task);
  1060. return count;
  1061. }
  1062. static const struct file_operations proc_fault_inject_operations = {
  1063. .read = proc_fault_inject_read,
  1064. .write = proc_fault_inject_write,
  1065. .llseek = generic_file_llseek,
  1066. };
  1067. #endif
  1068. #ifdef CONFIG_SCHED_DEBUG
  1069. /*
  1070. * Print out various scheduling related per-task fields:
  1071. */
  1072. static int sched_show(struct seq_file *m, void *v)
  1073. {
  1074. struct inode *inode = m->private;
  1075. struct task_struct *p;
  1076. p = get_proc_task(inode);
  1077. if (!p)
  1078. return -ESRCH;
  1079. proc_sched_show_task(p, m);
  1080. put_task_struct(p);
  1081. return 0;
  1082. }
  1083. static ssize_t
  1084. sched_write(struct file *file, const char __user *buf,
  1085. size_t count, loff_t *offset)
  1086. {
  1087. struct inode *inode = file_inode(file);
  1088. struct task_struct *p;
  1089. p = get_proc_task(inode);
  1090. if (!p)
  1091. return -ESRCH;
  1092. proc_sched_set_task(p);
  1093. put_task_struct(p);
  1094. return count;
  1095. }
  1096. static int sched_open(struct inode *inode, struct file *filp)
  1097. {
  1098. return single_open(filp, sched_show, inode);
  1099. }
  1100. static const struct file_operations proc_pid_sched_operations = {
  1101. .open = sched_open,
  1102. .read = seq_read,
  1103. .write = sched_write,
  1104. .llseek = seq_lseek,
  1105. .release = single_release,
  1106. };
  1107. #endif
  1108. #ifdef CONFIG_SCHED_AUTOGROUP
  1109. /*
  1110. * Print out autogroup related information:
  1111. */
  1112. static int sched_autogroup_show(struct seq_file *m, void *v)
  1113. {
  1114. struct inode *inode = m->private;
  1115. struct task_struct *p;
  1116. p = get_proc_task(inode);
  1117. if (!p)
  1118. return -ESRCH;
  1119. proc_sched_autogroup_show_task(p, m);
  1120. put_task_struct(p);
  1121. return 0;
  1122. }
  1123. static ssize_t
  1124. sched_autogroup_write(struct file *file, const char __user *buf,
  1125. size_t count, loff_t *offset)
  1126. {
  1127. struct inode *inode = file_inode(file);
  1128. struct task_struct *p;
  1129. char buffer[PROC_NUMBUF];
  1130. int nice;
  1131. int err;
  1132. memset(buffer, 0, sizeof(buffer));
  1133. if (count > sizeof(buffer) - 1)
  1134. count = sizeof(buffer) - 1;
  1135. if (copy_from_user(buffer, buf, count))
  1136. return -EFAULT;
  1137. err = kstrtoint(strstrip(buffer), 0, &nice);
  1138. if (err < 0)
  1139. return err;
  1140. p = get_proc_task(inode);
  1141. if (!p)
  1142. return -ESRCH;
  1143. err = proc_sched_autogroup_set_nice(p, nice);
  1144. if (err)
  1145. count = err;
  1146. put_task_struct(p);
  1147. return count;
  1148. }
  1149. static int sched_autogroup_open(struct inode *inode, struct file *filp)
  1150. {
  1151. int ret;
  1152. ret = single_open(filp, sched_autogroup_show, NULL);
  1153. if (!ret) {
  1154. struct seq_file *m = filp->private_data;
  1155. m->private = inode;
  1156. }
  1157. return ret;
  1158. }
  1159. static const struct file_operations proc_pid_sched_autogroup_operations = {
  1160. .open = sched_autogroup_open,
  1161. .read = seq_read,
  1162. .write = sched_autogroup_write,
  1163. .llseek = seq_lseek,
  1164. .release = single_release,
  1165. };
  1166. #endif /* CONFIG_SCHED_AUTOGROUP */
  1167. static ssize_t comm_write(struct file *file, const char __user *buf,
  1168. size_t count, loff_t *offset)
  1169. {
  1170. struct inode *inode = file_inode(file);
  1171. struct task_struct *p;
  1172. char buffer[TASK_COMM_LEN];
  1173. memset(buffer, 0, sizeof(buffer));
  1174. if (count > sizeof(buffer) - 1)
  1175. count = sizeof(buffer) - 1;
  1176. if (copy_from_user(buffer, buf, count))
  1177. return -EFAULT;
  1178. p = get_proc_task(inode);
  1179. if (!p)
  1180. return -ESRCH;
  1181. if (same_thread_group(current, p))
  1182. set_task_comm(p, buffer);
  1183. else
  1184. count = -EINVAL;
  1185. put_task_struct(p);
  1186. return count;
  1187. }
  1188. static int comm_show(struct seq_file *m, void *v)
  1189. {
  1190. struct inode *inode = m->private;
  1191. struct task_struct *p;
  1192. p = get_proc_task(inode);
  1193. if (!p)
  1194. return -ESRCH;
  1195. task_lock(p);
  1196. seq_printf(m, "%s\n", p->comm);
  1197. task_unlock(p);
  1198. put_task_struct(p);
  1199. return 0;
  1200. }
  1201. static int comm_open(struct inode *inode, struct file *filp)
  1202. {
  1203. return single_open(filp, comm_show, inode);
  1204. }
  1205. static const struct file_operations proc_pid_set_comm_operations = {
  1206. .open = comm_open,
  1207. .read = seq_read,
  1208. .write = comm_write,
  1209. .llseek = seq_lseek,
  1210. .release = single_release,
  1211. };
  1212. static int proc_exe_link(struct dentry *dentry, struct path *exe_path)
  1213. {
  1214. struct task_struct *task;
  1215. struct mm_struct *mm;
  1216. struct file *exe_file;
  1217. task = get_proc_task(dentry->d_inode);
  1218. if (!task)
  1219. return -ENOENT;
  1220. mm = get_task_mm(task);
  1221. put_task_struct(task);
  1222. if (!mm)
  1223. return -ENOENT;
  1224. exe_file = get_mm_exe_file(mm);
  1225. mmput(mm);
  1226. if (exe_file) {
  1227. *exe_path = exe_file->f_path;
  1228. path_get(&exe_file->f_path);
  1229. fput(exe_file);
  1230. return 0;
  1231. } else
  1232. return -ENOENT;
  1233. }
  1234. static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
  1235. {
  1236. struct inode *inode = dentry->d_inode;
  1237. struct path path;
  1238. int error = -EACCES;
  1239. /* Are we allowed to snoop on the tasks file descriptors? */
  1240. if (!proc_fd_access_allowed(inode))
  1241. goto out;
  1242. error = PROC_I(inode)->op.proc_get_link(dentry, &path);
  1243. if (error)
  1244. goto out;
  1245. nd_jump_link(nd, &path);
  1246. return NULL;
  1247. out:
  1248. return ERR_PTR(error);
  1249. }
  1250. static int do_proc_readlink(struct path *path, char __user *buffer, int buflen)
  1251. {
  1252. char *tmp = (char*)__get_free_page(GFP_TEMPORARY);
  1253. char *pathname;
  1254. int len;
  1255. if (!tmp)
  1256. return -ENOMEM;
  1257. pathname = d_path(path, tmp, PAGE_SIZE);
  1258. len = PTR_ERR(pathname);
  1259. if (IS_ERR(pathname))
  1260. goto out;
  1261. len = tmp + PAGE_SIZE - 1 - pathname;
  1262. if (len > buflen)
  1263. len = buflen;
  1264. if (copy_to_user(buffer, pathname, len))
  1265. len = -EFAULT;
  1266. out:
  1267. free_page((unsigned long)tmp);
  1268. return len;
  1269. }
  1270. static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int buflen)
  1271. {
  1272. int error = -EACCES;
  1273. struct inode *inode = dentry->d_inode;
  1274. struct path path;
  1275. /* Are we allowed to snoop on the tasks file descriptors? */
  1276. if (!proc_fd_access_allowed(inode))
  1277. goto out;
  1278. error = PROC_I(inode)->op.proc_get_link(dentry, &path);
  1279. if (error)
  1280. goto out;
  1281. error = do_proc_readlink(&path, buffer, buflen);
  1282. path_put(&path);
  1283. out:
  1284. return error;
  1285. }
  1286. const struct inode_operations proc_pid_link_inode_operations = {
  1287. .readlink = proc_pid_readlink,
  1288. .follow_link = proc_pid_follow_link,
  1289. .setattr = proc_setattr,
  1290. };
  1291. /* building an inode */
  1292. struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *task)
  1293. {
  1294. struct inode * inode;
  1295. struct proc_inode *ei;
  1296. const struct cred *cred;
  1297. /* We need a new inode */
  1298. inode = new_inode(sb);
  1299. if (!inode)
  1300. goto out;
  1301. /* Common stuff */
  1302. ei = PROC_I(inode);
  1303. inode->i_ino = get_next_ino();
  1304. inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
  1305. inode->i_op = &proc_def_inode_operations;
  1306. /*
  1307. * grab the reference to task.
  1308. */
  1309. ei->pid = get_task_pid(task, PIDTYPE_PID);
  1310. if (!ei->pid)
  1311. goto out_unlock;
  1312. if (task_dumpable(task)) {
  1313. rcu_read_lock();
  1314. cred = __task_cred(task);
  1315. inode->i_uid = cred->euid;
  1316. inode->i_gid = cred->egid;
  1317. rcu_read_unlock();
  1318. }
  1319. security_task_to_inode(task, inode);
  1320. out:
  1321. return inode;
  1322. out_unlock:
  1323. iput(inode);
  1324. return NULL;
  1325. }
  1326. int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
  1327. {
  1328. struct inode *inode = dentry->d_inode;
  1329. struct task_struct *task;
  1330. const struct cred *cred;
  1331. struct pid_namespace *pid = dentry->d_sb->s_fs_info;
  1332. generic_fillattr(inode, stat);
  1333. rcu_read_lock();
  1334. stat->uid = GLOBAL_ROOT_UID;
  1335. stat->gid = GLOBAL_ROOT_GID;
  1336. task = pid_task(proc_pid(inode), PIDTYPE_PID);
  1337. if (task) {
  1338. if (!has_pid_permissions(pid, task, 2)) {
  1339. rcu_read_unlock();
  1340. /*
  1341. * This doesn't prevent learning whether PID exists,
  1342. * it only makes getattr() consistent with readdir().
  1343. */
  1344. return -ENOENT;
  1345. }
  1346. if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
  1347. task_dumpable(task)) {
  1348. cred = __task_cred(task);
  1349. stat->uid = cred->euid;
  1350. stat->gid = cred->egid;
  1351. }
  1352. }
  1353. rcu_read_unlock();
  1354. return 0;
  1355. }
  1356. /* dentry stuff */
  1357. /*
  1358. * Exceptional case: normally we are not allowed to unhash a busy
  1359. * directory. In this case, however, we can do it - no aliasing problems
  1360. * due to the way we treat inodes.
  1361. *
  1362. * Rewrite the inode's ownerships here because the owning task may have
  1363. * performed a setuid(), etc.
  1364. *
  1365. * Before the /proc/pid/status file was created the only way to read
  1366. * the effective uid of a /process was to stat /proc/pid. Reading
  1367. * /proc/pid/status is slow enough that procps and other packages
  1368. * kept stating /proc/pid. To keep the rules in /proc simple I have
  1369. * made this apply to all per process world readable and executable
  1370. * directories.
  1371. */
  1372. int pid_revalidate(struct dentry *dentry, unsigned int flags)
  1373. {
  1374. struct inode *inode;
  1375. struct task_struct *task;
  1376. const struct cred *cred;
  1377. if (flags & LOOKUP_RCU)
  1378. return -ECHILD;
  1379. inode = dentry->d_inode;
  1380. task = get_proc_task(inode);
  1381. if (task) {
  1382. if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
  1383. task_dumpable(task)) {
  1384. rcu_read_lock();
  1385. cred = __task_cred(task);
  1386. inode->i_uid = cred->euid;
  1387. inode->i_gid = cred->egid;
  1388. rcu_read_unlock();
  1389. } else {
  1390. inode->i_uid = GLOBAL_ROOT_UID;
  1391. inode->i_gid = GLOBAL_ROOT_GID;
  1392. }
  1393. inode->i_mode &= ~(S_ISUID | S_ISGID);
  1394. security_task_to_inode(task, inode);
  1395. put_task_struct(task);
  1396. return 1;
  1397. }
  1398. d_drop(dentry);
  1399. return 0;
  1400. }
  1401. int pid_delete_dentry(const struct dentry *dentry)
  1402. {
  1403. /* Is the task we represent dead?
  1404. * If so, then don't put the dentry on the lru list,
  1405. * kill it immediately.
  1406. */
  1407. return !proc_pid(dentry->d_inode)->tasks[PIDTYPE_PID].first;
  1408. }
  1409. const struct dentry_operations pid_dentry_operations =
  1410. {
  1411. .d_revalidate = pid_revalidate,
  1412. .d_delete = pid_delete_dentry,
  1413. };
  1414. /* Lookups */
  1415. /*
  1416. * Fill a directory entry.
  1417. *
  1418. * If possible create the dcache entry and derive our inode number and
  1419. * file type from dcache entry.
  1420. *
  1421. * Since all of the proc inode numbers are dynamically generated, the inode
  1422. * numbers do not exist until the inode is cache. This means creating the
  1423. * the dcache entry in readdir is necessary to keep the inode numbers
  1424. * reported by readdir in sync with the inode numbers reported
  1425. * by stat.
  1426. */
  1427. int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
  1428. const char *name, int len,
  1429. instantiate_t instantiate, struct task_struct *task, const void *ptr)
  1430. {
  1431. struct dentry *child, *dir = filp->f_path.dentry;
  1432. struct inode *inode;
  1433. struct qstr qname;
  1434. ino_t ino = 0;
  1435. unsigned type = DT_UNKNOWN;
  1436. qname.name = name;
  1437. qname.len = len;
  1438. qname.hash = full_name_hash(name, len);
  1439. child = d_lookup(dir, &qname);
  1440. if (!child) {
  1441. struct dentry *new;
  1442. new = d_alloc(dir, &qname);
  1443. if (new) {
  1444. child = instantiate(dir->d_inode, new, task, ptr);
  1445. if (child)
  1446. dput(new);
  1447. else
  1448. child = new;
  1449. }
  1450. }
  1451. if (!child || IS_ERR(child) || !child->d_inode)
  1452. goto end_instantiate;
  1453. inode = child->d_inode;
  1454. if (inode) {
  1455. ino = inode->i_ino;
  1456. type = inode->i_mode >> 12;
  1457. }
  1458. dput(child);
  1459. end_instantiate:
  1460. if (!ino)
  1461. ino = find_inode_number(dir, &qname);
  1462. if (!ino)
  1463. ino = 1;
  1464. return filldir(dirent, name, len, filp->f_pos, ino, type);
  1465. }
  1466. #ifdef CONFIG_CHECKPOINT_RESTORE
  1467. /*
  1468. * dname_to_vma_addr - maps a dentry name into two unsigned longs
  1469. * which represent vma start and end addresses.
  1470. */
  1471. static int dname_to_vma_addr(struct dentry *dentry,
  1472. unsigned long *start, unsigned long *end)
  1473. {
  1474. if (sscanf(dentry->d_name.name, "%lx-%lx", start, end) != 2)
  1475. return -EINVAL;
  1476. return 0;
  1477. }
  1478. static int map_files_d_revalidate(struct dentry *dentry, unsigned int flags)
  1479. {
  1480. unsigned long vm_start, vm_end;
  1481. bool exact_vma_exists = false;
  1482. struct mm_struct *mm = NULL;
  1483. struct task_struct *task;
  1484. const struct cred *cred;
  1485. struct inode *inode;
  1486. int status = 0;
  1487. if (flags & LOOKUP_RCU)
  1488. return -ECHILD;
  1489. if (!capable(CAP_SYS_ADMIN)) {
  1490. status = -EPERM;
  1491. goto out_notask;
  1492. }
  1493. inode = dentry->d_inode;
  1494. task = get_proc_task(inode);
  1495. if (!task)
  1496. goto out_notask;
  1497. mm = mm_access(task, PTRACE_MODE_READ);
  1498. if (IS_ERR_OR_NULL(mm))
  1499. goto out;
  1500. if (!dname_to_vma_addr(dentry, &vm_start, &vm_end)) {
  1501. down_read(&mm->mmap_sem);
  1502. exact_vma_exists = !!find_exact_vma(mm, vm_start, vm_end);
  1503. up_read(&mm->mmap_sem);
  1504. }
  1505. mmput(mm);
  1506. if (exact_vma_exists) {
  1507. if (task_dumpable(task)) {
  1508. rcu_read_lock();
  1509. cred = __task_cred(task);
  1510. inode->i_uid = cred->euid;
  1511. inode->i_gid = cred->egid;
  1512. rcu_read_unlock();
  1513. } else {
  1514. inode->i_uid = GLOBAL_ROOT_UID;
  1515. inode->i_gid = GLOBAL_ROOT_GID;
  1516. }
  1517. security_task_to_inode(task, inode);
  1518. status = 1;
  1519. }
  1520. out:
  1521. put_task_struct(task);
  1522. out_notask:
  1523. if (status <= 0)
  1524. d_drop(dentry);
  1525. return status;
  1526. }
  1527. static const struct dentry_operations tid_map_files_dentry_operations = {
  1528. .d_revalidate = map_files_d_revalidate,
  1529. .d_delete = pid_delete_dentry,
  1530. };
  1531. static int proc_map_files_get_link(struct dentry *dentry, struct path *path)
  1532. {
  1533. unsigned long vm_start, vm_end;
  1534. struct vm_area_struct *vma;
  1535. struct task_struct *task;
  1536. struct mm_struct *mm;
  1537. int rc;
  1538. rc = -ENOENT;
  1539. task = get_proc_task(dentry->d_inode);
  1540. if (!task)
  1541. goto out;
  1542. mm = get_task_mm(task);
  1543. put_task_struct(task);
  1544. if (!mm)
  1545. goto out;
  1546. rc = dname_to_vma_addr(dentry, &vm_start, &vm_end);
  1547. if (rc)
  1548. goto out_mmput;
  1549. down_read(&mm->mmap_sem);
  1550. vma = find_exact_vma(mm, vm_start, vm_end);
  1551. if (vma && vma->vm_file) {
  1552. *path = vma->vm_file->f_path;
  1553. path_get(path);
  1554. rc = 0;
  1555. }
  1556. up_read(&mm->mmap_sem);
  1557. out_mmput:
  1558. mmput(mm);
  1559. out:
  1560. return rc;
  1561. }
  1562. struct map_files_info {
  1563. fmode_t mode;
  1564. unsigned long len;
  1565. unsigned char name[4*sizeof(long)+2]; /* max: %lx-%lx\0 */
  1566. };
  1567. static struct dentry *
  1568. proc_map_files_instantiate(struct inode *dir, struct dentry *dentry,
  1569. struct task_struct *task, const void *ptr)
  1570. {
  1571. fmode_t mode = (fmode_t)(unsigned long)ptr;
  1572. struct proc_inode *ei;
  1573. struct inode *inode;
  1574. inode = proc_pid_make_inode(dir->i_sb, task);
  1575. if (!inode)
  1576. return ERR_PTR(-ENOENT);
  1577. ei = PROC_I(inode);
  1578. ei->op.proc_get_link = proc_map_files_get_link;
  1579. inode->i_op = &proc_pid_link_inode_operations;
  1580. inode->i_size = 64;
  1581. inode->i_mode = S_IFLNK;
  1582. if (mode & FMODE_READ)
  1583. inode->i_mode |= S_IRUSR;
  1584. if (mode & FMODE_WRITE)
  1585. inode->i_mode |= S_IWUSR;
  1586. d_set_d_op(dentry, &tid_map_files_dentry_operations);
  1587. d_add(dentry, inode);
  1588. return NULL;
  1589. }
  1590. static struct dentry *proc_map_files_lookup(struct inode *dir,
  1591. struct dentry *dentry, unsigned int flags)
  1592. {
  1593. unsigned long vm_start, vm_end;
  1594. struct vm_area_struct *vma;
  1595. struct task_struct *task;
  1596. struct dentry *result;
  1597. struct mm_struct *mm;
  1598. result = ERR_PTR(-EPERM);
  1599. if (!capable(CAP_SYS_ADMIN))
  1600. goto out;
  1601. result = ERR_PTR(-ENOENT);
  1602. task = get_proc_task(dir);
  1603. if (!task)
  1604. goto out;
  1605. result = ERR_PTR(-EACCES);
  1606. if (!ptrace_may_access(task, PTRACE_MODE_READ))
  1607. goto out_put_task;
  1608. result = ERR_PTR(-ENOENT);
  1609. if (dname_to_vma_addr(dentry, &vm_start, &vm_end))
  1610. goto out_put_task;
  1611. mm = get_task_mm(task);
  1612. if (!mm)
  1613. goto out_put_task;
  1614. down_read(&mm->mmap_sem);
  1615. vma = find_exact_vma(mm, vm_start, vm_end);
  1616. if (!vma)
  1617. goto out_no_vma;
  1618. if (vma->vm_file)
  1619. result = proc_map_files_instantiate(dir, dentry, task,
  1620. (void *)(unsigned long)vma->vm_file->f_mode);
  1621. out_no_vma:
  1622. up_read(&mm->mmap_sem);
  1623. mmput(mm);
  1624. out_put_task:
  1625. put_task_struct(task);
  1626. out:
  1627. return result;
  1628. }
  1629. static const struct inode_operations proc_map_files_inode_operations = {
  1630. .lookup = proc_map_files_lookup,
  1631. .permission = proc_fd_permission,
  1632. .setattr = proc_setattr,
  1633. };
  1634. static int
  1635. proc_map_files_readdir(struct file *filp, void *dirent, filldir_t filldir)
  1636. {
  1637. struct dentry *dentry = filp->f_path.dentry;
  1638. struct inode *inode = dentry->d_inode;
  1639. struct vm_area_struct *vma;
  1640. struct task_struct *task;
  1641. struct mm_struct *mm;
  1642. ino_t ino;
  1643. int ret;
  1644. ret = -EPERM;
  1645. if (!capable(CAP_SYS_ADMIN))
  1646. goto out;
  1647. ret = -ENOENT;
  1648. task = get_proc_task(inode);
  1649. if (!task)
  1650. goto out;
  1651. ret = -EACCES;
  1652. if (!ptrace_may_access(task, PTRACE_MODE_READ))
  1653. goto out_put_task;
  1654. ret = 0;
  1655. switch (filp->f_pos) {
  1656. case 0:
  1657. ino = inode->i_ino;
  1658. if (filldir(dirent, ".", 1, 0, ino, DT_DIR) < 0)
  1659. goto out_put_task;
  1660. filp->f_pos++;
  1661. case 1:
  1662. ino = parent_ino(dentry);
  1663. if (filldir(dirent, "..", 2, 1, ino, DT_DIR) < 0)
  1664. goto out_put_task;
  1665. filp->f_pos++;
  1666. default:
  1667. {
  1668. unsigned long nr_files, pos, i;
  1669. struct flex_array *fa = NULL;
  1670. struct map_files_info info;
  1671. struct map_files_info *p;
  1672. mm = get_task_mm(task);
  1673. if (!mm)
  1674. goto out_put_task;
  1675. down_read(&mm->mmap_sem);
  1676. nr_files = 0;
  1677. /*
  1678. * We need two passes here:
  1679. *
  1680. * 1) Collect vmas of mapped files with mmap_sem taken
  1681. * 2) Release mmap_sem and instantiate entries
  1682. *
  1683. * otherwise we get lockdep complained, since filldir()
  1684. * routine might require mmap_sem taken in might_fault().
  1685. */
  1686. for (vma = mm->mmap, pos = 2; vma; vma = vma->vm_next) {
  1687. if (vma->vm_file && ++pos > filp->f_pos)
  1688. nr_files++;
  1689. }
  1690. if (nr_files) {
  1691. fa = flex_array_alloc(sizeof(info), nr_files,
  1692. GFP_KERNEL);
  1693. if (!fa || flex_array_prealloc(fa, 0, nr_files,
  1694. GFP_KERNEL)) {
  1695. ret = -ENOMEM;
  1696. if (fa)
  1697. flex_array_free(fa);
  1698. up_read(&mm->mmap_sem);
  1699. mmput(mm);
  1700. goto out_put_task;
  1701. }
  1702. for (i = 0, vma = mm->mmap, pos = 2; vma;
  1703. vma = vma->vm_next) {
  1704. if (!vma->vm_file)
  1705. continue;
  1706. if (++pos <= filp->f_pos)
  1707. continue;
  1708. info.mode = vma->vm_file->f_mode;
  1709. info.len = snprintf(info.name,
  1710. sizeof(info.name), "%lx-%lx",
  1711. vma->vm_start, vma->vm_end);
  1712. if (flex_array_put(fa, i++, &info, GFP_KERNEL))
  1713. BUG();
  1714. }
  1715. }
  1716. up_read(&mm->mmap_sem);
  1717. for (i = 0; i < nr_files; i++) {
  1718. p = flex_array_get(fa, i);
  1719. ret = proc_fill_cache(filp, dirent, filldir,
  1720. p->name, p->len,
  1721. proc_map_files_instantiate,
  1722. task,
  1723. (void *)(unsigned long)p->mode);
  1724. if (ret)
  1725. break;
  1726. filp->f_pos++;
  1727. }
  1728. if (fa)
  1729. flex_array_free(fa);
  1730. mmput(mm);
  1731. }
  1732. }
  1733. out_put_task:
  1734. put_task_struct(task);
  1735. out:
  1736. return ret;
  1737. }
  1738. static const struct file_operations proc_map_files_operations = {
  1739. .read = generic_read_dir,
  1740. .readdir = proc_map_files_readdir,
  1741. .llseek = default_llseek,
  1742. };
  1743. #endif /* CONFIG_CHECKPOINT_RESTORE */
  1744. static struct dentry *proc_pident_instantiate(struct inode *dir,
  1745. struct dentry *dentry, struct task_struct *task, const void *ptr)
  1746. {
  1747. const struct pid_entry *p = ptr;
  1748. struct inode *inode;
  1749. struct proc_inode *ei;
  1750. struct dentry *error = ERR_PTR(-ENOENT);
  1751. inode = proc_pid_make_inode(dir->i_sb, task);
  1752. if (!inode)
  1753. goto out;
  1754. ei = PROC_I(inode);
  1755. inode->i_mode = p->mode;
  1756. if (S_ISDIR(inode->i_mode))
  1757. set_nlink(inode, 2); /* Use getattr to fix if necessary */
  1758. if (p->iop)
  1759. inode->i_op = p->iop;
  1760. if (p->fop)
  1761. inode->i_fop = p->fop;
  1762. ei->op = p->op;
  1763. d_set_d_op(dentry, &pid_dentry_operations);
  1764. d_add(dentry, inode);
  1765. /* Close the race of the process dying before we return the dentry */
  1766. if (pid_revalidate(dentry, 0))
  1767. error = NULL;
  1768. out:
  1769. return error;
  1770. }
  1771. static struct dentry *proc_pident_lookup(struct inode *dir,
  1772. struct dentry *dentry,
  1773. const struct pid_entry *ents,
  1774. unsigned int nents)
  1775. {
  1776. struct dentry *error;
  1777. struct task_struct *task = get_proc_task(dir);
  1778. const struct pid_entry *p, *last;
  1779. error = ERR_PTR(-ENOENT);
  1780. if (!task)
  1781. goto out_no_task;
  1782. /*
  1783. * Yes, it does not scale. And it should not. Don't add
  1784. * new entries into /proc/<tgid>/ without very good reasons.
  1785. */
  1786. last = &ents[nents - 1];
  1787. for (p = ents; p <= last; p++) {
  1788. if (p->len != dentry->d_name.len)
  1789. continue;
  1790. if (!memcmp(dentry->d_name.name, p->name, p->len))
  1791. break;
  1792. }
  1793. if (p > last)
  1794. goto out;
  1795. error = proc_pident_instantiate(dir, dentry, task, p);
  1796. out:
  1797. put_task_struct(task);
  1798. out_no_task:
  1799. return error;
  1800. }
  1801. static int proc_pident_fill_cache(struct file *filp, void *dirent,
  1802. filldir_t filldir, struct task_struct *task, const struct pid_entry *p)
  1803. {
  1804. return proc_fill_cache(filp, dirent, filldir, p->name, p->len,
  1805. proc_pident_instantiate, task, p);
  1806. }
  1807. static int proc_pident_readdir(struct file *filp,
  1808. void *dirent, filldir_t filldir,
  1809. const struct pid_entry *ents, unsigned int nents)
  1810. {
  1811. int i;
  1812. struct dentry *dentry = filp->f_path.dentry;
  1813. struct inode *inode = dentry->d_inode;
  1814. struct task_struct *task = get_proc_task(inode);
  1815. const struct pid_entry *p, *last;
  1816. ino_t ino;
  1817. int ret;
  1818. ret = -ENOENT;
  1819. if (!task)
  1820. goto out_no_task;
  1821. ret = 0;
  1822. i = filp->f_pos;
  1823. switch (i) {
  1824. case 0:
  1825. ino = inode->i_ino;
  1826. if (filldir(dirent, ".", 1, i, ino, DT_DIR) < 0)
  1827. goto out;
  1828. i++;
  1829. filp->f_pos++;
  1830. /* fall through */
  1831. case 1:
  1832. ino = parent_ino(dentry);
  1833. if (filldir(dirent, "..", 2, i, ino, DT_DIR) < 0)
  1834. goto out;
  1835. i++;
  1836. filp->f_pos++;
  1837. /* fall through */
  1838. default:
  1839. i -= 2;
  1840. if (i >= nents) {
  1841. ret = 1;
  1842. goto out;
  1843. }
  1844. p = ents + i;
  1845. last = &ents[nents - 1];
  1846. while (p <= last) {
  1847. if (proc_pident_fill_cache(filp, dirent, filldir, task, p) < 0)
  1848. goto out;
  1849. filp->f_pos++;
  1850. p++;
  1851. }
  1852. }
  1853. ret = 1;
  1854. out:
  1855. put_task_struct(task);
  1856. out_no_task:
  1857. return ret;
  1858. }
  1859. #ifdef CONFIG_SECURITY
  1860. static ssize_t proc_pid_attr_read(struct file * file, char __user * buf,
  1861. size_t count, loff_t *ppos)
  1862. {
  1863. struct inode * inode = file_inode(file);
  1864. char *p = NULL;
  1865. ssize_t length;
  1866. struct task_struct *task = get_proc_task(inode);
  1867. if (!task)
  1868. return -ESRCH;
  1869. length = security_getprocattr(task,
  1870. (char*)file->f_path.dentry->d_name.name,
  1871. &p);
  1872. put_task_struct(task);
  1873. if (length > 0)
  1874. length = simple_read_from_buffer(buf, count, ppos, p, length);
  1875. kfree(p);
  1876. return length;
  1877. }
  1878. static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
  1879. size_t count, loff_t *ppos)
  1880. {
  1881. struct inode * inode = file_inode(file);
  1882. char *page;
  1883. ssize_t length;
  1884. struct task_struct *task = get_proc_task(inode);
  1885. length = -ESRCH;
  1886. if (!task)
  1887. goto out_no_task;
  1888. if (count > PAGE_SIZE)
  1889. count = PAGE_SIZE;
  1890. /* No partial writes. */
  1891. length = -EINVAL;
  1892. if (*ppos != 0)
  1893. goto out;
  1894. length = -ENOMEM;
  1895. page = (char*)__get_free_page(GFP_TEMPORARY);
  1896. if (!page)
  1897. goto out;
  1898. length = -EFAULT;
  1899. if (copy_from_user(page, buf, count))
  1900. goto out_free;
  1901. /* Guard against adverse ptrace interaction */
  1902. length = mutex_lock_interruptible(&task->signal->cred_guard_mutex);
  1903. if (length < 0)
  1904. goto out_free;
  1905. length = security_setprocattr(task,
  1906. (char*)file->f_path.dentry->d_name.name,
  1907. (void*)page, count);
  1908. mutex_unlock(&task->signal->cred_guard_mutex);
  1909. out_free:
  1910. free_page((unsigned long) page);
  1911. out:
  1912. put_task_struct(task);
  1913. out_no_task:
  1914. return length;
  1915. }
  1916. static const struct file_operations proc_pid_attr_operations = {
  1917. .read = proc_pid_attr_read,
  1918. .write = proc_pid_attr_write,
  1919. .llseek = generic_file_llseek,
  1920. };
  1921. static const struct pid_entry attr_dir_stuff[] = {
  1922. REG("current", S_IRUGO|S_IWUGO, proc_pid_attr_operations),
  1923. REG("prev", S_IRUGO, proc_pid_attr_operations),
  1924. REG("exec", S_IRUGO|S_IWUGO, proc_pid_attr_operations),
  1925. REG("fscreate", S_IRUGO|S_IWUGO, proc_pid_attr_operations),
  1926. REG("keycreate", S_IRUGO|S_IWUGO, proc_pid_attr_operations),
  1927. REG("sockcreate", S_IRUGO|S_IWUGO, proc_pid_attr_operations),
  1928. };
  1929. static int proc_attr_dir_readdir(struct file * filp,
  1930. void * dirent, filldir_t filldir)
  1931. {
  1932. return proc_pident_readdir(filp,dirent,filldir,
  1933. attr_dir_stuff,ARRAY_SIZE(attr_dir_stuff));
  1934. }
  1935. static const struct file_operations proc_attr_dir_operations = {
  1936. .read = generic_read_dir,
  1937. .readdir = proc_attr_dir_readdir,
  1938. .llseek = default_llseek,
  1939. };
  1940. static struct dentry *proc_attr_dir_lookup(struct inode *dir,
  1941. struct dentry *dentry, unsigned int flags)
  1942. {
  1943. return proc_pident_lookup(dir, dentry,
  1944. attr_dir_stuff, ARRAY_SIZE(attr_dir_stuff));
  1945. }
  1946. static const struct inode_operations proc_attr_dir_inode_operations = {
  1947. .lookup = proc_attr_dir_lookup,
  1948. .getattr = pid_getattr,
  1949. .setattr = proc_setattr,
  1950. };
  1951. #endif
  1952. #ifdef CONFIG_ELF_CORE
  1953. static ssize_t proc_coredump_filter_read(struct file *file, char __user *buf,
  1954. size_t count, loff_t *ppos)
  1955. {
  1956. struct task_struct *task = get_proc_task(file_inode(file));
  1957. struct mm_struct *mm;
  1958. char buffer[PROC_NUMBUF];
  1959. size_t len;
  1960. int ret;
  1961. if (!task)
  1962. return -ESRCH;
  1963. ret = 0;
  1964. mm = get_task_mm(task);
  1965. if (mm) {
  1966. len = snprintf(buffer, sizeof(buffer), "%08lx\n",
  1967. ((mm->flags & MMF_DUMP_FILTER_MASK) >>
  1968. MMF_DUMP_FILTER_SHIFT));
  1969. mmput(mm);
  1970. ret = simple_read_from_buffer(buf, count, ppos, buffer, len);
  1971. }
  1972. put_task_struct(task);
  1973. return ret;
  1974. }
  1975. static ssize_t proc_coredump_filter_write(struct file *file,
  1976. const char __user *buf,
  1977. size_t count,
  1978. loff_t *ppos)
  1979. {
  1980. struct task_struct *task;
  1981. struct mm_struct *mm;
  1982. char buffer[PROC_NUMBUF], *end;
  1983. unsigned int val;
  1984. int ret;
  1985. int i;
  1986. unsigned long mask;
  1987. ret = -EFAULT;
  1988. memset(buffer, 0, sizeof(buffer));
  1989. if (count > sizeof(buffer) - 1)
  1990. count = sizeof(buffer) - 1;
  1991. if (copy_from_user(buffer, buf, count))
  1992. goto out_no_task;
  1993. ret = -EINVAL;
  1994. val = (unsigned int)simple_strtoul(buffer, &end, 0);
  1995. if (*end == '\n')
  1996. end++;
  1997. if (end - buffer == 0)
  1998. goto out_no_task;
  1999. ret = -ESRCH;
  2000. task = get_proc_task(file_inode(file));
  2001. if (!task)
  2002. goto out_no_task;
  2003. ret = end - buffer;
  2004. mm = get_task_mm(task);
  2005. if (!mm)
  2006. goto out_no_mm;
  2007. for (i = 0, mask = 1; i < MMF_DUMP_FILTER_BITS; i++, mask <<= 1) {
  2008. if (val & mask)
  2009. set_bit(i + MMF_DUMP_FILTER_SHIFT, &mm->flags);
  2010. else
  2011. clear_bit(i + MMF_DUMP_FILTER_SHIFT, &mm->flags);
  2012. }
  2013. mmput(mm);
  2014. out_no_mm:
  2015. put_task_struct(task);
  2016. out_no_task:
  2017. return ret;
  2018. }
  2019. static const struct file_operations proc_coredump_filter_operations = {
  2020. .read = proc_coredump_filter_read,
  2021. .write = proc_coredump_filter_write,
  2022. .llseek = generic_file_llseek,
  2023. };
  2024. #endif
  2025. #ifdef CONFIG_TASK_IO_ACCOUNTING
  2026. static int do_io_accounting(struct task_struct *task, char *buffer, int whole)
  2027. {
  2028. struct task_io_accounting acct = task->ioac;
  2029. unsigned long flags;
  2030. int result;
  2031. result = mutex_lock_killable(&task->signal->cred_guard_mutex);
  2032. if (result)
  2033. return result;
  2034. if (!ptrace_may_access(task, PTRACE_MODE_READ)) {
  2035. result = -EACCES;
  2036. goto out_unlock;
  2037. }
  2038. if (whole && lock_task_sighand(task, &flags)) {
  2039. struct task_struct *t = task;
  2040. task_io_accounting_add(&acct, &task->signal->ioac);
  2041. while_each_thread(task, t)
  2042. task_io_accounting_add(&acct, &t->ioac);
  2043. unlock_task_sighand(task, &flags);
  2044. }
  2045. result = sprintf(buffer,
  2046. "rchar: %llu\n"
  2047. "wchar: %llu\n"
  2048. "syscr: %llu\n"
  2049. "syscw: %llu\n"
  2050. "read_bytes: %llu\n"
  2051. "write_bytes: %llu\n"
  2052. "cancelled_write_bytes: %llu\n",
  2053. (unsigned long long)acct.rchar,
  2054. (unsigned long long)acct.wchar,
  2055. (unsigned long long)acct.syscr,
  2056. (unsigned long long)acct.syscw,
  2057. (unsigned long long)acct.read_bytes,
  2058. (unsigned long long)acct.write_bytes,
  2059. (unsigned long long)acct.cancelled_write_bytes);
  2060. out_unlock:
  2061. mutex_unlock(&task->signal->cred_guard_mutex);
  2062. return result;
  2063. }
  2064. static int proc_tid_io_accounting(struct task_struct *task, char *buffer)
  2065. {
  2066. return do_io_accounting(task, buffer, 0);
  2067. }
  2068. static int proc_tgid_io_accounting(struct task_struct *task, char *buffer)
  2069. {
  2070. return do_io_accounting(task, buffer, 1);
  2071. }
  2072. #endif /* CONFIG_TASK_IO_ACCOUNTING */
  2073. #ifdef CONFIG_USER_NS
  2074. static int proc_id_map_open(struct inode *inode, struct file *file,
  2075. struct seq_operations *seq_ops)
  2076. {
  2077. struct user_namespace *ns = NULL;
  2078. struct task_struct *task;
  2079. struct seq_file *seq;
  2080. int ret = -EINVAL;
  2081. task = get_proc_task(inode);
  2082. if (task) {
  2083. rcu_read_lock();
  2084. ns = get_user_ns(task_cred_xxx(task, user_ns));
  2085. rcu_read_unlock();
  2086. put_task_struct(task);
  2087. }
  2088. if (!ns)
  2089. goto err;
  2090. ret = seq_open(file, seq_ops);
  2091. if (ret)
  2092. goto err_put_ns;
  2093. seq = file->private_data;
  2094. seq->private = ns;
  2095. return 0;
  2096. err_put_ns:
  2097. put_user_ns(ns);
  2098. err:
  2099. return ret;
  2100. }
  2101. static int proc_id_map_release(struct inode *inode, struct file *file)
  2102. {
  2103. struct seq_file *seq = file->private_data;
  2104. struct user_namespace *ns = seq->private;
  2105. put_user_ns(ns);
  2106. return seq_release(inode, file);
  2107. }
  2108. static int proc_uid_map_open(struct inode *inode, struct file *file)
  2109. {
  2110. return proc_id_map_open(inode, file, &proc_uid_seq_operations);
  2111. }
  2112. static int proc_gid_map_open(struct inode *inode, struct file *file)
  2113. {
  2114. return proc_id_map_open(inode, file, &proc_gid_seq_operations);
  2115. }
  2116. static int proc_projid_map_open(struct inode *inode, struct file *file)
  2117. {
  2118. return proc_id_map_open(inode, file, &proc_projid_seq_operations);
  2119. }
  2120. static const struct file_operations proc_uid_map_operations = {
  2121. .open = proc_uid_map_open,
  2122. .write = proc_uid_map_write,
  2123. .read = seq_read,
  2124. .llseek = seq_lseek,
  2125. .release = proc_id_map_release,
  2126. };
  2127. static const struct file_operations proc_gid_map_operations = {
  2128. .open = proc_gid_map_open,
  2129. .write = proc_gid_map_write,
  2130. .read = seq_read,
  2131. .llseek = seq_lseek,
  2132. .release = proc_id_map_release,
  2133. };
  2134. static const struct file_operations proc_projid_map_operations = {
  2135. .open = proc_projid_map_open,
  2136. .write = proc_projid_map_write,
  2137. .read = seq_read,
  2138. .llseek = seq_lseek,
  2139. .release = proc_id_map_release,
  2140. };
  2141. #endif /* CONFIG_USER_NS */
  2142. static int proc_pid_personality(struct seq_file *m, struct pid_namespace *ns,
  2143. struct pid *pid, struct task_struct *task)
  2144. {
  2145. int err = lock_trace(task);
  2146. if (!err) {
  2147. seq_printf(m, "%08x\n", task->personality);
  2148. unlock_trace(task);
  2149. }
  2150. return err;
  2151. }
  2152. /*
  2153. * Thread groups
  2154. */
  2155. static const struct file_operations proc_task_operations;
  2156. static const struct inode_operations proc_task_inode_operations;
  2157. static const struct pid_entry tgid_base_stuff[] = {
  2158. DIR("task", S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
  2159. DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
  2160. #ifdef CONFIG_CHECKPOINT_RESTORE
  2161. DIR("map_files", S_IRUSR|S_IXUSR, proc_map_files_inode_operations, proc_map_files_operations),
  2162. #endif
  2163. DIR("fdinfo", S_IRUSR|S_IXUSR, proc_fdinfo_inode_operations, proc_fdinfo_operations),
  2164. DIR("ns", S_IRUSR|S_IXUGO, proc_ns_dir_inode_operations, proc_ns_dir_operations),
  2165. #ifdef CONFIG_NET
  2166. DIR("net", S_IRUGO|S_IXUGO, proc_net_inode_operations, proc_net_operations),
  2167. #endif
  2168. REG("environ", S_IRUSR, proc_environ_operations),
  2169. INF("auxv", S_IRUSR, proc_pid_auxv),
  2170. ONE("status", S_IRUGO, proc_pid_status),
  2171. ONE("personality", S_IRUGO, proc_pid_personality),
  2172. INF("limits", S_IRUGO, proc_pid_limits),
  2173. #ifdef CONFIG_SCHED_DEBUG
  2174. REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
  2175. #endif
  2176. #ifdef CONFIG_SCHED_AUTOGROUP
  2177. REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
  2178. #endif
  2179. REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
  2180. #ifdef CONFIG_HAVE_ARCH_TRACEHOOK
  2181. INF("syscall", S_IRUGO, proc_pid_syscall),
  2182. #endif
  2183. INF("cmdline", S_IRUGO, proc_pid_cmdline),
  2184. ONE("stat", S_IRUGO, proc_tgid_stat),
  2185. ONE("statm", S_IRUGO, proc_pid_statm),
  2186. REG("maps", S_IRUGO, proc_pid_maps_operations),
  2187. #ifdef CONFIG_NUMA
  2188. REG("numa_maps", S_IRUGO, proc_pid_numa_maps_operations),
  2189. #endif
  2190. REG("mem", S_IRUSR|S_IWUSR, proc_mem_operations),
  2191. LNK("cwd", proc_cwd_link),
  2192. LNK("root", proc_root_link),
  2193. LNK("exe", proc_exe_link),
  2194. REG("mounts", S_IRUGO, proc_mounts_operations),
  2195. REG("mountinfo", S_IRUGO, proc_mountinfo_operations),
  2196. REG("mountstats", S_IRUSR, proc_mountstats_operations),
  2197. #ifdef CONFIG_PROC_PAGE_MONITOR
  2198. REG("clear_refs", S_IWUSR, proc_clear_refs_operations),
  2199. REG("smaps", S_IRUGO, proc_pid_smaps_operations),
  2200. REG("pagemap", S_IRUGO, proc_pagemap_operations),
  2201. #endif
  2202. #ifdef CONFIG_SECURITY
  2203. DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
  2204. #endif
  2205. #ifdef CONFIG_KALLSYMS
  2206. INF("wchan", S_IRUGO, proc_pid_wchan),
  2207. #endif
  2208. #ifdef CONFIG_STACKTRACE
  2209. ONE("stack", S_IRUGO, proc_pid_stack),
  2210. #endif
  2211. #ifdef CONFIG_SCHEDSTATS
  2212. INF("schedstat", S_IRUGO, proc_pid_schedstat),
  2213. #endif
  2214. #ifdef CONFIG_LATENCYTOP
  2215. REG("latency", S_IRUGO, proc_lstats_operations),
  2216. #endif
  2217. #ifdef CONFIG_PROC_PID_CPUSET
  2218. REG("cpuset", S_IRUGO, proc_cpuset_operations),
  2219. #endif
  2220. #ifdef CONFIG_CGROUPS
  2221. REG("cgroup", S_IRUGO, proc_cgroup_operations),
  2222. #endif
  2223. INF("oom_score", S_IRUGO, proc_oom_score),
  2224. REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adj_operations),
  2225. REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
  2226. #ifdef CONFIG_AUDITSYSCALL
  2227. REG("loginuid", S_IWUSR|S_IRUGO, proc_loginuid_operations),
  2228. REG("sessionid", S_IRUGO, proc_sessionid_operations),
  2229. #endif
  2230. #ifdef CONFIG_FAULT_INJECTION
  2231. REG("make-it-fail", S_IRUGO|S_IWUSR, proc_fault_inject_operations),
  2232. #endif
  2233. #ifdef CONFIG_ELF_CORE
  2234. REG("coredump_filter", S_IRUGO|S_IWUSR, proc_coredump_filter_operations),
  2235. #endif
  2236. #ifdef CONFIG_TASK_IO_ACCOUNTING
  2237. INF("io", S_IRUSR, proc_tgid_io_accounting),
  2238. #endif
  2239. #ifdef CONFIG_HARDWALL
  2240. INF("hardwall", S_IRUGO, proc_pid_hardwall),
  2241. #endif
  2242. #ifdef CONFIG_USER_NS
  2243. REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
  2244. REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
  2245. REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
  2246. #endif
  2247. };
  2248. static int proc_tgid_base_readdir(struct file * filp,
  2249. void * dirent, filldir_t filldir)
  2250. {
  2251. return proc_pident_readdir(filp,dirent,filldir,
  2252. tgid_base_stuff,ARRAY_SIZE(tgid_base_stuff));
  2253. }
  2254. static const struct file_operations proc_tgid_base_operations = {
  2255. .read = generic_read_dir,
  2256. .readdir = proc_tgid_base_readdir,
  2257. .llseek = default_llseek,
  2258. };
  2259. static struct dentry *proc_tgid_base_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
  2260. {
  2261. return proc_pident_lookup(dir, dentry,
  2262. tgid_base_stuff, ARRAY_SIZE(tgid_base_stuff));
  2263. }
  2264. static const struct inode_operations proc_tgid_base_inode_operations = {
  2265. .lookup = proc_tgid_base_lookup,
  2266. .getattr = pid_getattr,
  2267. .setattr = proc_setattr,
  2268. .permission = proc_pid_permission,
  2269. };
  2270. static void proc_flush_task_mnt(struct vfsmount *mnt, pid_t pid, pid_t tgid)
  2271. {
  2272. struct dentry *dentry, *leader, *dir;
  2273. char buf[PROC_NUMBUF];
  2274. struct qstr name;
  2275. name.name = buf;
  2276. name.len = snprintf(buf, sizeof(buf), "%d", pid);
  2277. /* no ->d_hash() rejects on procfs */
  2278. dentry = d_hash_and_lookup(mnt->mnt_root, &name);
  2279. if (dentry) {
  2280. shrink_dcache_parent(dentry);
  2281. d_drop(dentry);
  2282. dput(dentry);
  2283. }
  2284. name.name = buf;
  2285. name.len = snprintf(buf, sizeof(buf), "%d", tgid);
  2286. leader = d_hash_and_lookup(mnt->mnt_root, &name);
  2287. if (!leader)
  2288. goto out;
  2289. name.name = "task";
  2290. name.len = strlen(name.name);
  2291. dir = d_hash_and_lookup(leader, &name);
  2292. if (!dir)
  2293. goto out_put_leader;
  2294. name.name = buf;
  2295. name.len = snprintf(buf, sizeof(buf), "%d", pid);
  2296. dentry = d_hash_and_lookup(dir, &name);
  2297. if (dentry) {
  2298. shrink_dcache_parent(dentry);
  2299. d_drop(dentry);
  2300. dput(dentry);
  2301. }
  2302. dput(dir);
  2303. out_put_leader:
  2304. dput(leader);
  2305. out:
  2306. return;
  2307. }
  2308. /**
  2309. * proc_flush_task - Remove dcache entries for @task from the /proc dcache.
  2310. * @task: task that should be flushed.
  2311. *
  2312. * When flushing dentries from proc, one needs to flush them from global
  2313. * proc (proc_mnt) and from all the namespaces' procs this task was seen
  2314. * in. This call is supposed to do all of this job.
  2315. *
  2316. * Looks in the dcache for
  2317. * /proc/@pid
  2318. * /proc/@tgid/task/@pid
  2319. * if either directory is present flushes it and all of it'ts children
  2320. * from the dcache.
  2321. *
  2322. * It is safe and reasonable to cache /proc entries for a task until
  2323. * that task exits. After that they just clog up the dcache with
  2324. * useless entries, possibly causing useful dcache entries to be
  2325. * flushed instead. This routine is proved to flush those useless
  2326. * dcache entries at process exit time.
  2327. *
  2328. * NOTE: This routine is just an optimization so it does not guarantee
  2329. * that no dcache entries will exist at process exit time it
  2330. * just makes it very unlikely that any will persist.
  2331. */
  2332. void proc_flush_task(struct task_struct *task)
  2333. {
  2334. int i;
  2335. struct pid *pid, *tgid;
  2336. struct upid *upid;
  2337. pid = task_pid(task);
  2338. tgid = task_tgid(task);
  2339. for (i = 0; i <= pid->level; i++) {
  2340. upid = &pid->numbers[i];
  2341. proc_flush_task_mnt(upid->ns->proc_mnt, upid->nr,
  2342. tgid->numbers[i].nr);
  2343. }
  2344. }
  2345. static struct dentry *proc_pid_instantiate(struct inode *dir,
  2346. struct dentry * dentry,
  2347. struct task_struct *task, const void *ptr)
  2348. {
  2349. struct dentry *error = ERR_PTR(-ENOENT);
  2350. struct inode *inode;
  2351. inode = proc_pid_make_inode(dir->i_sb, task);
  2352. if (!inode)
  2353. goto out;
  2354. inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
  2355. inode->i_op = &proc_tgid_base_inode_operations;
  2356. inode->i_fop = &proc_tgid_base_operations;
  2357. inode->i_flags|=S_IMMUTABLE;
  2358. set_nlink(inode, 2 + pid_entry_count_dirs(tgid_base_stuff,
  2359. ARRAY_SIZE(tgid_base_stuff)));
  2360. d_set_d_op(dentry, &pid_dentry_operations);
  2361. d_add(dentry, inode);
  2362. /* Close the race of the process dying before we return the dentry */
  2363. if (pid_revalidate(dentry, 0))
  2364. error = NULL;
  2365. out:
  2366. return error;
  2367. }
  2368. struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsigned int flags)
  2369. {
  2370. struct dentry *result = NULL;
  2371. struct task_struct *task;
  2372. unsigned tgid;
  2373. struct pid_namespace *ns;
  2374. tgid = name_to_int(dentry);
  2375. if (tgid == ~0U)
  2376. goto out;
  2377. ns = dentry->d_sb->s_fs_info;
  2378. rcu_read_lock();
  2379. task = find_task_by_pid_ns(tgid, ns);
  2380. if (task)
  2381. get_task_struct(task);
  2382. rcu_read_unlock();
  2383. if (!task)
  2384. goto out;
  2385. result = proc_pid_instantiate(dir, dentry, task, NULL);
  2386. put_task_struct(task);
  2387. out:
  2388. return result;
  2389. }
  2390. /*
  2391. * Find the first task with tgid >= tgid
  2392. *
  2393. */
  2394. struct tgid_iter {
  2395. unsigned int tgid;
  2396. struct task_struct *task;
  2397. };
  2398. static struct tgid_iter next_tgid(struct pid_namespace *ns, struct tgid_iter iter)
  2399. {
  2400. struct pid *pid;
  2401. if (iter.task)
  2402. put_task_struct(iter.task);
  2403. rcu_read_lock();
  2404. retry:
  2405. iter.task = NULL;
  2406. pid = find_ge_pid(iter.tgid, ns);
  2407. if (pid) {
  2408. iter.tgid = pid_nr_ns(pid, ns);
  2409. iter.task = pid_task(pid, PIDTYPE_PID);
  2410. /* What we to know is if the pid we have find is the
  2411. * pid of a thread_group_leader. Testing for task
  2412. * being a thread_group_leader is the obvious thing
  2413. * todo but there is a window when it fails, due to
  2414. * the pid transfer logic in de_thread.
  2415. *
  2416. * So we perform the straight forward test of seeing
  2417. * if the pid we have found is the pid of a thread
  2418. * group leader, and don't worry if the task we have
  2419. * found doesn't happen to be a thread group leader.
  2420. * As we don't care in the case of readdir.
  2421. */
  2422. if (!iter.task || !has_group_leader_pid(iter.task)) {
  2423. iter.tgid += 1;
  2424. goto retry;
  2425. }
  2426. get_task_struct(iter.task);
  2427. }
  2428. rcu_read_unlock();
  2429. return iter;
  2430. }
  2431. #define TGID_OFFSET (FIRST_PROCESS_ENTRY + 1)
  2432. static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
  2433. struct tgid_iter iter)
  2434. {
  2435. char name[PROC_NUMBUF];
  2436. int len = snprintf(name, sizeof(name), "%d", iter.tgid);
  2437. return proc_fill_cache(filp, dirent, filldir, name, len,
  2438. proc_pid_instantiate, iter.task, NULL);
  2439. }
  2440. static int fake_filldir(void *buf, const char *name, int namelen,
  2441. loff_t offset, u64 ino, unsigned d_type)
  2442. {
  2443. return 0;
  2444. }
  2445. /* for the /proc/ directory itself, after non-process stuff has been done */
  2446. int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
  2447. {
  2448. struct tgid_iter iter;
  2449. struct pid_namespace *ns;
  2450. filldir_t __filldir;
  2451. loff_t pos = filp->f_pos;
  2452. if (pos >= PID_MAX_LIMIT + TGID_OFFSET)
  2453. goto out;
  2454. if (pos == TGID_OFFSET - 1) {
  2455. if (proc_fill_cache(filp, dirent, filldir, "self", 4,
  2456. NULL, NULL, NULL) < 0)
  2457. goto out;
  2458. iter.tgid = 0;
  2459. } else {
  2460. iter.tgid = pos - TGID_OFFSET;
  2461. }
  2462. iter.task = NULL;
  2463. ns = filp->f_dentry->d_sb->s_fs_info;
  2464. for (iter = next_tgid(ns, iter);
  2465. iter.task;
  2466. iter.tgid += 1, iter = next_tgid(ns, iter)) {
  2467. if (has_pid_permissions(ns, iter.task, 2))
  2468. __filldir = filldir;
  2469. else
  2470. __filldir = fake_filldir;
  2471. filp->f_pos = iter.tgid + TGID_OFFSET;
  2472. if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
  2473. put_task_struct(iter.task);
  2474. goto out;
  2475. }
  2476. }
  2477. filp->f_pos = PID_MAX_LIMIT + TGID_OFFSET;
  2478. out:
  2479. return 0;
  2480. }
  2481. /*
  2482. * Tasks
  2483. */
  2484. static const struct pid_entry tid_base_stuff[] = {
  2485. DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
  2486. DIR("fdinfo", S_IRUSR|S_IXUSR, proc_fdinfo_inode_operations, proc_fdinfo_operations),
  2487. DIR("ns", S_IRUSR|S_IXUGO, proc_ns_dir_inode_operations, proc_ns_dir_operations),
  2488. REG("environ", S_IRUSR, proc_environ_operations),
  2489. INF("auxv", S_IRUSR, proc_pid_auxv),
  2490. ONE("status", S_IRUGO, proc_pid_status),
  2491. ONE("personality", S_IRUGO, proc_pid_personality),
  2492. INF("limits", S_IRUGO, proc_pid_limits),
  2493. #ifdef CONFIG_SCHED_DEBUG
  2494. REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
  2495. #endif
  2496. REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
  2497. #ifdef CONFIG_HAVE_ARCH_TRACEHOOK
  2498. INF("syscall", S_IRUGO, proc_pid_syscall),
  2499. #endif
  2500. INF("cmdline", S_IRUGO, proc_pid_cmdline),
  2501. ONE("stat", S_IRUGO, proc_tid_stat),
  2502. ONE("statm", S_IRUGO, proc_pid_statm),
  2503. REG("maps", S_IRUGO, proc_tid_maps_operations),
  2504. #ifdef CONFIG_CHECKPOINT_RESTORE
  2505. REG("children", S_IRUGO, proc_tid_children_operations),
  2506. #endif
  2507. #ifdef CONFIG_NUMA
  2508. REG("numa_maps", S_IRUGO, proc_tid_numa_maps_operations),
  2509. #endif
  2510. REG("mem", S_IRUSR|S_IWUSR, proc_mem_operations),
  2511. LNK("cwd", proc_cwd_link),
  2512. LNK("root", proc_root_link),
  2513. LNK("exe", proc_exe_link),
  2514. REG("mounts", S_IRUGO, proc_mounts_operations),
  2515. REG("mountinfo", S_IRUGO, proc_mountinfo_operations),
  2516. #ifdef CONFIG_PROC_PAGE_MONITOR
  2517. REG("clear_refs", S_IWUSR, proc_clear_refs_operations),
  2518. REG("smaps", S_IRUGO, proc_tid_smaps_operations),
  2519. REG("pagemap", S_IRUGO, proc_pagemap_operations),
  2520. #endif
  2521. #ifdef CONFIG_SECURITY
  2522. DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
  2523. #endif
  2524. #ifdef CONFIG_KALLSYMS
  2525. INF("wchan", S_IRUGO, proc_pid_wchan),
  2526. #endif
  2527. #ifdef CONFIG_STACKTRACE
  2528. ONE("stack", S_IRUGO, proc_pid_stack),
  2529. #endif
  2530. #ifdef CONFIG_SCHEDSTATS
  2531. INF("schedstat", S_IRUGO, proc_pid_schedstat),
  2532. #endif
  2533. #ifdef CONFIG_LATENCYTOP
  2534. REG("latency", S_IRUGO, proc_lstats_operations),
  2535. #endif
  2536. #ifdef CONFIG_PROC_PID_CPUSET
  2537. REG("cpuset", S_IRUGO, proc_cpuset_operations),
  2538. #endif
  2539. #ifdef CONFIG_CGROUPS
  2540. REG("cgroup", S_IRUGO, proc_cgroup_operations),
  2541. #endif
  2542. INF("oom_score", S_IRUGO, proc_oom_score),
  2543. REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adj_operations),
  2544. REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
  2545. #ifdef CONFIG_AUDITSYSCALL
  2546. REG("loginuid", S_IWUSR|S_IRUGO, proc_loginuid_operations),
  2547. REG("sessionid", S_IRUGO, proc_sessionid_operations),
  2548. #endif
  2549. #ifdef CONFIG_FAULT_INJECTION
  2550. REG("make-it-fail", S_IRUGO|S_IWUSR, proc_fault_inject_operations),
  2551. #endif
  2552. #ifdef CONFIG_TASK_IO_ACCOUNTING
  2553. INF("io", S_IRUSR, proc_tid_io_accounting),
  2554. #endif
  2555. #ifdef CONFIG_HARDWALL
  2556. INF("hardwall", S_IRUGO, proc_pid_hardwall),
  2557. #endif
  2558. #ifdef CONFIG_USER_NS
  2559. REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
  2560. REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
  2561. REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
  2562. #endif
  2563. };
  2564. static int proc_tid_base_readdir(struct file * filp,
  2565. void * dirent, filldir_t filldir)
  2566. {
  2567. return proc_pident_readdir(filp,dirent,filldir,
  2568. tid_base_stuff,ARRAY_SIZE(tid_base_stuff));
  2569. }
  2570. static struct dentry *proc_tid_base_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
  2571. {
  2572. return proc_pident_lookup(dir, dentry,
  2573. tid_base_stuff, ARRAY_SIZE(tid_base_stuff));
  2574. }
  2575. static const struct file_operations proc_tid_base_operations = {
  2576. .read = generic_read_dir,
  2577. .readdir = proc_tid_base_readdir,
  2578. .llseek = default_llseek,
  2579. };
  2580. static const struct inode_operations proc_tid_base_inode_operations = {
  2581. .lookup = proc_tid_base_lookup,
  2582. .getattr = pid_getattr,
  2583. .setattr = proc_setattr,
  2584. };
  2585. static struct dentry *proc_task_instantiate(struct inode *dir,
  2586. struct dentry *dentry, struct task_struct *task, const void *ptr)
  2587. {
  2588. struct dentry *error = ERR_PTR(-ENOENT);
  2589. struct inode *inode;
  2590. inode = proc_pid_make_inode(dir->i_sb, task);
  2591. if (!inode)
  2592. goto out;
  2593. inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
  2594. inode->i_op = &proc_tid_base_inode_operations;
  2595. inode->i_fop = &proc_tid_base_operations;
  2596. inode->i_flags|=S_IMMUTABLE;
  2597. set_nlink(inode, 2 + pid_entry_count_dirs(tid_base_stuff,
  2598. ARRAY_SIZE(tid_base_stuff)));
  2599. d_set_d_op(dentry, &pid_dentry_operations);
  2600. d_add(dentry, inode);
  2601. /* Close the race of the process dying before we return the dentry */
  2602. if (pid_revalidate(dentry, 0))
  2603. error = NULL;
  2604. out:
  2605. return error;
  2606. }
  2607. static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry, unsigned int flags)
  2608. {
  2609. struct dentry *result = ERR_PTR(-ENOENT);
  2610. struct task_struct *task;
  2611. struct task_struct *leader = get_proc_task(dir);
  2612. unsigned tid;
  2613. struct pid_namespace *ns;
  2614. if (!leader)
  2615. goto out_no_task;
  2616. tid = name_to_int(dentry);
  2617. if (tid == ~0U)
  2618. goto out;
  2619. ns = dentry->d_sb->s_fs_info;
  2620. rcu_read_lock();
  2621. task = find_task_by_pid_ns(tid, ns);
  2622. if (task)
  2623. get_task_struct(task);
  2624. rcu_read_unlock();
  2625. if (!task)
  2626. goto out;
  2627. if (!same_thread_group(leader, task))
  2628. goto out_drop_task;
  2629. result = proc_task_instantiate(dir, dentry, task, NULL);
  2630. out_drop_task:
  2631. put_task_struct(task);
  2632. out:
  2633. put_task_struct(leader);
  2634. out_no_task:
  2635. return result;
  2636. }
  2637. /*
  2638. * Find the first tid of a thread group to return to user space.
  2639. *
  2640. * Usually this is just the thread group leader, but if the users
  2641. * buffer was too small or there was a seek into the middle of the
  2642. * directory we have more work todo.
  2643. *
  2644. * In the case of a short read we start with find_task_by_pid.
  2645. *
  2646. * In the case of a seek we start with the leader and walk nr
  2647. * threads past it.
  2648. */
  2649. static struct task_struct *first_tid(struct task_struct *leader,
  2650. int tid, int nr, struct pid_namespace *ns)
  2651. {
  2652. struct task_struct *pos;
  2653. rcu_read_lock();
  2654. /* Attempt to start with the pid of a thread */
  2655. if (tid && (nr > 0)) {
  2656. pos = find_task_by_pid_ns(tid, ns);
  2657. if (pos && (pos->group_leader == leader))
  2658. goto found;
  2659. }
  2660. /* If nr exceeds the number of threads there is nothing todo */
  2661. pos = NULL;
  2662. if (nr && nr >= get_nr_threads(leader))
  2663. goto out;
  2664. /* If we haven't found our starting place yet start
  2665. * with the leader and walk nr threads forward.
  2666. */
  2667. for (pos = leader; nr > 0; --nr) {
  2668. pos = next_thread(pos);
  2669. if (pos == leader) {
  2670. pos = NULL;
  2671. goto out;
  2672. }
  2673. }
  2674. found:
  2675. get_task_struct(pos);
  2676. out:
  2677. rcu_read_unlock();
  2678. return pos;
  2679. }
  2680. /*
  2681. * Find the next thread in the thread list.
  2682. * Return NULL if there is an error or no next thread.
  2683. *
  2684. * The reference to the input task_struct is released.
  2685. */
  2686. static struct task_struct *next_tid(struct task_struct *start)
  2687. {
  2688. struct task_struct *pos = NULL;
  2689. rcu_read_lock();
  2690. if (pid_alive(start)) {
  2691. pos = next_thread(start);
  2692. if (thread_group_leader(pos))
  2693. pos = NULL;
  2694. else
  2695. get_task_struct(pos);
  2696. }
  2697. rcu_read_unlock();
  2698. put_task_struct(start);
  2699. return pos;
  2700. }
  2701. static int proc_task_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
  2702. struct task_struct *task, int tid)
  2703. {
  2704. char name[PROC_NUMBUF];
  2705. int len = snprintf(name, sizeof(name), "%d", tid);
  2706. return proc_fill_cache(filp, dirent, filldir, name, len,
  2707. proc_task_instantiate, task, NULL);
  2708. }
  2709. /* for the /proc/TGID/task/ directories */
  2710. static int proc_task_readdir(struct file * filp, void * dirent, filldir_t filldir)
  2711. {
  2712. struct dentry *dentry = filp->f_path.dentry;
  2713. struct inode *inode = dentry->d_inode;
  2714. struct task_struct *leader = NULL;
  2715. struct task_struct *task;
  2716. int retval = -ENOENT;
  2717. ino_t ino;
  2718. int tid;
  2719. struct pid_namespace *ns;
  2720. task = get_proc_task(inode);
  2721. if (!task)
  2722. goto out_no_task;
  2723. rcu_read_lock();
  2724. if (pid_alive(task)) {
  2725. leader = task->group_leader;
  2726. get_task_struct(leader);
  2727. }
  2728. rcu_read_unlock();
  2729. put_task_struct(task);
  2730. if (!leader)
  2731. goto out_no_task;
  2732. retval = 0;
  2733. switch ((unsigned long)filp->f_pos) {
  2734. case 0:
  2735. ino = inode->i_ino;
  2736. if (filldir(dirent, ".", 1, filp->f_pos, ino, DT_DIR) < 0)
  2737. goto out;
  2738. filp->f_pos++;
  2739. /* fall through */
  2740. case 1:
  2741. ino = parent_ino(dentry);
  2742. if (filldir(dirent, "..", 2, filp->f_pos, ino, DT_DIR) < 0)
  2743. goto out;
  2744. filp->f_pos++;
  2745. /* fall through */
  2746. }
  2747. /* f_version caches the tgid value that the last readdir call couldn't
  2748. * return. lseek aka telldir automagically resets f_version to 0.
  2749. */
  2750. ns = filp->f_dentry->d_sb->s_fs_info;
  2751. tid = (int)filp->f_version;
  2752. filp->f_version = 0;
  2753. for (task = first_tid(leader, tid, filp->f_pos - 2, ns);
  2754. task;
  2755. task = next_tid(task), filp->f_pos++) {
  2756. tid = task_pid_nr_ns(task, ns);
  2757. if (proc_task_fill_cache(filp, dirent, filldir, task, tid) < 0) {
  2758. /* returning this tgid failed, save it as the first
  2759. * pid for the next readir call */
  2760. filp->f_version = (u64)tid;
  2761. put_task_struct(task);
  2762. break;
  2763. }
  2764. }
  2765. out:
  2766. put_task_struct(leader);
  2767. out_no_task:
  2768. return retval;
  2769. }
  2770. static int proc_task_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
  2771. {
  2772. struct inode *inode = dentry->d_inode;
  2773. struct task_struct *p = get_proc_task(inode);
  2774. generic_fillattr(inode, stat);
  2775. if (p) {
  2776. stat->nlink += get_nr_threads(p);
  2777. put_task_struct(p);
  2778. }
  2779. return 0;
  2780. }
  2781. static const struct inode_operations proc_task_inode_operations = {
  2782. .lookup = proc_task_lookup,
  2783. .getattr = proc_task_getattr,
  2784. .setattr = proc_setattr,
  2785. .permission = proc_pid_permission,
  2786. };
  2787. static const struct file_operations proc_task_operations = {
  2788. .read = generic_read_dir,
  2789. .readdir = proc_task_readdir,
  2790. .llseek = default_llseek,
  2791. };