Commit 9671081
hwmon: (vt1211) Convert macros to functions to avoid TOCTOU
The macros IN_FROM_REG, TEMP_FROM_REG, and RPM_FROM_REG evaluate their
arguments multiple times. These macros are used in lockless show functions
involving shared driver data, leading to Time-of-Check to Time-of-Use race
conditions.
For example, RPM_FROM_REG checks if a value is 0 or 255, and then uses it
in a division. If the value is modified by another thread to 0 after the
check but before the division, it causes a divide-by-zero error.
Convert these macros to static functions. This guarantees that arguments
are evaluated only once (pass-by-value), fixing the race conditions.
Adhere to the principle of minimal changes by only converting the specific
macros involved in these lockless contexts.
Link: https://lore.kernel.org/all/CALbr=LYJ_ehtp53HXEVkSpYoub+XYSTU8Rg=o1xxMJ8=5z8B-g@mail.gmail.com/
Signed-off-by: Gui-Dong Han <hanguidong02@gmail.com>
Link: https://lore.kernel.org/r/20251120041331.1917570-1-hanguidong02@gmail.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>1 parent d56933e commit 9671081
1 file changed
Lines changed: 35 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
146 | | - | |
147 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
148 | 154 | | |
149 | 155 | | |
150 | 156 | | |
| |||
156 | 162 | | |
157 | 163 | | |
158 | 164 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
163 | 174 | | |
164 | 175 | | |
165 | 176 | | |
166 | 177 | | |
167 | 178 | | |
168 | 179 | | |
169 | 180 | | |
170 | | - | |
171 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
172 | 189 | | |
173 | 190 | | |
174 | 191 | | |
| |||
343 | 360 | | |
344 | 361 | | |
345 | 362 | | |
346 | | - | |
| 363 | + | |
347 | 364 | | |
348 | 365 | | |
349 | | - | |
| 366 | + | |
350 | 367 | | |
351 | 368 | | |
352 | | - | |
| 369 | + | |
353 | 370 | | |
354 | 371 | | |
355 | 372 | | |
| |||
417 | 434 | | |
418 | 435 | | |
419 | 436 | | |
420 | | - | |
| 437 | + | |
421 | 438 | | |
422 | 439 | | |
423 | | - | |
| 440 | + | |
424 | 441 | | |
425 | 442 | | |
426 | | - | |
| 443 | + | |
427 | 444 | | |
428 | 445 | | |
429 | 446 | | |
| |||
493 | 510 | | |
494 | 511 | | |
495 | 512 | | |
496 | | - | |
| 513 | + | |
497 | 514 | | |
498 | 515 | | |
499 | | - | |
| 516 | + | |
500 | 517 | | |
501 | 518 | | |
502 | 519 | | |
| |||
751 | 768 | | |
752 | 769 | | |
753 | 770 | | |
754 | | - | |
| 771 | + | |
755 | 772 | | |
756 | 773 | | |
757 | 774 | | |
| |||
0 commit comments