sysctl.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640
  1. /*
  2. * sysctl.c: General linux system control interface
  3. *
  4. * Begun 24 March 1995, Stephen Tweedie
  5. * Added /proc support, Dec 1995
  6. * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
  7. * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
  8. * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
  9. * Dynamic registration fixes, Stephen Tweedie.
  10. * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
  11. * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
  12. * Horn.
  13. * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
  14. * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
  15. * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
  16. * Wendling.
  17. * The list_for_each() macro wasn't appropriate for the sysctl loop.
  18. * Removed it and replaced it with older style, 03/23/00, Bill Wendling
  19. */
  20. #include <linux/module.h>
  21. #include <linux/mm.h>
  22. #include <linux/swap.h>
  23. #include <linux/slab.h>
  24. #include <linux/sysctl.h>
  25. #include <linux/bitmap.h>
  26. #include <linux/signal.h>
  27. #include <linux/printk.h>
  28. #include <linux/proc_fs.h>
  29. #include <linux/security.h>
  30. #include <linux/ctype.h>
  31. #include <linux/kmemcheck.h>
  32. #include <linux/fs.h>
  33. #include <linux/init.h>
  34. #include <linux/kernel.h>
  35. #include <linux/kobject.h>
  36. #include <linux/net.h>
  37. #include <linux/sysrq.h>
  38. #include <linux/highuid.h>
  39. #include <linux/writeback.h>
  40. #include <linux/ratelimit.h>
  41. #include <linux/compaction.h>
  42. #include <linux/hugetlb.h>
  43. #include <linux/initrd.h>
  44. #include <linux/key.h>
  45. #include <linux/times.h>
  46. #include <linux/limits.h>
  47. #include <linux/dcache.h>
  48. #include <linux/dnotify.h>
  49. #include <linux/syscalls.h>
  50. #include <linux/vmstat.h>
  51. #include <linux/nfs_fs.h>
  52. #include <linux/acpi.h>
  53. #include <linux/reboot.h>
  54. #include <linux/ftrace.h>
  55. #include <linux/perf_event.h>
  56. #include <linux/kprobes.h>
  57. #include <linux/pipe_fs_i.h>
  58. #include <linux/oom.h>
  59. #include <linux/kmod.h>
  60. #include <linux/capability.h>
  61. #include <linux/binfmts.h>
  62. #include <asm/uaccess.h>
  63. #include <asm/processor.h>
  64. #ifdef CONFIG_X86
  65. #include <asm/nmi.h>
  66. #include <asm/stacktrace.h>
  67. #include <asm/io.h>
  68. #endif
  69. #ifdef CONFIG_SPARC
  70. #include <asm/setup.h>
  71. #endif
  72. #ifdef CONFIG_BSD_PROCESS_ACCT
  73. #include <linux/acct.h>
  74. #endif
  75. #ifdef CONFIG_RT_MUTEXES
  76. #include <linux/rtmutex.h>
  77. #endif
  78. #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
  79. #include <linux/lockdep.h>
  80. #endif
  81. #ifdef CONFIG_CHR_DEV_SG
  82. #include <scsi/sg.h>
  83. #endif
  84. #ifdef CONFIG_LOCKUP_DETECTOR
  85. #include <linux/nmi.h>
  86. #endif
  87. #if defined(CONFIG_SYSCTL)
  88. /* External variables not in a header file. */
  89. #ifdef CONFIG_USB
  90. extern int deny_new_usb;
  91. #endif
  92. extern int sysctl_overcommit_memory;
  93. extern int sysctl_overcommit_ratio;
  94. extern int max_threads;
  95. extern int core_uses_pid;
  96. extern int suid_dumpable;
  97. extern char core_pattern[];
  98. extern unsigned int core_pipe_limit;
  99. extern int pid_max;
  100. extern int min_free_kbytes;
  101. extern int extra_free_kbytes;
  102. extern int min_free_order_shift;
  103. extern int pid_max_min, pid_max_max;
  104. extern int sysctl_drop_caches;
  105. extern int percpu_pagelist_fraction;
  106. extern int compat_log;
  107. extern int latencytop_enabled;
  108. extern int sysctl_nr_open_min, sysctl_nr_open_max;
  109. #ifndef CONFIG_MMU
  110. extern int sysctl_nr_trim_pages;
  111. #endif
  112. #ifdef CONFIG_BLOCK
  113. extern int blk_iopoll_enabled;
  114. #endif
  115. /* Constants used for minimum and maximum */
  116. #ifdef CONFIG_LOCKUP_DETECTOR
  117. static int sixty = 60;
  118. static int neg_one = -1;
  119. #endif
  120. static int zero;
  121. static int __maybe_unused one = 1;
  122. static int __maybe_unused two = 2;
  123. static int __maybe_unused three = 3;
  124. static unsigned long one_ul = 1;
  125. static int one_hundred = 100;
  126. #ifdef CONFIG_INCREASE_MAXIMUM_SWAPPINESS
  127. extern int max_swappiness;
  128. #endif
  129. #ifdef CONFIG_PRINTK
  130. static int ten_thousand = 10000;
  131. #endif
  132. /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
  133. static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
  134. /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
  135. static int maxolduid = 65535;
  136. static int minolduid;
  137. static int min_percpu_pagelist_fract = 8;
  138. static int ngroups_max = NGROUPS_MAX;
  139. static const int cap_last_cap = CAP_LAST_CAP;
  140. /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
  141. #ifdef CONFIG_DETECT_HUNG_TASK
  142. static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
  143. #endif
  144. #ifdef CONFIG_INOTIFY_USER
  145. #include <linux/inotify.h>
  146. #endif
  147. #ifdef CONFIG_SPARC
  148. #endif
  149. #ifdef CONFIG_SPARC64
  150. extern int sysctl_tsb_ratio;
  151. #endif
  152. #ifdef __hppa__
  153. extern int pwrsw_enabled;
  154. extern int unaligned_enabled;
  155. #endif
  156. #ifdef CONFIG_IA64
  157. extern int no_unaligned_warning;
  158. extern int unaligned_dump_stack;
  159. #endif
  160. #ifdef CONFIG_PROC_SYSCTL
  161. static int proc_do_cad_pid(struct ctl_table *table, int write,
  162. void __user *buffer, size_t *lenp, loff_t *ppos);
  163. static int proc_taint(struct ctl_table *table, int write,
  164. void __user *buffer, size_t *lenp, loff_t *ppos);
  165. #endif
  166. #ifdef CONFIG_PRINTK
  167. static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
  168. void __user *buffer, size_t *lenp, loff_t *ppos);
  169. #endif
  170. #ifdef CONFIG_MAGIC_SYSRQ
  171. /* Note: sysrq code uses it's own private copy */
  172. static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
  173. static int sysrq_sysctl_handler(ctl_table *table, int write,
  174. void __user *buffer, size_t *lenp,
  175. loff_t *ppos)
  176. {
  177. int error;
  178. error = proc_dointvec(table, write, buffer, lenp, ppos);
  179. if (error)
  180. return error;
  181. if (write)
  182. sysrq_toggle_support(__sysrq_enabled);
  183. return 0;
  184. }
  185. #endif
  186. static struct ctl_table kern_table[];
  187. static struct ctl_table vm_table[];
  188. static struct ctl_table fs_table[];
  189. static struct ctl_table debug_table[];
  190. static struct ctl_table dev_table[];
  191. extern struct ctl_table random_table[];
  192. #ifdef CONFIG_EPOLL
  193. extern struct ctl_table epoll_table[];
  194. #endif
  195. #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
  196. int sysctl_legacy_va_layout;
  197. #endif
  198. /* The default sysctl tables: */
  199. static struct ctl_table sysctl_base_table[] = {
  200. {
  201. .procname = "kernel",
  202. .mode = 0555,
  203. .child = kern_table,
  204. },
  205. {
  206. .procname = "vm",
  207. .mode = 0555,
  208. .child = vm_table,
  209. },
  210. {
  211. .procname = "fs",
  212. .mode = 0555,
  213. .child = fs_table,
  214. },
  215. {
  216. .procname = "debug",
  217. .mode = 0555,
  218. .child = debug_table,
  219. },
  220. {
  221. .procname = "dev",
  222. .mode = 0555,
  223. .child = dev_table,
  224. },
  225. { }
  226. };
  227. #ifdef CONFIG_SCHED_DEBUG
  228. static int min_sched_granularity_ns = 100000; /* 100 usecs */
  229. static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
  230. static int min_wakeup_granularity_ns; /* 0 usecs */
  231. static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
  232. static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
  233. static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
  234. #endif
  235. #ifdef CONFIG_COMPACTION
  236. static int min_extfrag_threshold;
  237. static int max_extfrag_threshold = 1000;
  238. #endif
  239. static struct ctl_table kern_table[] = {
  240. {
  241. .procname = "sched_child_runs_first",
  242. .data = &sysctl_sched_child_runs_first,
  243. .maxlen = sizeof(unsigned int),
  244. .mode = 0644,
  245. .proc_handler = proc_dointvec,
  246. },
  247. {
  248. .procname = "sched_wake_to_idle",
  249. .data = &sysctl_sched_wake_to_idle,
  250. .maxlen = sizeof(unsigned int),
  251. .mode = 0644,
  252. .proc_handler = proc_dointvec,
  253. },
  254. #ifdef CONFIG_SCHED_DEBUG
  255. {
  256. .procname = "sched_min_granularity_ns",
  257. .data = &sysctl_sched_min_granularity,
  258. .maxlen = sizeof(unsigned int),
  259. .mode = 0644,
  260. .proc_handler = sched_proc_update_handler,
  261. .extra1 = &min_sched_granularity_ns,
  262. .extra2 = &max_sched_granularity_ns,
  263. },
  264. {
  265. .procname = "sched_latency_ns",
  266. .data = &sysctl_sched_latency,
  267. .maxlen = sizeof(unsigned int),
  268. .mode = 0644,
  269. .proc_handler = sched_proc_update_handler,
  270. .extra1 = &min_sched_granularity_ns,
  271. .extra2 = &max_sched_granularity_ns,
  272. },
  273. {
  274. .procname = "sched_wakeup_granularity_ns",
  275. .data = &sysctl_sched_wakeup_granularity,
  276. .maxlen = sizeof(unsigned int),
  277. .mode = 0644,
  278. .proc_handler = sched_proc_update_handler,
  279. .extra1 = &min_wakeup_granularity_ns,
  280. .extra2 = &max_wakeup_granularity_ns,
  281. },
  282. {
  283. .procname = "sched_tunable_scaling",
  284. .data = &sysctl_sched_tunable_scaling,
  285. .maxlen = sizeof(enum sched_tunable_scaling),
  286. .mode = 0644,
  287. .proc_handler = sched_proc_update_handler,
  288. .extra1 = &min_sched_tunable_scaling,
  289. .extra2 = &max_sched_tunable_scaling,
  290. },
  291. {
  292. .procname = "sched_migration_cost_ns",
  293. .data = &sysctl_sched_migration_cost,
  294. .maxlen = sizeof(unsigned int),
  295. .mode = 0644,
  296. .proc_handler = proc_dointvec,
  297. },
  298. {
  299. .procname = "sched_nr_migrate",
  300. .data = &sysctl_sched_nr_migrate,
  301. .maxlen = sizeof(unsigned int),
  302. .mode = 0644,
  303. .proc_handler = proc_dointvec,
  304. },
  305. {
  306. .procname = "sched_time_avg_ms",
  307. .data = &sysctl_sched_time_avg,
  308. .maxlen = sizeof(unsigned int),
  309. .mode = 0644,
  310. .proc_handler = proc_dointvec,
  311. },
  312. {
  313. .procname = "sched_shares_window_ns",
  314. .data = &sysctl_sched_shares_window,
  315. .maxlen = sizeof(unsigned int),
  316. .mode = 0644,
  317. .proc_handler = proc_dointvec,
  318. },
  319. {
  320. .procname = "timer_migration",
  321. .data = &sysctl_timer_migration,
  322. .maxlen = sizeof(unsigned int),
  323. .mode = 0644,
  324. .proc_handler = proc_dointvec_minmax,
  325. .extra1 = &zero,
  326. .extra2 = &one,
  327. },
  328. #endif
  329. {
  330. .procname = "sched_rt_period_us",
  331. .data = &sysctl_sched_rt_period,
  332. .maxlen = sizeof(unsigned int),
  333. .mode = 0644,
  334. .proc_handler = sched_rt_handler,
  335. },
  336. {
  337. .procname = "sched_rt_runtime_us",
  338. .data = &sysctl_sched_rt_runtime,
  339. .maxlen = sizeof(int),
  340. .mode = 0644,
  341. .proc_handler = sched_rt_handler,
  342. },
  343. #ifdef CONFIG_SCHED_AUTOGROUP
  344. {
  345. .procname = "sched_autogroup_enabled",
  346. .data = &sysctl_sched_autogroup_enabled,
  347. .maxlen = sizeof(unsigned int),
  348. .mode = 0644,
  349. .proc_handler = proc_dointvec_minmax,
  350. .extra1 = &zero,
  351. .extra2 = &one,
  352. },
  353. #endif
  354. #ifdef CONFIG_CFS_BANDWIDTH
  355. {
  356. .procname = "sched_cfs_bandwidth_slice_us",
  357. .data = &sysctl_sched_cfs_bandwidth_slice,
  358. .maxlen = sizeof(unsigned int),
  359. .mode = 0644,
  360. .proc_handler = proc_dointvec_minmax,
  361. .extra1 = &one,
  362. },
  363. #endif
  364. #ifdef CONFIG_PROVE_LOCKING
  365. {
  366. .procname = "prove_locking",
  367. .data = &prove_locking,
  368. .maxlen = sizeof(int),
  369. .mode = 0644,
  370. .proc_handler = proc_dointvec,
  371. },
  372. #endif
  373. #ifdef CONFIG_LOCK_STAT
  374. {
  375. .procname = "lock_stat",
  376. .data = &lock_stat,
  377. .maxlen = sizeof(int),
  378. .mode = 0644,
  379. .proc_handler = proc_dointvec,
  380. },
  381. #endif
  382. {
  383. .procname = "panic",
  384. .data = &panic_timeout,
  385. .maxlen = sizeof(int),
  386. .mode = 0644,
  387. .proc_handler = proc_dointvec,
  388. },
  389. {
  390. .procname = "core_uses_pid",
  391. .data = &core_uses_pid,
  392. .maxlen = sizeof(int),
  393. .mode = 0644,
  394. .proc_handler = proc_dointvec,
  395. },
  396. {
  397. .procname = "core_pattern",
  398. .data = core_pattern,
  399. .maxlen = CORENAME_MAX_SIZE,
  400. .mode = 0644,
  401. .proc_handler = proc_dostring,
  402. },
  403. {
  404. .procname = "core_pipe_limit",
  405. .data = &core_pipe_limit,
  406. .maxlen = sizeof(unsigned int),
  407. .mode = 0644,
  408. .proc_handler = proc_dointvec,
  409. },
  410. #ifdef CONFIG_PROC_SYSCTL
  411. {
  412. .procname = "tainted",
  413. .maxlen = sizeof(long),
  414. .mode = 0644,
  415. .proc_handler = proc_taint,
  416. },
  417. #endif
  418. #ifdef CONFIG_LATENCYTOP
  419. {
  420. .procname = "latencytop",
  421. .data = &latencytop_enabled,
  422. .maxlen = sizeof(int),
  423. .mode = 0644,
  424. .proc_handler = proc_dointvec,
  425. },
  426. #endif
  427. #ifdef CONFIG_BLK_DEV_INITRD
  428. {
  429. .procname = "real-root-dev",
  430. .data = &real_root_dev,
  431. .maxlen = sizeof(int),
  432. .mode = 0644,
  433. .proc_handler = proc_dointvec,
  434. },
  435. #endif
  436. {
  437. .procname = "print-fatal-signals",
  438. .data = &print_fatal_signals,
  439. .maxlen = sizeof(int),
  440. .mode = 0644,
  441. .proc_handler = proc_dointvec,
  442. },
  443. #ifdef CONFIG_SPARC
  444. {
  445. .procname = "reboot-cmd",
  446. .data = reboot_command,
  447. .maxlen = 256,
  448. .mode = 0644,
  449. .proc_handler = proc_dostring,
  450. },
  451. {
  452. .procname = "stop-a",
  453. .data = &stop_a_enabled,
  454. .maxlen = sizeof (int),
  455. .mode = 0644,
  456. .proc_handler = proc_dointvec,
  457. },
  458. {
  459. .procname = "scons-poweroff",
  460. .data = &scons_pwroff,
  461. .maxlen = sizeof (int),
  462. .mode = 0644,
  463. .proc_handler = proc_dointvec,
  464. },
  465. #endif
  466. #ifdef CONFIG_SPARC64
  467. {
  468. .procname = "tsb-ratio",
  469. .data = &sysctl_tsb_ratio,
  470. .maxlen = sizeof (int),
  471. .mode = 0644,
  472. .proc_handler = proc_dointvec,
  473. },
  474. #endif
  475. #ifdef __hppa__
  476. {
  477. .procname = "soft-power",
  478. .data = &pwrsw_enabled,
  479. .maxlen = sizeof (int),
  480. .mode = 0644,
  481. .proc_handler = proc_dointvec,
  482. },
  483. {
  484. .procname = "unaligned-trap",
  485. .data = &unaligned_enabled,
  486. .maxlen = sizeof (int),
  487. .mode = 0644,
  488. .proc_handler = proc_dointvec,
  489. },
  490. #endif
  491. {
  492. .procname = "ctrl-alt-del",
  493. .data = &C_A_D,
  494. .maxlen = sizeof(int),
  495. .mode = 0644,
  496. .proc_handler = proc_dointvec,
  497. },
  498. #ifdef CONFIG_FUNCTION_TRACER
  499. {
  500. .procname = "ftrace_enabled",
  501. .data = &ftrace_enabled,
  502. .maxlen = sizeof(int),
  503. .mode = 0644,
  504. .proc_handler = ftrace_enable_sysctl,
  505. },
  506. #endif
  507. #ifdef CONFIG_STACK_TRACER
  508. {
  509. .procname = "stack_tracer_enabled",
  510. .data = &stack_tracer_enabled,
  511. .maxlen = sizeof(int),
  512. .mode = 0644,
  513. .proc_handler = stack_trace_sysctl,
  514. },
  515. #endif
  516. #ifdef CONFIG_TRACING
  517. {
  518. .procname = "ftrace_dump_on_oops",
  519. .data = &ftrace_dump_on_oops,
  520. .maxlen = sizeof(int),
  521. .mode = 0644,
  522. .proc_handler = proc_dointvec,
  523. },
  524. #endif
  525. #ifdef CONFIG_MODULES
  526. {
  527. .procname = "modprobe",
  528. .data = &modprobe_path,
  529. .maxlen = KMOD_PATH_LEN,
  530. .mode = 0644,
  531. .proc_handler = proc_dostring,
  532. },
  533. {
  534. .procname = "modules_disabled",
  535. .data = &modules_disabled,
  536. .maxlen = sizeof(int),
  537. .mode = 0644,
  538. /* only handle a transition from default "0" to "1" */
  539. .proc_handler = proc_dointvec_minmax,
  540. .extra1 = &one,
  541. .extra2 = &one,
  542. },
  543. #endif
  544. #ifdef CONFIG_HOTPLUG
  545. {
  546. .procname = "hotplug",
  547. .data = &uevent_helper,
  548. .maxlen = UEVENT_HELPER_PATH_LEN,
  549. .mode = 0644,
  550. .proc_handler = proc_dostring,
  551. },
  552. #endif
  553. #ifdef CONFIG_CHR_DEV_SG
  554. {
  555. .procname = "sg-big-buff",
  556. .data = &sg_big_buff,
  557. .maxlen = sizeof (int),
  558. .mode = 0444,
  559. .proc_handler = proc_dointvec,
  560. },
  561. #endif
  562. #ifdef CONFIG_BSD_PROCESS_ACCT
  563. {
  564. .procname = "acct",
  565. .data = &acct_parm,
  566. .maxlen = 3*sizeof(int),
  567. .mode = 0644,
  568. .proc_handler = proc_dointvec,
  569. },
  570. #endif
  571. #ifdef CONFIG_MAGIC_SYSRQ
  572. {
  573. .procname = "sysrq",
  574. .data = &__sysrq_enabled,
  575. .maxlen = sizeof (int),
  576. .mode = 0644,
  577. .proc_handler = sysrq_sysctl_handler,
  578. },
  579. #endif
  580. #ifdef CONFIG_PROC_SYSCTL
  581. {
  582. .procname = "cad_pid",
  583. .data = NULL,
  584. .maxlen = sizeof (int),
  585. .mode = 0600,
  586. .proc_handler = proc_do_cad_pid,
  587. },
  588. #endif
  589. {
  590. .procname = "threads-max",
  591. .data = &max_threads,
  592. .maxlen = sizeof(int),
  593. .mode = 0644,
  594. .proc_handler = proc_dointvec,
  595. },
  596. {
  597. .procname = "random",
  598. .mode = 0555,
  599. .child = random_table,
  600. },
  601. {
  602. .procname = "usermodehelper",
  603. .mode = 0555,
  604. .child = usermodehelper_table,
  605. },
  606. {
  607. .procname = "overflowuid",
  608. .data = &overflowuid,
  609. .maxlen = sizeof(int),
  610. .mode = 0644,
  611. .proc_handler = proc_dointvec_minmax,
  612. .extra1 = &minolduid,
  613. .extra2 = &maxolduid,
  614. },
  615. {
  616. .procname = "overflowgid",
  617. .data = &overflowgid,
  618. .maxlen = sizeof(int),
  619. .mode = 0644,
  620. .proc_handler = proc_dointvec_minmax,
  621. .extra1 = &minolduid,
  622. .extra2 = &maxolduid,
  623. },
  624. #ifdef CONFIG_S390
  625. #ifdef CONFIG_MATHEMU
  626. {
  627. .procname = "ieee_emulation_warnings",
  628. .data = &sysctl_ieee_emulation_warnings,
  629. .maxlen = sizeof(int),
  630. .mode = 0644,
  631. .proc_handler = proc_dointvec,
  632. },
  633. #endif
  634. {
  635. .procname = "userprocess_debug",
  636. .data = &show_unhandled_signals,
  637. .maxlen = sizeof(int),
  638. .mode = 0644,
  639. .proc_handler = proc_dointvec,
  640. },
  641. #endif
  642. {
  643. .procname = "pid_max",
  644. .data = &pid_max,
  645. .maxlen = sizeof (int),
  646. .mode = 0644,
  647. .proc_handler = proc_dointvec_minmax,
  648. .extra1 = &pid_max_min,
  649. .extra2 = &pid_max_max,
  650. },
  651. {
  652. .procname = "panic_on_oops",
  653. .data = &panic_on_oops,
  654. .maxlen = sizeof(int),
  655. .mode = 0644,
  656. .proc_handler = proc_dointvec,
  657. },
  658. #if defined CONFIG_PRINTK
  659. {
  660. .procname = "printk",
  661. .data = &console_loglevel,
  662. .maxlen = 4*sizeof(int),
  663. .mode = 0644,
  664. .proc_handler = proc_dointvec,
  665. },
  666. {
  667. .procname = "printk_ratelimit",
  668. .data = &printk_ratelimit_state.interval,
  669. .maxlen = sizeof(int),
  670. .mode = 0644,
  671. .proc_handler = proc_dointvec_jiffies,
  672. },
  673. {
  674. .procname = "printk_ratelimit_burst",
  675. .data = &printk_ratelimit_state.burst,
  676. .maxlen = sizeof(int),
  677. .mode = 0644,
  678. .proc_handler = proc_dointvec,
  679. },
  680. {
  681. .procname = "printk_delay",
  682. .data = &printk_delay_msec,
  683. .maxlen = sizeof(int),
  684. .mode = 0644,
  685. .proc_handler = proc_dointvec_minmax,
  686. .extra1 = &zero,
  687. .extra2 = &ten_thousand,
  688. },
  689. {
  690. .procname = "dmesg_restrict",
  691. .data = &dmesg_restrict,
  692. .maxlen = sizeof(int),
  693. .mode = 0644,
  694. .proc_handler = proc_dointvec_minmax_sysadmin,
  695. .extra1 = &zero,
  696. .extra2 = &one,
  697. },
  698. {
  699. .procname = "kptr_restrict",
  700. .data = &kptr_restrict,
  701. .maxlen = sizeof(int),
  702. .mode = 0644,
  703. .proc_handler = proc_dointvec_minmax_sysadmin,
  704. .extra1 = &zero,
  705. .extra2 = &two,
  706. },
  707. #endif
  708. #ifdef CONFIG_USB
  709. {
  710. .procname = "deny_new_usb",
  711. .data = &deny_new_usb,
  712. .maxlen = sizeof(int),
  713. .mode = 0644,
  714. .proc_handler = proc_dointvec_minmax_sysadmin,
  715. .extra1 = &zero,
  716. .extra2 = &one,
  717. },
  718. #endif
  719. {
  720. .procname = "ngroups_max",
  721. .data = &ngroups_max,
  722. .maxlen = sizeof (int),
  723. .mode = 0444,
  724. .proc_handler = proc_dointvec,
  725. },
  726. {
  727. .procname = "cap_last_cap",
  728. .data = (void *)&cap_last_cap,
  729. .maxlen = sizeof(int),
  730. .mode = 0444,
  731. .proc_handler = proc_dointvec,
  732. },
  733. #if defined(CONFIG_LOCKUP_DETECTOR)
  734. {
  735. .procname = "watchdog",
  736. .data = &watchdog_enabled,
  737. .maxlen = sizeof (int),
  738. .mode = 0644,
  739. .proc_handler = proc_dowatchdog,
  740. .extra1 = &zero,
  741. .extra2 = &one,
  742. },
  743. {
  744. .procname = "watchdog_thresh",
  745. .data = &watchdog_thresh,
  746. .maxlen = sizeof(int),
  747. .mode = 0644,
  748. .proc_handler = proc_dowatchdog,
  749. .extra1 = &neg_one,
  750. .extra2 = &sixty,
  751. },
  752. {
  753. .procname = "softlockup_panic",
  754. .data = &softlockup_panic,
  755. .maxlen = sizeof(int),
  756. .mode = 0644,
  757. .proc_handler = proc_dointvec_minmax,
  758. .extra1 = &zero,
  759. .extra2 = &one,
  760. },
  761. {
  762. .procname = "nmi_watchdog",
  763. .data = &watchdog_enabled,
  764. .maxlen = sizeof (int),
  765. .mode = 0644,
  766. .proc_handler = proc_dowatchdog,
  767. .extra1 = &zero,
  768. .extra2 = &one,
  769. },
  770. #endif
  771. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
  772. {
  773. .procname = "unknown_nmi_panic",
  774. .data = &unknown_nmi_panic,
  775. .maxlen = sizeof (int),
  776. .mode = 0644,
  777. .proc_handler = proc_dointvec,
  778. },
  779. #endif
  780. #if defined(CONFIG_X86)
  781. {
  782. .procname = "panic_on_unrecovered_nmi",
  783. .data = &panic_on_unrecovered_nmi,
  784. .maxlen = sizeof(int),
  785. .mode = 0644,
  786. .proc_handler = proc_dointvec,
  787. },
  788. {
  789. .procname = "panic_on_io_nmi",
  790. .data = &panic_on_io_nmi,
  791. .maxlen = sizeof(int),
  792. .mode = 0644,
  793. .proc_handler = proc_dointvec,
  794. },
  795. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  796. {
  797. .procname = "panic_on_stackoverflow",
  798. .data = &sysctl_panic_on_stackoverflow,
  799. .maxlen = sizeof(int),
  800. .mode = 0644,
  801. .proc_handler = proc_dointvec,
  802. },
  803. #endif
  804. {
  805. .procname = "bootloader_type",
  806. .data = &bootloader_type,
  807. .maxlen = sizeof (int),
  808. .mode = 0444,
  809. .proc_handler = proc_dointvec,
  810. },
  811. {
  812. .procname = "bootloader_version",
  813. .data = &bootloader_version,
  814. .maxlen = sizeof (int),
  815. .mode = 0444,
  816. .proc_handler = proc_dointvec,
  817. },
  818. {
  819. .procname = "kstack_depth_to_print",
  820. .data = &kstack_depth_to_print,
  821. .maxlen = sizeof(int),
  822. .mode = 0644,
  823. .proc_handler = proc_dointvec,
  824. },
  825. {
  826. .procname = "io_delay_type",
  827. .data = &io_delay_type,
  828. .maxlen = sizeof(int),
  829. .mode = 0644,
  830. .proc_handler = proc_dointvec,
  831. },
  832. #endif
  833. #if defined(CONFIG_MMU)
  834. {
  835. .procname = "randomize_va_space",
  836. .data = &randomize_va_space,
  837. .maxlen = sizeof(int),
  838. .mode = 0644,
  839. .proc_handler = proc_dointvec,
  840. },
  841. #endif
  842. #if defined(CONFIG_S390) && defined(CONFIG_SMP)
  843. {
  844. .procname = "spin_retry",
  845. .data = &spin_retry,
  846. .maxlen = sizeof (int),
  847. .mode = 0644,
  848. .proc_handler = proc_dointvec,
  849. },
  850. #endif
  851. #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
  852. {
  853. .procname = "acpi_video_flags",
  854. .data = &acpi_realmode_flags,
  855. .maxlen = sizeof (unsigned long),
  856. .mode = 0644,
  857. .proc_handler = proc_doulongvec_minmax,
  858. },
  859. #endif
  860. #ifdef CONFIG_IA64
  861. {
  862. .procname = "ignore-unaligned-usertrap",
  863. .data = &no_unaligned_warning,
  864. .maxlen = sizeof (int),
  865. .mode = 0644,
  866. .proc_handler = proc_dointvec,
  867. },
  868. {
  869. .procname = "unaligned-dump-stack",
  870. .data = &unaligned_dump_stack,
  871. .maxlen = sizeof (int),
  872. .mode = 0644,
  873. .proc_handler = proc_dointvec,
  874. },
  875. #endif
  876. #ifdef CONFIG_DETECT_HUNG_TASK
  877. {
  878. .procname = "hung_task_panic",
  879. .data = &sysctl_hung_task_panic,
  880. .maxlen = sizeof(int),
  881. .mode = 0644,
  882. .proc_handler = proc_dointvec_minmax,
  883. .extra1 = &zero,
  884. .extra2 = &one,
  885. },
  886. {
  887. .procname = "hung_task_check_count",
  888. .data = &sysctl_hung_task_check_count,
  889. .maxlen = sizeof(unsigned long),
  890. .mode = 0644,
  891. .proc_handler = proc_doulongvec_minmax,
  892. },
  893. {
  894. .procname = "hung_task_timeout_secs",
  895. .data = &sysctl_hung_task_timeout_secs,
  896. .maxlen = sizeof(unsigned long),
  897. .mode = 0644,
  898. .proc_handler = proc_dohung_task_timeout_secs,
  899. .extra2 = &hung_task_timeout_max,
  900. },
  901. {
  902. .procname = "hung_task_warnings",
  903. .data = &sysctl_hung_task_warnings,
  904. .maxlen = sizeof(unsigned long),
  905. .mode = 0644,
  906. .proc_handler = proc_doulongvec_minmax,
  907. },
  908. #endif
  909. #ifdef CONFIG_COMPAT
  910. {
  911. .procname = "compat-log",
  912. .data = &compat_log,
  913. .maxlen = sizeof (int),
  914. .mode = 0644,
  915. .proc_handler = proc_dointvec,
  916. },
  917. #endif
  918. #ifdef CONFIG_RT_MUTEXES
  919. {
  920. .procname = "max_lock_depth",
  921. .data = &max_lock_depth,
  922. .maxlen = sizeof(int),
  923. .mode = 0644,
  924. .proc_handler = proc_dointvec,
  925. },
  926. #endif
  927. {
  928. .procname = "poweroff_cmd",
  929. .data = &poweroff_cmd,
  930. .maxlen = POWEROFF_CMD_PATH_LEN,
  931. .mode = 0644,
  932. .proc_handler = proc_dostring,
  933. },
  934. #ifdef CONFIG_KEYS
  935. {
  936. .procname = "keys",
  937. .mode = 0555,
  938. .child = key_sysctls,
  939. },
  940. #endif
  941. #ifdef CONFIG_RCU_TORTURE_TEST
  942. {
  943. .procname = "rcutorture_runnable",
  944. .data = &rcutorture_runnable,
  945. .maxlen = sizeof(int),
  946. .mode = 0644,
  947. .proc_handler = proc_dointvec,
  948. },
  949. #endif
  950. #ifdef CONFIG_PERF_EVENTS
  951. /*
  952. * User-space scripts rely on the existence of this file
  953. * as a feature check for perf_events being enabled.
  954. *
  955. * So it's an ABI, do not remove!
  956. */
  957. {
  958. .procname = "perf_event_paranoid",
  959. .data = &sysctl_perf_event_paranoid,
  960. .maxlen = sizeof(sysctl_perf_event_paranoid),
  961. .mode = 0644,
  962. .proc_handler = proc_dointvec,
  963. },
  964. {
  965. .procname = "perf_event_mlock_kb",
  966. .data = &sysctl_perf_event_mlock,
  967. .maxlen = sizeof(sysctl_perf_event_mlock),
  968. .mode = 0644,
  969. .proc_handler = proc_dointvec,
  970. },
  971. {
  972. .procname = "perf_event_max_sample_rate",
  973. .data = &sysctl_perf_event_sample_rate,
  974. .maxlen = sizeof(sysctl_perf_event_sample_rate),
  975. .mode = 0644,
  976. .proc_handler = perf_proc_update_handler,
  977. },
  978. #endif
  979. #ifdef CONFIG_KMEMCHECK
  980. {
  981. .procname = "kmemcheck",
  982. .data = &kmemcheck_enabled,
  983. .maxlen = sizeof(int),
  984. .mode = 0644,
  985. .proc_handler = proc_dointvec,
  986. },
  987. #endif
  988. #ifdef CONFIG_BLOCK
  989. {
  990. .procname = "blk_iopoll",
  991. .data = &blk_iopoll_enabled,
  992. .maxlen = sizeof(int),
  993. .mode = 0644,
  994. .proc_handler = proc_dointvec,
  995. },
  996. #endif
  997. #ifdef CONFIG_ARM
  998. {
  999. .procname = "boot_reason",
  1000. .data = &boot_reason,
  1001. .maxlen = sizeof(int),
  1002. .mode = 0444,
  1003. .proc_handler = proc_dointvec,
  1004. },
  1005. {
  1006. .procname = "cold_boot",
  1007. .data = &cold_boot,
  1008. .maxlen = sizeof(int),
  1009. .mode = 0444,
  1010. .proc_handler = proc_dointvec,
  1011. },
  1012. #endif
  1013. /*
  1014. * NOTE: do not add new entries to this table unless you have read
  1015. * Documentation/sysctl/ctl_unnumbered.txt
  1016. */
  1017. { }
  1018. };
  1019. static struct ctl_table vm_table[] = {
  1020. {
  1021. .procname = "overcommit_memory",
  1022. .data = &sysctl_overcommit_memory,
  1023. .maxlen = sizeof(sysctl_overcommit_memory),
  1024. .mode = 0644,
  1025. .proc_handler = proc_dointvec_minmax,
  1026. .extra1 = &zero,
  1027. .extra2 = &two,
  1028. },
  1029. {
  1030. .procname = "panic_on_oom",
  1031. .data = &sysctl_panic_on_oom,
  1032. .maxlen = sizeof(sysctl_panic_on_oom),
  1033. .mode = 0644,
  1034. .proc_handler = proc_dointvec_minmax,
  1035. .extra1 = &zero,
  1036. .extra2 = &two,
  1037. },
  1038. {
  1039. .procname = "oom_kill_allocating_task",
  1040. .data = &sysctl_oom_kill_allocating_task,
  1041. .maxlen = sizeof(sysctl_oom_kill_allocating_task),
  1042. .mode = 0644,
  1043. .proc_handler = proc_dointvec,
  1044. },
  1045. {
  1046. .procname = "oom_dump_tasks",
  1047. .data = &sysctl_oom_dump_tasks,
  1048. .maxlen = sizeof(sysctl_oom_dump_tasks),
  1049. .mode = 0644,
  1050. .proc_handler = proc_dointvec,
  1051. },
  1052. {
  1053. .procname = "overcommit_ratio",
  1054. .data = &sysctl_overcommit_ratio,
  1055. .maxlen = sizeof(sysctl_overcommit_ratio),
  1056. .mode = 0644,
  1057. .proc_handler = proc_dointvec,
  1058. },
  1059. {
  1060. .procname = "page-cluster",
  1061. .data = &page_cluster,
  1062. .maxlen = sizeof(int),
  1063. .mode = 0644,
  1064. .proc_handler = proc_dointvec_minmax,
  1065. .extra1 = &zero,
  1066. },
  1067. {
  1068. .procname = "dirty_background_ratio",
  1069. .data = &dirty_background_ratio,
  1070. .maxlen = sizeof(dirty_background_ratio),
  1071. .mode = 0644,
  1072. .proc_handler = dirty_background_ratio_handler,
  1073. .extra1 = &zero,
  1074. .extra2 = &one_hundred,
  1075. },
  1076. {
  1077. .procname = "dirty_background_bytes",
  1078. .data = &dirty_background_bytes,
  1079. .maxlen = sizeof(dirty_background_bytes),
  1080. .mode = 0644,
  1081. .proc_handler = dirty_background_bytes_handler,
  1082. .extra1 = &one_ul,
  1083. },
  1084. {
  1085. .procname = "dirty_ratio",
  1086. .data = &vm_dirty_ratio,
  1087. .maxlen = sizeof(vm_dirty_ratio),
  1088. .mode = 0644,
  1089. .proc_handler = dirty_ratio_handler,
  1090. .extra1 = &zero,
  1091. .extra2 = &one_hundred,
  1092. },
  1093. {
  1094. .procname = "dirty_bytes",
  1095. .data = &vm_dirty_bytes,
  1096. .maxlen = sizeof(vm_dirty_bytes),
  1097. .mode = 0644,
  1098. .proc_handler = dirty_bytes_handler,
  1099. .extra1 = &dirty_bytes_min,
  1100. },
  1101. {
  1102. .procname = "dirty_writeback_centisecs",
  1103. .data = &dirty_writeback_interval,
  1104. .maxlen = sizeof(dirty_writeback_interval),
  1105. .mode = 0644,
  1106. .proc_handler = dirty_writeback_centisecs_handler,
  1107. },
  1108. {
  1109. .procname = "dirty_expire_centisecs",
  1110. .data = &dirty_expire_interval,
  1111. .maxlen = sizeof(dirty_expire_interval),
  1112. .mode = 0644,
  1113. .proc_handler = proc_dointvec_minmax,
  1114. .extra1 = &zero,
  1115. },
  1116. {
  1117. .procname = "nr_pdflush_threads",
  1118. .data = &nr_pdflush_threads,
  1119. .maxlen = sizeof nr_pdflush_threads,
  1120. .mode = 0444 /* read-only*/,
  1121. .proc_handler = proc_dointvec,
  1122. },
  1123. {
  1124. .procname = "swappiness",
  1125. .data = &vm_swappiness,
  1126. .maxlen = sizeof(vm_swappiness),
  1127. .mode = 0644,
  1128. .proc_handler = proc_dointvec_minmax,
  1129. .extra1 = &zero,
  1130. #ifdef CONFIG_INCREASE_MAXIMUM_SWAPPINESS
  1131. .extra2 = &max_swappiness,
  1132. #else
  1133. .extra2 = &one_hundred,
  1134. #endif
  1135. },
  1136. #ifdef CONFIG_HUGETLB_PAGE
  1137. {
  1138. .procname = "nr_hugepages",
  1139. .data = NULL,
  1140. .maxlen = sizeof(unsigned long),
  1141. .mode = 0644,
  1142. .proc_handler = hugetlb_sysctl_handler,
  1143. .extra1 = (void *)&hugetlb_zero,
  1144. .extra2 = (void *)&hugetlb_infinity,
  1145. },
  1146. #ifdef CONFIG_NUMA
  1147. {
  1148. .procname = "nr_hugepages_mempolicy",
  1149. .data = NULL,
  1150. .maxlen = sizeof(unsigned long),
  1151. .mode = 0644,
  1152. .proc_handler = &hugetlb_mempolicy_sysctl_handler,
  1153. .extra1 = (void *)&hugetlb_zero,
  1154. .extra2 = (void *)&hugetlb_infinity,
  1155. },
  1156. #endif
  1157. {
  1158. .procname = "hugetlb_shm_group",
  1159. .data = &sysctl_hugetlb_shm_group,
  1160. .maxlen = sizeof(gid_t),
  1161. .mode = 0644,
  1162. .proc_handler = proc_dointvec,
  1163. },
  1164. {
  1165. .procname = "hugepages_treat_as_movable",
  1166. .data = &hugepages_treat_as_movable,
  1167. .maxlen = sizeof(int),
  1168. .mode = 0644,
  1169. .proc_handler = hugetlb_treat_movable_handler,
  1170. },
  1171. {
  1172. .procname = "nr_overcommit_hugepages",
  1173. .data = NULL,
  1174. .maxlen = sizeof(unsigned long),
  1175. .mode = 0644,
  1176. .proc_handler = hugetlb_overcommit_handler,
  1177. .extra1 = (void *)&hugetlb_zero,
  1178. .extra2 = (void *)&hugetlb_infinity,
  1179. },
  1180. #endif
  1181. {
  1182. .procname = "lowmem_reserve_ratio",
  1183. .data = &sysctl_lowmem_reserve_ratio,
  1184. .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
  1185. .mode = 0644,
  1186. .proc_handler = lowmem_reserve_ratio_sysctl_handler,
  1187. },
  1188. {
  1189. .procname = "drop_caches",
  1190. .data = &sysctl_drop_caches,
  1191. .maxlen = sizeof(int),
  1192. .mode = 0644,
  1193. .proc_handler = drop_caches_sysctl_handler,
  1194. .extra1 = &one,
  1195. .extra2 = &three,
  1196. },
  1197. #ifdef CONFIG_COMPACTION
  1198. {
  1199. .procname = "compact_memory",
  1200. .data = &sysctl_compact_memory,
  1201. .maxlen = sizeof(int),
  1202. .mode = 0644,
  1203. .proc_handler = sysctl_compaction_handler,
  1204. },
  1205. {
  1206. .procname = "extfrag_threshold",
  1207. .data = &sysctl_extfrag_threshold,
  1208. .maxlen = sizeof(int),
  1209. .mode = 0644,
  1210. .proc_handler = sysctl_extfrag_handler,
  1211. .extra1 = &min_extfrag_threshold,
  1212. .extra2 = &max_extfrag_threshold,
  1213. },
  1214. #endif /* CONFIG_COMPACTION */
  1215. {
  1216. .procname = "min_free_kbytes",
  1217. .data = &min_free_kbytes,
  1218. .maxlen = sizeof(min_free_kbytes),
  1219. .mode = 0644,
  1220. .proc_handler = min_free_kbytes_sysctl_handler,
  1221. .extra1 = &zero,
  1222. },
  1223. {
  1224. .procname = "extra_free_kbytes",
  1225. .data = &extra_free_kbytes,
  1226. .maxlen = sizeof(extra_free_kbytes),
  1227. .mode = 0644,
  1228. .proc_handler = min_free_kbytes_sysctl_handler,
  1229. .extra1 = &zero,
  1230. },
  1231. {
  1232. .procname = "min_free_order_shift",
  1233. .data = &min_free_order_shift,
  1234. .maxlen = sizeof(min_free_order_shift),
  1235. .mode = 0644,
  1236. .proc_handler = &proc_dointvec
  1237. },
  1238. {
  1239. .procname = "percpu_pagelist_fraction",
  1240. .data = &percpu_pagelist_fraction,
  1241. .maxlen = sizeof(percpu_pagelist_fraction),
  1242. .mode = 0644,
  1243. .proc_handler = percpu_pagelist_fraction_sysctl_handler,
  1244. .extra1 = &min_percpu_pagelist_fract,
  1245. },
  1246. #ifdef CONFIG_MMU
  1247. {
  1248. .procname = "max_map_count",
  1249. .data = &sysctl_max_map_count,
  1250. .maxlen = sizeof(sysctl_max_map_count),
  1251. .mode = 0644,
  1252. .proc_handler = proc_dointvec_minmax,
  1253. .extra1 = &zero,
  1254. },
  1255. #else
  1256. {
  1257. .procname = "nr_trim_pages",
  1258. .data = &sysctl_nr_trim_pages,
  1259. .maxlen = sizeof(sysctl_nr_trim_pages),
  1260. .mode = 0644,
  1261. .proc_handler = proc_dointvec_minmax,
  1262. .extra1 = &zero,
  1263. },
  1264. #endif
  1265. {
  1266. .procname = "laptop_mode",
  1267. .data = &laptop_mode,
  1268. .maxlen = sizeof(laptop_mode),
  1269. .mode = 0644,
  1270. .proc_handler = proc_dointvec_jiffies,
  1271. },
  1272. {
  1273. .procname = "block_dump",
  1274. .data = &block_dump,
  1275. .maxlen = sizeof(block_dump),
  1276. .mode = 0644,
  1277. .proc_handler = proc_dointvec,
  1278. .extra1 = &zero,
  1279. },
  1280. {
  1281. .procname = "vfs_cache_pressure",
  1282. .data = &sysctl_vfs_cache_pressure,
  1283. .maxlen = sizeof(sysctl_vfs_cache_pressure),
  1284. .mode = 0644,
  1285. .proc_handler = proc_dointvec,
  1286. .extra1 = &zero,
  1287. },
  1288. #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
  1289. {
  1290. .procname = "legacy_va_layout",
  1291. .data = &sysctl_legacy_va_layout,
  1292. .maxlen = sizeof(sysctl_legacy_va_layout),
  1293. .mode = 0644,
  1294. .proc_handler = proc_dointvec,
  1295. .extra1 = &zero,
  1296. },
  1297. #endif
  1298. #ifdef CONFIG_NUMA
  1299. {
  1300. .procname = "zone_reclaim_mode",
  1301. .data = &zone_reclaim_mode,
  1302. .maxlen = sizeof(zone_reclaim_mode),
  1303. .mode = 0644,
  1304. .proc_handler = proc_dointvec,
  1305. .extra1 = &zero,
  1306. },
  1307. {
  1308. .procname = "min_unmapped_ratio",
  1309. .data = &sysctl_min_unmapped_ratio,
  1310. .maxlen = sizeof(sysctl_min_unmapped_ratio),
  1311. .mode = 0644,
  1312. .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
  1313. .extra1 = &zero,
  1314. .extra2 = &one_hundred,
  1315. },
  1316. {
  1317. .procname = "min_slab_ratio",
  1318. .data = &sysctl_min_slab_ratio,
  1319. .maxlen = sizeof(sysctl_min_slab_ratio),
  1320. .mode = 0644,
  1321. .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
  1322. .extra1 = &zero,
  1323. .extra2 = &one_hundred,
  1324. },
  1325. #endif
  1326. #ifdef CONFIG_SMP
  1327. {
  1328. .procname = "stat_interval",
  1329. .data = &sysctl_stat_interval,
  1330. .maxlen = sizeof(sysctl_stat_interval),
  1331. .mode = 0644,
  1332. .proc_handler = proc_dointvec_jiffies,
  1333. },
  1334. #endif
  1335. #ifdef CONFIG_MMU
  1336. {
  1337. .procname = "mmap_min_addr",
  1338. .data = &dac_mmap_min_addr,
  1339. .maxlen = sizeof(unsigned long),
  1340. .mode = 0644,
  1341. .proc_handler = mmap_min_addr_handler,
  1342. },
  1343. #endif
  1344. #ifdef CONFIG_NUMA
  1345. {
  1346. .procname = "numa_zonelist_order",
  1347. .data = &numa_zonelist_order,
  1348. .maxlen = NUMA_ZONELIST_ORDER_LEN,
  1349. .mode = 0644,
  1350. .proc_handler = numa_zonelist_order_handler,
  1351. },
  1352. #endif
  1353. #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
  1354. (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
  1355. {
  1356. .procname = "vdso_enabled",
  1357. .data = &vdso_enabled,
  1358. .maxlen = sizeof(vdso_enabled),
  1359. .mode = 0644,
  1360. .proc_handler = proc_dointvec,
  1361. .extra1 = &zero,
  1362. },
  1363. #endif
  1364. #ifdef CONFIG_HIGHMEM
  1365. {
  1366. .procname = "highmem_is_dirtyable",
  1367. .data = &vm_highmem_is_dirtyable,
  1368. .maxlen = sizeof(vm_highmem_is_dirtyable),
  1369. .mode = 0644,
  1370. .proc_handler = proc_dointvec_minmax,
  1371. .extra1 = &zero,
  1372. .extra2 = &one,
  1373. },
  1374. #endif
  1375. {
  1376. .procname = "scan_unevictable_pages",
  1377. .data = &scan_unevictable_pages,
  1378. .maxlen = sizeof(scan_unevictable_pages),
  1379. .mode = 0644,
  1380. .proc_handler = scan_unevictable_handler,
  1381. },
  1382. #ifdef CONFIG_MEMORY_FAILURE
  1383. {
  1384. .procname = "memory_failure_early_kill",
  1385. .data = &sysctl_memory_failure_early_kill,
  1386. .maxlen = sizeof(sysctl_memory_failure_early_kill),
  1387. .mode = 0644,
  1388. .proc_handler = proc_dointvec_minmax,
  1389. .extra1 = &zero,
  1390. .extra2 = &one,
  1391. },
  1392. {
  1393. .procname = "memory_failure_recovery",
  1394. .data = &sysctl_memory_failure_recovery,
  1395. .maxlen = sizeof(sysctl_memory_failure_recovery),
  1396. .mode = 0644,
  1397. .proc_handler = proc_dointvec_minmax,
  1398. .extra1 = &zero,
  1399. .extra2 = &one,
  1400. },
  1401. #endif
  1402. #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
  1403. {
  1404. .procname = "mmap_rnd_bits",
  1405. .data = &mmap_rnd_bits,
  1406. .maxlen = sizeof(mmap_rnd_bits),
  1407. .mode = 0600,
  1408. .proc_handler = proc_dointvec_minmax,
  1409. .extra1 = (void *)&mmap_rnd_bits_min,
  1410. .extra2 = (void *)&mmap_rnd_bits_max,
  1411. },
  1412. #endif
  1413. #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
  1414. {
  1415. .procname = "mmap_rnd_compat_bits",
  1416. .data = &mmap_rnd_compat_bits,
  1417. .maxlen = sizeof(mmap_rnd_compat_bits),
  1418. .mode = 0600,
  1419. .proc_handler = proc_dointvec_minmax,
  1420. .extra1 = (void *)&mmap_rnd_compat_bits_min,
  1421. .extra2 = (void *)&mmap_rnd_compat_bits_max,
  1422. },
  1423. #endif
  1424. { }
  1425. };
  1426. #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
  1427. static struct ctl_table binfmt_misc_table[] = {
  1428. { }
  1429. };
  1430. #endif
  1431. static struct ctl_table fs_table[] = {
  1432. {
  1433. .procname = "inode-nr",
  1434. .data = &inodes_stat,
  1435. .maxlen = 2*sizeof(long),
  1436. .mode = 0444,
  1437. .proc_handler = proc_nr_inodes,
  1438. },
  1439. {
  1440. .procname = "inode-state",
  1441. .data = &inodes_stat,
  1442. .maxlen = 7*sizeof(long),
  1443. .mode = 0444,
  1444. .proc_handler = proc_nr_inodes,
  1445. },
  1446. {
  1447. .procname = "file-nr",
  1448. .data = &files_stat,
  1449. .maxlen = sizeof(files_stat),
  1450. .mode = 0444,
  1451. .proc_handler = proc_nr_files,
  1452. },
  1453. {
  1454. .procname = "file-max",
  1455. .data = &files_stat.max_files,
  1456. .maxlen = sizeof(files_stat.max_files),
  1457. .mode = 0644,
  1458. .proc_handler = proc_doulongvec_minmax,
  1459. },
  1460. {
  1461. .procname = "nr_open",
  1462. .data = &sysctl_nr_open,
  1463. .maxlen = sizeof(int),
  1464. .mode = 0644,
  1465. .proc_handler = proc_dointvec_minmax,
  1466. .extra1 = &sysctl_nr_open_min,
  1467. .extra2 = &sysctl_nr_open_max,
  1468. },
  1469. {
  1470. .procname = "dentry-state",
  1471. .data = &dentry_stat,
  1472. .maxlen = 6*sizeof(long),
  1473. .mode = 0444,
  1474. .proc_handler = proc_nr_dentry,
  1475. },
  1476. {
  1477. .procname = "overflowuid",
  1478. .data = &fs_overflowuid,
  1479. .maxlen = sizeof(int),
  1480. .mode = 0644,
  1481. .proc_handler = proc_dointvec_minmax,
  1482. .extra1 = &minolduid,
  1483. .extra2 = &maxolduid,
  1484. },
  1485. {
  1486. .procname = "overflowgid",
  1487. .data = &fs_overflowgid,
  1488. .maxlen = sizeof(int),
  1489. .mode = 0644,
  1490. .proc_handler = proc_dointvec_minmax,
  1491. .extra1 = &minolduid,
  1492. .extra2 = &maxolduid,
  1493. },
  1494. #ifdef CONFIG_FILE_LOCKING
  1495. {
  1496. .procname = "leases-enable",
  1497. .data = &leases_enable,
  1498. .maxlen = sizeof(int),
  1499. .mode = 0644,
  1500. .proc_handler = proc_dointvec,
  1501. },
  1502. #endif
  1503. #ifdef CONFIG_DNOTIFY
  1504. {
  1505. .procname = "dir-notify-enable",
  1506. .data = &dir_notify_enable,
  1507. .maxlen = sizeof(int),
  1508. .mode = 0644,
  1509. .proc_handler = proc_dointvec,
  1510. },
  1511. #endif
  1512. #ifdef CONFIG_MMU
  1513. #ifdef CONFIG_FILE_LOCKING
  1514. {
  1515. .procname = "lease-break-time",
  1516. .data = &lease_break_time,
  1517. .maxlen = sizeof(int),
  1518. .mode = 0644,
  1519. .proc_handler = proc_dointvec,
  1520. },
  1521. #endif
  1522. #ifdef CONFIG_AIO
  1523. {
  1524. .procname = "aio-nr",
  1525. .data = &aio_nr,
  1526. .maxlen = sizeof(aio_nr),
  1527. .mode = 0444,
  1528. .proc_handler = proc_doulongvec_minmax,
  1529. },
  1530. {
  1531. .procname = "aio-max-nr",
  1532. .data = &aio_max_nr,
  1533. .maxlen = sizeof(aio_max_nr),
  1534. .mode = 0644,
  1535. .proc_handler = proc_doulongvec_minmax,
  1536. },
  1537. #endif /* CONFIG_AIO */
  1538. #ifdef CONFIG_INOTIFY_USER
  1539. {
  1540. .procname = "inotify",
  1541. .mode = 0555,
  1542. .child = inotify_table,
  1543. },
  1544. #endif
  1545. #ifdef CONFIG_EPOLL
  1546. {
  1547. .procname = "epoll",
  1548. .mode = 0555,
  1549. .child = epoll_table,
  1550. },
  1551. #endif
  1552. #endif
  1553. {
  1554. .procname = "suid_dumpable",
  1555. .data = &suid_dumpable,
  1556. .maxlen = sizeof(int),
  1557. .mode = 0644,
  1558. .proc_handler = proc_dointvec_minmax,
  1559. .extra1 = &zero,
  1560. .extra2 = &two,
  1561. },
  1562. #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
  1563. {
  1564. .procname = "binfmt_misc",
  1565. .mode = 0555,
  1566. .child = binfmt_misc_table,
  1567. },
  1568. #endif
  1569. {
  1570. .procname = "pipe-max-size",
  1571. .data = &pipe_max_size,
  1572. .maxlen = sizeof(int),
  1573. .mode = 0644,
  1574. .proc_handler = &pipe_proc_fn,
  1575. .extra1 = &pipe_min_size,
  1576. },
  1577. {
  1578. .procname = "pipe-user-pages-hard",
  1579. .data = &pipe_user_pages_hard,
  1580. .maxlen = sizeof(pipe_user_pages_hard),
  1581. .mode = 0644,
  1582. .proc_handler = proc_doulongvec_minmax,
  1583. },
  1584. {
  1585. .procname = "pipe-user-pages-soft",
  1586. .data = &pipe_user_pages_soft,
  1587. .maxlen = sizeof(pipe_user_pages_soft),
  1588. .mode = 0644,
  1589. .proc_handler = proc_doulongvec_minmax,
  1590. },
  1591. { }
  1592. };
  1593. static struct ctl_table debug_table[] = {
  1594. #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
  1595. defined(CONFIG_S390) || defined(CONFIG_TILE)
  1596. {
  1597. .procname = "exception-trace",
  1598. .data = &show_unhandled_signals,
  1599. .maxlen = sizeof(int),
  1600. .mode = 0644,
  1601. .proc_handler = proc_dointvec
  1602. },
  1603. #endif
  1604. #if defined(CONFIG_OPTPROBES)
  1605. {
  1606. .procname = "kprobes-optimization",
  1607. .data = &sysctl_kprobes_optimization,
  1608. .maxlen = sizeof(int),
  1609. .mode = 0644,
  1610. .proc_handler = proc_kprobes_optimization_handler,
  1611. .extra1 = &zero,
  1612. .extra2 = &one,
  1613. },
  1614. #endif
  1615. { }
  1616. };
  1617. static struct ctl_table dev_table[] = {
  1618. { }
  1619. };
  1620. int __init sysctl_init(void)
  1621. {
  1622. register_sysctl_table(sysctl_base_table);
  1623. return 0;
  1624. }
  1625. #endif /* CONFIG_SYSCTL */
  1626. /*
  1627. * /proc/sys support
  1628. */
  1629. #ifdef CONFIG_PROC_SYSCTL
  1630. static int _proc_do_string(void* data, int maxlen, int write,
  1631. void __user *buffer,
  1632. size_t *lenp, loff_t *ppos)
  1633. {
  1634. size_t len;
  1635. char __user *p;
  1636. char c;
  1637. if (!data || !maxlen || !*lenp) {
  1638. *lenp = 0;
  1639. return 0;
  1640. }
  1641. if (write) {
  1642. len = 0;
  1643. p = buffer;
  1644. while (len < *lenp) {
  1645. if (get_user(c, p++))
  1646. return -EFAULT;
  1647. if (c == 0 || c == '\n')
  1648. break;
  1649. len++;
  1650. }
  1651. if (len >= maxlen)
  1652. len = maxlen-1;
  1653. if(copy_from_user(data, buffer, len))
  1654. return -EFAULT;
  1655. ((char *) data)[len] = 0;
  1656. *ppos += *lenp;
  1657. } else {
  1658. len = strlen(data);
  1659. if (len > maxlen)
  1660. len = maxlen;
  1661. if (*ppos > len) {
  1662. *lenp = 0;
  1663. return 0;
  1664. }
  1665. data += *ppos;
  1666. len -= *ppos;
  1667. if (len > *lenp)
  1668. len = *lenp;
  1669. if (len)
  1670. if(copy_to_user(buffer, data, len))
  1671. return -EFAULT;
  1672. if (len < *lenp) {
  1673. if(put_user('\n', ((char __user *) buffer) + len))
  1674. return -EFAULT;
  1675. len++;
  1676. }
  1677. *lenp = len;
  1678. *ppos += len;
  1679. }
  1680. return 0;
  1681. }
  1682. /**
  1683. * proc_dostring - read a string sysctl
  1684. * @table: the sysctl table
  1685. * @write: %TRUE if this is a write to the sysctl file
  1686. * @buffer: the user buffer
  1687. * @lenp: the size of the user buffer
  1688. * @ppos: file position
  1689. *
  1690. * Reads/writes a string from/to the user buffer. If the kernel
  1691. * buffer provided is not large enough to hold the string, the
  1692. * string is truncated. The copied string is %NULL-terminated.
  1693. * If the string is being read by the user process, it is copied
  1694. * and a newline '\n' is added. It is truncated if the buffer is
  1695. * not large enough.
  1696. *
  1697. * Returns 0 on success.
  1698. */
  1699. int proc_dostring(struct ctl_table *table, int write,
  1700. void __user *buffer, size_t *lenp, loff_t *ppos)
  1701. {
  1702. return _proc_do_string(table->data, table->maxlen, write,
  1703. buffer, lenp, ppos);
  1704. }
  1705. static size_t proc_skip_spaces(char **buf)
  1706. {
  1707. size_t ret;
  1708. char *tmp = skip_spaces(*buf);
  1709. ret = tmp - *buf;
  1710. *buf = tmp;
  1711. return ret;
  1712. }
  1713. static void proc_skip_char(char **buf, size_t *size, const char v)
  1714. {
  1715. while (*size) {
  1716. if (**buf != v)
  1717. break;
  1718. (*size)--;
  1719. (*buf)++;
  1720. }
  1721. }
  1722. #define TMPBUFLEN 22
  1723. /**
  1724. * proc_get_long - reads an ASCII formatted integer from a user buffer
  1725. *
  1726. * @buf: a kernel buffer
  1727. * @size: size of the kernel buffer
  1728. * @val: this is where the number will be stored
  1729. * @neg: set to %TRUE if number is negative
  1730. * @perm_tr: a vector which contains the allowed trailers
  1731. * @perm_tr_len: size of the perm_tr vector
  1732. * @tr: pointer to store the trailer character
  1733. *
  1734. * In case of success %0 is returned and @buf and @size are updated with
  1735. * the amount of bytes read. If @tr is non-NULL and a trailing
  1736. * character exists (size is non-zero after returning from this
  1737. * function), @tr is updated with the trailing character.
  1738. */
  1739. static int proc_get_long(char **buf, size_t *size,
  1740. unsigned long *val, bool *neg,
  1741. const char *perm_tr, unsigned perm_tr_len, char *tr)
  1742. {
  1743. int len;
  1744. char *p, tmp[TMPBUFLEN];
  1745. if (!*size)
  1746. return -EINVAL;
  1747. len = *size;
  1748. if (len > TMPBUFLEN - 1)
  1749. len = TMPBUFLEN - 1;
  1750. memcpy(tmp, *buf, len);
  1751. tmp[len] = 0;
  1752. p = tmp;
  1753. if (*p == '-' && *size > 1) {
  1754. *neg = true;
  1755. p++;
  1756. } else
  1757. *neg = false;
  1758. if (!isdigit(*p))
  1759. return -EINVAL;
  1760. *val = simple_strtoul(p, &p, 0);
  1761. len = p - tmp;
  1762. /* We don't know if the next char is whitespace thus we may accept
  1763. * invalid integers (e.g. 1234...a) or two integers instead of one
  1764. * (e.g. 123...1). So lets not allow such large numbers. */
  1765. if (len == TMPBUFLEN - 1)
  1766. return -EINVAL;
  1767. if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
  1768. return -EINVAL;
  1769. if (tr && (len < *size))
  1770. *tr = *p;
  1771. *buf += len;
  1772. *size -= len;
  1773. return 0;
  1774. }
  1775. /**
  1776. * proc_put_long - converts an integer to a decimal ASCII formatted string
  1777. *
  1778. * @buf: the user buffer
  1779. * @size: the size of the user buffer
  1780. * @val: the integer to be converted
  1781. * @neg: sign of the number, %TRUE for negative
  1782. *
  1783. * In case of success %0 is returned and @buf and @size are updated with
  1784. * the amount of bytes written.
  1785. */
  1786. static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
  1787. bool neg)
  1788. {
  1789. int len;
  1790. char tmp[TMPBUFLEN], *p = tmp;
  1791. sprintf(p, "%s%lu", neg ? "-" : "", val);
  1792. len = strlen(tmp);
  1793. if (len > *size)
  1794. len = *size;
  1795. if (copy_to_user(*buf, tmp, len))
  1796. return -EFAULT;
  1797. *size -= len;
  1798. *buf += len;
  1799. return 0;
  1800. }
  1801. #undef TMPBUFLEN
  1802. static int proc_put_char(void __user **buf, size_t *size, char c)
  1803. {
  1804. if (*size) {
  1805. char __user **buffer = (char __user **)buf;
  1806. if (put_user(c, *buffer))
  1807. return -EFAULT;
  1808. (*size)--, (*buffer)++;
  1809. *buf = *buffer;
  1810. }
  1811. return 0;
  1812. }
  1813. static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
  1814. int *valp,
  1815. int write, void *data)
  1816. {
  1817. if (write) {
  1818. *valp = *negp ? -*lvalp : *lvalp;
  1819. } else {
  1820. int val = *valp;
  1821. if (val < 0) {
  1822. *negp = true;
  1823. *lvalp = (unsigned long)-val;
  1824. } else {
  1825. *negp = false;
  1826. *lvalp = (unsigned long)val;
  1827. }
  1828. }
  1829. return 0;
  1830. }
  1831. static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
  1832. static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
  1833. int write, void __user *buffer,
  1834. size_t *lenp, loff_t *ppos,
  1835. int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
  1836. int write, void *data),
  1837. void *data)
  1838. {
  1839. int *i, vleft, first = 1, err = 0;
  1840. unsigned long page = 0;
  1841. size_t left;
  1842. char *kbuf;
  1843. if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
  1844. *lenp = 0;
  1845. return 0;
  1846. }
  1847. i = (int *) tbl_data;
  1848. vleft = table->maxlen / sizeof(*i);
  1849. left = *lenp;
  1850. if (!conv)
  1851. conv = do_proc_dointvec_conv;
  1852. if (write) {
  1853. if (left > PAGE_SIZE - 1)
  1854. left = PAGE_SIZE - 1;
  1855. page = __get_free_page(GFP_TEMPORARY);
  1856. kbuf = (char *) page;
  1857. if (!kbuf)
  1858. return -ENOMEM;
  1859. if (copy_from_user(kbuf, buffer, left)) {
  1860. err = -EFAULT;
  1861. goto free;
  1862. }
  1863. kbuf[left] = 0;
  1864. }
  1865. for (; left && vleft--; i++, first=0) {
  1866. unsigned long lval;
  1867. bool neg;
  1868. if (write) {
  1869. left -= proc_skip_spaces(&kbuf);
  1870. if (!left)
  1871. break;
  1872. err = proc_get_long(&kbuf, &left, &lval, &neg,
  1873. proc_wspace_sep,
  1874. sizeof(proc_wspace_sep), NULL);
  1875. if (err)
  1876. break;
  1877. if (conv(&neg, &lval, i, 1, data)) {
  1878. err = -EINVAL;
  1879. break;
  1880. }
  1881. } else {
  1882. if (conv(&neg, &lval, i, 0, data)) {
  1883. err = -EINVAL;
  1884. break;
  1885. }
  1886. if (!first)
  1887. err = proc_put_char(&buffer, &left, '\t');
  1888. if (err)
  1889. break;
  1890. err = proc_put_long(&buffer, &left, lval, neg);
  1891. if (err)
  1892. break;
  1893. }
  1894. }
  1895. if (!write && !first && left && !err)
  1896. err = proc_put_char(&buffer, &left, '\n');
  1897. if (write && !err && left)
  1898. left -= proc_skip_spaces(&kbuf);
  1899. free:
  1900. if (write) {
  1901. free_page(page);
  1902. if (first)
  1903. return err ? : -EINVAL;
  1904. }
  1905. *lenp -= left;
  1906. *ppos += *lenp;
  1907. return err;
  1908. }
  1909. static int do_proc_dointvec(struct ctl_table *table, int write,
  1910. void __user *buffer, size_t *lenp, loff_t *ppos,
  1911. int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
  1912. int write, void *data),
  1913. void *data)
  1914. {
  1915. return __do_proc_dointvec(table->data, table, write,
  1916. buffer, lenp, ppos, conv, data);
  1917. }
  1918. /**
  1919. * proc_dointvec - read a vector of integers
  1920. * @table: the sysctl table
  1921. * @write: %TRUE if this is a write to the sysctl file
  1922. * @buffer: the user buffer
  1923. * @lenp: the size of the user buffer
  1924. * @ppos: file position
  1925. *
  1926. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1927. * values from/to the user buffer, treated as an ASCII string.
  1928. *
  1929. * Returns 0 on success.
  1930. */
  1931. int proc_dointvec(struct ctl_table *table, int write,
  1932. void __user *buffer, size_t *lenp, loff_t *ppos)
  1933. {
  1934. return do_proc_dointvec(table,write,buffer,lenp,ppos,
  1935. NULL,NULL);
  1936. }
  1937. /*
  1938. * Taint values can only be increased
  1939. * This means we can safely use a temporary.
  1940. */
  1941. static int proc_taint(struct ctl_table *table, int write,
  1942. void __user *buffer, size_t *lenp, loff_t *ppos)
  1943. {
  1944. struct ctl_table t;
  1945. unsigned long tmptaint = get_taint();
  1946. int err;
  1947. if (write && !capable(CAP_SYS_ADMIN))
  1948. return -EPERM;
  1949. t = *table;
  1950. t.data = &tmptaint;
  1951. err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
  1952. if (err < 0)
  1953. return err;
  1954. if (write) {
  1955. /*
  1956. * Poor man's atomic or. Not worth adding a primitive
  1957. * to everyone's atomic.h for this
  1958. */
  1959. int i;
  1960. for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
  1961. if ((tmptaint >> i) & 1)
  1962. add_taint(i);
  1963. }
  1964. }
  1965. return err;
  1966. }
  1967. #ifdef CONFIG_PRINTK
  1968. static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
  1969. void __user *buffer, size_t *lenp, loff_t *ppos)
  1970. {
  1971. if (write && !capable(CAP_SYS_ADMIN))
  1972. return -EPERM;
  1973. return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
  1974. }
  1975. #endif
  1976. struct do_proc_dointvec_minmax_conv_param {
  1977. int *min;
  1978. int *max;
  1979. };
  1980. static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
  1981. int *valp,
  1982. int write, void *data)
  1983. {
  1984. struct do_proc_dointvec_minmax_conv_param *param = data;
  1985. if (write) {
  1986. int val;
  1987. if (*negp) {
  1988. if (*lvalp > (unsigned long) INT_MAX + 1)
  1989. return -EINVAL;
  1990. val = -*lvalp;
  1991. } else {
  1992. if (*lvalp > (unsigned long) INT_MAX)
  1993. return -EINVAL;
  1994. val = *lvalp;
  1995. }
  1996. if ((param->min && *param->min > val) ||
  1997. (param->max && *param->max < val))
  1998. return -EINVAL;
  1999. *valp = val;
  2000. } else {
  2001. int val = *valp;
  2002. if (val < 0) {
  2003. *negp = true;
  2004. *lvalp = (unsigned long)-val;
  2005. } else {
  2006. *negp = false;
  2007. *lvalp = (unsigned long)val;
  2008. }
  2009. }
  2010. return 0;
  2011. }
  2012. /**
  2013. * proc_dointvec_minmax - read a vector of integers with min/max values
  2014. * @table: the sysctl table
  2015. * @write: %TRUE if this is a write to the sysctl file
  2016. * @buffer: the user buffer
  2017. * @lenp: the size of the user buffer
  2018. * @ppos: file position
  2019. *
  2020. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2021. * values from/to the user buffer, treated as an ASCII string.
  2022. *
  2023. * This routine will ensure the values are within the range specified by
  2024. * table->extra1 (min) and table->extra2 (max).
  2025. *
  2026. * Returns 0 on success.
  2027. */
  2028. int proc_dointvec_minmax(struct ctl_table *table, int write,
  2029. void __user *buffer, size_t *lenp, loff_t *ppos)
  2030. {
  2031. struct do_proc_dointvec_minmax_conv_param param = {
  2032. .min = (int *) table->extra1,
  2033. .max = (int *) table->extra2,
  2034. };
  2035. return do_proc_dointvec(table, write, buffer, lenp, ppos,
  2036. do_proc_dointvec_minmax_conv, &param);
  2037. }
  2038. static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
  2039. void __user *buffer,
  2040. size_t *lenp, loff_t *ppos,
  2041. unsigned long convmul,
  2042. unsigned long convdiv)
  2043. {
  2044. unsigned long *i, *min, *max;
  2045. int vleft, first = 1, err = 0;
  2046. unsigned long page = 0;
  2047. size_t left;
  2048. char *kbuf;
  2049. if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
  2050. *lenp = 0;
  2051. return 0;
  2052. }
  2053. i = (unsigned long *) data;
  2054. min = (unsigned long *) table->extra1;
  2055. max = (unsigned long *) table->extra2;
  2056. vleft = table->maxlen / sizeof(unsigned long);
  2057. left = *lenp;
  2058. if (write) {
  2059. if (left > PAGE_SIZE - 1)
  2060. left = PAGE_SIZE - 1;
  2061. page = __get_free_page(GFP_TEMPORARY);
  2062. kbuf = (char *) page;
  2063. if (!kbuf)
  2064. return -ENOMEM;
  2065. if (copy_from_user(kbuf, buffer, left)) {
  2066. err = -EFAULT;
  2067. goto free;
  2068. }
  2069. kbuf[left] = 0;
  2070. }
  2071. for (; left && vleft--; i++, first = 0) {
  2072. unsigned long val;
  2073. if (write) {
  2074. bool neg;
  2075. left -= proc_skip_spaces(&kbuf);
  2076. err = proc_get_long(&kbuf, &left, &val, &neg,
  2077. proc_wspace_sep,
  2078. sizeof(proc_wspace_sep), NULL);
  2079. if (err)
  2080. break;
  2081. if (neg)
  2082. continue;
  2083. val = convmul * val / convdiv;
  2084. if ((min && val < *min) || (max && val > *max)) {
  2085. err = -EINVAL;
  2086. break;
  2087. }
  2088. *i = val;
  2089. } else {
  2090. val = convdiv * (*i) / convmul;
  2091. if (!first)
  2092. err = proc_put_char(&buffer, &left, '\t');
  2093. err = proc_put_long(&buffer, &left, val, false);
  2094. if (err)
  2095. break;
  2096. }
  2097. }
  2098. if (!write && !first && left && !err)
  2099. err = proc_put_char(&buffer, &left, '\n');
  2100. if (write && !err)
  2101. left -= proc_skip_spaces(&kbuf);
  2102. free:
  2103. if (write) {
  2104. free_page(page);
  2105. if (first)
  2106. return err ? : -EINVAL;
  2107. }
  2108. *lenp -= left;
  2109. *ppos += *lenp;
  2110. return err;
  2111. }
  2112. static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
  2113. void __user *buffer,
  2114. size_t *lenp, loff_t *ppos,
  2115. unsigned long convmul,
  2116. unsigned long convdiv)
  2117. {
  2118. return __do_proc_doulongvec_minmax(table->data, table, write,
  2119. buffer, lenp, ppos, convmul, convdiv);
  2120. }
  2121. /**
  2122. * proc_doulongvec_minmax - read a vector of long integers with min/max values
  2123. * @table: the sysctl table
  2124. * @write: %TRUE if this is a write to the sysctl file
  2125. * @buffer: the user buffer
  2126. * @lenp: the size of the user buffer
  2127. * @ppos: file position
  2128. *
  2129. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  2130. * values from/to the user buffer, treated as an ASCII string.
  2131. *
  2132. * This routine will ensure the values are within the range specified by
  2133. * table->extra1 (min) and table->extra2 (max).
  2134. *
  2135. * Returns 0 on success.
  2136. */
  2137. int proc_doulongvec_minmax(struct ctl_table *table, int write,
  2138. void __user *buffer, size_t *lenp, loff_t *ppos)
  2139. {
  2140. return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
  2141. }
  2142. /**
  2143. * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
  2144. * @table: the sysctl table
  2145. * @write: %TRUE if this is a write to the sysctl file
  2146. * @buffer: the user buffer
  2147. * @lenp: the size of the user buffer
  2148. * @ppos: file position
  2149. *
  2150. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  2151. * values from/to the user buffer, treated as an ASCII string. The values
  2152. * are treated as milliseconds, and converted to jiffies when they are stored.
  2153. *
  2154. * This routine will ensure the values are within the range specified by
  2155. * table->extra1 (min) and table->extra2 (max).
  2156. *
  2157. * Returns 0 on success.
  2158. */
  2159. int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
  2160. void __user *buffer,
  2161. size_t *lenp, loff_t *ppos)
  2162. {
  2163. return do_proc_doulongvec_minmax(table, write, buffer,
  2164. lenp, ppos, HZ, 1000l);
  2165. }
  2166. static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
  2167. int *valp,
  2168. int write, void *data)
  2169. {
  2170. if (write) {
  2171. if (*lvalp > LONG_MAX / HZ)
  2172. return 1;
  2173. *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
  2174. } else {
  2175. int val = *valp;
  2176. unsigned long lval;
  2177. if (val < 0) {
  2178. *negp = true;
  2179. lval = (unsigned long)-val;
  2180. } else {
  2181. *negp = false;
  2182. lval = (unsigned long)val;
  2183. }
  2184. *lvalp = lval / HZ;
  2185. }
  2186. return 0;
  2187. }
  2188. static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
  2189. int *valp,
  2190. int write, void *data)
  2191. {
  2192. if (write) {
  2193. if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
  2194. return 1;
  2195. *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
  2196. } else {
  2197. int val = *valp;
  2198. unsigned long lval;
  2199. if (val < 0) {
  2200. *negp = true;
  2201. lval = (unsigned long)-val;
  2202. } else {
  2203. *negp = false;
  2204. lval = (unsigned long)val;
  2205. }
  2206. *lvalp = jiffies_to_clock_t(lval);
  2207. }
  2208. return 0;
  2209. }
  2210. static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
  2211. int *valp,
  2212. int write, void *data)
  2213. {
  2214. if (write) {
  2215. *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
  2216. } else {
  2217. int val = *valp;
  2218. unsigned long lval;
  2219. if (val < 0) {
  2220. *negp = true;
  2221. lval = (unsigned long)-val;
  2222. } else {
  2223. *negp = false;
  2224. lval = (unsigned long)val;
  2225. }
  2226. *lvalp = jiffies_to_msecs(lval);
  2227. }
  2228. return 0;
  2229. }
  2230. /**
  2231. * proc_dointvec_jiffies - read a vector of integers as seconds
  2232. * @table: the sysctl table
  2233. * @write: %TRUE if this is a write to the sysctl file
  2234. * @buffer: the user buffer
  2235. * @lenp: the size of the user buffer
  2236. * @ppos: file position
  2237. *
  2238. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2239. * values from/to the user buffer, treated as an ASCII string.
  2240. * The values read are assumed to be in seconds, and are converted into
  2241. * jiffies.
  2242. *
  2243. * Returns 0 on success.
  2244. */
  2245. int proc_dointvec_jiffies(struct ctl_table *table, int write,
  2246. void __user *buffer, size_t *lenp, loff_t *ppos)
  2247. {
  2248. return do_proc_dointvec(table,write,buffer,lenp,ppos,
  2249. do_proc_dointvec_jiffies_conv,NULL);
  2250. }
  2251. /**
  2252. * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
  2253. * @table: the sysctl table
  2254. * @write: %TRUE if this is a write to the sysctl file
  2255. * @buffer: the user buffer
  2256. * @lenp: the size of the user buffer
  2257. * @ppos: pointer to the file position
  2258. *
  2259. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2260. * values from/to the user buffer, treated as an ASCII string.
  2261. * The values read are assumed to be in 1/USER_HZ seconds, and
  2262. * are converted into jiffies.
  2263. *
  2264. * Returns 0 on success.
  2265. */
  2266. int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
  2267. void __user *buffer, size_t *lenp, loff_t *ppos)
  2268. {
  2269. return do_proc_dointvec(table,write,buffer,lenp,ppos,
  2270. do_proc_dointvec_userhz_jiffies_conv,NULL);
  2271. }
  2272. /**
  2273. * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
  2274. * @table: the sysctl table
  2275. * @write: %TRUE if this is a write to the sysctl file
  2276. * @buffer: the user buffer
  2277. * @lenp: the size of the user buffer
  2278. * @ppos: file position
  2279. * @ppos: the current position in the file
  2280. *
  2281. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2282. * values from/to the user buffer, treated as an ASCII string.
  2283. * The values read are assumed to be in 1/1000 seconds, and
  2284. * are converted into jiffies.
  2285. *
  2286. * Returns 0 on success.
  2287. */
  2288. int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
  2289. void __user *buffer, size_t *lenp, loff_t *ppos)
  2290. {
  2291. return do_proc_dointvec(table, write, buffer, lenp, ppos,
  2292. do_proc_dointvec_ms_jiffies_conv, NULL);
  2293. }
  2294. static int proc_do_cad_pid(struct ctl_table *table, int write,
  2295. void __user *buffer, size_t *lenp, loff_t *ppos)
  2296. {
  2297. struct pid *new_pid;
  2298. pid_t tmp;
  2299. int r;
  2300. tmp = pid_vnr(cad_pid);
  2301. r = __do_proc_dointvec(&tmp, table, write, buffer,
  2302. lenp, ppos, NULL, NULL);
  2303. if (r || !write)
  2304. return r;
  2305. new_pid = find_get_pid(tmp);
  2306. if (!new_pid)
  2307. return -ESRCH;
  2308. put_pid(xchg(&cad_pid, new_pid));
  2309. return 0;
  2310. }
  2311. /**
  2312. * proc_do_large_bitmap - read/write from/to a large bitmap
  2313. * @table: the sysctl table
  2314. * @write: %TRUE if this is a write to the sysctl file
  2315. * @buffer: the user buffer
  2316. * @lenp: the size of the user buffer
  2317. * @ppos: file position
  2318. *
  2319. * The bitmap is stored at table->data and the bitmap length (in bits)
  2320. * in table->maxlen.
  2321. *
  2322. * We use a range comma separated format (e.g. 1,3-4,10-10) so that
  2323. * large bitmaps may be represented in a compact manner. Writing into
  2324. * the file will clear the bitmap then update it with the given input.
  2325. *
  2326. * Returns 0 on success.
  2327. */
  2328. int proc_do_large_bitmap(struct ctl_table *table, int write,
  2329. void __user *buffer, size_t *lenp, loff_t *ppos)
  2330. {
  2331. int err = 0;
  2332. bool first = 1;
  2333. size_t left = *lenp;
  2334. unsigned long bitmap_len = table->maxlen;
  2335. unsigned long *bitmap = (unsigned long *) table->data;
  2336. unsigned long *tmp_bitmap = NULL;
  2337. char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
  2338. if (!bitmap_len || !left || (*ppos && !write)) {
  2339. *lenp = 0;
  2340. return 0;
  2341. }
  2342. if (write) {
  2343. unsigned long page = 0;
  2344. char *kbuf;
  2345. if (left > PAGE_SIZE - 1)
  2346. left = PAGE_SIZE - 1;
  2347. page = __get_free_page(GFP_TEMPORARY);
  2348. kbuf = (char *) page;
  2349. if (!kbuf)
  2350. return -ENOMEM;
  2351. if (copy_from_user(kbuf, buffer, left)) {
  2352. free_page(page);
  2353. return -EFAULT;
  2354. }
  2355. kbuf[left] = 0;
  2356. tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
  2357. GFP_KERNEL);
  2358. if (!tmp_bitmap) {
  2359. free_page(page);
  2360. return -ENOMEM;
  2361. }
  2362. proc_skip_char(&kbuf, &left, '\n');
  2363. while (!err && left) {
  2364. unsigned long val_a, val_b;
  2365. bool neg;
  2366. err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
  2367. sizeof(tr_a), &c);
  2368. if (err)
  2369. break;
  2370. if (val_a >= bitmap_len || neg) {
  2371. err = -EINVAL;
  2372. break;
  2373. }
  2374. val_b = val_a;
  2375. if (left) {
  2376. kbuf++;
  2377. left--;
  2378. }
  2379. if (c == '-') {
  2380. err = proc_get_long(&kbuf, &left, &val_b,
  2381. &neg, tr_b, sizeof(tr_b),
  2382. &c);
  2383. if (err)
  2384. break;
  2385. if (val_b >= bitmap_len || neg ||
  2386. val_a > val_b) {
  2387. err = -EINVAL;
  2388. break;
  2389. }
  2390. if (left) {
  2391. kbuf++;
  2392. left--;
  2393. }
  2394. }
  2395. bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
  2396. first = 0;
  2397. proc_skip_char(&kbuf, &left, '\n');
  2398. }
  2399. free_page(page);
  2400. } else {
  2401. unsigned long bit_a, bit_b = 0;
  2402. while (left) {
  2403. bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
  2404. if (bit_a >= bitmap_len)
  2405. break;
  2406. bit_b = find_next_zero_bit(bitmap, bitmap_len,
  2407. bit_a + 1) - 1;
  2408. if (!first) {
  2409. err = proc_put_char(&buffer, &left, ',');
  2410. if (err)
  2411. break;
  2412. }
  2413. err = proc_put_long(&buffer, &left, bit_a, false);
  2414. if (err)
  2415. break;
  2416. if (bit_a != bit_b) {
  2417. err = proc_put_char(&buffer, &left, '-');
  2418. if (err)
  2419. break;
  2420. err = proc_put_long(&buffer, &left, bit_b, false);
  2421. if (err)
  2422. break;
  2423. }
  2424. first = 0; bit_b++;
  2425. }
  2426. if (!err)
  2427. err = proc_put_char(&buffer, &left, '\n');
  2428. }
  2429. if (!err) {
  2430. if (write) {
  2431. if (*ppos)
  2432. bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
  2433. else
  2434. bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
  2435. }
  2436. kfree(tmp_bitmap);
  2437. *lenp -= left;
  2438. *ppos += *lenp;
  2439. return 0;
  2440. } else {
  2441. kfree(tmp_bitmap);
  2442. return err;
  2443. }
  2444. }
  2445. #else /* CONFIG_PROC_SYSCTL */
  2446. int proc_dostring(struct ctl_table *table, int write,
  2447. void __user *buffer, size_t *lenp, loff_t *ppos)
  2448. {
  2449. return -ENOSYS;
  2450. }
  2451. int proc_dointvec(struct ctl_table *table, int write,
  2452. void __user *buffer, size_t *lenp, loff_t *ppos)
  2453. {
  2454. return -ENOSYS;
  2455. }
  2456. int proc_dointvec_minmax(struct ctl_table *table, int write,
  2457. void __user *buffer, size_t *lenp, loff_t *ppos)
  2458. {
  2459. return -ENOSYS;
  2460. }
  2461. int proc_dointvec_jiffies(struct ctl_table *table, int write,
  2462. void __user *buffer, size_t *lenp, loff_t *ppos)
  2463. {
  2464. return -ENOSYS;
  2465. }
  2466. int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
  2467. void __user *buffer, size_t *lenp, loff_t *ppos)
  2468. {
  2469. return -ENOSYS;
  2470. }
  2471. int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
  2472. void __user *buffer, size_t *lenp, loff_t *ppos)
  2473. {
  2474. return -ENOSYS;
  2475. }
  2476. int proc_doulongvec_minmax(struct ctl_table *table, int write,
  2477. void __user *buffer, size_t *lenp, loff_t *ppos)
  2478. {
  2479. return -ENOSYS;
  2480. }
  2481. int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
  2482. void __user *buffer,
  2483. size_t *lenp, loff_t *ppos)
  2484. {
  2485. return -ENOSYS;
  2486. }
  2487. #endif /* CONFIG_PROC_SYSCTL */
  2488. /*
  2489. * No sense putting this after each symbol definition, twice,
  2490. * exception granted :-)
  2491. */
  2492. EXPORT_SYMBOL(proc_dointvec);
  2493. EXPORT_SYMBOL(proc_dointvec_jiffies);
  2494. EXPORT_SYMBOL(proc_dointvec_minmax);
  2495. EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
  2496. EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
  2497. EXPORT_SYMBOL(proc_dostring);
  2498. EXPORT_SYMBOL(proc_doulongvec_minmax);
  2499. EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);