Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751694AbdGQSMr (ORCPT ); Mon, 17 Jul 2017 14:12:47 -0400 Received: from resqmta-po-05v.sys.comcast.net ([96.114.154.164]:49908 "EHLO resqmta-po-05v.sys.comcast.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751646AbdGQSMp (ORCPT ); Mon, 17 Jul 2017 14:12:45 -0400 X-Greylist: delayed 488 seconds by postgrey-1.27 at vger.kernel.org; Mon, 17 Jul 2017 14:12:45 EDT Date: Mon, 17 Jul 2017 13:04:34 -0500 (CDT) From: Christopher Lameter X-X-Sender: cl@nuc-kabylake To: Matthew Wilcox cc: Alexander Popov , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, keescook@chromium.org Subject: Re: [PATCH 1/1] mm/slub.c: add a naive detection of double free or corruption In-Reply-To: <20170717175459.GC14983@bombadil.infradead.org> Message-ID: References: <1500309907-9357-1-git-send-email-alex.popov@linux.com> <20170717175459.GC14983@bombadil.infradead.org> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-CMAE-Envelope: MS4wfGXPOMvkMXgE2s5gLri1ci+SkYtI4BQWKkgiWHpJH6s0uVdyAi6YHX69KrEjJF848uWSUFeRkOa0JdO4CDxvZk9Xzdg5x0jJLggzTHRdv9JWu2hXxbme hi9x69iKfdwYUFkPjkDgIlnRB3sS41KFMcxsh8agFEQdTArkUgAGPIGvZknDVp6iv61xQTa4kBdgx+Svm4JEjmVfKTrMwg4S5x7m58eK0XdEn8mqt54N5tMc znKIslnxlh8Xd4adbXIM4cEybJWf/0Ff4OnDdgDsGk0FXLWV+hbHdXQxxxOT9xg6nT/txQQkXEeS1csQYJS+Pk0XuXcCiU2caV+UcNtYWUuNZBnm1mxLYcNQ 15SzLsy3HlbPfLpK1wXc/JW65k07XjRs1bfBoBRQYWSK8mJvHDtCyA84jFvxQCfpV1DA9k/dN928Qv5M+adGptRZZLvuCothmjVEHgD/lPiZKGPcG3iQft1u 1bMnTNXzq4nglPJg Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 988 Lines: 22 On Mon, 17 Jul 2017, Matthew Wilcox wrote: > On Mon, Jul 17, 2017 at 07:45:07PM +0300, Alexander Popov wrote: > > Add an assertion similar to "fasttop" check in GNU C Library allocator: > > an object added to a singly linked freelist should not point to itself. > > That helps to detect some double free errors (e.g. CVE-2017-2636) without > > slub_debug and KASAN. Testing with hackbench doesn't show any noticeable > > performance penalty. > > > { > > + BUG_ON(object == fp); /* naive detection of double free or corruption */ > > *(void **)(object + s->offset) = fp; > > } > > Is BUG() the best response to this situation? If it's a corruption, then > yes, but if we spot a double-free, then surely we should WARN() and return > without doing anything? The double free debug checking already does the same thing in a more thourough way (this one only checks if the last free was the same address). So its duplicating a check that already exists. However, this one is always on.