netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] net: unexport some symbols that are annotated __init
@ 2022-06-06  4:53 Masahiro Yamada
  2022-06-06  4:53 ` [PATCH 1/3] net: mdio: unexport __init-annotated mdio_bus_init() Masahiro Yamada
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Masahiro Yamada @ 2022-06-06  4:53 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, netdev
  Cc: Eric Dumazet, Paolo Abeni, Masahiro Yamada, Andrew Lunn,
	David Ahern, David Lebrun, Florian Fainelli, Heiner Kallweit,
	Herbert Xu, Hideaki YOSHIFUJI, Russell King, Steffen Klassert,
	linux-kernel


This patch set fixes odd combinations
of EXPORT_SYMBOL and __init.

Checking this in modpost is a good thing and I really wanted to do it,
but Linus Torvalds imposes a very strict rule, "No new warning".

I'd like the maintainer to kindly pick this up and send a fixes pull request.

Unless I eliminate all the sites of warnings beforehand,
Linus refuses to re-enable the modpost check.   [1]

[1]: https://lore.kernel.org/linux-kbuild/CAK7LNATmd0bigp7HQ4fTzHw5ugZMkSb3UXG7L4fxpGbqkRKESA@mail.gmail.com/T/#m5e50cc2da17491ba210c72b5efdbc0ce76e0217f



Masahiro Yamada (3):
  net: mdio: unexport __init-annotated mdio_bus_init()
  net: xfrm: unexport __init-annotated xfrm4_protocol_init()
  net: ipv6: unexport __init-annotated seg6_hmac_init()

 drivers/net/phy/mdio_bus.c | 1 -
 net/ipv4/xfrm4_protocol.c  | 1 -
 net/ipv6/seg6_hmac.c       | 1 -
 3 files changed, 3 deletions(-)

-- 
2.32.0


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

* [PATCH 1/3] net: mdio: unexport __init-annotated mdio_bus_init()
  2022-06-06  4:53 [PATCH 0/3] net: unexport some symbols that are annotated __init Masahiro Yamada
@ 2022-06-06  4:53 ` Masahiro Yamada
  2022-06-06  8:09   ` Florian Fainelli
  2022-06-06  8:25   ` Russell King (Oracle)
  2022-06-06  4:53 ` [PATCH 2/3] net: xfrm: unexport __init-annotated xfrm4_protocol_init() Masahiro Yamada
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 9+ messages in thread
From: Masahiro Yamada @ 2022-06-06  4:53 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, netdev
  Cc: Eric Dumazet, Paolo Abeni, Masahiro Yamada, Stephen Rothwell,
	Andrew Lunn, Florian Fainelli, Heiner Kallweit, Russell King,
	linux-kernel

EXPORT_SYMBOL and __init is a bad combination because the .init.text
section is freed up after the initialization. Hence, modules cannot
use symbols annotated __init. The access to a freed symbol may end up
with kernel panic.

modpost used to detect it, but it has been broken for a decade.

Recently, I fixed modpost so it started to warn it again, then this
showed up in linux-next builds.

There are two ways to fix it:

  - Remove __init
  - Remove EXPORT_SYMBOL

I chose the latter for this case because the only in-tree call-site,
drivers/net/phy/phy_device.c is never compiled as modular.
(CONFIG_PHYLIB is boolean)

Fixes: 90eff9096c01 ("net: phy: Allow splitting MDIO bus/device support from PHYs")
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 drivers/net/phy/mdio_bus.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 58d602985877..8a2dbe849866 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -1046,7 +1046,6 @@ int __init mdio_bus_init(void)
 
 	return ret;
 }
-EXPORT_SYMBOL_GPL(mdio_bus_init);
 
 #if IS_ENABLED(CONFIG_PHYLIB)
 void mdio_bus_exit(void)
-- 
2.32.0


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

* [PATCH 2/3] net: xfrm: unexport __init-annotated xfrm4_protocol_init()
  2022-06-06  4:53 [PATCH 0/3] net: unexport some symbols that are annotated __init Masahiro Yamada
  2022-06-06  4:53 ` [PATCH 1/3] net: mdio: unexport __init-annotated mdio_bus_init() Masahiro Yamada
@ 2022-06-06  4:53 ` Masahiro Yamada
  2022-06-07 11:18   ` Paolo Abeni
  2022-06-06  4:53 ` [PATCH 3/3] net: ipv6: unexport __init-annotated seg6_hmac_init() Masahiro Yamada
  2022-06-08 17:20 ` [PATCH 0/3] net: unexport some symbols that are annotated __init patchwork-bot+netdevbpf
  3 siblings, 1 reply; 9+ messages in thread
