sysctl.c 68 KB

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