base.c 76 KB

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