Skip to contentSkip to conversation

net: rtnetlink: fix error handling in rtnl_fill_statsinfo()

PATCH Applied [email protected] 4 participants 4 messages Mar 5, 2022 – Mar 7, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: rtnetlink: fix error handling in rtnl_fill_statsinfo()

From: Tom Rix <[email protected]>

The clang static analyzer reports this issue
rtnetlink.c:5481:2: warning: Undefined or garbage
value returned to caller
return err;
^~~~~~~~~~

There is a function level err variable, in the
list_for_each_entry_rcu block there is a shadow
err. Remove the shadow.

In the same block, the call to nla_nest_start_noflag() can fail without setting an err. Set the err to -EMSGSIZE.

Fixes 216e690631f5 ("net: rtnetlink: rtnl_fill_statsinfo(): Permit non-EMSGSIZE error returns")
---
 net/core/rtnetlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/rtnetlink.c +1 -1
index a66b6761b88b1..a759f9e0a8476 100644
@@ -5440,12 +5440,12 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev,
 		list_for_each_entry_rcu(af_ops, &rtnl_af_ops, list) {
 			if (af_ops->fill_stats_af) {
 				struct nlattr *af;
-				int err;
 
 				af = nla_nest_start_noflag(skb,
 							   af_ops->family);
 				if (!af) {
 					rcu_read_unlock();
+					err = -EMSGSIZE;
 					goto nla_put_failure;
 				}
 				err = af_ops->fill_stats_af(skb, dev);
Signature · 1 line
2.26.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · On Sat, Mar 05, 2022 at 10:13:46AM -0800, [email protected] wrote:

From: Tom Rix <[email protected]>

The clang static analyzer reports this issue
rtnetlink.c:5481:2: warning: Undefined or garbage
value returned to caller
return err;
^~~~~~~~~~

There is a function level err variable, in the
list_for_each_entry_rcu block there is a shadow
err. Remove the shadow.

Quoted 6 lines

In the same block, the call to nla_nest_start_noflag() can fail without setting an err. Set the err to -EMSGSIZE.

Fixes 216e690631f5 ("net: rtnetlink: rtnl_fill_statsinfo(): Permit non-EMSGSIZE error returns")

For net-next:

Thanks

Reviewed-by on v1 1/1
#2 lore raw
In reply to [email protected]
Quoted 12 lines · [email protected] writes:

From: Tom Rix <[email protected]>

The clang static analyzer reports this issue
rtnetlink.c:5481:2: warning: Undefined or garbage
value returned to caller
return err;
^~~~~~~~~~

There is a function level err variable, in the
list_for_each_entry_rcu block there is a shadow
err. Remove the shadow.

Quoted 6 lines

In the same block, the call to nla_nest_start_noflag() can fail without setting an err. Set the err to -EMSGSIZE.

Fixes 216e690631f5 ("net: rtnetlink: rtnl_fill_statsinfo(): Permit non-EMSGSIZE error returns")

Thanks!

#3 lore raw
In reply to [email protected]
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 9 lines · On Sat, 5 Mar 2022 10:13:46 -0800 you wrote:

From: Tom Rix <[email protected]>

The clang static analyzer reports this issue
rtnetlink.c:5481:2: warning: Undefined or garbage
value returned to caller
return err;
^~~~~~~~~~

[...]

Here is the summary with links:
- net: rtnetlink: fix error handling in rtnl_fill_statsinfo()

    https://git.kernel.org/netdev/net-next/c/57d29a2935c9

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html