sysctl.c 62 KB

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