Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp627700pxt; Thu, 12 Aug 2021 06:17:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWL6/aGyi6ORRU8sxMaggfmIZ6RTH4J+u/YdBIn1iQWFaXlNx/OcKvDuID1wQZdeKz/mqb X-Received: by 2002:a17:906:7208:: with SMTP id m8mr3710987ejk.82.1628774224264; Thu, 12 Aug 2021 06:17:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628774224; cv=none; d=google.com; s=arc-20160816; b=ThJiTrH/ddsUvyP9A83FUMBmo5UntkY6eGDmkWdBtYTtWK18gcEr+NVPwA7aTPLRV/ iuvR869ViHbaDl7uu13vOZ58hrcd5e90r04RboQWBEsjLIvGY3ytM1XY31upf+gku2Om 0qsjm8NxoEEXvjZwr6FK5u4OvSHmzzD/gOh6RAJeQRzzqzKC6GscpCSk3MetNZqc1oGb Vgi4kxf+PLPmvmcpe8pKdgUFO75sbUSwLL8Fz2ftsvp28jqqg76Y7Mh5mbohBp0RkvON 1TNggkx6L9N+6i7twGp9XhiL2rGeRdYqE5cAryhei6zPat+tatocO7sSqEIVWjpr940S XsuQ== 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=hetAWS8vJTkbvJ1Yuh2ecULwYt0HQ0q3zS2e3QmOOk0=; b=TNnfV8ja5Z/kDDb3rEFWuRXcx4tgaaNOw07K1cQ5HUwGMua063T8GnQ6+36J+67Iv3 66Vx12AwHta1DchClGDJLsDtW/GWp4uS6EBevbJiS8sb0ZhCkX25qBd7rR/0jHJu7JYu HKCRr8ipTf42tsntCcfARC92OzTf9Z/djGZtmQgTJ6awpyoNIs+9smb5ItD/+zW4kHJh eCMWEhbBSkTTYsmPU+rgh2DdeqW5qsRjGAIcuYOVpL/BcezOhthhaTXRNr6Nkpfnms2t 8JoJl3GLoBuymY00TNt+OPbDnqdeYVUuBHNxzbVjPKiPXCDaixfXlcNwaVU5RtkC3Anb fc7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VX3lXUnc; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gt15si2307505ejb.30.2021.08.12.06.16.38; Thu, 12 Aug 2021 06:17:04 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=VX3lXUnc; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237547AbhHLMzz (ORCPT + 99 others); Thu, 12 Aug 2021 08:55:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236506AbhHLMzy (ORCPT ); Thu, 12 Aug 2021 08:55:54 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31D77C061765 for ; Thu, 12 Aug 2021 05:55:29 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id bq25so1341345ejb.11 for ; Thu, 12 Aug 2021 05:55:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hetAWS8vJTkbvJ1Yuh2ecULwYt0HQ0q3zS2e3QmOOk0=; b=VX3lXUncEAiMWCQXnnXyzQhXlgIUCn+99sQZAdcGcSPeCwxoiBQLOYxunMYCp2evFy PvDkaahs2fIVWzYkjnfhqbuT/TcmSgbaRkPDb4/gXnbSiXAHh+q/HnERGAinmqLS6Z0s 2nqvrzAq2/PAi5rpwaOdTGc+2B9oPKwBy+xyeSL6nEAbvcgKGZMkdIT+Npq4HeHqU4NR Ro5GOsX/6ci3aDRIg+zaloKpMkD08g1hXxTdo9pZzGp14KV/8bx+DC72UUAtDAOQJKxM uwkBkhURpaVyyIGy9UYYIepFjRFXXsI9BEAsjiFRyz+VCdDKsFXzjC9P2SLrLM5h4891 yZaQ== 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=hetAWS8vJTkbvJ1Yuh2ecULwYt0HQ0q3zS2e3QmOOk0=; b=WiHsC1zReVKgRQ5Vb4fPI1YUUYTFXcBuHmaOb5GFQXTRJTMY9MD840CZ27w8fudrWj owwWFRBrEUiAseIZT+ffR2iXRcO5fxH8o++ZcxU+1AjRaGn9DprjQBf9ZjberaNiHj5X kIJHZeOguLzOAP1tSzxChXQVZ+G3FszWmAzYFsvWWnNRR6o+PHEYrPHTIREEWakOVIr3 msWVGevBfUsAm4I3B6gTERiHPHVDqGsVSe1paPJPyaZJCe8vfKAztt29IE35Ad6pPFM+ 1YkrSiEq676X41qTY/0X7CKnrnveUSayJp+Hcp32l0y2zekzu+IXpUwzMZvQYx+xxc7E NhwQ== X-Gm-Message-State: AOAM532dPSBbZb7jkY8aDzG93CKkWb2QPLXPDdVMUR6Q9TCULJkqr6a9 7bpDjgt+3G2Bai4ZxQrnR38qAxTKTo6ATkMXjs4= X-Received: by 2002:a17:906:d147:: with SMTP id br7mr3613564ejb.126.1628772927836; Thu, 12 Aug 2021 05:55:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andrey Konovalov Date: Thu, 12 Aug 2021 14:55:16 +0200 Message-ID: Subject: Re: [PATCH 3/8] kasan: test: avoid corrupting memory via memset To: Marco Elver Cc: andrey.konovalov@linux.dev, Andrew Morton , Andrey Ryabinin , Dmitry Vyukov , Alexander Potapenko , kasan-dev , 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 Thu, Aug 12, 2021 at 10:57 AM Marco Elver wrote: > > On Wed, 11 Aug 2021 at 21:21, wrote: > > From: Andrey Konovalov > > > > kmalloc_oob_memset_*() tests do writes past the allocated objects. > > As the result, they corrupt memory, which might lead to crashes with the > > HW_TAGS mode, as it neither uses quarantine nor redzones. > > > > Adjust the tests to only write memory within the aligned kmalloc objects. > > > > Signed-off-by: Andrey Konovalov > > --- > > lib/test_kasan.c | 22 +++++++++++----------- > > 1 file changed, 11 insertions(+), 11 deletions(-) > > > > diff --git a/lib/test_kasan.c b/lib/test_kasan.c > > index c82a82eb5393..fd00cd35e82c 100644 > > --- a/lib/test_kasan.c > > +++ b/lib/test_kasan.c > > @@ -431,61 +431,61 @@ static void kmalloc_uaf_16(struct kunit *test) > > static void kmalloc_oob_memset_2(struct kunit *test) > > { > > char *ptr; > > - size_t size = 8; > > + size_t size = 128 - KASAN_GRANULE_SIZE; > > > > ptr = kmalloc(size, GFP_KERNEL); > > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); > > > > - KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + 7 + OOB_TAG_OFF, 0, 2)); > > + KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + size, 0, 2)); > > I think one important aspect of these tests in generic mode is that > the written range touches both valid and invalid memory. I think that > was meant to test any explicit instrumentation isn't just looking at > the starting address, but at the whole range. Good point! > It seems that with these changes that is no longer tested. Could we > somehow make it still test that? Yes, will do in v2. Thanks, Marco!