linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtnetlink: fix uninitialized variable
@ 2018-07-17 13:43 Gustavo A. R. Silva
  2018-07-17 17:57 ` Jakub Kicinski
  0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2018-07-17 13:43 UTC (permalink / raw)
  To: Jakub Kicinski, David S. Miller; +Cc: netdev, linux-kernel, Gustavo A. R. Silva

Currently, there are execution paths in which variable err is
returned without being properly initialized previously:

1417        if (rtnl_xdp_report_one(skb, dev, &prog_id, &mode, XDP_ATTACHED_SKB,
1418                                IFLA_XDP_SKB_PROG_ID, rtnl_xdp_prog_skb))
1419                goto err_cancel;
1420        if (rtnl_xdp_report_one(skb, dev, &prog_id, &mode, XDP_ATTACHED_DRV,
1421                                IFLA_XDP_DRV_PROG_ID, rtnl_xdp_prog_drv))
1422                goto err_cancel;
1423        if (rtnl_xdp_report_one(skb, dev, &prog_id, &mode, XDP_ATTACHED_HW,
1424                                IFLA_XDP_HW_PROG_ID, rtnl_xdp_prog_hw))
1425                goto err_cancel;

Fix this by initializing variable err to -EMSGSIZE.

Addresses-Coverity-ID: 1471831 ("Uninitialized scalar variable")
Fixes: a25717d2b604 ("xdp: support simultaneous driver and hw XDP attachment")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 net/core/rtnetlink.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index e03258e..648c984 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1405,12 +1405,12 @@ static int rtnl_xdp_fill(struct sk_buff *skb, struct net_device *dev)
 {
 	struct nlattr *xdp;
 	u32 prog_id;
-	int err;
+	int err = -EMSGSIZE;
 	u8 mode;
 
 	xdp = nla_nest_start(skb, IFLA_XDP);
 	if (!xdp)
-		return -EMSGSIZE;
+		return err;
 
 	prog_id = 0;
 	mode = XDP_ATTACHED_NONE;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] rtnetlink: fix uninitialized variable
  2018-07-17 13:43 [PATCH] rtnetlink: fix uninitialized variable Gustavo A. R. Silva
@ 2018-07-17 17:57 ` Jakub Kicinski
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2018-07-17 17:57 UTC (permalink / raw)
  To: Gustavo A. R. Silva; +Cc: David S. Miller, netdev, linux-kernel

On Tue, 17 Jul 2018 08:43:14 -0500, Gustavo A. R. Silva wrote:
> Currently, there are execution paths in which variable err is
> returned without being properly initialized previously:
> 
> 1417        if (rtnl_xdp_report_one(skb, dev, &prog_id, &mode, XDP_ATTACHED_SKB,
> 1418                                IFLA_XDP_SKB_PROG_ID, rtnl_xdp_prog_skb))
> 1419                goto err_cancel;
> 1420        if (rtnl_xdp_report_one(skb, dev, &prog_id, &mode, XDP_ATTACHED_DRV,
> 1421                                IFLA_XDP_DRV_PROG_ID, rtnl_xdp_prog_drv))
> 1422                goto err_cancel;
> 1423        if (rtnl_xdp_report_one(skb, dev, &prog_id, &mode, XDP_ATTACHED_HW,
> 1424                                IFLA_XDP_HW_PROG_ID, rtnl_xdp_prog_hw))
> 1425                goto err_cancel;
> 
> Fix this by initializing variable err to -EMSGSIZE.
> 
> Addresses-Coverity-ID: 1471831 ("Uninitialized scalar variable")
> Fixes: a25717d2b604 ("xdp: support simultaneous driver and hw XDP attachment")
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>

Looks like duplicate of:

http://patchwork.ozlabs.org/patch/944662/

Strage GCC doesn't catch this even with W=1, the code is fairly
straightforward :S

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-07-17 17:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-17 13:43 [PATCH] rtnetlink: fix uninitialized variable Gustavo A. R. Silva
2018-07-17 17:57 ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).