sysctl.c 54 KB

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