From: Masahiro Yamada @ 2022-06-06  4:53 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, netdev
  Cc: Eric Dumazet, Paolo Abeni, Masahiro Yamada, Stephen Rothwell,
	David Ahern, Herbert Xu, Hideaki YOSHIFUJI, Steffen Klassert,
	linux-kernel

EXPORT_SYMBOL and __init is a bad combination because the .init.text
section is freed up after the initialization. Hence, modules cannot
use symbols annotated __init. The access to a freed symbol may end up
with kernel panic.

modpost used to detect it, but it has been broken for a decade.

Recently, I fixed modpost so it started to warn it again, then this
showed up in linux-next builds.

There are two ways to fix it:

  - Remove __init
  - Remove EXPORT_SYMBOL

I chose the latter for this case because the only in-tree call-site,
net/ipv4/xfrm4_policy.c is never compiled as modular.
(CONFIG_XFRM is boolean)

Fixes: 2f32b51b609f ("xfrm: Introduce xfrm_input_afinfo to access the the callbacks properly")
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 net/ipv4/xfrm4_protocol.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/net/ipv4/xfrm4_protocol.c b/net/ipv4/xfrm4_protocol.c
index 2fe5860c21d6..b146ce88c5d0 100644
--- a/net/ipv4/xfrm4_protocol.c
+++ b/net/ipv4/xfrm4_protocol.c
@@ -304,4 +304,3 @@ void __init xfrm4_protocol_init(void)
 {
 	xfrm_input_register_afinfo(&xfrm4_input_afinfo);
 }
-EXPORT_SYMBOL(xfrm4_protocol_init);
-- 
2.32.0


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

* [PATCH 3/3] net: ipv6: unexport __init-annotated seg6_hmac_init()
  2022-06-06  4:53 [PATCH 0/3] net: unexport some symbols that are annotated __init Masahiro Yamada
  2022-06-06  4:53 ` [PATCH 1/3] net: mdio: unexport __init-annotated mdio_bus_init() Masahiro Yamada
  2022-06-06  4:53 ` [PATCH 2/3] net: xfrm: unexport __init-annotated xfrm4_protocol_init() Masahiro Yamada
@ 2022-06-06  4:53 ` Masahiro Yamada
  2022-06-08 17:20 ` [PATCH 0/3] net: unexport some symbols that are annotated __init patchwork-bot+netdevbpf
  3 siblings, 0 replies; 9+ messages in thread
From: Masahiro Yamada @ 2022-06-06  4:53 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, netdev
  Cc: Eric Dumazet, Paolo Abeni, Masahiro Yamada, Stephen Rothwell,
	David Ahern, David Lebrun, Hideaki YOSHIFUJI, linux-kernel

EXPORT_SYMBOL and __init is a bad combination because the .init.text
section is freed up after the initialization. Hence, modules cannot
use symbols annotated __init. The access to a freed symbol may end up
with kernel panic.

modpost used to detect it, but it has been broken for a decade.

Recently, I fixed modpost so it started to warn it again, then this
showed up in linux-next builds.

There are two ways to fix it:

  - Remove __init
  - Remove EXPORT_SYMBOL

I chose the latter for this case because the caller (net/ipv6/seg6.c)
and the callee (net/ipv6/seg6_hmac.c) belong to the same module.
It seems an internal function call in ipv6.ko.

Fixes: bf355b8d2c30 ("ipv6: sr: add core files for SR HMAC support")
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 net/ipv6/seg6_hmac.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/net/ipv6/seg6_hmac.c b/net/ipv6/seg6_hmac.c
index 29bc4e7c3046..6de01185cc68 100644
--- a/net/ipv6/seg6_hmac.c
+++ b/net/ipv6/seg6_hmac.c
@@ -399,7 +399,6 @@ int __init seg6_hmac_init(void)
 {
 	return seg6_hmac_init_algo();
 }
