From patchwork Mon Nov 21 08:08:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuang Wang X-Patchwork-Id: 23579 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1449603wrr; Mon, 21 Nov 2022 00:15:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf5w3rxXf8gKmSFPUSR1zBZmYrKK1AwKXSSd21OfYVse27R3ZZQZM5nDOyxVZs+kIz4QeWe9 X-Received: by 2002:a05:6402:2421:b0:461:524f:a8f4 with SMTP id t33-20020a056402242100b00461524fa8f4mr13655748eda.260.1669018509870; Mon, 21 Nov 2022 00:15:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669018509; cv=none; d=google.com; s=arc-20160816; b=ejaKzFCZtBzMSRu03Lh6uyYxAoi31YbBhLrnIVJ95OJjNfJO6uD0w4EEskMjFT3uXo tqHUYEE0lP3vEUeeVz6xQmA5ePCaWtX4XlrRo+g6z5m9tou+rU7Ses2r90+6kkV/pjSq GNLE+EUtemyQrW/Wqq6YZyjN+mg79WvfD0o9ov/8IDiyJxjpcgndvkiTERpAY0sK6NT8 2gBUtpY2iuqd9Wiv9TZ8UUxhOGIlRW6B/oVfp3n9tCRqNfRk9jbdAWifXUd486n2GbF/ 5toc2IrllKKbBF1v12X6rgoiIWel0tDpCXsYRv8q2x/vSNRanxTG0WaSD7Qe+1t6IdbF yNTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=ctzOaxaAqUph8NY0exPI9fEfZOLZGp5hg2p+b/QRssE=; b=od65lb+fMVGeRqV7AmkeVr/mYGeY9z8dcJRwEw9BLM64xgyBLFurnMJoE+qGVe2wBu nv7pce+unt9lXTPQOV5wnXqiXAWRl6cdK6LG4O+DQfqKI4jEoitugZ/hw16ZeRUkZSlK G64wcZAW99q+i0ZNwVUEFSdjTTXX0G9qM6lSEmGyWdyKvO9d+atiHQaMW8P7aNc6squX J2pPIPoxewPGteuPIvHPQrmRUfsIGWqQImEkCb1qkGkkDCq7z5fR2ojUElzLujSY3EPk 3LTSXIsTf+vPlg/sJBuEVzJJBXpzHYjI9ZnSiqpQmxf0aBSmgE0Y/FQ6uaOnjB+XQ1pp sR3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=KN3b37Yt; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p17-20020a056402501100b00460ce6c3a1asi8844920eda.454.2022.11.21.00.14.45; Mon, 21 Nov 2022 00:15:09 -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; dkim=fail header.i=@gmail.com header.s=20210112 header.b=KN3b37Yt; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229885AbiKUII5 (ORCPT + 99 others); Mon, 21 Nov 2022 03:08:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229598AbiKUIIv (ORCPT ); Mon, 21 Nov 2022 03:08:51 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF482165B2 for ; Mon, 21 Nov 2022 00:08:48 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id y14-20020a17090a2b4e00b002189a1b84d4so4158558pjc.2 for ; Mon, 21 Nov 2022 00:08:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ctzOaxaAqUph8NY0exPI9fEfZOLZGp5hg2p+b/QRssE=; b=KN3b37Ytia5wSuCz2QSXTAaiZbNm4/cnqhN8yPeNbPDdsHxlqAwx61CEagM5n8uSEJ 33yO1yGeBq9VBNl+5UWa7YqniTRmqkb27J8IuKA5+Fb/HJwZnS1L4K8Fvl6JUtSN9X8S VUchU5umNRq0uAjYx8FET0BMrzHqqfK2bksAh1GER/ngds1mA5rcgpAf7t/Gq+q2PT2p 4CbTQvpj511arCvwfTxO43IFEMpJ187SKn4abM/3L0q7tVCiEZ2UgHi/sLWHG5gaV3sm 8x62zURvIRN7RcmiXE3ocSlQaincr5pi/WDX2sV2+rznkDu9MR+9JPiLfjxDee/zVEQu 6vvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ctzOaxaAqUph8NY0exPI9fEfZOLZGp5hg2p+b/QRssE=; b=HjA0LBl4Rg+4hj/otz/FxQstnwxZiKhGUE+t9wURx9wa/kXzROOlGiIxa0958zyuCl FZJKp9jOFFg0GC8manXi/lgFiOZ6Kzbn5oKaol6JOM6U7eM5y8oVBPmQA71RngSXOPzv 8BgmguyKRO0+/ZHFrmtlDWfuJiJWIoMqc+WlE4J7brnPthXZxYtAT99y6JD4KrLQI0+F R0BeIO65WkWRqEVijghdFIEjQ+FWaxppU4tPpY7ebsUABynpTvARoL2/rxJ7OOZWYJ0E BLrDq3+E+ntvTcXbMea9VbcOKjfwR/e0xa4NOxIYcsCJSg1UId8OIZ1KszAVruMGu9G9 +/Jg== X-Gm-Message-State: ANoB5pkiqY/sL7Jh/IlEb5ZROlqbX1rERmkGsnKDGWS6H4FZ7XCIVWTm onSTltH5sOEYbHdTOf2yVcaDp8z/lAs= X-Received: by 2002:a17:90b:1d45:b0:218:6db5:fd98 with SMTP id ok5-20020a17090b1d4500b002186db5fd98mr20273666pjb.164.1669018128222; Mon, 21 Nov 2022 00:08:48 -0800 (PST) Received: from localhost.localdomain ([47.242.114.172]) by smtp.gmail.com with ESMTPSA id bh6-20020a17090b048600b00218847a356bsm5929506pjb.9.2022.11.21.00.08.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Nov 2022 00:08:47 -0800 (PST) From: Chuang Wang Cc: Chuang Wang , Steven Rostedt , Masami Hiramatsu , linux-kernel@vger.kernel.org Subject: [PATCH] tracing/perf: Use strndup_user instead of kzalloc/strncpy_from_user Date: Mon, 21 Nov 2022 16:08:31 +0800 Message-Id: <20221121080831.707409-1-nashuiliang@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 To: unlisted-recipients:; (no To-header on input) 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?1750092753354500638?= X-GMAIL-MSGID: =?utf-8?q?1750092753354500638?= This patch uses strndup_user instead of kzalloc + strncpy_from_user, which makes the code more concise. Signed-off-by: Chuang Wang --- 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);