ntfs3: harden against integer overflows
Subsystems (2)
PATCH 1/1 ntfs3: harden against integer overflows
Smatch complains that the "add_bytes" is not to be trusted. Use size_add() to prevent an integer overflow.
---
The add_bytes variable comes from:
add = ALIGN(struct_size(ea_all, name, 1 + name_len + val_size), 4);
This is problematic and has inspired a new static checker warning:
fs/ntfs3/xattr.c:26 unpacked_ea_size() warn: using integer overflow function 'size_add()' for math fs/ntfs3/xattr.c:290 ntfs_set_ea() warn: using integer overflow function 'size_add()' for math
The issue is that the struct_size() has an integer overflow and we call ALIGN() on it, then "add" becomes zero. Is there a bounds check that we could use here?
add = struct_size(ea_all, name, 1 + name_len + val_size); if (add > SOMETHING_MAX) return -EINVAL;
Otherwise the limit would have to be if (add > ULONG_MAX - 3) { which is ugly.
fs/ntfs3/xattr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/xattr.c +1 -1
@@ -107,7 +107,7 @@ static int ntfs_read_ea(struct ntfs_inode *ni, struct EA_FULL **ea,return -EFBIG ;/* Allocate memory for packed Ea. */ - ea_p =kmalloc (size + add_bytes,GFP_NOFS ); + ea_p =kmalloc (size_add (size, add_bytes),GFP_NOFS );if (!ea_p)return -ENOMEM ;
Signature · 1 line
2.35.1
Quoted 34 lines · Dan Carpenter
Smatch complains that the "
add_bytes" is not to be trusted. Usesize_add()to prevent an integer overflow.Fixes be71b5cba2e6 ("fs/ntfs3: Add attrib operations")Signed-off-by Dan Carpenter <[email protected]>---
Theadd_bytesvariable comes from:add = ALIGN(struct_size(ea_all, name, 1 + name_len + val_size), 4);This is problematic and has inspired a new static checker warning:
fs/ntfs3/xattr.c:26unpacked_ea_size()warn: using integer overflow function 'size_add()' for mathfs/ntfs3/xattr.c:290ntfs_set_ea()warn: using integer overflow function 'size_add()' for mathThe issue is that the
struct_size()has an integer overflow and we callALIGN()on it, then "add" becomes zero. Is there a bounds check that we could use here?add = struct_size(ea_all, name, 1 + name_len + val_size); if (add > SOMETHING_MAX) return -EINVAL;Otherwise the limit would have to be if (add >
ULONG_MAX- 3) { which is ugly.fs/ntfs3/xattr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ntfs3/xattr.c +0
-0
fs/ntfs3/xattr.c static int ntfs_read_ea(struct ntfs_inode *ni, struct EA_FULL **ea, · line 113
Quoted 8 lines
fs/ntfs3/xattr.c +1
-1@@ -107,7 +107,7 @@ static int ntfs_read_ea(struct ntfs_inode *ni, struct EA_FULL **ea,return -EFBIG ;/* Allocate memory for packed Ea. */ - ea_p =kmalloc (size + add_bytes,GFP_NOFS ); + ea_p =kmalloc (size_add (size, add_bytes),GFP_NOFS );if (!ea_p)return -ENOMEM ;
Applied, thanks!