sysctl.c 76 KB

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