From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ig0-f170.google.com (mail-ig0-f170.google.com [209.85.213.170]) by kanga.kvack.org (Postfix) with ESMTP id 20E716B0255 for ; Tue, 8 Sep 2015 11:33:28 -0400 (EDT) Received: by igxx6 with SMTP id x6so19291948igx.1 for ; Tue, 08 Sep 2015 08:33:28 -0700 (PDT) Received: from resqmta-ch2-12v.sys.comcast.net (resqmta-ch2-12v.sys.comcast.net. [2001:558:fe21:29:69:252:207:44]) by mx.google.com with ESMTPS id d71si3511810ioe.50.2015.09.08.08.33.27 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 08 Sep 2015 08:33:27 -0700 (PDT) Date: Tue, 8 Sep 2015 10:33:26 -0500 (CDT) From: Christoph Lameter Subject: Re: Is it OK to pass non-acquired objects to kfree? In-Reply-To: Message-ID: References: Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-linux-mm@kvack.org List-ID: To: Dmitry Vyukov Cc: Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , "linux-mm@kvack.org" , Andrey Konovalov , Alexander Potapenko , Paul McKenney On Tue, 8 Sep 2015, Dmitry Vyukov wrote: > Yes, this is a case of use-after-free bug. But the use-after-free can > happen only due to memory access reordering in a multithreaded > environment. > OK, here is a simpler code snippet: > > void *p; // = NULL > > // thread 1 > p = kmalloc(8); > > // thread 2 > void *r = READ_ONCE(p); > if (r != NULL) > kfree(r); > > I would expect that this is illegal code. Is my understanding correct? This should work. It could be a problem if thread 1 is touching the object. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org