From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753633AbbFCX3p (ORCPT ); Wed, 3 Jun 2015 19:29:45 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:43224 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751885AbbFCX3h (ORCPT ); Wed, 3 Jun 2015 19:29:37 -0400 Date: Wed, 3 Jun 2015 16:29:36 -0700 From: Andrew Morton To: Catalin Marinas Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Vignesh Radhakrishnan Subject: Re: [PATCH] mm: kmemleak: Fix crashing during kmemleak disabling Message-Id: <20150603162936.9132276820819001436585b3@linux-foundation.org> In-Reply-To: <1433346176-912-1-git-send-email-catalin.marinas@arm.com> References: <1433346176-912-1-git-send-email-catalin.marinas@arm.com> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 3 Jun 2015 16:42:56 +0100 Catalin Marinas wrote: > With the current implementation, if kmemleak is disabled because of an > error condition (e.g. fails to allocate metadata), alloc/free calls are > no longer tracked. Usually this is not a problem since the kmemleak > metadata is being removed via kmemleak_do_cleanup(). However, if the > scanning thread is running at the time of disabling, kmemleak would no > longer notice a potential vfree() call and the freed/unmapped object may > still be accessed, causing a fault. > > This patch separates the kmemleak_free() enabling/disabling from the > overall kmemleak_enabled nob so that we can defer the disabling of the > object freeing tracking until the scanning thread completed. The > kmemleak_free_part() is deliberately ignored by this patch since this is > only called during boot before the scanning thread started. I'm having trouble with this. afacit, kmemleak_free() can still be called while kmemleak_scan() is running on another CPU. kmemleak_free_enabled hasn't been cleared yet so the races remain. However your statement "if the scanning thread is running at the time of disabling" implies that the race is between kmemleak_scan() and kmemleak_disable(). Yet the race avoidance code is placed in kmemleak_free(). All confused. A more detailed description of the race would help. Also, the words "kmemleak would no longer notice a potential vfree() call" aren't sufficiently specific. kmemleak is a big place - what *part* of kmemleak are you referring to here? Finally, I'm concerned that a bare kmemleak_free_enabled = 0; lacks sufficient synchronization with respect to the kmemleak_free_enabled readers from a locking/reordering point of view. What's the story here?