History

[PATCH] Range checking in do_proc_dointvec_(userhz_)jiffies_conv

When (integer) sysctl values are in either seconds or centiseconds, but represented internally as jiffies, the allowable value range is decreased. This patch adds range checks to the conversion routines. For values in seconds: maximum LONG_MAX / HZ. For values in centiseconds: maximum (LONG_MAX / HZ) * USER_HZ. (BTW, does anyone else feel that an interface in seconds should not be accepting negative values?)

Bart Samwel committed 20 years ago

Commit cba9f331 parent ed5b43f1 file · +4 −0Browse files

Unified · Split

kernel/sysctl.c+4−0
@@ -2053,6 +2053,8 @@ static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp, · 2052 unmodified lines
20532053 int write, void *data)
20542054 {
20552055 if (write) {
2056+ if (*lvalp > LONG_MAX / HZ)
2057+ return 1;
20562058 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
20572059 } else {
20582060 int val = *valp;
@@ -2074,6 +2076,8 @@ static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp, · 15 unmodified lines
20742076 int write, void *data)
20752077 {
20762078 if (write) {
2079+ if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2080+ return 1;
20772081 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
20782082 } else {
20792083 int val = *valp;