From patchwork Thu May 12 14:17:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiabing Wan X-Patchwork-Id: 12847760 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0DB3C433F5 for ; Thu, 12 May 2022 14:17:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355153AbiELORi (ORCPT ); Thu, 12 May 2022 10:17:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345728AbiELORc (ORCPT ); Thu, 12 May 2022 10:17:32 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2133.outbound.protection.outlook.com [40.107.117.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB10D6D3A0; Thu, 12 May 2022 07:17:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NugzCha+YNRm0AeYPv5YUJCKiqT2q6p+QMWGhIe04IcyQuj5mIzIl3JnX9A9T2Reuc1XAQhE/e2frRqt8NSdCseIC4Idmi1zEj0UKTnKiNMz2NGAjiJywDmHRr+Z7PPvDaHEEA49CYnWe03gFUSrp3a4tcuS5bV8ABGY0u9mP1ED/LIxO/K7DDqL/vFV9MRwKxyGMxHvH/6NoeEN6upj9RIl2hpg16//4Xd3sSZl0pa1WFKJrOjuPclpwx8LFwGDwuMXq9qkOwXM6/8fJiwqZr2lckcgafLNAOblCK8N/GLR0SdJgi6cndJrSUgaGNuoGltwPoU+AvWK71DmI6h8Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/8IS6FtOIXEJkMT1RStg3DCcQcP41eEVOrVpG2WUKJs=; b=I7lFuzX9TQWO5xWHZZcYQRGkdbiY8EfK1fibv7HI9S34y/w8zm5zXCk/hM0QvTnogqhYvFt82dTVbO3Z+Ml2Ow49juZEeqGtjiGMyuTfBu0t93l13QC0ahRFAxFJdIkD9UQ3sppLQBpKOr0aGlS5tksPVSldBP7RDZmuvbOdbA1jMyywMNf+xQyg75qcVsgNuWbY2w75l4nx8N2al6pSOfrWV8XL7jt0iBVlPRZ6zVLCMtSNwRlyYt2KLqpxZKspDx8ZaNc4G0h+EXTHOXMugwoaa3RvYwPq0Wx90yAxdc50lwqfQxQUbR/gwT1Wn3w18aPbQIDNQvTlCiYXM2KOPA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo0.onmicrosoft.com; s=selector2-vivo0-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/8IS6FtOIXEJkMT1RStg3DCcQcP41eEVOrVpG2WUKJs=; b=XPOvPpu6GIeMCIBOkWfB8UZxxcEl0MOivuBkibTL3Ock34xGPx2i2CXr54psBmwKOfaPN6lO4WmoJHh87sADuHMUU7j7Usu3e+fcF7ZjTyWZxuYomx5rQEFso8gnE6+TzUjBzKKye+YF/amS4dGBrfhzlKPsraUxwOnd7pwEV6s= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SG2PR06MB3367.apcprd06.prod.outlook.com (2603:1096:4:78::19) by HK0PR06MB2819.apcprd06.prod.outlook.com (2603:1096:203:30::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.21; Thu, 12 May 2022 14:17:29 +0000 Received: from SG2PR06MB3367.apcprd06.prod.outlook.com ([fe80::4591:4f3e:f951:6c8c]) by SG2PR06MB3367.apcprd06.prod.outlook.com ([fe80::4591:4f3e:f951:6c8c%7]) with mapi id 15.20.5227.022; Thu, 12 May 2022 14:17:29 +0000 From: Wan Jiabing To: Steven Rostedt , Ingo Molnar , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Wan Jiabing Subject: [PATCH 1/3] bpf: use 'error_xxx' tags in bpf_kprobe_multi_link_attach Date: Thu, 12 May 2022 22:17:08 +0800 Message-Id: <20220512141710.116135-2-wanjiabing@vivo.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220512141710.116135-1-wanjiabing@vivo.com> References: <20220512141710.116135-1-wanjiabing@vivo.com> X-ClientProxiedBy: HK2PR02CA0133.apcprd02.prod.outlook.com (2603:1096:202:16::17) To SG2PR06MB3367.apcprd06.prod.outlook.com (2603:1096:4:78::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cf9f34b8-eca8-4f10-5b08-08da342225d2 X-MS-TrafficTypeDiagnostic: HK0PR06MB2819:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZvwXzbxNVGn4pfkaSOzeOgg5cs28T3007fbevJo1EgV0MTBETUz99JZ5c/wUdIGbBUc+JwgQtkDniYWYjvGBxk0WtYoadtzqa5wK5XslId2e+vyenVPVK4PZoJolkzlK6lwshziKix0e0gymYXI3dx2V0Kambm9Mn3xck6ViwS9cmAZxqHvQQLQWKtXN20kB3wxf/En3ac+637U768vsyFtfhq0X9I88ZWofDaid+sfdAfu7JGn5xTkPXpxEsZykV0WKUq28o9WMfW6pDMU0jIsZllIbL9c7BiugLFsVwG7l/KivitXrs4vmcAvehxkQ8/4wJChfiH97sJttnpwZefSHgzqUY/6sVsHyqBOO9t/rfJtoVftobDrxAmWh+nlf4yY6hIUyHAReZntf4CffeP7/zGOlzMJBc8TPvX4sYu+6Kj9+FPqDiVrZCueLL1CBcvdEOLTZVwU4DjHmqFC+k/MXGexsQiN743VaVkbEwU2ZVPyyr1I/59O7dRl2BfAWFS28BaLi7j2dVGCBD6Y0szb7rdKJFu8Bwpxl5yky2ZMyqf91cu7wN3pq/SoPVWcoeaYRhcoqfwOt8xtgc1tBAWi2sBwKFepsCYpM/QoqLhkVtQgqEpJNrEoSkSf+Z9EogUFreOdkuUjJ5ezsbeDyLyEa4Z6eFrs18jKUzgEYyT4jSHNZBszoGkqYVQVTW2geWEK5QRzmVZscq52nbIXyLg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SG2PR06MB3367.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(8936002)(921005)(36756003)(6512007)(38100700002)(38350700002)(2906002)(6486002)(26005)(6666004)(508600001)(7416002)(52116002)(5660300002)(6506007)(110136005)(86362001)(83380400001)(316002)(66946007)(66556008)(66476007)(8676002)(4326008)(2616005)(107886003)(1076003)(186003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Hx5+i+pNA5VAqiA6INhAotZyTj/6roBPk5ohldhpwsuUyaXq5vli5M1whq/kKcRzqK5h9IQ6x8Z25esfpkNa5QnHxxdewpDO5atm55o9Xm4bzTGOiseDi1pBsdNe5QQ05lQ11i1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bfvOnPT7gx5PT8jvSZAtPUyjvyncSaxZztpkW6kLHH1rR0EJf+FcPQbJpSKHbi2FDvYWRtMnIkCpdQsBIAVS/bg9k4QLnIi9CWdh0EKW4ej5Tw/0aqo5CrKZ5lW54NJvO+YrrPXc3sLT3aVi16Nq8fWPjmueD5FJORFbhiAfiJLAalsvYOT6XjTporPSEcG2ChgREkKdEqJtEUgM2KbaG7/4QNbQwEJpy+pBNPVPPPY0Bj8Tc26nmR7nkWZ4FuHNtzRnKB5ImmnZMQCC6y8aOJXd2kbzITszoKuyKfu6QP56BjZdWIRm3h35rrdGB7aMB0IZnE+WoGcKfQUAg6tu8ugqgjok+WC1Onl5q9IEaB2C717SBKzImB+rRNiMQgobe27SXjtq9wjVgaSMcYFUfdYOdDDXV4vCFWDRBvtc+SihpHH5zugrA0V+EMVdQ6y/ixXMHSzFaGIzdsLQbVrxrVxNorKQpRmOztq4PUJRYOoTZtnhDa6u0Zjy6ktiG+++4inZSlE1TBn1gD01Ifsel0ybLdv6EG/UDHQ== X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: cf9f34b8-eca8-4f10-5b08-08da342225d2 X-MS-Exchange-CrossTenant-AuthSource: SG2PR06MB3367.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2022 14:17:29.5984 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DP76C/1bx2FCxqOA7Ol47xYZnQyQtml+XvwAVJ1kupV46B1h7z7Kq9EO9ivn0AlXBqoXdqlD3zAyua3sUFpfjg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK0PR06MB2819 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Use 'error_addrs', 'error_cookies' and 'error_link' tags to make error handling more efficient. Signed-off-by: Wan Jiabing --- kernel/trace/bpf_trace.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 2eaac094caf8..3a8b69ef9a0d 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2467,20 +2467,20 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr if (uaddrs) { if (copy_from_user(addrs, uaddrs, size)) { err = -EFAULT; - goto error; + goto error_addrs; } } else { struct user_syms us; err = copy_user_syms(&us, usyms, cnt); if (err) - goto error; + goto error_addrs; sort(us.syms, cnt, sizeof(*us.syms), symbols_cmp, NULL); err = ftrace_lookup_symbols(us.syms, cnt, addrs); free_user_syms(&us); if (err) - goto error; + goto error_addrs; } ucookies = u64_to_user_ptr(attr->link_create.kprobe_multi.cookies); @@ -2488,18 +2488,18 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr cookies = kvmalloc(size, GFP_KERNEL); if (!cookies) { err = -ENOMEM; - goto error; + goto error_addrs; } if (copy_from_user(cookies, ucookies, size)) { err = -EFAULT; - goto error; + goto error_cookies; } } link = kzalloc(sizeof(*link), GFP_KERNEL); if (!link) { err = -ENOMEM; - goto error; + goto error_cookies; } bpf_link_init(&link->link, BPF_LINK_TYPE_KPROBE_MULTI, @@ -2507,7 +2507,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr err = bpf_link_prime(&link->link, &link_primer); if (err) - goto error; + goto error_link; if (flags & BPF_F_KPROBE_MULTI_RETURN) link->fp.exit_handler = kprobe_multi_link_handler; @@ -2539,10 +2539,12 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr return bpf_link_settle(&link_primer); -error: +error_link: kfree(link); - kvfree(addrs); +error_cookies: kvfree(cookies); +error_addrs: + kvfree(addrs); return err; } #else /* !CONFIG_FPROBE */ From patchwork Thu May 12 14:17:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiabing Wan X-Patchwork-Id: 12847761 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2BC2C433F5 for ; Thu, 12 May 2022 14:17:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355174AbiELORo (ORCPT ); Thu, 12 May 2022 10:17:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355152AbiELORh (ORCPT ); Thu, 12 May 2022 10:17:37 -0400 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2102.outbound.protection.outlook.com [40.107.255.102]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37A8D6D962; Thu, 12 May 2022 07:17:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UUOw9eyKG6OxkxcVzzO8Vj1bK3Mvpq/5RXUEApWxOs6povefQ02mUvYgj520WLN9xEBHhZuJdM/NVUsLBPeGo7EyXEF4+ycny74d4srACQKqVSQ6LKLq99soY2nM5oWdpFqx3klWbl1ov15f11xzbyBX12QEmzwSB89D3ByQZqAN7bXvZbP4GQpeJ9tJ02CPbkg2qldTkkGE7hrquEDM8NLlbFkCJP6xr95M6qMllKCtBzE8AVVd8tdXXwQD1kleyZdIloQuDRKU8E04HonzwpJwMH7rrS7IbLZo6vfyCI9qV6aucWqTdBSwxsvPo9IOY1IKu8kCmGv2E3ulril4Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1brYZdW9vRKek9R7Lm2RCTYnER1gZyRWOb0URYrLWR0=; b=c7Rtr/fWV/KM9nJFfxo3WYPGRQuHA/NMkH6z01iv2XF8Ky2nnhzogoreGofOEZkwaMNUZFmqftByQT7e1CwItIa9/7wtsOEMf+IV8qtzMgm//K0gH101d9l5y1erri7YIcLv2g/Byqg+SUiHjZghVJbmlTIbqKefXn2qs3snWUwGBEH7/dizHxxwSZwvon6woLHdVVQA5+/WFubWV8LUSQ9TjUZVMwFPPECzFgO5fBdeIPaJsralYlTgCQgN/geZ1CAo4ZHf+NqJTwQ6SXBOLYGx6eAJOqElocqKdBJvBky0+BoRJcvrrL8PuzFMua398uhSqqS3TB8sQ0QR4NveKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo0.onmicrosoft.com; s=selector2-vivo0-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1brYZdW9vRKek9R7Lm2RCTYnER1gZyRWOb0URYrLWR0=; b=Amg5xwfhhm98Z5Mv5WiaMIUOYqHHkHpT6MWPW7ymwmK9e8uNMf9raQDKypvURBoOwz/OTiGYjYFT8AJ2djgIL6SXEbSR2duB4MdeFx90wd7fEc5sOQjG/bWifyDT37nq2of/DMJo/YHWW/ZzyyKiJ2wwrmT8pp09boTsbdWGTeU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SG2PR06MB3367.apcprd06.prod.outlook.com (2603:1096:4:78::19) by HK0PR06MB2819.apcprd06.prod.outlook.com (2603:1096:203:30::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.21; Thu, 12 May 2022 14:17:34 +0000 Received: from SG2PR06MB3367.apcprd06.prod.outlook.com ([fe80::4591:4f3e:f951:6c8c]) by SG2PR06MB3367.apcprd06.prod.outlook.com ([fe80::4591:4f3e:f951:6c8c%7]) with mapi id 15.20.5227.022; Thu, 12 May 2022 14:17:33 +0000 From: Wan Jiabing To: Steven Rostedt , Ingo Molnar , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Wan Jiabing Subject: [PATCH 2/3] bpf: simplify if-if to if in bpf_kprobe_multi_link_attach Date: Thu, 12 May 2022 22:17:09 +0800 Message-Id: <20220512141710.116135-3-wanjiabing@vivo.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220512141710.116135-1-wanjiabing@vivo.com> References: <20220512141710.116135-1-wanjiabing@vivo.com> X-ClientProxiedBy: HK2PR02CA0133.apcprd02.prod.outlook.com (2603:1096:202:16::17) To SG2PR06MB3367.apcprd06.prod.outlook.com (2603:1096:4:78::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 31679fe5-4473-4bef-8116-08da3422284c X-MS-TrafficTypeDiagnostic: HK0PR06MB2819:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NRJyFWTFb5IuS8343xkKZw0IaCZvGownE/uoHDwXoUixFTYW+kYR1i5y88R3M1sID/0uK5F2eVN0PzFbarQsUcWqY/buMFj1Nna59+/fgaJfzvRdkKpdd2FG/Kc+biqgQccQqxwJ+FyGk5WXbozOhyFZBbAU3OLdxVJ4K9gdrPkgvOyBUeTydL2te5s/Nzh7TjVQiiVi1RRK31jEoqRreyeHonxhxhIYn6n9niAtSdr0hxPxtdwIICUOltI5traWw8vRdghu//b1xnPDZsvgx98K1NLYM3bEDu17LfEA0fwNTXDlLhu5mbZ7WH0DRvHGImWaNV0WCBQ7Cy4GJ8IDexRUXtDqwZgLCuXNCullXFh8tT/+mqsRsoqOQlHqkL37wGchzSTZMqCbR6/SgjkpuOpZN+klO5bG9MtfzSqqKO9G7N8lBWy7ygvvnLGL1JvKvNXEL6SG0aasuow5rQRqNCJ0nzbive9qejTazv44nuZglI7fl9wikzupp8rri8eXzYfscTEG/36kJc4KkbjcdNd2ZeyzF8PdjMVp0gdiPuu/zI6yxxsa3M8rV0CFyua3Pm7lLfP9w1A2+OoGGnM/sUqYOQuL8OfbKuYuRWGcJZCcTKb3RvOVLhWXUoOFHUbF2pLLVQJmElMPw+8JjSVwt94VxxFjip6TiR/K323sABZbMpu27dMaqHyMZWVe1uRSISfkFh1Yxqwj15WDVTMg6d65T1FFq/OfmOnJsry3yCw= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SG2PR06MB3367.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(8936002)(921005)(36756003)(6512007)(38100700002)(38350700002)(2906002)(6486002)(26005)(6666004)(508600001)(7416002)(4744005)(52116002)(5660300002)(6506007)(110136005)(86362001)(83380400001)(316002)(66946007)(66556008)(66476007)(8676002)(4326008)(2616005)(107886003)(1076003)(186003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XUt2FrTbyrRodKozN+0KhN5kcCddQQN0f2Q+75uSnKS1D3Y+uj7D7a8XLrniUHhoyJwYGQQmML0wILQes/L+Zoc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2Y0v9iHK6lultOfN6oFdgq9whD4RzyHr+MPheiVFclNyvnQ23uWgtv6NgHzwhCO/BnYpFCVVt5PfCADGiJl/4QxIB4s5CJuvPULTsEbLfb/qrH1wdxOvRy/3wSY/DSY9ETlej37LYyhuCaVu3Q+nkdJaZxyS+6SqGxnQgnUe3Hi04Wx+js5y8aYqAcElNB/CL67y1cOe5Nx4AZuAyv+2yqllE/ZBCAFlCVNLLRMddH5bablaEzYWvrDKZI6dctHJa9f596JOCssu8RdBWl+yFNbUkUOXou8lpmXuIe4eeFxW4b1UZj0ZAB0OY7oHr3mNXx2Np2a5P4XKZ5QM23Wh5GQMH5mMgMGc+qOUPYMOVF4IptvhHm1HbrO+qIt+aeFnSvmVwITDXuQUEdTF7ZpVw5Br9LzvPfJSvC06UuE3VyoryJbZ5H1fUrBOT6G9tmgDDMEGkSkUQAdl0g+4PQWGnhfKewzgIOLHf0kc9/nujdoF/DRft5npKQB+HJxQhiYHeOLhuO6CeKHb2QizlwL/tD8VQLdnRPy1FrueX5HTy3p1HKgBFs9Uk5tSQlAdfqcOsA== X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 31679fe5-4473-4bef-8116-08da3422284c X-MS-Exchange-CrossTenant-AuthSource: SG2PR06MB3367.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2022 14:17:33.8324 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vRwJ31OEYcShQrPXj03dQeZa9Cjjtao9pyo7KR8yEAnvER1qHKvIeeOx2FDjkTmB2VSfOfd5MqY/hgCARfOgkQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK0PR06MB2819 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Simplify double 'if' statements to one 'if' statement. Signed-off-by: Wan Jiabing --- kernel/trace/bpf_trace.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 3a8b69ef9a0d..1b0db8f78dc8 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2464,11 +2464,9 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr if (!addrs) return -ENOMEM; - if (uaddrs) { - if (copy_from_user(addrs, uaddrs, size)) { - err = -EFAULT; - goto error_addrs; - } + if (uaddrs && copy_from_user(addrs, uaddrs, size)) { + err = -EFAULT; + goto error_addrs; } else { struct user_syms us; From patchwork Thu May 12 14:17:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiabing Wan X-Patchwork-Id: 12847762 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74692C433F5 for ; Thu, 12 May 2022 14:17:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355176AbiELORr (ORCPT ); Thu, 12 May 2022 10:17:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355162AbiELORn (ORCPT ); Thu, 12 May 2022 10:17:43 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2132.outbound.protection.outlook.com [40.107.117.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CE176EB32; Thu, 12 May 2022 07:17:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fQVzCPYIRWQNsjipQsCiGc80u7I9erP/D8Tjt+HwM10jyortP+Y9ODiS2V6rmysfMbIi2muHu15yW+5xENPUq11TLfZr+uWCXVBSayo+VeZlgXsgMcd09Nkx0I4HPyonrlIThglwP9etXHJpluJaJvmuTbCeWhMTSVlkDVUCBNnrNzK883f/Cw2zpymWrYkFKURm6i6VE1/cnDrRncynWRmeuk8xn6eMey5/xVUhpMOFkujfD6NnrXN5saFE0x/bZY7c20SJk39kKp5Yan+2an9lBNeNquuDYGvqcuueYONpHhZ80AgS1x0zCZBXTcRIe5Cht1TPGrHKYPMVQA6UEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NuBxTX+btyBuKgDD17JBm6YZ6h+fq6v63KPqrl+KnUo=; b=R3fX98xuWN0/Gj2KiEbv9VzNAEiq/xeqqaP2UhPUg1GzBm5t/y2KLDZC6AekN68XvnalON/DEgM0PS5YIej5g8/ZjZmka8FPv3DdGHuVo06AuNm4OEtEYmMKjM3KjXfUF/kLE+y5OG7k6//le6J6jgacTjIxHlXDOoRLUv9O7t3FLzoZ6bcX/THxrihyPeRPd6x8TVMlw1r8Cc3qc6eqlFruj19QJUtB6An+A/biy5k59aEVq29LlmskMzIn69QcrAo/OjUjZhRmN/wCuEmzpROwy+n+fpUFw5eEoEWDNtOdVn9+gWBg1Li/ROdR16rZYxuvqVCAAedMKAa/QUvO5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo0.onmicrosoft.com; s=selector2-vivo0-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NuBxTX+btyBuKgDD17JBm6YZ6h+fq6v63KPqrl+KnUo=; b=dbcXmHqAnjEe185uhEx//ZkVm2TTZ1Oth44D+zsCoXsL9Hab5rf8vrQqq4WnDOeLg1amdVPCYb7jXKe1+gQnI5LZJvtiRfTn2kCOJHhA/k5+FBgmex5kiy78gGUV+xvvSI+HEEa/xFYr1+JcVjKRb/PzXI9+8sMK2U/s8NyyhtM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SG2PR06MB3367.apcprd06.prod.outlook.com (2603:1096:4:78::19) by HK0PR06MB2819.apcprd06.prod.outlook.com (2603:1096:203:30::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.21; Thu, 12 May 2022 14:17:38 +0000 Received: from SG2PR06MB3367.apcprd06.prod.outlook.com ([fe80::4591:4f3e:f951:6c8c]) by SG2PR06MB3367.apcprd06.prod.outlook.com ([fe80::4591:4f3e:f951:6c8c%7]) with mapi id 15.20.5227.022; Thu, 12 May 2022 14:17:38 +0000 From: Wan Jiabing To: Steven Rostedt , Ingo Molnar , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Wan Jiabing Subject: [PATCH 3/3] bpf: use vmemdup_user instead of kvmalloc and copy_from_user Date: Thu, 12 May 2022 22:17:10 +0800 Message-Id: <20220512141710.116135-4-wanjiabing@vivo.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220512141710.116135-1-wanjiabing@vivo.com> References: <20220512141710.116135-1-wanjiabing@vivo.com> X-ClientProxiedBy: HK2PR02CA0133.apcprd02.prod.outlook.com (2603:1096:202:16::17) To SG2PR06MB3367.apcprd06.prod.outlook.com (2603:1096:4:78::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2d5689af-9fb6-4678-a71a-08da34222ac6 X-MS-TrafficTypeDiagnostic: HK0PR06MB2819:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: l9z2mGNknD/ulheEmDer58qOPqkKe7GS2uHcZaWeYXD7QmCjZFSL59wiLPaDX/4xNhfLzRzf9aU0ix8u/GavUkJqo2BpOwxVkQEze1lQV+Fos3NFJJMAZrFayBSjqHOFFTjjuYP+rh7gD0nHcrcVsMsDJm1vsFB7KwM4Dv13MxdeZdM/kgbWIVjQYLPKD8I9PqsqZXQkdCJBujMc8Nl0AcJWIit7Z+RD4k1zuTBz4vVW19LXuaENvri+AHUMIb6EWkZfcvlgywYxB8K7EY5fUtwnW4q8UTKY2ayak/IVVBUJu2Qz/DFSDjJbYFGepYIAGWpxz94qVZgglClt8xenDe6OGEbYOzcvGjmYQb1maMu0rczWgaLshTMekr8504wXjRZ7Tq0whbRJcdnBTz41iuEfG9cN8LjK0jZsYKEhQVDgQHAQmZB45ap+cvKioZmJapc5FBI27YvO7hdN/HW1Tuzbx+27nF4OXuGS1ikMHxYoaCAPSGjPJqxC4YkPEQqq3LPXvMkQxiQY4jyFnczg2SJvEtkMOQutcUuPoFSW87Bh1NVyqlCC0RmUtLqdE76sXltOm2QrmGrBXirwXv4S58v4k52PaMsaH1U3GWVjtuErIr3EzDGTDVD/7j2IxVjqpK1HfE+bUhBQGQkP7fflsJejSrjH7WVVd0cD79y6UicK59dL/3gpebFslUCnpveYtFcoQT4tkH2PyrZ4IO+F/Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SG2PR06MB3367.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(8936002)(921005)(36756003)(6512007)(38100700002)(38350700002)(2906002)(6486002)(26005)(6666004)(508600001)(7416002)(4744005)(52116002)(5660300002)(6506007)(110136005)(86362001)(83380400001)(316002)(66946007)(66556008)(66476007)(8676002)(4326008)(2616005)(107886003)(1076003)(186003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: laURUt3C5jaDqjV7egzj+8RKnd2xc6P4oXcuoohCxg10PmvLFb+nbf/LzyZrumD+vbn13QJjJKvm+EyjCb0BZxO+3g7YdVRJHl3LBjIRjt47hqHPSP5iPx7P/3Noy5/E+WyyVywQqxobO/nWgetI+1TCB/M1d82DPX3fo8WVL97yKDziNeSp13rjoWKkYcWpjdJUYpGWa08wmRN+kvaE4yrA+7wimV8gHR2UCPHNr1joc/CY+6kDkKVN0tIxFutontscuv4gKKEI9OmA3nVdoK1WsPpuubU+aAzWZx+sfwWlP48MczMBQHcJb/HSMIzM3h/S37mOSG1CQ0NvUe1ZZ1/VzeoDfA3vSXKK6eFWsNf87h02VkoNvbv3RTdw7/pDLzUQ6f1JQBiU/vr04QT6NWRdVEohMWooaHQb7Wr6UIpOXC7w2bbbNsN4WER9HgpdSxp2gFSEgNsJGrEwno3iBKyDuHp7DYK45ljJyhLCs+qEtsC8toJvQcd0t3RDPNKAKN/CVRGPMbmvPvyslRu4cuS8CYhLECpsjcDX4EoihRIQkq2+3ixggDJw2PcfIZIVy8fEp6LdxEvFhLIPuI7zgKIbGET7KgxHtTy7/LX4S7PO6Q9tJrSmtNkxsifHC9mVO51wmyXVnYxIB7YbihqK27p5fhFLVzZlWLIFA1HsSF7mbH9FFgK3joteg6MA6KIj/CQikTzRkuv6WgY0CwNAMQxyB2m+dlMGSWw1QYDsQmLZ3kDWNWFogpdSqzEsYsB5YWgl/OhQn3pG5e2kkd67Vk82cacpKAKkDLQL/iU7wrhWkGP23jFEVbY9F2AmTmcHnZW2ntOlROY/PXV+glZz5wdkKevkphSPFQ7Sp6h9DZaDnBvMRxXBDhU+COzC8GJBh1+fLxK/ob1+lr7ytFK5agxzubyK9L2LnwPJJPF1iC0r1IeY0xhUt6jLTPfouIl+138sd2qboaLMsAOF27sJd3Jtx4gjq+xJoGAj22QRjXqOT7dQGDw227izJg/GHsTLM5K9lhe1qH3RmU8rokybwpoMtBSeEIcWvTQJRYUC5/aGPO+C+AAlw45SWI36DrjM/OHAaZ9jhH8ltU9qktQzw3Tf71eNQRBoBD9JTjttgvtjkJjGTcByVi0OnANPL/8jkjSrg75rZcQLDPsfU31QEI+cWr4aUvIdq831t9UAn2i0Q+r5RgZwJRbSGtoWSJxH1ebgmAK/+NCJccHzJjrcttRrp+1PzAR8JpNUfsmW9d2Mp90jpEIwsR+5aQ2jW3yulDPj8COV5jbS5CenI0Ap1RUR8fn1pg9FLMF9L8MvavXvk60Tu7HtaNNWnnzSW0Bj8iHzG1sqAhlV+v0WThiwGBEdPgBJJAkWaj7vW+T4l5HsOWE9eoLRK8e7VfOH/uDaf0tupC+Xz6cGwzLHEqbnlY6W4enezJ/7y4cb12n0JxVK3s2xgnZCuAI6BaxW8skGzgnEhbrBSD8gNv4Zs7CR8OAAa3uY5mN8dszKzNFw2/OjzpniOXN0bRkrixeGjaPX8PwSB7kKzlI8Z/zW8rmxQ3Nt9AHSQ3yl2vdxnkx+z6ycU6BBlEQm/mYzG0C3UaaMg7I3yNjM+Wl/bwCPEypQ7fo45uH64yp5ynTAhflFJFhKAn5SAoO4UX2KLjTLCicytzpKYH3oLZp69Lva2ufKtmSJSBiOCIkLnx3klcx7yS60bj29CH5qevqbKNxqItOyavkVe54KPxrL7CLM9fMuag== X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d5689af-9fb6-4678-a71a-08da34222ac6 X-MS-Exchange-CrossTenant-AuthSource: SG2PR06MB3367.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2022 14:17:38.0509 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: oKYp8sPUlrPOkjUjPTFjmpDaJOtxwljiX9zpzC8vJh6Ahqb8v4m52S7UnPvGbywIycSnDOyAN/1ukTduZ72aqw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK0PR06MB2819 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Fix following coccicheck warning: ./kernel/trace/bpf_trace.c:2488:12-20: WARNING opportunity for vmemdup_user Use vmemdup_user instead of kvmalloc and copy_from_user. Signed-off-by: Wan Jiabing --- 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 1b0db8f78dc8..48fc97a6db50 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2483,15 +2483,11 @@ 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; + cookies = vmemdup_user(ucookies, size); + if (IS_ERR(cookies)) { + err = PTR_ERR(cookies); goto error_addrs; } - if (copy_from_user(cookies, ucookies, size)) { - err = -EFAULT; - goto error_cookies; - } } link = kzalloc(sizeof(*link), GFP_KERNEL);