Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp574503pxb; Wed, 6 Oct 2021 10:46:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAQnV3z8/ocEqAmmY1IdoNfN/1GKA+xKI2CWxRVvxru3xKPHKgCtXebJgBDN47DHasGc+Y X-Received: by 2002:a17:902:6f01:b0:138:9aca:efda with SMTP id w1-20020a1709026f0100b001389acaefdamr12424900plk.19.1633542414804; Wed, 06 Oct 2021 10:46:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633542414; cv=none; d=google.com; s=arc-20160816; b=tLsgHqBf339SlOggmVtfhjK8OTf5GAy4u2Ganvu27ycy74F3d+pgTp059eIbomThzq JSiSSu3cjjxcYD7DO9yqcKmeP+LAXrekZap+CVBeVmKyP7QUedtHPuHyuDP1gwOQCVez d+2JlATUJUnoxJfvLI96o7TxFOjUETF3iyEgWNnKzEMQL4jMhVtakaDmBdM8swZlzoze T6FIZRArGedPEvahEou2sZE6PLZspjfz1mLEJMa4uc9qx1ka7+4N4Vqz8lesxJsBUBQF dq5EPU22CYekwdJPIa9ql65rKysWAYkOXf8O+UZ3fEduC1oeWjjmZXnFGMjJIb/27ZC3 PtcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=i/n+QiDlTHVITracDNEhPJ1sHflh5sKMrbbd7HbQrzk=; b=d/0l0UdFdt6V1wMj9528ka0attm9PEF5Oekpi0LISh3/3Ut/kjY3ZGlINelQyvDJka 8PVFSOiN5TVnnfKqR8Ekmcf1K90x+BK7oPOXloQ/YXs5N3E61CWuxCiw6vWxNQHlpp+2 TmkP+d95mWhyHqCrG1CnUlVAOlCn+bqrtRsgQVGn0ZfVqHshK2TJNWWT+Q3DpFgKRFho qpoX0IviWKqVoYy/ef5yUUc39KWQkw5ClI1xaPtBpAiRsCFKsiG5iqBoF94AiBGfGn5b e10IwRv51hTakIl9iC6hlRYAbiAjs3qqEFDVbnaZRzbkffZ0AK2eOaUfPZT+ZpXiIrYs hPmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r142si13561199pfc.275.2021.10.06.10.46.41; Wed, 06 Oct 2021 10:46:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238617AbhJFRqf (ORCPT + 99 others); Wed, 6 Oct 2021 13:46:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:36388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238534AbhJFRqW (ORCPT ); Wed, 6 Oct 2021 13:46:22 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (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 B2689610E6; Wed, 6 Oct 2021 17:44:29 +0000 (UTC) Date: Wed, 6 Oct 2021 13:44:28 -0400 From: Steven Rostedt To: Beau Belgrave Cc: mhiramat@kernel.org, linux-trace-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] user_events: Enable user processes to create and write to trace events Message-ID: <20211006134428.1132ebe0@gandalf.local.home> In-Reply-To: <20211006172723.GA2812@kbox> References: <20211005224428.2551-1-beaub@linux.microsoft.com> <20211006125441.24982dd3@gandalf.local.home> <20211006172723.GA2812@kbox> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 6 Oct 2021 10:27:23 -0700 Beau Belgrave wrote: > On Wed, Oct 06, 2021 at 12:54:41PM -0400, Steven Rostedt wrote: > > > Psuedo code example of typical usage: > > > page_fd = open("user_events_mmap", O_RDWR); > > > page_data = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, page_fd, 0); > > > > > > data_fd = open("user_events_data", O_RDWR); > > > data_id = ioctl(data_fd, DIAG_IOCSREG, "test"); > > > > > > if (page_data[data_id]) write(data_fd, &payload, sizeof(payload)); > > > > What is the type of "page_data". I'd like to test it before accepting it. > > > > From playing around, I see that page_data is of type char *. > Yes, it is char *. I'll make this clear in the next patch version > description. Thanks. > > > > +/* Bits 0-6 are for known probe types, Bit 7 is for unknown probes */ > > > +#define EVENT_BIT_FTRACE 0 > > > +#define EVENT_BIT_PERF 1 > > > +#define EVENT_BIT_OTHER 7 > > > + > > > +#define EVENT_STATUS_FTRACE (1 << EVENT_BIT_FTRACE) > > > +#define EVENT_STATUS_PERF (1 << EVENT_BIT_PERF) > > > +#define EVENT_STATUS_OTHER (1 << EVENT_BIT_OTHER) > ... > > > +#define DIAG_IOC_MAGIC '*' > > > +#define DIAG_IOCSREG _IOW(DIAG_IOC_MAGIC, 0, char*) > > > +#define DIAG_IOCSDEL _IOW(DIAG_IOC_MAGIC, 1, char*) > > > +#define DIAG_IOCQLOCOFFSET _IO(DIAG_IOC_MAGIC, 2) > > > > These obviously will need to go into a user abi header file. > > > Yes, I'm glad you mentioned it. I wasn't entirely sure where it should > live. Is there precedent on where to put these so they span both kernel > and user for discovery / distribution? There is a include/uapi directory in the Linux source code. I've never added to it (that I remember, but maybe I have? Wouldn't surprise me if I did and forgot about it :-p Sucks getting old). > > > > + > > > +static char *register_page_data; > > > + > > > +static DEFINE_HASHTABLE(register_table, 4); > > > +static DECLARE_BITMAP(page_bitmap, MAX_EVENTS); > > > + > > > +struct user_event { > > > + struct tracepoint tracepoint; > > > + struct trace_event_call call; > > > + struct trace_event_class class; > > > + struct dyn_event devent; > > > + struct hlist_node node; > > > + atomic_t refs; > > > + int index; > > > + char *args; > > > +}; > > > + > > > +#ifdef CONFIG_PERF_EVENTS > > > +struct user_bpf_context { > > > + int udatalen; > > > + const char __user *udata; > > > +}; > > > +#endif > > > + > > > +typedef void (*user_event_func_t) (struct user_event *user, > > > + const char __user *udata, > > > + size_t udatalen, void *tpdata); > > > + > > > +static int register_user_event(char *name, char *args, > > > + struct user_event **newuser); > > > + > > > > [..] > > > Is the ask here to get user_bpf_context definition also into a user ABI > header? (I took it as that). Not sure I understand the question. > > > > +static int __init trace_events_user_init(void) > > > +{ > > > + int ret; > > > + > > > + /* Zero all bits beside 0 (which is reserved for failures) */ > > > + bitmap_zero(page_bitmap, MAX_EVENTS); > > > + set_bit(0, page_bitmap); > > > + > > > + register_page_data = kmalloc(MAX_EVENTS, GFP_KERNEL); > > > > You want "kzalloc" here. Because when I read the map without adding > > anything, I get: > > > > printf("%lx\n", *(unsigned long *)page_data); > > > > Produces: > > > > ffffffff9065004e > > > > But if I convert it to kzalloc() it gives me: > > > > 0 > > > > Thus, you are exposing stale memory. If you want to expose this to > > non-admin users, this is a major security leak. > > > > -- Steve > > > Oops, sorry about that! No problem. Just pointing it out. I expect that this is going to take a few back and forth to get right. But I do like the way it is heading. -- Steve