sysctl.c 55 KB

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