From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, T_DKIMWL_WL_HIGH,UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05682C28CC0 for ; Thu, 30 May 2019 01:58:38 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CA23C2440E for ; Thu, 30 May 2019 01:58:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NPyeBaPK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA23C2440E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Date:To:From:Subject:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8+marc9ALrdBpcXk9F2zyyC54JLTec56iMGzJoJl75s=; b=NPyeBaPKv2KR7N V4T2TbZrqQNvuHZLZJgqEC9CfLoara5pvmdGvSNuxFI9qpZJMgZk+ANQpiQXK3bMydf9/q+CT80Hu X9Nz5diYyP1MYypbkpvkWrUfmAr9rKGugjfGNxwE9PEsJBAJPLToQcmF/Du1gmtoppLEZg37lYwiP qKRCRgyMbXuaXZvCIU5cv7F4b8OgzQ7cEp1nKrrPBt5RRHoCZiSr+wYOWd0SrFlmgpDTmYlFfsSKA YQNqNbySRWDeNNr96QVPKZkf4P7U5ABF1bdaebbSg+R+sxV/BDNux8g6LG2PVrpiGiMgnMublYJc5 j0LqdzJpwH+JEGxgfJfA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hWAKr-0005ln-K9; Thu, 30 May 2019 01:58:29 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hWAKn-0005kb-If; Thu, 30 May 2019 01:58:27 +0000 X-UUID: 0f66a0144afd4b8785e7f15f8bea6d9a-20190529 X-UUID: 0f66a0144afd4b8785e7f15f8bea6d9a-20190529 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1795255748; Wed, 29 May 2019 17:58:05 -0800 Received: from MTKMBS07N2.mediatek.inc (172.21.101.141) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 29 May 2019 18:58:04 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 30 May 2019 09:58:02 +0800 Received: from [172.21.84.99] (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Thu, 30 May 2019 09:58:02 +0800 Message-ID: <1559181482.24427.18.camel@mtksdccf07> Subject: Re: [PATCH] kasan: add memory corruption identification for software tag-based mode From: Walter Wu To: Dmitry Vyukov Date: Thu, 30 May 2019 09:58:02 +0800 In-Reply-To: References: <1559027797-30303-1-git-send-email-walter-zh.wu@mediatek.com> <1559122529.17186.24.camel@mtksdccf07> X-Mailer: Evolution 3.2.3-0ubuntu6 MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190529_185825_633648_A541D293 X-CRM114-Status: GOOD ( 21.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wsd_upstream@mediatek.com, Catalin Marinas , linux-mediatek@lists.infradead.org, LKML , kasan-dev , Pekka Enberg , Linux-MM , Miles Chen , Alexander Potapenko , David Rientjes , Matthias Brugger , Andrey Ryabinin , Christoph Lameter , Joonsoo Kim , Linux ARM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, 2019-05-29 at 12:00 +0200, Dmitry Vyukov wrote: > > > There can be multiple qobjects in the quarantine associated with the > > > address, right? If so, we need to find the last one rather then a > > > random one. > > > > > The qobject includes the address which has tag and range, corruption > > address must be satisfied with the same tag and within object address > > range, then it is found in the quarantine. > > It should not easy to get multiple qobjects have the same tag and within > > object address range. > > Yes, using the tag for matching (which I missed) makes the match less likely. > > But I think we should at least try to find the newest object in > best-effort manner. We hope it, too. > Consider, both slab and slub reallocate objects in LIFO manner and we > don't have a quarantine for objects themselves. So if we have a loop > that allocates and frees an object of same size a dozen of times. > That's enough to get a duplicate pointer+tag qobject. > This includes: > 1. walking the global quarantine from quarantine_tail backwards. It is ok. > 2. walking per-cpu lists in the opposite direction: from tail rather > then from head. I guess we don't have links, so we could change the > order and prepend new objects from head. > This way we significantly increase chances of finding the right > object. This also deserves a comment mentioning that we can find a > wrong objects. > The current walking per-cpu list direction is from head to trail. we will modify the direction and find the newest object. > > > Why don't we allocate qlist_object and qlist_node in a single > > > allocation? Doing 2 allocations is both unnecessary slow and leads to > > > more complex code. We need to allocate them with a single allocations. > > > Also I think they should be allocated from a dedicated cache that opts > > > out of quarantine? > > > > > Single allocation is good suggestion, if we only has one allocation. > > then we need to move all member of qlist_object to qlist_node? > > > > struct qlist_object { > > unsigned long addr; > > unsigned int size; > > struct kasan_alloc_meta free_track; > > }; > > struct qlist_node { > > struct qlist_object *qobject; > > struct qlist_node *next; > > }; > > I see 2 options: > 1. add addr/size/free_track to qlist_node under ifdef CONFIG_KASAN_SW_TAGS > 2. or probably better would be to include qlist_node into qlist_object > as first field, then allocate qlist_object and cast it to qlist_node > when adding to quarantine, and then as we iterate quarantine, we cast > qlist_node back to qlist_object and can access size/addr. > Choice 2 looks better, We first try it. > > > We call call ___cache_free() to free the qobject and qnode, it should be > > out of quarantine? > > This should work. Thanks your good suggestion. We will implement those solution which you suggested to the second edition. Thanks, Walter _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel