All of lore.kernel.org
 help / color / mirror / Atom feed
* dynamically allocating memory in the kernel
@ 2018-12-05 20:46 Carter Cheng
  2018-12-05 23:00 ` Kees Cook
  2018-12-09  0:30 ` Sandy Harris
  0 siblings, 2 replies; 4+ messages in thread
From: Carter Cheng @ 2018-12-05 20:46 UTC (permalink / raw)
  To: kernel-hardening

[-- Attachment #1: Type: text/plain, Size: 512 bytes --]

Hello,

I was wondering if someone here could help me understand something about
the kernel for a project I am working on tracking dynamically allocated
memory. How many ways are there to dynamically allocate memory in the
kernel presently? I know of 4.

get_free_pages family of functions
kmalloc family (including vmalloc)
slab allocation
mempools.

Are there others? I am trying to track them all down so I have
comprehensively know when all allocations occur and all "frees".

Thanks for your help,

Carter.

[-- Attachment #2: Type: text/html, Size: 696 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: dynamically allocating memory in the kernel
  2018-12-05 20:46 dynamically allocating memory in the kernel Carter Cheng
@ 2018-12-05 23:00 ` Kees Cook
  2018-12-06  1:51   ` Carter Cheng
  2018-12-09  0:30 ` Sandy Harris
  1 sibling, 1 reply; 4+ messages in thread
From: Kees Cook @ 2018-12-05 23:00 UTC (permalink / raw)
  To: Carter Cheng; +Cc: Kernel Hardening

On Wed, Dec 5, 2018 at 12:46 PM Carter Cheng <cartercheng@gmail.com> wrote:
>
> Hello,
>
> I was wondering if someone here could help me understand something about the kernel for a project I am working on tracking dynamically allocated memory. How many ways are there to dynamically allocate memory in the kernel presently? I know of 4.
>
> get_free_pages family of functions
> kmalloc family (including vmalloc)

vmalloc is quite different from kmalloc (see below).

> slab allocation

kmalloc is a type of slab allocation, so the base parts are the same.

> mempools.
>
> Are there others? I am trying to track them all down so I have comprehensively know when all allocations occur and all "frees".

I would recommend looking at KASAN hooks (which tracks use-after-free)
to see if there are any areas you're missing.

-Kees

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: dynamically allocating memory in the kernel
  2018-12-05 23:00 ` Kees Cook
@ 2018-12-06  1:51   ` Carter Cheng
  0 siblings, 0 replies; 4+ messages in thread
From: Carter Cheng @ 2018-12-06  1:51 UTC (permalink / raw)
  To: Kees Cook; +Cc: kernel-hardening

[-- Attachment #1: Type: text/plain, Size: 1001 bytes --]

Thanks, I'll check them out.

On Thu, Dec 6, 2018 at 7:01 AM Kees Cook <keescook@chromium.org> wrote:

> On Wed, Dec 5, 2018 at 12:46 PM Carter Cheng <cartercheng@gmail.com>
> wrote:
> >
> > Hello,
> >
> > I was wondering if someone here could help me understand something about
> the kernel for a project I am working on tracking dynamically allocated
> memory. How many ways are there to dynamically allocate memory in the
> kernel presently? I know of 4.
> >
> > get_free_pages family of functions
> > kmalloc family (including vmalloc)
>
> vmalloc is quite different from kmalloc (see below).
>
> > slab allocation
>
> kmalloc is a type of slab allocation, so the base parts are the same.
>
> > mempools.
> >
> > Are there others? I am trying to track them all down so I have
> comprehensively know when all allocations occur and all "frees".
>
> I would recommend looking at KASAN hooks (which tracks use-after-free)
> to see if there are any areas you're missing.
>
> -Kees
>
> --
> Kees Cook
>

[-- Attachment #2: Type: text/html, Size: 1440 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: dynamically allocating memory in the kernel
  2018-12-05 20:46 dynamically allocating memory in the kernel Carter Cheng
  2018-12-05 23:00 ` Kees Cook
@ 2018-12-09  0:30 ` Sandy Harris
  1 sibling, 0 replies; 4+ messages in thread
From: Sandy Harris @ 2018-12-09  0:30 UTC (permalink / raw)
  To: cartercheng, kernel-hardening

On Thu, Dec 6, 2018 at 4:46 AM Carter Cheng <cartercheng@gmail.com> wrote:

> I was wondering if someone here could help me understand something about the kernel for a project I am working on tracking dynamically allocated memory. How many ways are there to dynamically allocate memory in the kernel presently? I know of 4.
>
> get_free_pages family of functions
> kmalloc family (including vmalloc)
> slab allocation
> mempools.
>
> Are there others? I am trying to track them all down so I have comprehensively know when all allocations occur and all "frees".

You should also look at uses of alloca(3) which dynamically allocates
memory on the stack, automatically freed when the function returns.
Some programmers prefer this to other methods, mainly because it
reduces chances of unfreed memory creating memory leaks. Others
dislike it because it is not in any C standard (I think it was
originally a GNU extension but some other compilers now support it) so
it may limit portability. Some consider it dangerous because some
usages (e.g. in a recursive function) may grow a huge stack; I am not
sure how this interacts with kernel limits on stack size.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-12-09  0:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-05 20:46 dynamically allocating memory in the kernel Carter Cheng
2018-12-05 23:00 ` Kees Cook
2018-12-06  1:51   ` Carter Cheng
2018-12-09  0:30 ` Sandy Harris

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.