Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp15256ybi; Thu, 13 Jun 2019 10:47:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxF/1HlN8nuPddtUcBZzoCRlcISU+4oKltoD1s9lwQhkDTO3VoBCeTn6CbI1XqzGaUSMtyi X-Received: by 2002:a63:f349:: with SMTP id t9mr23665177pgj.296.1560448028225; Thu, 13 Jun 2019 10:47:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560448028; cv=none; d=google.com; s=arc-20160816; b=twz+1mJDw3EnUZCGupTPQOHI/SPz+ejF9/A6KnxfaahBZ8DuOZrlV5FqX9FCQFoPfx d4Y43LQcFajBe5CD1J/LkP58/5mwKk53F3CL2vQzCteMzzuCPT8mr5J0q1yKQVq74PGW bZo5PfMHa0UrhojsUFSuvMTHimxtfgPBoFtYu0sOQ7AHF3zoHZoVR9TMkBxq2hPDrdX+ oV75D+Pj8xBAQxsjiB6OjNgPtshNWfPPZnrgLDRA2i2j4b516xy7pil/uW1u7xqLMy4R L+YtruKfQvyJbnHGLfenGBLnqbljwKEkbIXklqoc6AqBIoCi9skuzhoSErqkMLF9kTsG wBfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :references:in-reply-to:date:cc:to:from:subject:message-id; bh=lEzlxuvpSMrNR4n7z6yfIaw8K7RTxUxdTVJa0UdpOPk=; b=TvZUKZxMMYh7cc0xERAH4QCGeB4jJaB/5/oPFjQOP+PaJkzd02kzNX0Bhgpz4dKdPh AbXNHewH+O2O80IFE8uqTTfYza+hp0/eS2aIs/Zno3iRkD3qF+XGvtl8PT/ytz8GiPWY 3gYbAqpvOA3MC1qTheP1GKloVPFRvSpaeN8Z7jp8TDrWjk255tRhapqAJvI2AJuR7A4R h/QmaX7AEB5otKY+LgzdbbSr6oqSrH2ChkK2jYxMUS/hankRHxNS9CLvWsrM8OGIIasw sp+JGdfHCc2/8R8kYb5EeGOb+04cyfmwVKysKxrcOb36cxxjvu80Wt0hICp2ryPQ+oeo WyJQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b26si302183pgm.318.2019.06.13.10.46.53; Thu, 13 Jun 2019 10:47:08 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727107AbfFMRqt (ORCPT + 99 others); Thu, 13 Jun 2019 13:46:49 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:11945 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725852AbfFMRqt (ORCPT ); Thu, 13 Jun 2019 13:46:49 -0400 X-UUID: 1bc9fbe28e904bcf97072f05f18c0602-20190614 X-UUID: 1bc9fbe28e904bcf97072f05f18c0602-20190614 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 795620865; Fri, 14 Jun 2019 01:46:41 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 14 Jun 2019 01:46:39 +0800 Received: from [172.21.84.99] (172.21.84.99) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Fri, 14 Jun 2019 01:46:39 +0800 Message-ID: <1560447999.15814.15.camel@mtksdccf07> Subject: Re: [PATCH v3] kasan: add memory corruption identification for software tag-based mode From: Walter Wu To: Andrey Ryabinin CC: Alexander Potapenko , Dmitry Vyukov , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Matthias Brugger , "Martin Schwidefsky" , Arnd Bergmann , "Vasily Gorbik" , Andrey Konovalov , "Jason A . Donenfeld" , Miles Chen , , , , , , Date: Fri, 14 Jun 2019 01:46:39 +0800 In-Reply-To: References: <20190613081357.1360-1-walter-zh.wu@mediatek.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-TM-SNTS-SMTP: 73E573334F60FA682523A92B528AE4E79ADB9EB515874F36690B616CC9E25A672000:8 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2019-06-13 at 15:27 +0300, Andrey Ryabinin wrote: > > On 6/13/19 11:13 AM, Walter Wu wrote: > > This patch adds memory corruption identification at bug report for > > software tag-based mode, the report show whether it is "use-after-free" > > or "out-of-bound" error instead of "invalid-access" error.This will make > > it easier for programmers to see the memory corruption problem. > > > > Now we extend the quarantine to support both generic and tag-based kasan. > > For tag-based kasan, the quarantine stores only freed object information > > to check if an object is freed recently. When tag-based kasan reports an > > error, we can check if the tagged addr is in the quarantine and make a > > good guess if the object is more like "use-after-free" or "out-of-bound". > > > > > We already have all the information and don't need the quarantine to make such guess. > Basically if shadow of the first byte of object has the same tag as tag in pointer than it's out-of-bounds, > otherwise it's use-after-free. > > In pseudo-code it's something like this: > > u8 object_tag = *(u8 *)kasan_mem_to_shadow(nearest_object(cacche, page, access_addr)); > > if (access_addr_tag == object_tag && object_tag != KASAN_TAG_INVALID) > // out-of-bounds > else > // use-after-free Thanks your explanation. I see, we can use it to decide corruption type. But some use-after-free issues, it may not have accurate free-backtrace. Unfortunately in that situation, free-backtrace is the most important. please see below example In generic KASAN, it gets accurate free-backrace(ptr1). In tag-based KASAN, it gets wrong free-backtrace(ptr2). It will make programmer misjudge, so they may not believe tag-based KASAN. So We provide this patch, we hope tag-based KASAN bug report is the same accurate with generic KASAN. --- ptr1 = kmalloc(size, GFP_KERNEL); ptr1_free(ptr1); ptr2 = kmalloc(size, GFP_KERNEL); ptr2_free(ptr2); ptr1[size] = 'x'; //corruption here static noinline void ptr1_free(char* ptr) { kfree(ptr); } static noinline void ptr2_free(char* ptr) { kfree(ptr); } ---