From patchwork Wed May 11 11:39:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12846076 X-Patchwork-Delegate: kuba@kernel.org 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 077F4C433F5 for ; Wed, 11 May 2022 11:39:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231749AbiEKLjt (ORCPT ); Wed, 11 May 2022 07:39:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229975AbiEKLjs (ORCPT ); Wed, 11 May 2022 07:39:48 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2100.outbound.protection.outlook.com [40.107.244.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC6A92415D9 for ; Wed, 11 May 2022 04:39:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fFvaVusNnoqqc9xzF0ZnCPI3ksNCVnVOWVhE3HTOJx7kANdeG+t/iK2mnwdJSummnrmWUNPNKJUhTRR49YZerX2K/vH6ZuF1cn6WnaALHkKe2u1In2IZAuiST+y9ZCXTpCsB/9Bnv/M5Poe9WyEaJjwBaC/Ovr6VPwH1TqD2rFMAsRKFmyuni4bXKLYpYjcgxlHqsrdjRSRzuL3OYWOLCkDMiLl41sqpVpCz4/1JkSW9dkv8PjXfQZJRG9Gp79jSZfx6hrOj8KJtUbib8RpprKxwFJWCaXMrLoGVYfEpl6ezlDc1ffc4s0lfrxqNPpHUkF80g/oU1AICQvK4I6iMZw== 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=UD8JUBXtuOzT442mdVYvqQBcI0P85Hw7Wue1ZWqEB/E=; b=NMwjcljBz51Jceb0cG40U8YvqoAYG9nZFty+xCWLJ55Ka2dl0MWkkIitir/JyH1mqc/GLjofn9EwQQEWV4jrK6a9N+9kIIrc0Z6NfRvU603PMyDS3xjjYnQgjwwvRwsqk47y5gkaR0/PK7klEgNqBgCbNSDOjGIzlOlNWVIKVH6JBgKpbROKX3ijRM/GnCmdblu/N3s83IGX7HlOVlZDq1BjiYTi+ZojBgCQ/AxBZV7FiuVU4LC6OJ6SKC4L3M1ceCO1aeAyJZUoR/1AsBF4XYPgVytvmbYyLGtLVdkTumgRt2e+GuEEou0P2yIz6oT47tLcVMgTrjbwb/QElmrqdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UD8JUBXtuOzT442mdVYvqQBcI0P85Hw7Wue1ZWqEB/E=; b=B0QLXM+YHMpE91/y6am25onCrlRWEr+m0DuRPuUG+J+YYoqP1HyuoN1QBc/L2q9SAokc2E3VIghvwu+xzp/9f8RMdDCMlcXH9lVNprOs8j8jAX3k6n9o2KMEHpEHu1+/+lpFvpg0XvxpRtv1oY0py5uOUAmH/e7JIofUba5oTAA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by DM6PR13MB2972.namprd13.prod.outlook.com (2603:10b6:5:19a::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.12; Wed, 11 May 2022 11:39:46 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::8808:1c60:e9cb:1f94]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::8808:1c60:e9cb:1f94%3]) with mapi id 15.20.5250.012; Wed, 11 May 2022 11:39:46 +0000 From: Simon Horman To: David Miller , Jakub Kicinski Cc: netdev@vger.kernel.org, oss-drivers@corigine.com, Bin Chen Subject: [PATCH v2 net-next 1/2] rtnetlink: verify rate parameters for calls to ndo_set_vf_rate Date: Wed, 11 May 2022 13:39:31 +0200 Message-Id: <20220511113932.92114-2-simon.horman@corigine.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220511113932.92114-1-simon.horman@corigine.com> References: <20220511113932.92114-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR10CA0054.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::34) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f1f89618-c9e6-4ff8-ad77-08da3342f2d2 X-MS-TrafficTypeDiagnostic: DM6PR13MB2972: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: 4TJvui7Q8x8TwJ/bNs/OU44Nasse/WE45pYd2qk6oFNkIOvCOodL6U9INi5lygXr6+PAHVqhYq4viLk0cEYfzsdnqzJYwfByoC8GkaV5GgMBoY5BFKNdX5ZFxluiteuOrOC3k2qeEg740+zqM2vsoE2fBsD7YUP9jP0Iu8lHbUXYSLuLlt8LKaZ688Zweoe6dqi2m4ysqKbFyGYNh+jNwANCoUNJDaFuDYJ8PniXdCGgPLZMqv3F/0SGDpHl9DwwMfQ7+hDU2x11ngotORuNp2oOUisPbseEf6f8c5b7ELdDMKiTVuK4rKya4troVqVvngD7xrwhiN06pA/YnekkFAlGw8zgZck2QzTg9O9FjHsd4W1G1aMlBaCCJ0V/QGbs0bjxcSNMygskayIK+dC2iRBNueHB5UeozppzDw+v7noTjliykY+grrlPS+8KjObvsB+E6pBOFE4LQCL8fYVOsNoCA4KE4E3KeTTyqvPdvQrFd5tu5SVnhpk+OUnKW+0JOBhxMFKQ3/Md7eI3WxHmq1yEabIyh/sph++xUdX2MoX6t4/qd4N/tUrki+ombvnlyXeK/3xYqYgePnWNOxo8WuGu4k+PvpbYXRYc8RVLNCTPxC613ZKHvtQBT1+NN+0txMGeuuZXVXWSjAB/pLQ2tA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR13MB4842.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(376002)(346002)(366004)(136003)(396003)(39840400004)(15650500001)(38100700002)(1076003)(508600001)(107886003)(6486002)(83380400001)(110136005)(316002)(186003)(8676002)(52116002)(6666004)(6506007)(36756003)(2906002)(6512007)(66556008)(66476007)(44832011)(66946007)(2616005)(5660300002)(86362001)(8936002)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: DMyJRQgy/D/ST0IhKsiKZHVHP3LhW72w7PD3L/XrVXW89slwCNE4c+FYWr7gujgR3Uzv8ax4Crt1Cq3vQb5QqAnFkiPYecriUhs1yqnCCjwBOaCSYKAeC0arVHff9gfclTwrNC59k2gSYXXas0k6jP8hSLoztfLR2rjWDzkW5o1mfhz4aZmf0HQN1bSTaE7qPEt6imJv2bMWfhLPp1axiDD0aYvIVeM9lI4P38m2eP6WHv5V9xiquOwN27NrqgqeNUTxX4VZVOR3d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WkGJYBx9gVAm165MWM73U3SLrychkyB0LogLCGUaQwDBybvwUYmxo40fBmTIKbKw/XistPk4Eg54FQngSwa5XLvEL29RRPZpUdgL9hjIPXbOczYLre+QFiF1A6kBuKaAQ6r2vrGAAumRl8qa4CHXsGpVds1sMIB7hybNEuVUmjkMgK35880qI9QsWRbL34VW6EPCgYcufWxp1BpCStMT+zXOW7R8oF05BBQfmcIIiDTz3BmOcDInCLYjsGM1U0Vv1afdaAe5ZnXj7MnqHhVMeInXSyKjvjDnW+Ly8QhUvtyeX52RUy8cdjPv4AWOhIuy5u0j1rX8tKOmPJoMbYajIM5QvFtiJytF37E8fzTOoqBhJLs3EP7+JgoR2LRULuI8vRwesTMM7IjMr/UbRqIF+0rSwgvpdHEYtSGTLRJJyianHy5gPuTW4xJKOl6fix X-MS-Exchange-AntiSpam-MessageData-1: ZiyKlzIZYo4gYwQDGq54GFsecyRRq+0na74= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: f1f89618-c9e6-4ff8-ad77-08da3342f2d2 X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2022 11:39:46.3771 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Bj1NwwKCZWyOV5AbKOmFECRUh/Z5a8B8VSEoXCPyDZzEi5s7BLkoq84zeW2cvG2YwOw+LfqZtZzYP4am1//ioq8TIoKW0ksB1oN4KEuti6E= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR13MB2972 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Bin Chen When calling ndo_set_vf_rate() the max_tx_rate parameter may be zero, in which case the setting is cleared, or it must be greater or equal to min_tx_rate. Enforce this requirement on all calls to ndo_set_vf_rate via a wrapper which also only calls ndo_set_vf_rate() if defined by the driver. Based on work by Jakub Kicinski Signed-off-by: Bin Chen Signed-off-by: Baowen Zheng Signed-off-by: Simon Horman --- net/core/rtnetlink.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 6aff02df9ba5..bdc891326102 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -2306,6 +2306,19 @@ static int rtnl_ensure_unique_netns(struct nlattr *tb[], return -EINVAL; } +static int rtnl_set_vf_rate(struct net_device *dev, int vf, int min_tx_rate, + int max_tx_rate) +{ + const struct net_device_ops *ops = dev->netdev_ops; + + if (!ops->ndo_set_vf_rate) + return -EOPNOTSUPP; + if (max_tx_rate && max_tx_rate < min_tx_rate) + return -EINVAL; + + return ops->ndo_set_vf_rate(dev, vf, min_tx_rate, max_tx_rate); +} + static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[], struct netlink_ext_ack *extack) { @@ -2443,11 +2456,8 @@ static int do_setvfinfo(struct net_device *dev, struct nlattr **tb) if (err < 0) return err; - err = -EOPNOTSUPP; - if (ops->ndo_set_vf_rate) - err = ops->ndo_set_vf_rate(dev, ivt->vf, - ivf.min_tx_rate, - ivt->rate); + err = rtnl_set_vf_rate(dev, ivt->vf, + ivf.min_tx_rate, ivt->rate); if (err < 0) return err; } @@ -2457,11 +2467,9 @@ static int do_setvfinfo(struct net_device *dev, struct nlattr **tb) if (ivt->vf >= INT_MAX) return -EINVAL; - err = -EOPNOTSUPP; - if (ops->ndo_set_vf_rate) - err = ops->ndo_set_vf_rate(dev, ivt->vf, - ivt->min_tx_rate, - ivt->max_tx_rate); + + err = rtnl_set_vf_rate(dev, ivt->vf, + ivt->min_tx_rate, ivt->max_tx_rate); if (err < 0) return err; }