2023-01-25 14:13:39

by Natalia Petrova

[permalink] [raw]
Subject: [PATCH] i40e: Add checking for null for nlmsg_find_attr()

The result of nlmsg_find_attr() 'br_spec' is dereferenced in
nla_for_each_nested, but it can take null value in 'nla_find' finction,
which will result in an error.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 51616018dd1b ("i40e: Add support for getlink, setlink ndo ops")
Signed-off-by: Natalia Petrova <[email protected]>
---
drivers/net/ethernet/intel/i40e/i40e_main.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
index b36bf9c3e1e4..ed4be4ffeb09 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -13101,6 +13101,8 @@ static int i40e_ndo_bridge_setlink(struct net_device *dev,
}

br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
+ if (!br_spec)
+ return -ENOENT;

nla_for_each_nested(attr, br_spec, rem) {
__u16 mode;
--
2.34.1



2023-01-25 15:08:26

by Simon Horman

[permalink] [raw]
Subject: Re: [PATCH] i40e: Add checking for null for nlmsg_find_attr()

On Wed, Jan 25, 2023 at 05:13:28PM +0300, Natalia Petrova wrote:
> The result of nlmsg_find_attr() 'br_spec' is dereferenced in
> nla_for_each_nested, but it can take null value in 'nla_find' finction,
> which will result in an error.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 51616018dd1b ("i40e: Add support for getlink, setlink ndo ops")
> Signed-off-by: Natalia Petrova <[email protected]>
> ---
> drivers/net/ethernet/intel/i40e/i40e_main.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
> index b36bf9c3e1e4..ed4be4ffeb09 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e_main.c
> +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
> @@ -13101,6 +13101,8 @@ static int i40e_ndo_bridge_setlink(struct net_device *dev,
> }
>
> br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
> + if (!br_spec)
> + return -ENOENT;

Seems fine to me, but I wonder if -EINVAL is more appropriate.
nlh is invalid in this case.

>
> nla_for_each_nested(attr, br_spec, rem) {
> __u16 mode;
> --
> 2.34.1
>

2023-01-25 15:58:46

by Deepak R Varma

[permalink] [raw]
Subject: Re: [PATCH] i40e: Add checking for null for nlmsg_find_attr()

On Wed, Jan 25, 2023 at 05:13:28PM +0300, Natalia Petrova wrote:
> The result of nlmsg_find_attr() 'br_spec' is dereferenced in
> nla_for_each_nested, but it can take null value in 'nla_find' finction,

s/finction/function

Regards,
./drv



2023-01-25 20:10:42

by Paul Menzel

[permalink] [raw]
Subject: Re: [Intel-wired-lan] [PATCH] i40e: Add checking for null for nlmsg_find_attr()

Dear Natalia,


Thank you for your patch.

Am 25.01.23 um 15:13 schrieb Natalia Petrova:

In the commit message summary, you could use:

Check if nlmsg_find_attr() returns null

> The result of nlmsg_find_attr() 'br_spec' is dereferenced in
> nla_for_each_nested, but it can take null value in 'nla_find' finction,

f*u*nction

> which will result in an error.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 51616018dd1b ("i40e: Add support for getlink, setlink ndo ops")
> Signed-off-by: Natalia Petrova <[email protected]>
> ---
> drivers/net/ethernet/intel/i40e/i40e_main.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
> index b36bf9c3e1e4..ed4be4ffeb09 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e_main.c
> +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
> @@ -13101,6 +13101,8 @@ static int i40e_ndo_bridge_setlink(struct net_device *dev,
> }
>
> br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
> + if (!br_spec)
> + return -ENOENT;
>
> nla_for_each_nested(attr, br_spec, rem) {
> __u16 mode;


Kind regards,

Paul

2023-01-30 22:11:25

by Natalia Petrova

[permalink] [raw]
Subject: [PATCH v2] i40e: Add checking for null for nlmsg_find_attr()

The result of nlmsg_find_attr() 'br_spec' is dereferenced in
nla_for_each_nested(), but it can take null value in nla_find() function,
which will result in an error.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 51616018dd1b ("i40e: Add support for getlink, setlink ndo ops")
Signed-off-by: Natalia Petrova <[email protected]>
Reviewed-by: Jesse Brandeburg <[email protected]>
---
v2: The remark about the error code by Simon Horman <[email protected]>
was taken into account; return value -ENOENT was changed to -EINVAL.
drivers/net/ethernet/intel/i40e/i40e_main.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
index 53d0083e35da..4626d2a1af91 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -13167,6 +13167,8 @@ static int i40e_ndo_bridge_setlink(struct net_device *dev,
}

br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
+ if (!br_spec)
+ return -EINVAL;

nla_for_each_nested(attr, br_spec, rem) {
__u16 mode;
--
2.34.1


2023-01-31 05:17:59

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v2] i40e: Add checking for null for nlmsg_find_attr()

On Tue, Jan 31, 2023 at 01:11:06AM +0300, Natalia Petrova wrote:
> The result of nlmsg_find_attr() 'br_spec' is dereferenced in
> nla_for_each_nested(), but it can take null value in nla_find() function,
> which will result in an error.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 51616018dd1b ("i40e: Add support for getlink, setlink ndo ops")
> Signed-off-by: Natalia Petrova <[email protected]>
> Reviewed-by: Jesse Brandeburg <[email protected]>
> ---
> v2: The remark about the error code by Simon Horman <[email protected]>
> was taken into account; return value -ENOENT was changed to -EINVAL.
> drivers/net/ethernet/intel/i40e/i40e_main.c | 2 ++
> 1 file changed, 2 insertions(+)
>

<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>

2023-01-31 16:23:45

by Simon Horman

[permalink] [raw]
Subject: Re: [PATCH v2] i40e: Add checking for null for nlmsg_find_attr()

On Tue, Jan 31, 2023 at 06:17:49AM +0100, Greg Kroah-Hartman wrote:
> On Tue, Jan 31, 2023 at 01:11:06AM +0300, Natalia Petrova wrote:
> > The result of nlmsg_find_attr() 'br_spec' is dereferenced in
> > nla_for_each_nested(), but it can take null value in nla_find() function,
> > which will result in an error.
> >
> > Found by Linux Verification Center (linuxtesting.org) with SVACE.
> >
> > Fixes: 51616018dd1b ("i40e: Add support for getlink, setlink ndo ops")
> > Signed-off-by: Natalia Petrova <[email protected]>
> > Reviewed-by: Jesse Brandeburg <[email protected]>
> > ---
> > v2: The remark about the error code by Simon Horman <[email protected]>
> > was taken into account; return value -ENOENT was changed to -EINVAL.
> > drivers/net/ethernet/intel/i40e/i40e_main.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
>
> <formletter>
>
> This is not the correct way to submit patches for inclusion in the
> stable kernel tree. Please read:
> https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
> for how to do this properly.
>
> </formletter>

Hi Natalia,

offering some friendly guidance here.

It seems to me that the problem you have highlighted is present
in current upstream code, and thus should be addressed there.

If it is considered a bug fix, then it should be targeted at the 'net'
tree. If the patch is accepted, into the release currently being
worked on (v6.2), backporting to older kernels can follow from there.
Otherwise it can be targeted at 'net-next', for inclusion
in the following release (v6.3).

As I think might have been mentioned, elsewhere, for networking
changes, you should indicate the target tree in the subject.
E.g. for net

Subject: [PATCH v3] i40e: Check if nlmsg_find_attr() returns null

The above also incorporates a suggested enhancement to the subject text.

I believe there was also a typo spotted in the patch description:
finction -> function

In all, my suggestion would be to address these problems as a v3.
I do not believe that you need to include [email protected]
or Greg on the recipient list, as the patch would be for 'net'
or 'net-next', not stable.

2023-02-01 09:06:26

by Natalia Petrova

[permalink] [raw]
Subject: [PATCH v3] i40e: Add checking for null for nlmsg_find_attr()

The result of nlmsg_find_attr() 'br_spec' is dereferenced in
nla_for_each_nested(), but it can take NULL value in nla_find() function,
which will result in an error.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 51616018dd1b ("i40e: Add support for getlink, setlink ndo ops")
Signed-off-by: Natalia Petrova <[email protected]>
Reviewed-by: Jesse Brandeburg <[email protected]>
---
v3: Fixed mailing list.
v2: The remark about the error code by Simon Horman <[email protected]>
was taken into account; return value -ENOENT was changed to -EINVAL.
drivers/net/ethernet/intel/i40e/i40e_main.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
index 53d0083e35da..4626d2a1af91 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -13167,6 +13167,8 @@ static int i40e_ndo_bridge_setlink(struct net_device *dev,
}

br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
+ if (!br_spec)
+ return -EINVAL;

nla_for_each_nested(attr, br_spec, rem) {
__u16 mode;
--
2.34.1


2023-02-02 17:23:24

by Tony Nguyen

[permalink] [raw]
Subject: Re: [PATCH v3] i40e: Add checking for null for nlmsg_find_attr()

On 2/1/2023 1:06 AM, Natalia Petrova wrote:
> The result of nlmsg_find_attr() 'br_spec' is dereferenced in
> nla_for_each_nested(), but it can take NULL value in nla_find() function,
> which will result in an error.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 51616018dd1b ("i40e: Add support for getlink, setlink ndo ops")
> Signed-off-by: Natalia Petrova <[email protected]>
> Reviewed-by: Jesse Brandeburg <[email protected]>
> ---

Thanks for the patch. I've applied it, however, for the future if you
could specify the target tree. Simon mentioned it in v2, but his example
omitted the tree.

i.e.
[PATCH v3 net] i40e: Add checking for null for nlmsg_find_attr()

Thanks,
Tony

> v3: Fixed mailing list.
> v2: The remark about the error code by Simon Horman <[email protected]>
> was taken into account; return value -ENOENT was changed to -EINVAL.
> drivers/net/ethernet/intel/i40e/i40e_main.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
> index 53d0083e35da..4626d2a1af91 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e_main.c
> +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
> @@ -13167,6 +13167,8 @@ static int i40e_ndo_bridge_setlink(struct net_device *dev,
> }
>
> br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
> + if (!br_spec)
> + return -EINVAL;
>
> nla_for_each_nested(attr, br_spec, rem) {
> __u16 mode;

2023-02-07 10:48:33

by G, GurucharanX

[permalink] [raw]
Subject: RE: [Intel-wired-lan] [PATCH v3] i40e: Add checking for null for nlmsg_find_attr()



> -----Original Message-----
> From: Intel-wired-lan <[email protected]> On Behalf Of
> Natalia Petrova
> Sent: Wednesday, February 1, 2023 2:36 PM
> To: Brandeburg, Jesse <[email protected]>
> Cc: [email protected]; [email protected]; Natalia
> Petrova <[email protected]>; [email protected]; Eric
> Dumazet <[email protected]>; Nguyen, Anthony L
> <[email protected]>; [email protected]; Jakub Kicinski
> <[email protected]>; Paolo Abeni <[email protected]>; David S. Miller
> <[email protected]>
> Subject: [Intel-wired-lan] [PATCH v3] i40e: Add checking for null for
> nlmsg_find_attr()
>
> The result of nlmsg_find_attr() 'br_spec' is dereferenced in
> nla_for_each_nested(), but it can take NULL value in nla_find() function,
> which will result in an error.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 51616018dd1b ("i40e: Add support for getlink, setlink ndo ops")
> Signed-off-by: Natalia Petrova <[email protected]>
> Reviewed-by: Jesse Brandeburg <[email protected]>
> ---
> v3: Fixed mailing list.
> v2: The remark about the error code by Simon Horman
> <[email protected]> was taken into account; return value -
> ENOENT was changed to -EINVAL.
> drivers/net/ethernet/intel/i40e/i40e_main.c | 2 ++
> 1 file changed, 2 insertions(+)
>

Tested-by: Gurucharan G <[email protected]> (A Contingent worker at Intel)