-
Notifications
You must be signed in to change notification settings - Fork 18
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
exfat driver may fail to write files with a size > 4GB when used in a 32bit kernel #32
Comments
Thanks for your suggestion! Can you send the patch to me ? |
Sure :)I've already left the office though, so I'll send you everything tomorrow.--Diese Nachricht wurde von meinem Android Mobiltelefon mit GMX Mail gesendet.Am 24.01.22, 17:00 schrieb Namjae Jeon ***@***.***>:
Thanks for your suggestion! Can you send the patch to me ?
—Reply to this email directly, view it on GitHub, or unsubscribe.Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you authored the thread.Message ID: ***@***.***>
|
@jerryatpb Okay! |
Ah, I can see this patch (https://patchwork.kernel.org/project/linux-block/patch/[email protected]/)
|
Our patch is based on your commit 1c014cb. Since it is really, really small I've simply attached it here. We're using Kernel version 4.14. |
The exfat driver fails to write files with a size > 4GB when these conditions are met:
We stumbled upon this when integrating the driver into our 32bit embedded Linux ecosystem.
The reason for this is an integer overflow when converting number of blocks into a file position, as for instance here:
https://github.com/namjaejeon/linux-exfat-oot/blob/5.14.1/inode.c#L338
Line:
pos = EXFAT_BLK_TO_B((iblock + 1), sb);
which translates to:
pos = (iblock + 1) << sb->s_blocksize_bits;
iblock
is of typesector_t
. Normally this is a 64bit integer, but on a 32bit system withoutCONFIG_LBDAF
being set, it is just 32bit.pos
, on the other hand is a full 64bit integerUnfortunately, the compiler performs the calculation in 32bit range without issuing a warning. As a result, an overflow will occur as soon as the file size reaches 4GB
A simple fix would be:
pos = EXFAT_BLK_TO_B((loff_t)(iblock + 1), sb);
This makes sure that the left side is cast to 64bit before shifting it.
Attention:
We've located a few more such lines where potentially 32bit-overflow-prone left-shifts are done, namely:
https://github.com/namjaejeon/linux-exfat-oot/blob/5.14.1/dir.c#L171
https://github.com/namjaejeon/linux-exfat-oot/blob/5.14.1/dir.c#L187
https://github.com/namjaejeon/linux-exfat-oot/blob/5.14.1/inode.c#L249
https://github.com/namjaejeon/linux-exfat-oot/blob/5.14.1/inode.c#L338
https://github.com/namjaejeon/linux-exfat-oot/blob/5.14.1/inode.c#L357
https://github.com/namjaejeon/linux-exfat-oot/blob/5.14.1/namei.c#L402
https://github.com/namjaejeon/linux-exfat-oot/blob/5.14.1/namei.c#L1292
https://github.com/namjaejeon/linux-exfat-oot/blob/5.14.1/super.c#L592
In general, all lines where types
sector_t
orblkcnt_t
are used with a left-shift operator should be considered.The text was updated successfully, but these errors were encountered: