sysctl.c 65 KB

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