Received: by 10.223.164.202 with SMTP id h10csp2732323wrb; Mon, 27 Nov 2017 23:53:58 -0800 (PST) X-Google-Smtp-Source: AGs4zMZ3ihSZrsx++/kZZ+EoFaGE8zgpc9uQxXi9zBOO5JPhQftIZ7J6tPcW4y65HOU9qhe/NsRI X-Received: by 10.98.36.199 with SMTP id k68mr39463005pfk.236.1511855638888; Mon, 27 Nov 2017 23:53:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511855638; cv=none; d=google.com; s=arc-20160816; b=YwkErA5VwlWUlVIgOfnzSPTHfxrPt42vEvgfYai5YnEDnIKtIpEYV6xjkvkWf/6Oka Y8EOm40aZuLX+HWtXPMfh1fP6NYBkMfdau8QapG3eAtw2Q2Hkc2j/asqXieUJ8uuDSPJ 8wvgGL5p027aHrti4smoljxAgvX/LPCP8gTHQb467rincgFtH2/8/0iDkGYPMnpC0NXi U+n+dm6Vfteu0N+Dw6HQUquqzNw9s0Y5I0SAqYuwhsC5h/uRZ38olZmNUJklP2P89hHC O9VeZeyosYnHEXwXWkjmCP2KoVKsRkmDUIKw/Obzg5udluA1l4fQKOkZRqvLNVqLWGV4 Hqkg== 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=BruHyg9k/lsQXT/uIxSJVRPjkoFaoMmAQq+fmzZswc8=; b=K7y6PiEfKFcw73GR1DqIpr5rGCuvpPCfXbp0fzA9FtQAn+7QchfI9BQBLXnzeUJoYz V7JUUHaQ/J71LSOhea1EzSAPCQHx0BBSYa2giGpid3jaamMhmevQQTCKBpdBBBfYNKSy YhR72Tw5mA4/ljCBuHxGtgmWLYRU1NqZpG8s2DQtPK9R5Zy9B/GVxxl8LFUlcTs/bo+V KodkISS4tAJ9v7XFMbIcsQBbYhPd3n+5kjxmJgkWGobx3+iaN8Wps6cxpvWzWvhv0F04 OnEYi3CcxAQ4jCnrC0tDI8gbuOveW9pZqf1UzCkU8wDpdwDNUVSrKa0LVlhEq3LR0CTk q10w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=S0186NIQ; 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 f15si25137049plr.237.2017.11.27.23.53.47; Mon, 27 Nov 2017 23:53:58 -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=S0186NIQ; 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 S1752561AbdK1Hvk (ORCPT + 78 others); Tue, 28 Nov 2017 02:51:40 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:38627 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752337AbdK1Ht6 (ORCPT ); Tue, 28 Nov 2017 02:49:58 -0500 Received: by mail-pf0-f196.google.com with SMTP id r62so18597430pfd.5 for ; Mon, 27 Nov 2017 23:49:58 -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=BruHyg9k/lsQXT/uIxSJVRPjkoFaoMmAQq+fmzZswc8=; b=S0186NIQ9r4DppAs/93icQwaDNG3rzjhm3S3P0Tirb2kNJF4YIqztA8Bm5S6K/cJ/7 FloEoZYFOeFnxXdTROiS4UW0ESdKE1KSKfldw8mr2mZyW6YlilauFWRQ3MOmkilyG70A zJjeggFN6DeLpjOLDMOB1Am+OiugjW93WdyRvSPnn/nDfJWgQ6G14x+vQjtuxxku/WYn TEamelJaTgRD6Zg8Az6Z8CgHH4nQtik7ThfCj1DI45UvxYarO4MzexsF1YzdlsAB4yT2 kWVTSq6P4ZkRzrYf/sNDRE/FEKhX1DYpZiBbFxcMd3pCNCMlr6mFMq8FMQGHra19J7A6 +Zkg== 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=BruHyg9k/lsQXT/uIxSJVRPjkoFaoMmAQq+fmzZswc8=; b=akesMC5kMPR4dyv0Tx2wjS3cNF/QCRemmFn9w7TuT7moXoIDZEVfhea7ObJ3FEKYm5 WWadRqMk8JMUG6wDMbRN+6pYdLOhv0g8sfwJyMI8AtXONXXsTKMw/WGEmlMT4Vqm2zJS OWeYcAn5QP4yYjFyxAJbzwhWURU2FevVFpLywjjwM7Bcbxcy1amVCL+0geMDs1EJ+4/Z N8JFEzaUAf8v1Wjo1m0r240AK156Lq6yxNGmU+t8tKlbUra5JYdL9ziQvH/7S/qUxqIJ m54lslN9ljX4+znvQdHKjxGNXrJRL3NoWNmRc8Lpcxgn1kLIMgoNVSSS5QAfbzGyVA7O A40g== X-Gm-Message-State: AJaThX7C5UjU2BXvgElREHff2CQEbgewpw11jQ1sBI7MeFU9pwKqkZ4D LUvTcZmS241iD1k4V0k+ot4= X-Received: by 10.98.72.130 with SMTP id q2mr39002683pfi.99.1511855397125; Mon, 27 Nov 2017 23:49:57 -0800 (PST) Received: from localhost.localdomain ([124.56.155.17]) by smtp.gmail.com with ESMTPSA id 67sm39403946pfz.171.2017.11.27.23.49.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Nov 2017 23:49:56 -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 11/18] vchecker: consistently exclude vchecker's stacktrace Date: Tue, 28 Nov 2017 16:48:46 +0900 Message-Id: <1511855333-3570-12-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 Since there is a different callpath even in the vchecker, static skip value doesn't always exclude vchecker's stacktrace. Fix it through checking stacktrace dynamically. v2: skip two depth of stack at default, it's safe! Signed-off-by: Joonsoo Kim --- mm/kasan/vchecker.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/mm/kasan/vchecker.c b/mm/kasan/vchecker.c index df480d5..dc3a9a7 100644 --- a/mm/kasan/vchecker.c +++ b/mm/kasan/vchecker.c @@ -23,6 +23,7 @@ #include "kasan.h" #define VCHECKER_STACK_DEPTH (16) +#define VCHECKER_SKIP_DEPTH (2) struct vchecker { bool enabled; @@ -48,7 +49,7 @@ struct vchecker_type { 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, + void *object, bool write, unsigned long ret_ip, unsigned long begin, unsigned long end); }; @@ -276,7 +277,7 @@ bool vchecker_check(unsigned long addr, size_t size, continue; checked = true; - if (cb->type->check(s, cb, object, write, begin, end)) + if (cb->type->check(s, cb, object, write, ret_ip, begin, end)) continue; vchecker_report(addr, size, write, ret_ip, s, cb, object); @@ -292,14 +293,29 @@ bool vchecker_check(unsigned long addr, size_t size, return vchecker_poisoned((void *)addr, size); } -static noinline depot_stack_handle_t save_stack(int skip, bool *is_new) +static void filter_vchecker_stacks(struct stack_trace *trace, + unsigned long ret_ip) +{ + int i; + + for (i = 0; i < trace->nr_entries; i++) { + if (trace->entries[i] == ret_ip) { + trace->entries = &trace->entries[i]; + trace->nr_entries -= i; + break; + } + } +} + +static noinline depot_stack_handle_t save_stack(unsigned long ret_ip, + bool *is_new) { unsigned long entries[VCHECKER_STACK_DEPTH]; struct stack_trace trace = { .nr_entries = 0, .entries = entries, .max_entries = VCHECKER_STACK_DEPTH, - .skip = skip, + .skip = VCHECKER_SKIP_DEPTH, }; depot_stack_handle_t handle; @@ -311,6 +327,7 @@ static noinline depot_stack_handle_t save_stack(int skip, bool *is_new) if (trace.nr_entries == 0) return 0; + filter_vchecker_stacks(&trace, ret_ip); handle = depot_save_stack(NULL, &trace, __GFP_ATOMIC, is_new); WARN_ON(!handle); @@ -542,7 +559,7 @@ static void show_value(struct kmem_cache *s, struct seq_file *f, } static bool check_value(struct kmem_cache *s, struct vchecker_cb *cb, - void *object, bool write, + void *object, bool write, unsigned long ret_ip, unsigned long begin, unsigned long end) { struct vchecker_value_arg *arg; @@ -553,7 +570,7 @@ static bool check_value(struct kmem_cache *s, struct vchecker_cb *cb, if (!write) goto check; - handle = save_stack(0, NULL); + handle = save_stack(ret_ip, NULL); if (!handle) { pr_err("VCHECKER: %s: fail at addr %p\n", __func__, object); dump_stack(); @@ -679,16 +696,8 @@ static void show_callstack(struct kmem_cache *s, struct seq_file *f, } } -/* - * number of stacks to skip (at least). - * - * __asan_loadX -> vchecker_check -> cb->check() -> save_stack - * -> save_stack_trace - */ -#define STACK_SKIP 5 - static bool check_callstack(struct kmem_cache *s, struct vchecker_cb *cb, - void *object, bool write, + void *object, bool write, unsigned long ret_ip, unsigned long begin, unsigned long end) { u32 handle; @@ -696,7 +705,7 @@ static bool check_callstack(struct kmem_cache *s, struct vchecker_cb *cb, struct vchecker_callstack_arg *arg = cb->arg; int idx; - handle = save_stack(STACK_SKIP, &is_new); + handle = save_stack(ret_ip, &is_new); if (!is_new) return true; -- 2.7.4 From 1584684669273655507@xxx Tue Nov 21 14:04:28 +0000 2017 X-GM-THRID: 1584684669273655507 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread