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=unavailable 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 D78F9C433B4 for ; Fri, 7 May 2021 02:59:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 541E6613E3 for ; Fri, 7 May 2021 02:59:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 541E6613E3 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 C839D6B0071; Thu, 6 May 2021 22:59:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C343D8D0002; Thu, 6 May 2021 22:59:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC1958D0001; Thu, 6 May 2021 22:59:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0020.hostedemail.com [216.40.44.20]) by kanga.kvack.org (Postfix) with ESMTP id 8DC7A6B0071 for ; Thu, 6 May 2021 22:59:55 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 440C15DDA for ; Fri, 7 May 2021 02:59:55 +0000 (UTC) X-FDA: 78112930350.14.ECE1ADE Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) by imf19.hostedemail.com (Postfix) with ESMTP id BE3CC90009EB for ; Fri, 7 May 2021 02:59:22 +0000 (UTC) Received: by mail-yb1-f175.google.com with SMTP id b131so10138047ybg.5 for ; Thu, 06 May 2021 19:59:54 -0700 (PDT) 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=/jyeEVDWCsJDK9WjnevEylhhMkY8rdV3C9LFNvXcKQQ=; b=XLGMlOmKZQf1wdAkiQjry4+JmGH0YYfwJibp+VuCfiEWY7dTIrkPxC0EL1+ViNqZEk jeVbG4Qs94DhxV/3JA5z0jfEZUYOhBENqMRZiHoJNy0jZVub8SHsHsnFIKMQusAxsIOj xywuMIOAnLVk5iILaYjg50+DD1gXZujVgKqUzpJgY37rG+DLBsM5cJr+ILXlfV6iNQbo PeNW4j/N0XE2a8mGlJBH4/b+WaZNmb8EqxG/SzA/L+i1kSobJQnJOIPcJsI/+8w6OZYb 8NRKdcty3iw6OnbeYRUp/jCEigwCYwOZu+9ZkIrL2Wgo5zk7LDxA2BaFszYGAT6I5ke0 5HIg== 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=/jyeEVDWCsJDK9WjnevEylhhMkY8rdV3C9LFNvXcKQQ=; b=cleT8UHcdSuqgfwzyNeh0PmRtUipHcmt3EhI/yF3F4hjgXbseJuklWd1LgwrOMlazm r2M7By4iqdOCi44dK5O9HIzhqVulkEoDr8DpltapOoBauMxb75Ln/IrVfwPT3P25Rmpv l+o5/3hIf9pMva8A/2X0AiAico2SGNm4wJcC6wSiUreKqh/xIjBMacCqyuhOaFuAtz/o Zcfk9NmtR52Av4tzEAVTt4lSeGfA0AX/GGOVOKgr+Tw5FiRL1R7230LQkuvV90QatB4c AjLJlZoObQfnSTaCQIUvT2wepk+OImHJx7eu1PsXRKWEdMVQjc0ah8Ku09KKP/C1RCQh IiHQ== X-Gm-Message-State: AOAM5311iAk1sf2bTK1hbEtJFo5+qg9NJY5dCVR0MNBk5+c55s2VSTYh +U/dZ02ywF5Advx9KqrVBWSL+SGf3Nv9dwDxJ+lkZQ== X-Google-Smtp-Source: ABdhPJzAU9HJOs0EbYseAm14OduSCR8BddYeCmVyRUFDX63L8L7sDVv3sqA4oLGOsl8ttMGrqoxFeamcoPgu0wKi8Lc= X-Received: by 2002:a25:cccd:: with SMTP id l196mr10927574ybf.26.1620356394027; Thu, 06 May 2021 19:59:54 -0700 (PDT) MIME-Version: 1.0 References: <20210506212025.815380-1-pcc@google.com> In-Reply-To: From: Peter Collingbourne Date: Thu, 6 May 2021 19:59:28 -0700 Message-ID: Subject: Re: [PATCH] kasan: fix unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled To: Andrey Konovalov Cc: Alexander Potapenko , George Popescu , Elena Petrova , Evgenii Stepanov , Andrew Morton , Linux Memory Management List , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: BE3CC90009EB Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=XLGMlOmK; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of pcc@google.com designates 209.85.219.175 as permitted sender) smtp.mailfrom=pcc@google.com X-Rspamd-Server: rspam04 X-Stat-Signature: 4jaqa1sp3abxxiyyseia86ox18eexs8h Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf19; identity=mailfrom; envelope-from=""; helo=mail-yb1-f175.google.com; client-ip=209.85.219.175 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620356362-467326 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 Thu, May 6, 2021 at 4:58 PM Andrey Konovalov wrote: > > On Fri, May 7, 2021 at 1:47 AM Peter Collingbourne wrote: > > > > On Thu, May 6, 2021 at 3:12 PM Andrey Konovalov wrote: > > > > > > On Thu, May 6, 2021 at 11:20 PM Peter Collingbourne wrote: > > > > > > > > These tests deliberately access these arrays out of bounds, > > > > which will cause the dynamic local bounds checks inserted by > > > > CONFIG_UBSAN_LOCAL_BOUNDS to fail and panic the kernel. To avoid this > > > > problem, access the arrays via volatile pointers, which will prevent > > > > the compiler from being able to determine the array bounds. > > > > > > > > Signed-off-by: Peter Collingbourne > > > > Cc: stable@vger.kernel.org > > > > Link: https://linux-review.googlesource.com/id/I90b1713fbfa1bf68ff895aef099ea77b98a7c3b9 > > > > --- > > > > lib/test_kasan.c | 14 ++++++++------ > > > > 1 file changed, 8 insertions(+), 6 deletions(-) > > > > > > > > diff --git a/lib/test_kasan.c b/lib/test_kasan.c > > > > index dc05cfc2d12f..2a078e8e7b8e 100644 > > > > --- a/lib/test_kasan.c > > > > +++ b/lib/test_kasan.c > > > > @@ -654,8 +654,8 @@ static char global_array[10]; > > > > > > > > static void kasan_global_oob(struct kunit *test) > > > > { > > > > - volatile int i = 3; > > > > - char *p = &global_array[ARRAY_SIZE(global_array) + i]; > > > > + char *volatile array = global_array; > > > > + char *p = &array[ARRAY_SIZE(global_array) + 3]; > > > > > > Nit: in the kernel, "volatile" usually comes before the pointer type. > > > > That would refer to a different type. "volatile char *" is a pointer > > to volatile char, while "char *volatile" is a volatile pointer to > > char. The latter is what we want here, because we want to prevent the > > compiler from inferring things about the pointer itself (i.e. its > > array bounds), not the data that it refers to. > > I see. This is unusual. I'd say this needs to be explicitly explained > in the commit message, as well as in a comment in the code. Done in v2. Peter