Dragos Tatulea
2023-Jul-26 18:30 UTC
[PATCH 0/2] vdpa: Enable strict validation for netlink ops
The original patch from Lin Ma enables the vdpa driver to use validation netlink ops. The second patch simply disables the validation skip which is no longer neccesary. Patchset started of from this discussion [0]. [0] https://lore.kernel.org/virtualization/20230726074710-mutt-send-email-mst at kernel.org/T/#t Dragos Tatulea (1): vdpa: Enable strict validation for netlinks ops Lin Ma (1): vdpa: Complement vdpa_nl_policy for nlattr length check drivers/vdpa/vdpa.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) -- 2.41.0
Dragos Tatulea
2023-Jul-26 18:30 UTC
[PATCH 1/2] vdpa: Complement vdpa_nl_policy for nlattr length check
From: Lin Ma <linma at zju.edu.cn> 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 three missing nla_policy to avoid such bugs. Fixes: 90fea5a800c3 ("vdpa: device feature provisioning") Fixes: 13b00b135665 ("vdpa: Add support for querying vendor statistics") Fixes: ad69dd0bf26b ("vdpa: Introduce query of device config layout") Signed-off-by: Lin Ma <linma at zju.edu.cn> --- drivers/vdpa/vdpa.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index 965e32529eb8..f2f654fd84e5 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -1247,8 +1247,11 @@ 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 }, + [VDPA_ATTR_DEV_FEATURES] = { .type = NLA_U64 }, }; static const struct genl_ops vdpa_nl_ops[] = { -- 2.41.0
Dragos Tatulea
2023-Jul-26 18:30 UTC
[PATCH 2/2] vdpa: Enable strict validation for netlinks ops
The previous patch 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. Signed-off-by: Dragos Tatulea <dtatulea at nvidia.com> --- drivers/vdpa/vdpa.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c index f2f654fd84e5..a7612e0783b3 100644 --- a/drivers/vdpa/vdpa.c +++ b/drivers/vdpa/vdpa.c @@ -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, }, -- 2.41.0
Michael S. Tsirkin
2023-Jul-26 18:36 UTC
[PATCH 0/2] vdpa: Enable strict validation for netlink ops
On Wed, Jul 26, 2023 at 09:30:48PM +0300, Dragos Tatulea wrote:> The original patch from Lin Ma enables the vdpa driver to use validation > netlink ops. > > The second patch simply disables the validation skip which is no longer > neccesary. Patchset started of from this discussion [0]. > > [0] https://lore.kernel.org/virtualization/20230726074710-mutt-send-email-mst at kernel.org/T/#tCc stable with at least 1/2 ?> Dragos Tatulea (1): > vdpa: Enable strict validation for netlinks ops > > Lin Ma (1): > vdpa: Complement vdpa_nl_policy for nlattr length check > > drivers/vdpa/vdpa.c | 9 +++------ > 1 file changed, 3 insertions(+), 6 deletions(-) > > -- > 2.41.0