From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io0-f175.google.com (mail-io0-f175.google.com [209.85.223.175]) by kanga.kvack.org (Postfix) with ESMTP id 926346B0038 for ; Wed, 9 Sep 2015 10:03:02 -0400 (EDT) Received: by ioiz6 with SMTP id z6so22894283ioi.2 for ; Wed, 09 Sep 2015 07:03:02 -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 17si4218395iom.144.2015.09.09.07.02.58 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 09 Sep 2015 07:02:58 -0700 (PDT) Date: Wed, 9 Sep 2015 09:02:57 -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: > > There is no access to p in the first thread. If there are such accesses > > then they are illegal. A user of slab allocators must ensure that there > > are no accesses after freeing the object. And since there is a thread > > that at random checks p and frees it when not NULL then no other thread > > would be allowed to touch the object. > > > But the memory allocator itself (kmalloc/kfree) generally reads and > writes the object (e.g. storing object size in header before object, > writing redzone in debug mode, reading and checking redzone in debug > mode, building freelist using first word of the object, etc). There is > no different between user accesses and memory allocator accesses just > before returning the object from kmalloc and right after accepting the > object in kfree. There is a difference. The object is not accessible to any code before kmalloc() returns. And it must not be accessible anymore when kfree() is called. Thus the object is under exclusive control of the allocators when it is handled. -- 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