sysctl.c 64 KB

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