From: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
To: Eric Dumazet <edumazet@google.com>
Cc: "David S. Miller" <davem@davemloft.net>,
David Ahern <dsahern@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Taehee Yoo <ap420073@gmail.com>, <netdev@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
<syzbot+a9400cabb1d784e49abf@syzkaller.appspotmail.com>
Subject: Re: [PATCH net] ipv6: mcast: fix data-race in ipv6_mc_down / mld_ifc_work
Date: Thu, 18 Jan 2024 05:04:30 -0800 [thread overview]
Message-ID: <549c658e-28a0-4e6c-be09-95ba748410b7@fintech.ru> (raw)
In-Reply-To: <CANn89iLUxP_YGLD1mrCmAr9qSg7wPWDjWPhJHNa_X4QVyNWqBQ@mail.gmail.com>
Hello,
On 1/18/24 00:59, Eric Dumazet wrote:
> On Wed, Jan 17, 2024 at 6:21 PM Nikita Zhandarovich
> <n.zhandarovich@fintech.ru> wrote:
>>
>> idev->mc_ifc_count can be written over without proper locking.
>>
>> Originally found by syzbot [1], fix this issue by encapsulating calls
>> to mld_ifc_stop_work() (and mld_gq_stop_work() for good measure) with
>> mutex_lock() and mutex_unlock() accordingly as these functions
>> should only be called with mc_lock per their declarations.
>>
>> [1]
>> BUG: KCSAN: data-race in ipv6_mc_down / mld_ifc_work
>>
>> Fixes: 2d9a93b4902b ("mld: convert from timer to delayed work")
>> Reported-by: syzbot+a9400cabb1d784e49abf@syzkaller.appspotmail.com
>> Link: https://lore.kernel.org/all/000000000000994e09060ebcdffb@google.com/
>> Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
>> ---
>> net/ipv6/mcast.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>>
>> diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
>> index b75d3c9d41bb..bc6e0a0bad3c 100644
>> --- a/net/ipv6/mcast.c
>> +++ b/net/ipv6/mcast.c
>> @@ -2722,8 +2722,12 @@ void ipv6_mc_down(struct inet6_dev *idev)
>> synchronize_net();
>> mld_query_stop_work(idev);
>> mld_report_stop_work(idev);
>> +
>> + mutex_lock(&idev->mc_lock);
>> mld_ifc_stop_work(idev);
>> mld_gq_stop_work(idev);
>> + mutex_unlock(&idev->mc_lock);
>> +
>> mld_dad_stop_work(idev);
>> }
>>
>
> Thanks for the fix.
>
> Reviewed-by: Eric Dumazet <edumazet@google.com>
>
> I would also add some lockdep_assert_held() to make sure assumptions are met.
> Trading a comment for a runtime check is better.
>
> diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
> index b75d3c9d41bb5005af2d4e10fab58f157e9ea4fa..b256362d3b5d5111f649ebfee4f1557d8c063d92
> 100644
> --- a/net/ipv6/mcast.c
> +++ b/net/ipv6/mcast.c
> @@ -1047,36 +1047,36 @@ bool ipv6_chk_mcast_addr(struct net_device
> *dev, const struct in6_addr *group,
> return rv;
> }
>
> -/* called with mc_lock */
> static void mld_gq_start_work(struct inet6_dev *idev)
> {
> unsigned long tv = get_random_u32_below(idev->mc_maxdelay);
>
> + lockdep_assert_held(&idev->mc_lock);
> idev->mc_gq_running = 1;
> if (!mod_delayed_work(mld_wq, &idev->mc_gq_work, tv + 2))
> in6_dev_hold(idev);
> }
>
> -/* called with mc_lock */
> static void mld_gq_stop_work(struct inet6_dev *idev)
> {
> + lockdep_assert_held(&idev->mc_lock);
> idev->mc_gq_running = 0;
> if (cancel_delayed_work(&idev->mc_gq_work))
> __in6_dev_put(idev);
> }
>
> -/* called with mc_lock */
> static void mld_ifc_start_work(struct inet6_dev *idev, unsigned long delay)
> {
> unsigned long tv = get_random_u32_below(delay);
>
> + lockdep_assert_held(&idev->mc_lock);
> if (!mod_delayed_work(mld_wq, &idev->mc_ifc_work, tv + 2))
> in6_dev_hold(idev);
> }
>
> -/* called with mc_lock */
> static void mld_ifc_stop_work(struct inet6_dev *idev)
> {
> + lockdep_assert_held(&idev->mc_lock);
> idev->mc_ifc_count = 0;
> if (cancel_delayed_work(&idev->mc_ifc_work))
> __in6_dev_put(idev);
Just to clarify: should I incorporate your change into v2 version of my
original one and attach 'Reviewed-by' tags or should I send a different
patch with your suggestion?
Apologies for the possibly silly question, got a little confused by
signals from multiple maintainers.
With regards,
Nikita
next prev parent reply other threads:[~2024-01-18 13:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-17 17:21 Nikita Zhandarovich
2024-01-18 2:45 ` Hangbin Liu
2024-01-18 7:24 ` Taehee Yoo
2024-01-18 9:55 ` Hangbin Liu
2024-01-18 7:11 ` Taehee Yoo
2024-01-18 8:59 ` Eric Dumazet
2024-01-18 13:04 ` Nikita Zhandarovich [this message]
2024-01-18 13:28 ` Eric Dumazet
2024-01-18 9:56 ` Hangbin Liu
2024-01-18 18:00 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=549c658e-28a0-4e6c-be09-95ba748410b7@fintech.ru \
--to=n.zhandarovich@fintech.ru \
--cc=ap420073@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=syzbot+a9400cabb1d784e49abf@syzkaller.appspotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®