orangefs: bound op_timeout_secs and slot_timeout_secs
Subsystems (2)
PATCH 1/1 orangefs: bound op_timeout_secs and slot_timeout_secs
service_operation() and wait_for_free() multiply op_timeout_secs and slot_timeout_secs by HZ as int and pass the result to schedule_timeout(). orangefs_init() only replaces negative module parameters with 0, and the /sys/fs/orangefs attributes store any int. Negative values are not valid timeouts, and values above INT_MAX / HZ overflow the signed multiplication. The result can be negative, zero, or much shorter than configured. Negative results make schedule_timeout() print "wrong timeout value" with a stack dump and return at once; all of these cases can make the operation fail with -ETIMEDOUT before the configured interval.
Reject values outside 0..INT_MAX / HZ when the attributes are written, and clamp the module parameters to that range at load time, as negative values already were.
---
Notes:
Tested on x86-64 (HZ=1000) in QEMU with the orangefs module and no client daemon, so a pvfs2 mount waits in service_operation(). On the base kernel, op_timeout_secs values of 2147484, 2147483647 and -1 were accepted, and the mount failed with ETIMEDOUT after 14-29 ms with the schedule_timeout() warning; loading the module with 2147484 did the same. With the patch those writes fail with EINVAL and keep the old value, the module parameter is clamped to 2147483, and the mount waits (stopped by a 3 s userspace timeout). 1 and 2147483 behaved the same on both kernels. slot_timeout_secs was checked through store and readback only; its wait needs a running client. Also built for i386 with W=1.
fs/orangefs/orangefs-mod.c | 8 +++----- fs/orangefs/orangefs-sysfs.c | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 7 deletions(-)
fs/orangefs/orangefs-mod.c +3 -5
@@ -83,11 +83,9 @@ static int __init orangefs_init(void)int ret;__u32 i =0 ; -if (op_timeout_secs <0 ) - op_timeout_secs =0 ; - -if (slot_timeout_secs <0 ) - slot_timeout_secs =0 ; +/* The timeouts are multiplied by HZ as int. */ + op_timeout_secs =clamp (op_timeout_secs,0 ,INT_MAX /HZ ); + slot_timeout_secs =clamp (slot_timeout_secs,0 ,INT_MAX /HZ );/* initialize global book keeping data structures */ ret =op_cache_initialize ();
fs/orangefs/orangefs-sysfs.c +17 -2
@@ -270,6 +270,21 @@ static ssize_t sysfs_int_show(struct kobject *kobj,return rc; } +/* The timeouts are multiplied by HZ as int. */ +static int sysfs_timeout_secs_store (const char *buf,int *timeout_secs) +{ +int val; +int rc; + + rc =kstrtoint (buf,0 , &val); +if (rc) +return rc; +if (val <0 || val >INT_MAX /HZ ) +return -EINVAL ; + *timeout_secs = val; +return 0 ; +} +static ssize_t sysfs_int_store (struct kobject *kobj,struct orangefs_attribute *attr,const char *buf,size_t count) {
@@ -280,10 +295,10 @@ static ssize_t sysfs_int_store(struct kobject *kobj, attr->attr.name, buf);if (!strcmp (attr->attr.name,"op_timeout_secs" )) { - rc =kstrtoint (buf,0 , &op_timeout_secs); + rc =sysfs_timeout_secs_store (buf, &op_timeout_secs); goto out; }else if (!strcmp (attr->attr.name,"slot_timeout_secs" )) { - rc =kstrtoint (buf,0 , &slot_timeout_secs); + rc =sysfs_timeout_secs_store (buf, &slot_timeout_secs); goto out; }else if (!strcmp (attr->attr.name,"cache_timeout_msecs" )) { rc =kstrtoint (buf,0 , &orangefs_cache_timeout_msecs);
base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
Signature · 1 line
2.43.0
Mike Marshall
maintainerYour patch looks good and runs through xfstests fine. I've added it to the stuff I intend to put on my linux next... Thanks...
-Mike
Quoted 99 lines · Yingjie Wang
service_operation()andwait_for_free()multiplyop_timeout_secsandslot_timeout_secsby HZ as int and pass the result toschedule_timeout().orangefs_init()only replaces negative module parameters with 0, and the/sys/fs/orangefsattributes store any int. Negative values are not valid timeouts, and values aboveINT_MAX/ HZ overflow the signed multiplication. The result can be negative, zero, or much shorter than configured. Negative results makeschedule_timeout()print "wrong timeout value" with a stack dump and return at once; all of these cases can make the operation fail with-ETIMEDOUTbefore the configured interval.Reject values outside 0..INT_MAX / HZ when the attributes are written, and clamp the module parameters to that range at load time, as negative values already were.
Fixes 274dcf55bd4a ("Orangefs: kernel client part 3")Signed-off-by Yingjie Wang <[email protected]>---
Notes:
Tested on x86-64 (HZ=1000) in QEMU with the orangefs module and no client daemon, so a pvfs2 mount waits inservice_operation(). On the base kernel,op_timeout_secsvalues of 2147484, 2147483647 and -1 were accepted, and the mount failed with ETIMEDOUT after 14-29 ms with theschedule_timeout()warning; loading the module with 2147484 did the same. With the patch those writes fail with EINVAL and keep the old value, the module parameter is clamped to 2147483, and the mount waits (stopped by a 3 s userspace timeout). 1 and 2147483 behaved the same on both kernels.slot_timeout_secswas checked through store and readback only; its wait needs a running client. Also built for i386 with W=1.fs/orangefs/orangefs-mod.c | 8 +++----- fs/orangefs/orangefs-sysfs.c | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 7 deletions(-)fs/orangefs/orangefs-mod.c +3
-5@@ -83,11 +83,9 @@ static int __init orangefs_init(void)int ret;__u32 i =0 ; -if (op_timeout_secs <0 ) - op_timeout_secs =0 ; - -if (slot_timeout_secs <0 ) - slot_timeout_secs =0 ; +/* The timeouts are multiplied by HZ as int. */ + op_timeout_secs =clamp (op_timeout_secs,0 ,INT_MAX /HZ ); + slot_timeout_secs =clamp (slot_timeout_secs,0 ,INT_MAX /HZ );/* initialize global book keeping data structures */ ret =op_cache_initialize ();fs/orangefs/orangefs-sysfs.c +17
-2@@ -270,6 +270,21 @@ static ssize_t sysfs_int_show(struct kobject *kobj,return rc; } +/* The timeouts are multiplied by HZ as int. */ +static int sysfs_timeout_secs_store (const char *buf,int *timeout_secs) +{ +int val; +int rc; + + rc =kstrtoint (buf,0 , &val); +if (rc) +return rc; +if (val <0 || val >INT_MAX /HZ ) +return -EINVAL ; + *timeout_secs = val; +return 0 ; +} +static ssize_t sysfs_int_store (struct kobject *kobj,struct orangefs_attribute *attr,const char *buf,size_t count) {@@ -280,10 +295,10 @@ static ssize_t sysfs_int_store(struct kobject *kobj, attr->attr.name, buf);if (!strcmp (attr->attr.name,"op_timeout_secs" )) { - rc =kstrtoint (buf,0 , &op_timeout_secs); + rc =sysfs_timeout_secs_store (buf, &op_timeout_secs); goto out; }else if (!strcmp (attr->attr.name,"slot_timeout_secs" )) { - rc =kstrtoint (buf,0 , &slot_timeout_secs); + rc =sysfs_timeout_secs_store (buf, &slot_timeout_secs); goto out; }else if (!strcmp (attr->attr.name,"cache_timeout_msecs" )) { rc =kstrtoint (buf,0 , &orangefs_cache_timeout_msecs);base-commit:
c339f4010dea8b0d754f84ace70cd1b089878ef8--
2.43.0