From patchwork Thu Nov 24 14:50:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 25607 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3442895wrr; Thu, 24 Nov 2022 06:55:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf4lJseIglD0Wfr1OcRDDwNGxNCGNAxLFFMbJUw0nVEOqDGQUTigEvb8J/0cI6cksjgVBh7f X-Received: by 2002:a05:6402:1d87:b0:459:41fa:8e07 with SMTP id dk7-20020a0564021d8700b0045941fa8e07mr13168300edb.140.1669301742027; Thu, 24 Nov 2022 06:55:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669301742; cv=none; d=google.com; s=arc-20160816; b=WMry6Xjqu1OGdnQWOBqGTSmcbBlo1ZT1RxUSidInihHCGkBraLMR0TvLbKfK9NwKk/ ocS1I31oiAMdFSZBUHIGhZPFJ3NV17BdPAA9Tx1sBz4eKyvQvtHmtnsUhSpBhm7aoncC +A7uX46YucFhG9t/lMRmkyAKf2mljxp54DHMa4KguTq5RQsPeE3ZiSK8nOT6Q8JsWQak 2/usfNaJIotdORhE7bUpbTlY8rXwewxtOPRccmyNQzdJgUgtnCdUP0orCUFcRo2eE9fz x7Y4aHb68QtCj7HZmC9RKvffulDdxgSdPAb+xNjO+4B/MjPAy31DXPlsXa/g8gh7fRjG /VOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=dNIofMo5INLTuJz6SlAcVPPKnJASktL6YfrzFbg9N7s=; b=DkzWHQBH55Ho11a0J/SY6irbdst1MRmuEMWE1PaGcILovYxPZ6Fig7YfQ3X2ExBoQS HajKU7TbRO1OquUNwqGvgEoiPFWwHWNpccL1sBD9r5KtwUab9B+oFAEpaKb9hix+kOLf kiLDttlRdo91MKl5qh6w3uN3S9ZaHvGwZRcJu1DLYONbwj5Ifxgaysg6OlWpoOgpDzY+ n0o9MHU/UyL00Wh+K5CnzHQHpSSgblOdXm19Lj6KP/G3dxT0jdYb3/MSj8uopOZwPJFS viHGGFr7o2byv73ciqUDXAUxLDbDU+ZOOgdexr7MaQgqTUtiuXRgJV8s/OReFTKMTss4 ZOjg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sb29-20020a1709076d9d00b0078d9f1f72bcsi388501ejc.726.2022.11.24.06.55.15; Thu, 24 Nov 2022 06:55:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229741AbiKXOvk (ORCPT + 99 others); Thu, 24 Nov 2022 09:51:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229839AbiKXOvC (ORCPT ); Thu, 24 Nov 2022 09:51:02 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C604134F26 for ; Thu, 24 Nov 2022 06:50:52 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 11F13B8284A for ; Thu, 24 Nov 2022 14:50:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9251CC43146; Thu, 24 Nov 2022 14:50:47 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1oyDYs-001X5z-2F; Thu, 24 Nov 2022 09:50:46 -0500 Message-ID: <20221124145046.573437905@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 24 Nov 2022 09:50:27 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Chuang Wang Subject: [for-next][PATCH 08/11] tracing/perf: Use strndup_user instead of kzalloc/strncpy_from_user References: <20221124145019.782980678@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750389743004486151?= X-GMAIL-MSGID: =?utf-8?q?1750389743004486151?= From: Chuang Wang This patch uses strndup_user instead of kzalloc + strncpy_from_user, which makes the code more concise. Link: https://lkml.kernel.org/r/20221121080831.707409-1-nashuiliang@gmail.com Signed-off-by: Chuang Wang Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_event_perf.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c index 61e3a2620fa3..05e791241812 100644 --- a/kernel/trace/trace_event_perf.c +++ b/kernel/trace/trace_event_perf.c @@ -251,16 +251,12 @@ int perf_kprobe_init(struct perf_event *p_event, bool is_retprobe) struct trace_event_call *tp_event; if (p_event->attr.kprobe_func) { - func = kzalloc(KSYM_NAME_LEN, GFP_KERNEL); - if (!func) - return -ENOMEM; - ret = strncpy_from_user( - func, u64_to_user_ptr(p_event->attr.kprobe_func), - KSYM_NAME_LEN); - if (ret == KSYM_NAME_LEN) - ret = -E2BIG; - if (ret < 0) - goto out; + func = strndup_user(u64_to_user_ptr(p_event->attr.kprobe_func), + KSYM_NAME_LEN); + if (IS_ERR(func)) { + ret = PTR_ERR(func); + return (ret == -EINVAL) ? -E2BIG : ret; + } if (func[0] == '\0') { kfree(func);