fs/erofs: fix an integer overflow in symlink resolution
PATCH 1/1 fs/erofs: fix an integer overflow in symlink resolution
See the original report [1], otherwise len + 1 will be overflowed.
Note that EROFS archive can record arbitary symlink sizes in principle, so we don't assume a short number like 4096.
[1] https://lore.kernel.org/r/20250210164151.GN1233568@bill-the-cat
--- fs/erofs/fs.c | 3 +++ 1 file changed, 3 insertions(+)
fs/erofs/fs.c +3 -0
@@ -63,6 +63,9 @@ static int erofs_readlink(struct erofs_inode *vi)char *target;int err; +if (len >=SIZE_MAX ) +return -EFSCORRUPTED ; + target =malloc (len +1 );if (!target)return -ENOMEM ;
Signature · 1 line
2.43.5
This is good, but may I suggest using __builtin_add_overflow instead?
Jonathan
Quoted 30 lines · Gao Xiang
See the original report [1], otherwise len + 1 will be overflowed.
Note that EROFS archive can record arbitary symlink sizes in principle, so we don't assume a short number like 4096.
[1] https://lore.kernel.org/r/20250210164151.GN1233568@bill-the-cat
Fixes 830613f8f5bb ("fs/erofs: add erofs filesystem support")Signed-off-by Gao Xiang <[email protected]>--- fs/erofs/fs.c | 3 +++ 1 file changed, 3 insertions(+)fs/erofs/fs.c +3
-1@@ -63,6 +63,9 @@ static int erofs_readlink(struct erofs_inode *vi)char *target;int err; +if (len >=SIZE_MAX ) +return -EFSCORRUPTED ; + target =malloc (len +1 );if (!target)return -ENOMEM ; --2.43.5
Quoted 1 line · Jonathan Bar Or
This is good, but may I suggest using
__builtin_add_overflowinstead?
They are just the same.
erofs-utils follows the kernel style, mostly the kernel doesn't directly use __builtin_add_overflow, instead it has a wrapper check_add_overflow().
I could use __builtin_add_overflow for u-boot only.
Thanks,
Gao Xiang
Quoted 3 lines
Jonathan
Got it, looks good.
Jonathan
Quoted 20 lines · Gao Xiang
Quoted 1 line · Jonathan Bar Or
This is good, but may I suggest using
__builtin_add_overflowinstead?They are just the same.
erofs-utils follows the kernel style, mostly the kernel doesn't directly use
__builtin_add_overflow, instead it has a wrappercheck_add_overflow().I could use
__builtin_add_overflowfor u-boot only.Thanks,
Gao XiangQuoted 3 lines
Jonathan