From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1CC6C282C0 for ; Thu, 24 Jan 2019 01:43:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9D397218A2 for ; Thu, 24 Jan 2019 01:43:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548294207; bh=aUwgTXxzagthyccfuLTO3DlniJHXKNpLtIQKc2o3ljU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-ID:From; b=0313jpgQcaHAkzcJHzq2zaY6aQTDjsS2pM4MO42777W/IlYbMvnUAt+HF15DmLR5p WvZJioYCnWkbCA0VraML2uLJDmLzyMkh1BfQn2kGccG9CallPruFJgFFqUXX8clAO2 tkTDhwoobqbNv/W1FBtpnuyzcKD5ghLrSHdLUXs8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726986AbfAXBn0 (ORCPT ); Wed, 23 Jan 2019 20:43:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:46776 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726236AbfAXBnZ (ORCPT ); Wed, 23 Jan 2019 20:43:25 -0500 Received: from devbox (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 3D1A121872; Thu, 24 Jan 2019 01:43:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548294205; bh=aUwgTXxzagthyccfuLTO3DlniJHXKNpLtIQKc2o3ljU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=PAli6chxH+c3DHR1SAfd38ohAAEt6u8aFZ8HgkCfa6Ypjtbr+uPDxdsM+yu8X1fr8 TWafgMFO7AN6QYbjbJR3ORNFoylq+H+zgiszE46LbGCEesrMtyRO+LdizyJwol2sTQ M/0TdqCj6sgBAgbWYztG7j/6gCmAR7KR3VILYiOo= Date: Thu, 24 Jan 2019 10:43:22 +0900 From: Masami Hiramatsu To: Steven Rostedt Cc: Andreas Ziegler , Ingo Molnar , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/3] tracing: uprobes: Re-enable $comm support for uprobe events Message-Id: <20190124104322.29e62ee0024c77a40110d569@kernel.org> In-Reply-To: <20190123034005.2b49e4fe@vmware.local.home> References: <154778663676.19927.12774448308165809570.stgit@devbox> <154778666570.19927.5960654930869453736.stgit@devbox> <20190123034005.2b49e4fe@vmware.local.home> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-redhat-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 Wed, 23 Jan 2019 03:40:05 -0500 Steven Rostedt wrote: > On Fri, 18 Jan 2019 13:44:25 +0900 > Masami Hiramatsu wrote: > > > Since commit 533059281ee5 ("tracing: probeevent: Introduce new > > argument fetching code") dropped the $comm support from uprobe > > events, this re-enables it. > > > > For $comm support, uses strlcpy() instead of strncpy_from_user() > > to copy current task's comm. Because it is in the kernel space, > > strncpy_from_user() always fails to copy the comm. > > This also uses strlen() instead of strnlen_user() to measure the > > length of the comm. > > > > Fixes: 533059281ee5 ("tracing: probeevent: Introduce new argument fetching code") > > Signed-off-by: Masami Hiramatsu > > Reported-by: Andreas Ziegler > > Acked-by: Andreas Ziegler > > --- > > kernel/trace/trace_uprobe.c | 15 +++++++++++++-- > > 1 file changed, 13 insertions(+), 2 deletions(-) > > > > diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c > > index 3a1d5ab6b4ba..b07e498ccbc6 100644 > > --- a/kernel/trace/trace_uprobe.c > > +++ b/kernel/trace/trace_uprobe.c > > @@ -156,7 +156,10 @@ fetch_store_string(unsigned long addr, void *dest, void *base) > > if (unlikely(!maxlen)) > > return -ENOMEM; > > > > - ret = strncpy_from_user(dst, src, maxlen); > > + if (addr == (unsigned long)current->comm) > > + ret = strlcpy(dst, current->comm, maxlen); > > As user space (although only root) defines the size of the event being > stored, and we could trick addr to be current->comm (although > difficult), we could possibly leak data if maxlen is > TASK_COMM_LEN. I > would feel better if we tested maxlen against TASK_COMM_LEN in this > case. > > if (maxlen > TASK_COMM_LEN) > maxlen = TASK_COMM_LEN; > > Or if we don't think it can happen, add a WARN_ON(maxlen > > TASK_COMM_LEN). Hmm, I thought current->comm is null terminated, isn't it? Anyway, if user can specify current->comm, he must be able to specify current->comm + TASK_COMM_LEN too by kprobe_events. Moreover, it can leak any data in kernel... And also, maxlen is calculated by fetch_store_strlen, right before this has been called. I rather concern the case that if we have shorter size of maxlen than current->comm. Would we better show "(fault)" or tail-cut name ? (of course this is very difficult to happen, since the length is already checked.) Thank you, > > -- Steve > > > > + else > > + ret = strncpy_from_user(dst, src, maxlen); > > if (ret >= 0) { > > if (ret == maxlen) > > dst[ret - 1] = '\0'; > > @@ -180,7 +183,12 @@ fetch_store_strlen(unsigned long addr) > > int len; > > void __user *vaddr = (void __force __user *) addr; > > > > - len = strnlen_user(vaddr, MAX_STRING_SIZE); > > + if (addr == (unsigned long)current->comm) { > > + len = strlen(current->comm); > > + if (len) > > + len++; > > + } else > > + len = strnlen_user(vaddr, MAX_STRING_SIZE); > > > > return (len > MAX_STRING_SIZE) ? 0 : len; > > } > > @@ -220,6 +228,9 @@ process_fetch_insn(struct fetch_insn *code, struct pt_regs *regs, void *dest, > > case FETCH_OP_IMM: > > val = code->immediate; > > break; > > + case FETCH_OP_COMM: > > + val = (unsigned long)current->comm; > > + break; > > case FETCH_OP_FOFFS: > > val = translate_user_vaddr(code->immediate); > > break; > -- Masami Hiramatsu