* [PATCH net-next] net: ethtool: Fix suspicious rcu_dereference usage
@ 2024-12-17 14:03 Kory Maincent
2024-12-17 15:47 ` Eric Dumazet
0 siblings, 1 reply; 5+ messages in thread
From: Kory Maincent @ 2024-12-17 14:03 UTC (permalink / raw)
To: David S. Miller, Kory Maincent, netdev, linux-kernel
Cc: syzbot+a344326c05c98ba19682, thomas.petazzoni, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman
The __ethtool_get_ts_info function can be called with or without the
rtnl lock held. When the rtnl lock is not held, using rtnl_dereference()
triggers a warning due to improper lock context.
Replace rtnl_dereference() with rcu_dereference_rtnl() to safely
dereference the RCU pointer in both scenarios, ensuring proper handling
regardless of the rtnl lock state.
Reported-by: syzbot+a344326c05c98ba19682@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/netdev/676147f8.050a0220.37aaf.0154.GAE@google.com/
Fixes: b9e3f7dc9ed9 ("net: ethtool: tsinfo: Enhance tsinfo to support several hwtstamp by net topology")
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
net/ethtool/common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ethtool/common.c b/net/ethtool/common.c
index 02f941f667dd..ec6f2e2caaf9 100644
--- a/net/ethtool/common.c
+++ b/net/ethtool/common.c
@@ -870,7 +870,7 @@ int __ethtool_get_ts_info(struct net_device *dev,
{
struct hwtstamp_provider *hwprov;
- hwprov = rtnl_dereference(dev->hwprov);
+ hwprov = rcu_dereference_rtnl(dev->hwprov);
/* No provider specified, use default behavior */
if (!hwprov) {
const struct ethtool_ops *ops = dev->ethtool_ops;
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] net: ethtool: Fix suspicious rcu_dereference usage
2024-12-17 14:03 [PATCH net-next] net: ethtool: Fix suspicious rcu_dereference usage Kory Maincent
@ 2024-12-17 15:47 ` Eric Dumazet
2024-12-17 17:17 ` Kory Maincent
0 siblings, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2024-12-17 15:47 UTC (permalink / raw)
To: Kory Maincent
Cc: David S. Miller, netdev, linux-kernel,
syzbot+a344326c05c98ba19682, thomas.petazzoni, Jakub Kicinski,
Paolo Abeni, Simon Horman
On Tue, Dec 17, 2024 at 3:03 PM Kory Maincent <kory.maincent@bootlin.com> wrote:
>
> The __ethtool_get_ts_info function can be called with or without the
> rtnl lock held. When the rtnl lock is not held, using rtnl_dereference()
> triggers a warning due to improper lock context.
>
> Replace rtnl_dereference() with rcu_dereference_rtnl() to safely
> dereference the RCU pointer in both scenarios, ensuring proper handling
> regardless of the rtnl lock state.
>
> Reported-by: syzbot+a344326c05c98ba19682@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/netdev/676147f8.050a0220.37aaf.0154.GAE@google.com/
> Fixes: b9e3f7dc9ed9 ("net: ethtool: tsinfo: Enhance tsinfo to support several hwtstamp by net topology")
> Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
> ---
> net/ethtool/common.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/ethtool/common.c b/net/ethtool/common.c
> index 02f941f667dd..ec6f2e2caaf9 100644
> --- a/net/ethtool/common.c
> +++ b/net/ethtool/common.c
> @@ -870,7 +870,7 @@ int __ethtool_get_ts_info(struct net_device *dev,
> {
> struct hwtstamp_provider *hwprov;
>
> - hwprov = rtnl_dereference(dev->hwprov);
> + hwprov = rcu_dereference_rtnl(dev->hwprov);
> /* No provider specified, use default behavior */
> if (!hwprov) {
> const struct ethtool_ops *ops = dev->ethtool_ops;
I have to ask : Can you tell how this patch has been tested ?
rcu is not held according to syzbot report.
If rtnl and rcu are not held, lockdep will still complain.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] net: ethtool: Fix suspicious rcu_dereference usage
2024-12-17 15:47 ` Eric Dumazet
@ 2024-12-17 17:17 ` Kory Maincent
2024-12-17 17:28 ` Eric Dumazet
0 siblings, 1 reply; 5+ messages in thread
From: Kory Maincent @ 2024-12-17 17:17 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S. Miller, netdev, linux-kernel,
syzbot+a344326c05c98ba19682, thomas.petazzoni, Jakub Kicinski,
Paolo Abeni, Simon Horman
On Tue, 17 Dec 2024 16:47:07 +0100
Eric Dumazet <edumazet@google.com> wrote:
> On Tue, Dec 17, 2024 at 3:03 PM Kory Maincent <kory.maincent@bootlin.com>
> wrote:
> >
> > The __ethtool_get_ts_info function can be called with or without the
> > rtnl lock held. When the rtnl lock is not held, using rtnl_dereference()
> > triggers a warning due to improper lock context.
> >
> > Replace rtnl_dereference() with rcu_dereference_rtnl() to safely
> > dereference the RCU pointer in both scenarios, ensuring proper handling
> > regardless of the rtnl lock state.
> >
> > Reported-by: syzbot+a344326c05c98ba19682@syzkaller.appspotmail.com
> > Closes:
> > https://lore.kernel.org/netdev/676147f8.050a0220.37aaf.0154.GAE@google.com/
> > Fixes: b9e3f7dc9ed9 ("net: ethtool: tsinfo: Enhance tsinfo to support
> > several hwtstamp by net topology") Signed-off-by: Kory Maincent
> > <kory.maincent@bootlin.com> --- net/ethtool/common.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/net/ethtool/common.c b/net/ethtool/common.c
> > index 02f941f667dd..ec6f2e2caaf9 100644
> > --- a/net/ethtool/common.c
> > +++ b/net/ethtool/common.c
> > @@ -870,7 +870,7 @@ int __ethtool_get_ts_info(struct net_device *dev,
> > {
> > struct hwtstamp_provider *hwprov;
> >
> > - hwprov = rtnl_dereference(dev->hwprov);
> > + hwprov = rcu_dereference_rtnl(dev->hwprov);
> > /* No provider specified, use default behavior */
> > if (!hwprov) {
> > const struct ethtool_ops *ops = dev->ethtool_ops;
>
> I have to ask : Can you tell how this patch has been tested ?
Oh, it was not at all sufficiently tested. Sorry!
I thought I had spotted the issue but I hadn't.
> rcu is not held according to syzbot report.
>
> If rtnl and rcu are not held, lockdep will still complain.
You are totally right.
I may be able to see it with the timestamping kselftest. I will try.
Regards,
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] net: ethtool: Fix suspicious rcu_dereference usage
2024-12-17 17:17 ` Kory Maincent
@ 2024-12-17 17:28 ` Eric Dumazet
2024-12-18 9:07 ` Kory Maincent
0 siblings, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2024-12-17 17:28 UTC (permalink / raw)
To: Kory Maincent
Cc: David S. Miller, netdev, linux-kernel,
syzbot+a344326c05c98ba19682, thomas.petazzoni, Jakub Kicinski,
Paolo Abeni, Simon Horman
On Tue, Dec 17, 2024 at 6:17 PM Kory Maincent <kory.maincent@bootlin.com> wrote:
>
> On Tue, 17 Dec 2024 16:47:07 +0100
> Eric Dumazet <edumazet@google.com> wrote:
>
> > On Tue, Dec 17, 2024 at 3:03 PM Kory Maincent <kory.maincent@bootlin.com>
> > wrote:
> > >
> > > The __ethtool_get_ts_info function can be called with or without the
> > > rtnl lock held. When the rtnl lock is not held, using rtnl_dereference()
> > > triggers a warning due to improper lock context.
> > >
> > > Replace rtnl_dereference() with rcu_dereference_rtnl() to safely
> > > dereference the RCU pointer in both scenarios, ensuring proper handling
> > > regardless of the rtnl lock state.
> > >
> > > Reported-by: syzbot+a344326c05c98ba19682@syzkaller.appspotmail.com
> > > Closes:
> > > https://lore.kernel.org/netdev/676147f8.050a0220.37aaf.0154.GAE@google.com/
> > > Fixes: b9e3f7dc9ed9 ("net: ethtool: tsinfo: Enhance tsinfo to support
> > > several hwtstamp by net topology") Signed-off-by: Kory Maincent
> > > <kory.maincent@bootlin.com> --- net/ethtool/common.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/net/ethtool/common.c b/net/ethtool/common.c
> > > index 02f941f667dd..ec6f2e2caaf9 100644
> > > --- a/net/ethtool/common.c
> > > +++ b/net/ethtool/common.c
> > > @@ -870,7 +870,7 @@ int __ethtool_get_ts_info(struct net_device *dev,
> > > {
> > > struct hwtstamp_provider *hwprov;
> > >
> > > - hwprov = rtnl_dereference(dev->hwprov);
> > > + hwprov = rcu_dereference_rtnl(dev->hwprov);
> > > /* No provider specified, use default behavior */
> > > if (!hwprov) {
> > > const struct ethtool_ops *ops = dev->ethtool_ops;
> >
> > I have to ask : Can you tell how this patch has been tested ?
>
> Oh, it was not at all sufficiently tested. Sorry!
> I thought I had spotted the issue but I hadn't.
>
> > rcu is not held according to syzbot report.
> >
> > If rtnl and rcu are not held, lockdep will still complain.
>
> You are totally right.
> I may be able to see it with the timestamping kselftest. I will try.
syzbot has a repro that you can compile and run.
Make sure to build and use a kernel with
CONFIG_PROVE_LOCKING=y
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] net: ethtool: Fix suspicious rcu_dereference usage
2024-12-17 17:28 ` Eric Dumazet
@ 2024-12-18 9:07 ` Kory Maincent
0 siblings, 0 replies; 5+ messages in thread
From: Kory Maincent @ 2024-12-18 9:07 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S. Miller, netdev, linux-kernel,
syzbot+a344326c05c98ba19682, thomas.petazzoni, Jakub Kicinski,
Paolo Abeni, Simon Horman
On Tue, 17 Dec 2024 18:28:16 +0100
Eric Dumazet <edumazet@google.com> wrote:
> On Tue, Dec 17, 2024 at 6:17 PM Kory Maincent <kory.maincent@bootlin.com>
> wrote:
> >
> > On Tue, 17 Dec 2024 16:47:07 +0100
> > Eric Dumazet <edumazet@google.com> wrote:
> >
> > > On Tue, Dec 17, 2024 at 3:03 PM Kory Maincent <kory.maincent@bootlin.com>
> > > wrote:
> [...]
> > >
> > > I have to ask : Can you tell how this patch has been tested ?
> >
> > Oh, it was not at all sufficiently tested. Sorry!
> > I thought I had spotted the issue but I hadn't.
> >
> > > rcu is not held according to syzbot report.
> > >
> > > If rtnl and rcu are not held, lockdep will still complain.
> >
> > You are totally right.
> > I may be able to see it with the timestamping kselftest. I will try.
>
> syzbot has a repro that you can compile and run.
Oh indeed, thanks for the pointer.
> Make sure to build and use a kernel with
>
> CONFIG_PROVE_LOCKING=y
Yes I did.
Regards,
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-12-18 9:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-17 14:03 [PATCH net-next] net: ethtool: Fix suspicious rcu_dereference usage Kory Maincent
2024-12-17 15:47 ` Eric Dumazet
2024-12-17 17:17 ` Kory Maincent
2024-12-17 17:28 ` Eric Dumazet
2024-12-18 9:07 ` Kory Maincent
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®