From: Bodo Stroesser <bostroesser@gmail.com>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Douglas Gilbert <dgilbert@interlog.com>,
linux-scsi@vger.kernel.org, martin.petersen@oracle.com,
jejb@linux.vnet.ibm.com, hare@suse.de, bvanassche@acm.org
Subject: Re: [PATCH 1/5] sgl_alloc_order: remove 4 GiB limit
Date: Tue, 25 Oct 2022 12:46:55 +0200 [thread overview]
Message-ID: <78357696-d9aa-71a0-8cee-0fadbc90655f@gmail.com> (raw)
In-Reply-To: <Y1bMKU5nq5DXYdbw@ziepe.ca>
On 24.10.22 19:32, Jason Gunthorpe wrote:
> On Mon, Oct 24, 2022 at 04:32:30PM +0200, Bodo Stroesser wrote:
>>> +struct scatterlist *sgl_alloc_order(size_t length, unsigned int order,
>>> + bool chainable, gfp_t gfp, size_t *nent_p)
>>> {
>>> struct scatterlist *sgl, *sg;
>>> struct page *page;
>>> - unsigned int nent, nalloc;
>>> + size_t nent, nalloc;
>>> u32 elem_len;
>>> - nent = round_up(length, PAGE_SIZE << order) >> (PAGE_SHIFT + order);
>>> - /* Check for integer overflow */
>>> - if (length > (nent << (PAGE_SHIFT + order)))
>>> - return NULL;
>>> + nent = length >> (PAGE_SHIFT + order);
>>> + if (length % (1 << (PAGE_SHIFT + order)))
>>
>> This might end up doing a modulo operation for divisor 0, if caller
>> specifies a too high order parameter, right?
>
> If that happens then the first >> will be busted too and this is all
> broken..
>
> We assume the caller will pass a valid order paramter it seems, it is
> not userspace controlled.
>
If a too high order is passed, alloc_pages will just return NULL, so
in the old code sgl_alloc_order simply returns NULL. Using modulo op
changes it to possibly crashing the system.
Bodo
next prev parent reply other threads:[~2022-10-25 10:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-24 1:02 [PATCH 0/5] scatterlist: add operations for scsi_debug Douglas Gilbert
2022-10-24 1:02 ` [PATCH 1/5] sgl_alloc_order: remove 4 GiB limit Douglas Gilbert
2022-10-24 12:21 ` Jason Gunthorpe
2022-10-24 14:32 ` Bodo Stroesser
2022-10-24 17:32 ` Jason Gunthorpe
2022-10-24 19:58 ` Douglas Gilbert
2022-10-25 12:19 ` Jason Gunthorpe
2022-10-25 10:46 ` Bodo Stroesser [this message]
2022-10-25 12:18 ` Jason Gunthorpe
2022-10-24 1:02 ` [PATCH 2/5] scatterlist: add sgl_copy_sgl() function Douglas Gilbert
2022-10-24 1:02 ` [PATCH 3/5] scatterlist: add sgl_equal_sgl() function Douglas Gilbert
2022-10-24 1:02 ` [PATCH 4/5] scatterlist: add sgl_memset() Douglas Gilbert
2022-10-24 1:02 ` [PATCH 5/5] scsi_debug: change store from vmalloc to sgl Douglas Gilbert
2022-10-24 15:08 ` Bodo Stroesser
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=78357696-d9aa-71a0-8cee-0fadbc90655f@gmail.com \
--to=bostroesser@gmail.com \
--cc=bvanassche@acm.org \
--cc=dgilbert@interlog.com \
--cc=hare@suse.de \
--cc=jejb@linux.vnet.ibm.com \
--cc=jgg@ziepe.ca \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.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