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=-16.6 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT 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 79847C433DB for ; Wed, 13 Jan 2021 16:22:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2894C2313C for ; Wed, 13 Jan 2021 16:22:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2894C2313C 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 507178D0077; Wed, 13 Jan 2021 11:22:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4DD288D0076; Wed, 13 Jan 2021 11:22:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3CF408D0077; Wed, 13 Jan 2021 11:22:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0045.hostedemail.com [216.40.44.45]) by kanga.kvack.org (Postfix) with ESMTP id 2517B8D0076 for ; Wed, 13 Jan 2021 11:22:09 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E121D824556B for ; Wed, 13 Jan 2021 16:22:08 +0000 (UTC) X-FDA: 77701268736.20.bomb90_070aab52751f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id AB72F180C07AF for ; Wed, 13 Jan 2021 16:22:08 +0000 (UTC) X-HE-Tag: bomb90_070aab52751f X-Filterd-Recvd-Size: 4943 Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 16:22:08 +0000 (UTC) Received: by mail-qk1-f202.google.com with SMTP id q7so1701005qki.16 for ; Wed, 13 Jan 2021 08:22:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=AYU8RiBMDoH8LqbcE5Bsl4HVhMUvTlIJH5ygAkCw1uo=; b=sK8w4/7+bFlRogPbbwsMzQZGIyJaLfruaGQq1NyTZoKuRV8kkSuJYSTajYObeb5BhB j5B0aO7AYdjA/X7h/55sqn/8eJ3L98sNWt0usa6ZKYeOu2Bu8A8yH7kyedWNIqOTdyrK 7CS2smIDxfMMUEU7+r5sUDMO6AU5v0dCsYRHfTm3snA0bdsu5Ihim6C+QorZWPCWRicw Qj0JSwE5rlQKQmMPulAWV7Qb3+JbCq4sEEKb5k2sIlwQpL768ladXTwg9PV88ssTPbGC ghBTXXxjBAM5WcVjFFrHK6/Ml9RcY1l1gksA/BDruf31RYSvG4PiPSYoNNlzTZKxcYQA r4hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=AYU8RiBMDoH8LqbcE5Bsl4HVhMUvTlIJH5ygAkCw1uo=; b=DWJHtFCWjVCWtg2IZ8jLGX5h46NtUJfXegA6V94cw7A24ChkvHbUr8qbVQP3y8K1+F /qU9rWOUSmBPyfuZ/qYTHF5V5ffD2IJqf9RxuuXV7vlFfUywujA3CQ/xaoI1CQwmYeGQ BaoMXtRk8j1R/FR/omjqQDQfp2FMdlQZwEyYedBUKVB/1nTscyhGMik0wuDxj/GTKY0q usvHamOmeF0SGwNG3DouvYFurDClddoSP92GqAnOrdQ/M5yIv6m4y5plrXrOJ/0tR/U4 1ak69QDE1MmcgnfVFXJkc74Rwa57by7sRoLpF9XDjwiUsPz3GemfGYA8M2Kme2dBDAlD bB7g== X-Gm-Message-State: AOAM533N2rsZf30WCZX0zGw3GMPdFqdlv9JBoDlyRD5pCACIO25xmiiO IvUNQs0o1s2DX517J643eDA4ChKd0YyiI/xs X-Google-Smtp-Source: ABdhPJzAk8lbAA2oeZ/5LkBz1EFW7U5GssDQ0xOiO1RZBV9k+c3FKD7ufLGB+DknkADCLYH+T0s3FGzAptjFgwj6 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:fe91:: with SMTP id d17mr3133660qvs.50.1610554927401; Wed, 13 Jan 2021 08:22:07 -0800 (PST) Date: Wed, 13 Jan 2021 17:21:36 +0100 In-Reply-To: Message-Id: <1b884616c85091d6d173f7c1a8647d25424f1e7e.1610554432.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH v2 09/14] kasan: adapt kmalloc_uaf2 test to HW_TAGS mode From: Andrey Konovalov To: Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Andrew Morton , Will Deacon , Andrey Ryabinin , Peter Collingbourne , 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, Andrey Konovalov 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: 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/Ibfa458ef2804ff465d8eb07434a300bf36388d55 Signed-off-by: Andrey Konovalov --- 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 = 43; + int counter = 0; +again: ptr1 = kmalloc(size, GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); @@ -391,6 +393,15 @@ 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 16 attempts at generating different tags. + */ + if (!IS_ENABLED(CONFIG_KASAN_GENERIC) && ptr1 == ptr2 && counter++ < 16) { + kfree(ptr2); + goto again; + } + KUNIT_EXPECT_KASAN_FAIL(test, ptr1[40] = 'x'); KUNIT_EXPECT_PTR_NE(test, ptr1, ptr2); -- 2.30.0.284.gd98b1dd5eaa7-goog