From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: linux-sparse@vger.kernel.org
Subject: Re: [PATCH] ptrlist: use after free in last_ptr_list()
Date: Wed, 2 Nov 2016 13:48:45 +0100 [thread overview]
Message-ID: <20161102124844.GA12544@macbook.home> (raw)
In-Reply-To: <20160613094517.GA25301@mwanda>
On Mon, Jun 13, 2016 at 12:45:17PM +0300, Dan Carpenter wrote:
> This change is similar to 2e7dd34d11cb ('ptrlist: reading deleted items
> in NEXT_PTR_LIST()'). If we use DELETE_CURRENT_PTR() then we can end up
> with a list->nr that is zero meaning that we have to go back another
> list->prev to find what we want. Otherwise we dereference 0xf0f0f0f0
> and crash.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> ptrlist.h | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/ptrlist.h b/ptrlist.h
> index 61e159f..6f90c8f 100644
> --- a/ptrlist.h
> +++ b/ptrlist.h
> @@ -78,6 +78,8 @@ static inline void *last_ptr_list(struct ptr_list *list)
> if (!list)
> return NULL;
> list = list->prev;
> + while (list->nr == 0)
> + list = list->prev;
> return PTR_ENTRY(list, list->nr-1);
> }
>
> --
Hi,
while trying to find a test case for this one, I noticed that something
as simple as:
void rem_rev(struct vpl *list)
{
void *last;
void *ptr;
FOR_EACH_PTR_REVERSE(list, ptr) {
DELETE_CURRENT_PTR(ptr);
last = last_ptr_list((struct ptr_list *)list);
} END_FOR_EACH_PTR_REVERSE(ptr);
}
loops forever on a list with 1 element with your patch.
Without your patch, last_ptr_list() return an invalid pointer instead of NULL.
So, I don't think your patch is the right solution but, yes somethings
should be done about this.
Cheers,
Luc Van Oostenryck
next prev parent reply other threads:[~2016-11-02 12:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-13 9:45 [PATCH] ptrlist: use after free in last_ptr_list() Dan Carpenter
2016-11-02 12:48 ` Luc Van Oostenryck [this message]
2016-11-02 14:52 ` Christopher Li
2016-11-02 15:23 ` Luc Van Oostenryck
2016-11-04 10:44 ` Luc Van Oostenryck
2016-11-05 0:30 ` Christopher Li
2016-11-06 8:49 ` Luc Van Oostenryck
2016-11-07 10:00 ` Luc Van Oostenryck
2016-11-16 22:46 ` Christopher Li
2016-11-16 23:22 ` Luc Van Oostenryck
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=20161102124844.GA12544@macbook.home \
--to=luc.vanoostenryck@gmail.com \
--cc=dan.carpenter@oracle.com \
--cc=linux-sparse@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).