sysctl.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528
  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. { .ctl_name = 0 }
  900. };
  901. static ctl_table fs_table[] = {
  902. {
  903. .ctl_name = FS_NRINODE,
  904. .procname = "inode-nr",
  905. .data = &inodes_stat,
  906. .maxlen = 2*sizeof(int),
  907. .mode = 0444,
  908. .proc_handler = &proc_dointvec,
  909. },
  910. {
  911. .ctl_name = FS_STATINODE,
  912. .procname = "inode-state",
  913. .data = &inodes_stat,
  914. .maxlen = 7*sizeof(int),
  915. .mode = 0444,
  916. .proc_handler = &proc_dointvec,
  917. },
  918. {
  919. .ctl_name = FS_NRFILE,
  920. .procname = "file-nr",
  921. .data = &files_stat,
  922. .maxlen = 3*sizeof(int),
  923. .mode = 0444,
  924. .proc_handler = &proc_nr_files,
  925. },
  926. {
  927. .ctl_name = FS_MAXFILE,
  928. .procname = "file-max",
  929. .data = &files_stat.max_files,
  930. .maxlen = sizeof(int),
  931. .mode = 0644,
  932. .proc_handler = &proc_dointvec,
  933. },
  934. {
  935. .ctl_name = FS_DENTRY,
  936. .procname = "dentry-state",
  937. .data = &dentry_stat,
  938. .maxlen = 6*sizeof(int),
  939. .mode = 0444,
  940. .proc_handler = &proc_dointvec,
  941. },
  942. {
  943. .ctl_name = FS_OVERFLOWUID,
  944. .procname = "overflowuid",
  945. .data = &fs_overflowuid,
  946. .maxlen = sizeof(int),
  947. .mode = 0644,
  948. .proc_handler = &proc_dointvec_minmax,
  949. .strategy = &sysctl_intvec,
  950. .extra1 = &minolduid,
  951. .extra2 = &maxolduid,
  952. },
  953. {
  954. .ctl_name = FS_OVERFLOWGID,
  955. .procname = "overflowgid",
  956. .data = &fs_overflowgid,
  957. .maxlen = sizeof(int),
  958. .mode = 0644,
  959. .proc_handler = &proc_dointvec_minmax,
  960. .strategy = &sysctl_intvec,
  961. .extra1 = &minolduid,
  962. .extra2 = &maxolduid,
  963. },
  964. {
  965. .ctl_name = FS_LEASES,
  966. .procname = "leases-enable",
  967. .data = &leases_enable,
  968. .maxlen = sizeof(int),
  969. .mode = 0644,
  970. .proc_handler = &proc_dointvec,
  971. },
  972. #ifdef CONFIG_DNOTIFY
  973. {
  974. .ctl_name = FS_DIR_NOTIFY,
  975. .procname = "dir-notify-enable",
  976. .data = &dir_notify_enable,
  977. .maxlen = sizeof(int),
  978. .mode = 0644,
  979. .proc_handler = &proc_dointvec,
  980. },
  981. #endif
  982. #ifdef CONFIG_MMU
  983. {
  984. .ctl_name = FS_LEASE_TIME,
  985. .procname = "lease-break-time",
  986. .data = &lease_break_time,
  987. .maxlen = sizeof(int),
  988. .mode = 0644,
  989. .proc_handler = &proc_dointvec,
  990. },
  991. {
  992. .ctl_name = FS_AIO_NR,
  993. .procname = "aio-nr",
  994. .data = &aio_nr,
  995. .maxlen = sizeof(aio_nr),
  996. .mode = 0444,
  997. .proc_handler = &proc_doulongvec_minmax,
  998. },
  999. {
  1000. .ctl_name = FS_AIO_MAX_NR,
  1001. .procname = "aio-max-nr",
  1002. .data = &aio_max_nr,
  1003. .maxlen = sizeof(aio_max_nr),
  1004. .mode = 0644,
  1005. .proc_handler = &proc_doulongvec_minmax,
  1006. },
  1007. #ifdef CONFIG_INOTIFY_USER
  1008. {
  1009. .ctl_name = FS_INOTIFY,
  1010. .procname = "inotify",
  1011. .mode = 0555,
  1012. .child = inotify_table,
  1013. },
  1014. #endif
  1015. #endif
  1016. {
  1017. .ctl_name = KERN_SETUID_DUMPABLE,
  1018. .procname = "suid_dumpable",
  1019. .data = &suid_dumpable,
  1020. .maxlen = sizeof(int),
  1021. .mode = 0644,
  1022. .proc_handler = &proc_dointvec,
  1023. },
  1024. { .ctl_name = 0 }
  1025. };
  1026. static ctl_table debug_table[] = {
  1027. { .ctl_name = 0 }
  1028. };
  1029. static ctl_table dev_table[] = {
  1030. { .ctl_name = 0 }
  1031. };
  1032. extern void init_irq_proc (void);
  1033. static DEFINE_SPINLOCK(sysctl_lock);
  1034. /* called under sysctl_lock */
  1035. static int use_table(struct ctl_table_header *p)
  1036. {
  1037. if (unlikely(p->unregistering))
  1038. return 0;
  1039. p->used++;
  1040. return 1;
  1041. }
  1042. /* called under sysctl_lock */
  1043. static void unuse_table(struct ctl_table_header *p)
  1044. {
  1045. if (!--p->used)
  1046. if (unlikely(p->unregistering))
  1047. complete(p->unregistering);
  1048. }
  1049. /* called under sysctl_lock, will reacquire if has to wait */
  1050. static void start_unregistering(struct ctl_table_header *p)
  1051. {
  1052. /*
  1053. * if p->used is 0, nobody will ever touch that entry again;
  1054. * we'll eliminate all paths to it before dropping sysctl_lock
  1055. */
  1056. if (unlikely(p->used)) {
  1057. struct completion wait;
  1058. init_completion(&wait);
  1059. p->unregistering = &wait;
  1060. spin_unlock(&sysctl_lock);
  1061. wait_for_completion(&wait);
  1062. spin_lock(&sysctl_lock);
  1063. }
  1064. /*
  1065. * do not remove from the list until nobody holds it; walking the
  1066. * list in do_sysctl() relies on that.
  1067. */
  1068. list_del_init(&p->ctl_entry);
  1069. }
  1070. void __init sysctl_init(void)
  1071. {
  1072. #ifdef CONFIG_PROC_FS
  1073. register_proc_table(root_table, proc_sys_root, &root_table_header);
  1074. init_irq_proc();
  1075. #endif
  1076. }
  1077. int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
  1078. void __user *newval, size_t newlen)
  1079. {
  1080. struct list_head *tmp;
  1081. int error = -ENOTDIR;
  1082. if (nlen <= 0 || nlen >= CTL_MAXNAME)
  1083. return -ENOTDIR;
  1084. if (oldval) {
  1085. int old_len;
  1086. if (!oldlenp || get_user(old_len, oldlenp))
  1087. return -EFAULT;
  1088. }
  1089. spin_lock(&sysctl_lock);
  1090. tmp = &root_table_header.ctl_entry;
  1091. do {
  1092. struct ctl_table_header *head =
  1093. list_entry(tmp, struct ctl_table_header, ctl_entry);
  1094. void *context = NULL;
  1095. if (!use_table(head))
  1096. continue;
  1097. spin_unlock(&sysctl_lock);
  1098. error = parse_table(name, nlen, oldval, oldlenp,
  1099. newval, newlen, head->ctl_table,
  1100. &context);
  1101. kfree(context);
  1102. spin_lock(&sysctl_lock);
  1103. unuse_table(head);
  1104. if (error != -ENOTDIR)
  1105. break;
  1106. } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
  1107. spin_unlock(&sysctl_lock);
  1108. return error;
  1109. }
  1110. asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
  1111. {
  1112. struct __sysctl_args tmp;
  1113. int error;
  1114. if (copy_from_user(&tmp, args, sizeof(tmp)))
  1115. return -EFAULT;
  1116. lock_kernel();
  1117. error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
  1118. tmp.newval, tmp.newlen);
  1119. unlock_kernel();
  1120. return error;
  1121. }
  1122. /*
  1123. * ctl_perm does NOT grant the superuser all rights automatically, because
  1124. * some sysctl variables are readonly even to root.
  1125. */
  1126. static int test_perm(int mode, int op)
  1127. {
  1128. if (!current->euid)
  1129. mode >>= 6;
  1130. else if (in_egroup_p(0))
  1131. mode >>= 3;
  1132. if ((mode & op & 0007) == op)
  1133. return 0;
  1134. return -EACCES;
  1135. }
  1136. static inline int ctl_perm(ctl_table *table, int op)
  1137. {
  1138. int error;
  1139. error = security_sysctl(table, op);
  1140. if (error)
  1141. return error;
  1142. return test_perm(table->mode, op);
  1143. }
  1144. static int parse_table(int __user *name, int nlen,
  1145. void __user *oldval, size_t __user *oldlenp,
  1146. void __user *newval, size_t newlen,
  1147. ctl_table *table, void **context)
  1148. {
  1149. int n;
  1150. repeat:
  1151. if (!nlen)
  1152. return -ENOTDIR;
  1153. if (get_user(n, name))
  1154. return -EFAULT;
  1155. for ( ; table->ctl_name; table++) {
  1156. if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
  1157. int error;
  1158. if (table->child) {
  1159. if (ctl_perm(table, 001))
  1160. return -EPERM;
  1161. if (table->strategy) {
  1162. error = table->strategy(
  1163. table, name, nlen,
  1164. oldval, oldlenp,
  1165. newval, newlen, context);
  1166. if (error)
  1167. return error;
  1168. }
  1169. name++;
  1170. nlen--;
  1171. table = table->child;
  1172. goto repeat;
  1173. }
  1174. error = do_sysctl_strategy(table, name, nlen,
  1175. oldval, oldlenp,
  1176. newval, newlen, context);
  1177. return error;
  1178. }
  1179. }
  1180. return -ENOTDIR;
  1181. }
  1182. /* Perform the actual read/write of a sysctl table entry. */
  1183. int do_sysctl_strategy (ctl_table *table,
  1184. int __user *name, int nlen,
  1185. void __user *oldval, size_t __user *oldlenp,
  1186. void __user *newval, size_t newlen, void **context)
  1187. {
  1188. int op = 0, rc;
  1189. size_t len;
  1190. if (oldval)
  1191. op |= 004;
  1192. if (newval)
  1193. op |= 002;
  1194. if (ctl_perm(table, op))
  1195. return -EPERM;
  1196. if (table->strategy) {
  1197. rc = table->strategy(table, name, nlen, oldval, oldlenp,
  1198. newval, newlen, context);
  1199. if (rc < 0)
  1200. return rc;
  1201. if (rc > 0)
  1202. return 0;
  1203. }
  1204. /* If there is no strategy routine, or if the strategy returns
  1205. * zero, proceed with automatic r/w */
  1206. if (table->data && table->maxlen) {
  1207. if (oldval && oldlenp) {
  1208. if (get_user(len, oldlenp))
  1209. return -EFAULT;
  1210. if (len) {
  1211. if (len > table->maxlen)
  1212. len = table->maxlen;
  1213. if(copy_to_user(oldval, table->data, len))
  1214. return -EFAULT;
  1215. if(put_user(len, oldlenp))
  1216. return -EFAULT;
  1217. }
  1218. }
  1219. if (newval && newlen) {
  1220. len = newlen;
  1221. if (len > table->maxlen)
  1222. len = table->maxlen;
  1223. if(copy_from_user(table->data, newval, len))
  1224. return -EFAULT;
  1225. }
  1226. }
  1227. return 0;
  1228. }
  1229. /**
  1230. * register_sysctl_table - register a sysctl hierarchy
  1231. * @table: the top-level table structure
  1232. * @insert_at_head: whether the entry should be inserted in front or at the end
  1233. *
  1234. * Register a sysctl table hierarchy. @table should be a filled in ctl_table
  1235. * array. An entry with a ctl_name of 0 terminates the table.
  1236. *
  1237. * The members of the &ctl_table structure are used as follows:
  1238. *
  1239. * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
  1240. * must be unique within that level of sysctl
  1241. *
  1242. * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
  1243. * enter a sysctl file
  1244. *
  1245. * data - a pointer to data for use by proc_handler
  1246. *
  1247. * maxlen - the maximum size in bytes of the data
  1248. *
  1249. * mode - the file permissions for the /proc/sys file, and for sysctl(2)
  1250. *
  1251. * child - a pointer to the child sysctl table if this entry is a directory, or
  1252. * %NULL.
  1253. *
  1254. * proc_handler - the text handler routine (described below)
  1255. *
  1256. * strategy - the strategy routine (described below)
  1257. *
  1258. * de - for internal use by the sysctl routines
  1259. *
  1260. * extra1, extra2 - extra pointers usable by the proc handler routines
  1261. *
  1262. * Leaf nodes in the sysctl tree will be represented by a single file
  1263. * under /proc; non-leaf nodes will be represented by directories.
  1264. *
  1265. * sysctl(2) can automatically manage read and write requests through
  1266. * the sysctl table. The data and maxlen fields of the ctl_table
  1267. * struct enable minimal validation of the values being written to be
  1268. * performed, and the mode field allows minimal authentication.
  1269. *
  1270. * More sophisticated management can be enabled by the provision of a
  1271. * strategy routine with the table entry. This will be called before
  1272. * any automatic read or write of the data is performed.
  1273. *
  1274. * The strategy routine may return
  1275. *
  1276. * < 0 - Error occurred (error is passed to user process)
  1277. *
  1278. * 0 - OK - proceed with automatic read or write.
  1279. *
  1280. * > 0 - OK - read or write has been done by the strategy routine, so
  1281. * return immediately.
  1282. *
  1283. * There must be a proc_handler routine for any terminal nodes
  1284. * mirrored under /proc/sys (non-terminals are handled by a built-in
  1285. * directory handler). Several default handlers are available to
  1286. * cover common cases -
  1287. *
  1288. * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
  1289. * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
  1290. * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
  1291. *
  1292. * It is the handler's job to read the input buffer from user memory
  1293. * and process it. The handler should return 0 on success.
  1294. *
  1295. * This routine returns %NULL on a failure to register, and a pointer
  1296. * to the table header on success.
  1297. */
  1298. struct ctl_table_header *register_sysctl_table(ctl_table * table,
  1299. int insert_at_head)
  1300. {
  1301. struct ctl_table_header *tmp;
  1302. tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
  1303. if (!tmp)
  1304. return NULL;
  1305. tmp->ctl_table = table;
  1306. INIT_LIST_HEAD(&tmp->ctl_entry);
  1307. tmp->used = 0;
  1308. tmp->unregistering = NULL;
  1309. spin_lock(&sysctl_lock);
  1310. if (insert_at_head)
  1311. list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
  1312. else
  1313. list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
  1314. spin_unlock(&sysctl_lock);
  1315. #ifdef CONFIG_PROC_FS
  1316. register_proc_table(table, proc_sys_root, tmp);
  1317. #endif
  1318. return tmp;
  1319. }
  1320. /**
  1321. * unregister_sysctl_table - unregister a sysctl table hierarchy
  1322. * @header: the header returned from register_sysctl_table
  1323. *
  1324. * Unregisters the sysctl table and all children. proc entries may not
  1325. * actually be removed until they are no longer used by anyone.
  1326. */
  1327. void unregister_sysctl_table(struct ctl_table_header * header)
  1328. {
  1329. might_sleep();
  1330. spin_lock(&sysctl_lock);
  1331. start_unregistering(header);
  1332. #ifdef CONFIG_PROC_FS
  1333. unregister_proc_table(header->ctl_table, proc_sys_root);
  1334. #endif
  1335. spin_unlock(&sysctl_lock);
  1336. kfree(header);
  1337. }
  1338. /*
  1339. * /proc/sys support
  1340. */
  1341. #ifdef CONFIG_PROC_FS
  1342. /* Scan the sysctl entries in table and add them all into /proc */
  1343. static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
  1344. {
  1345. struct proc_dir_entry *de;
  1346. int len;
  1347. mode_t mode;
  1348. for (; table->ctl_name; table++) {
  1349. /* Can't do anything without a proc name. */
  1350. if (!table->procname)
  1351. continue;
  1352. /* Maybe we can't do anything with it... */
  1353. if (!table->proc_handler && !table->child) {
  1354. printk(KERN_WARNING "SYSCTL: Can't register %s\n",
  1355. table->procname);
  1356. continue;
  1357. }
  1358. len = strlen(table->procname);
  1359. mode = table->mode;
  1360. de = NULL;
  1361. if (table->proc_handler)
  1362. mode |= S_IFREG;
  1363. else {
  1364. mode |= S_IFDIR;
  1365. for (de = root->subdir; de; de = de->next) {
  1366. if (proc_match(len, table->procname, de))
  1367. break;
  1368. }
  1369. /* If the subdir exists already, de is non-NULL */
  1370. }
  1371. if (!de) {
  1372. de = create_proc_entry(table->procname, mode, root);
  1373. if (!de)
  1374. continue;
  1375. de->set = set;
  1376. de->data = (void *) table;
  1377. if (table->proc_handler)
  1378. de->proc_fops = &proc_sys_file_operations;
  1379. }
  1380. table->de = de;
  1381. if (de->mode & S_IFDIR)
  1382. register_proc_table(table->child, de, set);
  1383. }
  1384. }
  1385. /*
  1386. * Unregister a /proc sysctl table and any subdirectories.
  1387. */
  1388. static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
  1389. {
  1390. struct proc_dir_entry *de;
  1391. for (; table->ctl_name; table++) {
  1392. if (!(de = table->de))
  1393. continue;
  1394. if (de->mode & S_IFDIR) {
  1395. if (!table->child) {
  1396. printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
  1397. continue;
  1398. }
  1399. unregister_proc_table(table->child, de);
  1400. /* Don't unregister directories which still have entries.. */
  1401. if (de->subdir)
  1402. continue;
  1403. }
  1404. /*
  1405. * In any case, mark the entry as goner; we'll keep it
  1406. * around if it's busy, but we'll know to do nothing with
  1407. * its fields. We are under sysctl_lock here.
  1408. */
  1409. de->data = NULL;
  1410. /* Don't unregister proc entries that are still being used.. */
  1411. if (atomic_read(&de->count))
  1412. continue;
  1413. table->de = NULL;
  1414. remove_proc_entry(table->procname, root);
  1415. }
  1416. }
  1417. static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
  1418. size_t count, loff_t *ppos)
  1419. {
  1420. int op;
  1421. struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
  1422. struct ctl_table *table;
  1423. size_t res;
  1424. ssize_t error = -ENOTDIR;
  1425. spin_lock(&sysctl_lock);
  1426. if (de && de->data && use_table(de->set)) {
  1427. /*
  1428. * at that point we know that sysctl was not unregistered
  1429. * and won't be until we finish
  1430. */
  1431. spin_unlock(&sysctl_lock);
  1432. table = (struct ctl_table *) de->data;
  1433. if (!table || !table->proc_handler)
  1434. goto out;
  1435. error = -EPERM;
  1436. op = (write ? 002 : 004);
  1437. if (ctl_perm(table, op))
  1438. goto out;
  1439. /* careful: calling conventions are nasty here */
  1440. res = count;
  1441. error = (*table->proc_handler)(table, write, file,
  1442. buf, &res, ppos);
  1443. if (!error)
  1444. error = res;
  1445. out:
  1446. spin_lock(&sysctl_lock);
  1447. unuse_table(de->set);
  1448. }
  1449. spin_unlock(&sysctl_lock);
  1450. return error;
  1451. }
  1452. static int proc_opensys(struct inode *inode, struct file *file)
  1453. {
  1454. if (file->f_mode & FMODE_WRITE) {
  1455. /*
  1456. * sysctl entries that are not writable,
  1457. * are _NOT_ writable, capabilities or not.
  1458. */
  1459. if (!(inode->i_mode & S_IWUSR))
  1460. return -EPERM;
  1461. }
  1462. return 0;
  1463. }
  1464. static ssize_t proc_readsys(struct file * file, char __user * buf,
  1465. size_t count, loff_t *ppos)
  1466. {
  1467. return do_rw_proc(0, file, buf, count, ppos);
  1468. }
  1469. static ssize_t proc_writesys(struct file * file, const char __user * buf,
  1470. size_t count, loff_t *ppos)
  1471. {
  1472. return do_rw_proc(1, file, (char __user *) buf, count, ppos);
  1473. }
  1474. /**
  1475. * proc_dostring - read a string sysctl
  1476. * @table: the sysctl table
  1477. * @write: %TRUE if this is a write to the sysctl file
  1478. * @filp: the file structure
  1479. * @buffer: the user buffer
  1480. * @lenp: the size of the user buffer
  1481. * @ppos: file position
  1482. *
  1483. * Reads/writes a string from/to the user buffer. If the kernel
  1484. * buffer provided is not large enough to hold the string, the
  1485. * string is truncated. The copied string is %NULL-terminated.
  1486. * If the string is being read by the user process, it is copied
  1487. * and a newline '\n' is added. It is truncated if the buffer is
  1488. * not large enough.
  1489. *
  1490. * Returns 0 on success.
  1491. */
  1492. int proc_dostring(ctl_table *table, int write, struct file *filp,
  1493. void __user *buffer, size_t *lenp, loff_t *ppos)
  1494. {
  1495. size_t len;
  1496. char __user *p;
  1497. char c;
  1498. if (!table->data || !table->maxlen || !*lenp ||
  1499. (*ppos && !write)) {
  1500. *lenp = 0;
  1501. return 0;
  1502. }
  1503. if (write) {
  1504. len = 0;
  1505. p = buffer;
  1506. while (len < *lenp) {
  1507. if (get_user(c, p++))
  1508. return -EFAULT;
  1509. if (c == 0 || c == '\n')
  1510. break;
  1511. len++;
  1512. }
  1513. if (len >= table->maxlen)
  1514. len = table->maxlen-1;
  1515. if(copy_from_user(table->data, buffer, len))
  1516. return -EFAULT;
  1517. ((char *) table->data)[len] = 0;
  1518. *ppos += *lenp;
  1519. } else {
  1520. len = strlen(table->data);
  1521. if (len > table->maxlen)
  1522. len = table->maxlen;
  1523. if (len > *lenp)
  1524. len = *lenp;
  1525. if (len)
  1526. if(copy_to_user(buffer, table->data, len))
  1527. return -EFAULT;
  1528. if (len < *lenp) {
  1529. if(put_user('\n', ((char __user *) buffer) + len))
  1530. return -EFAULT;
  1531. len++;
  1532. }
  1533. *lenp = len;
  1534. *ppos += len;
  1535. }
  1536. return 0;
  1537. }
  1538. /*
  1539. * Special case of dostring for the UTS structure. This has locks
  1540. * to observe. Should this be in kernel/sys.c ????
  1541. */
  1542. static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
  1543. void __user *buffer, size_t *lenp, loff_t *ppos)
  1544. {
  1545. int r;
  1546. if (!write) {
  1547. down_read(&uts_sem);
  1548. r=proc_dostring(table,0,filp,buffer,lenp, ppos);
  1549. up_read(&uts_sem);
  1550. } else {
  1551. down_write(&uts_sem);
  1552. r=proc_dostring(table,1,filp,buffer,lenp, ppos);
  1553. up_write(&uts_sem);
  1554. }
  1555. return r;
  1556. }
  1557. static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
  1558. int *valp,
  1559. int write, void *data)
  1560. {
  1561. if (write) {
  1562. *valp = *negp ? -*lvalp : *lvalp;
  1563. } else {
  1564. int val = *valp;
  1565. if (val < 0) {
  1566. *negp = -1;
  1567. *lvalp = (unsigned long)-val;
  1568. } else {
  1569. *negp = 0;
  1570. *lvalp = (unsigned long)val;
  1571. }
  1572. }
  1573. return 0;
  1574. }
  1575. static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
  1576. void __user *buffer, size_t *lenp, loff_t *ppos,
  1577. int (*conv)(int *negp, unsigned long *lvalp, int *valp,
  1578. int write, void *data),
  1579. void *data)
  1580. {
  1581. #define TMPBUFLEN 21
  1582. int *i, vleft, first=1, neg, val;
  1583. unsigned long lval;
  1584. size_t left, len;
  1585. char buf[TMPBUFLEN], *p;
  1586. char __user *s = buffer;
  1587. if (!table->data || !table->maxlen || !*lenp ||
  1588. (*ppos && !write)) {
  1589. *lenp = 0;
  1590. return 0;
  1591. }
  1592. i = (int *) table->data;
  1593. vleft = table->maxlen / sizeof(*i);
  1594. left = *lenp;
  1595. if (!conv)
  1596. conv = do_proc_dointvec_conv;
  1597. for (; left && vleft--; i++, first=0) {
  1598. if (write) {
  1599. while (left) {
  1600. char c;
  1601. if (get_user(c, s))
  1602. return -EFAULT;
  1603. if (!isspace(c))
  1604. break;
  1605. left--;
  1606. s++;
  1607. }
  1608. if (!left)
  1609. break;
  1610. neg = 0;
  1611. len = left;
  1612. if (len > sizeof(buf) - 1)
  1613. len = sizeof(buf) - 1;
  1614. if (copy_from_user(buf, s, len))
  1615. return -EFAULT;
  1616. buf[len] = 0;
  1617. p = buf;
  1618. if (*p == '-' && left > 1) {
  1619. neg = 1;
  1620. left--, p++;
  1621. }
  1622. if (*p < '0' || *p > '9')
  1623. break;
  1624. lval = simple_strtoul(p, &p, 0);
  1625. len = p-buf;
  1626. if ((len < left) && *p && !isspace(*p))
  1627. break;
  1628. if (neg)
  1629. val = -val;
  1630. s += len;
  1631. left -= len;
  1632. if (conv(&neg, &lval, i, 1, data))
  1633. break;
  1634. } else {
  1635. p = buf;
  1636. if (!first)
  1637. *p++ = '\t';
  1638. if (conv(&neg, &lval, i, 0, data))
  1639. break;
  1640. sprintf(p, "%s%lu", neg ? "-" : "", lval);
  1641. len = strlen(buf);
  1642. if (len > left)
  1643. len = left;
  1644. if(copy_to_user(s, buf, len))
  1645. return -EFAULT;
  1646. left -= len;
  1647. s += len;
  1648. }
  1649. }
  1650. if (!write && !first && left) {
  1651. if(put_user('\n', s))
  1652. return -EFAULT;
  1653. left--, s++;
  1654. }
  1655. if (write) {
  1656. while (left) {
  1657. char c;
  1658. if (get_user(c, s++))
  1659. return -EFAULT;
  1660. if (!isspace(c))
  1661. break;
  1662. left--;
  1663. }
  1664. }
  1665. if (write && first)
  1666. return -EINVAL;
  1667. *lenp -= left;
  1668. *ppos += *lenp;
  1669. return 0;
  1670. #undef TMPBUFLEN
  1671. }
  1672. /**
  1673. * proc_dointvec - read a vector of integers
  1674. * @table: the sysctl table
  1675. * @write: %TRUE if this is a write to the sysctl file
  1676. * @filp: the file structure
  1677. * @buffer: the user buffer
  1678. * @lenp: the size of the user buffer
  1679. * @ppos: file position
  1680. *
  1681. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1682. * values from/to the user buffer, treated as an ASCII string.
  1683. *
  1684. * Returns 0 on success.
  1685. */
  1686. int proc_dointvec(ctl_table *table, int write, struct file *filp,
  1687. void __user *buffer, size_t *lenp, loff_t *ppos)
  1688. {
  1689. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1690. NULL,NULL);
  1691. }
  1692. #define OP_SET 0
  1693. #define OP_AND 1
  1694. #define OP_OR 2
  1695. #define OP_MAX 3
  1696. #define OP_MIN 4
  1697. static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
  1698. int *valp,
  1699. int write, void *data)
  1700. {
  1701. int op = *(int *)data;
  1702. if (write) {
  1703. int val = *negp ? -*lvalp : *lvalp;
  1704. switch(op) {
  1705. case OP_SET: *valp = val; break;
  1706. case OP_AND: *valp &= val; break;
  1707. case OP_OR: *valp |= val; break;
  1708. case OP_MAX: if(*valp < val)
  1709. *valp = val;
  1710. break;
  1711. case OP_MIN: if(*valp > val)
  1712. *valp = val;
  1713. break;
  1714. }
  1715. } else {
  1716. int val = *valp;
  1717. if (val < 0) {
  1718. *negp = -1;
  1719. *lvalp = (unsigned long)-val;
  1720. } else {
  1721. *negp = 0;
  1722. *lvalp = (unsigned long)val;
  1723. }
  1724. }
  1725. return 0;
  1726. }
  1727. /*
  1728. * init may raise the set.
  1729. */
  1730. int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
  1731. void __user *buffer, size_t *lenp, loff_t *ppos)
  1732. {
  1733. int op;
  1734. if (!capable(CAP_SYS_MODULE)) {
  1735. return -EPERM;
  1736. }
  1737. op = (current->pid == 1) ? OP_SET : OP_AND;
  1738. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1739. do_proc_dointvec_bset_conv,&op);
  1740. }
  1741. struct do_proc_dointvec_minmax_conv_param {
  1742. int *min;
  1743. int *max;
  1744. };
  1745. static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
  1746. int *valp,
  1747. int write, void *data)
  1748. {
  1749. struct do_proc_dointvec_minmax_conv_param *param = data;
  1750. if (write) {
  1751. int val = *negp ? -*lvalp : *lvalp;
  1752. if ((param->min && *param->min > val) ||
  1753. (param->max && *param->max < val))
  1754. return -EINVAL;
  1755. *valp = val;
  1756. } else {
  1757. int val = *valp;
  1758. if (val < 0) {
  1759. *negp = -1;
  1760. *lvalp = (unsigned long)-val;
  1761. } else {
  1762. *negp = 0;
  1763. *lvalp = (unsigned long)val;
  1764. }
  1765. }
  1766. return 0;
  1767. }
  1768. /**
  1769. * proc_dointvec_minmax - read a vector of integers with min/max values
  1770. * @table: the sysctl table
  1771. * @write: %TRUE if this is a write to the sysctl file
  1772. * @filp: the file structure
  1773. * @buffer: the user buffer
  1774. * @lenp: the size of the user buffer
  1775. * @ppos: file position
  1776. *
  1777. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1778. * values from/to the user buffer, treated as an ASCII string.
  1779. *
  1780. * This routine will ensure the values are within the range specified by
  1781. * table->extra1 (min) and table->extra2 (max).
  1782. *
  1783. * Returns 0 on success.
  1784. */
  1785. int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
  1786. void __user *buffer, size_t *lenp, loff_t *ppos)
  1787. {
  1788. struct do_proc_dointvec_minmax_conv_param param = {
  1789. .min = (int *) table->extra1,
  1790. .max = (int *) table->extra2,
  1791. };
  1792. return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
  1793. do_proc_dointvec_minmax_conv, &param);
  1794. }
  1795. static int do_proc_doulongvec_minmax(ctl_table *table, int write,
  1796. struct file *filp,
  1797. void __user *buffer,
  1798. size_t *lenp, loff_t *ppos,
  1799. unsigned long convmul,
  1800. unsigned long convdiv)
  1801. {
  1802. #define TMPBUFLEN 21
  1803. unsigned long *i, *min, *max, val;
  1804. int vleft, first=1, neg;
  1805. size_t len, left;
  1806. char buf[TMPBUFLEN], *p;
  1807. char __user *s = buffer;
  1808. if (!table->data || !table->maxlen || !*lenp ||
  1809. (*ppos && !write)) {
  1810. *lenp = 0;
  1811. return 0;
  1812. }
  1813. i = (unsigned long *) table->data;
  1814. min = (unsigned long *) table->extra1;
  1815. max = (unsigned long *) table->extra2;
  1816. vleft = table->maxlen / sizeof(unsigned long);
  1817. left = *lenp;
  1818. for (; left && vleft--; i++, min++, max++, first=0) {
  1819. if (write) {
  1820. while (left) {
  1821. char c;
  1822. if (get_user(c, s))
  1823. return -EFAULT;
  1824. if (!isspace(c))
  1825. break;
  1826. left--;
  1827. s++;
  1828. }
  1829. if (!left)
  1830. break;
  1831. neg = 0;
  1832. len = left;
  1833. if (len > TMPBUFLEN-1)
  1834. len = TMPBUFLEN-1;
  1835. if (copy_from_user(buf, s, len))
  1836. return -EFAULT;
  1837. buf[len] = 0;
  1838. p = buf;
  1839. if (*p == '-' && left > 1) {
  1840. neg = 1;
  1841. left--, p++;
  1842. }
  1843. if (*p < '0' || *p > '9')
  1844. break;
  1845. val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
  1846. len = p-buf;
  1847. if ((len < left) && *p && !isspace(*p))
  1848. break;
  1849. if (neg)
  1850. val = -val;
  1851. s += len;
  1852. left -= len;
  1853. if(neg)
  1854. continue;
  1855. if ((min && val < *min) || (max && val > *max))
  1856. continue;
  1857. *i = val;
  1858. } else {
  1859. p = buf;
  1860. if (!first)
  1861. *p++ = '\t';
  1862. sprintf(p, "%lu", convdiv * (*i) / convmul);
  1863. len = strlen(buf);
  1864. if (len > left)
  1865. len = left;
  1866. if(copy_to_user(s, buf, len))
  1867. return -EFAULT;
  1868. left -= len;
  1869. s += len;
  1870. }
  1871. }
  1872. if (!write && !first && left) {
  1873. if(put_user('\n', s))
  1874. return -EFAULT;
  1875. left--, s++;
  1876. }
  1877. if (write) {
  1878. while (left) {
  1879. char c;
  1880. if (get_user(c, s++))
  1881. return -EFAULT;
  1882. if (!isspace(c))
  1883. break;
  1884. left--;
  1885. }
  1886. }
  1887. if (write && first)
  1888. return -EINVAL;
  1889. *lenp -= left;
  1890. *ppos += *lenp;
  1891. return 0;
  1892. #undef TMPBUFLEN
  1893. }
  1894. /**
  1895. * proc_doulongvec_minmax - read a vector of long integers with min/max values
  1896. * @table: the sysctl table
  1897. * @write: %TRUE if this is a write to the sysctl file
  1898. * @filp: the file structure
  1899. * @buffer: the user buffer
  1900. * @lenp: the size of the user buffer
  1901. * @ppos: file position
  1902. *
  1903. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  1904. * values from/to the user buffer, treated as an ASCII string.
  1905. *
  1906. * This routine will ensure the values are within the range specified by
  1907. * table->extra1 (min) and table->extra2 (max).
  1908. *
  1909. * Returns 0 on success.
  1910. */
  1911. int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
  1912. void __user *buffer, size_t *lenp, loff_t *ppos)
  1913. {
  1914. return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
  1915. }
  1916. /**
  1917. * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
  1918. * @table: the sysctl table
  1919. * @write: %TRUE if this is a write to the sysctl file
  1920. * @filp: the file structure
  1921. * @buffer: the user buffer
  1922. * @lenp: the size of the user buffer
  1923. * @ppos: file position
  1924. *
  1925. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  1926. * values from/to the user buffer, treated as an ASCII string. The values
  1927. * are treated as milliseconds, and converted to jiffies when they are stored.
  1928. *
  1929. * This routine will ensure the values are within the range specified by
  1930. * table->extra1 (min) and table->extra2 (max).
  1931. *
  1932. * Returns 0 on success.
  1933. */
  1934. int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
  1935. struct file *filp,
  1936. void __user *buffer,
  1937. size_t *lenp, loff_t *ppos)
  1938. {
  1939. return do_proc_doulongvec_minmax(table, write, filp, buffer,
  1940. lenp, ppos, HZ, 1000l);
  1941. }
  1942. static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
  1943. int *valp,
  1944. int write, void *data)
  1945. {
  1946. if (write) {
  1947. if (*lvalp > LONG_MAX / HZ)
  1948. return 1;
  1949. *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
  1950. } else {
  1951. int val = *valp;
  1952. unsigned long lval;
  1953. if (val < 0) {
  1954. *negp = -1;
  1955. lval = (unsigned long)-val;
  1956. } else {
  1957. *negp = 0;
  1958. lval = (unsigned long)val;
  1959. }
  1960. *lvalp = lval / HZ;
  1961. }
  1962. return 0;
  1963. }
  1964. static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
  1965. int *valp,
  1966. int write, void *data)
  1967. {
  1968. if (write) {
  1969. if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
  1970. return 1;
  1971. *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
  1972. } else {
  1973. int val = *valp;
  1974. unsigned long lval;
  1975. if (val < 0) {
  1976. *negp = -1;
  1977. lval = (unsigned long)-val;
  1978. } else {
  1979. *negp = 0;
  1980. lval = (unsigned long)val;
  1981. }
  1982. *lvalp = jiffies_to_clock_t(lval);
  1983. }
  1984. return 0;
  1985. }
  1986. static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
  1987. int *valp,
  1988. int write, void *data)
  1989. {
  1990. if (write) {
  1991. *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
  1992. } else {
  1993. int val = *valp;
  1994. unsigned long lval;
  1995. if (val < 0) {
  1996. *negp = -1;
  1997. lval = (unsigned long)-val;
  1998. } else {
  1999. *negp = 0;
  2000. lval = (unsigned long)val;
  2001. }
  2002. *lvalp = jiffies_to_msecs(lval);
  2003. }
  2004. return 0;
  2005. }
  2006. /**
  2007. * proc_dointvec_jiffies - read a vector of integers as seconds
  2008. * @table: the sysctl table
  2009. * @write: %TRUE if this is a write to the sysctl file
  2010. * @filp: the file structure
  2011. * @buffer: the user buffer
  2012. * @lenp: the size of the user buffer
  2013. * @ppos: file position
  2014. *
  2015. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2016. * values from/to the user buffer, treated as an ASCII string.
  2017. * The values read are assumed to be in seconds, and are converted into
  2018. * jiffies.
  2019. *
  2020. * Returns 0 on success.
  2021. */
  2022. int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
  2023. void __user *buffer, size_t *lenp, loff_t *ppos)
  2024. {
  2025. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  2026. do_proc_dointvec_jiffies_conv,NULL);
  2027. }
  2028. /**
  2029. * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
  2030. * @table: the sysctl table
  2031. * @write: %TRUE if this is a write to the sysctl file
  2032. * @filp: the file structure
  2033. * @buffer: the user buffer
  2034. * @lenp: the size of the user buffer
  2035. * @ppos: pointer to the file position
  2036. *
  2037. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2038. * values from/to the user buffer, treated as an ASCII string.
  2039. * The values read are assumed to be in 1/USER_HZ seconds, and
  2040. * are converted into jiffies.
  2041. *
  2042. * Returns 0 on success.
  2043. */
  2044. int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
  2045. void __user *buffer, size_t *lenp, loff_t *ppos)
  2046. {
  2047. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  2048. do_proc_dointvec_userhz_jiffies_conv,NULL);
  2049. }
  2050. /**
  2051. * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
  2052. * @table: the sysctl table
  2053. * @write: %TRUE if this is a write to the sysctl file
  2054. * @filp: the file structure
  2055. * @buffer: the user buffer
  2056. * @lenp: the size of the user buffer
  2057. * @ppos: file position
  2058. * @ppos: the current position in the file
  2059. *
  2060. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2061. * values from/to the user buffer, treated as an ASCII string.
  2062. * The values read are assumed to be in 1/1000 seconds, and
  2063. * are converted into jiffies.
  2064. *
  2065. * Returns 0 on success.
  2066. */
  2067. int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
  2068. void __user *buffer, size_t *lenp, loff_t *ppos)
  2069. {
  2070. return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
  2071. do_proc_dointvec_ms_jiffies_conv, NULL);
  2072. }
  2073. #else /* CONFIG_PROC_FS */
  2074. int proc_dostring(ctl_table *table, int write, struct file *filp,
  2075. void __user *buffer, size_t *lenp, loff_t *ppos)
  2076. {
  2077. return -ENOSYS;
  2078. }
  2079. static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
  2080. void __user *buffer, size_t *lenp, loff_t *ppos)
  2081. {
  2082. return -ENOSYS;
  2083. }
  2084. int proc_dointvec(ctl_table *table, int write, struct file *filp,
  2085. void __user *buffer, size_t *lenp, loff_t *ppos)
  2086. {
  2087. return -ENOSYS;
  2088. }
  2089. int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
  2090. void __user *buffer, size_t *lenp, loff_t *ppos)
  2091. {
  2092. return -ENOSYS;
  2093. }
  2094. int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
  2095. void __user *buffer, size_t *lenp, loff_t *ppos)
  2096. {
  2097. return -ENOSYS;
  2098. }
  2099. int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
  2100. void __user *buffer, size_t *lenp, loff_t *ppos)
  2101. {
  2102. return -ENOSYS;
  2103. }
  2104. int proc_dointvec_userhz_jiffies(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_ms_jiffies(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_doulongvec_minmax(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_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
  2120. struct file *filp,
  2121. void __user *buffer,
  2122. size_t *lenp, loff_t *ppos)
  2123. {
  2124. return -ENOSYS;
  2125. }
  2126. #endif /* CONFIG_PROC_FS */
  2127. /*
  2128. * General sysctl support routines
  2129. */
  2130. /* The generic string strategy routine: */
  2131. int sysctl_string(ctl_table *table, int __user *name, int nlen,
  2132. void __user *oldval, size_t __user *oldlenp,
  2133. void __user *newval, size_t newlen, void **context)
  2134. {
  2135. if (!table->data || !table->maxlen)
  2136. return -ENOTDIR;
  2137. if (oldval && oldlenp) {
  2138. size_t bufsize;
  2139. if (get_user(bufsize, oldlenp))
  2140. return -EFAULT;
  2141. if (bufsize) {
  2142. size_t len = strlen(table->data), copied;
  2143. /* This shouldn't trigger for a well-formed sysctl */
  2144. if (len > table->maxlen)
  2145. len = table->maxlen;
  2146. /* Copy up to a max of bufsize-1 bytes of the string */
  2147. copied = (len >= bufsize) ? bufsize - 1 : len;
  2148. if (copy_to_user(oldval, table->data, copied) ||
  2149. put_user(0, (char __user *)(oldval + copied)))
  2150. return -EFAULT;
  2151. if (put_user(len, oldlenp))
  2152. return -EFAULT;
  2153. }
  2154. }
  2155. if (newval && newlen) {
  2156. size_t len = newlen;
  2157. if (len > table->maxlen)
  2158. len = table->maxlen;
  2159. if(copy_from_user(table->data, newval, len))
  2160. return -EFAULT;
  2161. if (len == table->maxlen)
  2162. len--;
  2163. ((char *) table->data)[len] = 0;
  2164. }
  2165. return 1;
  2166. }
  2167. /*
  2168. * This function makes sure that all of the integers in the vector
  2169. * are between the minimum and maximum values given in the arrays
  2170. * table->extra1 and table->extra2, respectively.
  2171. */
  2172. int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
  2173. void __user *oldval, size_t __user *oldlenp,
  2174. void __user *newval, size_t newlen, void **context)
  2175. {
  2176. if (newval && newlen) {
  2177. int __user *vec = (int __user *) newval;
  2178. int *min = (int *) table->extra1;
  2179. int *max = (int *) table->extra2;
  2180. size_t length;
  2181. int i;
  2182. if (newlen % sizeof(int) != 0)
  2183. return -EINVAL;
  2184. if (!table->extra1 && !table->extra2)
  2185. return 0;
  2186. if (newlen > table->maxlen)
  2187. newlen = table->maxlen;
  2188. length = newlen / sizeof(int);
  2189. for (i = 0; i < length; i++) {
  2190. int value;
  2191. if (get_user(value, vec + i))
  2192. return -EFAULT;
  2193. if (min && value < min[i])
  2194. return -EINVAL;
  2195. if (max && value > max[i])
  2196. return -EINVAL;
  2197. }
  2198. }
  2199. return 0;
  2200. }
  2201. /* Strategy function to convert jiffies to seconds */
  2202. int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
  2203. void __user *oldval, size_t __user *oldlenp,
  2204. void __user *newval, size_t newlen, void **context)
  2205. {
  2206. if (oldval) {
  2207. size_t olen;
  2208. if (oldlenp) {
  2209. if (get_user(olen, oldlenp))
  2210. return -EFAULT;
  2211. if (olen!=sizeof(int))
  2212. return -EINVAL;
  2213. }
  2214. if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
  2215. (oldlenp && put_user(sizeof(int),oldlenp)))
  2216. return -EFAULT;
  2217. }
  2218. if (newval && newlen) {
  2219. int new;
  2220. if (newlen != sizeof(int))
  2221. return -EINVAL;
  2222. if (get_user(new, (int __user *)newval))
  2223. return -EFAULT;
  2224. *(int *)(table->data) = new*HZ;
  2225. }
  2226. return 1;
  2227. }
  2228. /* Strategy function to convert jiffies to seconds */
  2229. int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
  2230. void __user *oldval, size_t __user *oldlenp,
  2231. void __user *newval, size_t newlen, void **context)
  2232. {
  2233. if (oldval) {
  2234. size_t olen;
  2235. if (oldlenp) {
  2236. if (get_user(olen, oldlenp))
  2237. return -EFAULT;
  2238. if (olen!=sizeof(int))
  2239. return -EINVAL;
  2240. }
  2241. if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
  2242. (oldlenp && put_user(sizeof(int),oldlenp)))
  2243. return -EFAULT;
  2244. }
  2245. if (newval && newlen) {
  2246. int new;
  2247. if (newlen != sizeof(int))
  2248. return -EINVAL;
  2249. if (get_user(new, (int __user *)newval))
  2250. return -EFAULT;
  2251. *(int *)(table->data) = msecs_to_jiffies(new);
  2252. }
  2253. return 1;
  2254. }
  2255. #else /* CONFIG_SYSCTL */
  2256. asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
  2257. {
  2258. return -ENOSYS;
  2259. }
  2260. int sysctl_string(ctl_table *table, int __user *name, int nlen,
  2261. void __user *oldval, size_t __user *oldlenp,
  2262. void __user *newval, size_t newlen, void **context)
  2263. {
  2264. return -ENOSYS;
  2265. }
  2266. int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
  2267. void __user *oldval, size_t __user *oldlenp,
  2268. void __user *newval, size_t newlen, void **context)
  2269. {
  2270. return -ENOSYS;
  2271. }
  2272. int sysctl_jiffies(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_ms_jiffies(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 proc_dostring(ctl_table *table, int write, struct file *filp,
  2285. void __user *buffer, size_t *lenp, loff_t *ppos)
  2286. {
  2287. return -ENOSYS;
  2288. }
  2289. int proc_dointvec(ctl_table *table, int write, struct file *filp,
  2290. void __user *buffer, size_t *lenp, loff_t *ppos)
  2291. {
  2292. return -ENOSYS;
  2293. }
  2294. int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
  2295. void __user *buffer, size_t *lenp, loff_t *ppos)
  2296. {
  2297. return -ENOSYS;
  2298. }
  2299. int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
  2300. void __user *buffer, size_t *lenp, loff_t *ppos)
  2301. {
  2302. return -ENOSYS;
  2303. }
  2304. int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
  2305. void __user *buffer, size_t *lenp, loff_t *ppos)
  2306. {
  2307. return -ENOSYS;
  2308. }
  2309. int proc_dointvec_userhz_jiffies(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_ms_jiffies(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_doulongvec_minmax(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_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
  2325. struct file *filp,
  2326. void __user *buffer,
  2327. size_t *lenp, loff_t *ppos)
  2328. {
  2329. return -ENOSYS;
  2330. }
  2331. struct ctl_table_header * register_sysctl_table(ctl_table * table,
  2332. int insert_at_head)
  2333. {
  2334. return NULL;
  2335. }
  2336. void unregister_sysctl_table(struct ctl_table_header * table)
  2337. {
  2338. }
  2339. #endif /* CONFIG_SYSCTL */
  2340. /*
  2341. * No sense putting this after each symbol definition, twice,
  2342. * exception granted :-)
  2343. */
  2344. EXPORT_SYMBOL(proc_dointvec);
  2345. EXPORT_SYMBOL(proc_dointvec_jiffies);
  2346. EXPORT_SYMBOL(proc_dointvec_minmax);
  2347. EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
  2348. EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
  2349. EXPORT_SYMBOL(proc_dostring);
  2350. EXPORT_SYMBOL(proc_doulongvec_minmax);
  2351. EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
  2352. EXPORT_SYMBOL(register_sysctl_table);
  2353. EXPORT_SYMBOL(sysctl_intvec);
  2354. EXPORT_SYMBOL(sysctl_jiffies);
  2355. EXPORT_SYMBOL(sysctl_ms_jiffies);
  2356. EXPORT_SYMBOL(sysctl_string);
  2357. EXPORT_SYMBOL(unregister_sysctl_table);