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=-8.3 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 0E76FC31E45 for ; Thu, 13 Jun 2019 15:18:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D81C521473 for ; Thu, 13 Jun 2019 15:18:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qc01olia" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388824AbfFMPSn (ORCPT ); Thu, 13 Jun 2019 11:18:43 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:38217 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732154AbfFMNFQ (ORCPT ); Thu, 13 Jun 2019 09:05:16 -0400 Received: by mail-io1-f68.google.com with SMTP id k13so16651893iop.5 for ; Thu, 13 Jun 2019 06:05:16 -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=COMq1DZp1tUFDOVJCz+Oc5oRle5W+TVy2bbvRpSIdF4=; b=qc01olia4cmwrnoPTe2ZFrmw8g/xeegnMkBjI6b5n3TIdaetazObaCuOVxxJGxztfx UWxdZDvZDFYmTfiHnlGPUNiNlz24GdHLSttZMTJdYvj6tFmu3BtHAev5gqLNhXvSPYnM NsXWoj0lkbckrxBeZEJgG5KoxPDrFhBmupApL0hfeJS3hCMIKbbkjYDoZCw2sNnAkwZQ 6cKSZeJReF8wUT0bqEHGB7mByLnj/TeKWcvCjWas4NwnEgzQpNFuh3wA5GgvZBs88li2 oNEgWYm244rN1o23TzoBUZ+n2kFqLpUW00bU/764tbCeMtdqKf/ChMz/FSj1569Oj9Ra UQvg== 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=COMq1DZp1tUFDOVJCz+Oc5oRle5W+TVy2bbvRpSIdF4=; b=jzoOy0UQB5naT6aqhyQXp62XrPg+0y9+927v+ZN+34fZE29XlyrmIRy7srGjBNjgj+ FNskKsL3yZtz6fYa6K5PQ7eI9pK2PsB1iFWUghAeiJeshSuTFBn4l7DorRbh4MtwQe1R hXB9oBZrc4CxCq2m2duhStjW95hUqcaPHnPeHBS5WpZ65tU6rwLPDkuLOZ7qao23G46L Ir6t/vT7+sP9gMLxlG3YScXm6et0iIvkf9zfR+OxL0bt4qGrPpWG2rOzpmIU56SHv/WJ m0plRY8dtxIS9JFA2vN7LhrVuY3bTMG2fGZAWtYtAmQ23XOzAcuH5Aak288svKNc69jH jn5A== X-Gm-Message-State: APjAAAWiMjD88QzRQL86CpNBByp8HrBywLY/WjrkGyg6Oglono/808r9 IQyaYvzymfKjscD17OlEpQx4TWcnP2BPh0qSOLmwpQ== X-Google-Smtp-Source: APXvYqx+Wyo9dQ01vmbb1QVMUlNB4LxKek/Z4JsplxvhFxRKIXJWRUTg5jAa3SaPJ4zJ8mK/k/T7Pj1+pIKN6neeKaQ= X-Received: by 2002:a5d:80d6:: with SMTP id h22mr6100497ior.231.1560431115386; Thu, 13 Jun 2019 06:05:15 -0700 (PDT) MIME-Version: 1.0 References: <20190613081357.1360-1-walter-zh.wu@mediatek.com> In-Reply-To: From: Dmitry Vyukov Date: Thu, 13 Jun 2019 15:05:04 +0200 Message-ID: Subject: Re: [PATCH v3] kasan: add memory corruption identification for software tag-based mode To: Andrey Ryabinin Cc: Walter Wu , 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 Thu, Jun 13, 2019 at 2:27 PM 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 But we don't have redzones in tag mode (intentionally), so unless I am missing something we don't have the necessary info. Both cases look the same -- we hit a different tag. There may only be a small trailer for kmalloc-allocated objects that is painted with a different tag. I don't remember if we actually use a different tag for the trailer. Since tag mode granularity is 16 bytes, for smaller objects the trailer is impossible at all. 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=-8.3 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=ham 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 2AC09C31E45 for ; Thu, 13 Jun 2019 13:05:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D59DE2173C for ; Thu, 13 Jun 2019 13:05:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qc01olia" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D59DE2173C Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6DD936B0006; Thu, 13 Jun 2019 09:05:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 667776B000C; Thu, 13 Jun 2019 09:05:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 508796B000E; Thu, 13 Jun 2019 09:05:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by kanga.kvack.org (Postfix) with ESMTP id 2D0496B0006 for ; Thu, 13 Jun 2019 09:05:36 -0400 (EDT) Received: by mail-io1-f70.google.com with SMTP id p12so15006414iog.19 for ; Thu, 13 Jun 2019 06:05:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:mime-version:references :in-reply-to:from:date:message-id:subject:to:cc; bh=COMq1DZp1tUFDOVJCz+Oc5oRle5W+TVy2bbvRpSIdF4=; b=Y6RiOWPhwU4ALsgiIY/0H6mzVPz+D1uOFeC93kyX2HA95EFBe5Bv2fjZLhV8QuI/k8 Y3cs78zTD7y/CqcLopn30Sg01Cv3sBrYGi0CtdZKfBIun8YHf5+cuK0SS5UHZCQL5Qfz 1d5tQJi/bqwjpKMB8Kh12sReiO1lNTYRnhEt/7AtF/c0K/LYL951+96wis355jfCZ4gN igUpOJ+LUaKiB2SR0dukeHGhNN6C0d8uEk62zC3r7GTzoTArfO9RE0xA0v/ISqlW5H7u TuYY0nkHCLRcgL4t8FahuLVl5n0bFFNTfAGMYBgHpuyl/lFi/+ut5IdM5hfqXCqeJt3C PudQ== X-Gm-Message-State: APjAAAVpww48/nPhIYTZb6tiI+TG/kNI+kVRnqFh5MFV12u1uBbtNtTV T7fP49g/ZYMm/IgFg1d1F5Ys46hU8y+dlzqkcnhzthn7uoLLRCjvQgqNKhxvxmQk2bvWKoyL8Km iA1Ps8de9dkWPBWumeHaidaN9T5Jjsel+SryeZ00SdaLgrQxNBYlWgZpxU/C+7Ot8tg== X-Received: by 2002:a02:40c8:: with SMTP id n191mr31843719jaa.14.1560431135907; Thu, 13 Jun 2019 06:05:35 -0700 (PDT) X-Received: by 2002:a02:40c8:: with SMTP id n191mr31843602jaa.14.1560431134951; Thu, 13 Jun 2019 06:05:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560431116; cv=none; d=google.com; s=arc-20160816; b=v5HLibmDCdY2o46XE/2TdM01+tJItcTNCHGoE7YW5V0YshKTgmkwGX7AZVcwh2Kf4K u+o4D2jsfU1aHB/jQQdB48C6Hb5/S2yHrb5hxT+oWq2rUiQOE0tlkz7rsUh+OsnePHbI ncTsXbTBZvTpbn+9rL8c/dqx5YLrs3Qay8n20yo2KSPU0nwD+0KEPdefOhPoZHVLYVKr 3bz0CyTU05bd+5h4sM+WD/mFwwRYq6ooz1vN6RXHfwLDwcWRr24pZHU9sHCk6SvkzsVU rKG4NJRDv8qJpO0xwlqNOr9rlO7cajgppi2I8Kvbng5alK4CQMQYPZZbWEuVu/fqLgjq AjyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=COMq1DZp1tUFDOVJCz+Oc5oRle5W+TVy2bbvRpSIdF4=; b=0+mjxoVeZjyZ0M3HsaH/b3LSTi7oc+YJ14sU4bDmt/0TS+riV/vJjKs7B5N5k32WuI hsy1shFyKzXziZrHGvEUL+BsCZdNUTlwwXMROvZIg6P0BgfMzt/CC8XVzdcN5LmnjqCG 2cma8GLgTyjH97RA8SOpZZtKd/PMhovNCrjJrlFdx06Un7wQdM7A4Mcp7JOySSezYczo C8APZsGAyyJ2IhejKwsmiK726+VT4sQnThCI5v7YhzLJqlU3mBoztP9AISyESVl/tMOA 4Z8IdBQMk1hP9STVbaAeIJwP7Zgjf0E73StxETp+eFwxVjTjcuR9NaWZO6oDJ/aIwmCq Pyow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qc01olia; spf=pass (google.com: domain of dvyukov@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=dvyukov@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id n200sor1707165iod.116.2019.06.13.06.05.15 for (Google Transport Security); Thu, 13 Jun 2019 06:05:16 -0700 (PDT) Received-SPF: pass (google.com: domain of dvyukov@google.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qc01olia; spf=pass (google.com: domain of dvyukov@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=dvyukov@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=COMq1DZp1tUFDOVJCz+Oc5oRle5W+TVy2bbvRpSIdF4=; b=qc01olia4cmwrnoPTe2ZFrmw8g/xeegnMkBjI6b5n3TIdaetazObaCuOVxxJGxztfx UWxdZDvZDFYmTfiHnlGPUNiNlz24GdHLSttZMTJdYvj6tFmu3BtHAev5gqLNhXvSPYnM NsXWoj0lkbckrxBeZEJgG5KoxPDrFhBmupApL0hfeJS3hCMIKbbkjYDoZCw2sNnAkwZQ 6cKSZeJReF8wUT0bqEHGB7mByLnj/TeKWcvCjWas4NwnEgzQpNFuh3wA5GgvZBs88li2 oNEgWYm244rN1o23TzoBUZ+n2kFqLpUW00bU/764tbCeMtdqKf/ChMz/FSj1569Oj9Ra UQvg== X-Google-Smtp-Source: APXvYqx+Wyo9dQ01vmbb1QVMUlNB4LxKek/Z4JsplxvhFxRKIXJWRUTg5jAa3SaPJ4zJ8mK/k/T7Pj1+pIKN6neeKaQ= X-Received: by 2002:a5d:80d6:: with SMTP id h22mr6100497ior.231.1560431115386; Thu, 13 Jun 2019 06:05:15 -0700 (PDT) MIME-Version: 1.0 References: <20190613081357.1360-1-walter-zh.wu@mediatek.com> In-Reply-To: From: Dmitry Vyukov Date: Thu, 13 Jun 2019 15:05:04 +0200 Message-ID: Subject: Re: [PATCH v3] kasan: add memory corruption identification for software tag-based mode To: Andrey Ryabinin Cc: Walter Wu , 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" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Jun 13, 2019 at 2:27 PM 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 But we don't have redzones in tag mode (intentionally), so unless I am missing something we don't have the necessary info. Both cases look the same -- we hit a different tag. There may only be a small trailer for kmalloc-allocated objects that is painted with a different tag. I don't remember if we actually use a different tag for the trailer. Since tag mode granularity is 16 bytes, for smaller objects the trailer is impossible at all. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dmitry Vyukov Subject: Re: [PATCH v3] kasan: add memory corruption identification for software tag-based mode Date: Thu, 13 Jun 2019 15:05:04 +0200 Message-ID: References: <20190613081357.1360-1-walter-zh.wu@mediatek.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=m.gmane.org@lists.infradead.org To: Andrey Ryabinin Cc: wsd_upstream , Walter Wu , Vasily Gorbik , Arnd Bergmann , Linux-MM , Andrey Konovalov , "Jason A . Donenfeld" , kasan-dev , LKML , Pekka Enberg , Martin Schwidefsky , Miles Chen , Alexander Potapenko , David Rientjes , Matthias Brugger , linux-mediatek@lists.infradead.org, Joonsoo Kim , Christoph Lameter , Linux ARM List-Id: linux-mediatek@lists.infradead.org On Thu, Jun 13, 2019 at 2:27 PM 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 But we don't have redzones in tag mode (intentionally), so unless I am missing something we don't have the necessary info. Both cases look the same -- we hit a different tag. There may only be a small trailer for kmalloc-allocated objects that is painted with a different tag. I don't remember if we actually use a different tag for the trailer. Since tag mode granularity is 16 bytes, for smaller objects the trailer is impossible at all. 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=-0.7 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 59E01C31E45 for ; Thu, 13 Jun 2019 13:05:27 +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 2FF65205ED for ; Thu, 13 Jun 2019 13:05:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Y03/535s"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="qc01olia" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2FF65205ED Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.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:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=dhWVK6AIdQk5Xq992+b9wUZytLCHeDvQlFTupITqHZk=; b=Y03/535swP8oDT 0pxQGuRpU1DSfYXkE8LJPyozqzmA9cB+38y7uhn4NXDbcX2tQDspLtA0RDZDI7y5N4cT2OzRHFfHJ lglHA86sXh3eTxchgeBC1McdecUoKn6oHcuH/MLUlihwYWjdfVKTP9tqvSt3TwhMSRssyTqtrzi3Q vFpv2I1DYt6mpF1LL4yHn4ZdL0zfv/mrZwxguyYuGpWSIQYsMcoewogWWOinnCKnxu3W7U0IhKP9G WjcH7pT+S/70E0z/ellfK+OCmUdHJ9rh7BceC+xyvW6av5WWwNG6SINFob9DZZUu2jzC2QI0/J5wd Bs1Prfh4TLaTpyHQiWGw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hbPPy-0002vj-7P; Thu, 13 Jun 2019 13:05:26 +0000 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hbPPv-0002tW-PO for linux-arm-kernel@lists.infradead.org; Thu, 13 Jun 2019 13:05:25 +0000 Received: by mail-io1-xd42.google.com with SMTP id k20so16645492ios.10 for ; Thu, 13 Jun 2019 06:05:16 -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=COMq1DZp1tUFDOVJCz+Oc5oRle5W+TVy2bbvRpSIdF4=; b=qc01olia4cmwrnoPTe2ZFrmw8g/xeegnMkBjI6b5n3TIdaetazObaCuOVxxJGxztfx UWxdZDvZDFYmTfiHnlGPUNiNlz24GdHLSttZMTJdYvj6tFmu3BtHAev5gqLNhXvSPYnM NsXWoj0lkbckrxBeZEJgG5KoxPDrFhBmupApL0hfeJS3hCMIKbbkjYDoZCw2sNnAkwZQ 6cKSZeJReF8wUT0bqEHGB7mByLnj/TeKWcvCjWas4NwnEgzQpNFuh3wA5GgvZBs88li2 oNEgWYm244rN1o23TzoBUZ+n2kFqLpUW00bU/764tbCeMtdqKf/ChMz/FSj1569Oj9Ra UQvg== 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=COMq1DZp1tUFDOVJCz+Oc5oRle5W+TVy2bbvRpSIdF4=; b=bdmaSAAyy+uboo8UpkrG/9o+iU+4LiFSx+kPxGeBIXmhpfNrjnSNrSneokUQDRA4qK kxlWcEm4Z9nbT3nMmfsif93Zs6qgSwdshMesUjtoyZRUy+qkRAZhGxYAhOJw0k/WY+F9 4Cufm34JsbuzSobhZ5dCPUSi1pEVTzk57H/aaPfAYSyazQpmGefVdVi+YzYui59UEjVZ YGKczqdWpNm1paL+4i69kiIx5DrM4S8LixZMzWqAktFOLEo9DehqD8VzkD8zVxJVTT95 vCbeY/o4ZiRaBWNzprFF20rnuQXT5AkQscXuLrP+FfU3iGi6JmMu11U7pewjWuEVqMp5 QEvA== X-Gm-Message-State: APjAAAWy5PpafBnf4GuPx2JjgWwQ8JUBmnJHLQuGrwIllUXuMsm32TQM FF2Un0T+yZaizbOMUFK7AJQTCpcDRDN6MBMPdUUJSg== X-Google-Smtp-Source: APXvYqx+Wyo9dQ01vmbb1QVMUlNB4LxKek/Z4JsplxvhFxRKIXJWRUTg5jAa3SaPJ4zJ8mK/k/T7Pj1+pIKN6neeKaQ= X-Received: by 2002:a5d:80d6:: with SMTP id h22mr6100497ior.231.1560431115386; Thu, 13 Jun 2019 06:05:15 -0700 (PDT) MIME-Version: 1.0 References: <20190613081357.1360-1-walter-zh.wu@mediatek.com> In-Reply-To: From: Dmitry Vyukov Date: Thu, 13 Jun 2019 15:05:04 +0200 Message-ID: Subject: Re: [PATCH v3] kasan: add memory corruption identification for software tag-based mode To: Andrey Ryabinin X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190613_060523_850881_CE852228 X-CRM114-Status: GOOD ( 15.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wsd_upstream , Walter Wu , Vasily Gorbik , Arnd Bergmann , Linux-MM , Andrey Konovalov , "Jason A . Donenfeld" , kasan-dev , LKML , Pekka Enberg , Martin Schwidefsky , Miles Chen , Alexander Potapenko , David Rientjes , Matthias Brugger , linux-mediatek@lists.infradead.org, Joonsoo Kim , Christoph Lameter , 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 Thu, Jun 13, 2019 at 2:27 PM 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 But we don't have redzones in tag mode (intentionally), so unless I am missing something we don't have the necessary info. Both cases look the same -- we hit a different tag. There may only be a small trailer for kmalloc-allocated objects that is painted with a different tag. I don't remember if we actually use a different tag for the trailer. Since tag mode granularity is 16 bytes, for smaller objects the trailer is impossible at all. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel