linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] ipv4: add iPv4_is_multicast() check in ip_mc_leave_group().
@ 2021-01-17 13:34 wangyingjie55
  2021-01-19  4:39 ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: wangyingjie55 @ 2021-01-17 13:34 UTC (permalink / raw)
  To: davem, kuznet, yoshfuji, kuba; +Cc: netdev, linux-kernel, wangyingjie55

From: Yingjie Wang <wangyingjie55@126.com>

There is no iPv4_is_multicast() check added to ip_mc_leave_group()
to check if imr->imr_multiaddr.s_addr is a multicast address.
If not a multicast address, it may result in an error.
In some cases, the callers of ip_mc_leave_group() don't check
whether it is multicast address or not before calling
such as do_ip_setsockopt(). So I suggest adding the ipv4_is_multicast()
check to the ip_mc_leave_group() to prevent this from happening.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Yingjie Wang <wangyingjie55@126.com>
---
 net/ipv4/igmp.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index 7b272bbed2b4..1b6f91271cfd 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -2248,6 +2248,9 @@ int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr)
 	u32 ifindex;
 	int ret = -EADDRNOTAVAIL;
 
+	if (!ipv4_is_multicast(group))
+		return -EINVAL;
+
 	ASSERT_RTNL();
 
 	in_dev = ip_mc_find_dev(net, imr);
-- 
2.7.4


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

* Re: [PATCH v1] ipv4: add iPv4_is_multicast() check in ip_mc_leave_group().
  2021-01-17 13:34 [PATCH v1] ipv4: add iPv4_is_multicast() check in ip_mc_leave_group() wangyingjie55
@ 2021-01-19  4:39 ` Jakub Kicinski
  2021-01-19 10:28   ` Nikolay Aleksandrov
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2021-01-19  4:39 UTC (permalink / raw)
  To: wangyingjie55
  Cc: davem, kuznet, yoshfuji, netdev, linux-kernel, Nikolay Aleksandrov

On Sun, 17 Jan 2021 05:34:16 -0800 wangyingjie55@126.com wrote:
> From: Yingjie Wang <wangyingjie55@126.com>
> 
> There is no iPv4_is_multicast() check added to ip_mc_leave_group()
> to check if imr->imr_multiaddr.s_addr is a multicast address.
> If not a multicast address, it may result in an error.

Could you please say more? From looking at the code it seems like
no address should match if group is non-mcast, and -EADDRNOTAVAIL 
will be returned.

Adding Nik to CC.

> In some cases, the callers of ip_mc_leave_group() don't check
> whether it is multicast address or not before calling
> such as do_ip_setsockopt(). So I suggest adding the ipv4_is_multicast()
> check to the ip_mc_leave_group() to prevent this from happening.
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Yingjie Wang <wangyingjie55@126.com>
> ---
>  net/ipv4/igmp.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
> index 7b272bbed2b4..1b6f91271cfd 100644
> --- a/net/ipv4/igmp.c
> +++ b/net/ipv4/igmp.c
> @@ -2248,6 +2248,9 @@ int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr)
>  	u32 ifindex;
>  	int ret = -EADDRNOTAVAIL;
>  
> +	if (!ipv4_is_multicast(group))
> +		return -EINVAL;
> +
>  	ASSERT_RTNL();
>  
>  	in_dev = ip_mc_find_dev(net, imr);


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

* Re: [PATCH v1] ipv4: add iPv4_is_multicast() check in ip_mc_leave_group().
  2021-01-19  4:39 ` Jakub Kicinski
@ 2021-01-19 10:28   ` Nikolay Aleksandrov
  0 siblings, 0 replies; 3+ messages in thread
From: Nikolay Aleksandrov @ 2021-01-19 10:28 UTC (permalink / raw)
  To: Jakub Kicinski, wangyingjie55
  Cc: davem, kuznet, yoshfuji, netdev, linux-kernel

On 19/01/2021 06:39, Jakub Kicinski wrote:
> On Sun, 17 Jan 2021 05:34:16 -0800 wangyingjie55@126.com wrote:
>> From: Yingjie Wang <wangyingjie55@126.com>
>>
>> There is no iPv4_is_multicast() check added to ip_mc_leave_group()
>> to check if imr->imr_multiaddr.s_addr is a multicast address.
>> If not a multicast address, it may result in an error.
> 
> Could you please say more? From looking at the code it seems like
> no address should match if group is non-mcast, and -EADDRNOTAVAIL 
> will be returned.
> 
> Adding Nik to CC.
> 

Thanks, and absolutely right. I don't see any point in changing the code, also
you are definitely not fixing any bug. 

>> In some cases, the callers of ip_mc_leave_group() don't check
>> whether it is multicast address or not before calling
>> such as do_ip_setsockopt(). So I suggest adding the ipv4_is_multicast()
>> check to the ip_mc_leave_group() to prevent this from happening.
>>
>> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
>> Signed-off-by: Yingjie Wang <wangyingjie55@126.com>
>> ---
>>  net/ipv4/igmp.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
>> index 7b272bbed2b4..1b6f91271cfd 100644
>> --- a/net/ipv4/igmp.c
>> +++ b/net/ipv4/igmp.c
>> @@ -2248,6 +2248,9 @@ int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr)
>>  	u32 ifindex;
>>  	int ret = -EADDRNOTAVAIL;
>>  
>> +	if (!ipv4_is_multicast(group))
>> +		return -EINVAL;
>> +
>>  	ASSERT_RTNL();
>>  
>>  	in_dev = ip_mc_find_dev(net, imr);
> 


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

end of thread, other threads:[~2021-01-19 10:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-17 13:34 [PATCH v1] ipv4: add iPv4_is_multicast() check in ip_mc_leave_group() wangyingjie55
2021-01-19  4:39 ` Jakub Kicinski
2021-01-19 10:28   ` Nikolay Aleksandrov

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