sysctl.c 62 KB

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