-EXPORT_SYMBOL(seg6_hmac_init);
 
 int __net_init seg6_hmac_net_init(struct net *net)
 {
-- 
2.32.0


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

* Re: [PATCH 1/3] net: mdio: unexport __init-annotated mdio_bus_init()
  2022-06-06  4:53 ` [PATCH 1/3] net: mdio: unexport __init-annotated mdio_bus_init() Masahiro Yamada
@ 2022-06-06  8:09   ` Florian Fainelli
  2022-06-06  8:25   ` Russell King (Oracle)
  1 sibling, 0 replies; 9+ messages in thread
From: Florian Fainelli @ 2022-06-06  8:09 UTC (permalink / raw)
  To: Masahiro Yamada, David S . Miller, Jakub Kicinski, netdev
  Cc: Eric Dumazet, Paolo Abeni, Stephen Rothwell, Andrew Lunn,
	Heiner Kallweit, Russell King, linux-kernel



On 6/6/2022 6:53 AM, Masahiro Yamada wrote:
> EXPORT_SYMBOL and __init is a bad combination because the .init.text
> section is freed up after the initialization. Hence, modules cannot
> use symbols annotated __init. The access to a freed symbol may end up
> with kernel panic.
> 
> modpost used to detect it, but it has been broken for a decade.
> 
> Recently, I fixed modpost so it started to warn it again, then this
> showed up in linux-next builds.
> 
> There are two ways to fix it:
> 
>    - Remove __init
>    - Remove EXPORT_SYMBOL
> 
> I chose the latter for this case because the only in-tree call-site,
> drivers/net/phy/phy_device.c is never compiled as modular.
> (CONFIG_PHYLIB is boolean)
> 
> Fixes: 90eff9096c01 ("net: phy: Allow splitting MDIO bus/device support from PHYs")
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

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

* Re: [PATCH 1/3] net: mdio: unexport __init-annotated mdio_bus_init()
  2022-06-06  4:53 ` [PATCH 1/3] net: mdio: unexport __init-annotated mdio_bus_init() Masahiro Yamada
  2022-06-06  8:09   ` Florian Fainelli
@ 2022-06-06  8:25   ` Russell King (Oracle)
  1 sibling, 0 replies; 9+ messages in thread
From: Russell King (Oracle) @ 2022-06-06  8:25 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: David S . Miller, Jakub Kicinski, netdev, Eric Dumazet,
	Paolo Abeni, Stephen Rothwell, Andrew Lunn, Florian Fainelli,
	Heiner Kallweit, linux-kernel

On Mon, Jun 06, 2022 at 01:53:53PM +0900, Masahiro Yamada wrote:
> EXPORT_SYMBOL and __init is a bad combination because the .init.text
> section is freed up after the initialization. Hence, modules cannot
> use symbols annotated __init. The access to a freed symbol may end up
> with kernel panic.
> 
> modpost used to detect it, but it has been broken for a decade.
> 
> Recently, I fixed modpost so it started to warn it again, then this
> showed up in linux-next builds.
> 
> There are two ways to fix it:
> 
>   - Remove __init
>   - Remove EXPORT_SYMBOL
> 
> I chose the latter for this case because the only in-tree call-site,
> drivers/net/phy/phy_device.c is never compiled as modular.
> (CONFIG_PHYLIB is boolean)
> 
> Fixes: 90eff9096c01 ("net: phy: Allow splitting MDIO bus/device support from PHYs")
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

Thanks!

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

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

* Re: [PATCH 2/3] net: xfrm: unexport __init-annotated xfrm4_protocol_init()
  2022-06-06  4:53 ` [PATCH 2/3] net: xfrm: unexport __init-annotated xfrm4_protocol_init() Masahiro Yamada
@ 2022-06-07 11:18   ` Paolo Abeni
  2022-06-08  5:39     ` Steffen Klassert
  0 siblings, 1 reply; 9+ messages in thread
From: Paolo Abeni @ 2022-06-07 11:18 UTC (permalink / raw)
  To: Steffen Klassert
  Cc: Eric Dumazet, Stephen Rothwell, David Ahern, Herbert Xu,
	Hideaki YOSHIFUJI, linux-kernel, Masahiro Yamada,
	David S . Miller, Jakub Kicinski, netdev

On Mon, 2022-06-06 at 13:53 +0900, Masahiro Yamada wrote:
> EXPORT_SYMBOL and __init is a bad combination because the .init.text
> section is freed up after the initialization. Hence, modules cannot
> use symbols annotated __init. The access to a freed symbol may end up
> with kernel panic.
> 
> modpost used to detect it, but it has been broken for a decade.
> 
> Recently, I fixed modpost so it started to warn it again, then this
> showed up in linux-next builds.
> 
> There are two ways to fix it:
> 
>   - Remove __init
>   - Remove EXPORT_SYMBOL
> 
> I chose the latter for this case because the only in-tree call-site,
> net/ipv4/xfrm4_policy.c is never compiled as modular.
> (CONFIG_XFRM is boolean)
> 
> Fixes: 2f32b51b609f ("xfrm: Introduce xfrm_input_afinfo to access the the callbacks properly")
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

@Steffen: are you ok if we take this one in the -net tree directly?
Otherwise a repost would probably be the better option, with this patch
stand-alone targeting the ipsec tree and the other 2 targeting -net.

Thanks!

Paolo


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

* Re: [PATCH 2/3] net: xfrm: unexport __init-annotated xfrm4_protocol_init()
  2022-06-07 11:18   ` Paolo Abeni
@ 2022-06-08  5:39     ` Steffen Klassert
  0 siblings, 0 replies; 9+ messages in thread
From: Steffen Klassert @ 2022-06-08  5:39 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: Eric Dumazet, Stephen Rothwell, David Ahern, Herbert Xu,
	Hideaki YOSHIFUJI, linux-kernel, Masahiro Yamada,
	David S . Miller, Jakub Kicinski, netdev

On Tue, Jun 07, 2022 at 01:18:32PM +0200, Paolo Abeni wrote:
> On Mon, 2022-06-06 at 13:53 +0900, Masahiro Yamada wrote:
> > EXPORT_SYMBOL and __init is a bad combination because the .init.text
> > section is freed up after the initialization. Hence, modules cannot
> > use symbols annotated __init. The access to a freed symbol may end up
> > with kernel panic.
> > 
> > modpost used to detect it, but it has been broken for a decade.
> > 
> > Recently, I fixed modpost so it started to warn it again, then this
> > showed up in linux-next builds.
> > 
> > There are two ways to fix it:
> > 
> >   - Remove __init
> >   - Remove EXPORT_SYMBOL
> > 
> > I chose the latter for this case because the only in-tree call-site,
> > net/ipv4/xfrm4_policy.c is never compiled as modular.
> > (CONFIG_XFRM is boolean)
> > 
> > Fixes: 2f32b51b609f ("xfrm: Introduce xfrm_input_afinfo to access the the callbacks properly")
> > Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> 
> @Steffen: are you ok if we take this one in the -net tree directly?
> Otherwise a repost would probably be the better option, with this patch
> stand-alone targeting the ipsec tree and the other 2 targeting -net.

Yes, just take it.

Acked-by: Steffen Klassert <steffen.klassert@secunet.com>

Thanks!

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

* Re: [PATCH 0/3] net: unexport some symbols that are annotated __init
  2022-06-06  4:53 [PATCH 0/3] net: unexport some symbols that are annotated __init Masahiro Yamada
                   ` (2 preceding siblings ...)
  2022-06-06  4:53 ` [PATCH 3/3] net: ipv6: unexport __init-annotated seg6_hmac_init() Masahiro Yamada
@ 2022-06-08 17:20 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 9+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-06-08 17:20 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: davem, kuba, netdev, edumazet, pabeni, andrew, dsahern,
	david.lebrun, f.fainelli, hkallweit1, herbert, yoshfuji, linux,
	steffen.klassert, linux-kernel

Hello:

This series was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Mon,  6 Jun 2022 13:53:52 +0900 you wrote:
> This patch set fixes odd combinations
> of EXPORT_SYMBOL and __init.
> 
> Checking this in modpost is a good thing and I really wanted to do it,
> but Linus Torvalds imposes a very strict rule, "No new warning".
> 
> I'd like the maintainer to kindly pick this up and send a fixes pull request.
> 
> [...]

Here is the summary with links:
  - [1/3] net: mdio: unexport __init-annotated mdio_bus_init()
    https://git.kernel.org/netdev/net/c/35b42dce6197
  - [2/3] net: xfrm: unexport __init-annotated xfrm4_protocol_init()
    https://git.kernel.org/netdev/net/c/4a388f08d878
  - [3/3] net: ipv6: unexport __init-annotated seg6_hmac_init()
    https://git.kernel.org/netdev/net/c/5801f064e351

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2022-06-08 17:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-06  4:53 [PATCH 0/3] net: unexport some symbols that are annotated __init Masahiro Yamada
2022-06-06  4:53 ` [PATCH 1/3] net: mdio: unexport __init-annotated mdio_bus_init() Masahiro Yamada
2022-06-06  8:09   ` Florian Fainelli
2022-06-06  8:25   ` Russell King (Oracle)
2022-06-06  4:53 ` [PATCH 2/3] net: xfrm: unexport __init-annotated xfrm4_protocol_init() Masahiro Yamada
2022-06-07 11:18   ` Paolo Abeni
2022-06-08  5:39     ` Steffen Klassert
2022-06-06  4:53 ` [PATCH 3/3] net: ipv6: unexport __init-annotated seg6_hmac_init() Masahiro Yamada
2022-06-08 17:20 ` [PATCH 0/3] net: unexport some symbols that are annotated __init patchwork-bot+netdevbpf

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).