sysctl.c 62 KB

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