sysctl.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367
  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_dointvec,
  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_dointvec,
  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. *
  1886. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1887. * values from/to the user buffer, treated as an ASCII string.
  1888. * The values read are assumed to be in 1/USER_HZ seconds, and
  1889. * are converted into jiffies.
  1890. *
  1891. * Returns 0 on success.
  1892. */
  1893. int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
  1894. void __user *buffer, size_t *lenp, loff_t *ppos)
  1895. {
  1896. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1897. do_proc_dointvec_userhz_jiffies_conv,NULL);
  1898. }
  1899. /**
  1900. * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
  1901. * @table: the sysctl table
  1902. * @write: %TRUE if this is a write to the sysctl file
  1903. * @filp: the file structure
  1904. * @buffer: the user buffer
  1905. * @lenp: the size of the user buffer
  1906. * @ppos: file position
  1907. * @ppos: the current position in the file
  1908. *
  1909. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1910. * values from/to the user buffer, treated as an ASCII string.
  1911. * The values read are assumed to be in 1/1000 seconds, and
  1912. * are converted into jiffies.
  1913. *
  1914. * Returns 0 on success.
  1915. */
  1916. int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
  1917. void __user *buffer, size_t *lenp, loff_t *ppos)
  1918. {
  1919. return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
  1920. do_proc_dointvec_ms_jiffies_conv, NULL);
  1921. }
  1922. #else /* CONFIG_PROC_FS */
  1923. int proc_dostring(ctl_table *table, int write, struct file *filp,
  1924. void __user *buffer, size_t *lenp, loff_t *ppos)
  1925. {
  1926. return -ENOSYS;
  1927. }
  1928. static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
  1929. void __user *buffer, size_t *lenp, loff_t *ppos)
  1930. {
  1931. return -ENOSYS;
  1932. }
  1933. int proc_dointvec(ctl_table *table, int write, struct file *filp,
  1934. void __user *buffer, size_t *lenp, loff_t *ppos)
  1935. {
  1936. return -ENOSYS;
  1937. }
  1938. int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
  1939. void __user *buffer, size_t *lenp, loff_t *ppos)
  1940. {
  1941. return -ENOSYS;
  1942. }
  1943. int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
  1944. void __user *buffer, size_t *lenp, loff_t *ppos)
  1945. {
  1946. return -ENOSYS;
  1947. }
  1948. int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
  1949. void __user *buffer, size_t *lenp, loff_t *ppos)
  1950. {
  1951. return -ENOSYS;
  1952. }
  1953. int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
  1954. void __user *buffer, size_t *lenp, loff_t *ppos)
  1955. {
  1956. return -ENOSYS;
  1957. }
  1958. int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
  1959. void __user *buffer, size_t *lenp, loff_t *ppos)
  1960. {
  1961. return -ENOSYS;
  1962. }
  1963. int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
  1964. void __user *buffer, size_t *lenp, loff_t *ppos)
  1965. {
  1966. return -ENOSYS;
  1967. }
  1968. int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
  1969. struct file *filp,
  1970. void __user *buffer,
  1971. size_t *lenp, loff_t *ppos)
  1972. {
  1973. return -ENOSYS;
  1974. }
  1975. #endif /* CONFIG_PROC_FS */
  1976. /*
  1977. * General sysctl support routines
  1978. */
  1979. /* The generic string strategy routine: */
  1980. int sysctl_string(ctl_table *table, int __user *name, int nlen,
  1981. void __user *oldval, size_t __user *oldlenp,
  1982. void __user *newval, size_t newlen, void **context)
  1983. {
  1984. size_t l, len;
  1985. if (!table->data || !table->maxlen)
  1986. return -ENOTDIR;
  1987. if (oldval && oldlenp) {
  1988. if (get_user(len, oldlenp))
  1989. return -EFAULT;
  1990. if (len) {
  1991. l = strlen(table->data);
  1992. if (len > l) len = l;
  1993. if (len >= table->maxlen)
  1994. len = table->maxlen;
  1995. if(copy_to_user(oldval, table->data, len))
  1996. return -EFAULT;
  1997. if(put_user(0, ((char __user *) oldval) + len))
  1998. return -EFAULT;
  1999. if(put_user(len, oldlenp))
  2000. return -EFAULT;
  2001. }
  2002. }
  2003. if (newval && newlen) {
  2004. len = newlen;
  2005. if (len > table->maxlen)
  2006. len = table->maxlen;
  2007. if(copy_from_user(table->data, newval, len))
  2008. return -EFAULT;
  2009. if (len == table->maxlen)
  2010. len--;
  2011. ((char *) table->data)[len] = 0;
  2012. }
  2013. return 0;
  2014. }
  2015. /*
  2016. * This function makes sure that all of the integers in the vector
  2017. * are between the minimum and maximum values given in the arrays
  2018. * table->extra1 and table->extra2, respectively.
  2019. */
  2020. int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
  2021. void __user *oldval, size_t __user *oldlenp,
  2022. void __user *newval, size_t newlen, void **context)
  2023. {
  2024. if (newval && newlen) {
  2025. int __user *vec = (int __user *) newval;
  2026. int *min = (int *) table->extra1;
  2027. int *max = (int *) table->extra2;
  2028. size_t length;
  2029. int i;
  2030. if (newlen % sizeof(int) != 0)
  2031. return -EINVAL;
  2032. if (!table->extra1 && !table->extra2)
  2033. return 0;
  2034. if (newlen > table->maxlen)
  2035. newlen = table->maxlen;
  2036. length = newlen / sizeof(int);
  2037. for (i = 0; i < length; i++) {
  2038. int value;
  2039. if (get_user(value, vec + i))
  2040. return -EFAULT;
  2041. if (min && value < min[i])
  2042. return -EINVAL;
  2043. if (max && value > max[i])
  2044. return -EINVAL;
  2045. }
  2046. }
  2047. return 0;
  2048. }
  2049. /* Strategy function to convert jiffies to seconds */
  2050. int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
  2051. void __user *oldval, size_t __user *oldlenp,
  2052. void __user *newval, size_t newlen, void **context)
  2053. {
  2054. if (oldval) {
  2055. size_t olen;
  2056. if (oldlenp) {
  2057. if (get_user(olen, oldlenp))
  2058. return -EFAULT;
  2059. if (olen!=sizeof(int))
  2060. return -EINVAL;
  2061. }
  2062. if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
  2063. (oldlenp && put_user(sizeof(int),oldlenp)))
  2064. return -EFAULT;
  2065. }
  2066. if (newval && newlen) {
  2067. int new;
  2068. if (newlen != sizeof(int))
  2069. return -EINVAL;
  2070. if (get_user(new, (int __user *)newval))
  2071. return -EFAULT;
  2072. *(int *)(table->data) = new*HZ;
  2073. }
  2074. return 1;
  2075. }
  2076. /* Strategy function to convert jiffies to seconds */
  2077. int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
  2078. void __user *oldval, size_t __user *oldlenp,
  2079. void __user *newval, size_t newlen, void **context)
  2080. {
  2081. if (oldval) {
  2082. size_t olen;
  2083. if (oldlenp) {
  2084. if (get_user(olen, oldlenp))
  2085. return -EFAULT;
  2086. if (olen!=sizeof(int))
  2087. return -EINVAL;
  2088. }
  2089. if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
  2090. (oldlenp && put_user(sizeof(int),oldlenp)))
  2091. return -EFAULT;
  2092. }
  2093. if (newval && newlen) {
  2094. int new;
  2095. if (newlen != sizeof(int))
  2096. return -EINVAL;
  2097. if (get_user(new, (int __user *)newval))
  2098. return -EFAULT;
  2099. *(int *)(table->data) = msecs_to_jiffies(new);
  2100. }
  2101. return 1;
  2102. }
  2103. #else /* CONFIG_SYSCTL */
  2104. asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
  2105. {
  2106. return -ENOSYS;
  2107. }
  2108. int sysctl_string(ctl_table *table, int __user *name, int nlen,
  2109. void __user *oldval, size_t __user *oldlenp,
  2110. void __user *newval, size_t newlen, void **context)
  2111. {
  2112. return -ENOSYS;
  2113. }
  2114. int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
  2115. void __user *oldval, size_t __user *oldlenp,
  2116. void __user *newval, size_t newlen, void **context)
  2117. {
  2118. return -ENOSYS;
  2119. }
  2120. int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
  2121. void __user *oldval, size_t __user *oldlenp,
  2122. void __user *newval, size_t newlen, void **context)
  2123. {
  2124. return -ENOSYS;
  2125. }
  2126. int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
  2127. void __user *oldval, size_t __user *oldlenp,
  2128. void __user *newval, size_t newlen, void **context)
  2129. {
  2130. return -ENOSYS;
  2131. }
  2132. int proc_dostring(ctl_table *table, int write, struct file *filp,
  2133. void __user *buffer, size_t *lenp, loff_t *ppos)
  2134. {
  2135. return -ENOSYS;
  2136. }
  2137. int proc_dointvec(ctl_table *table, int write, struct file *filp,
  2138. void __user *buffer, size_t *lenp, loff_t *ppos)
  2139. {
  2140. return -ENOSYS;
  2141. }
  2142. int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
  2143. void __user *buffer, size_t *lenp, loff_t *ppos)
  2144. {
  2145. return -ENOSYS;
  2146. }
  2147. int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
  2148. void __user *buffer, size_t *lenp, loff_t *ppos)
  2149. {
  2150. return -ENOSYS;
  2151. }
  2152. int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
  2153. void __user *buffer, size_t *lenp, loff_t *ppos)
  2154. {
  2155. return -ENOSYS;
  2156. }
  2157. int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
  2158. void __user *buffer, size_t *lenp, loff_t *ppos)
  2159. {
  2160. return -ENOSYS;
  2161. }
  2162. int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
  2163. void __user *buffer, size_t *lenp, loff_t *ppos)
  2164. {
  2165. return -ENOSYS;
  2166. }
  2167. int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
  2168. void __user *buffer, size_t *lenp, loff_t *ppos)
  2169. {
  2170. return -ENOSYS;
  2171. }
  2172. int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
  2173. struct file *filp,
  2174. void __user *buffer,
  2175. size_t *lenp, loff_t *ppos)
  2176. {
  2177. return -ENOSYS;
  2178. }
  2179. struct ctl_table_header * register_sysctl_table(ctl_table * table,
  2180. int insert_at_head)
  2181. {
  2182. return NULL;
  2183. }
  2184. void unregister_sysctl_table(struct ctl_table_header * table)
  2185. {
  2186. }
  2187. #endif /* CONFIG_SYSCTL */
  2188. /*
  2189. * No sense putting this after each symbol definition, twice,
  2190. * exception granted :-)
  2191. */
  2192. EXPORT_SYMBOL(proc_dointvec);
  2193. EXPORT_SYMBOL(proc_dointvec_jiffies);
  2194. EXPORT_SYMBOL(proc_dointvec_minmax);
  2195. EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
  2196. EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
  2197. EXPORT_SYMBOL(proc_dostring);
  2198. EXPORT_SYMBOL(proc_doulongvec_minmax);
  2199. EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
  2200. EXPORT_SYMBOL(register_sysctl_table);
  2201. EXPORT_SYMBOL(sysctl_intvec);
  2202. EXPORT_SYMBOL(sysctl_jiffies);
  2203. EXPORT_SYMBOL(sysctl_ms_jiffies);
  2204. EXPORT_SYMBOL(sysctl_string);
  2205. EXPORT_SYMBOL(unregister_sysctl_table);