From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-eopbgr140055.outbound.protection.outlook.com [40.107.14.55]) by dpdk.org (Postfix) with ESMTP id 0F7AE239 for ; Sat, 10 Nov 2018 10:59:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fGMIzvJ9Xoq1vWXlJQRMjI+wDqqCHP6ndx35BWNoCvg=; b=g+gSLw+cssWv9zbGxCh9j2HHpNEGKYbCqVzuKWBbbrEdqv3GqL4vmQu6FfQOcvvZnI2WXiGWsJczKKeVK890nWgHK/DsBEPmfd+X0uZxNHVJsizqt+/MzOiTLkx8XBZIMjEA6SmktmNwus3oWrktTurKz6zJJNOApU9sxzGEJSE= Received: from AM4PR05MB3265.eurprd05.prod.outlook.com (10.171.186.150) by AM4PR05MB3250.eurprd05.prod.outlook.com (10.171.186.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.21; Sat, 10 Nov 2018 09:59:26 +0000 Received: from AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::544b:a68d:e6a5:ba6e]) by AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::544b:a68d:e6a5:ba6e%2]) with mapi id 15.20.1294.039; Sat, 10 Nov 2018 09:59:26 +0000 From: Slava Ovsiienko To: Shahaf Shuler , Yongseok Koh CC: "dev@dpdk.org" , Slava Ovsiienko Thread-Topic: [PATCH 2/3] net/mlx5: add Netlink message size check in rule cleanup Thread-Index: AQHUeNwQOrvXfX571USCIW4MNFhU8g== Date: Sat, 10 Nov 2018 09:59:26 +0000 Message-ID: <1541843951-31708-3-git-send-email-viacheslavo@mellanox.com> References: <1541843951-31708-1-git-send-email-viacheslavo@mellanox.com> In-Reply-To: <1541843951-31708-1-git-send-email-viacheslavo@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: CWLP265CA0342.GBRP265.PROD.OUTLOOK.COM (2603:10a6:401:5a::18) To AM4PR05MB3265.eurprd05.prod.outlook.com (2603:10a6:205:4::22) authentication-results: spf=none (sender IP is ) smtp.mailfrom=viacheslavo@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [37.142.13.130] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM4PR05MB3250; 6:Dk0Na9jPcGqjpnkppg5WPok2ZS44HZ7Kd3hGAt85R5qciGyNRpAQSE6dcxan/70E0HkztlDMc61m+MhwlcBsZEgdwOrX7zwCjHpA351Ao7V3KDv5NFrLWHLH8Wwumoa09EG8u1E6fJ+Pk9Q+yzOJf2PoIOJjtHTE0tP9pee6b7Bd4ClJ/GDd2cZTWXAZCNmaK/ttUtckdxNvzd5okSVeoL5Dzf1WA7lFQgveJXVlE40bTUt/6kId/KmwJN6YGtLbl/42Gkjvf2yqFcVM7UXP94GFKAYS9onGspQfkgdUXBhah6YQ35g+awjT2xJvBjRfEEeSclarM9TukK6elhN4zkSH/2IQq/LUGIX3AePZ7elI3ST7jK5uuWZsF0m+rLT+iRdByOG0BlJkA0JiMgUcH9ddbdoNrSpVsh9jzKKeNI0GG1Kl2xCray3jrUlZCscJs+nbELkm0dD4L/CJxTz9Gg==; 5:PTvIYhJ4VNaGNDjW3ADD0lnoA0Rk5RSEpuA1uuKF08993Ee2cVjTjKcto7JmYcQPZOwHi89nrEGVAuLO+Lt3YJD5HlxClQN3B8tKgU07YBlkbDru1FCJvGQPC9iaPhhTCThGGnXxwQylX5QitGtfaikABlNUNB0pc/V3DpeMRSA=; 7:zT6LOts3UNcXlIEsQnZZC2gwDgZqrLNHt40eIz0dlEpjKLYuwGGMWKFWWGY7Hdld8uh+Dh8HgPvOIJdZfkufN5Mb2bQjD8oSIioq4ZZJbJ2uo9jB/GqAxyOlHvLJXL3xs31neAXlLqBCIJadIlEmAw== x-ms-office365-filtering-correlation-id: b1c2291c-e8f2-4f36-1609-08d646f33292 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390040)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:AM4PR05MB3250; x-ms-traffictypediagnostic: AM4PR05MB3250: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231382)(944501410)(52105095)(3002001)(10201501046)(93006095)(93001095)(6055026)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:AM4PR05MB3250; BCL:0; PCL:0; RULEID:; SRVR:AM4PR05MB3250; x-forefront-prvs: 0852EB6797 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(376002)(39860400002)(346002)(136003)(366004)(199004)(189003)(2616005)(11346002)(6436002)(476003)(486006)(4326008)(7736002)(2906002)(3846002)(76176011)(186003)(54906003)(105586002)(6486002)(6116002)(446003)(305945005)(25786009)(110136005)(66066001)(386003)(6506007)(14454004)(102836004)(36756003)(52116002)(81156014)(15650500001)(97736004)(81166006)(6512007)(106356001)(8676002)(2900100001)(53936002)(107886003)(316002)(478600001)(71200400001)(99286004)(8936002)(68736007)(14444005)(6636002)(256004)(5660300001)(71190400001)(86362001)(85306007)(26005)(5024004); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR05MB3250; H:AM4PR05MB3265.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: E2oKbXTPbBnIan0TKGONydoVAG7Ska3ch3hqTEzekNLcSnHsMZg6v6Ug8b3MwuxZ2jfRBqvx5PTtkAG/2jErtsMpBp7MhWctqterHsm6FYxCzXDfpk4eZRJsZXBb7HJvf8Wf/aoFmsUWzcRXUVFsiZdlaQ0riX4oPWLDSjpw5L2+xwk2a8U8lR8G5+HzNZKcXT9ge9Cn6k7N0jByio31OrT/iJvNLgUiqgZ0DbQPtIh1Brr6z+QVL+6G0Sae3IyZ0yIZ0jDH9WA16TgYka5+6f7HtzqDpvwHgAqsI0vKoU/OJ8sIC6HXXsbQjZtQWvDP2FNuwIdxXdo3cOlytZ8+4mYO79p3xp7rLS/GTVQ9fNU= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: b1c2291c-e8f2-4f36-1609-08d646f33292 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Nov 2018 09:59:26.1417 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR05MB3250 Subject: [dpdk-dev] [PATCH 2/3] net/mlx5: add Netlink message size check in rule cleanup X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Nov 2018 09:59:27 -0000 This patch is preparation for the following fix, we are going to send Netlink message from buffer in one-by-one fashion. It is highly desirable to check multimessage buffer consistency for debug purposes. Signed-off-by: Viacheslav Ovsiienko --- drivers/net/mlx5/mlx5_flow_tcf.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_= tcf.c index ba0674a..bba8aed 100644 --- a/drivers/net/mlx5/mlx5_flow_tcf.c +++ b/drivers/net/mlx5/mlx5_flow_tcf.c @@ -3935,6 +3935,7 @@ struct tcf_nlcb_context { struct nlattr *na_local =3D NULL; struct nlattr *na_peer =3D NULL; unsigned char family; + uint32_t size; =20 if (nlh->nlmsg_type !=3D RTM_NEWADDR) { rte_errno =3D EINVAL; @@ -3962,11 +3963,11 @@ struct tcf_nlcb_context { if (!na_local || !na_peer) return 1; /* Local rule found with scope link, permanent and assigned peer. */ - cmd =3D flow_tcf_alloc_nlcmd(ctx, MNL_ALIGN(sizeof(struct nlmsghdr)) + - MNL_ALIGN(sizeof(struct ifaddrmsg)) + - (family =3D=3D AF_INET6 - ? 2 * SZ_NLATTR_DATA_OF(IPV6_ADDR_LEN) - : 2 * SZ_NLATTR_TYPE_OF(uint32_t))); + size =3D MNL_ALIGN(sizeof(struct nlmsghdr)) + + MNL_ALIGN(sizeof(struct ifaddrmsg)) + + (family =3D=3D AF_INET6 ? 2 * SZ_NLATTR_DATA_OF(IPV6_ADDR_LEN) + : 2 * SZ_NLATTR_TYPE_OF(uint32_t)); + cmd =3D flow_tcf_alloc_nlcmd(ctx, size); if (!cmd) { rte_errno =3D ENOMEM; return -rte_errno; @@ -3991,6 +3992,7 @@ struct tcf_nlcb_context { mnl_attr_put(cmd, IFA_ADDRESS, IPV6_ADDR_LEN, mnl_attr_get_payload(na_peer)); } + assert(size =3D=3D cmd->nlmsg_len); return 1; } =20 @@ -4059,6 +4061,7 @@ struct tcf_nlcb_context { struct nlattr *na_ip =3D NULL; struct nlattr *na_mac =3D NULL; unsigned char family; + uint32_t size; =20 if (nlh->nlmsg_type !=3D RTM_NEWNEIGH) { rte_errno =3D EINVAL; @@ -4085,12 +4088,12 @@ struct tcf_nlcb_context { if (!na_mac || !na_ip) return 1; /* Neigh rule with permenent attribute found. */ - cmd =3D flow_tcf_alloc_nlcmd(ctx, MNL_ALIGN(sizeof(struct nlmsghdr)) + - MNL_ALIGN(sizeof(struct ndmsg)) + - SZ_NLATTR_DATA_OF(ETHER_ADDR_LEN) + - (family =3D=3D AF_INET6 - ? SZ_NLATTR_DATA_OF(IPV6_ADDR_LEN) - : SZ_NLATTR_TYPE_OF(uint32_t))); + size =3D MNL_ALIGN(sizeof(struct nlmsghdr)) + + MNL_ALIGN(sizeof(struct ndmsg)) + + SZ_NLATTR_DATA_OF(ETHER_ADDR_LEN) + + (family =3D=3D AF_INET6 ? SZ_NLATTR_DATA_OF(IPV6_ADDR_LEN) + : SZ_NLATTR_TYPE_OF(uint32_t)); + cmd =3D flow_tcf_alloc_nlcmd(ctx, size); if (!cmd) { rte_errno =3D ENOMEM; return -rte_errno; @@ -4113,6 +4116,7 @@ struct tcf_nlcb_context { } mnl_attr_put(cmd, NDA_LLADDR, ETHER_ADDR_LEN, mnl_attr_get_payload(na_mac)); + assert(size =3D=3D cmd->nlmsg_len); return 1; } =20 @@ -4179,6 +4183,7 @@ struct tcf_nlcb_context { struct nlattr *na_vxlan =3D NULL; bool found =3D false; unsigned int vxindex; + uint32_t size; =20 if (nlh->nlmsg_type !=3D RTM_NEWLINK) { rte_errno =3D EINVAL; @@ -4224,8 +4229,9 @@ struct tcf_nlcb_context { return 1; /* Attached VXLAN device found, store the command to delete. */ vxindex =3D ifm->ifi_index; - cmd =3D flow_tcf_alloc_nlcmd(ctx, MNL_ALIGN(sizeof(struct nlmsghdr)) + - MNL_ALIGN(sizeof(struct ifinfomsg))); + size =3D MNL_ALIGN(sizeof(struct nlmsghdr)) + + MNL_ALIGN(sizeof(struct ifinfomsg)); + cmd =3D flow_tcf_alloc_nlcmd(ctx, size); if (!cmd) { rte_errno =3D ENOMEM; return -rte_errno; @@ -4236,6 +4242,7 @@ struct tcf_nlcb_context { ifm =3D mnl_nlmsg_put_extra_header(cmd, sizeof(*ifm)); ifm->ifi_family =3D AF_UNSPEC; ifm->ifi_index =3D vxindex; + assert(size =3D=3D cmd->nlmsg_len); return 1; } =20 --=20 1.8.3.1