Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2437386ybi; Mon, 17 Jun 2019 04:58:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzSxE+xf4ziVcqpAqfG6XPYmKwPg9LVKoIuKShuPqdf7O4ZN6uv2prtYuGqdH2bhXYoOPdH X-Received: by 2002:a63:d24f:: with SMTP id t15mr16813324pgi.301.1560772716093; Mon, 17 Jun 2019 04:58:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560772716; cv=none; d=google.com; s=arc-20160816; b=AWfIhnWNu+5A99PpUIvchda4pDFHi9bDVg9ofg8ID/H2l2SkIquSZRWRuEjHEEBoci DpeABZ1oiGOitJAsWs2wbfLAJ3gOQ30frfde7PsPNRyh1FCWq+t8glENugNDiyuApU1w UrKonF/6DgxrP1KJUxmDPuBVB4sjnLbV9s8LEdaxMzcoRj430Em6CyR9Ac86jp4I4IyM NlrDjMfL/2HP9k8+CzCVzWYEpBMBtXCqubEp2GB4kA0m8Tk8YSom4cQTDdy8zmATPvls WX0eUx7v1JbUazdcYCXJhl+9PPUmpRUKyncAPJU0g8VSlYgFKFkup9TiVkGru4w/gPax g0lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ueOYS1wFyeCCBxDCVsPVG5+an3vWjzFueCDlI0BJDTQ=; b=gYX7/PO/R5uPRRm8e/qNrzXCPWaMOYrJYoptc8agwJDLcN3HrmgDPaPLhTzY73s870 n1wIP3z2MPgJNEoHFa0o78hI2ccYa7RpGhBMLiNFjG/wxmMzWr7Vp4Az1LniRtALI/RH fusoFHP14hWiCo0dB6XcW5AtDjVDIz4NTjf2nTyLCeRL9+grrVX13M074C/oGUoKbp6z xjHl0JFlyP4snr/fOPK0EFwYyy9B2tzFOULIAh76RwqJc57hcIpRzm3zRu87Fpi8lI4r h3PbyGEXpcPzY3X1xKTQId30xyOtwdTqXL+UFOoB3VVGiDAa+DWrl7P017IBF2zpABVa 8JJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="m/nic/1g"; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o11si7965963plk.47.2019.06.17.04.58.20; Mon, 17 Jun 2019 04:58:36 -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; dkim=pass header.i=@google.com header.s=20161025 header.b="m/nic/1g"; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725995AbfFQL6K (ORCPT + 99 others); Mon, 17 Jun 2019 07:58:10 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:45150 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725763AbfFQL6K (ORCPT ); Mon, 17 Jun 2019 07:58:10 -0400 Received: by mail-io1-f66.google.com with SMTP id e3so20377932ioc.12 for ; Mon, 17 Jun 2019 04:58:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ueOYS1wFyeCCBxDCVsPVG5+an3vWjzFueCDlI0BJDTQ=; b=m/nic/1gMsqRM3aXpp3S0P7cl9f86+N1HuW0xsCIUi26svfLi1qjvD8/zHDJfv4CtC agTG9FTFwES2e6fKPNgesel4PIaXyheHVvmzttqU9n3CyDEI5yYSs0KzLEhRXDmkIDiU BoHvb5PH7lF6fHNpMMcZCbfokLgEMLHe9fSGVjgWlkE+tshkqtTNJW8XqsM7EiTbmZYV zY9Uiv1rua98ZWBS7vxyFk1D1Qek2WDw0hPW2R1nacVvqRmslLdyg7GzuKjnyjdUSKAy n8cKtLfeAZ7oUirrutBaSPmjmPh9zhy8sGDCjUK9FZlC0Yr3nw5q6M2O+M/R+2cooSGO gHDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ueOYS1wFyeCCBxDCVsPVG5+an3vWjzFueCDlI0BJDTQ=; b=S5Gv6dzkAbDKfTiAM6vMXdGH8J3pgP6ymP5g0FcB4CVlFTqeWpwWZLIWTWnPbh9RSa +BvxTJZOt/Z5XAZSjJa+cSbcgtqld81vec1iJDQUZvo88LdH23Aii/Zs6/IqunrrfclI XtakDR9HaAeqK0F0HgRkeBk/qB0XnpIKnQJteE/nBcDz6wwae+LfQTlKCSq8KQgp5YKV 2/wkkr6Od+bYWwfLfq55N5s+dpwijwUKfwMe+fSHKm8X1DeuquC4PvPj5QqNPxBqXwyh wEIQ6afSN1otOvXb7stm2pWVt1Z/iVkUtQmqnl+DjT3zx50KcPUvmGWlUsxlUSOq0Ys5 QTGw== X-Gm-Message-State: APjAAAXE6uZ0+SAxMj9shaLrdZ08WDFzxLallU4+alnuAThdxKiOeq7p B01bItj/CgQlNp1kArhcL9KnjmIXSv9H9y3X8H1JVQ== X-Received: by 2002:a6b:fb0f:: with SMTP id h15mr2795600iog.266.1560772688590; Mon, 17 Jun 2019 04:58:08 -0700 (PDT) MIME-Version: 1.0 References: <20190613081357.1360-1-walter-zh.wu@mediatek.com> <1560447999.15814.15.camel@mtksdccf07> <1560479520.15814.34.camel@mtksdccf07> <1560744017.15814.49.camel@mtksdccf07> In-Reply-To: <1560744017.15814.49.camel@mtksdccf07> From: Dmitry Vyukov Date: Mon, 17 Jun 2019 13:57:57 +0200 Message-ID: Subject: Re: [PATCH v3] kasan: add memory corruption identification for software tag-based mode To: Walter Wu Cc: Andrey Ryabinin , 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 17, 2019 at 6:00 AM Walter Wu wrote: > > On Fri, 2019-06-14 at 10:32 +0800, Walter Wu wrote: > > On Fri, 2019-06-14 at 01:46 +0800, Walter Wu wrote: > > > 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); > > > } > > > --- > > > > > We think of another question about deciding by that shadow of the first > > byte. > > In tag-based KASAN, it is immediately released after calling kfree(), so > > the slub is easy to be used by another pointer, then it will change > > shadow memory to the tag of new pointer, it will not be the > > KASAN_TAG_INVALID, so there are many false negative cases, especially in > > small size allocation. > > > > Our patch is to solve those problems. so please consider it, thanks. > > > Hi, Andrey and Dmitry, > > I am sorry to bother you. > Would you tell me what you think about this patch? > We want to use tag-based KASAN, so we hope its bug report is clear and > correct as generic KASAN. > > Thanks your review. > Walter Hi Walter, I will probably be busy till the next week. Sorry for delays.