Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3927030pxp; Wed, 23 Mar 2022 08:15:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyB4JdtIpOx/zabO5tBxPqUghMmP3wHsAMP0253tjoaEnSvBnLumAbARQU2Rw1+ig+S70g2 X-Received: by 2002:a17:90a:5a86:b0:1bf:7860:c0f6 with SMTP id n6-20020a17090a5a8600b001bf7860c0f6mr12190424pji.213.1648048539580; Wed, 23 Mar 2022 08:15:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648048539; cv=none; d=google.com; s=arc-20160816; b=vdKgP/DePnC0VFnbxcenK0DNl+cMWP/9yGWs16G6omY71yzaNwlu1yPS8XYxEVYwJN 4tU6qo66TPUPWsrWjSTUMHiAUKBJideMbEyBjWSpi3SYatEOiz2xBuUp3tyNDEy9jbpB LSFHJWEHyjGCSce3+5SUBMi74yPqBgHiwgKlQeNeTA5LFtVqMnh+zbaAolbw9CZMbDBp KvjKnMtpWFugnR8aRJnLmgvJjUPMpm1Q512HfS+JQikpSfpWtjMmx8xJh4VSCyJd1UOB wfsFmV569iJGyPpsQbDI7hSGezhGg2wQgdVV2UlGngfqAtf8Vm/D1gExqvvoJSu5Py1S D7Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=DOYK8So+AZd7TCdsavhK7vVzd9phodxyXPohOzcUiLk=; b=eJUEHgMEH8Y0IoKCJ5zCApzXlBv7KeTytRz9iSTRLDONeDS0lvQvO7J4DJOqUlxC8W TTtGtTZsquy/LNWfkD88bAyaB9lzF5HyvMflwOJFjI2hepx5nbAHCEBsqTPyz899+qac xTxkQwoP7cqvavNSDc0EhXbOfNcVu8iI1fKF2/NjbXDGb+HqEDI5SX1GKdq3Rtc69AQL pnSdkPZLqVAffJJA4EvSLOqyv8cF+eBohgBYYj/e64/5hQ8ZFSfrd0E3A2uK3HiA5GUT um6hw2B+M50eRSEOYPHWzivDfxDFsHCBYLI/EW1pD8xwgBaPDuAOawfWMNWgxnkhFBCf qiPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EBOGdm18; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ch10-20020a056a00288a00b004fa3a8dff4esi8991037pfb.5.2022.03.23.08.15.24; Wed, 23 Mar 2022 08:15:39 -0700 (PDT) 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=pass header.i=@gmail.com header.s=20210112 header.b=EBOGdm18; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235206AbiCVVMl (ORCPT + 99 others); Tue, 22 Mar 2022 17:12:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230087AbiCVVMk (ORCPT ); Tue, 22 Mar 2022 17:12:40 -0400 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDC642662; Tue, 22 Mar 2022 14:11:12 -0700 (PDT) Received: by mail-io1-xd2d.google.com with SMTP id w7so21733125ioj.5; Tue, 22 Mar 2022 14:11:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DOYK8So+AZd7TCdsavhK7vVzd9phodxyXPohOzcUiLk=; b=EBOGdm18SbzOZ7SoijcSpi89A8Gqmkx7spYqqvHhu/4nSaNWG5/41Lt3FtfJKHCYTB FE5dyMMy688ylsK9sbe0xNWkmo5UxHfQ5Q5WHzmK+5ekxQX28j7l85nexRBOFOtlGegG QrpOp7Fb136h56arpx54x2LvF+9jmLevFqhKyp9A18V7XhpjR2q0Eo0wlJa73sR+aPBa QnlpvemHgShB2Y32sHehxPxKUXS7SfH7UW94UkIsDszM1n1VvwGEjn7QlTioaNV6ZhjY Y0hxvH1GR7kevyMoiJCyZ2dPsWdE+svvPYUntdD1FNXZp+LAGtJcw7vcmf5vnv1lWCIU 9Hyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DOYK8So+AZd7TCdsavhK7vVzd9phodxyXPohOzcUiLk=; b=sHVGOFSbZjstXtdeWXZYz/+KLmRkLM4QNycG8gJXPKHCW4GnTMwHlXFwsz9erMrHxn FqJdn1EA8blA6ZW/WoFeNivU+F6sO4+HRjLGdvJzPb8w/ca/lVQuvxmM3djUt0D9EeUj kf8eBYPmRUqf2rnGTgugTJxoekgixfqepZqNLGCydUTMSSId/ZTwiWgsEQkVD87e6S09 zdShW0Fp9JMOUrxJqEzue3FY22GMOpXS6FL6mzFi6QLJ/MJPklCWW26NZVUZx/xzYVSL 6ZogmZ8ZVk68yuDQqKHt9HhXaoSaWTXSG6aGlgG+2kTATHUYidDIpv5F4iZfhsZN0yKM FJ2g== X-Gm-Message-State: AOAM531F3TlYyZrXNMX1qiq1afOiQCPpan9zsddUyo6mCdy2DLdP1UeL 6eWcHyL55AfTAVxSrtU/T1qEjZ5G3MNGEF971ZA= X-Received: by 2002:a05:6638:4516:b0:321:4911:c292 with SMTP id bs22-20020a056638451600b003214911c292mr4901855jab.145.1647983472263; Tue, 22 Mar 2022 14:11:12 -0700 (PDT) MIME-Version: 1.0 References: <20220322112843.6687-1-hanyihao@vivo.com> In-Reply-To: <20220322112843.6687-1-hanyihao@vivo.com> From: Andrii Nakryiko Date: Tue, 22 Mar 2022 14:11:01 -0700 Message-ID: Subject: Re: [PATCH] bpf: use vmemdup_user instead of kvmalloc and copy_from_user To: Yihao Han Cc: Steven Rostedt , Ingo Molnar , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Networking , bpf , open list , kernel@vivo.com Content-Type: text/plain; charset="UTF-8" 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,T_SCC_BODY_TEXT_LINE 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 On Tue, Mar 22, 2022 at 4:29 AM Yihao Han wrote: > > fix memdup_user.cocci warning: > kernel/trace/bpf_trace.c:2450:12-20: WARNING opportunity > for vmemdup_user > > Signed-off-by: Yihao Han > --- > kernel/trace/bpf_trace.c | 10 +++------- > 1 file changed, 3 insertions(+), 7 deletions(-) > > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c > index 7fa2ebc07f60..aff2461c1ea2 100644 > --- a/kernel/trace/bpf_trace.c > +++ b/kernel/trace/bpf_trace.c > @@ -2447,13 +2447,9 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr > > ucookies = u64_to_user_ptr(attr->link_create.kprobe_multi.cookies); > if (ucookies) { > - cookies = kvmalloc(size, GFP_KERNEL); > - if (!cookies) { > - err = -ENOMEM; > - goto error; > - } > - if (copy_from_user(cookies, ucookies, size)) { > - err = -EFAULT; > + cookies = vmemdup_user(ucookies, size); does kvfree() handle ERR_PTR() values properly? I doubt so. Did you validate your change or just blindly applied some tool? > + if (IS_ERR(cookies)) { > + err = PTR_ERR(cookies); > goto error; > } > } > -- > 2.17.1 >