Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10341191ybi; Thu, 11 Jul 2019 03:45:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqztlUX6SEGa4/j0nEmoV7Tw5eVbYTqdBTDQrb21epeBjFDxAB0KnDUGR+7B7lI/VzB2slnD X-Received: by 2002:a63:ce01:: with SMTP id y1mr983445pgf.389.1562841919650; Thu, 11 Jul 2019 03:45:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562841919; cv=none; d=google.com; s=arc-20160816; b=C7imtSRzEoJyRF4CjK7jKJSRTzl+izaXL7bgZtGG1QzulLwGihEMZeXw6wc6BwR8WB SanOjARAVb2zDCtwFPd3yjD18kZYDJ43ybZAqZ7BmXJtnYZhC5asOREQ2rfm7a8XfbmE JldHOL17gypXtqVy6z3MNOdQY2JxbJj6WQRjSCKo3QoWlG/4xzl7baovSMoDhKhGnkjn iU5rBpdVCJxrcjqk5ONH6Swu4qmpm/W3UonioqXk5l47fqg8WNQRSXPKUflTl8GYDQ+Z g21R6OsUh43B6bQlgue9pkxhHvMKohxgTIOgFhMelzVM6Sm0QeCrrQHz0Ur/HCO2a91z oCIg== 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=lBDaQaXRrUq4knov/Wq1uP79LCOzMma2QenhtGj5Gj0=; b=g7aLWXc0NzOtKBg/ieQbMBg1XRFjxjpeFkGznrc+uFiBY81afjC+h9WSgmn5fneKOp Q5aAqyTH4eC/xj8wDXNBmcAluaUr6JilG4ZZL6AsCpnPXJLs1lFdMNjhEHoHLhFfDx1e 4QaM96xyhdxpmXAJJ289+KEA5ggKvZkZZ8dYK3D0NVgfSh/SJ/K+ks9MtBFDkVv1SJw2 xDMjjq2tjFNBWMeGMkbX8fjWOssvZVV4o865YhkH6DTR5ly1VPXeK1D6cupG3YvmmDii OseyiNyP/o12NEm89vl+/izE/Q2TrPiMl5m8FuNLZG8f/4VTogHisYYWCsCB0MOcT9UA e48Q== 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 g8si4443579plt.273.2019.07.11.03.45.04; Thu, 11 Jul 2019 03:45:19 -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 S1728161AbfGKKGZ (ORCPT + 99 others); Thu, 11 Jul 2019 06:06:25 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:59267 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727636AbfGKKGY (ORCPT ); Thu, 11 Jul 2019 06:06:24 -0400 X-UUID: 992731da7b244743b02a101ec454b63e-20190711 X-UUID: 992731da7b244743b02a101ec454b63e-20190711 Received: from mtkmrs01.mediatek.inc [(172.21.131.159)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 749532910; Thu, 11 Jul 2019 18:06:20 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 11 Jul 2019 18:06:19 +0800 Received: from [172.21.84.99] (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Thu, 11 Jul 2019 18:06:19 +0800 Message-ID: <1562839579.5846.12.camel@mtksdccf07> Subject: Re: [PATCH v3] kasan: add memory corruption identification for software tag-based mode From: Walter Wu To: Andrey Ryabinin CC: Dmitry Vyukov , 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 , , wsd_upstream Date: Thu, 11 Jul 2019 18:06:19 +0800 In-Reply-To: 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> 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: FCA1495ABCFBF051C3A138F429F412BB004A5166313DECBCF8F5873EED71160F2000:8 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2019-07-10 at 21:24 +0300, Andrey Ryabinin wrote: > > 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. > To make the object reused, we must ensure that no other pointers uses it after kfree() release the pointer. Scenario: 1). The object reused information is valid when no another pointer uses it. 2). The object reused information is invalid when another pointer uses it. Do you mean that the object reused is scenario 1) ? If yes, maybe we can change the calling quarantine_put() location. It will be fully use that quarantine, but at scenario 2) it looks like to need this patch. If no, maybe i miss your meaning, would you tell me how to use invalid object information? or? > 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. we already used it on qemu and ran kasan UT. It look like ok. > Also GFP_NOWAIT allocation which fails very noisy and very often, especially in memory constraint enviromnent where tag-based KASAN supposed to be used. > Maybe, we can change it into GFP_KERNEL. > - Inefficient usage of memory: > 48 bytes (sizeof (qlist_object) + sizeof(kasan_alloc_meta)) per kfree() call seems like a lot. It could be less. > We will think it. > 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. > Duplicate information is solved after change the calling quarantine_put() location.