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=-24.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1,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 1B14CC433DB for ; Tue, 12 Jan 2021 13:39:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9637822285 for ; Tue, 12 Jan 2021 13:39:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9637822285 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 ECE5C6B0205; Tue, 12 Jan 2021 08:39:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E7F0D8D00A6; Tue, 12 Jan 2021 08:39:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D95608D0090; Tue, 12 Jan 2021 08:39:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0087.hostedemail.com [216.40.44.87]) by kanga.kvack.org (Postfix) with ESMTP id C44206B0205 for ; Tue, 12 Jan 2021 08:39:11 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 927411EE6 for ; Tue, 12 Jan 2021 13:39:11 +0000 (UTC) X-FDA: 77697229302.02.hope18_1a003c927515 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 7866E10097AA2 for ; Tue, 12 Jan 2021 13:39:11 +0000 (UTC) X-HE-Tag: hope18_1a003c927515 X-Filterd-Recvd-Size: 5294 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Jan 2021 13:39:10 +0000 (UTC) Received: by mail-wm1-f42.google.com with SMTP id y23so2159997wmi.1 for ; Tue, 12 Jan 2021 05:39:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=/gH3LsuYOCe5YajoCQBV3RVdjva6zoqEdCztkktjq5s=; b=OgC9q6GbZVYgSYwfRsnVA97mDQQb5YryYDbuZFTON5T2+M9PQsgMqupSXeu0/sx8vE 2zWqyL+iSWOdmSaRkHou9pJTUuxus2fEik2ecgEwiuWw5zzGcQ28thXkiOlB4HhfG0iq VStgmplVPo5egyk/r/tR1xjTbFfUrYpu8GcRzL0dQnKVtgTmwzwVOlE8KQKr4f2EvBxK 0AJ2sd4V3RBDsd6j784bCQIXxNo1It4nwn3islj3jGxvYcvUffFJLHibxYKdTigsyY3w r9ICUv94Kf7T9EtrWaC4egNPUgg035qOOU4HIF1/qJoD5h/HRAQEoeBkKyEwP6ZETzZV 6M5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=/gH3LsuYOCe5YajoCQBV3RVdjva6zoqEdCztkktjq5s=; b=dntgGb1hOgNafFv3QmqnUBsmqOiG0Zbg/MyXb7f/GNx1kHGCZuptGEp/PewWHbOteI +Qtyi/Ccwg4d4Rv6DnthUabjXO3YLVM0GG7EPtURAgyk6jfC3rlAEqm17FvKp8LfNYHL EoM4CqsUuTE6Uj1aQzh+MYEhXbOWxZaKN/MIw8OtX91aaJ55nLLrQKSMvD5sz01rprT1 YriDYWMFsJ4pStzju/H63rn9kcaY7SNYsBXyqS/KNOtpjh7nEZ5oIiZm7H/57Fldzy5s 4FeXduI33IqWvGaDzgbEiMvidwW19i4QnttgSDJDuFopgabDniAw19uVlNp2JGzUvMgO NpEA== X-Gm-Message-State: AOAM530lruRG0mh3tsXH6LcacM219wxeh0pB4TBjIyUqCapu0HAfkiTd BmpNkZj7NJJCKb7ptJzo5yTsHw== X-Google-Smtp-Source: ABdhPJwfJ5xv+7Q8U7WOU65hNyU1wtHLGDZ9L7S4xnjkAKIEuZTC299bYdx3zqbgyyZ9nUOw/LBEuA== X-Received: by 2002:a1c:c204:: with SMTP id s4mr3615203wmf.73.1610458749636; Tue, 12 Jan 2021 05:39:09 -0800 (PST) Received: from elver.google.com ([2a00:79e0:15:13:f693:9fff:fef4:2449]) by smtp.gmail.com with ESMTPSA id l20sm5038940wrh.82.2021.01.12.05.39.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 05:39:08 -0800 (PST) Date: Tue, 12 Jan 2021 14:39:03 +0100 From: Marco Elver To: Andrey Konovalov Cc: Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Andrew Morton , Will Deacon , Andrey Ryabinin , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 08/11] kasan: adopt kmalloc_uaf2 test to HW_TAGS mode Message-ID: References: <9a4f47fe8717b4b249591b307cdd1f26c46dcb82.1609871239.git.andreyknvl@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9a4f47fe8717b4b249591b307cdd1f26c46dcb82.1609871239.git.andreyknvl@google.com> User-Agent: Mutt/2.0.2 (2020-11-20) 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 Tue, Jan 05, 2021 at 07:27PM +0100, Andrey Konovalov wrote: > In the kmalloc_uaf2() test, the pointers to the two allocated memory > blocks might be the same, and the test will fail. With the software > tag-based mode, the probability of the that happening is 1/254, so it's > hard to observe the failure. For the hardware tag-based mode though, > the probablity is 1/14, which is quite noticable. > > Allow up to 4 attempts at generating different tags for the tag-based > modes. > > Signed-off-by: Andrey Konovalov > Link: https://linux-review.googlesource.com/id/Ibfa458ef2804ff465d8eb07434a300bf36388d55 > --- > lib/test_kasan.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/lib/test_kasan.c b/lib/test_kasan.c > index b5077a47b95a..b67da7f6e17f 100644 > --- a/lib/test_kasan.c > +++ b/lib/test_kasan.c > @@ -375,7 +375,9 @@ static void kmalloc_uaf2(struct kunit *test) > { > char *ptr1, *ptr2; > size_t size = 43; > + int counter = 0; > > +again: > ptr1 = kmalloc(size, GFP_KERNEL); > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); > > @@ -384,6 +386,13 @@ static void kmalloc_uaf2(struct kunit *test) > ptr2 = kmalloc(size, GFP_KERNEL); > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); > > + /* > + * For tag-based KASAN ptr1 and ptr2 tags might happen to be the same. > + * Allow up to 4 attempts at generating different tags. > + */ > + if (!IS_ENABLED(CONFIG_KASAN_GENERIC) && ptr1 == ptr2 && counter++ < 4) > + goto again; > + Why do we even need a limit? Why not retry until ptr1 != ptr2? > KUNIT_EXPECT_KASAN_FAIL(test, ptr1[40] = 'x'); > KUNIT_EXPECT_PTR_NE(test, ptr1, ptr2); > > -- > 2.29.2.729.g45daf8777d-goog >