Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp4717964pxt; Wed, 11 Aug 2021 12:24:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwU+FTqKvTQwU+UDNrbAEYzkzOL0RC3MO+6RhlCscL7F0hdjUowNTGrGt+gPmPnayMRNKo/ X-Received: by 2002:a05:6e02:2149:: with SMTP id d9mr13680ilv.141.1628709854048; Wed, 11 Aug 2021 12:24:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628709854; cv=none; d=google.com; s=arc-20160816; b=SLQOCODlcw/izxj7GlNRQ4GN2dU/qym0RHrqt5r6Vea/+b9t7C/836HN/QPibeh+B8 YO/x6+9gNjDsYdfECaVat3pDCiPtc+6g0rRXGjK2oKyCqnCIRJ0iiNsvzdq3A7jlLCB1 7cQ3Zpl0N1t+j1E53iZiPqOVOYwARwOF9jMiVI9nZLYy/qXiQwooyHch++l03SUMRhFe ro9B5/8bY7ko5heBrQ71noyK7A0hD0B3lkK5zJZy2d/QH1lu5jFJlNyE7VH3oDc6oNrv XzzIq4f3XA53LyBp13vXREGWM4OLM8fxxpLLmZehGnsGnQndAVt4gHe3crieVVkHa7x+ 8RGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jkojDrgxIR2XbRn8TG52WE2ryFsf3sjf8wg3n6qSYXw=; b=R2NLD2XuH08YPIqHnyqZoAflhu802wNEomfBjbeYB2yZXQHJ8to5lp/Y+mHUs2x9p5 ievSZQKu4xPdB8+0odpUFigFoSvf5kAyt11Q3vEZyrmmJaCjsPWMLm72No0IEgVKsdKc gAEotYjjtaTz3WhTZMOIY5IY8MAzA6ZCaFSL5W5Kax0Ld+etadV/XJe1ox4brZCQaGkh 8ZhpTcfNQCyLA2Nn73cfXUi1uJvo7xplo1nSftlcLDqyQeTwp4HlKx2Tyrug9Zqygvek S+r7xAd7gPwuhyWoKu0UZ4qbiOrhVzHUFbAgi69Qgx+1ah7q9IM5pOkZMzhhDIHCwD54 FAmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ZQA3DIJP; 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=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d7si145855iop.31.2021.08.11.12.23.59; Wed, 11 Aug 2021 12:24:14 -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=@linux.dev header.s=key1 header.b=ZQA3DIJP; 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=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231627AbhHKTWP (ORCPT + 99 others); Wed, 11 Aug 2021 15:22:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231366AbhHKTWI (ORCPT ); Wed, 11 Aug 2021 15:22:08 -0400 Received: from out1.migadu.com (out1.migadu.com [IPv6:2001:41d0:2:863f::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8DAEC0613D5 for ; Wed, 11 Aug 2021 12:21:44 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1628709702; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jkojDrgxIR2XbRn8TG52WE2ryFsf3sjf8wg3n6qSYXw=; b=ZQA3DIJPeYBGIm367eDBHHF5G/+S1RPsCaAuYZJjP7ppikgECgag9bDuLaHwXtIOvbikBs PJXPsL/HWVXrnWWeHixEunAx8QceGbqi3S10zPdeIyGk8HyHhPA5KbEezuBjPYsKS7KNrT sr//2VMSZRN/cOnXy0j7La5BBStzulw= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Andrey Ryabinin , Marco Elver , Dmitry Vyukov , Alexander Potapenko , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/8] kasan: test: avoid corrupting memory via memset Date: Wed, 11 Aug 2021 21:21:19 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: andrey.konovalov@linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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)); kfree(ptr); } static void kmalloc_oob_memset_4(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 + 5 + OOB_TAG_OFF, 0, 4)); + KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + size, 0, 4)); kfree(ptr); } - static void kmalloc_oob_memset_8(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 + 1 + OOB_TAG_OFF, 0, 8)); + KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + size, 0, 8)); kfree(ptr); } static void kmalloc_oob_memset_16(struct kunit *test) { char *ptr; - size_t size = 16; + 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 + 1 + OOB_TAG_OFF, 0, 16)); + KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + size, 0, 16)); kfree(ptr); } static void kmalloc_oob_in_memset(struct kunit *test) { char *ptr; - size_t size = 666; + 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, 0, size + 5 + OOB_TAG_OFF)); + KUNIT_EXPECT_KASAN_FAIL(test, + memset(ptr, 0, size + KASAN_GRANULE_SIZE)); kfree(ptr); } -- 2.25.1