sysctl.c 65 KB

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