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