sysctl.c 59 KB

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