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 AFEAFC433DB for ; Wed, 13 Jan 2021 16:33:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5960E23442 for ; Wed, 13 Jan 2021 16:33:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5960E23442 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 D4A5F8D002E; Wed, 13 Jan 2021 11:33:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D20D26B0165; Wed, 13 Jan 2021 11:33:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C36108D002E; Wed, 13 Jan 2021 11:33:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0117.hostedemail.com [216.40.44.117]) by kanga.kvack.org (Postfix) with ESMTP id AE4AE6B0164 for ; Wed, 13 Jan 2021 11:33:09 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 70F81824556B for ; Wed, 13 Jan 2021 16:33:09 +0000 (UTC) X-FDA: 77701296498.22.bead59_350eca72751f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 495DB180721AC for ; Wed, 13 Jan 2021 16:33:09 +0000 (UTC) X-HE-Tag: bead59_350eca72751f X-Filterd-Recvd-Size: 5991 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 16:33:08 +0000 (UTC) Received: by mail-qk1-f171.google.com with SMTP id b64so2431226qkc.12 for ; Wed, 13 Jan 2021 08:33:08 -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:content-transfer-encoding; bh=Yukq8DLGoUwetcyUpU1xVWQNvOKdjhm4xJiehIsqbBA=; b=YGT1jcFIluAWJW2FDHcPmAosrpToO/jK0CvjYfbSOS+Tqmlfv5EjHK1Da1q5FGX8zs jhXMkLMMa/VuTzv/tvzAI+KNlQrjWnhu9GfvG1EHWoiQstkQMpUwmtSAlZa00LJdsdqY UxbpZFG0JlKscgGRIYZe3VPVnIggyHtm0uUPbFBIemWWvXVCBWQj17+Mv9EvMaYPrwIM A7PiTJj0rRZHVIrE0cgBVNWDyhHCuwTSVeyhJ56K4vCD1o/ZOvRxY0yXjtRBUFqg50I6 1WqqNEpdgzmJJ1Dr4pl0P4kjqSNgwXnwkzhgUXzkGhChB6iasZweauR5Zyg3KdmT5mGn XUbA== 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:content-transfer-encoding; bh=Yukq8DLGoUwetcyUpU1xVWQNvOKdjhm4xJiehIsqbBA=; b=ZOVnciRLX2JKE1MFrDkmjjUjmM9jzezuTNKrHlL3kuzIQZUmRS5dqHiTTZJh6aFGdN fS5uVbGWvm++w0jRqwOpkFwms8QU6Q8OD4dH7ikOep4GjHRxY4TK8DgUOACrCHNxIwUA /xe/gNbBU2Zb/L3RrCcZeXYb5xgw7XTGY/EjyWasW8D0MP66M0PFXbLycvGoDgbvzYm7 LFi3zorkw0j9HM2akHcYQhn6UhAfZEvZEw75U8i2SscyDWdzaBOlIitDaI5/AoiniQaX E77aBNzAQxKVrcwfDWSPMLxyrMWB6pKG069NgtvZeYFj5IhZr81tlJH9Uxqeua+kgsFi CXLA== X-Gm-Message-State: AOAM530CapY6VeHjuZU8dyNVTgUr/EEL3n1klotEeNw7HeL2L2pJd4rW JUKbXQgRSsZ4zG5BxlsXfxyiC3PxcpFreejfDutEiA== X-Google-Smtp-Source: ABdhPJx7f/7Y7/PbylHk8TCYLor6Xb5GsG6LVEIjHX5o6sAkN9BT82botUdw7znicMa4tS6YdlAkVgj3T+jDibV/OBw= X-Received: by 2002:a37:a747:: with SMTP id q68mr2927473qke.352.1610555587689; Wed, 13 Jan 2021 08:33:07 -0800 (PST) MIME-Version: 1.0 References: <1b884616c85091d6d173f7c1a8647d25424f1e7e.1610554432.git.andreyknvl@google.com> In-Reply-To: <1b884616c85091d6d173f7c1a8647d25424f1e7e.1610554432.git.andreyknvl@google.com> From: Alexander Potapenko Date: Wed, 13 Jan 2021 17:32:55 +0100 Message-ID: Subject: Re: [PATCH v2 09/14] kasan: adapt kmalloc_uaf2 test to HW_TAGS mode To: Andrey Konovalov Cc: Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , Marco Elver , Andrew Morton , Will Deacon , Andrey Ryabinin , Peter Collingbourne , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev , Linux ARM , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Wed, Jan 13, 2021 at 5:22 PM 'Andrey Konovalov' via kasan-dev wrote: > > In the kmalloc_uaf2() test, the pointers to the two allocated memory > blocks might happen to be the same, and the test will fail. With the > software tag-based mode, the probability of the that 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 16 attempts at generating different tags for the tag-based > modes. > > Link: https://linux-review.googlesource.com/id/Ibfa458ef2804ff465d8eb0743= 4a300bf36388d55 > Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko > --- > lib/test_kasan.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/lib/test_kasan.c b/lib/test_kasan.c > index 283feda9882a..a1a35d75ee1e 100644 > --- a/lib/test_kasan.c > +++ b/lib/test_kasan.c > @@ -382,7 +382,9 @@ static void kmalloc_uaf2(struct kunit *test) > { > char *ptr1, *ptr2; > size_t size =3D 43; > + int counter =3D 0; > > +again: > ptr1 =3D kmalloc(size, GFP_KERNEL); > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); > > @@ -391,6 +393,15 @@ static void kmalloc_uaf2(struct kunit *test) > ptr2 =3D 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 16 attempts at generating different tags. > + */ > + if (!IS_ENABLED(CONFIG_KASAN_GENERIC) && ptr1 =3D=3D ptr2 && coun= ter++ < 16) { > + kfree(ptr2); > + goto again; > + } > + > KUNIT_EXPECT_KASAN_FAIL(test, ptr1[40] =3D 'x'); > KUNIT_EXPECT_PTR_NE(test, ptr1, ptr2); > > -- > 2.30.0.284.gd98b1dd5eaa7-goog > > -- > You received this message because you are subscribed to the Google Groups= "kasan-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an= email to kasan-dev+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgi= d/kasan-dev/1b884616c85091d6d173f7c1a8647d25424f1e7e.1610554432.git.andreyk= nvl%40google.com. --=20 Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Stra=C3=9Fe, 33 80636 M=C3=BCnchen Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg