[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKdAkRTFhSKLB40snpC_10adAPdqPkB_tu2Kg=cvo60H=O8=ww@mail.gmail.com>
Date: Wed, 2 Sep 2015 09:29:57 -0700
From: Dmitry Torokhov <dmitry.torokhov@...il.com>
To: Muni Sekhar <munisekharrms@...il.com>
Cc: lkml <linux-kernel@...r.kernel.org>
Subject: Re: kfree a pointer "from the middle" causing protection faults
On Wed, Sep 2, 2015 at 8:02 AM, Muni Sekhar <munisekharrms@...il.com> wrote:
> [ Please keep me in CC as I'm not subscribed to the list]
>
> Hello,
>
>
> I am getting protection faults in different kernel modules if I try to
> free a pointer "from the middle" for example, look at the following
> code:
>
>
> u8 *buf;
>
>
> buf = kzalloc( 100 , GFP_KERNEL );
>
> …
>
> buf = buf + 50;
>
> …
>
> Kfree(buf);
>
>
>
>
> I would like to know, why the above code is causing protection faults
> in other kernel modules?
Because you can not make a "hole" in returned memory like that, you
can only free entire block allocated by k*alloc and you need to pass
the original pointer in.
Thanks.
--
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists