Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sysctl: Discriminate between kernel and user converter params

Rename converter parameter to indicate data flow direction: "lvalp" to
"u_ptr" indicating a user space parsed value pointer. "valp" to "k_ptr"
indicating a kernel storage value pointer. This facilitates the
identification of discrepancies between direction (copy to kernel or
copy to user space) and the modified variable. This is a preparation
commit for when the converter functions are exposed to the rest of the
kernel.

Signed-off-by: Joel Granados <joel.granados@kernel.org>

+59 -59
+59 -59
kernel/sysctl.c
··· 368 368 } 369 369 } 370 370 371 - static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, 372 - int *valp, int dir, 371 + static int do_proc_dointvec_conv(bool *negp, unsigned long *u_ptr, 372 + int *k_ptr, int dir, 373 373 const struct ctl_table *table) 374 374 { 375 375 if (SYSCTL_USER_TO_KERN(dir)) { 376 376 if (*negp) { 377 - if (*lvalp > (unsigned long) INT_MAX + 1) 377 + if (*u_ptr > (unsigned long) INT_MAX + 1) 378 378 return -EINVAL; 379 - WRITE_ONCE(*valp, -*lvalp); 379 + WRITE_ONCE(*k_ptr, -*u_ptr); 380 380 } else { 381 - if (*lvalp > (unsigned long) INT_MAX) 381 + if (*u_ptr > (unsigned long) INT_MAX) 382 382 return -EINVAL; 383 - WRITE_ONCE(*valp, *lvalp); 383 + WRITE_ONCE(*k_ptr, *u_ptr); 384 384 } 385 385 } else { 386 - int val = READ_ONCE(*valp); 386 + int val = READ_ONCE(*k_ptr); 387 387 if (val < 0) { 388 388 *negp = true; 389 - *lvalp = -(unsigned long)val; 389 + *u_ptr = -(unsigned long)val; 390 390 } else { 391 391 *negp = false; 392 - *lvalp = (unsigned long)val; 392 + *u_ptr = (unsigned long)val; 393 393 } 394 394 } 395 395 return 0; 396 396 } 397 397 398 - static int do_proc_douintvec_conv(unsigned long *lvalp, 399 - unsigned int *valp, int dir, 398 + static int do_proc_douintvec_conv(unsigned long *u_ptr, 399 + unsigned int *k_ptr, int dir, 400 400 const struct ctl_table *table) 401 401 { 402 402 if (SYSCTL_USER_TO_KERN(dir)) { 403 - if (*lvalp > UINT_MAX) 403 + if (*u_ptr > UINT_MAX) 404 404 return -EINVAL; 405 - WRITE_ONCE(*valp, *lvalp); 405 + WRITE_ONCE(*k_ptr, *u_ptr); 406 406 } else { 407 - unsigned int val = READ_ONCE(*valp); 408 - *lvalp = (unsigned long)val; 407 + unsigned int val = READ_ONCE(*k_ptr); 408 + *u_ptr = (unsigned long)val; 409 409 } 410 410 return 0; 411 411 } ··· 415 415 416 416 static int do_proc_dointvec(const struct ctl_table *table, int dir, 417 417 void *buffer, size_t *lenp, loff_t *ppos, 418 - int (*conv)(bool *negp, unsigned long *lvalp, int *valp, 418 + int (*conv)(bool *negp, unsigned long *u_ptr, int *k_ptr, 419 419 int dir, const struct ctl_table *table)) 420 420 { 421 421 int *i, vleft, first = 1, err = 0; ··· 487 487 488 488 static int do_proc_douintvec_w(const struct ctl_table *table, void *buffer, 489 489 size_t *lenp, loff_t *ppos, 490 - int (*conv)(unsigned long *lvalp, 491 - unsigned int *valp, int dir, 490 + int (*conv)(unsigned long *u_ptr, 491 + unsigned int *k_ptr, int dir, 492 492 const struct ctl_table *table)) 493 493 { 494 494 unsigned long lval; ··· 540 540 541 541 static int do_proc_douintvec_r(const struct ctl_table *table, void *buffer, 542 542 size_t *lenp, loff_t *ppos, 543 - int (*conv)(unsigned long *lvalp, 544 - unsigned int *valp, int dir, 543 + int (*conv)(unsigned long *u_ptr, 544 + unsigned int *k_ptr, int dir, 545 545 const struct ctl_table *table)) 546 546 { 547 547 unsigned long lval; ··· 570 570 571 571 int do_proc_douintvec(const struct ctl_table *table, int dir, void *buffer, 572 572 size_t *lenp, loff_t *ppos, 573 - int (*conv)(unsigned long *lvalp, unsigned int *valp, 573 + int (*conv)(unsigned long *u_ptr, unsigned int *k_ptr, 574 574 int dir, const struct ctl_table *table)) 575 575 { 576 576 unsigned int vleft; ··· 679 679 do_proc_douintvec_conv); 680 680 } 681 681 682 - static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp, 683 - int *valp, int dir, 682 + static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *u_ptr, 683 + int *k_ptr, int dir, 684 684 const struct ctl_table *table) 685 685 { 686 686 int tmp, ret, *min, *max; 687 687 /* 688 - * If writing, first do so via a temporary local int so we can 689 - * bounds-check it before touching *valp. 688 + * If writing to a kernel variable, first do so via a temporary 689 + * local int so we can bounds-check it before touching *k_ptr. 690 690 */ 691 - int *ip = SYSCTL_USER_TO_KERN(dir) ? &tmp : valp; 691 + int *ip = SYSCTL_USER_TO_KERN(dir) ? &tmp : k_ptr; 692 692 693 - ret = do_proc_dointvec_conv(negp, lvalp, ip, dir, table); 693 + ret = do_proc_dointvec_conv(negp, u_ptr, ip, dir, table); 694 694 if (ret) 695 695 return ret; 696 696 ··· 699 699 max = (int *) table->extra2; 700 700 if ((min && *min > tmp) || (max && *max < tmp)) 701 701 return -EINVAL; 702 - WRITE_ONCE(*valp, tmp); 702 + WRITE_ONCE(*k_ptr, tmp); 703 703 } 704 704 705 705 return 0; ··· 729 729 do_proc_dointvec_minmax_conv); 730 730 } 731 731 732 - static int do_proc_douintvec_minmax_conv(unsigned long *lvalp, 733 - unsigned int *valp, int dir, 732 + static int do_proc_douintvec_minmax_conv(unsigned long *u_ptr, 733 + unsigned int *k_ptr, int dir, 734 734 const struct ctl_table *table) 735 735 { 736 736 int ret; 737 737 unsigned int tmp, *min, *max; 738 738 /* When writing to the kernel use a temp local uint for bounds-checking */ 739 - unsigned int *up = SYSCTL_USER_TO_KERN(dir) ? &tmp : valp; 739 + unsigned int *up = SYSCTL_USER_TO_KERN(dir) ? &tmp : k_ptr; 740 740 741 - ret = do_proc_douintvec_conv(lvalp, up, dir, table); 741 + ret = do_proc_douintvec_conv(u_ptr, up, dir, table); 742 742 if (ret) 743 743 return ret; 744 744 ··· 748 748 if ((min && *min > tmp) || (max && *max < tmp)) 749 749 return -ERANGE; 750 750 751 - WRITE_ONCE(*valp, tmp); 751 + WRITE_ONCE(*k_ptr, tmp); 752 752 } 753 753 754 754 return 0; ··· 953 953 } 954 954 955 955 956 - static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp, 957 - int *valp, int dir, 956 + static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *u_ptr, 957 + int *k_ptr, int dir, 958 958 const struct ctl_table *table) 959 959 { 960 960 if (SYSCTL_USER_TO_KERN(dir)) { 961 - if (*lvalp > INT_MAX / HZ) 961 + if (*u_ptr > INT_MAX / HZ) 962 962 return 1; 963 963 if (*negp) 964 - WRITE_ONCE(*valp, -*lvalp * HZ); 964 + WRITE_ONCE(*k_ptr, -*u_ptr * HZ); 965 965 else 966 - WRITE_ONCE(*valp, *lvalp * HZ); 966 + WRITE_ONCE(*k_ptr, *u_ptr * HZ); 967 967 } else { 968 - int val = READ_ONCE(*valp); 968 + int val = READ_ONCE(*k_ptr); 969 969 unsigned long lval; 970 970 if (val < 0) { 971 971 *negp = true; ··· 974 974 *negp = false; 975 975 lval = (unsigned long)val; 976 976 } 977 - *lvalp = lval / HZ; 977 + *u_ptr = lval / HZ; 978 978 } 979 979 return 0; 980 980 } 981 981 982 - static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp, 983 - int *valp, int dir, 982 + static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *u_ptr, 983 + int *k_ptr, int dir, 984 984 const struct ctl_table *table) 985 985 { 986 986 if (SYSCTL_USER_TO_KERN(dir)) { 987 - if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ) 987 + if (USER_HZ < HZ && (LONG_MAX / HZ) * USER_HZ < *u_ptr) 988 988 return 1; 989 - *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp); 989 + *k_ptr = clock_t_to_jiffies(*negp ? -*u_ptr : *u_ptr); 990 990 } else { 991 - int val = *valp; 991 + int val = *k_ptr; 992 992 unsigned long lval; 993 993 if (val < 0) { 994 994 *negp = true; ··· 997 997 *negp = false; 998 998 lval = (unsigned long)val; 999 999 } 1000 - *lvalp = jiffies_to_clock_t(lval); 1000 + *u_ptr = jiffies_to_clock_t(lval); 1001 1001 } 1002 1002 return 0; 1003 1003 } 1004 1004 1005 - static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp, 1006 - int *valp, int dir, 1005 + static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *u_ptr, 1006 + int *k_ptr, int dir, 1007 1007 const struct ctl_table *table) 1008 1008 { 1009 1009 if (SYSCTL_USER_TO_KERN(dir)) { 1010 - unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp); 1010 + unsigned long jif = msecs_to_jiffies(*negp ? -*u_ptr : *u_ptr); 1011 1011 1012 1012 if (jif > INT_MAX) 1013 1013 return 1; 1014 - WRITE_ONCE(*valp, (int)jif); 1014 + WRITE_ONCE(*k_ptr, (int)jif); 1015 1015 } else { 1016 - int val = READ_ONCE(*valp); 1016 + int val = READ_ONCE(*k_ptr); 1017 1017 unsigned long lval; 1018 1018 if (val < 0) { 1019 1019 *negp = true; ··· 1022 1022 *negp = false; 1023 1023 lval = (unsigned long)val; 1024 1024 } 1025 - *lvalp = jiffies_to_msecs(lval); 1025 + *u_ptr = jiffies_to_msecs(lval); 1026 1026 } 1027 1027 return 0; 1028 1028 } 1029 1029 1030 - static int do_proc_dointvec_ms_jiffies_minmax_conv(bool *negp, unsigned long *lvalp, 1031 - int *valp, int dir, 1030 + static int do_proc_dointvec_ms_jiffies_minmax_conv(bool *negp, unsigned long *u_ptr, 1031 + int *k_ptr, int dir, 1032 1032 const struct ctl_table *table) 1033 1033 { 1034 1034 int tmp, ret, *min, *max; 1035 1035 /* 1036 - * If writing, first do so via a temporary local int so we can 1037 - * bounds-check it before touching *valp. 1036 + * If writing to a kernel var, first do so via a temporary local 1037 + * int so we can bounds-check it before touching *k_ptr. 1038 1038 */ 1039 - int *ip = SYSCTL_USER_TO_KERN(dir) ? &tmp : valp; 1039 + int *ip = SYSCTL_USER_TO_KERN(dir) ? &tmp : k_ptr; 1040 1040 1041 - ret = do_proc_dointvec_ms_jiffies_conv(negp, lvalp, ip, dir, table); 1041 + ret = do_proc_dointvec_ms_jiffies_conv(negp, u_ptr, ip, dir, table); 1042 1042 if (ret) 1043 1043 return ret; 1044 1044 ··· 1047 1047 max = (int *) table->extra2; 1048 1048 if ((min && *min > tmp) || (max && *max < tmp)) 1049 1049 return -EINVAL; 1050 - *valp = tmp; 1050 + *k_ptr = tmp; 1051 1051 } 1052 1052 return 0; 1053 1053 }