From: Stephen Hemminger <stephen@networkplumber.org>
To: Roded Zats <rzats@paloaltonetworks.com>
Cc: benve@cisco.com, satishkh@cisco.com, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
orcohen@paloaltonetworks.com, netdev@vger.kernel.org
Subject: Re: [PATCH net v2] enic: Validate length of nl attributes in enic_set_vf_port
Date: Thu, 27 Jun 2024 16:20:38 -0700 [thread overview]
Message-ID: <20240627162038.6e16d851@hermes.local> (raw)
In-Reply-To: <20240522073044.33519-1-rzats@paloaltonetworks.com>
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.
prev parent reply other threads:[~2024-06-27 23:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240627162038.6e16d851@hermes.local \
--to=stephen@networkplumber.org \
--cc=benve@cisco.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=orcohen@paloaltonetworks.com \
--cc=pabeni@redhat.com \
--cc=rzats@paloaltonetworks.com \
--cc=satishkh@cisco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox