Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1323062imu; Fri, 7 Dec 2018 19:43:05 -0800 (PST) X-Google-Smtp-Source: AFSGD/UYQRpWu/QoxVP8S+jfL2TkYjyNOELBw0L/MS2y9/AC11uOt+SjAo/LPoOL1nL2NOhvk8n6 X-Received: by 2002:a17:902:6e0f:: with SMTP id u15mr4437222plk.175.1544240585917; Fri, 07 Dec 2018 19:43:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544240585; cv=none; d=google.com; s=arc-20160816; b=zzX9jvqttqya7dr6UGrxrtUMamIcy6YA4RZ6AXwHCznfFBeAYaA7XNVZB0qILjY+wb gA1HWngV21F+XN5kBac37Lda43qCo5Xd8pheUxqrKMxp4tj8/t13nCnDCMCmT9w/RNaK 7bGYLexcyvxup85UoAWsMAow5UbdGv0NNlEEt3lYaXhue0Moqztsq8n8K0xTV3dDBn6v wZXslUsfzKyeiQ0NIcPrGJaR6WfL+dVxQznNhgp5+g3W0C88d0jlJu7EyhXVE7UeADNs S9SniCZPZ3F7cva6U+W1wYPLjUN7GTsOl/qzpn7hFwd6rKCQW2+JAUYr8g5fy4RzUjw0 5VFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=0eUnqVNnZRlRGX/3zGs28vJ6m5Q78xyWomb50WezOs4=; b=cU9zNcQcWkvrkjRoKtkpUA/y3XkH2voo47HPWNr80YapF4TuXu1WmqII11qajhXxZb r5kKrrRsXZrbl3bTRwmR1BUSs0XMwscANOsCwD5ESgjz3v9/RvN4N1nijDeZBsu1B/gz bQloX1N40SxGw38cSF+yYjPSN7xkM7EQ91Whny7fzhFAJ7ifEz4QgDqqSIYIKlyqz5MR 8renjuMqKt24wqmEsonQcwkHqSt24bxjjYJ4B4PLTVxI6bARmc6k6yAFrHTnSJgD8jaN oB/jgSU9JXqwM5Pxz72TSR74XQaTbGg8dc5+PcUNz1IfYuSxuZZdnb8p4cuOjKL/x9v4 Tv0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UI3CR0sc; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j5si4736684pfg.254.2018.12.07.19.42.50; Fri, 07 Dec 2018 19:43:05 -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=@kernel.org header.s=default header.b=UI3CR0sc; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726146AbeLHDmQ (ORCPT + 99 others); Fri, 7 Dec 2018 22:42:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:57700 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726077AbeLHDmP (ORCPT ); Fri, 7 Dec 2018 22:42:15 -0500 Received: from devnote (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 130022083D; Sat, 8 Dec 2018 03:42:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544240534; bh=HpuI/iXOie6DYydNZ/GjJmWFzgjbhpYCqpYKVxtgqWI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=UI3CR0sc49v0mkEZPYfWWBW1aCxiNtmPLIPCf1wOmfmMItWL3rh/CrcypdrXFcFBT BBYmccDlq3z43NnWtuuKXkhH/hzjVonhw8y6TyfT4e/27aFGUwWes9iWH7RxlAmAnw 9cWaVlm4mfZIUm1MsmxIK2pySbVY+sWZGSNYmNj4= Date: Sat, 8 Dec 2018 12:42:10 +0900 From: Masami Hiramatsu To: Andrea Righi 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: <20181208124210.7f46eb88544e2e3899713052@kernel.org> In-Reply-To: <20181207170026.GA1379@Dell> References: <20181206095648.GA8249@Dell> <20181207234731.f52a8c1eff6c0e72c073ad40@kernel.org> <20181208010120.c3eda9042912068aecc68317@kernel.org> <20181207170026.GA1379@Dell> X-Mailer: Sylpheed 3.5.0 (GTK+ 2.24.30; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 7 Dec 2018 18:00:26 +0100 Andrea Righi wrote: > 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. > > > > Reported-by: Andrea Righi > > Signed-off-by: Masami Hiramatsu > > --- > > [snip] > > > +int kprobe_add_ksym_blacklist(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 - offset; > > + ent->end_addr = entry - offset + size; > > Do we need to take offset into account? The code before wasn't using it. Yes, if we hit an alias symbol (zero-size), we forcibly increment address and retry it. In that case, offset will be 1. > > > + INIT_LIST_HEAD(&ent->list); > > + list_add_tail(&ent->list, &kprobe_blacklist); > > + > > + return (int)size; > > +} > > + > > +/* Add functions in arch defined probe-prohibited area */ > > +int __weak arch_populate_kprobe_blacklist(void) > > +{ > > + unsigned long entry; > > + int ret = 0; > > + > > + for (entry = (unsigned long)__kprobes_text_start; > > + entry < (unsigned long)__kprobes_text_end; > > + entry += ret) { > > + ret = kprobe_add_ksym_blacklist(entry); > > + if (ret < 0) > > + return ret; > > + if (ret == 0) /* In case of alias symbol */ > > + ret = 1; Here, we incremented. Thank you, > > + } > > + return 0; > > +} > > + > > /* > > * Lookup and populate the kprobe_blacklist. > > * > > @@ -2104,26 +2142,20 @@ NOKPROBE_SYMBOL(dump_kprobe); > > static int __init populate_kprobe_blacklist(unsigned long *start, > > unsigned long *end) > > { > > + unsigned long entry; > > unsigned long *iter; > > - struct kprobe_blacklist_entry *ent; > > - unsigned long entry, offset = 0, size = 0; > > + int ret; > > > > 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_add_ksym_blacklist(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; > > + > > + return arch_populate_kprobe_blacklist(); > > } > > > > /* Module notifier call back, checking kprobes on the module */ -- Masami Hiramatsu