sysctl.c 65 KB

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