* [PATCH net] enic: Validate length of nl attributes in enic_set_vf_port
[not found] <20240516065755.6bce136f@kernel.org>
@ 2024-05-16 15:42 ` Roded Zats
2024-05-21 10:38 ` Paolo Abeni
0 siblings, 1 reply; 5+ messages in thread
From: Roded Zats @ 2024-05-16 15:42 UTC (permalink / raw)
To: benve, satishkh, davem, edumazet, kuba, pabeni; +Cc: orcohen, rzats, netdev
enic_set_vf_port assumes that the nl attribute IFLA_PORT_PROFILE
is of length PORT_PROFILE_MAX and that the nl attributes
IFLA_PORT_INSTANCE_UUID, IFLA_PORT_HOST_UUID are of length PORT_UUID_MAX.
These attributes are validated (in the function do_setlink in rtnetlink.c)
using the nla_policy ifla_port_policy. The policy defines IFLA_PORT_PROFILE
as NLA_STRING, IFLA_PORT_INSTANCE_UUID as NLA_BINARY and
IFLA_PORT_HOST_UUID as NLA_STRING. That means that the length validation
using the policy is for the max size of the attributes and not on exact
size so the length of these attributes might be less than the sizes that
enic_set_vf_port expects. This might cause an out of bands
read access in the memcpys of the data of these
attributes in enic_set_vf_port.
Fixes: f8bd909183ac ("net: Add ndo_{set|get}_vf_port support for enic dynamic vnics")
Signed-off-by: Roded Zats <rzats@paloaltonetworks.com>
---
drivers/net/ethernet/cisco/enic/enic_main.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
index f604119efc80..4179c6f9580d 100644
--- a/drivers/net/ethernet/cisco/enic/enic_main.c
+++ b/drivers/net/ethernet/cisco/enic/enic_main.c
@@ -1117,18 +1117,30 @@ static int enic_set_vf_port(struct net_device *netdev, int vf,
pp->request = nla_get_u8(port[IFLA_PORT_REQUEST]);
if (port[IFLA_PORT_PROFILE]) {
+ if (nla_len(port[IFLA_PORT_PROFILE]) != PORT_PROFILE_MAX) {
+ memcpy(pp, &prev_pp, sizeof(*pp));
+ return -EOPNOTSUPP;
+ }
pp->set |= ENIC_SET_NAME;
memcpy(pp->name, nla_data(port[IFLA_PORT_PROFILE]),
PORT_PROFILE_MAX);
}
if (port[IFLA_PORT_INSTANCE_UUID]) {
+ if (nla_len(port[IFLA_PORT_INSTANCE_UUID]) != PORT_UUID_MAX) {
+ memcpy(pp, &prev_pp, sizeof(*pp));
+ return -EOPNOTSUPP;
+ }
pp->set |= ENIC_SET_INSTANCE;
memcpy(pp->instance_uuid,
nla_data(port[IFLA_PORT_INSTANCE_UUID]), PORT_UUID_MAX);
}
if (port[IFLA_PORT_HOST_UUID]) {
+ if (nla_len(port[IFLA_PORT_HOST_UUID]) != PORT_UUID_MAX) {
+ memcpy(pp, &prev_pp, sizeof(*pp));
+ return -EOPNOTSUPP;
+ }
pp->set |= ENIC_SET_HOST;
memcpy(pp->host_uuid,
nla_data(port[IFLA_PORT_HOST_UUID]), PORT_UUID_MAX);
--
2.39.3 (Apple Git-146)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net] enic: Validate length of nl attributes in enic_set_vf_port
2024-05-16 15:42 ` [PATCH net] enic: Validate length of nl attributes in enic_set_vf_port Roded Zats
@ 2024-05-21 10:38 ` Paolo Abeni
2024-05-22 7:30 ` [PATCH net v2] " Roded Zats
0 siblings, 1 reply; 5+ messages in thread
From: Paolo Abeni @ 2024-05-21 10:38 UTC (permalink / raw)
To: Roded Zats, benve, satishkh, davem, edumazet, kuba; +Cc: orcohen, netdev
On Thu, 2024-05-16 at 18:42 +0300, Roded Zats wrote:
> enic_set_vf_port assumes that the nl attribute IFLA_PORT_PROFILE
> is of length PORT_PROFILE_MAX and that the nl attributes
> IFLA_PORT_INSTANCE_UUID, IFLA_PORT_HOST_UUID are of length PORT_UUID_MAX.
> These attributes are validated (in the function do_setlink in rtnetlink.c)
> using the nla_policy ifla_port_policy. The policy defines IFLA_PORT_PROFILE
> as NLA_STRING, IFLA_PORT_INSTANCE_UUID as NLA_BINARY and
> IFLA_PORT_HOST_UUID as NLA_STRING. That means that the length validation
> using the policy is for the max size of the attributes and not on exact
> size so the length of these attributes might be less than the sizes that
> enic_set_vf_port expects. This might cause an out of bands
> read access in the memcpys of the data of these
> attributes in enic_set_vf_port.
>
> Fixes: f8bd909183ac ("net: Add ndo_{set|get}_vf_port support for enic dynamic vnics")
> Signed-off-by: Roded Zats <rzats@paloaltonetworks.com>
> ---
> drivers/net/ethernet/cisco/enic/enic_main.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
> index f604119efc80..4179c6f9580d 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_main.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_main.c
> @@ -1117,18 +1117,30 @@ static int enic_set_vf_port(struct net_device *netdev, int vf,
> pp->request = nla_get_u8(port[IFLA_PORT_REQUEST]);
>
> if (port[IFLA_PORT_PROFILE]) {
> + if (nla_len(port[IFLA_PORT_PROFILE]) != PORT_PROFILE_MAX) {
> + memcpy(pp, &prev_pp, sizeof(*pp));
> + return -EOPNOTSUPP;
I think -EOPNOTSUPP is misleading here (and below), -EINVAL should be
appropriate.
Thanks,
Paolo
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net v2] enic: Validate length of nl attributes in enic_set_vf_port
2024-05-21 10:38 ` Paolo Abeni
@ 2024-05-22 7:30 ` Roded Zats
2024-05-27 9:42 ` patchwork-bot+netdevbpf
2024-06-27 23:20 ` Stephen Hemminger
0 siblings, 2 replies; 5+ messages in thread
From: Roded Zats @ 2024-05-22 7:30 UTC (permalink / raw)
To: benve, satishkh, davem, edumazet, kuba, pabeni; +Cc: orcohen, rzats, netdev
enic_set_vf_port assumes that the nl attribute IFLA_PORT_PROFILE
is of length PORT_PROFILE_MAX and that the nl attributes
IFLA_PORT_INSTANCE_UUID, IFLA_PORT_HOST_UUID are of length PORT_UUID_MAX.
These attributes are validated (in the function do_setlink in rtnetlink.c)
using the nla_policy ifla_port_policy. The policy defines IFLA_PORT_PROFILE
as NLA_STRING, IFLA_PORT_INSTANCE_UUID as NLA_BINARY and
IFLA_PORT_HOST_UUID as NLA_STRING. That means that the length validation
using the policy is for the max size of the attributes and not on exact
size so the length of these attributes might be less than the sizes that
enic_set_vf_port expects. This might cause an out of bands
read access in the memcpys of the data of these
attributes in enic_set_vf_port.
Fixes: f8bd909183ac ("net: Add ndo_{set|get}_vf_port support for enic dynamic vnics")
Signed-off-by: Roded Zats <rzats@paloaltonetworks.com>
---
drivers/net/ethernet/cisco/enic/enic_main.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
index f604119efc80..5f26fc3ad655 100644
--- a/drivers/net/ethernet/cisco/enic/enic_main.c
+++ b/drivers/net/ethernet/cisco/enic/enic_main.c
@@ -1117,18 +1117,30 @@ static int enic_set_vf_port(struct net_device *netdev, int vf,
pp->request = nla_get_u8(port[IFLA_PORT_REQUEST]);
if (port[IFLA_PORT_PROFILE]) {
+ if (nla_len(port[IFLA_PORT_PROFILE]) != PORT_PROFILE_MAX) {
+ memcpy(pp, &prev_pp, sizeof(*pp));
+ return -EINVAL;
+ }
pp->set |= ENIC_SET_NAME;
memcpy(pp->name, nla_data(port[IFLA_PORT_PROFILE]),
PORT_PROFILE_MAX);
}
if (port[IFLA_PORT_INSTANCE_UUID]) {
+ if (nla_len(port[IFLA_PORT_INSTANCE_UUID]) != PORT_UUID_MAX) {
+ memcpy(pp, &prev_pp, sizeof(*pp));
+ return -EINVAL;
+ }
pp->set |= ENIC_SET_INSTANCE;
memcpy(pp->instance_uuid,
nla_data(port[IFLA_PORT_INSTANCE_UUID]), PORT_UUID_MAX);
}
if (port[IFLA_PORT_HOST_UUID]) {
+ if (nla_len(port[IFLA_PORT_HOST_UUID]) != PORT_UUID_MAX) {
+ memcpy(pp, &prev_pp, sizeof(*pp));
+ return -EINVAL;
+ }
pp->set |= ENIC_SET_HOST;
memcpy(pp->host_uuid,
nla_data(port[IFLA_PORT_HOST_UUID]), PORT_UUID_MAX);
--
2.39.3 (Apple Git-146)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net v2] enic: Validate length of nl attributes in enic_set_vf_port
2024-05-22 7:30 ` [PATCH net v2] " Roded Zats
@ 2024-05-27 9:42 ` patchwork-bot+netdevbpf
2024-06-27 23:20 ` Stephen Hemminger
1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-05-27 9:42 UTC (permalink / raw)
To: Roded Zats
Cc: benve, satishkh, davem, edumazet, kuba, pabeni, orcohen, netdev
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Wed, 22 May 2024 10:30:44 +0300 you wrote:
> enic_set_vf_port assumes that the nl attribute IFLA_PORT_PROFILE
> is of length PORT_PROFILE_MAX and that the nl attributes
> IFLA_PORT_INSTANCE_UUID, IFLA_PORT_HOST_UUID are of length PORT_UUID_MAX.
> These attributes are validated (in the function do_setlink in rtnetlink.c)
> using the nla_policy ifla_port_policy. The policy defines IFLA_PORT_PROFILE
> as NLA_STRING, IFLA_PORT_INSTANCE_UUID as NLA_BINARY and
> IFLA_PORT_HOST_UUID as NLA_STRING. That means that the length validation
> using the policy is for the max size of the attributes and not on exact
> size so the length of these attributes might be less than the sizes that
> enic_set_vf_port expects. This might cause an out of bands
> read access in the memcpys of the data of these
> attributes in enic_set_vf_port.
>
> [...]
Here is the summary with links:
- [net,v2] enic: Validate length of nl attributes in enic_set_vf_port
https://git.kernel.org/netdev/net/c/e8021b94b041
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v2] enic: Validate length of nl attributes in enic_set_vf_port
2024-05-22 7:30 ` [PATCH net v2] " Roded Zats
2024-05-27 9:42 ` patchwork-bot+netdevbpf
@ 2024-06-27 23:20 ` Stephen Hemminger
1 sibling, 0 replies; 5+ messages in thread
From: Stephen Hemminger @ 2024-06-27 23:20 UTC (permalink / raw)
To: Roded Zats
Cc: benve, satishkh, davem, edumazet, kuba, pabeni, orcohen, netdev
On Wed, 22 May 2024 10:30:44 +0300
Roded Zats <rzats@paloaltonetworks.com> wrote:
> enic_set_vf_port assumes that the nl attribute IFLA_PORT_PROFILE
> is of length PORT_PROFILE_MAX and that the nl attributes
> IFLA_PORT_INSTANCE_UUID, IFLA_PORT_HOST_UUID are of length PORT_UUID_MAX.
> These attributes are validated (in the function do_setlink in rtnetlink.c)
> using the nla_policy ifla_port_policy. The policy defines IFLA_PORT_PROFILE
> as NLA_STRING, IFLA_PORT_INSTANCE_UUID as NLA_BINARY and
> IFLA_PORT_HOST_UUID as NLA_STRING. That means that the length validation
> using the policy is for the max size of the attributes and not on exact
> size so the length of these attributes might be less than the sizes that
> enic_set_vf_port expects. This might cause an out of bands
> read access in the memcpys of the data of these
> attributes in enic_set_vf_port.
>
> Fixes: f8bd909183ac ("net: Add ndo_{set|get}_vf_port support for enic dynamic vnics")
> Signed-off-by: Roded Zats <rzats@paloaltonetworks.com>
> ---
> drivers/net/ethernet/cisco/enic/enic_main.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
> index f604119efc80..5f26fc3ad655 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_main.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_main.c
> @@ -1117,18 +1117,30 @@ static int enic_set_vf_port(struct net_device *netdev, int vf,
> pp->request = nla_get_u8(port[IFLA_PORT_REQUEST]);
>
> if (port[IFLA_PORT_PROFILE]) {
> + if (nla_len(port[IFLA_PORT_PROFILE]) != PORT_PROFILE_MAX) {
> + memcpy(pp, &prev_pp, sizeof(*pp));
> + return -EINVAL;
> + }
If you have multiple error conditions with the same unwind, the common design
pattern in Linux is to use a goto error at end of function.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-06-27 23:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20240516065755.6bce136f@kernel.org>
2024-05-16 15:42 ` [PATCH net] enic: Validate length of nl attributes in enic_set_vf_port Roded Zats
2024-05-21 10:38 ` Paolo Abeni
2024-05-22 7:30 ` [PATCH net v2] " Roded Zats
2024-05-27 9:42 ` patchwork-bot+netdevbpf
2024-06-27 23:20 ` Stephen Hemminger
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.