sysctl.c 67 KB

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