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=-23.3 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_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 53BB0C433DB for ; Tue, 12 Jan 2021 20:05:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BD80A22CAD for ; Tue, 12 Jan 2021 20:05:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BD80A22CAD 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 3B7016B00C1; Tue, 12 Jan 2021 15:05:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3414A6B00C3; Tue, 12 Jan 2021 15:05:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 208F16B00C4; Tue, 12 Jan 2021 15:05:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0214.hostedemail.com [216.40.44.214]) by kanga.kvack.org (Postfix) with ESMTP id 0BA4B6B00C1 for ; Tue, 12 Jan 2021 15:05:31 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id BDA1D824556B for ; Tue, 12 Jan 2021 20:05:30 +0000 (UTC) X-FDA: 77698202820.13.twig82_3d0976e27518 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 5F29918140B69 for ; Tue, 12 Jan 2021 20:05:30 +0000 (UTC) X-HE-Tag: twig82_3d0976e27518 X-Filterd-Recvd-Size: 5162 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Jan 2021 20:05:29 +0000 (UTC) Received: by mail-pl1-f176.google.com with SMTP id b8so2024361plx.0 for ; Tue, 12 Jan 2021 12:05:29 -0800 (PST) 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=zL6WgU5Xs4gBKlOeTyyYJxfsUDm2s7KXGqsTMwbacGQ=; b=wPsXp3Ms+9EG1G2s8Vph8Xwk1B8VZYND0uude8zcWLUg4+owazggV+vpjAf+tzTgdC W8z3dx3wqpnqzj+clMUqZ5w32P12JqYLB7GGqKQS20jYZUYXLbBPX+nWFcoS+ytaCgfa ps9VzSsZn4MKGUaHATXr6ILJ1S41IjhM9JP1Z6sZj2SmTTb1Y0zl640U45qm+Bo5Hu4M U/ysBYw5lPnASZUCeG4IppqXWhMinJNkXvYVH8dIrQQBUgOFXvVB1SFZuyquAdrPSXXZ IIXjjQrJrG1GtenX2Ohzzx4r5y0UQTJQV50f04e+n/urAEsIXZxxDOldEga5JSxuu6WB U+MA== 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=zL6WgU5Xs4gBKlOeTyyYJxfsUDm2s7KXGqsTMwbacGQ=; b=JS/OMHCfu6L9Lj8QGW9aUsMPo83Zw0pOpUqd8p9GlXzfX9Zc/aD1sC23cCjvGoWmuO vUo6SyFwsICErChpkC0nzFsa1VRDB4Qt9M6XGVUCTFc/B2D/BWIseZncsm0tuWdYDrv2 4tS9m4MdX5XTXYkF0MXkZZyC74rYuqd9aYROjBo/efV+QRDCfsOUuC4yrqCfkhbfbfG7 F+3yO8FSCBr3SBE6zMU0WXaKShwNwX+U+SoR8QPU8/bUuYWcxhh26+eKY/8uAiqEBi/E f6htdYv2gAdYRnobSVfXZNdAOXqrfPKNq2HD6U3ZTS8GbAZbhujyEZwiqHRT8y1O3rzF pH4g== X-Gm-Message-State: AOAM5327Lb3NxYN1zAnhlYIhNthT/U5fQ7igdifrksixMwAWj19ZY+Jd KTInL+kAi+MlM5E7Ok7okkYpbkKOReY7x6EWVQuo+g== X-Google-Smtp-Source: ABdhPJwYQTFzqikue18gpW9umL0WcFvbyoNK1QEUuE6kEZf85DaGVaLKgmWEvox10SpVBdo9Ni4n/BW0mjJiejzq8OY= X-Received: by 2002:a17:90b:1087:: with SMTP id gj7mr814111pjb.41.1610481928938; Tue, 12 Jan 2021 12:05:28 -0800 (PST) MIME-Version: 1.0 References: <9a4f47fe8717b4b249591b307cdd1f26c46dcb82.1609871239.git.andreyknvl@google.com> In-Reply-To: From: Andrey Konovalov Date: Tue, 12 Jan 2021 21:05:18 +0100 Message-ID: Subject: Re: [PATCH 08/11] kasan: adopt kmalloc_uaf2 test to HW_TAGS mode To: Marco Elver Cc: Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Andrew Morton , Will Deacon , Andrey Ryabinin , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev , Linux ARM , Linux Memory Management List , LKML 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 Tue, Jan 12, 2021 at 2:39 PM Marco Elver wrote: > > 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? Then the test will hang if it's failing. Let's do up to 16 attempts, it should be more than enough in practice. Thanks!