Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the bug that config->env is greater than ulong_max when units->val =1 #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zhuofeng6
Copy link

@zhuofeng6 zhuofeng6 commented Dec 7, 2023

when PAGE_CE_THRESHOLD is greater than ulong_max, it can be set

rasdaemon: Improper PAGE_CE_ACTION, set to default soft
rasdaemon: Page offline choice on Corrected Errors is soft
rasdaemon: Threshold of memory Corrected Errors is 9999999999999999999999999999999999999999999999999 / 23h
overriding event (1136) ras:mc_event with new print handler
rasdaemon: ras:mc_event event enabled
rasdaemon: Enabled event ras:mc_event
overriding event (1133) ras:aer_event with new print handler
rasdaemon: ras:aer_event event enabled
rasdaemon: Enabled event ras:aer_event
overriding event (1134) ras:non_standard_event with new print handler

@zhuofeng6 zhuofeng6 changed the title Fix the bug that config->env is greater than ulong_max when units… Fix the bug that config->env is greater than ulong_max when units->val =1 Dec 7, 2023
if (errno == ERANGE || *endptr != '\0')
config->overflow = true;
}
unit_matched = 0;
Copy link
Owner

@mchehab mchehab Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic seems weird to me. First of all, units is an array. It may potentially have units->name == NULL as the first element, indicating the end of such array, in which case units->val should not be used.

Also, I tried to understand why units->val==1 so special. I mean, why other values can't overflow?

Looking at the check code:

       /* if env value string is greater than ulong_max, truncate the last digit */
        sscanf(config->env, "%lu", &value);
        for (units = config->units; units->name; units++) {
                if (!strcasecmp(config->unit, units->name))
                        unit_matched = 1;
                if (unit_matched) {
                        tmp = value;
                        value *= units->val;
                        if (tmp != 0 && value / tmp != units->val)
                                config->overflow = true;
                }
        }

The idea of the above check were exactly to catch ERANGE issues. If it is broken, or should instead use strtoul to catch overflows, please fix it or replace the check by a better logic.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if units->val==1 and PAGE_CE_THRESHOLD or PAGE_CE_REFRESH_CYCLE is greater than ulong_max.
e.g.
PAGE_CE_THRESHOLD=9999999999999999999999999999999999999999999999999
PAGE_CE_REFRESH_CYCLE=333333999999999999999999999999999999999s

/* if env value string is greater than ulong_max, truncate the last digit */
	sscanf(config->env, "%lu", &value);
	for (units = config->units; units->name; units++) {
		if (!strcasecmp(config->unit, units->name))
			unit_matched = 1;
		if (unit_matched) {
			tmp = value;
			value *= units->val;
			if (tmp != 0 && value / tmp != units->val)
				config->overflow = true;
		}
	}

then sscanf(config->env, "%lu", &value); value is 18446744073709551615(2^64-1)
value *= units->val; // value is 2^64-1, because units->val == 1
if (tmp != 0 && value / tmp != units->val)
and then that condition is not met. because (value / tmp == 1)

but units->val is not 1, e.g. 1000,
then sscanf(config->env, "%lu", &value); value is 18446744073709551615(2^64-1)
value *= units->val; // value is 2^64-1, Even though value is multiplied by 1000, the maximum value is still 2^64-1
if (tmp != 0 && value / tmp != units->val)
and then that condition is met. because (value / tmp == 1, not 1000)

@zhuofeng6
Copy link
Author

This is just showing overflow, it doesn't actually seem to be overflowing because the maximum value can only be 2^64 - 1

@zhuofeng6
Copy link
Author

PAGE_CE_THRESHOLD=9999999999999999999999999999999999999999999999999k
PAGE_CE_REFRESH_CYCLE=333333999999999999999999999999999999999s

rasdaemon: Improper PAGE_CE_ACTION, set to default soft
rasdaemon: Page offline choice on Corrected Errors is soft
rasdaemon: PAGE_CE_THRESHOLD is set overflow(9999999999999999999999999999999999999999999999999k), truncate it
rasdaemon: Threshold of memory Corrected Errors is 18446744073709550616 / 333333999999999999999999999999999999999s
overriding event (1135) ras:mc_event with new print handler
rasdaemon: ras:mc_event event enabled
rasdaemon: Enabled event ras:mc_event
overriding event (1132) ras:aer_event with new print handler
rasdaemon: ras:aer_event event enabled
rasdaemon: Enabled event ras:aer_event
overriding event (1133) ras:non_standard_event with new print handler
rasdaemon: ras:non_standard_event event enabled
rasdaemon: Enabled event ras:non_standard_event
overriding event (1134) ras:arm_event with new print handler
rasdaemon: ras:arm_event event enabled
rasdaemon: Enabled event ras:arm_event
rasdaemon: Can't parse /proc/cpuinfo: missing [vendor_id] [cpu family] [model] [flags]
rasdaemon: Can't register mce handler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants