From: Xu Yilun <yilun.xu@intel.com>
To: k1rh4.lee@gmail.com
Cc: Wu Hao <hao.wu@intel.com>, Tom Rix <trix@redhat.com>,
Moritz Fischer <mdf@kernel.org>,
linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fpga: dfl-afu-region: Add overflow checks for region size and offset
Date: Fri, 10 Feb 2023 16:21:37 +0800 [thread overview]
Message-ID: <Y+X+kZResf0a/aES@yilunxu-OptiPlex-7050> (raw)
In-Reply-To: <20230206054326.89323-1-k1rh4.lee@gmail.com>
On 2023-02-05 at 21:43:26 -0800, k1rh4.lee@gmail.com wrote:
> From: Sangsup Lee <k1rh4.lee@gmail.com>
>
> The size + offset is able to be integer overflow value and it lead to mis-allocate region.
But I didn't see the memory allocation.
>
> Signed-off-by: Sangsup Lee <k1rh4.lee@gmail.com>
> ---
> drivers/fpga/dfl-afu-region.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/fpga/dfl-afu-region.c b/drivers/fpga/dfl-afu-region.c
> index 2e7b41629406..82b530111601 100644
> --- a/drivers/fpga/dfl-afu-region.c
> +++ b/drivers/fpga/dfl-afu-region.c
> @@ -151,12 +151,17 @@ int afu_mmio_region_get_by_offset(struct dfl_feature_platform_data *pdata,
> struct dfl_afu_mmio_region *region;
> struct dfl_afu *afu;
> int ret = 0;
> + u64 region_size = 0;
Reverse Xmax tree please.
>
> mutex_lock(&pdata->lock);
> + if (check_add_overflow(offset, size, ®ion_size)) {
I'm not sure if the check is necessary.
The offset comes from: offset = vma->vm_pgoff << PAGE_SHIFT
The size comes from: size = vma->vm_end - vma->vm_start
Is it possible the upper mm layer passes invalid vma?
Thanks,
Yilun
> + ret = -EINVAL;
> + goto exit;
> + }
> afu = dfl_fpga_pdata_get_private(pdata);
> for_each_region(region, afu)
> if (region->offset <= offset &&
> - region->offset + region->size >= offset + size) {
> + region->offset + region->size >= region_size) {
> *pregion = *region;
> goto exit;
> }
> --
> 2.25.1
>
next prev parent reply other threads:[~2023-02-10 8:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-06 5:43 k1rh4.lee
2023-02-06 16:50 ` Russ Weight
2023-02-10 8:21 ` Xu Yilun [this message]
2023-04-09 19:00 ` Salvatore Bonaccorso
2023-04-10 2:17 ` sangsup lee
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=Y+X+kZResf0a/aES@yilunxu-OptiPlex-7050 \
--to=yilun.xu@intel.com \
--cc=hao.wu@intel.com \
--cc=k1rh4.lee@gmail.com \
--cc=linux-fpga@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mdf@kernel.org \
--cc=trix@redhat.com \
/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
all inboxes | Powered by JetHome®