Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1506317ybk; Thu, 21 May 2020 08:27:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRST0v8u+LKtfNagcA7gh+xfriawudSNCptBql986BYFaV33TG49goD79vCco/guHxNhMT X-Received: by 2002:a50:9b58:: with SMTP id a24mr7705790edj.256.1590074878707; Thu, 21 May 2020 08:27:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590074878; cv=none; d=google.com; s=arc-20160816; b=ellBY0TdykQ3WxAWkrnhsxIRXvhxrNPuxW8K9GQ5zzJCKQpQubvM7aRQF2eN0Bv1hV 0RU5yzc5Xj8vNSQvJP9rtCwSYIv1wlTmn/nqnXdY79TiT+jLlG8zSsLGbBGH1J7F2MgA f4CkF3o1TfUFJXuharlA3qQBMa1+4DFI3KEXPNQ1ZEnRAsuCqkKBPI+1pOJydRwX99yx svRXdFqmXaGmAySvyRFtPY2uHMChXVH+mLrsVpsijXZ2awK4u0C0Ce026E5Sn2jVWcLk 4KE8S68uyH+FV9Xfb4lOhv+wuoSwRGslsMtQi5kegsoyFMgnjakwBgvryK5PfCDVA7UI 7a/g== 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:date:subject:cc:to:from :dkim-signature; bh=V3sFdWlGraEdlC3I/bIfjhE1S8jpT74WDIoCxf3hPhY=; b=S39dIPmvGP/sXVApxQ4AlWAfcwSmJuRknk1sMVn2fhU6oNcpwYgf1kfbrGrrHH7UjY U+GYoBKhTUhhTNxgF23bsil+fidVIL8hGnHEWp5Gk0mvGztBjnafdzHcdrc18ibHZv0+ kFoaIEJObCoz2JTN7rzS7H2NeOxdcWWNet++1/E83yteQlsHSDSY0MEPs1AD+MiQ9hD3 QUAUl4mJRDeNo0zbiW1zUVjyGAPQvjZEDXI8h5MJkZHMtci2wvn4ASlfIWd1+sL6GUFo yQNqDGv1UBrEGnph+QulDZRl+zGUQcdmhNAnVdgd2TJbWTR+YmtBalA/wRnmCVVJQYTw JQvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=o+3+sQwx; 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 od24si3615022ejb.691.2020.05.21.08.27.35; Thu, 21 May 2020 08:27:58 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=o+3+sQwx; 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 S1730171AbgEUPXm (ORCPT + 99 others); Thu, 21 May 2020 11:23:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730109AbgEUPXi (ORCPT ); Thu, 21 May 2020 11:23:38 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F815C061A0E; Thu, 21 May 2020 08:23:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=V3sFdWlGraEdlC3I/bIfjhE1S8jpT74WDIoCxf3hPhY=; b=o+3+sQwxPcLlavSAzP5Wb5mlV7 4pJUfozGOBi+EIdePhgfn8R7BXuK2VW+obVElYBj27JQHb2XZMxDpZqD4cKu6yd1Wxi3zmUey9w4G cSMuw9ovKiqDPDFdMm4g3jRhW2zBbAiBjNndhVDynW8RLwzBEOxtIhEfjSSbDZtt7iOT+FE8Lp/X1 4zpZKlYtOXAtDNdzckmlEGshqtiEiBMF4FjH5cFnTCrwuLlhqu1mhJVCN+7oH3wmcyjYZDegy6Ic7 B6VUnU34PLKnYbmSvgeCI+h00IT3Tyahd8vT8OxgqcmtSYXZH/bYgX5Ix8xedieOXDC7SKeM/T4f0 k/gEciKw==; Received: from [2001:4bb8:18c:5da7:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jbn2m-0004RB-Pa; Thu, 21 May 2020 15:23:37 +0000 From: Christoph Hellwig To: x86@kernel.org, Alexei Starovoitov , Daniel Borkmann , Masami Hiramatsu , Linus Torvalds , Andrew Morton Cc: linux-parisc@vger.kernel.org, linux-um@lists.infradead.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 11/23] bpf: factor out a bpf_trace_copy_string helper Date: Thu, 21 May 2020 17:22:49 +0200 Message-Id: <20200521152301.2587579-12-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521152301.2587579-1-hch@lst.de> References: <20200521152301.2587579-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Split out a helper to do the fault free access to the string pointer to get it out of a crazy indentation level. Signed-off-by: Christoph Hellwig --- kernel/trace/bpf_trace.c | 42 +++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index f5231ffea85b9..9d4080590f711 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -321,6 +321,28 @@ static const struct bpf_func_proto *bpf_get_probe_write_proto(void) return &bpf_probe_write_user_proto; } +static void bpf_trace_copy_string(char *buf, void *unsafe_ptr, char fmt_ptype, + size_t bufsz) +{ + void __user *user_ptr = (__force void __user *)unsafe_ptr; + + buf[0] = 0; + + switch (fmt_ptype) { + case 's': +#ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE + strncpy_from_unsafe(buf, unsafe_ptr, bufsz); + break; +#endif + case 'k': + strncpy_from_kernel_nofault(buf, unsafe_ptr, bufsz); + break; + case 'u': + strncpy_from_user_nofault(buf, user_ptr, bufsz); + break; + } +} + /* * Only limited trace_printk() conversion specifiers allowed: * %d %i %u %x %ld %li %lu %lx %lld %lli %llu %llx %p %pks %pus %s @@ -403,24 +425,8 @@ BPF_CALL_5(bpf_trace_printk, char *, fmt, u32, fmt_size, u64, arg1, break; } - buf[0] = 0; - switch (fmt_ptype) { - case 's': -#ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE - strncpy_from_unsafe(buf, unsafe_ptr, - sizeof(buf)); - break; -#endif - case 'k': - strncpy_from_kernel_nofault(buf, unsafe_ptr, - sizeof(buf)); - break; - case 'u': - strncpy_from_user_nofault(buf, - (__force void __user *)unsafe_ptr, - sizeof(buf)); - break; - } + bpf_trace_copy_string(buf, unsafe_ptr, fmt_ptype, + sizeof(buf)); goto fmt_next; } -- 2.26.2