diff mbox series

leds: trigger: netdev: Fix kernel panic on interface rename trig notify

Message ID 20240203235413.1146-1-ansuelsmth@gmail.com
State New
Headers show
Series leds: trigger: netdev: Fix kernel panic on interface rename trig notify | expand

Commit Message

Christian Marangi Feb. 3, 2024, 11:54 p.m. UTC
Commit d5e01266e7f5 ("leds: trigger: netdev: add additional specific link
speed mode") in the various changes, reworked the way to set the LINKUP
mode in commit cee4bd16c319 ("leds: trigger: netdev: Recheck
NETDEV_LED_MODE_LINKUP on dev rename") and moved it to a generic function.

This changed the logic where, in the previous implementation the dev
from the trigger event was used to check if the carrier was ok, but in
the new implementation with the generic function, the dev in
trigger_data is used instead.

This is problematic and cause a possible kernel panic due to the fact
that the dev in the trigger_data still reference the old one as the
new one (passed from the trigger event) still has to be hold and saved
in the trigger_data struct (done in the NETDEV_REGISTER case).

On calling of get_device_state(), an invalid net_dev is used and this
cause a kernel panic.

To handle this correctly, move the call to get_device_state() after the
new net_dev is correctly set in trigger_data (in the NETDEV_REGISTER
case) and correctly parse the new dev.

Fixes: d5e01266e7f5 ("leds: trigger: netdev: add additional specific link speed mode")
Cc: stable@vger.kernel.org
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/leds/trigger/ledtrig-netdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Andrew Lunn Feb. 4, 2024, 3:15 p.m. UTC | #1
On Sun, Feb 04, 2024 at 12:54:01AM +0100, Christian Marangi wrote:
> Commit d5e01266e7f5 ("leds: trigger: netdev: add additional specific link
> speed mode") in the various changes, reworked the way to set the LINKUP
> mode in commit cee4bd16c319 ("leds: trigger: netdev: Recheck
> NETDEV_LED_MODE_LINKUP on dev rename") and moved it to a generic function.
> 
> This changed the logic where, in the previous implementation the dev
> from the trigger event was used to check if the carrier was ok, but in
> the new implementation with the generic function, the dev in
> trigger_data is used instead.
> 
> This is problematic and cause a possible kernel panic due to the fact
> that the dev in the trigger_data still reference the old one as the
> new one (passed from the trigger event) still has to be hold and saved
> in the trigger_data struct (done in the NETDEV_REGISTER case).
> 
> On calling of get_device_state(), an invalid net_dev is used and this
> cause a kernel panic.
> 
> To handle this correctly, move the call to get_device_state() after the
> new net_dev is correctly set in trigger_data (in the NETDEV_REGISTER
> case) and correctly parse the new dev.
> 
> Fixes: d5e01266e7f5 ("leds: trigger: netdev: add additional specific link speed mode")
> Cc: stable@vger.kernel.org
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>

This should have 'net' in the subject line, to indicate which tree its
for.

Otherwise:

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
Lee Jones Feb. 5, 2024, 8:50 a.m. UTC | #2
On Sun, 04 Feb 2024, Andrew Lunn wrote:

> On Sun, Feb 04, 2024 at 12:54:01AM +0100, Christian Marangi wrote:
> > Commit d5e01266e7f5 ("leds: trigger: netdev: add additional specific link
> > speed mode") in the various changes, reworked the way to set the LINKUP
> > mode in commit cee4bd16c319 ("leds: trigger: netdev: Recheck
> > NETDEV_LED_MODE_LINKUP on dev rename") and moved it to a generic function.
> > 
> > This changed the logic where, in the previous implementation the dev
> > from the trigger event was used to check if the carrier was ok, but in
> > the new implementation with the generic function, the dev in
> > trigger_data is used instead.
> > 
> > This is problematic and cause a possible kernel panic due to the fact
> > that the dev in the trigger_data still reference the old one as the
> > new one (passed from the trigger event) still has to be hold and saved
> > in the trigger_data struct (done in the NETDEV_REGISTER case).
> > 
> > On calling of get_device_state(), an invalid net_dev is used and this
> > cause a kernel panic.
> > 
> > To handle this correctly, move the call to get_device_state() after the
> > new net_dev is correctly set in trigger_data (in the NETDEV_REGISTER
> > case) and correctly parse the new dev.
> > 
> > Fixes: d5e01266e7f5 ("leds: trigger: netdev: add additional specific link speed mode")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> 
> This should have 'net' in the subject line, to indicate which tree its
> for.

No, it shouldn't.

Contributors aren't obliged to know anything about merging strategies.

Why does this need to go in via net?

> Otherwise:
> 
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>

Thanks.  Always very useful.
Andrew Lunn Feb. 5, 2024, 1:41 p.m. UTC | #3
> > This should have 'net' in the subject line, to indicate which tree its
> > for.
> 
> No, it shouldn't.
> 
> Contributors aren't obliged to know anything about merging strategies.

With netdev, we tend to assume they do, or at least can contribute to
the discussion. They often know about any dependencies etc which could
influence the decision. When there are multiple subsystem maintainers
involved, i tend to use To: to indicate the maintainer i think should
merge the patch, and Cc: for the rest.

> Why does this need to go in via net?

It does not, as far as i'm aware. Christian, do you know of any
reason?

	Andrew
Christian Marangi Feb. 5, 2024, 1:53 p.m. UTC | #4
On Mon, Feb 05, 2024 at 02:41:46PM +0100, Andrew Lunn wrote:
> > > This should have 'net' in the subject line, to indicate which tree its
> > > for.
> > 
> > No, it shouldn't.
> > 
> > Contributors aren't obliged to know anything about merging strategies.
> 
> With netdev, we tend to assume they do, or at least can contribute to
> the discussion. They often know about any dependencies etc which could
> influence the decision. When there are multiple subsystem maintainers
> involved, i tend to use To: to indicate the maintainer i think should
> merge the patch, and Cc: for the rest.
>

I'm always a bit confused when I have to send patch to mixed subsystem
(not the case but for net trigger it's almost that). Sorry for the
confusion/noise.

> > Why does this need to go in via net?
> 
> It does not, as far as i'm aware. Christian, do you know of any
> reason?
> 

This is strictly a fix, no dependency or anything like that. Maybe using
net as target would make this faster to merge (since net is for fix only
and this has to be backported) than using leds-next?

Again if needed I can send v2 with the correct tag for net subsystem if
better.
Lee Jones Feb. 5, 2024, 2:27 p.m. UTC | #5
On Mon, 05 Feb 2024, Andrew Lunn wrote:

> > > This should have 'net' in the subject line, to indicate which tree its
> > > for.
> > 
> > No, it shouldn't.
> > 
> > Contributors aren't obliged to know anything about merging strategies.
> 
> With netdev, we tend to assume they do, or at least can contribute to
> the discussion. They often know about any dependencies etc which could
> influence the decision. When there are multiple subsystem maintainers
> involved, i tend to use To: to indicate the maintainer i think should
> merge the patch, and Cc: for the rest.

This isn't a netdev patch. :)

We make no such stipulation for any of the subsystems I maintain.

The subject line should indicate which subsystem the commit pertains to,
not which maintainer will merge it or which tree it's merged via.  In
this case, it's drivers/leds, so "leds: " is fine.

> > Why does this need to go in via net?
> 
> It does not, as far as i'm aware. Christian, do you know of any
> reason?

It's pretty early in the cycle and there are no cross-subsystem deps
yet, as far as I'm aware.
Lee Jones Feb. 5, 2024, 2:33 p.m. UTC | #6
On Mon, 05 Feb 2024, Christian Marangi wrote:

> On Mon, Feb 05, 2024 at 02:41:46PM +0100, Andrew Lunn wrote:
> > > > This should have 'net' in the subject line, to indicate which tree its
> > > > for.
> > > 
> > > No, it shouldn't.
> > > 
> > > Contributors aren't obliged to know anything about merging strategies.
> > 
> > With netdev, we tend to assume they do, or at least can contribute to
> > the discussion. They often know about any dependencies etc which could
> > influence the decision. When there are multiple subsystem maintainers
> > involved, i tend to use To: to indicate the maintainer i think should
> > merge the patch, and Cc: for the rest.
> >
> 
> I'm always a bit confused when I have to send patch to mixed subsystem
> (not the case but for net trigger it's almost that). Sorry for the
> confusion/noise.

When you have a truly cross-subsystem patch, it's up to you.

 - Mention both e.g. leds/net:
 - Mention neither e.g. <device>:
 - Mention the one that is most relevant

 An example of the last option might be when the lion's share of the
 changes occur in one subsystem and only header files are changed in the
 other.

In an ideal world i.e. when there are no build-time/runtime deps between
them, changes should be separated out into their own commits.

> > > Why does this need to go in via net?
> > 
> > It does not, as far as i'm aware. Christian, do you know of any
> > reason?
> > 
> 
> This is strictly a fix, no dependency or anything like that. Maybe using
> net as target would make this faster to merge (since net is for fix only
> and this has to be backported) than using leds-next?

We have leds-fixes for that.
Christian Marangi Feb. 5, 2024, 2:38 p.m. UTC | #7
On Mon, Feb 05, 2024 at 02:33:59PM +0000, Lee Jones wrote:
> On Mon, 05 Feb 2024, Christian Marangi wrote:
> 
> > On Mon, Feb 05, 2024 at 02:41:46PM +0100, Andrew Lunn wrote:
> > > > > This should have 'net' in the subject line, to indicate which tree its
> > > > > for.
> > > > 
> > > > No, it shouldn't.
> > > > 
> > > > Contributors aren't obliged to know anything about merging strategies.
> > > 
> > > With netdev, we tend to assume they do, or at least can contribute to
> > > the discussion. They often know about any dependencies etc which could
> > > influence the decision. When there are multiple subsystem maintainers
> > > involved, i tend to use To: to indicate the maintainer i think should
> > > merge the patch, and Cc: for the rest.
> > >
> > 
> > I'm always a bit confused when I have to send patch to mixed subsystem
> > (not the case but for net trigger it's almost that). Sorry for the
> > confusion/noise.
> 
> When you have a truly cross-subsystem patch, it's up to you.
> 
>  - Mention both e.g. leds/net:
>  - Mention neither e.g. <device>:
>  - Mention the one that is most relevant
> 
>  An example of the last option might be when the lion's share of the
>  changes occur in one subsystem and only header files are changed in the
>  other.
> 
> In an ideal world i.e. when there are no build-time/runtime deps between
> them, changes should be separated out into their own commits.
>

Thanks a lot for the explaination and the examples!

> > > > Why does this need to go in via net?
> > > 
> > > It does not, as far as i'm aware. Christian, do you know of any
> > > reason?
> > > 
> > 
> > This is strictly a fix, no dependency or anything like that. Maybe using
> > net as target would make this faster to merge (since net is for fix only
> > and this has to be backported) than using leds-next?
> 
> We have leds-fixes for that.
>

Oh! No idea, should I add a tag to the patch to target that branch
specifically?

Anyway Since we have leds-fixes and this is leds related I think it's ok
to use that and don't disturb net subsystem.

(again IT IS a kernel panic but happens only on some specific situation
so it's not that critical)
Lee Jones Feb. 5, 2024, 3:04 p.m. UTC | #8
On Mon, 05 Feb 2024, Christian Marangi wrote:

> On Mon, Feb 05, 2024 at 02:33:59PM +0000, Lee Jones wrote:
> > On Mon, 05 Feb 2024, Christian Marangi wrote:
> > 
> > > On Mon, Feb 05, 2024 at 02:41:46PM +0100, Andrew Lunn wrote:
> > > > > > This should have 'net' in the subject line, to indicate which tree its
> > > > > > for.
> > > > > 
> > > > > No, it shouldn't.
> > > > > 
> > > > > Contributors aren't obliged to know anything about merging strategies.
> > > > 
> > > > With netdev, we tend to assume they do, or at least can contribute to
> > > > the discussion. They often know about any dependencies etc which could
> > > > influence the decision. When there are multiple subsystem maintainers
> > > > involved, i tend to use To: to indicate the maintainer i think should
> > > > merge the patch, and Cc: for the rest.
> > > >
> > > 
> > > I'm always a bit confused when I have to send patch to mixed subsystem
> > > (not the case but for net trigger it's almost that). Sorry for the
> > > confusion/noise.
> > 
> > When you have a truly cross-subsystem patch, it's up to you.
> > 
> >  - Mention both e.g. leds/net:
> >  - Mention neither e.g. <device>:
> >  - Mention the one that is most relevant
> > 
> >  An example of the last option might be when the lion's share of the
> >  changes occur in one subsystem and only header files are changed in the
> >  other.
> > 
> > In an ideal world i.e. when there are no build-time/runtime deps between
> > them, changes should be separated out into their own commits.
> >
> 
> Thanks a lot for the explaination and the examples!
> 
> > > > > Why does this need to go in via net?
> > > > 
> > > > It does not, as far as i'm aware. Christian, do you know of any
> > > > reason?
> > > > 
> > > 
> > > This is strictly a fix, no dependency or anything like that. Maybe using
> > > net as target would make this faster to merge (since net is for fix only
> > > and this has to be backported) than using leds-next?
> > 
> > We have leds-fixes for that.
> >
> 
> Oh! No idea, should I add a tag to the patch to target that branch
> specifically?

You don't need to do anything special.

The Fixes: tag is enough to let us know that this is a fix.

If the commit mentioned in Fixes: was accepted as part of the last
merge-window, it'll be sent to the -rcs in good time.  If it fixes a
commit which was introduced in a previous cycle, it'll be submitted
during the next merge-window.

> Anyway Since we have leds-fixes and this is leds related I think it's ok
> to use that and don't disturb net subsystem.

There is no reason why this should be merged via netdev.

> (again IT IS a kernel panic but happens only on some specific situation
> so it's not that critical)
Lee Jones Feb. 8, 2024, 2:04 p.m. UTC | #9
On Sun, 04 Feb 2024 00:54:01 +0100, Christian Marangi wrote:
> Commit d5e01266e7f5 ("leds: trigger: netdev: add additional specific link
> speed mode") in the various changes, reworked the way to set the LINKUP
> mode in commit cee4bd16c319 ("leds: trigger: netdev: Recheck
> NETDEV_LED_MODE_LINKUP on dev rename") and moved it to a generic function.
> 
> This changed the logic where, in the previous implementation the dev
> from the trigger event was used to check if the carrier was ok, but in
> the new implementation with the generic function, the dev in
> trigger_data is used instead.
> 
> [...]

Applied, thanks!

[1/1] leds: trigger: netdev: Fix kernel panic on interface rename trig notify
      commit: db36d7d45d191879ec4dd1535fbf04ee4ac28711

--
Lee Jones [李琼斯]
Lee Jones Feb. 8, 2024, 2:12 p.m. UTC | #10
On Mon, 05 Feb 2024, Lee Jones wrote:

> On Mon, 05 Feb 2024, Christian Marangi wrote:
> 
> > On Mon, Feb 05, 2024 at 02:33:59PM +0000, Lee Jones wrote:
> > > On Mon, 05 Feb 2024, Christian Marangi wrote:
> > > 
> > > > On Mon, Feb 05, 2024 at 02:41:46PM +0100, Andrew Lunn wrote:
> > > > > > > This should have 'net' in the subject line, to indicate which tree its
> > > > > > > for.
> > > > > > 
> > > > > > No, it shouldn't.
> > > > > > 
> > > > > > Contributors aren't obliged to know anything about merging strategies.
> > > > > 
> > > > > With netdev, we tend to assume they do, or at least can contribute to
> > > > > the discussion. They often know about any dependencies etc which could
> > > > > influence the decision. When there are multiple subsystem maintainers
> > > > > involved, i tend to use To: to indicate the maintainer i think should
> > > > > merge the patch, and Cc: for the rest.
> > > > >
> > > > 
> > > > I'm always a bit confused when I have to send patch to mixed subsystem
> > > > (not the case but for net trigger it's almost that). Sorry for the
> > > > confusion/noise.
> > > 
> > > When you have a truly cross-subsystem patch, it's up to you.
> > > 
> > >  - Mention both e.g. leds/net:
> > >  - Mention neither e.g. <device>:
> > >  - Mention the one that is most relevant
> > > 
> > >  An example of the last option might be when the lion's share of the
> > >  changes occur in one subsystem and only header files are changed in the
> > >  other.
> > > 
> > > In an ideal world i.e. when there are no build-time/runtime deps between
> > > them, changes should be separated out into their own commits.
> > >
> > 
> > Thanks a lot for the explaination and the examples!
> > 
> > > > > > Why does this need to go in via net?
> > > > > 
> > > > > It does not, as far as i'm aware. Christian, do you know of any
> > > > > reason?
> > > > > 
> > > > 
> > > > This is strictly a fix, no dependency or anything like that. Maybe using
> > > > net as target would make this faster to merge (since net is for fix only
> > > > and this has to be backported) than using leds-next?
> > > 
> > > We have leds-fixes for that.
> > >
> > 
> > Oh! No idea, should I add a tag to the patch to target that branch
> > specifically?
> 
> You don't need to do anything special.
> 
> The Fixes: tag is enough to let us know that this is a fix.
> 
> If the commit mentioned in Fixes: was accepted as part of the last
> merge-window, it'll be sent to the -rcs in good time.  If it fixes a
> commit which was introduced in a previous cycle, it'll be submitted
> during the next merge-window.

Since this patch fixes an issue that was incorporated into v6.4, we
shall not be submitting this for the v6.8-rcs.  Instead it's heading for
the v6.9 merge-window and will be backported to v6.6.y accordingly.
diff mbox series

Patch

diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c
index 8e5475819590..df1b1d8468e6 100644
--- a/drivers/leds/trigger/ledtrig-netdev.c
+++ b/drivers/leds/trigger/ledtrig-netdev.c
@@ -504,12 +504,12 @@  static int netdev_trig_notify(struct notifier_block *nb,
 	trigger_data->duplex = DUPLEX_UNKNOWN;
 	switch (evt) {
 	case NETDEV_CHANGENAME:
-		get_device_state(trigger_data);
-		fallthrough;
 	case NETDEV_REGISTER:
 		dev_put(trigger_data->net_dev);
 		dev_hold(dev);
 		trigger_data->net_dev = dev;
+		if (evt == NETDEV_CHANGENAME)
+			get_device_state(trigger_data);
 		break;
 	case NETDEV_UNREGISTER:
 		dev_put(trigger_data->net_dev);