Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4369443ybp; Mon, 14 Oct 2019 03:38:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqw9nGvBEjWKYonImEu1K9b1AG6NWgU7qUGS+0obND9f2Xkba/8OaMXjX4mBnTpixojqlR1q X-Received: by 2002:a05:6402:170e:: with SMTP id y14mr27661097edu.82.1571049510320; Mon, 14 Oct 2019 03:38:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571049510; cv=none; d=google.com; s=arc-20160816; b=urR/VHN7WUGnRlm1lYZ9a5enT5b/Fl9rfD0gfKlBwGwoi3Q7X0BXp6BK3P/3kWm5Ri UPC1Jb3YRnNs6gGr6VQum5TbVYWB/KSpngOxkxMrEjbdTJLcDEU3X63mA/ADbR7nDLB+ /ONo7Ele7wZ9PBhEe5TLJLhR29MS8BH5XwurCG7bR/Z90YnIfV9Exzi5yFh/TnOm99+i 4XFXKg5T0LSQS52MMmeFEOOJNgt7B9o2LBWd3hksz85wxwtJYVXQFZskv4EzzJ4rqp1S /xMyCQ4Bwz6s13EvqemAqINSn0eRQ97O6lH5L2tXWJuQERPbs3f+H+2yPjdu5FCYyQvG qAHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=8FPgTQop/5D6P+RLHbKHGh0ZbBOGliZrgDB/gUABhBM=; b=VIG52c09/HsVfnmBUltzDKq/y62Cb6KDJJRFzD7heJ6Rkc0OHStSnJYIyhPccKUNTE g+ITaJT0UsOHd2pBKBOaV1xmUtwvFHsLWbwK3zPB+GT905NRgECokDgD+ucQwxxSgfBw KodrTdQ9R/Lk8mWYPKYhjpAg7E7HBAxr+s/vc5wD4pjSedih+xuOBvDd4PAxi+uXeEX5 zxec8Genilz/kOvQaSVKNA5bNSw298u5p40fDAOwiFm1XfoL7z7E7lTWvxKaZmF9wAwa u0qgDSPrDdnLSwlxSSQdzH2fK7AU63BkFuxhEsRzQbOdqykfUB87iAbXSWAvPafZOWaH zskw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id oz6si10814828ejb.124.2019.10.14.03.38.07; Mon, 14 Oct 2019 03:38:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731569AbfJNKhB (ORCPT + 99 others); Mon, 14 Oct 2019 06:37:01 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:24096 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1731249AbfJNKhB (ORCPT ); Mon, 14 Oct 2019 06:37:01 -0400 X-UUID: 7dcb933b18764e979c3cfe88a285e36a-20191014 X-UUID: 7dcb933b18764e979c3cfe88a285e36a-20191014 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 752259523; Mon, 14 Oct 2019 18:36:57 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 14 Oct 2019 18:36:52 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 14 Oct 2019 18:36:52 +0800 From: Walter Wu To: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Matthias Brugger CC: , , , , , , Walter Wu Subject: [PATCH 2/2] kasan: add test for invalid size in memmove Date: Mon, 14 Oct 2019 18:36:54 +0800 Message-ID: <20191014103654.17982-1-walter-zh.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-TM-SNTS-SMTP: 0CF6CECFA4DBB0B2BBA0BF7B47F0B4713B9EC9875EB27669122A6B9E49B63E752000:8 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Test size is negative numbers in memmove in order to verify whether it correctly get KASAN report. Signed-off-by: Walter Wu --- lib/test_kasan.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/test_kasan.c b/lib/test_kasan.c index 49cc4d570a40..06942cf585cc 100644 --- a/lib/test_kasan.c +++ b/lib/test_kasan.c @@ -283,6 +283,23 @@ static noinline void __init kmalloc_oob_in_memset(void) kfree(ptr); } +static noinline void __init kmalloc_memmove_invalid_size(void) +{ + char *ptr; + size_t size = 64; + + pr_info("invalid size in memmove\n"); + ptr = kmalloc(size, GFP_KERNEL); + if (!ptr) { + pr_err("Allocation failed\n"); + return; + } + + memset((char *)ptr, 0, 64); + memmove((char *)ptr, (char *)ptr + 4, -2); + kfree(ptr); +} + static noinline void __init kmalloc_uaf(void) { char *ptr; @@ -773,6 +790,7 @@ static int __init kmalloc_tests_init(void) kmalloc_oob_memset_4(); kmalloc_oob_memset_8(); kmalloc_oob_memset_16(); + kmalloc_memmove_invalid_size(); kmalloc_uaf(); kmalloc_uaf_memset(); kmalloc_uaf2(); -- 2.18.0