From: Paulo Alcantara <pc@manguebit.com>
To: David Howells <dhowells@redhat.com>, Steve French <smfrench@gmail.com>
Cc: David Howells <dhowells@redhat.com>,
Shyam Prasad N <nspmangalore@gmail.com>,
Rohith Surabattula <rohiths.msft@gmail.com>,
Tom Talpey <tom@talpey.com>, Stefan Metzmacher <metze@samba.org>,
Jeff Layton <jlayton@kernel.org>,
linux-cifs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org,
Murphy Zhou <jencce.kernel@gmail.com>,
Steve French <sfrench@samba.org>
Subject: Re: [PATCH 1/1] cifs: Fix memory leak in direct I/O
Date: Wed, 01 Mar 2023 12:11:09 -0300 [thread overview]
Message-ID: <07171afd91dbd05b425d92e54f9832f9.pc@manguebit.com> (raw)
In-Reply-To: <20230228223838.3794807-2-dhowells@redhat.com>
David Howells <dhowells@redhat.com> writes:
> When __cifs_readv() and __cifs_writev() extract pages from a user-backed
> iterator into a BVEC-type iterator, they set ->bv_need_unpin to note
> whether they need to unpin the pages later. However, in both cases they
> examine the BVEC-type iterator and not the source iterator - and so
> bv_need_unpin doesn't get set and the pages are leaked.
>
> I think this may be responsible for the generic/208 xfstest failing
> occasionally with:
>
> WARNING: CPU: 0 PID: 3064 at mm/gup.c:218 try_grab_page+0x65/0x100
> RIP: 0010:try_grab_page+0x65/0x100
> follow_page_pte+0x1a7/0x570
> __get_user_pages+0x1a2/0x650
> __gup_longterm_locked+0xdc/0xb50
> internal_get_user_pages_fast+0x17f/0x310
> pin_user_pages_fast+0x46/0x60
> iov_iter_extract_pages+0xc9/0x510
> ? __kmalloc_large_node+0xb1/0x120
> ? __kmalloc_node+0xbe/0x130
> netfs_extract_user_iter+0xbf/0x200 [netfs]
> __cifs_writev+0x150/0x330 [cifs]
> vfs_write+0x2a8/0x3c0
> ksys_pwrite64+0x65/0xa0
>
> with the page refcount going negative. This is less unlikely than it seems
> because the page is being pinned, not simply got, and so the refcount
> increased by 1024 each time, and so only needs to be called around ~2097152
> for the refcount to go negative.
>
> Further, the test program (aio-dio-invalidate-failure) uses a 32MiB static
> buffer and all the PTEs covering it refer to the same page because it's
> never written to.
>
> The warning in try_grab_page():
>
> if (WARN_ON_ONCE(folio_ref_count(folio) <= 0))
> return -ENOMEM;
>
> then trips and prevents us ever using the page again for DIO at least.
>
> Fixes: d08089f649a0 ("cifs: Change the I/O paths to use an iterator rather than a page list")
> Reported-by: Murphy Zhou <jencce.kernel@gmail.com>
> Link: https://lore.kernel.org/r/CAH2r5mvaTsJ---n=265a4zqRA7pP+o4MJ36WCQUS6oPrOij8cw@mail.gmail.com
> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: Steve French <sfrench@samba.org>
> cc: Shyam Prasad N <nspmangalore@gmail.com>
> cc: Rohith Surabattula <rohiths.msft@gmail.com>
> cc: Paulo Alcantara <pc@cjr.nz>
> cc: Jeff Layton <jlayton@kernel.org>
> cc: linux-cifs@vger.kernel.org
> ---
> fs/cifs/file.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Paulo Alcantara (SUSE) <pc@manguebit.com>
next prev parent reply other threads:[~2023-03-01 15:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-28 22:38 [PATCH 0/1] smb3: Memory leak/page refcount overflow fix David Howells
2023-02-28 22:38 ` [PATCH 1/1] cifs: Fix memory leak in direct I/O David Howells
2023-03-01 14:54 ` Steve French
2023-03-01 15:11 ` Paulo Alcantara [this message]
2023-03-01 18:24 ` Steve French
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=07171afd91dbd05b425d92e54f9832f9.pc@manguebit.com \
--to=pc@manguebit.com \
--cc=dhowells@redhat.com \
--cc=jencce.kernel@gmail.com \
--cc=jlayton@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=metze@samba.org \
--cc=nspmangalore@gmail.com \
--cc=rohiths.msft@gmail.com \
--cc=sfrench@samba.org \
--cc=smfrench@gmail.com \
--cc=tom@talpey.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