Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1614171

Re: [PATCH v2] module: check if memory leak by module.

From Joel Fernandes <joelaf@google.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2] module: check if memory leak by module.
Date 2017-03-31 19:10 +0200
Message-ID <tr8dJ-7tj-31@gated-at.bofh.it> (permalink)
References (3 earlier) <tqjbc-5zA-35@gated-at.bofh.it> <tqjbc-5zA-33@gated-at.bofh.it> <tqk7g-6e9-15@gated-at.bofh.it> <tqYxI-10x-15@gated-at.bofh.it> <tqZN8-204-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Fri, Mar 31, 2017 at 1:00 AM, Michal Hocko <mhocko@kernel.org> wrote:
> On Thu 30-03-17 23:49:52, Joel Fernandes wrote:
>> Hi Michal,
>>
>> On Wed, Mar 29, 2017 at 3:43 AM, Michal Hocko <mhocko@kernel.org> wrote:
>> > On Wed 29-03-17 09:23:32, Vaneet Narang wrote:
>> >> Hi,
>> >>
>> >> >> Hmm, how can you track _all_ vmalloc allocations done on behalf of the
>> >> >> module? It is quite some time since I've checked kernel/module.c but
>> >> >> from my vague understading your check is basically only about statically
>> >> >> vmalloced areas by module loader. Is that correct? If yes then is this
>> >> >> actually useful? Were there any bugs in the loader code recently? What
>> >> >> led you to prepare this patch? All this should be part of the changelog!
>> >>
>> >> First of all there is no issue in kernel/module.c. This patch add functionality
>> >> to detect scenario where some kernel module does some memory allocation but gets
>> >> unloaded without doing vfree. For example
>> >> static int kernel_init(void)
>> >> {
>> >>         char * ptr = vmalloc(400 * 1024);
>> >>         return 0;
>> >> }
>> >
>> > How can you track that allocation back to the module? Does this patch
>> > actually works at all? Also why would be vmalloc more important than
>> > kmalloc allocations?
>>
>> Doesn't the patch use caller's (in this case, the module is the
>> caller) text address for tracking this? vma->vm->caller should track
>> the caller doing the allocation?
>
> Not really. First of all it will be vmalloc() to be tracked in the above
> the example because vmalloc is not inlined. And secondly even if the

vmalloc is not inlined, but __built_in_address(0) will return the
*return address* of vmalloc:

From https://gcc.gnu.org/onlinedocs/gcc-4.6.0/gcc/Return-Address.html :
"The level argument is number of frames to scan up the call stack. A
value of 0 yields the return address of the current function"

> caller of the vmalloc was tracked then it would be hopelessly
> insufficient because you would get coverage of the _direct_ module usage
> of vmalloc rather than anything that the module triggered and that is
> outside of the module. Which means any library function etc...

Yes true, but I think the check is for direct allocations, done by the
module, not indirect ones... it may not be a catch-all issues type of
deal but is still IMO a good check since we already have
va->vm->caller available.

Thanks,
Joel

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2] module: check if memory leak by module. Maninder Singh <maninder1.s@samsung.com> - 2017-03-29 08:10 +0200
  Re: [PATCH v2] module: check if memory leak by module. Michal Hocko <mhocko@kernel.org> - 2017-03-29 09:50 +0200
    Re: [PATCH v2] module: check if memory leak by module. Miroslav Benes <mbenes@suse.cz> - 2017-03-29 10:10 +0200
      Re: [PATCH v2] module: check if memory leak by module. Vaneet Narang <v.narang@samsung.com> - 2017-03-29 12:40 +0200
        Re: [PATCH v2] module: check if memory leak by module. Michal Hocko <mhocko@kernel.org> - 2017-03-29 13:40 +0200
          Re: [PATCH v2] module: check if memory leak by module. Joel Fernandes <joelaf@google.com> - 2017-03-31 08:50 +0200
            Re: [PATCH v2] module: check if memory leak by module. Michal Hocko <mhocko@kernel.org> - 2017-03-31 10:10 +0200
              Re: [PATCH v2] module: check if memory leak by module. Joel Fernandes <joelaf@google.com> - 2017-03-31 19:10 +0200
                Re: [PATCH v2] module: check if memory leak by module. Michal Hocko <mhocko@kernel.org> - 2017-04-03 09:30 +0200
        Re: [PATCH v2] module: check if memory leak by module. Jessica Yu <jeyu@redhat.com> - 2017-04-01 00:20 +0200
  Re: [PATCH v2] module: check if memory leak by module. Pavel Machek <pavel@ucw.cz> - 2017-03-30 15:40 +0200

csiph-web