sysctl.c 59 KB

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