sysctl.c 66 KB

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