From: Greg KH <gregkh@linuxfoundation.org>
To: "Sebastián Alba" <sebasjosue84@gmail.com>
Cc: linux-fpga@vger.kernel.org, yilun.xu@linux.intel.com,
conor.dooley@microchip.com, mdf@kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] fpga: dfl-afu: fix integer truncation of npages in afu_dma_pin_pages()
Date: Fri, 3 Apr 2026 13:16:51 +0200 [thread overview]
Message-ID: <2026040346-semicolon-catty-3f93@gregkh> (raw)
In-Reply-To: <CAJD=UNc06upxLFo5eNrvy-UvP1Cu6CEBt-csCgECxAK94pa8mg@mail.gmail.com>
Please reply inline with the real message, not just at the top...
On Thu, Apr 02, 2026 at 10:25:14AM -0600, Sebastián Alba wrote:
> On Thu, Apr 02, 2026 at 10:07:00AM, Greg KH wrote:
> > How can length be that large? You are shifting down, not up.
>
> region->length comes from userspace via the DFL_FPGA_PORT_DMA_MAP
> ioctl (struct dfl_fpga_port_dma_map.length, __u64). The only
> validation in afu_dma_map_region() is PAGE_ALIGNED and an overflow
> check (user_addr + length < user_addr), but there is no upper bound.
> So length >> PAGE_SHIFT can still exceed INT_MAX.
>
> > Why INT_MAX? SHouldn't this be much smaller?
>
> INT_MAX because pin_user_pages_fast() takes int nr_pages. But you
> are right, a practical limit should be much smaller. Happy to use a
> tighter cap if you have a preferred value, or I can base it on
> totalram_pages().
Ok, I think you should move back up the call chain, and for every ioctl,
properly validate ALL arguments before calling 3 levels deep into the
kernel afterwards, and just hope that the values you are passing around
then are actually valid.
Same for the firmware verification, that should all be done in one
place, before you start poking around in the image. Try to treat all
data coming from userspace, or a firmware image, as "unverified" and it
must be verified before it can cross the boundry to being trusted to do
anything with it.
I'm guessing you have access to some "bad" firmware images to test this
out with? This is a very odd driver, I doubt that anyone has thrown
any untrusted data at it before.
thanks,
greg k-h
next prev parent reply other threads:[~2026-04-03 11:16 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-02 12:54 [PATCH 1/3] fpga: dfl: add bounds check in dfh_get_param_size() Sebastian Alba Vives
2026-04-02 12:54 ` [PATCH 2/3] fpga: dfl-afu: fix integer truncation of npages in afu_dma_pin_pages() Sebastian Alba Vives
2026-04-02 16:07 ` Greg KH
[not found] ` <CAJD=UNc06upxLFo5eNrvy-UvP1Cu6CEBt-csCgECxAK94pa8mg@mail.gmail.com>
2026-04-03 11:16 ` Greg KH [this message]
2026-04-03 17:57 ` [PATCH v2] fpga: dfl-afu: validate DMA mapping length in afu_dma_map_region() Sebastian Alba Vives
2026-04-04 7:01 ` Greg KH
2026-04-07 14:17 ` [PATCH v3 2/3] " Sebastian Alba Vives
2026-04-02 12:54 ` [PATCH 3/3] fpga: microchip-spi: add bounds checks in mpf_ops_parse_header() Sebastian Alba Vives
2026-04-02 15:03 ` Conor Dooley
2026-04-02 15:16 ` Conor Dooley
2026-04-02 15:37 ` [PATCH v2] " Sebastian Alba Vives
2026-04-02 16:03 ` Greg KH
2026-04-02 16:06 ` Greg KH
2026-04-02 16:16 ` Conor Dooley
2026-04-02 16:23 ` [PATCH v3] " Sebastian Alba Vives
2026-04-07 10:44 ` Xu Yilun
2026-04-07 8:51 ` [PATCH 1/3] fpga: dfl: add bounds check in dfh_get_param_size() Xu Yilun
2026-04-07 14:05 ` [PATCH v2 " Sebastian Alba Vives
2026-04-07 14:06 ` [PATCH v2 2/3] fpga: dfl-afu: fix integer truncation of npages in afu_dma_pin_pages() Sebastian Alba Vives
2026-04-07 14:06 ` [PATCH v2 3/3] fpga: microchip-spi: add bounds checks in mpf_ops_parse_header() Sebastian Alba Vives
2026-04-07 16:43 ` Conor Dooley
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=2026040346-semicolon-catty-3f93@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=conor.dooley@microchip.com \
--cc=linux-fpga@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mdf@kernel.org \
--cc=sebasjosue84@gmail.com \
--cc=yilun.xu@linux.intel.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