sysctl.c 76 KB

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