Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp15145pxb; Tue, 12 Jan 2021 18:32:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJx00VZ7/unluELmPBkFbimvWaYfRQGTGvS/ekV/tacuDY7zjacNf9wTt6DOUWXobNGbgIOb X-Received: by 2002:a05:6402:513:: with SMTP id m19mr10376edv.244.1610505160379; Tue, 12 Jan 2021 18:32:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610505160; cv=none; d=google.com; s=arc-20160816; b=Y1X7+u8z8uQTk6uu6J98tdXoZPW/hpJkUP9BxIzbFM1NncY1mAFZKHejkFL9DcgLht 4kDaJd/HGuQTk/LYso0FE3WX7Bdfznc3fA+lyN49Tc37hOxFhlb48jYFupJv46AXskHZ Hv1SxPsJv3ERnczIE0TFraG7C1likIpm1kxxV9Mz03BNpPB1dHWdkoN391dFNB2bwuVy Jlp9pW7wcm1B+TUtslRT4JIUGWhK+tnOPxBNjQAAJupenq0IWMEvZOWJB6TuP8OrypWR 4LL4yR6+XDV2qbAP45DFYCls+IKTS6JQHQNqofMrjwkdFomJu5YRsbUhnkKOrysVXD7P hUgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=pMt208i988Aj1RV+YWcUlsqzon7o0ifo6LZ2mK0qEq0=; b=Ul9/9M4DqiYLTfd85jZn1rmzDAI6R/dTRP1Fd5p7gbaR1n8b+lOUeaH0z5bMwJWqOI C2J1pg5U9X4JUmCNElpyjgmlzUVY3M1wl7NeVmSy4k8WAByNI+4nABotBgw0IJPm1N/x N8NCCO9E9yY+hF66lilmceMxlXVEQRpfjl9uP2LPAQ0x3nIntQVDgePiQ2yFNoPZkdIr rIVZR5iBfFH8d4MFwE6ZGrOoq5qAE8cZvrfnOgrdb3rrMZTX6TBTGqfQ2AzZIuH6K6Tb ZJcABI+UppASmCZ48oiLS23ekLnw7YLQTKEwCbKrg76N0Bp96jvoBNMwjruCGlnOl+Ao dHEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hp5afakN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x13si262658ejb.243.2021.01.12.18.32.16; Tue, 12 Jan 2021 18:32:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hp5afakN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437269AbhALVeR (ORCPT + 99 others); Tue, 12 Jan 2021 16:34:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436671AbhALUHs (ORCPT ); Tue, 12 Jan 2021 15:07:48 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2209C061795 for ; Tue, 12 Jan 2021 12:07:07 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id p12so2290942pju.5 for ; Tue, 12 Jan 2021 12:07:07 -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; bh=pMt208i988Aj1RV+YWcUlsqzon7o0ifo6LZ2mK0qEq0=; b=hp5afakNd2d/FQoQpixyj3+dET0KAs/17uAZVG2pt5rAFbU6WZBkW/T0x4f5Gwu0rF zVN+Ck9CcaN4f7yG+3ctQS1OCckqVyxGKNe/NL+mMblv6IdAJ8EYWnioEfhdVoJrb+zg jwPFQR87TwuAPE1J9s9t0JSpwYAvlQE2Z96giLtFUHgqvklZhu3buAnwiINDF6nAqy8r maxUiS6HPd87hiGmj9YyUz23qOlrjdNH/0Ab6y/uGq26aFj4vzS8skOfh5jOLRldoHgs LlDnU/6XEb0LNfs1eKaW9Uj+CGSFM951EH0Qm87MTYfrhqsoTYwXrz1HwydVZqVKVWEG D8zQ== 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=pMt208i988Aj1RV+YWcUlsqzon7o0ifo6LZ2mK0qEq0=; b=fhUG+CMaTaw/cBsQ992VKjW7qZLSgeG06MQR7n7MUkpBX/fFNG0wYTcHO9zQsJCs6f f939oGeoTRkbrm7V5jxPY1tC5MI9AhbJcAVnt5mS19gPZ5VWzHPBkaLjFoO60JUD3Gza DxCege2zrNmrv5R1ZKcjHUUB7NvsCkz+ZUs2zVUf0BFpnuZE9Ct2stKyMkL/rK3XTG/I LOS091TQourXAfEgbhyISsNAW/on4Xs+u2r7pycqtahB2H7mYG/vzGFKJC4/yGGiCGKF AB1/CV7KxL1X2zPKpn1CJaCSBOe8jTEmfZ9ICapGule35xTXRufOtahIS/eG8lvMKYOE sr5g== X-Gm-Message-State: AOAM531uQPe6apVzHUNkdtc7D9t6iR594WjuKIUzj71Ag4YEffQB/RSa Ka/m/GRkROqOVmQ+FMj95SzDY7ZItz4CXSSKR/pf+A== X-Received: by 2002:a17:90b:350b:: with SMTP id ls11mr844230pjb.166.1610482027266; Tue, 12 Jan 2021 12:07:07 -0800 (PST) MIME-Version: 1.0 References: <0c51a7266ea851797dc9816405fc40d860a48db1.1609871239.git.andreyknvl@google.com> In-Reply-To: From: Andrey Konovalov Date: Tue, 12 Jan 2021 21:06:56 +0100 Message-ID: Subject: Re: [PATCH 09/11] kasan: fix memory corruption in kasan_bitops_tags test To: Alexander Potapenko Cc: Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , Marco Elver , Andrew Morton , Will Deacon , Andrey Ryabinin , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev , Linux ARM , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 12, 2021 at 9:30 AM Alexander Potapenko wrote: > > On Tue, Jan 5, 2021 at 7:28 PM Andrey Konovalov wrote: > > > > Since the hardware tag-based KASAN mode might not have a redzone that > > comes after an allocated object (when kasan.mode=prod is enabled), the > > kasan_bitops_tags() test ends up corrupting the next object in memory. > > > > Change the test so it always accesses the redzone that lies within the > > allocated object's boundaries. > > > > Signed-off-by: Andrey Konovalov > > Link: https://linux-review.googlesource.com/id/I67f51d1ee48f0a8d0fe2658c2a39e4879fe0832a > > --- > > lib/test_kasan.c | 12 ++++++------ > > 1 file changed, 6 insertions(+), 6 deletions(-) > > > > diff --git a/lib/test_kasan.c b/lib/test_kasan.c > > index b67da7f6e17f..3ea52da52714 100644 > > --- a/lib/test_kasan.c > > +++ b/lib/test_kasan.c > > @@ -771,17 +771,17 @@ static void kasan_bitops_tags(struct kunit *test) > > > > /* This test is specifically crafted for the tag-based mode. */ > > if (IS_ENABLED(CONFIG_KASAN_GENERIC)) { > > - kunit_info(test, "skipping, CONFIG_KASAN_SW_TAGS required"); > > + kunit_info(test, "skipping, CONFIG_KASAN_SW/HW_TAGS required"); > > return; > > } > > > > - /* Allocation size will be rounded to up granule size, which is 16. */ > > - bits = kzalloc(sizeof(*bits), GFP_KERNEL); > > + /* kmalloc-64 cache will be used and the last 16 bytes will be the redzone. */ > > + bits = kzalloc(48, GFP_KERNEL); > > I think it might make sense to call ksize() here to ensure we have > these spare bytes. Calling ksize() will unpoison the whole object. I think it's OK to make assumptions about KASAN internals in tests. I would actually say that we need more tests that check such internal properties. Thanks!