From: Maurizio Lombardi <mlombard@redhat.com>
To: Alexander Duyck <alexander.duyck@gmail.com>
Cc: 愚树 <chen45464546@163.com>, "Jakub Kicinski" <kuba@kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
linux-mm <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>,
Netdev <netdev@vger.kernel.org>
Subject: Re: Re: [PATCH v2] mm: page_frag: Warn_on when frag_alloc size is bigger than PAGE_SIZE
Date: Wed, 6 Jul 2022 17:21:31 +0200 [thread overview]
Message-ID: <CAFL455=bAEXeyUPjDPZm-hK-K8aKJSw7wRQ0CCYoKWO8VMJUqw@mail.gmail.com> (raw)
In-Reply-To: <CAKgT0UdoGJ_dG9vZ3aqQhTagCGf_J3H9A8yJbO5mWCgrt6vd4Q@mail.gmail.com>
st 1. 6. 2022 v 17:05 odesílatel Alexander Duyck
<alexander.duyck@gmail.com> napsal:
> > diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> > index e6f211d..ac60a97 100644
> > --- a/mm/page_alloc.c
> > +++ b/mm/page_alloc.c
> > @@ -5580,6 +5580,7 @@ void *page_frag_alloc_align(struct page_frag_cache *nc,
> > /* reset page count bias and offset to start of new frag */
> > nc->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1;
> > offset = size - fragsz;
> > + BUG_ON(offset < 0);
> > }
> >
> > nc->pagecnt_bias--;
> >
>
>
> I think I could be onboard with a patch like this. The test shouldn't
> add more than 1 instruction since it is essentially just a jump if
> signed test which will be performed after the size - fragsz check.
FYI, I hit this problem a few days ago with the nfp network driver, it uses
page_frag_alloc() with a frag size larger than PAGE_SIZE when MTU is
set to 9000,
this may result in memory corruptions when the system runs out of memory.
The solution I was working on was something like the following, this
makes the allocation
fail if fragsz is greater than the cache size.
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 4dc0d333279f..c6b40b85c55d 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5544,12 +5544,17 @@ void *page_frag_alloc_align(struct page_frag_cache *nc,
/* if size can vary use size else just use PAGE_SIZE */
size = nc->size;
#endif
- /* OK, page count is 0, we can safely set it */
- set_page_count(page, PAGE_FRAG_CACHE_MAX_SIZE + 1);
-
/* reset page count bias and offset to start of new frag */
nc->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1;
offset = size - fragsz;
+ if (unlikely(offset < 0)) {
+ free_the_page(page, compound_order(page));
+ nc->va = NULL;
+ return NULL;
+ }
+
+ /* OK, page count is 0, we can safely set it */
+ set_page_count(page, PAGE_FRAG_CACHE_MAX_SIZE + 1);
}
nc->pagecnt_bias--;
Maurizio
next prev parent reply other threads:[~2022-07-06 15:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-28 15:39 [PATCH] mm: page_frag: Warn_on when frag_alloc size is bigger than PAGE_SIZE Chen Lin
2022-05-29 23:30 ` Andrew Morton
[not found] ` <1653917942-5982-1-git-send-email-chen45464546@163.com>
2022-05-30 19:27 ` [PATCH v2] " Jakub Kicinski
2022-05-30 19:29 ` Jakub Kicinski
2022-05-31 14:41 ` Chen Lin
2022-05-31 15:14 ` Jakub Kicinski
2022-05-31 15:36 ` Chen Lin
2022-05-31 15:47 ` Jakub Kicinski
2022-05-31 18:28 ` Alexander Duyck
2022-06-01 12:32 ` 愚树
2022-06-01 15:04 ` Alexander Duyck
2022-07-06 15:21 ` Maurizio Lombardi [this message]
2022-05-30 20:07 ` Andrew Morton
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='CAFL455=bAEXeyUPjDPZm-hK-K8aKJSw7wRQ0CCYoKWO8VMJUqw@mail.gmail.com' \
--to=mlombard@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.duyck@gmail.com \
--cc=chen45464546@163.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).