sysctl.c 63 KB

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