vdpa: Enable strict validation for netlink ops
Subsystems (2)
v3 cover vdpa: Enable strict validation for netlink ops
The original patch from Lin Ma enables the vdpa driver to use validation netlink ops. The patch got split into 3 parts for easier backporting.
The last patch simply disables the validation skip which is no longer neccesary. Patchset started of from this discussion [0].
[0] https://lore.kernel.org/virtualization/[email protected]/T/#t
v3:
- Split initial patch for easier backporting.
- Correctly marked patches for stable inclusion.
v2:
- cc'ed stable
Dragos Tatulea (1):
vdpa: Enable strict validation for netlinks ops
Lin Ma (3):
vdpa: Add features attr to vdpa_nl_policy for nlattr length check
vdpa: Add queue index attr to vdpa_nl_policy for nlattr length check
vdpa: Add max vqp attr to vdpa_nl_policy for nlattr length check
drivers/vdpa/vdpa.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
Signature · 1 line
2.41.0
PATCH v3 1/4 vdpa: Add features attr to vdpa_nl_policy for nlattr length check
From: Lin Ma <[email protected]>
The vdpa_nl_policy structure is used to validate the nlattr when parsing the incoming nlmsg. It will ensure the attribute being described produces a valid nlattr pointer in info->attrs before entering into each handler in vdpa_nl_ops.
That is to say, the missing part in vdpa_nl_policy may lead to illegal nlattr after parsing, which could lead to OOB read just like CVE-2023-3773.
This patch adds the missing nla_policy for vdpa features attr to avoid such bugs.
--- drivers/vdpa/vdpa.c | 1 + 1 file changed, 1 insertion(+)
drivers/vdpa/vdpa.c +1 -0
@@ -1249,6 +1249,7 @@ static const struct nla_policy vdpa_nl_policy[VDPA_ATTR_MAX + 1] = { [VDPA_ATTR_DEV_NET_CFG_MACADDR ] =NLA_POLICY_ETH_ADDR , /* virtio spec 1.1 section 5.1.4.1 for valid MTU range */ [VDPA_ATTR_DEV_NET_CFG_MTU] = NLA_POLICY_MIN(NLA_U16, 68), + [VDPA_ATTR_DEV_FEATURES] = { .type = NLA_U64 }, };static const struct genl_ops vdpa_nl_ops[] = {
Signature · 1 line
2.41.0
PATCH v3 2/4 vdpa: Add queue index attr to vdpa_nl_policy for nlattr length check
In reply to Dragos TatuleaFrom: Lin Ma <[email protected]>
The vdpa_nl_policy structure is used to validate the nlattr when parsing the incoming nlmsg. It will ensure the attribute being described produces a valid nlattr pointer in info->attrs before entering into each handler in vdpa_nl_ops.
That is to say, the missing part in vdpa_nl_policy may lead to illegal nlattr after parsing, which could lead to OOB read just like CVE-2023-3773.
This patch adds the missing nla_policy for vdpa queue index attr to avoid such bugs.
--- drivers/vdpa/vdpa.c | 1 + 1 file changed, 1 insertion(+)
drivers/vdpa/vdpa.c +1 -0
@@ -1249,6 +1249,7 @@ static const struct nla_policy vdpa_nl_policy[VDPA_ATTR_MAX + 1] = { [VDPA_ATTR_DEV_NET_CFG_MACADDR] = NLA_POLICY_ETH_ADDR,/* virtio spec 1.1 section 5.1.4.1 for valid MTU range */ [VDPA_ATTR_DEV_NET_CFG_MTU] = NLA_POLICY_MIN(NLA_U16, 68), + [VDPA_ATTR_DEV_QUEUE_INDEX] = { .type = NLA_U32 }, [VDPA_ATTR_DEV_FEATURES] = { .type = NLA_U64 }, };
Signature · 6 lines
2.41.0 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v3 3/4 vdpa: Add max vqp attr to vdpa_nl_policy for nlattr length check
In reply to Dragos TatuleaFrom: Lin Ma <[email protected]>
The vdpa_nl_policy structure is used to validate the nlattr when parsing the incoming nlmsg. It will ensure the attribute being described produces a valid nlattr pointer in info->attrs before entering into each handler in vdpa_nl_ops.
That is to say, the missing part in vdpa_nl_policy may lead to illegal nlattr after parsing, which could lead to OOB read just like CVE-2023-3773.
This patch adds the missing nla_policy for vdpa max vqp attr to avoid such bugs.
--- drivers/vdpa/vdpa.c | 1 + 1 file changed, 1 insertion(+)
drivers/vdpa/vdpa.c +1 -0
@@ -1247,6 +1247,7 @@ static const struct nla_policy vdpa_nl_policy[VDPA_ATTR_MAX + 1] = { [VDPA_ATTR_MGMTDEV_DEV_NAME] = { .type = NLA_STRING }, [VDPA_ATTR_DEV_NAME] = { .type = NLA_STRING }, [VDPA_ATTR_DEV_NET_CFG_MACADDR] = NLA_POLICY_ETH_ADDR, + [VDPA_ATTR_DEV_NET_CFG_MAX_VQP] = { .type = NLA_U16 },/* virtio spec 1.1 section 5.1.4.1 for valid MTU range */ [VDPA_ATTR_DEV_NET_CFG_MTU] = NLA_POLICY_MIN(NLA_U16, 68), [VDPA_ATTR_DEV_QUEUE_INDEX] = { .type = NLA_U32 },
Signature · 6 lines
2.41.0 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v3 4/4 vdpa: Enable strict validation for netlinks ops
In reply to Dragos TatuleaThe previous patches added the missing nla policies that were required for validation to work.
Now strict validation on netlink ops can be enabled. This patch does it.
--- drivers/vdpa/vdpa.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/vdpa/vdpa.c +0 -6
@@ -1257,37 +1257,31 @@ static const struct nla_policy vdpa_nl_policy[VDPA_ATTR_MAX + 1] = {static const struct genl_ops vdpa_nl_ops[] = { { .cmd =VDPA_CMD_MGMTDEV_GET , - .validate =GENL_DONT_VALIDATE_STRICT |GENL_DONT_VALIDATE_DUMP , .doit = vdpa_nl_cmd_mgmtdev_get_doit, .dumpit = vdpa_nl_cmd_mgmtdev_get_dumpit, }, { .cmd =VDPA_CMD_DEV_NEW , - .validate =GENL_DONT_VALIDATE_STRICT |GENL_DONT_VALIDATE_DUMP , .doit = vdpa_nl_cmd_dev_add_set_doit, .flags =GENL_ADMIN_PERM , }, { .cmd =VDPA_CMD_DEV_DEL , - .validate =GENL_DONT_VALIDATE_STRICT |GENL_DONT_VALIDATE_DUMP , .doit = vdpa_nl_cmd_dev_del_set_doit, .flags =GENL_ADMIN_PERM , }, { .cmd =VDPA_CMD_DEV_GET , - .validate =GENL_DONT_VALIDATE_STRICT |GENL_DONT_VALIDATE_DUMP , .doit = vdpa_nl_cmd_dev_get_doit, .dumpit = vdpa_nl_cmd_dev_get_dumpit, }, { .cmd =VDPA_CMD_DEV_CONFIG_GET , - .validate =GENL_DONT_VALIDATE_STRICT |GENL_DONT_VALIDATE_DUMP , .doit = vdpa_nl_cmd_dev_config_get_doit, .dumpit = vdpa_nl_cmd_dev_config_get_dumpit, }, { .cmd =VDPA_CMD_DEV_VSTATS_GET , - .validate =GENL_DONT_VALIDATE_STRICT |GENL_DONT_VALIDATE_DUMP , .doit = vdpa_nl_cmd_dev_stats_get_doit, .flags =GENL_ADMIN_PERM , },
Signature · 6 lines
2.41.0 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization