* [PATCH v1 net] net: macb: Use rcu_dereference() for idev->ifa_list in macb_suspend().
@ 2024-08-08 4:00 Kuniyuki Iwashima
2024-08-08 4:23 ` Vineeth Karumanchi
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Kuniyuki Iwashima @ 2024-08-08 4:00 UTC (permalink / raw)
To: Nicolas Ferre, Claudiu Beznea, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: Vineeth Karumanchi, Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
In macb_suspend(), idev->ifa_list is fetched with rcu_access_pointer()
and later the pointer is dereferenced as ifa->ifa_local.
So, idev->ifa_list must be fetched with rcu_dereference().
Fixes: 0cb8de39a776 ("net: macb: Add ARP support to WOL")
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
drivers/net/ethernet/cadence/macb_main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 11665be3a22c..dcd3f54ed0cf 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -5250,8 +5250,8 @@ static int __maybe_unused macb_suspend(struct device *dev)
if (bp->wol & MACB_WOL_ENABLED) {
/* Check for IP address in WOL ARP mode */
idev = __in_dev_get_rcu(bp->dev);
- if (idev && idev->ifa_list)
- ifa = rcu_access_pointer(idev->ifa_list);
+ if (idev)
+ ifa = rcu_dereference(idev->ifa_list);
if ((bp->wolopts & WAKE_ARP) && !ifa) {
netdev_err(netdev, "IP address not assigned as required by WoL walk ARP\n");
return -EOPNOTSUPP;
--
2.30.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v1 net] net: macb: Use rcu_dereference() for idev->ifa_list in macb_suspend().
2024-08-08 4:00 [PATCH v1 net] net: macb: Use rcu_dereference() for idev->ifa_list in macb_suspend() Kuniyuki Iwashima
@ 2024-08-08 4:23 ` Vineeth Karumanchi
2024-08-08 4:45 ` Kuniyuki Iwashima
2024-08-13 1:40 ` Jakub Kicinski
2024-08-13 1:50 ` patchwork-bot+netdevbpf
2 siblings, 1 reply; 7+ messages in thread
From: Vineeth Karumanchi @ 2024-08-08 4:23 UTC (permalink / raw)
To: Kuniyuki Iwashima, Nicolas Ferre, Claudiu Beznea, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Kuniyuki Iwashima, netdev
Hi Kuniyuki,
On 08/08/24 9:30 am, Kuniyuki Iwashima wrote:
> In macb_suspend(), idev->ifa_list is fetched with rcu_access_pointer()
> and later the pointer is dereferenced as ifa->ifa_local.
>
> So, idev->ifa_list must be fetched with rcu_dereference().
>
Is there any functional breakage ?
I sent initial patch with rcu_dereference, but there is a review comment:
https://lore.kernel.org/netdev/a02fac3b21a97dc766d65c4ed2d080f1ed87e87e.camel@redhat.com/
🙏 vineeth
> Fixes: 0cb8de39a776 ("net: macb: Add ARP support to WOL")
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
> ---
> drivers/net/ethernet/cadence/macb_main.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index 11665be3a22c..dcd3f54ed0cf 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -5250,8 +5250,8 @@ static int __maybe_unused macb_suspend(struct device *dev)
> if (bp->wol & MACB_WOL_ENABLED) {
> /* Check for IP address in WOL ARP mode */
> idev = __in_dev_get_rcu(bp->dev);
> - if (idev && idev->ifa_list)
> - ifa = rcu_access_pointer(idev->ifa_list);
> + if (idev)
> + ifa = rcu_dereference(idev->ifa_list);
> if ((bp->wolopts & WAKE_ARP) && !ifa) {
> netdev_err(netdev, "IP address not assigned as required by WoL walk ARP\n");
> return -EOPNOTSUPP;
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 net] net: macb: Use rcu_dereference() for idev->ifa_list in macb_suspend().
2024-08-08 4:23 ` Vineeth Karumanchi
@ 2024-08-08 4:45 ` Kuniyuki Iwashima
2024-08-12 9:11 ` Vineeth Karumanchi
0 siblings, 1 reply; 7+ messages in thread
From: Kuniyuki Iwashima @ 2024-08-08 4:45 UTC (permalink / raw)
To: vineeth.karumanchi
Cc: claudiu.beznea, davem, edumazet, kuba, kuni1840, kuniyu, netdev,
nicolas.ferre, pabeni
From: Vineeth Karumanchi <vineeth.karumanchi@amd.com>
Date: Thu, 8 Aug 2024 09:53:42 +0530
> Hi Kuniyuki,
>
> On 08/08/24 9:30 am, Kuniyuki Iwashima wrote:
> > In macb_suspend(), idev->ifa_list is fetched with rcu_access_pointer()
> > and later the pointer is dereferenced as ifa->ifa_local.
> >
> > So, idev->ifa_list must be fetched with rcu_dereference().
> >
>
> Is there any functional breakage ?
rcu_dereference() triggers lockdep splat if not called under
rcu_read_lock().
Also in include/linux/rcupdate.h:
/**
* rcu_access_pointer() - fetch RCU pointer with no dereferencing
...
* It is usually best to test the rcu_access_pointer() return value
* directly in order to avoid accidental dereferences being introduced
* by later inattentive changes. In other words, assigning the
* rcu_access_pointer() return value to a local variable results in an
* accident waiting to happen.
> I sent initial patch with rcu_dereference, but there is a review comment:
>
> https://lore.kernel.org/netdev/a02fac3b21a97dc766d65c4ed2d080f1ed87e87e.camel@redhat.com/
I guess the following ifa_local was missed then ?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 net] net: macb: Use rcu_dereference() for idev->ifa_list in macb_suspend().
2024-08-08 4:45 ` Kuniyuki Iwashima
@ 2024-08-12 9:11 ` Vineeth Karumanchi
2024-08-12 18:35 ` Kuniyuki Iwashima
0 siblings, 1 reply; 7+ messages in thread
From: Vineeth Karumanchi @ 2024-08-12 9:11 UTC (permalink / raw)
To: Kuniyuki Iwashima
Cc: claudiu.beznea, davem, edumazet, kuba, kuni1840, netdev,
nicolas.ferre, pabeni
On 08/08/24 10:15 am, Kuniyuki Iwashima wrote:
> From: Vineeth Karumanchi <vineeth.karumanchi@amd.com>
> Date: Thu, 8 Aug 2024 09:53:42 +0530
>> Hi Kuniyuki,
>>
>> On 08/08/24 9:30 am, Kuniyuki Iwashima wrote:
>>> In macb_suspend(), idev->ifa_list is fetched with rcu_access_pointer()
>>> and later the pointer is dereferenced as ifa->ifa_local.
>>>
>>> So, idev->ifa_list must be fetched with rcu_dereference().
>>>
>>
>> Is there any functional breakage ?
>
> rcu_dereference() triggers lockdep splat if not called under
> rcu_read_lock().
>
> Also in include/linux/rcupdate.h:
>
> /**
> * rcu_access_pointer() - fetch RCU pointer with no dereferencing
> ...
> * It is usually best to test the rcu_access_pointer() return value
> * directly in order to avoid accidental dereferences being introduced
> * by later inattentive changes. In other words, assigning the
> * rcu_access_pointer() return value to a local variable results in an
> * accident waiting to happen.
>
>
>> I sent initial patch with rcu_dereference, but there is a review comment:
>>
>> https://lore.kernel.org/netdev/a02fac3b21a97dc766d65c4ed2d080f1ed87e87e.camel@redhat.com/
>
> I guess the following ifa_local was missed then ?
I am ok to use rcu_dereference(), just curios why the check
idev->ifa_list was removed ?
vineeth
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 net] net: macb: Use rcu_dereference() for idev->ifa_list in macb_suspend().
2024-08-12 9:11 ` Vineeth Karumanchi
@ 2024-08-12 18:35 ` Kuniyuki Iwashima
0 siblings, 0 replies; 7+ messages in thread
From: Kuniyuki Iwashima @ 2024-08-12 18:35 UTC (permalink / raw)
To: vineeth.karumanchi
Cc: claudiu.beznea, davem, edumazet, kuba, kuni1840, kuniyu, netdev,
nicolas.ferre, pabeni
From: Vineeth Karumanchi <vineeth.karumanchi@amd.com>
Date: Mon, 12 Aug 2024 14:41:40 +0530
> On 08/08/24 10:15 am, Kuniyuki Iwashima wrote:
> > From: Vineeth Karumanchi <vineeth.karumanchi@amd.com>
> > Date: Thu, 8 Aug 2024 09:53:42 +0530
> >> Hi Kuniyuki,
> >>
> >> On 08/08/24 9:30 am, Kuniyuki Iwashima wrote:
> >>> In macb_suspend(), idev->ifa_list is fetched with rcu_access_pointer()
> >>> and later the pointer is dereferenced as ifa->ifa_local.
> >>>
> >>> So, idev->ifa_list must be fetched with rcu_dereference().
> >>>
> >>
> >> Is there any functional breakage ?
> >
> > rcu_dereference() triggers lockdep splat if not called under
> > rcu_read_lock().
> >
> > Also in include/linux/rcupdate.h:
> >
> > /**
> > * rcu_access_pointer() - fetch RCU pointer with no dereferencing
> > ...
> > * It is usually best to test the rcu_access_pointer() return value
> > * directly in order to avoid accidental dereferences being introduced
> > * by later inattentive changes. In other words, assigning the
> > * rcu_access_pointer() return value to a local variable results in an
> > * accident waiting to happen.
> >
> >
> >> I sent initial patch with rcu_dereference, but there is a review comment:
> >>
> >> https://lore.kernel.org/netdev/a02fac3b21a97dc766d65c4ed2d080f1ed87e87e.camel@redhat.com/
> >
> > I guess the following ifa_local was missed then ?
>
> I am ok to use rcu_dereference(), just curios why the check
> idev->ifa_list was removed ?
"if (idev->ifa_list)" could fetch an invalid pointer due to lack of
READ_ONCE(), it's not a big problem, but neither we should write it as
if (rcu_assign_pointer(idev->ifa_list))
ifa = rcu_dereference(idev->ifa_list)
because rcu_dereference()ed ifa is not guaranteed as the same value
(non-NULL) with rcu_assign_pointer(), so we need the following check
anyway:
if (!ifa)
Basically, we can't use rcu_assign_pointer() with rcu_dereference().
list_first_or_null_rcu() is a nice example:
include/linux/rculist.h
/*
* Where are list_empty_rcu() and list_first_entry_rcu()?
*
* They do not exist because they would lead to subtle race conditions:
*
* if (!list_empty_rcu(mylist)) {
* struct foo *bar = list_first_entry_rcu(mylist, struct foo, list_member);
* do_something(bar);
* }
*
* The list might be non-empty when list_empty_rcu() checks it, but it
* might have become empty by the time that list_first_entry_rcu() rereads
* the ->next pointer, which would result in a SEGV.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 net] net: macb: Use rcu_dereference() for idev->ifa_list in macb_suspend().
2024-08-08 4:00 [PATCH v1 net] net: macb: Use rcu_dereference() for idev->ifa_list in macb_suspend() Kuniyuki Iwashima
2024-08-08 4:23 ` Vineeth Karumanchi
@ 2024-08-13 1:40 ` Jakub Kicinski
2024-08-13 1:50 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 7+ messages in thread
From: Jakub Kicinski @ 2024-08-13 1:40 UTC (permalink / raw)
To: Kuniyuki Iwashima
Cc: Nicolas Ferre, Claudiu Beznea, David S. Miller, Eric Dumazet,
Paolo Abeni, Vineeth Karumanchi, Kuniyuki Iwashima, netdev
On Wed, 7 Aug 2024 21:00:21 -0700 Kuniyuki Iwashima wrote:
> In macb_suspend(), idev->ifa_list is fetched with rcu_access_pointer()
> and later the pointer is dereferenced as ifa->ifa_local.
>
> So, idev->ifa_list must be fetched with rcu_dereference().
I don't see where this driver takes rcu_read_lock, but
__in_dev_get_rcu() will already splat so we're not making
it any worse.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 net] net: macb: Use rcu_dereference() for idev->ifa_list in macb_suspend().
2024-08-08 4:00 [PATCH v1 net] net: macb: Use rcu_dereference() for idev->ifa_list in macb_suspend() Kuniyuki Iwashima
2024-08-08 4:23 ` Vineeth Karumanchi
2024-08-13 1:40 ` Jakub Kicinski
@ 2024-08-13 1:50 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-08-13 1:50 UTC (permalink / raw)
To: Kuniyuki Iwashima
Cc: nicolas.ferre, claudiu.beznea, davem, edumazet, kuba, pabeni,
vineeth.karumanchi, kuni1840, netdev
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Wed, 7 Aug 2024 21:00:21 -0700 you wrote:
> In macb_suspend(), idev->ifa_list is fetched with rcu_access_pointer()
> and later the pointer is dereferenced as ifa->ifa_local.
>
> So, idev->ifa_list must be fetched with rcu_dereference().
>
> Fixes: 0cb8de39a776 ("net: macb: Add ARP support to WOL")
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
>
> [...]
Here is the summary with links:
- [v1,net] net: macb: Use rcu_dereference() for idev->ifa_list in macb_suspend().
https://git.kernel.org/netdev/net/c/6e1918ff6805
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] 7+ messages in thread
end of thread, other threads:[~2024-08-13 1:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-08 4:00 [PATCH v1 net] net: macb: Use rcu_dereference() for idev->ifa_list in macb_suspend() Kuniyuki Iwashima
2024-08-08 4:23 ` Vineeth Karumanchi
2024-08-08 4:45 ` Kuniyuki Iwashima
2024-08-12 9:11 ` Vineeth Karumanchi
2024-08-12 18:35 ` Kuniyuki Iwashima
2024-08-13 1:40 ` Jakub Kicinski
2024-08-13 1:50 ` 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).