Skip to contentSkip to conversation

sfc: fix uninitialized variable use

PATCH In review Arnd Bergmann 4 participants 7 messages Jun 16, 2023

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

PATCH 1/2 sfc: fix uninitialized variable use

From: Arnd Bergmann <[email protected]>

The new efx_bind_neigh() function contains a broken code path when IPV6 is disabled:

drivers/net/ethernet/sfc/tc_encap_actions.c:144:7: error: variable 'n' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]

                if (encap->type & EFX_ENCAP_FLAG_IPV6) {
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/sfc/tc_encap_actions.c:184:8: note: uninitialized use occurs here
                if (!n) {
                     ^
drivers/net/ethernet/sfc/tc_encap_actions.c:144:3: note: remove the 'if' if its condition is always false
                if (encap->type & EFX_ENCAP_FLAG_IPV6) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/sfc/tc_encap_actions.c:141:22: note: initialize the variable 'n' to silence this warning
                struct neighbour *n;
                                   ^
                                    = NULL

Change it to use the existing error handling path here.

Fixes 7e5e7d800011a ("sfc: neighbour lookup for TC encap action offload")
---
 drivers/net/ethernet/sfc/tc_encap_actions.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/sfc/tc_encap_actions.c +1 -0
index aac259528e73e..cfd76d5bbdd48 100644
@@ -163,6 +163,7 @@ static int efx_bind_neigh(struct efx_nic *efx,
 			 * enabled how did someone create an IPv6 tunnel_key?
 			 */
 			rc = -EOPNOTSUPP;
+			n = NULL;
 			NL_SET_ERR_MSG_MOD(extack, "No IPv6 support (neigh bind)");
 #endif
 		} else {
Signature · 1 line
2.39.2
#1 lore raw

PATCH 2/2 sfc: add CONFIG_INET dependency for TC offload

From: Arnd Bergmann <[email protected]>

The driver now fails to link when CONFIG_INET is disabled, so add an explicit Kconfig dependency:

ld.lld: error: undefined symbol: ip_route_output_flow

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by tc_encap_actions.c
drivers/net/ethernet/sfc/tc_encap_actions.o:(efx_tc_flower_create_encap_md) in archive vmlinux.a

ld.lld: error: undefined symbol: ip_send_check

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

referenced by tc_encap_actions.c
drivers/net/ethernet/sfc/tc_encap_actions.o:(efx_gen_encap_header) in archive vmlinux.a
referenced by tc_encap_actions.c
drivers/net/ethernet/sfc/tc_encap_actions.o:(efx_gen_encap_header) in archive vmlinux.a

ld.lld: error: undefined symbol: arp_tbl

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

referenced by tc_encap_actions.c
drivers/net/ethernet/sfc/tc_encap_actions.o:(efx_tc_netevent_event) in archive vmlinux.a
referenced by tc_encap_actions.c
drivers/net/ethernet/sfc/tc_encap_actions.o:(efx_tc_netevent_event) in archive vmlinux.a

Fixes a1e82162af0b8 ("sfc: generate encap headers for TC offload")
---
 drivers/net/ethernet/sfc/Kconfig | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/sfc/Kconfig +1 -0
index 4af36ba8906ba..3eb55dcfa8a61 100644
@@ -50,6 +50,7 @@ config SFC_MCDI_MON
 config SFC_SRIOV
 	bool "Solarflare SFC9100-family SR-IOV support"
 	depends on SFC && PCI_IOV
+	depends on INET
 	default y
 	help
 	  This enables support for the Single Root I/O Virtualization
Signature · 1 line
2.39.2
Reviewed-by on v1 1/2
#5 lore raw
In reply to Arnd Bergmann
Quoted 19 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The new efx_bind_neigh() function contains a broken code path when IPV6 is disabled:

drivers/net/ethernet/sfc/tc_encap_actions.c:144:7: error: variable 'n' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]

                if (encap->type & EFX_ENCAP_FLAG_IPV6) {
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/sfc/tc_encap_actions.c:184:8: note: uninitialized use occurs here
                if (!n) {
                     ^
drivers/net/ethernet/sfc/tc_encap_actions.c:144:3: note: remove the 'if' if its condition is always false
                if (encap->type & EFX_ENCAP_FLAG_IPV6) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/sfc/tc_encap_actions.c:141:22: note: initialize the variable 'n' to silence this warning
                struct neighbour *n;
                                   ^
                                    = NULL
Quoted 4 lines

Change it to use the existing error handling path here.

Fixes 7e5e7d800011a ("sfc: neighbour lookup for TC encap action offload")
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] sfc: add CONFIG_INET dependency for TC offload

In reply to Arnd Bergmann
Quoted 15 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The driver now fails to link when CONFIG_INET is disabled, so add an explicit Kconfig dependency:

ld.lld: error: undefined symbol: ip_route_output_flow

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by tc_encap_actions.c
drivers/net/ethernet/sfc/tc_encap_actions.o:(efx_tc_flower_create_encap_md) in archive vmlinux.a

ld.lld: error: undefined symbol: ip_send_check

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

referenced by tc_encap_actions.c
drivers/net/ethernet/sfc/tc_encap_actions.o:(efx_gen_encap_header) in archive vmlinux.a
referenced by tc_encap_actions.c
drivers/net/ethernet/sfc/tc_encap_actions.o:(efx_gen_encap_header) in archive vmlinux.a

Quoted 8 lines

ld.lld: error: undefined symbol: arp_tbl

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

referenced by tc_encap_actions.c
drivers/net/ethernet/sfc/tc_encap_actions.o:(efx_tc_netevent_event) in archive vmlinux.a
referenced by tc_encap_actions.c
drivers/net/ethernet/sfc/tc_encap_actions.o:(efx_tc_netevent_event) in archive vmlinux.a

Fixes a1e82162af0b8 ("sfc: generate encap headers for TC offload")
maintainer
#6 lore raw
In reply to Arnd Bergmann
Quoted 33 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The new efx_bind_neigh() function contains a broken code path when IPV6 is disabled:

drivers/net/ethernet/sfc/tc_encap_actions.c:144:7: error: variable 'n' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]

                if (encap->type & EFX_ENCAP_FLAG_IPV6) {
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/sfc/tc_encap_actions.c:184:8: note: uninitialized use occurs here
                if (!n) {
                     ^
drivers/net/ethernet/sfc/tc_encap_actions.c:144:3: note: remove the 'if' if its condition is always false
                if (encap->type & EFX_ENCAP_FLAG_IPV6) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/sfc/tc_encap_actions.c:141:22: note: initialize the variable 'n' to silence this warning
                struct neighbour *n;
                                   ^
                                    = NULL

Change it to use the existing error handling path here.

Fixes 7e5e7d800011a ("sfc: neighbour lookup for TC encap action offload")
---
 drivers/net/ethernet/sfc/tc_encap_actions.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/sfc/tc_encap_actions.c +0 -0
index aac259528e73e..cfd76d5bbdd48 100644

drivers/net/ethernet/sfc/tc_encap_actions.c static int efx_bind_neigh(struct efx_nic *efx, · line 169

Quoted 7 lines
drivers/net/ethernet/sfc/tc_encap_actions.c +1 -0
@@ -163,6 +163,7 @@ static int efx_bind_neigh(struct efx_nic *efx,
 			 * enabled how did someone create an IPv6 tunnel_key?
 			 */
 			rc = -EOPNOTSUPP;
+			n = NULL;
 			NL_SET_ERR_MSG_MOD(extack, "No IPv6 support (neigh bind)");
 #endif
 		} else {

Nack. There is a bug here, as you've identified, but the right fix
is to add a 'goto out_free;' after setting the rc and extack msg.
Setting n to NULL and relying on the subsequent error path will not
only produce the wrong rc and error message, it will also attempt to drop a reference on neigh->egdev that was never taken.

-ed

maintainer Reviewed-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] sfc: add CONFIG_INET dependency for TC offload

In reply to Arnd Bergmann
Quoted 15 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The driver now fails to link when CONFIG_INET is disabled, so add an explicit Kconfig dependency:

ld.lld: error: undefined symbol: ip_route_output_flow

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by tc_encap_actions.c
drivers/net/ethernet/sfc/tc_encap_actions.o:(efx_tc_flower_create_encap_md) in archive vmlinux.a

ld.lld: error: undefined symbol: ip_send_check

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

referenced by tc_encap_actions.c
drivers/net/ethernet/sfc/tc_encap_actions.o:(efx_gen_encap_header) in archive vmlinux.a
referenced by tc_encap_actions.c
drivers/net/ethernet/sfc/tc_encap_actions.o:(efx_gen_encap_header) in archive vmlinux.a

Quoted 8 lines

ld.lld: error: undefined symbol: arp_tbl

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

referenced by tc_encap_actions.c
drivers/net/ethernet/sfc/tc_encap_actions.o:(efx_tc_netevent_event) in archive vmlinux.a
referenced by tc_encap_actions.c
drivers/net/ethernet/sfc/tc_encap_actions.o:(efx_tc_netevent_event) in archive vmlinux.a

Fixes a1e82162af0b8 ("sfc: generate encap headers for TC offload")

and I think you also need

Fixes 7e5e7d800011 ("sfc: neighbour lookup for TC encap action offload")

since that added the references to ip_route_output_flow and arp_tbl (the commit in your Fixes: added the ip_send_check reference on top of that).

You also might want to add the Closes: tag from [1], I don't know how
that works but I assume it'll make someone's regression-bot happy.

-ed

[1] https://lore.kernel.org/oe-kbuild-all/[email protected]/

Quoted 17 lines
---
 drivers/net/ethernet/sfc/Kconfig | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/sfc/Kconfig +1 -0
index 4af36ba8906ba..3eb55dcfa8a61 100644
@@ -50,6 +50,7 @@ config SFC_MCDI_MON
 config SFC_SRIOV
 	bool "Solarflare SFC9100-family SR-IOV support"
 	depends on SFC && PCI_IOV
+	depends on INET
 	default y
 	help
 	  This enables support for the Single Root I/O Virtualization
#4 lore raw

Re: [PATCH 2/2] sfc: add CONFIG_INET dependency for TC offload

Quoted 7 lines · Edward Cree
Quoted 3 lines · Arnd Bergmann
Fixes a1e82162af0b8 ("sfc: generate encap headers for TC offload")

and I think you also need

Quoted 8 lines
Fixes 7e5e7d800011 ("sfc: neighbour lookup for TC encap action offload")

since that added the references to ip_route_output_flow and arp_tbl (the commit in your Fixes: added the ip_send_check reference on top of that).

You also might want to add the Closes: tag from [1], I don't know how
that works but I assume it'll make someone's regression-bot happy.

[1] https://lore.kernel.org/oe-kbuild-all/[email protected]/

FWIW, yes, regression tracking relies on them (for now Link: and the newly introduced Closes: work; the latter came up totally independent of regression tracking). And I have no problem with being the bad guy here. :-D

But for completeness, in case anyone cares:

It's Linus that for many years already wants these links. He a while ago mentioned that in a few posts I bookmarked:

https://lore.kernel.org/all/CAHk-=wjMmSZzMJ3Xnskdg4+GGz=5p5p+GSYyFBTh0f-DgvdBWg@mail.gmail.com/
https://lore.kernel.org/all/CAHk-=wgs38ZrfPvy=nOwVkVzjpM3VFU1zobP37Fwd_h9iAD5JQ@mail.gmail.com/
https://lore.kernel.org/all/CAHk-=wjxzafG-=J8oT30s7upn4RhBs6TX-uVFZ5rME+L5_DoJA@mail.gmail.com/

But that's nothing new: Documentation/process/submitting-patches.rst explained this usage for many years already (I just made this more explicit a while a go).

Ciao, Thorsten