Received: by 10.223.164.202 with SMTP id h10csp2730902wrb; Mon, 27 Nov 2017 23:51:57 -0800 (PST) X-Google-Smtp-Source: AGs4zMYjf2V69t0VHU2+BHIZNJT9OM7j1kPavg6qDF5b5WlPgM0b5KpkQfQk2NPu/VG/ZIn0XubF X-Received: by 10.99.155.9 with SMTP id r9mr13817098pgd.202.1511855517274; Mon, 27 Nov 2017 23:51:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511855517; cv=none; d=google.com; s=arc-20160816; b=fB6qVPs7ch7qL5a27+4Agtp44ATWp6ZZLBlaVtOJNlLnG8ni43teq9QcenLnmX+l7l A12C0yPIElxNepcShwUY9em1AHVxfg6kRXKF2cHESz32T4Mv+EWgrFLQQfV6uQo4UmEE /v+NARgJBHeOl6ahKBnnnbYYRxmhhMDDjTx1FkFwncQlsEapKLtxuBdRM9qBStL9m2SW ODCx3x80SurqMBfnEeken80xqvDBKSbMpXQ4dQ8QTy2nmBDsCctqrNe6v4FhqhlvVyXo vdb5uy7PJvmgoITRZVwRKXBf619D6T/oTPeXT5TvDO2A74VRcoTq80Tzj2DpUCBcqo/B MJEw== 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=sy7nAUrdXv9F+G9AkO+wxSSU6j9t0vslKjFgo2rVrUI=; b=dKW/ORKzpIFiil6/NH/ghaWpGysRvlpxUgl72kj1uNmWC7gCDCnJM0Ty7guVNRK4GR BoFKzWC8fXFW4vd2h9lDajKP63mmCbGldE4CBgLEAVk8sCu6NxFz9cD5CHbnt6/m1GTY 8CDl9s89/hWEYQGDtAFxjFTH/I7KZvqIEfNq5k6u6HiRjhuD4l5DJcZzX9NCgYTOxnqQ FDRenYNZWSYcAwLeJrxHiqWjxjZCkM9vEQ2M0cR/rzDRiOaj5Wv3uqkklKp8fQ68Njff nYZRuM2eaUuX5LE1YGIm8RGxngy8opImUktGRcbzvrYGCDsBO2W5wVwp9IqkektnCyF+ LxCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bhD7lV4z; 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 i1si24463741plt.238.2017.11.27.23.51.45; Mon, 27 Nov 2017 23:51:57 -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=bhD7lV4z; 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 S1752486AbdK1HuY (ORCPT + 78 others); Tue, 28 Nov 2017 02:50:24 -0500 Received: from mail-pl0-f46.google.com ([209.85.160.46]:34499 "EHLO mail-pl0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752433AbdK1HuV (ORCPT ); Tue, 28 Nov 2017 02:50:21 -0500 Received: by mail-pl0-f46.google.com with SMTP id o17so10176964pli.1 for ; Mon, 27 Nov 2017 23:50:21 -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=sy7nAUrdXv9F+G9AkO+wxSSU6j9t0vslKjFgo2rVrUI=; b=bhD7lV4zPZL5p5tEZJjrqr6qggZ4wCjPGt1NEr74DlFABH0HZ0IBp3LbP+dxLzJoO9 Pmrd1y9PDrjflJ+TjdPz02+xX/VMS+ESGJte1v77AipyFOfs7tnej8owcqAbjwqWhXoB llf+w1bJ2TfkkX9klunK7FxsV4q2yQUgkqZAbAiWMkWe4eIqCB9NwnHh1BTwS0yGYbxV ObyB+wJ5+1wvN0baUgjFGUUYuv9F8miRzWx/jaNmUnNT1p7pjfUh4Sjw3084IabhOKz8 pEMOuqyAWlVUSXBBjKR6EKHFYckgbiX3FNdO2ESJc/bQEPsvl+N8YwXTzcps+jIBN4dw v1Aw== 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=sy7nAUrdXv9F+G9AkO+wxSSU6j9t0vslKjFgo2rVrUI=; b=SUdeZ6lPkiTaMB/S/lh6VX0vRm+9lb1ctu05Nr6LIlby2+gE/JOF0awb0J9o2yekin kqun7Z/jkE6ScnNDt9yy52ZCNXhJuEdqfr/nWz3LqLuUMYglTxVzKL6eDWi4/ZPK1oTK bm6wSY5cULi3/u0fwoD1ndRDPWaAM9PRlYYPwEQ1AcVdkcfxLKvlWZ5gDxz494qp715G wfsgSOk88Npxwbv0S5AQj1ZWUhBrF5n/XDRfAkOez2hER4VKqovZcu/dc2bQiZ/RfQqq nkdJQngW5wjj+S+pPwdKI9UEp1iB8t/4cV2Rs515mVOx6nMPW+TrOOuK8jEH3v6uh+5o 7Rwg== X-Gm-Message-State: AJaThX4M3LgzU0Ur7c5JslIWGXZmkz/s7mPItcd1wZ6GwuZK0zVrzD/2 xzWmbMtjiNxvcpCtksVrnJ8= X-Received: by 10.84.172.1 with SMTP id m1mr42240710plb.174.1511855420798; Mon, 27 Nov 2017 23:50:20 -0800 (PST) Received: from localhost.localdomain ([124.56.155.17]) by smtp.gmail.com with ESMTPSA id 67sm39403946pfz.171.2017.11.27.23.50.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Nov 2017 23:50:19 -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 18/18] doc: add vchecker document Date: Tue, 28 Nov 2017 16:48:53 +0900 Message-Id: <1511855333-3570-19-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 This is a main document for vchecker user. Signed-off-by: Joonsoo Kim --- Documentation/dev-tools/vchecker.rst | 200 +++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 Documentation/dev-tools/vchecker.rst diff --git a/Documentation/dev-tools/vchecker.rst b/Documentation/dev-tools/vchecker.rst new file mode 100644 index 0000000..136e5d9 --- /dev/null +++ b/Documentation/dev-tools/vchecker.rst @@ -0,0 +1,200 @@ +The Valid Access Checker (VCHECKER) +=================================== + +Overview +-------- +Vchecker is a dynamic memory error detector. It provides a new debug feature +that can find out an un-intended access to valid area. Valid area here means +the memory which is allocated and allowed to be accessed by memory owner and +un-intended access means the read/write that is initiated by non-owner. +Usual problem of this class is memory overwritten. + +Most of debug feature focused on finding out un-intended access to +in-valid area, for example, out-of-bound access and use-after-free, and, +there are many good tools for it. But, as far as I know, there is no good tool +to find out un-intended access to valid area. This kind of problem is really +hard to solve so this tool would be very useful. + +This tool doesn't automatically catch a problem. Manual configuration to +specify the target object is required. See the usage part on the below. + +Usage +----- + +To enable vchecker configure kernel with + +:: + + CONFIG_VCHECKER = y + +and choose the target slab object type and the type of the checkers by debugfs +interface at the runtime. Following is the hierarchy of the interface. + +:: + + - debugfs root for vchecker + - directory per slab cache + - alloc_filter + - callstack_depth + - enable + - value + - callstack + + +alloc_filter can be used to apply the checker to specific allocation caller +for this slab cache. For example, there are multiple users for kmalloc-N +slab cache and it's better to filter out un-related allocation caller +when debugging. Note that, if alloc_filter is specified, vchecker doesn't +regard existing allocated objects as debugging target since it's not easy +to know the allocation caller for existing allocated objects. + +callstack_depth can be used to limit the depth of callstack. It would be +helpful to reduce overhead. + +enable can be used to begin/end the checker for this slab cache. + +There are two checkers now, value checker and callstack checker. + +Value checker checks the value stored in the target object. +See following example. + +:: + + static void workfn(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; + obj->v[0] = 0; + + kmem_cache_free(s, obj); + mod_delayed_work(system_wq, dwork, HZ); + } + +Assume that v[0] should not be the value, 7, however, there is a code +to set v[0] to the value, 7. To detect this error, register the value checker +for this object and specify that invalid value is '7'. After registration, +if someone stores '7' to this object, the error will be reported. Registration +can be done by three parameter as following. + +:: + + # cd /sys/kernel/debug/vchecker + # echo 0 0xffff 7 > [slab cache]/value + // offset 0 (dec) + // mask 0xffff (hex) + // value 7 (dec) + # echo 1 > [slab cache]/enable + +Before describing the each parameters, one thing should be noted. One value +checker works for 8 bytes at maximum. If more bytes should be checked, +please register multiple value checkers. + +First parameter is a target offset from the object base. It should be aligned +by 8 bytes due to implementation constraint. Second parameter is a mask that +is used to specify the range in the specified 8 bytes. Occasionally, we want to +check just 1 byte or 1 bit and this mask makes it possible to check such +a small range. Third parameter is the value that is assumed as invalid. + +Second checker is the callstack checker. It checks the read/write callstack +of the target object. Overwritten problem usually happens by non-owner and +it would have odd callstack. By checking the oddity of the callstack, vchecker +can report the possible error candidate. Currently, the oddity of the callstack +is naively determined by checking whether it is a new callstack or not. It can +be extended to use whitelist but not yet implemented. + +:: + + # echo 0 8 > [slab cache]/callstack + // offset 0 (dec) + // size 8 (dec) + # echo 1 > [slab cache]/enable + +First parameter is a target offset as usual and the second one is the size to +determine the range. Unlike the value checker, callstack checker can check +more than 8 bytes by just one checker. + +:: + + # echo off > [slab cache]/callstack + // ... (do some work to collect enough valid callstacks) ... + # echo on > [slab cache]/callstack + +You can collect potential valid callstack during 'off state'. If you think +that enough callstacks are collected, turn on the checker. It will report +a new callstack and it may be a bug candidate. + +Error reports +------------- + +Report format looks very similar with the report of KASAN + +:: + + [ 49.400673] ================================================================== + [ 49.402297] BUG: VCHECKER: invalid access in workfn_old_obj+0x14/0x50 [vchecker_test] at addr ffff88002e9dc000 + [ 49.403899] Write of size 8 by task kworker/0:2/465 + [ 49.404538] value checker for offset 0 ~ 8 at ffff88002e9dc000 + [ 49.405374] (mask 0xffff value 7) invalid value 7 + + [ 49.406016] Invalid writer: + [ 49.406302] workfn_old_obj+0x14/0x50 [vchecker_test] + [ 49.406973] process_one_work+0x3b5/0x9f0 + [ 49.407463] worker_thread+0x87/0x750 + [ 49.407895] kthread+0x1b2/0x200 + [ 49.408252] ret_from_fork+0x24/0x30 + + [ 49.408723] Allocated by task 1326: + [ 49.409126] kasan_kmalloc+0xb9/0xe0 + [ 49.409571] kmem_cache_alloc+0xd1/0x250 + [ 49.410046] 0xffffffffa00c8157 + [ 49.410389] do_one_initcall+0x82/0x1cf + [ 49.410851] do_init_module+0xe7/0x333 + [ 49.411296] load_module+0x406b/0x4b40 + [ 49.411745] SYSC_finit_module+0x14d/0x180 + [ 49.412247] do_syscall_64+0xf0/0x340 + [ 49.412674] return_from_SYSCALL_64+0x0/0x75 + + [ 49.413276] Freed by task 0: + [ 49.413566] (stack is not available) + + [ 49.414034] The buggy address belongs to the object at ffff88002e9dc000 + which belongs to the cache vchecker_test of size 8 + [ 49.415708] The buggy address is located 0 bytes inside of + 8-byte region [ffff88002e9dc000, ffff88002e9dc008) + [ 49.417148] ================================================================== + +It shows that vchecker find the invalid value writing +at workfn_old_obj+0x14/0x50. Object information is also reported. + +Implementation details +---------------------- +This part requires some understanding of how KASAN works since vchecker is +highly depends on shadow memory of KASAN. Vchecker uses the shadow to +distinguish interesting memory address for validation. If it finds the special +value on the shadow of the accessing address, it means that this address is +the target for validation check. Then, it tries to do additional checks to this +address. With this way, vchecker can filter out un-interesting memory access +very efficiently. + +A new type of checks can be added by implementing following callback structure. +check() callback is the main function that checks whether the access is valid +or not. Please reference existing checkers for more information. + +:: + + struct vchecker_type { + char *name; + const struct file_operations *fops; + int (*init)(struct kmem_cache *s, struct vchecker_cb *cb, + char *buf, size_t cnt); + void (*fini)(struct vchecker_cb *cb); + void (*show)(struct kmem_cache *s, struct seq_file *f, + struct vchecker_cb *cb, void *object, bool verbose); + bool (*check)(struct kmem_cache *s, struct vchecker_cb *cb, + void *object, bool write, unsigned long ret_ip, + unsigned long begin, unsigned long end); + }; -- 2.7.4 From 1590862384610369229@xxx Sun Jan 28 18:36:37 +0000 2018 X-GM-THRID: 1585256826031550639 X-Gmail-Labels: Inbox,Category Forums,Downloaded_2018-01