sysctl.c 54 KB

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