From: Alan Stern <stern@rowland.harvard.edu>
To: "Kirill A. Shutemov" <kirill@shutemov.name>
Cc: linux-mm@kvack.org,
Kernel development list <linux-kernel@vger.kernel.org>,
David Laight <David.Laight@ACULAB.COM>,
"'Steinar H. Gunderson'" <sesse@google.com>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: Re: Does vm_operations_struct require a .owner field?
Date: Tue, 5 Jan 2016 16:31:09 -0500 (EST) [thread overview]
Message-ID: <Pine.LNX.4.44L0.1601051619200.1350-100000@iolanthe.rowland.org> (raw)
In-Reply-To: <20160105205812.GA24738@node.shutemov.name>
On Tue, 5 Jan 2016, Kirill A. Shutemov wrote:
> On Tue, Jan 05, 2016 at 11:27:45AM -0500, Alan Stern wrote:
> > Hello:
> >
> > Question: The vm_operations_struct structure contains lots of callback
> > pointers. Is there any mechanism to prevent the callback routines and
> > the structure itself being unloaded from memory (if they are built into
> > modules) while the relevant VMAs are still in use?
> >
> > Consider a simple example: A user program calls mmap(2) on a device
> > file. Later on, the file is closed and the device driver's module is
> > unloaded. But until munmap(2) is called or the user program exits, the
> > memory mapping and the corresponding VMA will remain in existence.
> > (The man page for munmap specifically says "closing the file descriptor
> > does not unmap the region".) Thus when the user program does do an
> > munmap(), the callback to vma->vm_ops->close will reference nonexistent
> > memory and cause an oops.
> >
> > Normally this sort of thing is prevented by try_module_get(...->owner).
> > But vm_operations_struct doesn't include a .owner field.
> >
> > Am I missing something here?
>
> mmap(2) takes reference of the file, therefore the file is not closed from
> kernel POV until vma is gone and you cannot unload relevant module.
> See get_file() in mmap_region().
Thank you. So it looks like I was worried about nothing.
Steinar, you can remove the try_module_get/module_put lines from your
patch. Also, the list_del() and comment in usbdev_release() aren't
needed -- at that point we know the memory_list has to be empty since
there can't be any outstanding URBs or VMA references. If you take
those things out then the patch should be ready for merging.
Alan Stern
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2016-01-05 21:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Pine.LNX.4.44L0.1601051024110.1666-100000@iolanthe.rowland.org>
2016-01-05 16:27 ` Alan Stern
2016-01-05 20:58 ` Kirill A. Shutemov
2016-01-05 21:31 ` Alan Stern [this message]
2016-01-05 23:54 ` Steinar H. Gunderson
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=Pine.LNX.4.44L0.1601051619200.1350-100000@iolanthe.rowland.org \
--to=stern@rowland.harvard.edu \
--cc=David.Laight@ACULAB.COM \
--cc=kirill@shutemov.name \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-usb@vger.kernel.org \
--cc=sesse@google.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