sysctl.c 73 KB

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