<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Mar 4, 2016 at 5:01 AM, Navy Cheng <span dir="ltr"><<a href="mailto:navych@126.com" target="_blank">navych@126.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Fri, Mar 04, 2016 at 02:07:26AM -0500, <a href="mailto:Valdis.Kletnieks@vt.edu">Valdis.Kletnieks@vt.edu</a> wrote:<br>
> On Fri, 04 Mar 2016 13:02:02 +0800, Navy Cheng said:<br>
> > Hi,<br>
> ><br>
> > When I read the code of list_del(), I find LIST_POISON1 and LIST_POISON2:<br>
> ><br>
> > static inline void list_del(struct list_head *entry)<br>
> > {<br>
> > __list_del(entry->prev, entry->next);<br>
> > entry->next = LIST_POISON1;<br>
> > entry->prev = LIST_POISON2;<br>
> > }<br>
> ><br>
> > Why not set entry->next and entry->prev to NULL ?<br>
><br>
> To more easily detect different classes of list corruption, use-after-free, and<br>
> other programming errors. If ->next and ->prev are NULL, it may be the result<br>
> of following a bad pointer. If they're equal to POISON 1 and 2, you're almost<br>
> certainly looking at a once-valid pointer that is a use-after-free situation.<br>
> It's easy to end up pointing at a zeroed page. The chances of pointing at<br>
> some random data that happens to be POISON 1/2 is much lower.<br>
><br>
> See the code in lib/list_debug.c<br>
><br></div></div>
<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div><br></div><div>It's like when you find a pointer to 0xdeadbeef you will know that it is some uninitialized value which is more helpful in debugging. If its a NULL, it will be difficult to know if the pointer is uninitialized. </div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" rel="noreferrer" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</div></div></blockquote></div><br></div></div>