From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: <ntfs3@lists.linux.dev>, <kernel-janitors@vger.kernel.org>
Subject: Re: [PATCH] ntfs3: harden against integer overflows
Date: Fri, 30 Sep 2022 19:07:34 +0300 [thread overview]
Message-ID: <97ee7bbe-652f-e0f5-1ffe-06eb3a32d1aa@paragon-software.com> (raw)
In-Reply-To: <YxIGoOgUtaUP59FK@kili>
On 9/12/22 18:08, Dan Carpenter wrote:
> Smatch complains that the "add_bytes" is not to be trusted. Use
> size_add() to prevent an integer overflow.
>
> Fixes: be71b5cba2e6 ("fs/ntfs3: Add attrib operations")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> 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(-)
>
> diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c
> index 7de8718c68a9..ea582b4fe1d9 100644
> --- a/fs/ntfs3/xattr.c
> +++ b/fs/ntfs3/xattr.c
> @@ -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!
prev parent reply other threads:[~2022-09-30 16:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-12 15:08 [PATCH] ntfs3: harden against integer overflows Dan Carpenter
2022-09-30 16:07 ` Konstantin Komarov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=97ee7bbe-652f-e0f5-1ffe-06eb3a32d1aa@paragon-software.com \
--to=almaz.alexandrovich@paragon-software.com \
--cc=dan.carpenter@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=ntfs3@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox