Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp859225imu; Fri, 7 Dec 2018 10:00:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vtf1YxokLgc/cATEjXHjQQlWz/wOlhI04624Gst2jdemFDwXXDqt9OYTcj2uty8/lzpppi X-Received: by 2002:a17:902:2a29:: with SMTP id i38mr3080351plb.253.1544205637386; Fri, 07 Dec 2018 10:00:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544205637; cv=none; d=google.com; s=arc-20160816; b=khs1rOMNIxh4YiCX/BRBjCpd7/DgSBiiZBIdWSU4tCXOa+pmBIhcUXeAA8gR75ioup G1QVv+I9syj3cceYfdPR5vFm7BCQ/fMZMd2/L93rlpwfxsi81M7FX68aRK3tKzrxKX0E 1/1cP2DXZHb0SGQT8bVIyZhTZ1nU7pbZgHs+Kxj1u1RAyjkmt86WYntQozH0c1qTi2Ks kccuzwQSt3oRS3lZ2tpBUPPux5GpIZOwGxoirBhf5oBWfUbnLHDSKfgTK/Jgp1nGuZnC j8X/NB+836FRql/Aoh6acFnLfvK41ssQaPdhk0fn4ZPUFXzyCzNsoV9ffsin7Sd6K6BR XO1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Ij5NMCgHh050nn2K68nR5/ASlkkd5cTchIyWvqT7cgA=; b=pOS5sNRVzl0HQPq+VaiZ46+p96hpuBQZCZEnk//ZfXNayAGJUCPh+jWBcIyoSc9pET XcxgOJlSL4mxYiV4DpYAld9oJxUnJxNkhjQFbEGy11PL0JThu4bQoY/zVzPqXSj2XOe6 pcTlenbIiF7PIvAfaRjFaVycf7hwUMVz4AfYwI/dQlQW+9rKewJO4O3fwdWYZ7hUUF8f UY/tf6tfiBfVcTZc7YGoPtHwi3M608L3ZmQb5U547FtHqCFTg7MRuJEG3ypzoJfE9lZb eIxFv5Rt6+3l0cW7PDyZ+GuzG1pF0jQVYB9MnINuJcestyEIMtBLA5wrunUK0cJ5qILA 5Y1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="c/2fNwG2"; 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=QUARANTINE 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 x18si3510104pfm.39.2018.12.07.10.00.21; Fri, 07 Dec 2018 10:00:37 -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="c/2fNwG2"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726236AbeLGR6K (ORCPT + 99 others); Fri, 7 Dec 2018 12:58:10 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:51865 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726223AbeLGR6K (ORCPT ); Fri, 7 Dec 2018 12:58:10 -0500 Received: by mail-wm1-f68.google.com with SMTP id s14so5229416wmh.1 for ; Fri, 07 Dec 2018 09:58:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Ij5NMCgHh050nn2K68nR5/ASlkkd5cTchIyWvqT7cgA=; b=c/2fNwG27Kt3tW8D4uC3+LOYOaHZ8djyCo1TDj9ZmIdThKyEs6AT1mVTz0Hc0OBq5p +SE+Xvnjzquz9Fpb8wtzgAzmykKOswgjg7bwC8ghfSFcTnDeOuytbO7ivnARNQDtB3OL p23LBwAOz9heidMq7CXYqnRi16wYHbWJphZpufGm/PA5k12kPBgYBZksNvvKJRTdNhxw /mdzU1ojfJjTLXdirKW6kbsgehltgabjK9Dn6SdY8atcmUeNvswMukRcFmV34r9AAC80 eb56fWXiGLbIt6N34moXDq3CbJbSOn8JWHmhfeghln5sesiT1fxE7h/C+QFcb9JxYJSC +7gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Ij5NMCgHh050nn2K68nR5/ASlkkd5cTchIyWvqT7cgA=; b=Fcq+xdrNxjRnChQ09RspPvznDuznhp9lhxFMOTCq9Q4b388xufTWDx7Bd9cC0oI0w5 h0tPhDum0cZet6d5w8dc1DS2gn5QNU/HETWgClnhqyeCLNCjjaNLt4u5+8j6n5DfooSQ SifwfmzFd01MPRtfSrKPTYu9bUmK2sqT4cZg+fHVa2/HBTKfaDLOZZzewN4md7s/KkWa 2+vbP0Gnu+iIMaNr/O7JvcinLT8ZP/2MJn8TOU2RdpiZ6iJT18DGPObbPPCdmQYpQICo zr6JBnugrUfqVaEDoQlp9F48CfsU4WJd6RkmJPPF1w0FXX85XuD9HD2kFcyv7I4m/9B4 H1Xg== X-Gm-Message-State: AA+aEWa6IS0+5vX4wR2LLsVVu+vwKl1+YvACVB0KaX3A3wHOW3b+kM/n +aeQgMqcQ3qAzVEjogOWjQ== X-Received: by 2002:a1c:e488:: with SMTP id b130mr3167417wmh.124.1544205487208; Fri, 07 Dec 2018 09:58:07 -0800 (PST) Received: from localhost (host34-126-dynamic.27-79-r.retail.telecomitalia.it. [79.27.126.34]) by smtp.gmail.com with ESMTPSA id s202sm5403857wme.40.2018.12.07.09.58.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Dec 2018 09:58:06 -0800 (PST) Date: Fri, 7 Dec 2018 18:58:05 +0100 From: Andrea Righi To: Masami Hiramatsu Cc: "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Yonghong Song , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] kprobes: x86_64: blacklist non-attachable interrupt functions Message-ID: <20181207175805.GA1369@Dell> References: <20181206095648.GA8249@Dell> <20181207234731.f52a8c1eff6c0e72c073ad40@kernel.org> <20181208010120.c3eda9042912068aecc68317@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181208010120.c3eda9042912068aecc68317@kernel.org> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Dec 08, 2018 at 01:01:20AM +0900, Masami Hiramatsu wrote: > Hi Andrea and Ingo, > > Here is the patch what I meant. I just ran it on qemu-x86, and seemed working. > After introducing this patch, I will start adding arch_populate_kprobe_blacklist() > to some arches. > > Thank you, > > [RFC] kprobes: x86/kprobes: Blacklist symbols in arch-defined prohibited area > > From: Masami Hiramatsu > > Blacklist symbols in arch-defined probe-prohibited areas. > With this change, user can see all symbols which are prohibited > to probe in debugfs. > > All archtectures which have custom prohibit areas should define > its own arch_populate_kprobe_blacklist() function, but unless that, > all symbols marked __kprobes are blacklisted. What about iterating all symbols and use arch_within_kprobe_blacklist() to check if we need to blacklist them or not. In this way we don't have to introduce an arch_populate_kprobe_blacklist() for each architecture. Something like the following maybe. Thanks. [RFC] kprobes: blacklist all symbols in arch-defined prohibited area From: Andrea Righi Blacklist symbols in arch-defined probe-prohibited areas. With this change, user can see all symbols which are prohibited to probe in debugfs. Signed-off-by: Masami Hiramatsu Signed-off-by: Andrea Righi --- kernel/kprobes.c | 55 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 90e98e233647..e67598dd7468 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -2093,6 +2093,35 @@ void dump_kprobe(struct kprobe *kp) } NOKPROBE_SYMBOL(dump_kprobe); +static int kprobe_blacklist_add(unsigned long entry) +{ + struct kprobe_blacklist_entry *ent; + unsigned long offset = 0, size = 0; + + if (!kernel_text_address(entry) || + !kallsyms_lookup_size_offset(entry, &size, &offset)) + return -EINVAL; + + ent = kmalloc(sizeof(*ent), GFP_KERNEL); + if (!ent) + return -ENOMEM; + ent->start_addr = entry; + ent->end_addr = entry + size; + INIT_LIST_HEAD(&ent->list); + list_add_tail(&ent->list, &kprobe_blacklist); + + return 0; +} + +static int arch_populate_kprobe_blacklist(void *data, const char *name, + struct module *mod, + unsigned long entry) +{ + if (arch_within_kprobe_blacklist(entry)) + kprobe_blacklist_add(entry); + return 0; +} + /* * Lookup and populate the kprobe_blacklist. * @@ -2104,24 +2133,22 @@ NOKPROBE_SYMBOL(dump_kprobe); static int __init populate_kprobe_blacklist(unsigned long *start, unsigned long *end) { - unsigned long *iter; - struct kprobe_blacklist_entry *ent; - unsigned long entry, offset = 0, size = 0; + unsigned long entry, *iter; + int ret; + /* Blacklist all arch_within_kprobe_blacklist() symbols */ + mutex_lock(&module_mutex); + kallsyms_on_each_symbol(arch_populate_kprobe_blacklist, NULL); + mutex_unlock(&module_mutex); + + /* Add explicitly blacklisted symbols */ for (iter = start; iter < end; iter++) { entry = arch_deref_entry_point((void *)*iter); - - if (!kernel_text_address(entry) || - !kallsyms_lookup_size_offset(entry, &size, &offset)) + ret = kprobe_blacklist_add(entry); + if (ret == -EINVAL) continue; - - ent = kmalloc(sizeof(*ent), GFP_KERNEL); - if (!ent) - return -ENOMEM; - ent->start_addr = entry; - ent->end_addr = entry + size; - INIT_LIST_HEAD(&ent->list); - list_add_tail(&ent->list, &kprobe_blacklist); + if (ret < 0) + return ret; } return 0; }