2023-01-26 13:58:58

by Natalia Petrova

[permalink] [raw]
Subject: [PATCH 5.10 0/1] i40e: Add checking for null for nlmsg_find_attr()

The remark about the error code by Simon Horman <[email protected]> was taken into account.
Return value -ENOENT was changed to -EINVAL.

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


2023-01-26 13:59:06

by Natalia Petrova

[permalink] [raw]
Subject: [PATCH 5.10 1/1] 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]>
---
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-26 19:55:36

by Jesse Brandeburg

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

On 1/26/2023 5:55 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]>
> ---
> 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;

Makes sense to me. Thanks.

Reviewed-by: Jesse Brandeburg <[email protected]>


2023-01-26 19:59:50

by Jesse Brandeburg

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

On 1/26/2023 11:55 AM, Jesse Brandeburg wrote:
> On 1/26/2023 5:55 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]>
>> ---
>>   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;
>
> Makes sense to me. Thanks.
>
> Reviewed-by: Jesse Brandeburg <[email protected]>
>

I presume that you meant this to be targeted to the "net" tree, which
you should indicate with the subject line:
[PATCH net ...]

as per the netdev rules published [1], and generally you don't need a
cover letter for a single patch.

[1] https://www.kernel.org/doc/html/v5.10/networking/netdev-FAQ.html


2023-01-27 07:33:09

by Greg Kroah-Hartman

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

On Thu, Jan 26, 2023 at 04:55:55PM +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]>
> ---
> 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>