Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9567667ybi; Wed, 10 Jul 2019 12:36:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqxu0KnxWt+G3xoZTKboK5QNO5aseqyJbgY14AkiD3B+4UzA6f+N22Ym2I4U/9cO5qIT7CfB X-Received: by 2002:a63:eb06:: with SMTP id t6mr23201209pgh.107.1562787367736; Wed, 10 Jul 2019 12:36:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562787367; cv=none; d=google.com; s=arc-20160816; b=gNmCWgJD6LEJUDok4z+5fgp4tySEEiwFGZ9LiTqryt4RNF7ABznxeB23a4BPY25iEh lBHf1OpbvaeLkS4nTyLoVK3PDx8/1ISdOUILTgQlTebb5yeDS4tSkHkYYlcNTCjaml0W kPG/9ysEykFoAEcBT/+p/bb8cunRDE8nVQtR+Zr7yMp2LaLJSMO286tdHaulQ1EI/Zl4 AP+LISujfonb4/5XwgyMLqnzsKT8vbmjv7Kb31KTVvCrZ57QBsC7PameatCHigNaplj9 Pj5veTAT0esV1+u3uC5aCwZWoUnaWrfpNZtST/HNc3esfwuSP1c/ycKF7oxsqDUCGlft N2XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=wZtz7lm7J/SagsRkoCghKnDoEzNg/tnMRP90/zbxSlc=; b=cWtlJPOAAvwSCWZ5Pe/0tLmketz+HcTG1iZxbOQ4OBfA6TsHESMuCecdJhpAURuYrU 3lxnNUzOiCorSL2VEDiAjsJtiZOw00jRJ76YncQo6ibUstdhMh2IQlflPpkmFZUprbVj 01nsluRvY2bMmS2t0TrTRtX5yLNQnzWkynLg/NXMS3sT/GFmugP4ptGPR7kWjS0beiOU 9Y+tOfg/4UsjrYH5Z1VpNygSlAS1A72/qomvb29K5fvLddLx+MiTOBCCD5Mf9LuY1j01 w/SIRicPVLvxibICbAEJcyjmhNIwimZ7jgM8Y2So9MYOGV/d1jobClbwWGlgy8cQPLWw YDIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m9si2784143pjs.95.2019.07.10.12.35.51; Wed, 10 Jul 2019 12:36:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728029AbfGJSYo (ORCPT + 99 others); Wed, 10 Jul 2019 14:24:44 -0400 Received: from relay.sw.ru ([185.231.240.75]:47462 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727460AbfGJSYo (ORCPT ); Wed, 10 Jul 2019 14:24:44 -0400 Received: from [172.16.25.12] by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hlHGV-0006Kk-L9; Wed, 10 Jul 2019 21:24:27 +0300 Subject: Re: [PATCH v3] kasan: add memory corruption identification for software tag-based mode To: Walter Wu , Dmitry Vyukov Cc: Alexander Potapenko , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Matthias Brugger , Martin Schwidefsky , Arnd Bergmann , Vasily Gorbik , Andrey Konovalov , "Jason A . Donenfeld" , Miles Chen , kasan-dev , LKML , Linux-MM , Linux ARM , linux-mediatek@lists.infradead.org, wsd_upstream References: <20190613081357.1360-1-walter-zh.wu@mediatek.com> <1560447999.15814.15.camel@mtksdccf07> <1560479520.15814.34.camel@mtksdccf07> <1560744017.15814.49.camel@mtksdccf07> <1560774735.15814.54.camel@mtksdccf07> <1561974995.18866.1.camel@mtksdccf07> <1562640832.9077.32.camel@mtksdccf07> From: Andrey Ryabinin Message-ID: Date: Wed, 10 Jul 2019 21:24:22 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <1562640832.9077.32.camel@mtksdccf07> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/9/19 5:53 AM, Walter Wu wrote: > On Mon, 2019-07-08 at 19:33 +0300, Andrey Ryabinin wrote: >> >> On 7/5/19 4:34 PM, Dmitry Vyukov wrote: >>> On Mon, Jul 1, 2019 at 11:56 AM Walter Wu wrote: >>> >>> Sorry for delays. I am overwhelm by some urgent work. I afraid to >>> promise any dates because the next week I am on a conference, then >>> again a backlog and an intern starting... >>> >>> Andrey, do you still have concerns re this patch? This change allows >>> to print the free stack. >> >> I 'm not sure that quarantine is a best way to do that. Quarantine is made to delay freeing, but we don't that here. >> If we want to remember more free stacks wouldn't be easier simply to remember more stacks in object itself? >> Same for previously used tags for better use-after-free identification. >> > > Hi Andrey, > > We ever tried to use object itself to determine use-after-free > identification, but tag-based KASAN immediately released the pointer > after call kfree(), the original object will be used by another > pointer, if we use object itself to determine use-after-free issue, then > it has many false negative cases. so we create a lite quarantine(ring > buffers) to record recent free stacks in order to avoid those false > negative situations. I'm telling that *more* than one free stack and also tags per object can be stored. If object reused we would still have information about n-last usages of the object. It seems like much easier and more efficient solution than patch you proposing. As for other concern about this particular patch - It wasn't tested. There is deadlock (sleep in atomic) on the report path which would have been noticed it tested. Also GFP_NOWAIT allocation which fails very noisy and very often, especially in memory constraint enviromnent where tag-based KASAN supposed to be used. - Inefficient usage of memory: 48 bytes (sizeof (qlist_object) + sizeof(kasan_alloc_meta)) per kfree() call seems like a lot. It could be less. The same 'struct kasan_track' stored twice in two different places (in object and in quarantine). Basically, at least some part of the quarantine always duplicates information that we already know about recently freed object. Since now we call kmalloc() from kfree() path, every unique kfree() stacktrace now generates additional unique stacktrace that takes space in stackdepot.