sysctl.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670
  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/proc_fs.h>
  26. #include <linux/security.h>
  27. #include <linux/ctype.h>
  28. #include <linux/utsname.h>
  29. #include <linux/smp_lock.h>
  30. #include <linux/fs.h>
  31. #include <linux/init.h>
  32. #include <linux/kernel.h>
  33. #include <linux/kobject.h>
  34. #include <linux/net.h>
  35. #include <linux/sysrq.h>
  36. #include <linux/highuid.h>
  37. #include <linux/writeback.h>
  38. #include <linux/hugetlb.h>
  39. #include <linux/security.h>
  40. #include <linux/initrd.h>
  41. #include <linux/times.h>
  42. #include <linux/limits.h>
  43. #include <linux/dcache.h>
  44. #include <linux/syscalls.h>
  45. #include <linux/nfs_fs.h>
  46. #include <linux/acpi.h>
  47. #include <linux/reboot.h>
  48. #include <asm/uaccess.h>
  49. #include <asm/processor.h>
  50. #ifdef CONFIG_X86
  51. #include <asm/nmi.h>
  52. #include <asm/stacktrace.h>
  53. #endif
  54. static int deprecated_sysctl_warning(struct __sysctl_args *args);
  55. #if defined(CONFIG_SYSCTL)
  56. /* External variables not in a header file. */
  57. extern int C_A_D;
  58. extern int print_fatal_signals;
  59. extern int sysctl_overcommit_memory;
  60. extern int sysctl_overcommit_ratio;
  61. extern int sysctl_panic_on_oom;
  62. extern int sysctl_oom_kill_allocating_task;
  63. extern int max_threads;
  64. extern int core_uses_pid;
  65. extern int suid_dumpable;
  66. extern char core_pattern[];
  67. extern int pid_max;
  68. extern int min_free_kbytes;
  69. extern int printk_ratelimit_jiffies;
  70. extern int printk_ratelimit_burst;
  71. extern int pid_max_min, pid_max_max;
  72. extern int sysctl_drop_caches;
  73. extern int percpu_pagelist_fraction;
  74. extern int compat_log;
  75. extern int maps_protect;
  76. extern int sysctl_stat_interval;
  77. extern int audit_argv_kb;
  78. /* Constants used for minimum and maximum */
  79. #ifdef CONFIG_DETECT_SOFTLOCKUP
  80. static int one = 1;
  81. static int sixty = 60;
  82. #endif
  83. #ifdef CONFIG_MMU
  84. static int two = 2;
  85. #endif
  86. static int zero;
  87. static int one_hundred = 100;
  88. /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
  89. static int maxolduid = 65535;
  90. static int minolduid;
  91. static int min_percpu_pagelist_fract = 8;
  92. static int ngroups_max = NGROUPS_MAX;
  93. #ifdef CONFIG_KMOD
  94. extern char modprobe_path[];
  95. #endif
  96. #ifdef CONFIG_CHR_DEV_SG
  97. extern int sg_big_buff;
  98. #endif
  99. #ifdef __sparc__
  100. extern char reboot_command [];
  101. extern int stop_a_enabled;
  102. extern int scons_pwroff;
  103. #endif
  104. #ifdef __hppa__
  105. extern int pwrsw_enabled;
  106. extern int unaligned_enabled;
  107. #endif
  108. #ifdef CONFIG_S390
  109. #ifdef CONFIG_MATHEMU
  110. extern int sysctl_ieee_emulation_warnings;
  111. #endif
  112. extern int sysctl_userprocess_debug;
  113. extern int spin_retry;
  114. #endif
  115. extern int sysctl_hz_timer;
  116. #ifdef CONFIG_BSD_PROCESS_ACCT
  117. extern int acct_parm[];
  118. #endif
  119. #ifdef CONFIG_IA64
  120. extern int no_unaligned_warning;
  121. #endif
  122. #ifdef CONFIG_RT_MUTEXES
  123. extern int max_lock_depth;
  124. #endif
  125. #ifdef CONFIG_SYSCTL_SYSCALL
  126. static int parse_table(int __user *, int, void __user *, size_t __user *,
  127. void __user *, size_t, struct ctl_table *);
  128. #endif
  129. #ifdef CONFIG_PROC_SYSCTL
  130. static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
  131. void __user *buffer, size_t *lenp, loff_t *ppos);
  132. static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
  133. void __user *buffer, size_t *lenp, loff_t *ppos);
  134. #endif
  135. static struct ctl_table root_table[];
  136. static struct ctl_table_header root_table_header =
  137. { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
  138. static struct ctl_table kern_table[];
  139. static struct ctl_table vm_table[];
  140. static struct ctl_table fs_table[];
  141. static struct ctl_table debug_table[];
  142. static struct ctl_table dev_table[];
  143. extern struct ctl_table random_table[];
  144. #ifdef CONFIG_INOTIFY_USER
  145. extern struct ctl_table inotify_table[];
  146. #endif
  147. #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
  148. int sysctl_legacy_va_layout;
  149. #endif
  150. extern int prove_locking;
  151. extern int lock_stat;
  152. /* The default sysctl tables: */
  153. static struct ctl_table root_table[] = {
  154. {
  155. .ctl_name = CTL_KERN,
  156. .procname = "kernel",
  157. .mode = 0555,
  158. .child = kern_table,
  159. },
  160. {
  161. .ctl_name = CTL_VM,
  162. .procname = "vm",
  163. .mode = 0555,
  164. .child = vm_table,
  165. },
  166. #ifdef CONFIG_NET
  167. {
  168. .ctl_name = CTL_NET,
  169. .procname = "net",
  170. .mode = 0555,
  171. .child = net_table,
  172. },
  173. #endif
  174. {
  175. .ctl_name = CTL_FS,
  176. .procname = "fs",
  177. .mode = 0555,
  178. .child = fs_table,
  179. },
  180. {
  181. .ctl_name = CTL_DEBUG,
  182. .procname = "debug",
  183. .mode = 0555,
  184. .child = debug_table,
  185. },
  186. {
  187. .ctl_name = CTL_DEV,
  188. .procname = "dev",
  189. .mode = 0555,
  190. .child = dev_table,
  191. },
  192. /*
  193. * NOTE: do not add new entries to this table unless you have read
  194. * Documentation/sysctl/ctl_unnumbered.txt
  195. */
  196. { .ctl_name = 0 }
  197. };
  198. #ifdef CONFIG_SCHED_DEBUG
  199. static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
  200. static unsigned long max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
  201. static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
  202. static unsigned long max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
  203. #endif
  204. static struct ctl_table kern_table[] = {
  205. #ifdef CONFIG_SCHED_DEBUG
  206. {
  207. .ctl_name = CTL_UNNUMBERED,
  208. .procname = "sched_min_granularity_ns",
  209. .data = &sysctl_sched_min_granularity,
  210. .maxlen = sizeof(unsigned int),
  211. .mode = 0644,
  212. .proc_handler = &sched_nr_latency_handler,
  213. .strategy = &sysctl_intvec,
  214. .extra1 = &min_sched_granularity_ns,
  215. .extra2 = &max_sched_granularity_ns,
  216. },
  217. {
  218. .ctl_name = CTL_UNNUMBERED,
  219. .procname = "sched_latency_ns",
  220. .data = &sysctl_sched_latency,
  221. .maxlen = sizeof(unsigned int),
  222. .mode = 0644,
  223. .proc_handler = &sched_nr_latency_handler,
  224. .strategy = &sysctl_intvec,
  225. .extra1 = &min_sched_granularity_ns,
  226. .extra2 = &max_sched_granularity_ns,
  227. },
  228. {
  229. .ctl_name = CTL_UNNUMBERED,
  230. .procname = "sched_wakeup_granularity_ns",
  231. .data = &sysctl_sched_wakeup_granularity,
  232. .maxlen = sizeof(unsigned int),
  233. .mode = 0644,
  234. .proc_handler = &proc_dointvec_minmax,
  235. .strategy = &sysctl_intvec,
  236. .extra1 = &min_wakeup_granularity_ns,
  237. .extra2 = &max_wakeup_granularity_ns,
  238. },
  239. {
  240. .ctl_name = CTL_UNNUMBERED,
  241. .procname = "sched_batch_wakeup_granularity_ns",
  242. .data = &sysctl_sched_batch_wakeup_granularity,
  243. .maxlen = sizeof(unsigned int),
  244. .mode = 0644,
  245. .proc_handler = &proc_dointvec_minmax,
  246. .strategy = &sysctl_intvec,
  247. .extra1 = &min_wakeup_granularity_ns,
  248. .extra2 = &max_wakeup_granularity_ns,
  249. },
  250. {
  251. .ctl_name = CTL_UNNUMBERED,
  252. .procname = "sched_child_runs_first",
  253. .data = &sysctl_sched_child_runs_first,
  254. .maxlen = sizeof(unsigned int),
  255. .mode = 0644,
  256. .proc_handler = &proc_dointvec,
  257. },
  258. {
  259. .ctl_name = CTL_UNNUMBERED,
  260. .procname = "sched_features",
  261. .data = &sysctl_sched_features,
  262. .maxlen = sizeof(unsigned int),
  263. .mode = 0644,
  264. .proc_handler = &proc_dointvec,
  265. },
  266. {
  267. .ctl_name = CTL_UNNUMBERED,
  268. .procname = "sched_migration_cost",
  269. .data = &sysctl_sched_migration_cost,
  270. .maxlen = sizeof(unsigned int),
  271. .mode = 0644,
  272. .proc_handler = &proc_dointvec,
  273. },
  274. {
  275. .ctl_name = CTL_UNNUMBERED,
  276. .procname = "sched_nr_migrate",
  277. .data = &sysctl_sched_nr_migrate,
  278. .maxlen = sizeof(unsigned int),
  279. .mode = 644,
  280. .proc_handler = &proc_dointvec,
  281. },
  282. #endif
  283. {
  284. .ctl_name = CTL_UNNUMBERED,
  285. .procname = "sched_compat_yield",
  286. .data = &sysctl_sched_compat_yield,
  287. .maxlen = sizeof(unsigned int),
  288. .mode = 0644,
  289. .proc_handler = &proc_dointvec,
  290. },
  291. #ifdef CONFIG_PROVE_LOCKING
  292. {
  293. .ctl_name = CTL_UNNUMBERED,
  294. .procname = "prove_locking",
  295. .data = &prove_locking,
  296. .maxlen = sizeof(int),
  297. .mode = 0644,
  298. .proc_handler = &proc_dointvec,
  299. },
  300. #endif
  301. #ifdef CONFIG_LOCK_STAT
  302. {
  303. .ctl_name = CTL_UNNUMBERED,
  304. .procname = "lock_stat",
  305. .data = &lock_stat,
  306. .maxlen = sizeof(int),
  307. .mode = 0644,
  308. .proc_handler = &proc_dointvec,
  309. },
  310. #endif
  311. {
  312. .ctl_name = KERN_PANIC,
  313. .procname = "panic",
  314. .data = &panic_timeout,
  315. .maxlen = sizeof(int),
  316. .mode = 0644,
  317. .proc_handler = &proc_dointvec,
  318. },
  319. {
  320. .ctl_name = KERN_CORE_USES_PID,
  321. .procname = "core_uses_pid",
  322. .data = &core_uses_pid,
  323. .maxlen = sizeof(int),
  324. .mode = 0644,
  325. .proc_handler = &proc_dointvec,
  326. },
  327. #ifdef CONFIG_AUDITSYSCALL
  328. {
  329. .ctl_name = CTL_UNNUMBERED,
  330. .procname = "audit_argv_kb",
  331. .data = &audit_argv_kb,
  332. .maxlen = sizeof(int),
  333. .mode = 0644,
  334. .proc_handler = &proc_dointvec,
  335. },
  336. #endif
  337. {
  338. .ctl_name = KERN_CORE_PATTERN,
  339. .procname = "core_pattern",
  340. .data = core_pattern,
  341. .maxlen = CORENAME_MAX_SIZE,
  342. .mode = 0644,
  343. .proc_handler = &proc_dostring,
  344. .strategy = &sysctl_string,
  345. },
  346. #ifdef CONFIG_PROC_SYSCTL
  347. {
  348. .procname = "tainted",
  349. .data = &tainted,
  350. .maxlen = sizeof(int),
  351. .mode = 0644,
  352. .proc_handler = &proc_dointvec_taint,
  353. },
  354. #endif
  355. #ifdef CONFIG_SECURITY_CAPABILITIES
  356. {
  357. .procname = "cap-bound",
  358. .data = &cap_bset,
  359. .maxlen = sizeof(kernel_cap_t),
  360. .mode = 0600,
  361. .proc_handler = &proc_dointvec_bset,
  362. },
  363. #endif /* def CONFIG_SECURITY_CAPABILITIES */
  364. #ifdef CONFIG_BLK_DEV_INITRD
  365. {
  366. .ctl_name = KERN_REALROOTDEV,
  367. .procname = "real-root-dev",
  368. .data = &real_root_dev,
  369. .maxlen = sizeof(int),
  370. .mode = 0644,
  371. .proc_handler = &proc_dointvec,
  372. },
  373. #endif
  374. {
  375. .ctl_name = CTL_UNNUMBERED,
  376. .procname = "print-fatal-signals",
  377. .data = &print_fatal_signals,
  378. .maxlen = sizeof(int),
  379. .mode = 0644,
  380. .proc_handler = &proc_dointvec,
  381. },
  382. #ifdef __sparc__
  383. {
  384. .ctl_name = KERN_SPARC_REBOOT,
  385. .procname = "reboot-cmd",
  386. .data = reboot_command,
  387. .maxlen = 256,
  388. .mode = 0644,
  389. .proc_handler = &proc_dostring,
  390. .strategy = &sysctl_string,
  391. },
  392. {
  393. .ctl_name = KERN_SPARC_STOP_A,
  394. .procname = "stop-a",
  395. .data = &stop_a_enabled,
  396. .maxlen = sizeof (int),
  397. .mode = 0644,
  398. .proc_handler = &proc_dointvec,
  399. },
  400. {
  401. .ctl_name = KERN_SPARC_SCONS_PWROFF,
  402. .procname = "scons-poweroff",
  403. .data = &scons_pwroff,
  404. .maxlen = sizeof (int),
  405. .mode = 0644,
  406. .proc_handler = &proc_dointvec,
  407. },
  408. #endif
  409. #ifdef __hppa__
  410. {
  411. .ctl_name = KERN_HPPA_PWRSW,
  412. .procname = "soft-power",
  413. .data = &pwrsw_enabled,
  414. .maxlen = sizeof (int),
  415. .mode = 0644,
  416. .proc_handler = &proc_dointvec,
  417. },
  418. {
  419. .ctl_name = KERN_HPPA_UNALIGNED,
  420. .procname = "unaligned-trap",
  421. .data = &unaligned_enabled,
  422. .maxlen = sizeof (int),
  423. .mode = 0644,
  424. .proc_handler = &proc_dointvec,
  425. },
  426. #endif
  427. {
  428. .ctl_name = KERN_CTLALTDEL,
  429. .procname = "ctrl-alt-del",
  430. .data = &C_A_D,
  431. .maxlen = sizeof(int),
  432. .mode = 0644,
  433. .proc_handler = &proc_dointvec,
  434. },
  435. {
  436. .ctl_name = KERN_PRINTK,
  437. .procname = "printk",
  438. .data = &console_loglevel,
  439. .maxlen = 4*sizeof(int),
  440. .mode = 0644,
  441. .proc_handler = &proc_dointvec,
  442. },
  443. #ifdef CONFIG_KMOD
  444. {
  445. .ctl_name = KERN_MODPROBE,
  446. .procname = "modprobe",
  447. .data = &modprobe_path,
  448. .maxlen = KMOD_PATH_LEN,
  449. .mode = 0644,
  450. .proc_handler = &proc_dostring,
  451. .strategy = &sysctl_string,
  452. },
  453. #endif
  454. #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
  455. {
  456. .ctl_name = KERN_HOTPLUG,
  457. .procname = "hotplug",
  458. .data = &uevent_helper,
  459. .maxlen = UEVENT_HELPER_PATH_LEN,
  460. .mode = 0644,
  461. .proc_handler = &proc_dostring,
  462. .strategy = &sysctl_string,
  463. },
  464. #endif
  465. #ifdef CONFIG_CHR_DEV_SG
  466. {
  467. .ctl_name = KERN_SG_BIG_BUFF,
  468. .procname = "sg-big-buff",
  469. .data = &sg_big_buff,
  470. .maxlen = sizeof (int),
  471. .mode = 0444,
  472. .proc_handler = &proc_dointvec,
  473. },
  474. #endif
  475. #ifdef CONFIG_BSD_PROCESS_ACCT
  476. {
  477. .ctl_name = KERN_ACCT,
  478. .procname = "acct",
  479. .data = &acct_parm,
  480. .maxlen = 3*sizeof(int),
  481. .mode = 0644,
  482. .proc_handler = &proc_dointvec,
  483. },
  484. #endif
  485. #ifdef CONFIG_MAGIC_SYSRQ
  486. {
  487. .ctl_name = KERN_SYSRQ,
  488. .procname = "sysrq",
  489. .data = &__sysrq_enabled,
  490. .maxlen = sizeof (int),
  491. .mode = 0644,
  492. .proc_handler = &proc_dointvec,
  493. },
  494. #endif
  495. #ifdef CONFIG_PROC_SYSCTL
  496. {
  497. .procname = "cad_pid",
  498. .data = NULL,
  499. .maxlen = sizeof (int),
  500. .mode = 0600,
  501. .proc_handler = &proc_do_cad_pid,
  502. },
  503. #endif
  504. {
  505. .ctl_name = KERN_MAX_THREADS,
  506. .procname = "threads-max",
  507. .data = &max_threads,
  508. .maxlen = sizeof(int),
  509. .mode = 0644,
  510. .proc_handler = &proc_dointvec,
  511. },
  512. {
  513. .ctl_name = KERN_RANDOM,
  514. .procname = "random",
  515. .mode = 0555,
  516. .child = random_table,
  517. },
  518. {
  519. .ctl_name = KERN_OVERFLOWUID,
  520. .procname = "overflowuid",
  521. .data = &overflowuid,
  522. .maxlen = sizeof(int),
  523. .mode = 0644,
  524. .proc_handler = &proc_dointvec_minmax,
  525. .strategy = &sysctl_intvec,
  526. .extra1 = &minolduid,
  527. .extra2 = &maxolduid,
  528. },
  529. {
  530. .ctl_name = KERN_OVERFLOWGID,
  531. .procname = "overflowgid",
  532. .data = &overflowgid,
  533. .maxlen = sizeof(int),
  534. .mode = 0644,
  535. .proc_handler = &proc_dointvec_minmax,
  536. .strategy = &sysctl_intvec,
  537. .extra1 = &minolduid,
  538. .extra2 = &maxolduid,
  539. },
  540. #ifdef CONFIG_S390
  541. #ifdef CONFIG_MATHEMU
  542. {
  543. .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
  544. .procname = "ieee_emulation_warnings",
  545. .data = &sysctl_ieee_emulation_warnings,
  546. .maxlen = sizeof(int),
  547. .mode = 0644,
  548. .proc_handler = &proc_dointvec,
  549. },
  550. #endif
  551. #ifdef CONFIG_NO_IDLE_HZ
  552. {
  553. .ctl_name = KERN_HZ_TIMER,
  554. .procname = "hz_timer",
  555. .data = &sysctl_hz_timer,
  556. .maxlen = sizeof(int),
  557. .mode = 0644,
  558. .proc_handler = &proc_dointvec,
  559. },
  560. #endif
  561. {
  562. .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
  563. .procname = "userprocess_debug",
  564. .data = &sysctl_userprocess_debug,
  565. .maxlen = sizeof(int),
  566. .mode = 0644,
  567. .proc_handler = &proc_dointvec,
  568. },
  569. #endif
  570. {
  571. .ctl_name = KERN_PIDMAX,
  572. .procname = "pid_max",
  573. .data = &pid_max,
  574. .maxlen = sizeof (int),
  575. .mode = 0644,
  576. .proc_handler = &proc_dointvec_minmax,
  577. .strategy = sysctl_intvec,
  578. .extra1 = &pid_max_min,
  579. .extra2 = &pid_max_max,
  580. },
  581. {
  582. .ctl_name = KERN_PANIC_ON_OOPS,
  583. .procname = "panic_on_oops",
  584. .data = &panic_on_oops,
  585. .maxlen = sizeof(int),
  586. .mode = 0644,
  587. .proc_handler = &proc_dointvec,
  588. },
  589. {
  590. .ctl_name = KERN_PRINTK_RATELIMIT,
  591. .procname = "printk_ratelimit",
  592. .data = &printk_ratelimit_jiffies,
  593. .maxlen = sizeof(int),
  594. .mode = 0644,
  595. .proc_handler = &proc_dointvec_jiffies,
  596. .strategy = &sysctl_jiffies,
  597. },
  598. {
  599. .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
  600. .procname = "printk_ratelimit_burst",
  601. .data = &printk_ratelimit_burst,
  602. .maxlen = sizeof(int),
  603. .mode = 0644,
  604. .proc_handler = &proc_dointvec,
  605. },
  606. {
  607. .ctl_name = KERN_NGROUPS_MAX,
  608. .procname = "ngroups_max",
  609. .data = &ngroups_max,
  610. .maxlen = sizeof (int),
  611. .mode = 0444,
  612. .proc_handler = &proc_dointvec,
  613. },
  614. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
  615. {
  616. .ctl_name = KERN_UNKNOWN_NMI_PANIC,
  617. .procname = "unknown_nmi_panic",
  618. .data = &unknown_nmi_panic,
  619. .maxlen = sizeof (int),
  620. .mode = 0644,
  621. .proc_handler = &proc_dointvec,
  622. },
  623. {
  624. .procname = "nmi_watchdog",
  625. .data = &nmi_watchdog_enabled,
  626. .maxlen = sizeof (int),
  627. .mode = 0644,
  628. .proc_handler = &proc_nmi_enabled,
  629. },
  630. #endif
  631. #if defined(CONFIG_X86)
  632. {
  633. .ctl_name = KERN_PANIC_ON_NMI,
  634. .procname = "panic_on_unrecovered_nmi",
  635. .data = &panic_on_unrecovered_nmi,
  636. .maxlen = sizeof(int),
  637. .mode = 0644,
  638. .proc_handler = &proc_dointvec,
  639. },
  640. {
  641. .ctl_name = KERN_BOOTLOADER_TYPE,
  642. .procname = "bootloader_type",
  643. .data = &bootloader_type,
  644. .maxlen = sizeof (int),
  645. .mode = 0444,
  646. .proc_handler = &proc_dointvec,
  647. },
  648. {
  649. .ctl_name = CTL_UNNUMBERED,
  650. .procname = "kstack_depth_to_print",
  651. .data = &kstack_depth_to_print,
  652. .maxlen = sizeof(int),
  653. .mode = 0644,
  654. .proc_handler = &proc_dointvec,
  655. },
  656. #endif
  657. #if defined(CONFIG_MMU)
  658. {
  659. .ctl_name = KERN_RANDOMIZE,
  660. .procname = "randomize_va_space",
  661. .data = &randomize_va_space,
  662. .maxlen = sizeof(int),
  663. .mode = 0644,
  664. .proc_handler = &proc_dointvec,
  665. },
  666. #endif
  667. #if defined(CONFIG_S390) && defined(CONFIG_SMP)
  668. {
  669. .ctl_name = KERN_SPIN_RETRY,
  670. .procname = "spin_retry",
  671. .data = &spin_retry,
  672. .maxlen = sizeof (int),
  673. .mode = 0644,
  674. .proc_handler = &proc_dointvec,
  675. },
  676. #endif
  677. #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
  678. {
  679. .procname = "acpi_video_flags",
  680. .data = &acpi_realmode_flags,
  681. .maxlen = sizeof (unsigned long),
  682. .mode = 0644,
  683. .proc_handler = &proc_doulongvec_minmax,
  684. },
  685. #endif
  686. #ifdef CONFIG_IA64
  687. {
  688. .ctl_name = KERN_IA64_UNALIGNED,
  689. .procname = "ignore-unaligned-usertrap",
  690. .data = &no_unaligned_warning,
  691. .maxlen = sizeof (int),
  692. .mode = 0644,
  693. .proc_handler = &proc_dointvec,
  694. },
  695. #endif
  696. #ifdef CONFIG_DETECT_SOFTLOCKUP
  697. {
  698. .ctl_name = CTL_UNNUMBERED,
  699. .procname = "softlockup_thresh",
  700. .data = &softlockup_thresh,
  701. .maxlen = sizeof(int),
  702. .mode = 0644,
  703. .proc_handler = &proc_dointvec_minmax,
  704. .strategy = &sysctl_intvec,
  705. .extra1 = &one,
  706. .extra2 = &sixty,
  707. },
  708. #endif
  709. #ifdef CONFIG_COMPAT
  710. {
  711. .ctl_name = KERN_COMPAT_LOG,
  712. .procname = "compat-log",
  713. .data = &compat_log,
  714. .maxlen = sizeof (int),
  715. .mode = 0644,
  716. .proc_handler = &proc_dointvec,
  717. },
  718. #endif
  719. #ifdef CONFIG_RT_MUTEXES
  720. {
  721. .ctl_name = KERN_MAX_LOCK_DEPTH,
  722. .procname = "max_lock_depth",
  723. .data = &max_lock_depth,
  724. .maxlen = sizeof(int),
  725. .mode = 0644,
  726. .proc_handler = &proc_dointvec,
  727. },
  728. #endif
  729. #ifdef CONFIG_PROC_FS
  730. {
  731. .ctl_name = CTL_UNNUMBERED,
  732. .procname = "maps_protect",
  733. .data = &maps_protect,
  734. .maxlen = sizeof(int),
  735. .mode = 0644,
  736. .proc_handler = &proc_dointvec,
  737. },
  738. #endif
  739. {
  740. .ctl_name = CTL_UNNUMBERED,
  741. .procname = "poweroff_cmd",
  742. .data = &poweroff_cmd,
  743. .maxlen = POWEROFF_CMD_PATH_LEN,
  744. .mode = 0644,
  745. .proc_handler = &proc_dostring,
  746. .strategy = &sysctl_string,
  747. },
  748. /*
  749. * NOTE: do not add new entries to this table unless you have read
  750. * Documentation/sysctl/ctl_unnumbered.txt
  751. */
  752. { .ctl_name = 0 }
  753. };
  754. static struct ctl_table vm_table[] = {
  755. {
  756. .ctl_name = VM_OVERCOMMIT_MEMORY,
  757. .procname = "overcommit_memory",
  758. .data = &sysctl_overcommit_memory,
  759. .maxlen = sizeof(sysctl_overcommit_memory),
  760. .mode = 0644,
  761. .proc_handler = &proc_dointvec,
  762. },
  763. {
  764. .ctl_name = VM_PANIC_ON_OOM,
  765. .procname = "panic_on_oom",
  766. .data = &sysctl_panic_on_oom,
  767. .maxlen = sizeof(sysctl_panic_on_oom),
  768. .mode = 0644,
  769. .proc_handler = &proc_dointvec,
  770. },
  771. {
  772. .ctl_name = CTL_UNNUMBERED,
  773. .procname = "oom_kill_allocating_task",
  774. .data = &sysctl_oom_kill_allocating_task,
  775. .maxlen = sizeof(sysctl_oom_kill_allocating_task),
  776. .mode = 0644,
  777. .proc_handler = &proc_dointvec,
  778. },
  779. {
  780. .ctl_name = VM_OVERCOMMIT_RATIO,
  781. .procname = "overcommit_ratio",
  782. .data = &sysctl_overcommit_ratio,
  783. .maxlen = sizeof(sysctl_overcommit_ratio),
  784. .mode = 0644,
  785. .proc_handler = &proc_dointvec,
  786. },
  787. {
  788. .ctl_name = VM_PAGE_CLUSTER,
  789. .procname = "page-cluster",
  790. .data = &page_cluster,
  791. .maxlen = sizeof(int),
  792. .mode = 0644,
  793. .proc_handler = &proc_dointvec,
  794. },
  795. {
  796. .ctl_name = VM_DIRTY_BACKGROUND,
  797. .procname = "dirty_background_ratio",
  798. .data = &dirty_background_ratio,
  799. .maxlen = sizeof(dirty_background_ratio),
  800. .mode = 0644,
  801. .proc_handler = &proc_dointvec_minmax,
  802. .strategy = &sysctl_intvec,
  803. .extra1 = &zero,
  804. .extra2 = &one_hundred,
  805. },
  806. {
  807. .ctl_name = VM_DIRTY_RATIO,
  808. .procname = "dirty_ratio",
  809. .data = &vm_dirty_ratio,
  810. .maxlen = sizeof(vm_dirty_ratio),
  811. .mode = 0644,
  812. .proc_handler = &dirty_ratio_handler,
  813. .strategy = &sysctl_intvec,
  814. .extra1 = &zero,
  815. .extra2 = &one_hundred,
  816. },
  817. {
  818. .procname = "dirty_writeback_centisecs",
  819. .data = &dirty_writeback_interval,
  820. .maxlen = sizeof(dirty_writeback_interval),
  821. .mode = 0644,
  822. .proc_handler = &dirty_writeback_centisecs_handler,
  823. },
  824. {
  825. .procname = "dirty_expire_centisecs",
  826. .data = &dirty_expire_interval,
  827. .maxlen = sizeof(dirty_expire_interval),
  828. .mode = 0644,
  829. .proc_handler = &proc_dointvec_userhz_jiffies,
  830. },
  831. {
  832. .ctl_name = VM_NR_PDFLUSH_THREADS,
  833. .procname = "nr_pdflush_threads",
  834. .data = &nr_pdflush_threads,
  835. .maxlen = sizeof nr_pdflush_threads,
  836. .mode = 0444 /* read-only*/,
  837. .proc_handler = &proc_dointvec,
  838. },
  839. {
  840. .ctl_name = VM_SWAPPINESS,
  841. .procname = "swappiness",
  842. .data = &vm_swappiness,
  843. .maxlen = sizeof(vm_swappiness),
  844. .mode = 0644,
  845. .proc_handler = &proc_dointvec_minmax,
  846. .strategy = &sysctl_intvec,
  847. .extra1 = &zero,
  848. .extra2 = &one_hundred,
  849. },
  850. #ifdef CONFIG_HUGETLB_PAGE
  851. {
  852. .procname = "nr_hugepages",
  853. .data = &max_huge_pages,
  854. .maxlen = sizeof(unsigned long),
  855. .mode = 0644,
  856. .proc_handler = &hugetlb_sysctl_handler,
  857. .extra1 = (void *)&hugetlb_zero,
  858. .extra2 = (void *)&hugetlb_infinity,
  859. },
  860. {
  861. .ctl_name = VM_HUGETLB_GROUP,
  862. .procname = "hugetlb_shm_group",
  863. .data = &sysctl_hugetlb_shm_group,
  864. .maxlen = sizeof(gid_t),
  865. .mode = 0644,
  866. .proc_handler = &proc_dointvec,
  867. },
  868. {
  869. .ctl_name = CTL_UNNUMBERED,
  870. .procname = "hugepages_treat_as_movable",
  871. .data = &hugepages_treat_as_movable,
  872. .maxlen = sizeof(int),
  873. .mode = 0644,
  874. .proc_handler = &hugetlb_treat_movable_handler,
  875. },
  876. {
  877. .ctl_name = CTL_UNNUMBERED,
  878. .procname = "hugetlb_dynamic_pool",
  879. .data = &hugetlb_dynamic_pool,
  880. .maxlen = sizeof(hugetlb_dynamic_pool),
  881. .mode = 0644,
  882. .proc_handler = &proc_dointvec,
  883. },
  884. #endif
  885. {
  886. .ctl_name = VM_LOWMEM_RESERVE_RATIO,
  887. .procname = "lowmem_reserve_ratio",
  888. .data = &sysctl_lowmem_reserve_ratio,
  889. .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
  890. .mode = 0644,
  891. .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
  892. .strategy = &sysctl_intvec,
  893. },
  894. {
  895. .ctl_name = VM_DROP_PAGECACHE,
  896. .procname = "drop_caches",
  897. .data = &sysctl_drop_caches,
  898. .maxlen = sizeof(int),
  899. .mode = 0644,
  900. .proc_handler = drop_caches_sysctl_handler,
  901. .strategy = &sysctl_intvec,
  902. },
  903. {
  904. .ctl_name = VM_MIN_FREE_KBYTES,
  905. .procname = "min_free_kbytes",
  906. .data = &min_free_kbytes,
  907. .maxlen = sizeof(min_free_kbytes),
  908. .mode = 0644,
  909. .proc_handler = &min_free_kbytes_sysctl_handler,
  910. .strategy = &sysctl_intvec,
  911. .extra1 = &zero,
  912. },
  913. {
  914. .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
  915. .procname = "percpu_pagelist_fraction",
  916. .data = &percpu_pagelist_fraction,
  917. .maxlen = sizeof(percpu_pagelist_fraction),
  918. .mode = 0644,
  919. .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
  920. .strategy = &sysctl_intvec,
  921. .extra1 = &min_percpu_pagelist_fract,
  922. },
  923. #ifdef CONFIG_MMU
  924. {
  925. .ctl_name = VM_MAX_MAP_COUNT,
  926. .procname = "max_map_count",
  927. .data = &sysctl_max_map_count,
  928. .maxlen = sizeof(sysctl_max_map_count),
  929. .mode = 0644,
  930. .proc_handler = &proc_dointvec
  931. },
  932. #endif
  933. {
  934. .ctl_name = VM_LAPTOP_MODE,
  935. .procname = "laptop_mode",
  936. .data = &laptop_mode,
  937. .maxlen = sizeof(laptop_mode),
  938. .mode = 0644,
  939. .proc_handler = &proc_dointvec_jiffies,
  940. .strategy = &sysctl_jiffies,
  941. },
  942. {
  943. .ctl_name = VM_BLOCK_DUMP,
  944. .procname = "block_dump",
  945. .data = &block_dump,
  946. .maxlen = sizeof(block_dump),
  947. .mode = 0644,
  948. .proc_handler = &proc_dointvec,
  949. .strategy = &sysctl_intvec,
  950. .extra1 = &zero,
  951. },
  952. {
  953. .ctl_name = VM_VFS_CACHE_PRESSURE,
  954. .procname = "vfs_cache_pressure",
  955. .data = &sysctl_vfs_cache_pressure,
  956. .maxlen = sizeof(sysctl_vfs_cache_pressure),
  957. .mode = 0644,
  958. .proc_handler = &proc_dointvec,
  959. .strategy = &sysctl_intvec,
  960. .extra1 = &zero,
  961. },
  962. #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
  963. {
  964. .ctl_name = VM_LEGACY_VA_LAYOUT,
  965. .procname = "legacy_va_layout",
  966. .data = &sysctl_legacy_va_layout,
  967. .maxlen = sizeof(sysctl_legacy_va_layout),
  968. .mode = 0644,
  969. .proc_handler = &proc_dointvec,
  970. .strategy = &sysctl_intvec,
  971. .extra1 = &zero,
  972. },
  973. #endif
  974. #ifdef CONFIG_NUMA
  975. {
  976. .ctl_name = VM_ZONE_RECLAIM_MODE,
  977. .procname = "zone_reclaim_mode",
  978. .data = &zone_reclaim_mode,
  979. .maxlen = sizeof(zone_reclaim_mode),
  980. .mode = 0644,
  981. .proc_handler = &proc_dointvec,
  982. .strategy = &sysctl_intvec,
  983. .extra1 = &zero,
  984. },
  985. {
  986. .ctl_name = VM_MIN_UNMAPPED,
  987. .procname = "min_unmapped_ratio",
  988. .data = &sysctl_min_unmapped_ratio,
  989. .maxlen = sizeof(sysctl_min_unmapped_ratio),
  990. .mode = 0644,
  991. .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
  992. .strategy = &sysctl_intvec,
  993. .extra1 = &zero,
  994. .extra2 = &one_hundred,
  995. },
  996. {
  997. .ctl_name = VM_MIN_SLAB,
  998. .procname = "min_slab_ratio",
  999. .data = &sysctl_min_slab_ratio,
  1000. .maxlen = sizeof(sysctl_min_slab_ratio),
  1001. .mode = 0644,
  1002. .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
  1003. .strategy = &sysctl_intvec,
  1004. .extra1 = &zero,
  1005. .extra2 = &one_hundred,
  1006. },
  1007. #endif
  1008. #ifdef CONFIG_SMP
  1009. {
  1010. .ctl_name = CTL_UNNUMBERED,
  1011. .procname = "stat_interval",
  1012. .data = &sysctl_stat_interval,
  1013. .maxlen = sizeof(sysctl_stat_interval),
  1014. .mode = 0644,
  1015. .proc_handler = &proc_dointvec_jiffies,
  1016. .strategy = &sysctl_jiffies,
  1017. },
  1018. #endif
  1019. #ifdef CONFIG_SECURITY
  1020. {
  1021. .ctl_name = CTL_UNNUMBERED,
  1022. .procname = "mmap_min_addr",
  1023. .data = &mmap_min_addr,
  1024. .maxlen = sizeof(unsigned long),
  1025. .mode = 0644,
  1026. .proc_handler = &proc_doulongvec_minmax,
  1027. },
  1028. #endif
  1029. #ifdef CONFIG_NUMA
  1030. {
  1031. .ctl_name = CTL_UNNUMBERED,
  1032. .procname = "numa_zonelist_order",
  1033. .data = &numa_zonelist_order,
  1034. .maxlen = NUMA_ZONELIST_ORDER_LEN,
  1035. .mode = 0644,
  1036. .proc_handler = &numa_zonelist_order_handler,
  1037. .strategy = &sysctl_string,
  1038. },
  1039. #endif
  1040. #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
  1041. (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
  1042. {
  1043. .ctl_name = VM_VDSO_ENABLED,
  1044. .procname = "vdso_enabled",
  1045. .data = &vdso_enabled,
  1046. .maxlen = sizeof(vdso_enabled),
  1047. .mode = 0644,
  1048. .proc_handler = &proc_dointvec,
  1049. .strategy = &sysctl_intvec,
  1050. .extra1 = &zero,
  1051. },
  1052. #endif
  1053. /*
  1054. * NOTE: do not add new entries to this table unless you have read
  1055. * Documentation/sysctl/ctl_unnumbered.txt
  1056. */
  1057. { .ctl_name = 0 }
  1058. };
  1059. #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
  1060. static struct ctl_table binfmt_misc_table[] = {
  1061. { .ctl_name = 0 }
  1062. };
  1063. #endif
  1064. static struct ctl_table fs_table[] = {
  1065. {
  1066. .ctl_name = FS_NRINODE,
  1067. .procname = "inode-nr",
  1068. .data = &inodes_stat,
  1069. .maxlen = 2*sizeof(int),
  1070. .mode = 0444,
  1071. .proc_handler = &proc_dointvec,
  1072. },
  1073. {
  1074. .ctl_name = FS_STATINODE,
  1075. .procname = "inode-state",
  1076. .data = &inodes_stat,
  1077. .maxlen = 7*sizeof(int),
  1078. .mode = 0444,
  1079. .proc_handler = &proc_dointvec,
  1080. },
  1081. {
  1082. .procname = "file-nr",
  1083. .data = &files_stat,
  1084. .maxlen = 3*sizeof(int),
  1085. .mode = 0444,
  1086. .proc_handler = &proc_nr_files,
  1087. },
  1088. {
  1089. .ctl_name = FS_MAXFILE,
  1090. .procname = "file-max",
  1091. .data = &files_stat.max_files,
  1092. .maxlen = sizeof(int),
  1093. .mode = 0644,
  1094. .proc_handler = &proc_dointvec,
  1095. },
  1096. {
  1097. .ctl_name = FS_DENTRY,
  1098. .procname = "dentry-state",
  1099. .data = &dentry_stat,
  1100. .maxlen = 6*sizeof(int),
  1101. .mode = 0444,
  1102. .proc_handler = &proc_dointvec,
  1103. },
  1104. {
  1105. .ctl_name = FS_OVERFLOWUID,
  1106. .procname = "overflowuid",
  1107. .data = &fs_overflowuid,
  1108. .maxlen = sizeof(int),
  1109. .mode = 0644,
  1110. .proc_handler = &proc_dointvec_minmax,
  1111. .strategy = &sysctl_intvec,
  1112. .extra1 = &minolduid,
  1113. .extra2 = &maxolduid,
  1114. },
  1115. {
  1116. .ctl_name = FS_OVERFLOWGID,
  1117. .procname = "overflowgid",
  1118. .data = &fs_overflowgid,
  1119. .maxlen = sizeof(int),
  1120. .mode = 0644,
  1121. .proc_handler = &proc_dointvec_minmax,
  1122. .strategy = &sysctl_intvec,
  1123. .extra1 = &minolduid,
  1124. .extra2 = &maxolduid,
  1125. },
  1126. {
  1127. .ctl_name = FS_LEASES,
  1128. .procname = "leases-enable",
  1129. .data = &leases_enable,
  1130. .maxlen = sizeof(int),
  1131. .mode = 0644,
  1132. .proc_handler = &proc_dointvec,
  1133. },
  1134. #ifdef CONFIG_DNOTIFY
  1135. {
  1136. .ctl_name = FS_DIR_NOTIFY,
  1137. .procname = "dir-notify-enable",
  1138. .data = &dir_notify_enable,
  1139. .maxlen = sizeof(int),
  1140. .mode = 0644,
  1141. .proc_handler = &proc_dointvec,
  1142. },
  1143. #endif
  1144. #ifdef CONFIG_MMU
  1145. {
  1146. .ctl_name = FS_LEASE_TIME,
  1147. .procname = "lease-break-time",
  1148. .data = &lease_break_time,
  1149. .maxlen = sizeof(int),
  1150. .mode = 0644,
  1151. .proc_handler = &proc_dointvec_minmax,
  1152. .strategy = &sysctl_intvec,
  1153. .extra1 = &zero,
  1154. .extra2 = &two,
  1155. },
  1156. {
  1157. .procname = "aio-nr",
  1158. .data = &aio_nr,
  1159. .maxlen = sizeof(aio_nr),
  1160. .mode = 0444,
  1161. .proc_handler = &proc_doulongvec_minmax,
  1162. },
  1163. {
  1164. .procname = "aio-max-nr",
  1165. .data = &aio_max_nr,
  1166. .maxlen = sizeof(aio_max_nr),
  1167. .mode = 0644,
  1168. .proc_handler = &proc_doulongvec_minmax,
  1169. },
  1170. #ifdef CONFIG_INOTIFY_USER
  1171. {
  1172. .ctl_name = FS_INOTIFY,
  1173. .procname = "inotify",
  1174. .mode = 0555,
  1175. .child = inotify_table,
  1176. },
  1177. #endif
  1178. #endif
  1179. {
  1180. .ctl_name = KERN_SETUID_DUMPABLE,
  1181. .procname = "suid_dumpable",
  1182. .data = &suid_dumpable,
  1183. .maxlen = sizeof(int),
  1184. .mode = 0644,
  1185. .proc_handler = &proc_dointvec,
  1186. },
  1187. #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
  1188. {
  1189. .ctl_name = CTL_UNNUMBERED,
  1190. .procname = "binfmt_misc",
  1191. .mode = 0555,
  1192. .child = binfmt_misc_table,
  1193. },
  1194. #endif
  1195. /*
  1196. * NOTE: do not add new entries to this table unless you have read
  1197. * Documentation/sysctl/ctl_unnumbered.txt
  1198. */
  1199. { .ctl_name = 0 }
  1200. };
  1201. static struct ctl_table debug_table[] = {
  1202. #if defined(CONFIG_X86) || defined(CONFIG_PPC)
  1203. {
  1204. .ctl_name = CTL_UNNUMBERED,
  1205. .procname = "exception-trace",
  1206. .data = &show_unhandled_signals,
  1207. .maxlen = sizeof(int),
  1208. .mode = 0644,
  1209. .proc_handler = proc_dointvec
  1210. },
  1211. #endif
  1212. { .ctl_name = 0 }
  1213. };
  1214. static struct ctl_table dev_table[] = {
  1215. { .ctl_name = 0 }
  1216. };
  1217. static DEFINE_SPINLOCK(sysctl_lock);
  1218. /* called under sysctl_lock */
  1219. static int use_table(struct ctl_table_header *p)
  1220. {
  1221. if (unlikely(p->unregistering))
  1222. return 0;
  1223. p->used++;
  1224. return 1;
  1225. }
  1226. /* called under sysctl_lock */
  1227. static void unuse_table(struct ctl_table_header *p)
  1228. {
  1229. if (!--p->used)
  1230. if (unlikely(p->unregistering))
  1231. complete(p->unregistering);
  1232. }
  1233. /* called under sysctl_lock, will reacquire if has to wait */
  1234. static void start_unregistering(struct ctl_table_header *p)
  1235. {
  1236. /*
  1237. * if p->used is 0, nobody will ever touch that entry again;
  1238. * we'll eliminate all paths to it before dropping sysctl_lock
  1239. */
  1240. if (unlikely(p->used)) {
  1241. struct completion wait;
  1242. init_completion(&wait);
  1243. p->unregistering = &wait;
  1244. spin_unlock(&sysctl_lock);
  1245. wait_for_completion(&wait);
  1246. spin_lock(&sysctl_lock);
  1247. }
  1248. /*
  1249. * do not remove from the list until nobody holds it; walking the
  1250. * list in do_sysctl() relies on that.
  1251. */
  1252. list_del_init(&p->ctl_entry);
  1253. }
  1254. void sysctl_head_finish(struct ctl_table_header *head)
  1255. {
  1256. if (!head)
  1257. return;
  1258. spin_lock(&sysctl_lock);
  1259. unuse_table(head);
  1260. spin_unlock(&sysctl_lock);
  1261. }
  1262. struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
  1263. {
  1264. struct ctl_table_header *head;
  1265. struct list_head *tmp;
  1266. spin_lock(&sysctl_lock);
  1267. if (prev) {
  1268. tmp = &prev->ctl_entry;
  1269. unuse_table(prev);
  1270. goto next;
  1271. }
  1272. tmp = &root_table_header.ctl_entry;
  1273. for (;;) {
  1274. head = list_entry(tmp, struct ctl_table_header, ctl_entry);
  1275. if (!use_table(head))
  1276. goto next;
  1277. spin_unlock(&sysctl_lock);
  1278. return head;
  1279. next:
  1280. tmp = tmp->next;
  1281. if (tmp == &root_table_header.ctl_entry)
  1282. break;
  1283. }
  1284. spin_unlock(&sysctl_lock);
  1285. return NULL;
  1286. }
  1287. #ifdef CONFIG_SYSCTL_SYSCALL
  1288. int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
  1289. void __user *newval, size_t newlen)
  1290. {
  1291. struct ctl_table_header *head;
  1292. int error = -ENOTDIR;
  1293. if (nlen <= 0 || nlen >= CTL_MAXNAME)
  1294. return -ENOTDIR;
  1295. if (oldval) {
  1296. int old_len;
  1297. if (!oldlenp || get_user(old_len, oldlenp))
  1298. return -EFAULT;
  1299. }
  1300. for (head = sysctl_head_next(NULL); head;
  1301. head = sysctl_head_next(head)) {
  1302. error = parse_table(name, nlen, oldval, oldlenp,
  1303. newval, newlen, head->ctl_table);
  1304. if (error != -ENOTDIR) {
  1305. sysctl_head_finish(head);
  1306. break;
  1307. }
  1308. }
  1309. return error;
  1310. }
  1311. asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
  1312. {
  1313. struct __sysctl_args tmp;
  1314. int error;
  1315. if (copy_from_user(&tmp, args, sizeof(tmp)))
  1316. return -EFAULT;
  1317. error = deprecated_sysctl_warning(&tmp);
  1318. if (error)
  1319. goto out;
  1320. lock_kernel();
  1321. error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
  1322. tmp.newval, tmp.newlen);
  1323. unlock_kernel();
  1324. out:
  1325. return error;
  1326. }
  1327. #endif /* CONFIG_SYSCTL_SYSCALL */
  1328. /*
  1329. * sysctl_perm does NOT grant the superuser all rights automatically, because
  1330. * some sysctl variables are readonly even to root.
  1331. */
  1332. static int test_perm(int mode, int op)
  1333. {
  1334. if (!current->euid)
  1335. mode >>= 6;
  1336. else if (in_egroup_p(0))
  1337. mode >>= 3;
  1338. if ((mode & op & 0007) == op)
  1339. return 0;
  1340. return -EACCES;
  1341. }
  1342. int sysctl_perm(struct ctl_table *table, int op)
  1343. {
  1344. int error;
  1345. error = security_sysctl(table, op);
  1346. if (error)
  1347. return error;
  1348. return test_perm(table->mode, op);
  1349. }
  1350. #ifdef CONFIG_SYSCTL_SYSCALL
  1351. static int parse_table(int __user *name, int nlen,
  1352. void __user *oldval, size_t __user *oldlenp,
  1353. void __user *newval, size_t newlen,
  1354. struct ctl_table *table)
  1355. {
  1356. int n;
  1357. repeat:
  1358. if (!nlen)
  1359. return -ENOTDIR;
  1360. if (get_user(n, name))
  1361. return -EFAULT;
  1362. for ( ; table->ctl_name || table->procname; table++) {
  1363. if (!table->ctl_name)
  1364. continue;
  1365. if (n == table->ctl_name) {
  1366. int error;
  1367. if (table->child) {
  1368. if (sysctl_perm(table, 001))
  1369. return -EPERM;
  1370. name++;
  1371. nlen--;
  1372. table = table->child;
  1373. goto repeat;
  1374. }
  1375. error = do_sysctl_strategy(table, name, nlen,
  1376. oldval, oldlenp,
  1377. newval, newlen);
  1378. return error;
  1379. }
  1380. }
  1381. return -ENOTDIR;
  1382. }
  1383. /* Perform the actual read/write of a sysctl table entry. */
  1384. int do_sysctl_strategy (struct ctl_table *table,
  1385. int __user *name, int nlen,
  1386. void __user *oldval, size_t __user *oldlenp,
  1387. void __user *newval, size_t newlen)
  1388. {
  1389. int op = 0, rc;
  1390. if (oldval)
  1391. op |= 004;
  1392. if (newval)
  1393. op |= 002;
  1394. if (sysctl_perm(table, op))
  1395. return -EPERM;
  1396. if (table->strategy) {
  1397. rc = table->strategy(table, name, nlen, oldval, oldlenp,
  1398. newval, newlen);
  1399. if (rc < 0)
  1400. return rc;
  1401. if (rc > 0)
  1402. return 0;
  1403. }
  1404. /* If there is no strategy routine, or if the strategy returns
  1405. * zero, proceed with automatic r/w */
  1406. if (table->data && table->maxlen) {
  1407. rc = sysctl_data(table, name, nlen, oldval, oldlenp,
  1408. newval, newlen);
  1409. if (rc < 0)
  1410. return rc;
  1411. }
  1412. return 0;
  1413. }
  1414. #endif /* CONFIG_SYSCTL_SYSCALL */
  1415. static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
  1416. {
  1417. for (; table->ctl_name || table->procname; table++) {
  1418. table->parent = parent;
  1419. if (table->child)
  1420. sysctl_set_parent(table, table->child);
  1421. }
  1422. }
  1423. static __init int sysctl_init(void)
  1424. {
  1425. int err;
  1426. sysctl_set_parent(NULL, root_table);
  1427. err = sysctl_check_table(root_table);
  1428. return 0;
  1429. }
  1430. core_initcall(sysctl_init);
  1431. /**
  1432. * register_sysctl_table - register a sysctl hierarchy
  1433. * @table: the top-level table structure
  1434. *
  1435. * Register a sysctl table hierarchy. @table should be a filled in ctl_table
  1436. * array. An entry with a ctl_name of 0 terminates the table.
  1437. *
  1438. * The members of the &struct ctl_table structure are used as follows:
  1439. *
  1440. * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
  1441. * must be unique within that level of sysctl
  1442. *
  1443. * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
  1444. * enter a sysctl file
  1445. *
  1446. * data - a pointer to data for use by proc_handler
  1447. *
  1448. * maxlen - the maximum size in bytes of the data
  1449. *
  1450. * mode - the file permissions for the /proc/sys file, and for sysctl(2)
  1451. *
  1452. * child - a pointer to the child sysctl table if this entry is a directory, or
  1453. * %NULL.
  1454. *
  1455. * proc_handler - the text handler routine (described below)
  1456. *
  1457. * strategy - the strategy routine (described below)
  1458. *
  1459. * de - for internal use by the sysctl routines
  1460. *
  1461. * extra1, extra2 - extra pointers usable by the proc handler routines
  1462. *
  1463. * Leaf nodes in the sysctl tree will be represented by a single file
  1464. * under /proc; non-leaf nodes will be represented by directories.
  1465. *
  1466. * sysctl(2) can automatically manage read and write requests through
  1467. * the sysctl table. The data and maxlen fields of the ctl_table
  1468. * struct enable minimal validation of the values being written to be
  1469. * performed, and the mode field allows minimal authentication.
  1470. *
  1471. * More sophisticated management can be enabled by the provision of a
  1472. * strategy routine with the table entry. This will be called before
  1473. * any automatic read or write of the data is performed.
  1474. *
  1475. * The strategy routine may return
  1476. *
  1477. * < 0 - Error occurred (error is passed to user process)
  1478. *
  1479. * 0 - OK - proceed with automatic read or write.
  1480. *
  1481. * > 0 - OK - read or write has been done by the strategy routine, so
  1482. * return immediately.
  1483. *
  1484. * There must be a proc_handler routine for any terminal nodes
  1485. * mirrored under /proc/sys (non-terminals are handled by a built-in
  1486. * directory handler). Several default handlers are available to
  1487. * cover common cases -
  1488. *
  1489. * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
  1490. * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
  1491. * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
  1492. *
  1493. * It is the handler's job to read the input buffer from user memory
  1494. * and process it. The handler should return 0 on success.
  1495. *
  1496. * This routine returns %NULL on a failure to register, and a pointer
  1497. * to the table header on success.
  1498. */
  1499. struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
  1500. {
  1501. struct ctl_table_header *tmp;
  1502. tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
  1503. if (!tmp)
  1504. return NULL;
  1505. tmp->ctl_table = table;
  1506. INIT_LIST_HEAD(&tmp->ctl_entry);
  1507. tmp->used = 0;
  1508. tmp->unregistering = NULL;
  1509. sysctl_set_parent(NULL, table);
  1510. if (sysctl_check_table(tmp->ctl_table)) {
  1511. kfree(tmp);
  1512. return NULL;
  1513. }
  1514. spin_lock(&sysctl_lock);
  1515. list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
  1516. spin_unlock(&sysctl_lock);
  1517. return tmp;
  1518. }
  1519. /**
  1520. * unregister_sysctl_table - unregister a sysctl table hierarchy
  1521. * @header: the header returned from register_sysctl_table
  1522. *
  1523. * Unregisters the sysctl table and all children. proc entries may not
  1524. * actually be removed until they are no longer used by anyone.
  1525. */
  1526. void unregister_sysctl_table(struct ctl_table_header * header)
  1527. {
  1528. might_sleep();
  1529. if (header == NULL)
  1530. return;
  1531. spin_lock(&sysctl_lock);
  1532. start_unregistering(header);
  1533. spin_unlock(&sysctl_lock);
  1534. kfree(header);
  1535. }
  1536. #else /* !CONFIG_SYSCTL */
  1537. struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
  1538. {
  1539. return NULL;
  1540. }
  1541. void unregister_sysctl_table(struct ctl_table_header * table)
  1542. {
  1543. }
  1544. #endif /* CONFIG_SYSCTL */
  1545. /*
  1546. * /proc/sys support
  1547. */
  1548. #ifdef CONFIG_PROC_SYSCTL
  1549. static int _proc_do_string(void* data, int maxlen, int write,
  1550. struct file *filp, void __user *buffer,
  1551. size_t *lenp, loff_t *ppos)
  1552. {
  1553. size_t len;
  1554. char __user *p;
  1555. char c;
  1556. if (!data || !maxlen || !*lenp) {
  1557. *lenp = 0;
  1558. return 0;
  1559. }
  1560. if (write) {
  1561. len = 0;
  1562. p = buffer;
  1563. while (len < *lenp) {
  1564. if (get_user(c, p++))
  1565. return -EFAULT;
  1566. if (c == 0 || c == '\n')
  1567. break;
  1568. len++;
  1569. }
  1570. if (len >= maxlen)
  1571. len = maxlen-1;
  1572. if(copy_from_user(data, buffer, len))
  1573. return -EFAULT;
  1574. ((char *) data)[len] = 0;
  1575. *ppos += *lenp;
  1576. } else {
  1577. len = strlen(data);
  1578. if (len > maxlen)
  1579. len = maxlen;
  1580. if (*ppos > len) {
  1581. *lenp = 0;
  1582. return 0;
  1583. }
  1584. data += *ppos;
  1585. len -= *ppos;
  1586. if (len > *lenp)
  1587. len = *lenp;
  1588. if (len)
  1589. if(copy_to_user(buffer, data, len))
  1590. return -EFAULT;
  1591. if (len < *lenp) {
  1592. if(put_user('\n', ((char __user *) buffer) + len))
  1593. return -EFAULT;
  1594. len++;
  1595. }
  1596. *lenp = len;
  1597. *ppos += len;
  1598. }
  1599. return 0;
  1600. }
  1601. /**
  1602. * proc_dostring - read a string sysctl
  1603. * @table: the sysctl table
  1604. * @write: %TRUE if this is a write to the sysctl file
  1605. * @filp: the file structure
  1606. * @buffer: the user buffer
  1607. * @lenp: the size of the user buffer
  1608. * @ppos: file position
  1609. *
  1610. * Reads/writes a string from/to the user buffer. If the kernel
  1611. * buffer provided is not large enough to hold the string, the
  1612. * string is truncated. The copied string is %NULL-terminated.
  1613. * If the string is being read by the user process, it is copied
  1614. * and a newline '\n' is added. It is truncated if the buffer is
  1615. * not large enough.
  1616. *
  1617. * Returns 0 on success.
  1618. */
  1619. int proc_dostring(struct ctl_table *table, int write, struct file *filp,
  1620. void __user *buffer, size_t *lenp, loff_t *ppos)
  1621. {
  1622. return _proc_do_string(table->data, table->maxlen, write, filp,
  1623. buffer, lenp, ppos);
  1624. }
  1625. static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
  1626. int *valp,
  1627. int write, void *data)
  1628. {
  1629. if (write) {
  1630. *valp = *negp ? -*lvalp : *lvalp;
  1631. } else {
  1632. int val = *valp;
  1633. if (val < 0) {
  1634. *negp = -1;
  1635. *lvalp = (unsigned long)-val;
  1636. } else {
  1637. *negp = 0;
  1638. *lvalp = (unsigned long)val;
  1639. }
  1640. }
  1641. return 0;
  1642. }
  1643. static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
  1644. int write, struct file *filp, void __user *buffer,
  1645. size_t *lenp, loff_t *ppos,
  1646. int (*conv)(int *negp, unsigned long *lvalp, int *valp,
  1647. int write, void *data),
  1648. void *data)
  1649. {
  1650. #define TMPBUFLEN 21
  1651. int *i, vleft, first=1, neg, val;
  1652. unsigned long lval;
  1653. size_t left, len;
  1654. char buf[TMPBUFLEN], *p;
  1655. char __user *s = buffer;
  1656. if (!tbl_data || !table->maxlen || !*lenp ||
  1657. (*ppos && !write)) {
  1658. *lenp = 0;
  1659. return 0;
  1660. }
  1661. i = (int *) tbl_data;
  1662. vleft = table->maxlen / sizeof(*i);
  1663. left = *lenp;
  1664. if (!conv)
  1665. conv = do_proc_dointvec_conv;
  1666. for (; left && vleft--; i++, first=0) {
  1667. if (write) {
  1668. while (left) {
  1669. char c;
  1670. if (get_user(c, s))
  1671. return -EFAULT;
  1672. if (!isspace(c))
  1673. break;
  1674. left--;
  1675. s++;
  1676. }
  1677. if (!left)
  1678. break;
  1679. neg = 0;
  1680. len = left;
  1681. if (len > sizeof(buf) - 1)
  1682. len = sizeof(buf) - 1;
  1683. if (copy_from_user(buf, s, len))
  1684. return -EFAULT;
  1685. buf[len] = 0;
  1686. p = buf;
  1687. if (*p == '-' && left > 1) {
  1688. neg = 1;
  1689. p++;
  1690. }
  1691. if (*p < '0' || *p > '9')
  1692. break;
  1693. lval = simple_strtoul(p, &p, 0);
  1694. len = p-buf;
  1695. if ((len < left) && *p && !isspace(*p))
  1696. break;
  1697. if (neg)
  1698. val = -val;
  1699. s += len;
  1700. left -= len;
  1701. if (conv(&neg, &lval, i, 1, data))
  1702. break;
  1703. } else {
  1704. p = buf;
  1705. if (!first)
  1706. *p++ = '\t';
  1707. if (conv(&neg, &lval, i, 0, data))
  1708. break;
  1709. sprintf(p, "%s%lu", neg ? "-" : "", lval);
  1710. len = strlen(buf);
  1711. if (len > left)
  1712. len = left;
  1713. if(copy_to_user(s, buf, len))
  1714. return -EFAULT;
  1715. left -= len;
  1716. s += len;
  1717. }
  1718. }
  1719. if (!write && !first && left) {
  1720. if(put_user('\n', s))
  1721. return -EFAULT;
  1722. left--, s++;
  1723. }
  1724. if (write) {
  1725. while (left) {
  1726. char c;
  1727. if (get_user(c, s++))
  1728. return -EFAULT;
  1729. if (!isspace(c))
  1730. break;
  1731. left--;
  1732. }
  1733. }
  1734. if (write && first)
  1735. return -EINVAL;
  1736. *lenp -= left;
  1737. *ppos += *lenp;
  1738. return 0;
  1739. #undef TMPBUFLEN
  1740. }
  1741. static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
  1742. void __user *buffer, size_t *lenp, loff_t *ppos,
  1743. int (*conv)(int *negp, unsigned long *lvalp, int *valp,
  1744. int write, void *data),
  1745. void *data)
  1746. {
  1747. return __do_proc_dointvec(table->data, table, write, filp,
  1748. buffer, lenp, ppos, conv, data);
  1749. }
  1750. /**
  1751. * proc_dointvec - read a vector of integers
  1752. * @table: the sysctl table
  1753. * @write: %TRUE if this is a write to the sysctl file
  1754. * @filp: the file structure
  1755. * @buffer: the user buffer
  1756. * @lenp: the size of the user buffer
  1757. * @ppos: file position
  1758. *
  1759. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1760. * values from/to the user buffer, treated as an ASCII string.
  1761. *
  1762. * Returns 0 on success.
  1763. */
  1764. int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
  1765. void __user *buffer, size_t *lenp, loff_t *ppos)
  1766. {
  1767. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1768. NULL,NULL);
  1769. }
  1770. #define OP_SET 0
  1771. #define OP_AND 1
  1772. #define OP_OR 2
  1773. static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
  1774. int *valp,
  1775. int write, void *data)
  1776. {
  1777. int op = *(int *)data;
  1778. if (write) {
  1779. int val = *negp ? -*lvalp : *lvalp;
  1780. switch(op) {
  1781. case OP_SET: *valp = val; break;
  1782. case OP_AND: *valp &= val; break;
  1783. case OP_OR: *valp |= val; break;
  1784. }
  1785. } else {
  1786. int val = *valp;
  1787. if (val < 0) {
  1788. *negp = -1;
  1789. *lvalp = (unsigned long)-val;
  1790. } else {
  1791. *negp = 0;
  1792. *lvalp = (unsigned long)val;
  1793. }
  1794. }
  1795. return 0;
  1796. }
  1797. #ifdef CONFIG_SECURITY_CAPABILITIES
  1798. /*
  1799. * init may raise the set.
  1800. */
  1801. int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
  1802. void __user *buffer, size_t *lenp, loff_t *ppos)
  1803. {
  1804. int op;
  1805. if (write && !capable(CAP_SYS_MODULE)) {
  1806. return -EPERM;
  1807. }
  1808. op = is_global_init(current) ? OP_SET : OP_AND;
  1809. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1810. do_proc_dointvec_bset_conv,&op);
  1811. }
  1812. #endif /* def CONFIG_SECURITY_CAPABILITIES */
  1813. /*
  1814. * Taint values can only be increased
  1815. */
  1816. static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
  1817. void __user *buffer, size_t *lenp, loff_t *ppos)
  1818. {
  1819. int op;
  1820. if (write && !capable(CAP_SYS_ADMIN))
  1821. return -EPERM;
  1822. op = OP_OR;
  1823. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1824. do_proc_dointvec_bset_conv,&op);
  1825. }
  1826. struct do_proc_dointvec_minmax_conv_param {
  1827. int *min;
  1828. int *max;
  1829. };
  1830. static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
  1831. int *valp,
  1832. int write, void *data)
  1833. {
  1834. struct do_proc_dointvec_minmax_conv_param *param = data;
  1835. if (write) {
  1836. int val = *negp ? -*lvalp : *lvalp;
  1837. if ((param->min && *param->min > val) ||
  1838. (param->max && *param->max < val))
  1839. return -EINVAL;
  1840. *valp = val;
  1841. } else {
  1842. int val = *valp;
  1843. if (val < 0) {
  1844. *negp = -1;
  1845. *lvalp = (unsigned long)-val;
  1846. } else {
  1847. *negp = 0;
  1848. *lvalp = (unsigned long)val;
  1849. }
  1850. }
  1851. return 0;
  1852. }
  1853. /**
  1854. * proc_dointvec_minmax - read a vector of integers with min/max values
  1855. * @table: the sysctl table
  1856. * @write: %TRUE if this is a write to the sysctl file
  1857. * @filp: the file structure
  1858. * @buffer: the user buffer
  1859. * @lenp: the size of the user buffer
  1860. * @ppos: file position
  1861. *
  1862. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1863. * values from/to the user buffer, treated as an ASCII string.
  1864. *
  1865. * This routine will ensure the values are within the range specified by
  1866. * table->extra1 (min) and table->extra2 (max).
  1867. *
  1868. * Returns 0 on success.
  1869. */
  1870. int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
  1871. void __user *buffer, size_t *lenp, loff_t *ppos)
  1872. {
  1873. struct do_proc_dointvec_minmax_conv_param param = {
  1874. .min = (int *) table->extra1,
  1875. .max = (int *) table->extra2,
  1876. };
  1877. return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
  1878. do_proc_dointvec_minmax_conv, &param);
  1879. }
  1880. static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
  1881. struct file *filp,
  1882. void __user *buffer,
  1883. size_t *lenp, loff_t *ppos,
  1884. unsigned long convmul,
  1885. unsigned long convdiv)
  1886. {
  1887. #define TMPBUFLEN 21
  1888. unsigned long *i, *min, *max, val;
  1889. int vleft, first=1, neg;
  1890. size_t len, left;
  1891. char buf[TMPBUFLEN], *p;
  1892. char __user *s = buffer;
  1893. if (!data || !table->maxlen || !*lenp ||
  1894. (*ppos && !write)) {
  1895. *lenp = 0;
  1896. return 0;
  1897. }
  1898. i = (unsigned long *) data;
  1899. min = (unsigned long *) table->extra1;
  1900. max = (unsigned long *) table->extra2;
  1901. vleft = table->maxlen / sizeof(unsigned long);
  1902. left = *lenp;
  1903. for (; left && vleft--; i++, min++, max++, first=0) {
  1904. if (write) {
  1905. while (left) {
  1906. char c;
  1907. if (get_user(c, s))
  1908. return -EFAULT;
  1909. if (!isspace(c))
  1910. break;
  1911. left--;
  1912. s++;
  1913. }
  1914. if (!left)
  1915. break;
  1916. neg = 0;
  1917. len = left;
  1918. if (len > TMPBUFLEN-1)
  1919. len = TMPBUFLEN-1;
  1920. if (copy_from_user(buf, s, len))
  1921. return -EFAULT;
  1922. buf[len] = 0;
  1923. p = buf;
  1924. if (*p == '-' && left > 1) {
  1925. neg = 1;
  1926. p++;
  1927. }
  1928. if (*p < '0' || *p > '9')
  1929. break;
  1930. val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
  1931. len = p-buf;
  1932. if ((len < left) && *p && !isspace(*p))
  1933. break;
  1934. if (neg)
  1935. val = -val;
  1936. s += len;
  1937. left -= len;
  1938. if(neg)
  1939. continue;
  1940. if ((min && val < *min) || (max && val > *max))
  1941. continue;
  1942. *i = val;
  1943. } else {
  1944. p = buf;
  1945. if (!first)
  1946. *p++ = '\t';
  1947. sprintf(p, "%lu", convdiv * (*i) / convmul);
  1948. len = strlen(buf);
  1949. if (len > left)
  1950. len = left;
  1951. if(copy_to_user(s, buf, len))
  1952. return -EFAULT;
  1953. left -= len;
  1954. s += len;
  1955. }
  1956. }
  1957. if (!write && !first && left) {
  1958. if(put_user('\n', s))
  1959. return -EFAULT;
  1960. left--, s++;
  1961. }
  1962. if (write) {
  1963. while (left) {
  1964. char c;
  1965. if (get_user(c, s++))
  1966. return -EFAULT;
  1967. if (!isspace(c))
  1968. break;
  1969. left--;
  1970. }
  1971. }
  1972. if (write && first)
  1973. return -EINVAL;
  1974. *lenp -= left;
  1975. *ppos += *lenp;
  1976. return 0;
  1977. #undef TMPBUFLEN
  1978. }
  1979. static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
  1980. struct file *filp,
  1981. void __user *buffer,
  1982. size_t *lenp, loff_t *ppos,
  1983. unsigned long convmul,
  1984. unsigned long convdiv)
  1985. {
  1986. return __do_proc_doulongvec_minmax(table->data, table, write,
  1987. filp, buffer, lenp, ppos, convmul, convdiv);
  1988. }
  1989. /**
  1990. * proc_doulongvec_minmax - read a vector of long integers with min/max values
  1991. * @table: the sysctl table
  1992. * @write: %TRUE if this is a write to the sysctl file
  1993. * @filp: the file structure
  1994. * @buffer: the user buffer
  1995. * @lenp: the size of the user buffer
  1996. * @ppos: file position
  1997. *
  1998. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  1999. * values from/to the user buffer, treated as an ASCII string.
  2000. *
  2001. * This routine will ensure the values are within the range specified by
  2002. * table->extra1 (min) and table->extra2 (max).
  2003. *
  2004. * Returns 0 on success.
  2005. */
  2006. int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
  2007. void __user *buffer, size_t *lenp, loff_t *ppos)
  2008. {
  2009. return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
  2010. }
  2011. /**
  2012. * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
  2013. * @table: the sysctl table
  2014. * @write: %TRUE if this is a write to the sysctl file
  2015. * @filp: the file structure
  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 long) unsigned long
  2021. * values from/to the user buffer, treated as an ASCII string. The values
  2022. * are treated as milliseconds, and converted to jiffies when they are stored.
  2023. *
  2024. * This routine will ensure the values are within the range specified by
  2025. * table->extra1 (min) and table->extra2 (max).
  2026. *
  2027. * Returns 0 on success.
  2028. */
  2029. int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
  2030. struct file *filp,
  2031. void __user *buffer,
  2032. size_t *lenp, loff_t *ppos)
  2033. {
  2034. return do_proc_doulongvec_minmax(table, write, filp, buffer,
  2035. lenp, ppos, HZ, 1000l);
  2036. }
  2037. static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
  2038. int *valp,
  2039. int write, void *data)
  2040. {
  2041. if (write) {
  2042. if (*lvalp > LONG_MAX / HZ)
  2043. return 1;
  2044. *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
  2045. } else {
  2046. int val = *valp;
  2047. unsigned long lval;
  2048. if (val < 0) {
  2049. *negp = -1;
  2050. lval = (unsigned long)-val;
  2051. } else {
  2052. *negp = 0;
  2053. lval = (unsigned long)val;
  2054. }
  2055. *lvalp = lval / HZ;
  2056. }
  2057. return 0;
  2058. }
  2059. static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
  2060. int *valp,
  2061. int write, void *data)
  2062. {
  2063. if (write) {
  2064. if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
  2065. return 1;
  2066. *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
  2067. } else {
  2068. int val = *valp;
  2069. unsigned long lval;
  2070. if (val < 0) {
  2071. *negp = -1;
  2072. lval = (unsigned long)-val;
  2073. } else {
  2074. *negp = 0;
  2075. lval = (unsigned long)val;
  2076. }
  2077. *lvalp = jiffies_to_clock_t(lval);
  2078. }
  2079. return 0;
  2080. }
  2081. static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
  2082. int *valp,
  2083. int write, void *data)
  2084. {
  2085. if (write) {
  2086. *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
  2087. } else {
  2088. int val = *valp;
  2089. unsigned long lval;
  2090. if (val < 0) {
  2091. *negp = -1;
  2092. lval = (unsigned long)-val;
  2093. } else {
  2094. *negp = 0;
  2095. lval = (unsigned long)val;
  2096. }
  2097. *lvalp = jiffies_to_msecs(lval);
  2098. }
  2099. return 0;
  2100. }
  2101. /**
  2102. * proc_dointvec_jiffies - read a vector of integers as seconds
  2103. * @table: the sysctl table
  2104. * @write: %TRUE if this is a write to the sysctl file
  2105. * @filp: the file structure
  2106. * @buffer: the user buffer
  2107. * @lenp: the size of the user buffer
  2108. * @ppos: file position
  2109. *
  2110. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2111. * values from/to the user buffer, treated as an ASCII string.
  2112. * The values read are assumed to be in seconds, and are converted into
  2113. * jiffies.
  2114. *
  2115. * Returns 0 on success.
  2116. */
  2117. int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
  2118. void __user *buffer, size_t *lenp, loff_t *ppos)
  2119. {
  2120. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  2121. do_proc_dointvec_jiffies_conv,NULL);
  2122. }
  2123. /**
  2124. * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
  2125. * @table: the sysctl table
  2126. * @write: %TRUE if this is a write to the sysctl file
  2127. * @filp: the file structure
  2128. * @buffer: the user buffer
  2129. * @lenp: the size of the user buffer
  2130. * @ppos: pointer to the file position
  2131. *
  2132. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2133. * values from/to the user buffer, treated as an ASCII string.
  2134. * The values read are assumed to be in 1/USER_HZ seconds, and
  2135. * are converted into jiffies.
  2136. *
  2137. * Returns 0 on success.
  2138. */
  2139. int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
  2140. void __user *buffer, size_t *lenp, loff_t *ppos)
  2141. {
  2142. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  2143. do_proc_dointvec_userhz_jiffies_conv,NULL);
  2144. }
  2145. /**
  2146. * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
  2147. * @table: the sysctl table
  2148. * @write: %TRUE if this is a write to the sysctl file
  2149. * @filp: the file structure
  2150. * @buffer: the user buffer
  2151. * @lenp: the size of the user buffer
  2152. * @ppos: file position
  2153. * @ppos: the current position in the file
  2154. *
  2155. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2156. * values from/to the user buffer, treated as an ASCII string.
  2157. * The values read are assumed to be in 1/1000 seconds, and
  2158. * are converted into jiffies.
  2159. *
  2160. * Returns 0 on success.
  2161. */
  2162. int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
  2163. void __user *buffer, size_t *lenp, loff_t *ppos)
  2164. {
  2165. return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
  2166. do_proc_dointvec_ms_jiffies_conv, NULL);
  2167. }
  2168. static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
  2169. void __user *buffer, size_t *lenp, loff_t *ppos)
  2170. {
  2171. struct pid *new_pid;
  2172. pid_t tmp;
  2173. int r;
  2174. tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
  2175. r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
  2176. lenp, ppos, NULL, NULL);
  2177. if (r || !write)
  2178. return r;
  2179. new_pid = find_get_pid(tmp);
  2180. if (!new_pid)
  2181. return -ESRCH;
  2182. put_pid(xchg(&cad_pid, new_pid));
  2183. return 0;
  2184. }
  2185. #else /* CONFIG_PROC_FS */
  2186. int proc_dostring(struct ctl_table *table, int write, struct file *filp,
  2187. void __user *buffer, size_t *lenp, loff_t *ppos)
  2188. {
  2189. return -ENOSYS;
  2190. }
  2191. int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
  2192. void __user *buffer, size_t *lenp, loff_t *ppos)
  2193. {
  2194. return -ENOSYS;
  2195. }
  2196. int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
  2197. void __user *buffer, size_t *lenp, loff_t *ppos)
  2198. {
  2199. return -ENOSYS;
  2200. }
  2201. int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
  2202. void __user *buffer, size_t *lenp, loff_t *ppos)
  2203. {
  2204. return -ENOSYS;
  2205. }
  2206. int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
  2207. void __user *buffer, size_t *lenp, loff_t *ppos)
  2208. {
  2209. return -ENOSYS;
  2210. }
  2211. int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
  2212. void __user *buffer, size_t *lenp, loff_t *ppos)
  2213. {
  2214. return -ENOSYS;
  2215. }
  2216. int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
  2217. void __user *buffer, size_t *lenp, loff_t *ppos)
  2218. {
  2219. return -ENOSYS;
  2220. }
  2221. int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
  2222. void __user *buffer, size_t *lenp, loff_t *ppos)
  2223. {
  2224. return -ENOSYS;
  2225. }
  2226. int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
  2227. struct file *filp,
  2228. void __user *buffer,
  2229. size_t *lenp, loff_t *ppos)
  2230. {
  2231. return -ENOSYS;
  2232. }
  2233. #endif /* CONFIG_PROC_FS */
  2234. #ifdef CONFIG_SYSCTL_SYSCALL
  2235. /*
  2236. * General sysctl support routines
  2237. */
  2238. /* The generic sysctl data routine (used if no strategy routine supplied) */
  2239. int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
  2240. void __user *oldval, size_t __user *oldlenp,
  2241. void __user *newval, size_t newlen)
  2242. {
  2243. size_t len;
  2244. /* Get out of I don't have a variable */
  2245. if (!table->data || !table->maxlen)
  2246. return -ENOTDIR;
  2247. if (oldval && oldlenp) {
  2248. if (get_user(len, oldlenp))
  2249. return -EFAULT;
  2250. if (len) {
  2251. if (len > table->maxlen)
  2252. len = table->maxlen;
  2253. if (copy_to_user(oldval, table->data, len))
  2254. return -EFAULT;
  2255. if (put_user(len, oldlenp))
  2256. return -EFAULT;
  2257. }
  2258. }
  2259. if (newval && newlen) {
  2260. if (newlen > table->maxlen)
  2261. newlen = table->maxlen;
  2262. if (copy_from_user(table->data, newval, newlen))
  2263. return -EFAULT;
  2264. }
  2265. return 1;
  2266. }
  2267. /* The generic string strategy routine: */
  2268. int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
  2269. void __user *oldval, size_t __user *oldlenp,
  2270. void __user *newval, size_t newlen)
  2271. {
  2272. if (!table->data || !table->maxlen)
  2273. return -ENOTDIR;
  2274. if (oldval && oldlenp) {
  2275. size_t bufsize;
  2276. if (get_user(bufsize, oldlenp))
  2277. return -EFAULT;
  2278. if (bufsize) {
  2279. size_t len = strlen(table->data), copied;
  2280. /* This shouldn't trigger for a well-formed sysctl */
  2281. if (len > table->maxlen)
  2282. len = table->maxlen;
  2283. /* Copy up to a max of bufsize-1 bytes of the string */
  2284. copied = (len >= bufsize) ? bufsize - 1 : len;
  2285. if (copy_to_user(oldval, table->data, copied) ||
  2286. put_user(0, (char __user *)(oldval + copied)))
  2287. return -EFAULT;
  2288. if (put_user(len, oldlenp))
  2289. return -EFAULT;
  2290. }
  2291. }
  2292. if (newval && newlen) {
  2293. size_t len = newlen;
  2294. if (len > table->maxlen)
  2295. len = table->maxlen;
  2296. if(copy_from_user(table->data, newval, len))
  2297. return -EFAULT;
  2298. if (len == table->maxlen)
  2299. len--;
  2300. ((char *) table->data)[len] = 0;
  2301. }
  2302. return 1;
  2303. }
  2304. /*
  2305. * This function makes sure that all of the integers in the vector
  2306. * are between the minimum and maximum values given in the arrays
  2307. * table->extra1 and table->extra2, respectively.
  2308. */
  2309. int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
  2310. void __user *oldval, size_t __user *oldlenp,
  2311. void __user *newval, size_t newlen)
  2312. {
  2313. if (newval && newlen) {
  2314. int __user *vec = (int __user *) newval;
  2315. int *min = (int *) table->extra1;
  2316. int *max = (int *) table->extra2;
  2317. size_t length;
  2318. int i;
  2319. if (newlen % sizeof(int) != 0)
  2320. return -EINVAL;
  2321. if (!table->extra1 && !table->extra2)
  2322. return 0;
  2323. if (newlen > table->maxlen)
  2324. newlen = table->maxlen;
  2325. length = newlen / sizeof(int);
  2326. for (i = 0; i < length; i++) {
  2327. int value;
  2328. if (get_user(value, vec + i))
  2329. return -EFAULT;
  2330. if (min && value < min[i])
  2331. return -EINVAL;
  2332. if (max && value > max[i])
  2333. return -EINVAL;
  2334. }
  2335. }
  2336. return 0;
  2337. }
  2338. /* Strategy function to convert jiffies to seconds */
  2339. int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
  2340. void __user *oldval, size_t __user *oldlenp,
  2341. void __user *newval, size_t newlen)
  2342. {
  2343. if (oldval && oldlenp) {
  2344. size_t olen;
  2345. if (get_user(olen, oldlenp))
  2346. return -EFAULT;
  2347. if (olen) {
  2348. int val;
  2349. if (olen < sizeof(int))
  2350. return -EINVAL;
  2351. val = *(int *)(table->data) / HZ;
  2352. if (put_user(val, (int __user *)oldval))
  2353. return -EFAULT;
  2354. if (put_user(sizeof(int), oldlenp))
  2355. return -EFAULT;
  2356. }
  2357. }
  2358. if (newval && newlen) {
  2359. int new;
  2360. if (newlen != sizeof(int))
  2361. return -EINVAL;
  2362. if (get_user(new, (int __user *)newval))
  2363. return -EFAULT;
  2364. *(int *)(table->data) = new*HZ;
  2365. }
  2366. return 1;
  2367. }
  2368. /* Strategy function to convert jiffies to seconds */
  2369. int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
  2370. void __user *oldval, size_t __user *oldlenp,
  2371. void __user *newval, size_t newlen)
  2372. {
  2373. if (oldval && oldlenp) {
  2374. size_t olen;
  2375. if (get_user(olen, oldlenp))
  2376. return -EFAULT;
  2377. if (olen) {
  2378. int val;
  2379. if (olen < sizeof(int))
  2380. return -EINVAL;
  2381. val = jiffies_to_msecs(*(int *)(table->data));
  2382. if (put_user(val, (int __user *)oldval))
  2383. return -EFAULT;
  2384. if (put_user(sizeof(int), oldlenp))
  2385. return -EFAULT;
  2386. }
  2387. }
  2388. if (newval && newlen) {
  2389. int new;
  2390. if (newlen != sizeof(int))
  2391. return -EINVAL;
  2392. if (get_user(new, (int __user *)newval))
  2393. return -EFAULT;
  2394. *(int *)(table->data) = msecs_to_jiffies(new);
  2395. }
  2396. return 1;
  2397. }
  2398. #else /* CONFIG_SYSCTL_SYSCALL */
  2399. asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
  2400. {
  2401. struct __sysctl_args tmp;
  2402. int error;
  2403. if (copy_from_user(&tmp, args, sizeof(tmp)))
  2404. return -EFAULT;
  2405. error = deprecated_sysctl_warning(&tmp);
  2406. /* If no error reading the parameters then just -ENOSYS ... */
  2407. if (!error)
  2408. error = -ENOSYS;
  2409. return error;
  2410. }
  2411. int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
  2412. void __user *oldval, size_t __user *oldlenp,
  2413. void __user *newval, size_t newlen)
  2414. {
  2415. return -ENOSYS;
  2416. }
  2417. int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
  2418. void __user *oldval, size_t __user *oldlenp,
  2419. void __user *newval, size_t newlen)
  2420. {
  2421. return -ENOSYS;
  2422. }
  2423. int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
  2424. void __user *oldval, size_t __user *oldlenp,
  2425. void __user *newval, size_t newlen)
  2426. {
  2427. return -ENOSYS;
  2428. }
  2429. int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
  2430. void __user *oldval, size_t __user *oldlenp,
  2431. void __user *newval, size_t newlen)
  2432. {
  2433. return -ENOSYS;
  2434. }
  2435. int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
  2436. void __user *oldval, size_t __user *oldlenp,
  2437. void __user *newval, size_t newlen)
  2438. {
  2439. return -ENOSYS;
  2440. }
  2441. #endif /* CONFIG_SYSCTL_SYSCALL */
  2442. static int deprecated_sysctl_warning(struct __sysctl_args *args)
  2443. {
  2444. static int msg_count;
  2445. int name[CTL_MAXNAME];
  2446. int i;
  2447. /* Check args->nlen. */
  2448. if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
  2449. return -ENOTDIR;
  2450. /* Read in the sysctl name for better debug message logging */
  2451. for (i = 0; i < args->nlen; i++)
  2452. if (get_user(name[i], args->name + i))
  2453. return -EFAULT;
  2454. /* Ignore accesses to kernel.version */
  2455. if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
  2456. return 0;
  2457. if (msg_count < 5) {
  2458. msg_count++;
  2459. printk(KERN_INFO
  2460. "warning: process `%s' used the deprecated sysctl "
  2461. "system call with ", current->comm);
  2462. for (i = 0; i < args->nlen; i++)
  2463. printk("%d.", name[i]);
  2464. printk("\n");
  2465. }
  2466. return 0;
  2467. }
  2468. /*
  2469. * No sense putting this after each symbol definition, twice,
  2470. * exception granted :-)
  2471. */
  2472. EXPORT_SYMBOL(proc_dointvec);
  2473. EXPORT_SYMBOL(proc_dointvec_jiffies);
  2474. EXPORT_SYMBOL(proc_dointvec_minmax);
  2475. EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
  2476. EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
  2477. EXPORT_SYMBOL(proc_dostring);
  2478. EXPORT_SYMBOL(proc_doulongvec_minmax);
  2479. EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
  2480. EXPORT_SYMBOL(register_sysctl_table);
  2481. EXPORT_SYMBOL(sysctl_intvec);
  2482. EXPORT_SYMBOL(sysctl_jiffies);
  2483. EXPORT_SYMBOL(sysctl_ms_jiffies);
  2484. EXPORT_SYMBOL(sysctl_string);
  2485. EXPORT_SYMBOL(sysctl_data);
  2486. EXPORT_SYMBOL(unregister_sysctl_table);