Received: by 10.223.164.202 with SMTP id h10csp2730819wrb; Mon, 27 Nov 2017 23:51:51 -0800 (PST) X-Google-Smtp-Source: AGs4zMbDQMNgTuiBCNQ1ZxagwUtsTHBGAcCmir5bTyVWZeK9yn+irhWGag/iPxjjTz/UVlza4cpE X-Received: by 10.98.67.150 with SMTP id l22mr6829781pfi.32.1511855511191; Mon, 27 Nov 2017 23:51:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511855511; cv=none; d=google.com; s=arc-20160816; b=DTv7Fo/4HJxBqsJEZf+Zmi5lbNUU7rUdbXTLS858J2zll81aCgtg9+TXoh2YBUkH0r NCbLBCJmEfvlef3altS6nZbaB00BS/WVgjwTAPwQ24CZaInqT0Bp/u0kFaf9+3+K37NS 9/+2JxcHuRmq/qHbLwzP6wgDcigHWqecHlG8IYtbbsYKZpM7pBEVjfVJaZqkX++jeBV1 wh3y/Asl08hf9anoqi2NqYjLdZ8N/ulAZ9vOjpmIUNBPffzMIap9hidoWAZpSSYn80/t louU7qpXMwb1UWnnWkQGYb/RFjoEZIzi14Kw+9b49L5j2xgzXw1d7xgGQQcFwXy8J3Fr 5e0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=FeXKXhgDx6Hl50DfMRf/6EULFXwCc9UJY3w+8fU9c9M=; b=MRxNc+0XYnfcOt5FwDfeDOx/jrxBVLQwnFtQ32X2HAaqrFLW6dw3wzTKUFuUDkTIFX ajqi4Nj4+YW9NN48lqXaObLhvJS/nHUX7fqS22ddaiBqgqFs37A4gt0qkFrOzV2odR1h 0nr3sghbdKPglTin95T8u5NI0Gq7/KrBLZxm8Bj4Bh++J+/TdfutioaWS0OpopmxtFe0 WHyhAZh6n7+QgdraY4sVEfNWUWN49BQ0IqgKXwUXf7qY/U2X1expCwPIl4xeuRkLZgZo pryV/TzVtU7u2FkJ70QWuc+AY0sv1kBiohYmm7NC4m9n2Xush1v0dhwU5AJMOsH32j3b 9CLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=d81bs2bF; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f7si26826004pff.45.2017.11.27.23.51.39; Mon, 27 Nov 2017 23:51:51 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=d81bs2bF; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752503AbdK1Huq (ORCPT + 78 others); Tue, 28 Nov 2017 02:50:46 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:39316 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752417AbdK1HuS (ORCPT ); Tue, 28 Nov 2017 02:50:18 -0500 Received: by mail-pl0-f68.google.com with SMTP id l16so10169554pli.6 for ; Mon, 27 Nov 2017 23:50:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FeXKXhgDx6Hl50DfMRf/6EULFXwCc9UJY3w+8fU9c9M=; b=d81bs2bFZDGxte/icGjneEzIkVsguKtTvAmrMX8oi8MgJ6Fk5RqrOj+k1TvWhhcMVJ /P/eLgfJb38GVKQdqkE+f90bcLehmd4fGE43/aihhSjOYKNzZJjiVYXjqjZCyX0Vjk0P ZUlfV0BOu0Zx3lNZdzJs6meTbgNjmTJS8cy/3aDOfm7kzFcIybzHOcspFk63VqV7Yo6R VzdYmBV+yy2+2Jr2/xufBbmYym6Sg/UEHlJPHzFqA4lHl8eYMhaJDyzyMkt0EkN3YreR O9XKh6Q45CuAP+ShpQ13iobvOq/mXvT8/4XA+RXdMtdoZjEz81rgUk8d3o0W+VdMJ4x0 tBcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FeXKXhgDx6Hl50DfMRf/6EULFXwCc9UJY3w+8fU9c9M=; b=bGYOKOk8vrZp+vU7kVfit2KgZAESG1y3qym7fH579Hz4OTkYFg+aVbZwGFuvJv6MZS lT8rN9494Dx8l4VuJnutvlsG6Jp55eObe/BhfKqF6pNNlUgBDUHffSjWkAvGDWZ1SzDa +fO4JAhpJOloEgyFM5zGvFR5S21fkERygKKnfzgU+n2FQKdU6oNuoWtYahRneRAWUN10 +fdtL7M9U5a2K5RIkn5fE1iIIoKmtJsfi4rMUV/ZvonawjZQ/yPWOHU0pO6ERZFUzR8k mdBVtXBfaYzCLS/IueiKaixxEW2hHuxLuopkJLg73rk8SnBiJEwvyXNiJv4oYy+Yzrwa OavA== X-Gm-Message-State: AJaThX6/MarVX5MzmvnpGzt0dVK53M0UWs3aaWPuz4k8aiNz6PWqzjel 9K5qYa8Z0GkR5cbGg6WIRyE= X-Received: by 10.159.207.134 with SMTP id z6mr42339259plo.144.1511855417367; Mon, 27 Nov 2017 23:50:17 -0800 (PST) Received: from localhost.localdomain ([124.56.155.17]) by smtp.gmail.com with ESMTPSA id 67sm39403946pfz.171.2017.11.27.23.50.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Nov 2017 23:50:16 -0800 (PST) From: js1304@gmail.com X-Google-Original-From: iamjoonsoo.kim@lge.com To: Andrew Morton Cc: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Namhyung Kim , Wengang Wang , Joonsoo Kim Subject: [PATCH 17/18] lib/vchecker_test: introduce a sample for vchecker test Date: Tue, 28 Nov 2017 16:48:52 +0900 Message-Id: <1511855333-3570-18-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511855333-3570-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1511855333-3570-1-git-send-email-iamjoonsoo.kim@lge.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joonsoo Kim It's not easy to understand what can be done by the vchecker. This sample could explain it and help to understand the vchecker. Signed-off-by: Joonsoo Kim --- lib/Kconfig.kasan | 9 ++++ lib/Makefile | 1 + lib/vchecker_test.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 lib/vchecker_test.c diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan index 4b8e748..9983ec8 100644 --- a/lib/Kconfig.kasan +++ b/lib/Kconfig.kasan @@ -65,4 +65,13 @@ config VCHECKER depends on KASAN && DEBUG_FS select KALLSYMS +config TEST_VCHECKER + tristate "Module for testing vchecker" + depends on m && KASAN + help + This is a test module doing memory over-write. If vchecker is + properly set up to check that over-write, memory over-written + problem would be detected. See the help text in the + lib/vchecker_test.c for vchecker sample run. + endif diff --git a/lib/Makefile b/lib/Makefile index d11c48e..cc1f5ec 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -244,6 +244,7 @@ clean-files += oid_registry_data.c obj-$(CONFIG_UCS2_STRING) += ucs2_string.o obj-$(CONFIG_UBSAN) += ubsan.o +obj-$(CONFIG_TEST_VCHECKER) += vchecker_test.o UBSAN_SANITIZE_ubsan.o := n diff --git a/lib/vchecker_test.c b/lib/vchecker_test.c new file mode 100644 index 0000000..fcb4b7f --- /dev/null +++ b/lib/vchecker_test.c @@ -0,0 +1,117 @@ +#include +#include +#include +#include +#include + +/* + * How to use this sample for vchecker sample-run + * + * 1. Insert this module + * 2. Do following command on debugfs directory + * # cd /sys/kernel/debug/vchecker + * # echo 0 0xffff 7 > vchecker_test/value # offset 0, mask 0xffff, value 7 + * # echo 1 > vchecker_test/enable + * # echo workfn_kmalloc_obj > kmalloc-8/alloc_filter + * # echo "0 8" > kmalloc-8/callstack + * # echo on > kmalloc-8/callstack + * # echo 1 > kmalloc-8/enable + * 3. Check the error report due to invalid written value + */ + +struct object { + volatile unsigned long v[1]; +}; + +static struct kmem_cache *s; +static void *old_obj; +static struct delayed_work dwork_old_obj; +static struct delayed_work dwork_new_obj; +static struct delayed_work dwork_kmalloc_obj; + +static void workfn_old_obj(struct work_struct *work) +{ + struct object *obj = old_obj; + struct delayed_work *dwork = (struct delayed_work *)work; + + obj->v[0] = 7; + + mod_delayed_work(system_wq, dwork, HZ * 5); +} + +static void workfn_new_obj(struct work_struct *work) +{ + struct object *obj; + struct delayed_work *dwork = (struct delayed_work *)work; + + obj = kmem_cache_alloc(s, GFP_KERNEL); + + obj->v[0] = 7; + /* + * Need one more access to detect wrong value since there is + * no proper infrastructure yet and the feature is just emulated. + */ + obj->v[0] = 0; + + kmem_cache_free(s, obj); + mod_delayed_work(system_wq, dwork, HZ * 5); +} + +static void workfn_kmalloc_obj(struct work_struct *work) +{ + struct object *obj; + struct delayed_work *dwork = (struct delayed_work *)work; + + obj = kmalloc(sizeof(*obj), GFP_KERNEL); + + obj->v[0] = 7; + /* + * Need one more access to detect wrong value since there is + * no proper infrastructure yet and the feature is just emulated. + */ + obj->v[0] = 0; + + kfree(obj); + mod_delayed_work(system_wq, dwork, HZ * 5); +} + +static int __init vchecker_test_init(void) +{ + s = kmem_cache_create("vchecker_test", + sizeof(struct object), 0, SLAB_NOLEAKTRACE, NULL); + if (!s) + return 1; + + old_obj = kmem_cache_alloc(s, GFP_KERNEL); + if (!old_obj) { + kmem_cache_destroy(s); + return 1; + } + + INIT_DELAYED_WORK(&dwork_old_obj, workfn_old_obj); + INIT_DELAYED_WORK(&dwork_new_obj, workfn_new_obj); + INIT_DELAYED_WORK(&dwork_kmalloc_obj, workfn_kmalloc_obj); + + mod_delayed_work(system_wq, &dwork_old_obj, HZ * 5); + mod_delayed_work(system_wq, &dwork_new_obj, HZ * 5); + mod_delayed_work(system_wq, &dwork_kmalloc_obj, HZ * 5); + + return 0; +} + +static void __exit vchecker_test_fini(void) +{ + cancel_delayed_work_sync(&dwork_old_obj); + cancel_delayed_work_sync(&dwork_new_obj); + cancel_delayed_work_sync(&dwork_kmalloc_obj); + + kmem_cache_free(s, old_obj); + kmem_cache_destroy(s); +} + + +module_init(vchecker_test_init); +module_exit(vchecker_test_fini) + +MODULE_LICENSE("GPL"); + -- 2.7.4 From 1585311709846005088@xxx Tue Nov 28 12:11:01 +0000 2017 X-GM-THRID: 1585305121007847842 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread