Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH net-next 0/2] devlink: Use nla_policy to validate range
@ 2020-09-21 16:41 Parav Pandit
2020-09-21 16:41 ` [PATCH net-next 1/2] devlink: Enhance policy to validate eswitch mode value Parav Pandit
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Parav Pandit @ 2020-09-21 16:41 UTC (permalink / raw)
To: davem, kuba, netdev; +Cc: Parav Pandit
This two small patches uses nla_policy to validate user specified
fields are in valid range or not.
Patch summary:
Patch-1 checks the range of eswitch mode field
Patch-2 checks for the port type field. It eliminates a check in
code by using nla policy infrastructure.
Parav Pandit (2):
devlink: Enhance policy to validate eswitch mode value
devlink: Enhance policy to validate port type input value
net/core/devlink.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
--
2.26.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next 1/2] devlink: Enhance policy to validate eswitch mode value
2020-09-21 16:41 [PATCH net-next 0/2] devlink: Use nla_policy to validate range Parav Pandit
@ 2020-09-21 16:41 ` Parav Pandit
2020-09-21 16:41 ` [PATCH net-next 2/2] devlink: Enhance policy to validate port type input value Parav Pandit
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Parav Pandit @ 2020-09-21 16:41 UTC (permalink / raw)
To: davem, kuba, netdev; +Cc: Parav Pandit, Jiri Pirko
Use range checking facility of nla_policy to validate eswitch mode input
attribute value is valid or not.
Signed-off-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
net/core/devlink.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 25dd9309e86f..4ecc68a9c7df 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -7202,7 +7202,8 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = {
[DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE] = { .type = NLA_U8 },
[DEVLINK_ATTR_SB_THRESHOLD] = { .type = NLA_U32 },
[DEVLINK_ATTR_SB_TC_INDEX] = { .type = NLA_U16 },
- [DEVLINK_ATTR_ESWITCH_MODE] = { .type = NLA_U16 },
+ [DEVLINK_ATTR_ESWITCH_MODE] = NLA_POLICY_RANGE(NLA_U16, DEVLINK_ESWITCH_MODE_LEGACY,
+ DEVLINK_ESWITCH_MODE_SWITCHDEV),
[DEVLINK_ATTR_ESWITCH_INLINE_MODE] = { .type = NLA_U8 },
[DEVLINK_ATTR_ESWITCH_ENCAP_MODE] = { .type = NLA_U8 },
[DEVLINK_ATTR_DPIPE_TABLE_NAME] = { .type = NLA_NUL_STRING },
--
2.26.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next 2/2] devlink: Enhance policy to validate port type input value
2020-09-21 16:41 [PATCH net-next 0/2] devlink: Use nla_policy to validate range Parav Pandit
2020-09-21 16:41 ` [PATCH net-next 1/2] devlink: Enhance policy to validate eswitch mode value Parav Pandit
@ 2020-09-21 16:41 ` Parav Pandit
2020-09-21 22:47 ` [PATCH net-next 0/2] devlink: Use nla_policy to validate range Jakub Kicinski
2020-09-23 0:39 ` David Miller
3 siblings, 0 replies; 5+ messages in thread
From: Parav Pandit @ 2020-09-21 16:41 UTC (permalink / raw)
To: davem, kuba, netdev; +Cc: Parav Pandit, Jiri Pirko
Use range checking facility of nla_policy to validate port type
attribute input value is valid or not.
Signed-off-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
net/core/devlink.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 4ecc68a9c7df..4494937df7eb 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -867,8 +867,6 @@ static int devlink_port_type_set(struct devlink *devlink,
int err;
if (devlink->ops->port_type_set) {
- if (port_type == DEVLINK_PORT_TYPE_NOTSET)
- return -EINVAL;
if (port_type == devlink_port->type)
return 0;
err = devlink->ops->port_type_set(devlink_port, port_type);
@@ -7193,7 +7191,8 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = {
[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING },
[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING },
[DEVLINK_ATTR_PORT_INDEX] = { .type = NLA_U32 },
- [DEVLINK_ATTR_PORT_TYPE] = { .type = NLA_U16 },
+ [DEVLINK_ATTR_PORT_TYPE] = NLA_POLICY_RANGE(NLA_U16, DEVLINK_PORT_TYPE_AUTO,
+ DEVLINK_PORT_TYPE_IB),
[DEVLINK_ATTR_PORT_SPLIT_COUNT] = { .type = NLA_U32 },
[DEVLINK_ATTR_SB_INDEX] = { .type = NLA_U32 },
[DEVLINK_ATTR_SB_POOL_INDEX] = { .type = NLA_U16 },
--
2.26.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next 0/2] devlink: Use nla_policy to validate range
2020-09-21 16:41 [PATCH net-next 0/2] devlink: Use nla_policy to validate range Parav Pandit
2020-09-21 16:41 ` [PATCH net-next 1/2] devlink: Enhance policy to validate eswitch mode value Parav Pandit
2020-09-21 16:41 ` [PATCH net-next 2/2] devlink: Enhance policy to validate port type input value Parav Pandit
@ 2020-09-21 22:47 ` Jakub Kicinski
2020-09-23 0:39 ` David Miller
3 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2020-09-21 22:47 UTC (permalink / raw)
To: Parav Pandit; +Cc: davem, netdev
On Mon, 21 Sep 2020 19:41:28 +0300 Parav Pandit wrote:
> This two small patches uses nla_policy to validate user specified
> fields are in valid range or not.
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next 0/2] devlink: Use nla_policy to validate range
2020-09-21 16:41 [PATCH net-next 0/2] devlink: Use nla_policy to validate range Parav Pandit
` (2 preceding siblings ...)
2020-09-21 22:47 ` [PATCH net-next 0/2] devlink: Use nla_policy to validate range Jakub Kicinski
@ 2020-09-23 0:39 ` David Miller
3 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2020-09-23 0:39 UTC (permalink / raw)
To: parav; +Cc: kuba, netdev
From: Parav Pandit <parav@nvidia.com>
Date: Mon, 21 Sep 2020 19:41:28 +0300
> This two small patches uses nla_policy to validate user specified
> fields are in valid range or not.
>
> Patch summary:
> Patch-1 checks the range of eswitch mode field
> Patch-2 checks for the port type field. It eliminates a check in
> code by using nla policy infrastructure.
Series applied, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-09-23 0:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-21 16:41 [PATCH net-next 0/2] devlink: Use nla_policy to validate range Parav Pandit
2020-09-21 16:41 ` [PATCH net-next 1/2] devlink: Enhance policy to validate eswitch mode value Parav Pandit
2020-09-21 16:41 ` [PATCH net-next 2/2] devlink: Enhance policy to validate port type input value Parav Pandit
2020-09-21 22:47 ` [PATCH net-next 0/2] devlink: Use nla_policy to validate range Jakub Kicinski
2020-09-23 0:39 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).