sysctl.c 60 KB

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