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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FD67C433F5 for ; Mon, 21 Feb 2022 11:20:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A584C8D0002; Mon, 21 Feb 2022 06:20:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A084D8D0001; Mon, 21 Feb 2022 06:20:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D0068D0002; Mon, 21 Feb 2022 06:20:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0056.hostedemail.com [216.40.44.56]) by kanga.kvack.org (Postfix) with ESMTP id 7BB368D0001 for ; Mon, 21 Feb 2022 06:20:35 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 3E2FA181CC405 for ; Mon, 21 Feb 2022 11:20:35 +0000 (UTC) X-FDA: 79166544030.20.AED387C Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) by imf10.hostedemail.com (Postfix) with ESMTP id B78B9C0009 for ; Mon, 21 Feb 2022 11:20:34 +0000 (UTC) Received: by mail-yb1-f177.google.com with SMTP id j2so33731750ybu.0 for ; Mon, 21 Feb 2022 03:20:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NjKrfGzLGlEon1RMte/jjmVRaWvN7F73qDlwuyQ/zYs=; b=KVnvCl9SXCIAFVXXcrWnELc0cbmTmjsCJFTP40Wnwx3bappQWSCGC0co2cN21AFisu zFGQutfRR4Y8cw6T1m4WpD8Qg6RJH06P6j3XcRYINj1Nh7AdctBuHylH6+n2z4IOexZ1 ulRlDRzSqrJoOjoNIlAcyaDs40H16vzvdNfLeW50Zz5yEdnWIgwNudBQDDfNuRrJUYre u+X+150q1gG3VgHLY3ndJ+YXLDDYAk/3wnDZf4UlO9qK617hT/H5HMx0z6jUCtxp7d2I 0Hw4a2nJDDOUH6gL3eFbPKCUX0aVDLCi+7JkSnaOO+Owk+Bvr+hDPnjzLdbrHRO45wmh euEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NjKrfGzLGlEon1RMte/jjmVRaWvN7F73qDlwuyQ/zYs=; b=ZbdlzE1P5f3AbXyi4/Yfco5hFg6uU4xy0oWivOrQa+9x3G6crOStBoFeHFGpoOBZ4H pbRf7YhnaTXmR7uoy2v5PXvh1RB6bLvz1JSEuJDCbs6PValnVnI/HLj79ZC164iK+f5g zb05SGFkrep2QV1KIzhUxWtvIoMG5zitegx7/0oFVg33VVLrjZ7eCZF0ADrvuoZIIIRG eH6kPm43+pcLGhwXOQtzOnQrjytF553yo/k7U7DwJU0QsWY9i9nqUF7VdJZ8Vn296ZBo EirFposkJMsGsJpxp0O319IFIa4qUEiTqsjefXczJX3iwlBGHCfB+GqqfdmD2ydgTGWS 6w0g== X-Gm-Message-State: AOAM532YbsjUa6rhn7J+mb0LyNNxpIge3q9j1BCxPomVIWuvyP4i7rse R+wZPifC091KNbmtwCA68YLvSBJ+QZzAHkHwrc22lg== X-Google-Smtp-Source: ABdhPJykNMsrySTFXO/n9IosEJ7fJiemNoCPy7o5SFUUFfp950VVTfS0ryvWrIgF0b87z65j4cwVD6Lpqb/+Iv5G48s= X-Received: by 2002:a25:bb8d:0:b0:61d:aca6:8aa0 with SMTP id y13-20020a25bb8d000000b0061daca68aa0mr17780158ybg.609.1645442433890; Mon, 21 Feb 2022 03:20:33 -0800 (PST) MIME-Version: 1.0 References: <20220219012643.892158-1-pcc@google.com> In-Reply-To: <20220219012643.892158-1-pcc@google.com> From: Marco Elver Date: Mon, 21 Feb 2022 12:20:22 +0100 Message-ID: Subject: Re: [PATCH] kasan: fix more unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled To: Peter Collingbourne Cc: Andrey Konovalov , Kees Cook , Andrew Morton , linux-mm@kvack.org, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: B78B9C0009 X-Stat-Signature: fwf7wj53xya31m91n14jgq7c31dimq55 X-Rspam-User: Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=KVnvCl9S; spf=pass (imf10.hostedemail.com: domain of elver@google.com designates 209.85.219.177 as permitted sender) smtp.mailfrom=elver@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam05 X-HE-Tag: 1645442434-56109 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 Sat, 19 Feb 2022 at 02:26, Peter Collingbourne wrote: > > This is a followup to commit f649dc0e0d7b ("kasan: fix unit tests > with CONFIG_UBSAN_LOCAL_BOUNDS enabled") that fixes tests that fail > as a result of __alloc_size annotations being added to the kernel > allocator functions. > > Link: https://linux-review.googlesource.com/id/I4334cafc5db600fda5cebb851b2ee9fd09fb46cc > Signed-off-by: Peter Collingbourne > Cc: # 5.16.x > Fixes: c37495d6254c ("slab: add __alloc_size attributes for better bounds checking") > --- > lib/test_kasan.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/lib/test_kasan.c b/lib/test_kasan.c > index 26a5c9007653..3bf8801d0e66 100644 > --- a/lib/test_kasan.c > +++ b/lib/test_kasan.c > @@ -177,7 +177,8 @@ static void kmalloc_node_oob_right(struct kunit *test) > */ > static void kmalloc_pagealloc_oob_right(struct kunit *test) > { > - char *ptr; > + /* See comment in kasan_global_oob_right. */ > + char *volatile ptr; > size_t size = KMALLOC_MAX_CACHE_SIZE + 10; I think more recently we've been using OPTIMIZER_HIDE_VAR() to hide things from the compiler. Does OPTIMIZER_HIDE_VAR(ptr) right before the access also work in this case? I leave it to you which you think is cleaner - I'm guessing that we might want to avoid volatile if we can. > KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); > @@ -272,7 +273,8 @@ static void kmalloc_large_oob_right(struct kunit *test) > static void krealloc_more_oob_helper(struct kunit *test, > size_t size1, size_t size2) > { > - char *ptr1, *ptr2; > + /* See comment in kasan_global_oob_right. */ > + char *ptr1, *volatile ptr2; > size_t middle; > > KUNIT_ASSERT_LT(test, size1, size2); > @@ -304,7 +306,8 @@ static void krealloc_more_oob_helper(struct kunit *test, > static void krealloc_less_oob_helper(struct kunit *test, > size_t size1, size_t size2) > { > - char *ptr1, *ptr2; > + /* See comment in kasan_global_oob_right. */ > + char *ptr1, *volatile ptr2; > size_t middle; > > KUNIT_ASSERT_LT(test, size2, size1); > -- > 2.35.1.473.g83b2b277ed-goog >