sysctl.c 64 KB

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