Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 27 Jun 2019 13:45:06 +0200
From: Vegard Nossum <>
To: "Gote, Nitin R" <>
Cc: Kees Cook <>, 
	"" <>
Subject: Re: Regarding have kfree() (and related) set the pointer to NULL too

On Thu, 27 Jun 2019 at 12:23, Gote, Nitin R <> wrote:
> Hi,
> I’m looking  into “have kfree() (and related) set the pointer to NULL too” task.
> As per my understanding, I did below changes :
> Could you please provide some points on below ways ?
> @@ -3754,6 +3754,7 @@ void kfree(const void *objp)
>         debug_check_no_obj_freed(objp, c->object_size);
>         __cache_free(c, (void *)objp, _RET_IP_);
>         local_irq_restore(flags);
> +       objp = NULL;
> }

This will not do anything, since the assignment happens to the local
variable inside kfree() rather than to the original expression that
was passed to it as an argument.

Consider that the code in the caller looks like this:

void *x = kmalloc(...);
pr_info("x = %p\n", x);

this will still print "x = (some non-NULL address)" because the
variable 'x' in the caller still retains its original value.

You could try wrapping kfree() in a C macro, something like

#define kfree(x) real_kfree(x); (x) = NULL;

but using proper C macro best practices (like putting do {} while (0)
around it, etc.).

It's probably easier to play with this in a simple userspace program first.


Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.