From patchwork Mon Oct 18 11:30:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?546L5pOO?= X-Patchwork-Id: 12566047 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EEC11C433FE for ; Mon, 18 Oct 2021 11:31:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D380F60FC2 for ; Mon, 18 Oct 2021 11:31:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229781AbhJRLdO (ORCPT ); Mon, 18 Oct 2021 07:33:14 -0400 Received: from mail-eopbgr1300127.outbound.protection.outlook.com ([40.107.130.127]:9876 "EHLO APC01-HK2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229491AbhJRLdO (ORCPT ); Mon, 18 Oct 2021 07:33:14 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VUWPYV3BR1m0LHnMPIAlryWU3Ol8ulFCl00P0u3RpbcSyUgVlD0YIsIuKwY/xGVc7oVZlRUpOULc8hyEFquhmQr7Bian7h7BP9s7EsCgbY3guZZsZ9/TE5gV0MPMuKMBMp8ik5fV9dIGNV9gKwahP8csJs4NERaJnxR/MXcl3oBl2/wIeBK2MtWrD89eDVldQIW2t2qXQ5WTgMAUwLO59dkRoz8QaHlI3O9zahV7PcggEQUVLPM6gc8vqa7V/T8piSPf7tqW5UvVXyMkKQddLONNUqmwEqpELY/t4xl8TNT2aP6YR4SAEq2FeuOJKUEu35Vp1JgpTW7SY2BtpGzLYA== 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=dlhWNaFd6qORY7uFhL5+jFdI7EssNdoefkfCIBPICc4=; b=Mpl6F80ktrP83Ep3W7x9XoHvjqh6aAJ/8ZT7L4Myz8CPTESpCerY5g8Kq0DZlGMQwIlBHJAGU83FAYvGPUHDuzEXrpW8orTZFO5MPBToE8ZOl79sRkF9h9vn3teibv1KOpd0XBXwnsJNJk9QONjT62dX+9XCUn4aSbIfo2Wo3YcubJ87uLktr0Jj+xeBeOIZJvs08T+Fi0XXfZQlvvTmghbtOC96l/w3Wram5y+QAQovsKl1v9CGcBsjhjlmlzN1jCJK1Dyw9aCBEsgNFYEGEHzOsl8+e9E7jKNyzppD7q6ljppGWVR3ri9oV4zjrBfM4MlukhtMy/6thsW5pNN9Lg== 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=dlhWNaFd6qORY7uFhL5+jFdI7EssNdoefkfCIBPICc4=; b=pDYYgI0BBdxsN+83yW8GsNbovuyA4oBXXBtLvqoWqkEUw/BQ7wjYXes8AWjclyyVAqdFyBMRWN/mdnpl8LeeGqVRTCa3TVKP5jq8cdhSldXV/xikhhI5EdVYjNx96y5ZNhkE14MXSkYp1NrU6DSeh0XGBnyK9+2M/RR9D1JPkBE= Authentication-Results: davemloft.net; dkim=none (message not signed) header.d=none;davemloft.net; dmarc=none action=none header.from=vivo.com; Received: from SL2PR06MB3082.apcprd06.prod.outlook.com (2603:1096:100:37::17) by SL2PR06MB2986.apcprd06.prod.outlook.com (2603:1096:100:2e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Mon, 18 Oct 2021 11:30:59 +0000 Received: from SL2PR06MB3082.apcprd06.prod.outlook.com ([fe80::4c9b:b71f:fb67:6414]) by SL2PR06MB3082.apcprd06.prod.outlook.com ([fe80::4c9b:b71f:fb67:6414%6]) with mapi id 15.20.4608.018; Mon, 18 Oct 2021 11:30:59 +0000 From: Qing Wang To: "David S. Miller" , Jakub Kicinski , 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: Qing Wang Subject: [PATCH V2] net: bpf: switch over to memdup_user() Date: Mon, 18 Oct 2021 04:30:48 -0700 Message-Id: <1634556651-38702-1-git-send-email-wangqing@vivo.com> X-Mailer: git-send-email 2.7.4 X-ClientProxiedBy: HK2PR0401CA0011.apcprd04.prod.outlook.com (2603:1096:202:2::21) To SL2PR06MB3082.apcprd06.prod.outlook.com (2603:1096:100:37::17) MIME-Version: 1.0 Received: from ubuntu.localdomain (103.220.76.181) by HK2PR0401CA0011.apcprd04.prod.outlook.com (2603:1096:202:2::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.4608.16 via Frontend Transport; Mon, 18 Oct 2021 11:30:57 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 235f7320-2875-4233-7138-08d9922ac1d8 X-MS-TrafficTypeDiagnostic: SL2PR06MB2986: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3513; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2umuLxo0HDiI1jP65GVdxLMg6QX4sNBT7I+/87vndh5JJ0xjUa9s1AeGpvRKuN8J69S7A2oykOdP7PCvZTkjoQ3vR3k/Uu1bZNgfuOiF4EDhvmahyL7qexURRtksVBCAZa086Kdo+JQI7TQ+1mmb1oF7lXQBva/4FVzrr3GH9BF7sLTMUFQYdXrLXfYLFcCMXABpn9673juCKIJSUPOoadN5tRHk/QNVVNj1uSttBmx0trppQttZGlhtHIAcw6bywVW1zHwot8EjW0DM1M1Maa3uVPpDLt9ny7g2iV2ve7E8ODJrJbH9teECtOnOfyntkeNSwEUGRHkTiF0MevmLt5Ju1U5b4Px60EuciyMYK9oF+ej/af/+qo5q1/PFcMX2UZZbQoDRoL/8B6C1T79pICCZ7+QKzkNaFb/w/C2rx/t/OzmITzJVwcWEWiBSErIhOfhoewRDd6LzPkzX9at5ahvw35b86lyEe5ZUE3a4/vW9smDA2UUhyIOUouR5Phrv9CLHwLh5nOoOYJf3Fi92gHYBSdwybVPks/p1+9bHzIBw1nF/brNsGhsjN8rG+8WiREaXIPnA7vjkeKdy83cGT0F0KXAYbQ0Jw9xjyMCVP4LG6twL/y+Xcntivs/Ye/aXSmlKCLy51v7SOPYi+dqkRgJ6tEV7neR/wVct7sw/qJLb2SrefAomV2YLyO4GRF/pGe0yCdLA+MjLi+JaVYXR8geXgf4UsE34qbzrgGcglTY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SL2PR06MB3082.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(6666004)(2616005)(956004)(107886003)(5660300002)(8676002)(8936002)(83380400001)(26005)(7416002)(86362001)(110136005)(66476007)(921005)(36756003)(4326008)(186003)(66556008)(66946007)(6512007)(6486002)(316002)(38350700002)(508600001)(2906002)(6506007)(52116002)(38100700002);DIR:OUT;SFP:1102; X-MS-Exchange-A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UUjeOAFl1IXanpmEyxOO/tN72ZvfUUAIyxF6/X8w+hyWwMuMQwzq0UegmLwEtZRQ5k3mctcMWO1lTxh3jzNEW8kH8QVSpPZxy82adG5gCYkuFgQTjpZjaysOEllAWLL8yylOwywVRsMj8T+euUnqgCZQzHf//XheXokzXZ7E2tWj3KbIbwVqwOa/sWqhEgIfC4SB34ndzRVJbw8fyLLwQUG2cOCqKUhh4tvvfxaRaHiY3I14ibF1K7DjFabhhafDLVZZIPgmGiXh+cARqceUh/cy/sdypr98dCasMZpCt X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 235f7320-2875-4233-7138-08d9922ac1d8 X-MS-Exchange-CrossTenant-AuthSource: SL2PR06MB3082.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2021 11:30:59.0223 (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: wpBYFFVt3oTpFLx7uwjVKm79WlMQgqU1HOU2qPkNQ20DccgLjwchlFSTAGPwu7Bbgoetz2InuofHRQ3/8hSqWg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SL2PR06MB2986 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net This patch fixes the following Coccinelle warning: net/bpf/test_run.c:361:8-15: WARNING opportunity for memdup_user net/bpf/test_run.c:1055:8-15: WARNING opportunity for memdup_user Use memdup_user rather than duplicating its implementation This is a little bit restricted to reduce false positives Signed-off-by: Qing Wang Acked-by: John Fastabend --- net/bpf/test_run.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c index 5296087..fbda8f5 --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -358,13 +358,9 @@ int bpf_prog_test_run_raw_tp(struct bpf_prog *prog, return -EINVAL; if (ctx_size_in) { - info.ctx = kzalloc(ctx_size_in, GFP_USER); - if (!info.ctx) - return -ENOMEM; - if (copy_from_user(info.ctx, ctx_in, ctx_size_in)) { - err = -EFAULT; - goto out; - } + info.ctx = memdup_user(ctx_in, ctx_size_in); + if (IS_ERR(info.ctx)) + return PTR_ERR(info.ctx); } else { info.ctx = NULL; } @@ -392,7 +388,6 @@ int bpf_prog_test_run_raw_tp(struct bpf_prog *prog, copy_to_user(&uattr->test.retval, &info.retval, sizeof(u32))) err = -EFAULT; -out: kfree(info.ctx); return err; } @@ -1052,13 +1047,9 @@ int bpf_prog_test_run_syscall(struct bpf_prog *prog, return -EINVAL; if (ctx_size_in) { - ctx = kzalloc(ctx_size_in, GFP_USER); - if (!ctx) - return -ENOMEM; - if (copy_from_user(ctx, ctx_in, ctx_size_in)) { - err = -EFAULT; - goto out; - } + ctx = memdup_user(ctx_in, ctx_size_in); + if (IS_ERR(ctx)) + return PTR_ERR(ctx); } rcu_read_lock_trace();