From patchwork Tue Jan 5 18:27:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12000083 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=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, 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 16E8BC433E6 for ; Tue, 5 Jan 2021 18:31:54 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 B09E822D57 for ; Tue, 5 Jan 2021 18:31:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B09E822D57 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+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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=DVTOmIHsd0jxdOoQM0cbeXlRMqQNZ9Uqf97wiAscCKc=; b=0uBtwVlkw3A2Sb8fGxJeCLIgD gGxQb5ERQ/slFb+hc4Zqrn/zEZUaZIkpjSAAYfhZahJXq3yBayhnPyoNaloQ+YGR2mZ5toLijU9dF 4++FGzlbGatc4LyPmdbGfZ88nvaX/0YGLC9jYL+IZ6Rb4KoDCThiSKp06KJ9PiyDt+/eR0VaMR1NA OaTGISUL910xtJggGA+5nKe44UF3M606c6mHlm49wZML7kWF6y2JKlTJP4PeO5NL1e2dM0GgPvzdD C77nzfGWg8LISUqKJxt4XLxlMibn239mO2OcHhb4c+zCcKwy390uhAmMQ/yqANIvoNqQfblcLIAkE 45xpMX+Xg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kwr4s-0007Kb-0O; Tue, 05 Jan 2021 18:29:06 +0000 Received: from mail-qt1-x849.google.com ([2607:f8b0:4864:20::849]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kwr4E-000748-SP for linux-arm-kernel@lists.infradead.org; Tue, 05 Jan 2021 18:28:31 +0000 Received: by mail-qt1-x849.google.com with SMTP id a11so399143qto.16 for ; Tue, 05 Jan 2021 10:28:24 -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=KRXpzoAkHqv6MlP+Q/fGJx09RWdmlAlIVzxtUVuwpVM=; b=Fb3Q6nCT57b+4oec7OslcxN7gAFtRYQJmn5KExlMD4IEMm/aMW+oydy50jC6i5Fi3I ozZK5SylYmuAGCpYHep2PY3CQIMgXQyCS1mNWz9BwzWk0h+zMnMBr8jfu/p58hR8voeQ Ox5qAB7CTTFDHlWYDh0sSWQjQlZcEUcI8dH0dQ/CMbIk6Vy32+JURCXcIr2jckjFJh+T DhGfUfCVDtASvkaZsJVSE+CJExCAjNej+oEOmZTzKwkYai4t5e6Cpz7OZK0EKqG241b/ V8DEmXfKegA/XsMJ6HE3j+YTV7XG3Zj0DNmo9rA3kz8kLKwyCoe1BGAFntOuNaAR6HVq wl2A== 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=KRXpzoAkHqv6MlP+Q/fGJx09RWdmlAlIVzxtUVuwpVM=; b=XH9/Tf3Wh7V6g7zPnEEfB+2W91vYOdLjfwGuZTjG9ikc6Ea6zTwCuX5539/hEcDmTz hKb2Rqr9OcwkUdZ0ePjTSyE0tlPqoTJSCYvLLfOzDX4M5cxOfoEWfV8GSKh/+DLvxK0W y39SHl56TglXTYHjVrBv2q/PLOEHGKmchOJIvR4LaOPY8wIC/Hi00CEiyWviMwSxWSLe pvQSB825hNbAeUf2zZk53h8aBc1fUE5L1pjk1ogGllHD63TaMIPBieav4UzwYqsgEm78 Wsxnsg/+XCpC2vTLqwAZXD1N+aVYxYo/kTyYoYunpaz3Q5TgJ9K5kMLXSRqqbs0UB+y8 HEAQ== X-Gm-Message-State: AOAM531HUYyaE0+ndQT3985ZgGyOR59/GmEJ0PQF6ODBHi2lnU2EVk2+ 3bfGZaYfsXMP/cN8XS2NFG8WPsjZCb4SXgR1 X-Google-Smtp-Source: ABdhPJxT90gB7YILrKMHoRfd8xi56D/8zCgNctAzqvpw1JEB+6Jc2/mpZafdl3bgFb9he5+PwmsqWLivJbSsh8PS X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:b38b:: with SMTP id t11mr470993qve.58.1609871303254; Tue, 05 Jan 2021 10:28:23 -0800 (PST) Date: Tue, 5 Jan 2021 19:27:52 +0100 In-Reply-To: Message-Id: <9a4f47fe8717b4b249591b307cdd1f26c46dcb82.1609871239.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [PATCH 08/11] kasan: adopt kmalloc_uaf2 test to HW_TAGS mode From: Andrey Konovalov To: Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Marco Elver X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210105_132826_989471_2BFE6110 X-CRM114-Status: GOOD ( 13.82 ) 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: Branislav Rankov , Andrey Konovalov , Kevin Brodsky , Will Deacon , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Andrey Ryabinin , Andrew Morton , Evgenii Stepanov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; + KUNIT_EXPECT_KASAN_FAIL(test, ptr1[40] = 'x'); KUNIT_EXPECT_PTR_NE(test, ptr1, ptr2);