[LU-6174] do_div() silently truncates divisor to uint32_t Created: 29/Jan/15 Updated: 25/Oct/23 Resolved: 25/Oct/23 |
|
| Status: | Resolved |
| Project: | Lustre |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | Lustre 2.16.0 |
| Type: | Bug | Priority: | Major |
| Reporter: | Isaac Huang (Inactive) | Assignee: | James A Simmons |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||||||
| Severity: | 3 | ||||||||||||||||
| Rank (Obsolete): | 17275 | ||||||||||||||||
| Description |
|
The Linux do_div() silently truncates divisor to uint32_t, even on x86_64:
25 # define do_div(n,base) ({ \
26 uint32_t __base = (base);
Any code that uses 64-bit divisor will end up with incorrect result whenever the higher 32 bits aren't all zero. And when the lower 32 bits are all zero, it will end up with a division by zero error. It happens on both x86_64 and i686. I've verified it on a x86_64 VM. So any code that looks like the following is BAD:
uint64_t foo, bar;
......
if (bar != 0)
do_div(foo, bar);
There seemed to be plenty of such code in Lustre, e.g.:
void fld_cache_fini(struct fld_cache *cache)
__u64 pct;
......
if (cache->fci_stat.fst_count > 0) {
pct = cache->fci_stat.fst_cache * 100;
do_div(pct, cache->fci_stat.fst_count);
I'd suggest to go through and verify all callers of do_div(). In addition, it'd be good to add a warning on do_div() in our patch checker script. |
| Comments |
| Comment by Oleg Drokin [ 02/Feb/15 ] |
|
Did some existing bug in lustre prompted this? Is there a patch? where? |
| Comment by Isaac Huang (Inactive) [ 06/Feb/15 ] |
|
I just happened to notice that the divisor was silently truncated, and grep'ed through Lustre code and found a few vulnerable places. There's no existing bug as far as I know, but it does look like something that may cause us trouble in the future. |
| Comment by James A Simmons [ 07/Mar/16 ] |
|
If the divisor is u64 then the correct function to use is div64_u64_rem() which is in math64.h. We will have to do a code audit for this. |
| Comment by Gerrit Updater [ 13/Nov/19 ] |
|
James Simmons (jsimmons@infradead.org) uploaded a new patch: https://review.whamcloud.com/36749 |
| Comment by Gerrit Updater [ 13/Nov/19 ] |
|
James Simmons (jsimmons@infradead.org) uploaded a new patch: https://review.whamcloud.com/36750 |
| Comment by Gerrit Updater [ 13/Nov/19 ] |
|
James Simmons (jsimmons@infradead.org) uploaded a new patch: https://review.whamcloud.com/36751 |
| Comment by Gerrit Updater [ 14/Dec/19 ] |
|
Oleg Drokin (green@whamcloud.com) merged in patch https://review.whamcloud.com/36751/ |
| Comment by Gerrit Updater [ 17/Mar/20 ] |
|
Oleg Drokin (green@whamcloud.com) merged in patch https://review.whamcloud.com/36749/ |
| Comment by Gerrit Updater [ 24/Mar/20 ] |
|
Oleg Drokin (green@whamcloud.com) merged in patch https://review.whamcloud.com/36750/ |
| Comment by Peter Jones [ 24/Mar/20 ] |
|
Seems to be complete for 2.14 |
| Comment by James A Simmons [ 24/Mar/20 ] |
|
Only thing I can see left is the lov / lod handling. |
| Comment by Gerrit Updater [ 30/Mar/20 ] |
|
James Simmons (jsimmons@infradead.org) uploaded a new patch: https://review.whamcloud.com/38101 |
| Comment by James A Simmons [ 01/Apr/20 ] |
|
Just lov layer needs to be fixed but it needs a more complex solution. |
| Comment by Gerrit Updater [ 07/Apr/20 ] |
|
Oleg Drokin (green@whamcloud.com) merged in patch https://review.whamcloud.com/38101/ |
| Comment by Gerrit Updater [ 13/Jul/20 ] |
|
James Simmons (jsimmons@infradead.org) uploaded a new patch: https://review.whamcloud.com/39343 |
| Comment by Andreas Dilger [ 08/Apr/21 ] |
|
The new test_54c in patch https://review.whamcloud.com/43230 " |
| Comment by Andreas Dilger [ 09/Apr/21 ] |
|
It probably makes sense to further improve the |
| Comment by Gerrit Updater [ 18/Jan/22 ] |
|
"Etienne AUJAMES <eaujames@ddn.com>" uploaded a new patch: https://review.whamcloud.com/46164 |
| Comment by Gerrit Updater [ 25/Oct/23 ] |
|
"Oleg Drokin <green@whamcloud.com>" merged in patch https://review.whamcloud.com/c/fs/lustre-release/+/39343/ |
| Comment by Peter Jones [ 25/Oct/23 ] |
|
Is this body of work now complete - or is more work needed? |
| Comment by James A Simmons [ 25/Oct/23 ] |
|
It is finally complete!!!! |