sysctl.c 54 KB

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